diff --git a/indexer-core/src/main/java/org/opengroup/osdu/indexer/api/ReindexApi.java b/indexer-core/src/main/java/org/opengroup/osdu/indexer/api/ReindexApi.java index 7a74eb61236f61d1621b91c0934bcb5381b2566d..166d4ae36aed7c5866d8a4de6ed1b0cc702e8e17 100644 --- a/indexer-core/src/main/java/org/opengroup/osdu/indexer/api/ReindexApi.java +++ b/indexer-core/src/main/java/org/opengroup/osdu/indexer/api/ReindexApi.java @@ -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); } diff --git a/indexer-core/src/main/java/org/opengroup/osdu/indexer/model/ReindexRecordsRequest.java b/indexer-core/src/main/java/org/opengroup/osdu/indexer/model/ReindexRecordsRequest.java new file mode 100644 index 0000000000000000000000000000000000000000..5406656243ea6dbac4abc833983d52e27c4accc8 --- /dev/null +++ b/indexer-core/src/main/java/org/opengroup/osdu/indexer/model/ReindexRecordsRequest.java @@ -0,0 +1,17 @@ +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; +} diff --git a/indexer-core/src/test/java/org/opengroup/osdu/indexer/api/ReindexApiTest.java b/indexer-core/src/test/java/org/opengroup/osdu/indexer/api/ReindexApiTest.java index 5ddda237548d1969b769c92f21a3e99c87bdabec..719943ae2b5e3aeb4f49c34563732d5b0f2070a4 100644 --- a/indexer-core/src/test/java/org/opengroup/osdu/indexer/api/ReindexApiTest.java +++ b/indexer-core/src/test/java/org/opengroup/osdu/indexer/api/ReindexApiTest.java @@ -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)); } }