Skip to content
Snippets Groups Projects
Commit 0a309ae8 authored by MZhu9's avatar MZhu9
Browse files

wrap the ReindexRecordsRequest

parent 422092f9
No related branches found
No related tags found
1 merge request!556Implement reindex records API
......@@ -27,6 +27,7 @@ import org.opengroup.osdu.core.common.model.indexer.RecordReindexRequest;
import org.opengroup.osdu.core.common.model.indexer.Records;
import org.opengroup.osdu.core.common.model.search.SearchServiceRole;
import org.opengroup.osdu.indexer.logging.AuditLogger;
import org.opengroup.osdu.indexer.model.ReindexRecordsRequest;
import org.opengroup.osdu.indexer.model.ReindexRecordsResponse;
import org.opengroup.osdu.indexer.service.IndexSchemaService;
import org.opengroup.osdu.indexer.service.ReindexService;
......@@ -77,8 +78,8 @@ public class ReindexApi {
})
@PreAuthorize("@authorizationFilter.hasPermission('" + SearchServiceRole.ADMIN + "')")
@PostMapping(path = "/records", consumes = "application/json")
public ResponseEntity<?> reindexRecords(@NotNull @RequestBody List<String> recordIds) {
Records records = this.reIndexService.reindexRecords(recordIds);
public ResponseEntity<?> reindexRecords(@NotNull @RequestBody ReindexRecordsRequest reindexRecordsRequest) {
Records records = this.reIndexService.reindexRecords(reindexRecordsRequest.getRecordIds());
this.auditLogger.getReindex(records.getRecords().stream().map(Records.Entity::getId).collect(Collectors.toList()));
return new ResponseEntity<>(ReindexRecordsResponse.builder().reIndexedRecords(records.getRecords().stream().map(Records.Entity::getId).collect(Collectors.toList())).notFoundRecords(records.getNotFound()).build(), HttpStatus.ACCEPTED);
}
......
package org.opengroup.osdu.indexer.model;
import lombok.AllArgsConstructor;
import lombok.Data;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import java.util.List;
@Data
@AllArgsConstructor
public class ReindexRecordsRequest {
@NotNull
@Size(min = 1)
private List<@NotBlank String> recordIds;
}
......@@ -23,6 +23,7 @@ import org.opengroup.osdu.core.common.model.http.AppException;
import org.opengroup.osdu.core.common.model.indexer.RecordReindexRequest;
import org.opengroup.osdu.core.common.model.indexer.Records;
import org.opengroup.osdu.indexer.logging.AuditLogger;
import org.opengroup.osdu.indexer.model.ReindexRecordsRequest;
import org.opengroup.osdu.indexer.model.ReindexRecordsResponse;
import org.opengroup.osdu.indexer.service.IndexSchemaService;
import org.opengroup.osdu.indexer.service.ReindexService;
......@@ -86,7 +87,7 @@ public class ReindexApiTest {
public void should_return200_when_valid_record_id_list_provided() {
when(this.reIndexService.reindexRecords(recordIds)).thenReturn(Records.builder().records(new ArrayList<>()).notFound(recordIds).build());
ResponseEntity<?> response = sut.reindexRecords(recordIds);
ResponseEntity<?> response = sut.reindexRecords(new ReindexRecordsRequest(recordIds));
assertEquals(HttpStatus.ACCEPTED, response.getStatusCode());
}
......@@ -95,13 +96,13 @@ public class ReindexApiTest {
public void should_throwAppException_ifUnknownExceptionCaught_reindexRecordsTest() {
when(this.reIndexService.reindexRecords(recordIds)).thenThrow(new AppException(500, "", ""));
sut.reindexRecords(recordIds);
sut.reindexRecords(new ReindexRecordsRequest(recordIds));
}
@Test(expected = NullPointerException.class)
public void should_throwAppException_ifNullPointerExceptionCaught_ReindexRecordsTest() {
when(this.reIndexService.reindexRecords(recordIds)).thenThrow(new NullPointerException(""));
sut.reindexRecords(recordIds);
sut.reindexRecords(new ReindexRecordsRequest(recordIds));
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment