From 1e5525944b7af98ca47f2176e5ae54a7445dc6c7 Mon Sep 17 00:00:00 2001 From: Mukhiddin Yusupov Date: Fri, 16 Aug 2024 18:10:18 +0500 Subject: [PATCH] MSEARCH-794: refactor inventory clients --- .../search/client/InventoryHoldingClient.java | 17 +++++++++++------ .../client/InventoryInstanceClient.java | 17 +++++++++++------ .../search/client/InventoryItemClient.java | 17 +++++++++++------ .../client/InventoryRecordDtoCollection.java | 5 ----- .../client/InventoryRecordsCountDto.java | 3 +++ .../folio/search/client/TotalRecordsType.java | 16 ---------------- .../search/integration/InventoryService.java | 19 +++++++++---------- 7 files changed, 45 insertions(+), 49 deletions(-) delete mode 100644 src/main/java/org/folio/search/client/InventoryRecordDtoCollection.java create mode 100644 src/main/java/org/folio/search/client/InventoryRecordsCountDto.java delete mode 100644 src/main/java/org/folio/search/client/TotalRecordsType.java diff --git a/src/main/java/org/folio/search/client/InventoryHoldingClient.java b/src/main/java/org/folio/search/client/InventoryHoldingClient.java index 375ed0c03..24276062f 100644 --- a/src/main/java/org/folio/search/client/InventoryHoldingClient.java +++ b/src/main/java/org/folio/search/client/InventoryHoldingClient.java @@ -3,6 +3,7 @@ import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE; import static org.springframework.http.MediaType.APPLICATION_OCTET_STREAM_VALUE; +import java.util.List; import org.folio.search.model.client.CqlQuery; import org.springframework.cloud.openfeign.FeignClient; import org.springframework.web.bind.annotation.GetMapping; @@ -15,14 +16,18 @@ public interface InventoryHoldingClient { path = "/holdings", consumes = APPLICATION_OCTET_STREAM_VALUE, produces = APPLICATION_JSON_VALUE) - InventoryRecordDtoCollection getHoldings(@RequestParam("query") CqlQuery cql, - @RequestParam("offset") int offset, - @RequestParam("limit") int limit); + InventoryHoldingDtoCollection getHoldings(@RequestParam("query") CqlQuery cql, + @RequestParam("offset") int offset, + @RequestParam("limit") int limit); @GetMapping(path = "/holdings", produces = APPLICATION_JSON_VALUE) - InventoryRecordDtoCollection getHoldings(@RequestParam("offset") int offset, - @RequestParam("limit") int limit, - @RequestParam("totalRecords") String totalRecords); + InventoryHoldingDtoCollection getHoldings(@RequestParam("offset") int offset, + @RequestParam("limit") int limit); + + @GetMapping(path = "/holdings?limit=0&totalRecords=exact", produces = APPLICATION_JSON_VALUE) + InventoryRecordsCountDto getHoldingsCount(); record InventoryHoldingDto(String id) {} + + record InventoryHoldingDtoCollection(List holdingsRecords, int totalRecords) {} } diff --git a/src/main/java/org/folio/search/client/InventoryInstanceClient.java b/src/main/java/org/folio/search/client/InventoryInstanceClient.java index 667f6d2f0..4a51e1c38 100644 --- a/src/main/java/org/folio/search/client/InventoryInstanceClient.java +++ b/src/main/java/org/folio/search/client/InventoryInstanceClient.java @@ -3,6 +3,7 @@ import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE; import static org.springframework.http.MediaType.APPLICATION_OCTET_STREAM_VALUE; +import java.util.List; import org.folio.search.model.client.CqlQuery; import org.springframework.cloud.openfeign.FeignClient; import org.springframework.web.bind.annotation.GetMapping; @@ -15,14 +16,18 @@ public interface InventoryInstanceClient { path = "/instances", consumes = APPLICATION_OCTET_STREAM_VALUE, produces = APPLICATION_JSON_VALUE) - InventoryRecordDtoCollection getInstances(@RequestParam("query") CqlQuery cql, - @RequestParam("offset") int offset, - @RequestParam("limit") int limit); + InventoryInstanceDtoCollection getInstances(@RequestParam("query") CqlQuery cql, + @RequestParam("offset") int offset, + @RequestParam("limit") int limit); @GetMapping(path = "/instances", produces = APPLICATION_JSON_VALUE) - InventoryRecordDtoCollection getInstances(@RequestParam("offset") int offset, - @RequestParam("limit") int limit, - @RequestParam("totalRecords") String totalRecords); + InventoryInstanceDtoCollection getInstances(@RequestParam("offset") int offset, + @RequestParam("limit") int limit); + + @GetMapping(path = "/instances?limit=0&totalRecords=exact", produces = APPLICATION_JSON_VALUE) + InventoryRecordsCountDto getInstancesCount(); record InventoryInstanceDto(String id) {} + + record InventoryInstanceDtoCollection(List instances, int totalRecords) {} } diff --git a/src/main/java/org/folio/search/client/InventoryItemClient.java b/src/main/java/org/folio/search/client/InventoryItemClient.java index ac3aa561d..49a716b7c 100644 --- a/src/main/java/org/folio/search/client/InventoryItemClient.java +++ b/src/main/java/org/folio/search/client/InventoryItemClient.java @@ -3,6 +3,7 @@ import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE; import static org.springframework.http.MediaType.APPLICATION_OCTET_STREAM_VALUE; +import java.util.List; import org.folio.search.model.client.CqlQuery; import org.springframework.cloud.openfeign.FeignClient; import org.springframework.web.bind.annotation.GetMapping; @@ -15,14 +16,18 @@ public interface InventoryItemClient { path = "/items", consumes = APPLICATION_OCTET_STREAM_VALUE, produces = APPLICATION_JSON_VALUE) - InventoryRecordDtoCollection getItems(@RequestParam("query") CqlQuery cql, - @RequestParam("offset") int offset, - @RequestParam("limit") int limit); + InventoryItemDtoCollection getItems(@RequestParam("query") CqlQuery cql, + @RequestParam("offset") int offset, + @RequestParam("limit") int limit); @GetMapping(path = "/items", produces = APPLICATION_JSON_VALUE) - InventoryRecordDtoCollection getItems(@RequestParam("offset") int offset, - @RequestParam("limit") int limit, - @RequestParam("totalRecords") String totalRecords); + InventoryItemDtoCollection getItems(@RequestParam("offset") int offset, + @RequestParam("limit") int limit); + + @GetMapping(path = "/items?limit=0&totalRecords=exact", produces = APPLICATION_JSON_VALUE) + InventoryRecordsCountDto getItemsCount(); record InventoryItemDto(String id) {} + + record InventoryItemDtoCollection(List items, int totalRecords) {} } diff --git a/src/main/java/org/folio/search/client/InventoryRecordDtoCollection.java b/src/main/java/org/folio/search/client/InventoryRecordDtoCollection.java deleted file mode 100644 index 901a926d6..000000000 --- a/src/main/java/org/folio/search/client/InventoryRecordDtoCollection.java +++ /dev/null @@ -1,5 +0,0 @@ -package org.folio.search.client; - -import java.util.List; - -public record InventoryRecordDtoCollection(List records, int totalRecords) {} diff --git a/src/main/java/org/folio/search/client/InventoryRecordsCountDto.java b/src/main/java/org/folio/search/client/InventoryRecordsCountDto.java new file mode 100644 index 000000000..9d5101daa --- /dev/null +++ b/src/main/java/org/folio/search/client/InventoryRecordsCountDto.java @@ -0,0 +1,3 @@ +package org.folio.search.client; + +public record InventoryRecordsCountDto(int totalRecords) { } diff --git a/src/main/java/org/folio/search/client/TotalRecordsType.java b/src/main/java/org/folio/search/client/TotalRecordsType.java deleted file mode 100644 index 51ddfbb58..000000000 --- a/src/main/java/org/folio/search/client/TotalRecordsType.java +++ /dev/null @@ -1,16 +0,0 @@ -package org.folio.search.client; - -import lombok.AllArgsConstructor; -import lombok.Getter; - -@Getter -@AllArgsConstructor -public enum TotalRecordsType { - - EXACT("exact"), - ESTIMATED("estimated"), - NONE("none"), - AUTO("auto"); - - private final String value; -} diff --git a/src/main/java/org/folio/search/integration/InventoryService.java b/src/main/java/org/folio/search/integration/InventoryService.java index 0da5f3c67..9570b1eb8 100644 --- a/src/main/java/org/folio/search/integration/InventoryService.java +++ b/src/main/java/org/folio/search/integration/InventoryService.java @@ -10,7 +10,6 @@ import org.folio.search.client.InventoryInstanceClient; import org.folio.search.client.InventoryItemClient; import org.folio.search.client.InventoryReindexRecordsClient; -import org.folio.search.client.TotalRecordsType; import org.folio.search.exception.FolioIntegrationException; import org.folio.search.model.client.CqlQuery; import org.folio.search.model.reindex.MergeRangeEntity; @@ -62,9 +61,9 @@ public int fetchInventoryRecordCount(InventoryRecordType recordType) { try { var result = switch (recordType) { - case INSTANCE -> inventoryInstanceClient.getInstances(0, 0, TotalRecordsType.EXACT.getValue()); - case ITEM -> inventoryItemClient.getItems(0, 0, TotalRecordsType.EXACT.getValue()); - case HOLDING -> inventoryHoldingClient.getHoldings(0, 0, TotalRecordsType.EXACT.getValue()); + case INSTANCE -> inventoryInstanceClient.getInstancesCount(); + case ITEM -> inventoryItemClient.getItemsCount(); + case HOLDING -> inventoryHoldingClient.getHoldingsCount(); }; if (result == null) { @@ -105,14 +104,14 @@ public void publishReindexRecordsRange(MergeRangeEntity rangeEntity) { private List fetchInstances(CqlQuery cqlQuery, int offset, int limit) { var result = Optional.ofNullable(cqlQuery) .map(query -> inventoryInstanceClient.getInstances(query, offset, limit)) - .orElseGet(() -> inventoryInstanceClient.getInstances(offset, limit, TotalRecordsType.AUTO.getValue())); + .orElseGet(() -> inventoryInstanceClient.getInstances(offset, limit)); if (result == null) { log.warn("Failed to retrieve Inventory Instances, [query: {}, offset: {}, limit: {}]", cqlQuery, offset, limit); return Collections.emptyList(); } - return result.records().stream() + return result.instances().stream() .map(InventoryInstanceClient.InventoryInstanceDto::id) .map(UUID::fromString) .toList(); @@ -121,14 +120,14 @@ private List fetchInstances(CqlQuery cqlQuery, int offset, int limit) { private List fetchItems(CqlQuery cqlQuery, int offset, int limit) { var result = Optional.ofNullable(cqlQuery) .map(query -> inventoryItemClient.getItems(query, offset, limit)) - .orElseGet(() -> inventoryItemClient.getItems(offset, limit, TotalRecordsType.AUTO.getValue())); + .orElseGet(() -> inventoryItemClient.getItems(offset, limit)); if (result == null) { log.warn("Failed to retrieve Inventory Items, [query: {}, offset: {}, limit: {}]", cqlQuery, offset, limit); return Collections.emptyList(); } - return result.records().stream() + return result.items().stream() .map(InventoryItemClient.InventoryItemDto::id) .map(UUID::fromString) .toList(); @@ -137,14 +136,14 @@ private List fetchItems(CqlQuery cqlQuery, int offset, int limit) { private List fetchHoldings(CqlQuery cqlQuery, int offset, int limit) { var result = Optional.ofNullable(cqlQuery) .map(query -> inventoryHoldingClient.getHoldings(query, offset, limit)) - .orElseGet(() -> inventoryHoldingClient.getHoldings(offset, limit, TotalRecordsType.AUTO.getValue())); + .orElseGet(() -> inventoryHoldingClient.getHoldings(offset, limit)); if (result == null) { log.warn("Failed to retrieve Inventory Holdings, [query: {}, offset: {}, limit: {}]", cqlQuery, offset, limit); return Collections.emptyList(); } - return result.records().stream() + return result.holdingsRecords().stream() .map(InventoryHoldingClient.InventoryHoldingDto::id) .map(UUID::fromString) .toList();