Skip to content

Commit

Permalink
MSEARCH-794: refactor inventory clients
Browse files Browse the repository at this point in the history
  • Loading branch information
mukhiddin-yusuf committed Aug 16, 2024
1 parent 2c03b2f commit c208148
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ InventoryRecordDtoCollection<InventoryHoldingDto> getHoldings(@RequestParam("que
@RequestParam("limit") int limit);

@GetMapping(path = "/holdings", produces = APPLICATION_JSON_VALUE)
InventoryRecordDtoCollection<InventoryHoldingDto> getHoldings(
@RequestParam("limit") int limit, @RequestParam("totalRecords") String totalRecords);
InventoryRecordDtoCollection<InventoryHoldingDto> getHoldings(@RequestParam("offset") int offset,
@RequestParam("limit") int limit,
@RequestParam("totalRecords") String totalRecords);

record InventoryHoldingDto(String id) {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ InventoryRecordDtoCollection<InventoryInstanceDto> getInstances(@RequestParam("q
@RequestParam("limit") int limit);

@GetMapping(path = "/instances", produces = APPLICATION_JSON_VALUE)
InventoryRecordDtoCollection<InventoryInstanceDto> getInstances(
@RequestParam("limit") int limit, @RequestParam("totalRecords") String totalRecords);
InventoryRecordDtoCollection<InventoryInstanceDto> getInstances(@RequestParam("offset") int offset,
@RequestParam("limit") int limit,
@RequestParam("totalRecords") String totalRecords);

record InventoryInstanceDto(String id) {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ InventoryRecordDtoCollection<InventoryItemDto> getItems(@RequestParam("query") C
@RequestParam("limit") int limit);

@GetMapping(path = "/items", produces = APPLICATION_JSON_VALUE)
InventoryRecordDtoCollection<InventoryItemDto> getItems(
@RequestParam("limit") int limit, @RequestParam("totalRecords") String totalRecords);
InventoryRecordDtoCollection<InventoryItemDto> getItems(@RequestParam("offset") int offset,
@RequestParam("limit") int limit,
@RequestParam("totalRecords") String totalRecords);

record InventoryItemDto(String id) {}
}
19 changes: 13 additions & 6 deletions src/main/java/org/folio/search/integration/InventoryService.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.util.Collections;
import java.util.List;
import java.util.Optional;
import java.util.UUID;
import lombok.extern.log4j.Log4j2;
import org.apache.commons.lang3.ObjectUtils;
Expand Down Expand Up @@ -61,9 +62,9 @@ public int fetchInventoryRecordCount(InventoryRecordType recordType) {

try {
var result = switch (recordType) {
case INSTANCE -> inventoryInstanceClient.getInstances(0, TotalRecordsType.EXACT.getValue());
case ITEM -> inventoryItemClient.getItems(0, TotalRecordsType.EXACT.getValue());
case HOLDING -> inventoryHoldingClient.getHoldings(0, TotalRecordsType.EXACT.getValue());
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());
};

if (result == null) {
Expand Down Expand Up @@ -102,7 +103,9 @@ public void publishReindexRecordsRange(MergeRangeEntity rangeEntity) {
}

private List<UUID> fetchInstances(CqlQuery cqlQuery, int offset, int limit) {
var result = inventoryInstanceClient.getInstances(cqlQuery, offset, limit);
var result = Optional.ofNullable(cqlQuery)
.map(query -> inventoryInstanceClient.getInstances(query, offset, limit))
.orElseGet(() -> inventoryInstanceClient.getInstances(offset, limit, TotalRecordsType.AUTO.getValue()));

if (result == null) {
log.warn("Failed to retrieve Inventory Instances, [query: {}, offset: {}, limit: {}]", cqlQuery, offset, limit);
Expand All @@ -116,7 +119,9 @@ private List<UUID> fetchInstances(CqlQuery cqlQuery, int offset, int limit) {
}

private List<UUID> fetchItems(CqlQuery cqlQuery, int offset, int limit) {
var result = inventoryItemClient.getItems(cqlQuery, offset, limit);
var result = Optional.ofNullable(cqlQuery)
.map(query -> inventoryItemClient.getItems(query, offset, limit))
.orElseGet(() -> inventoryItemClient.getItems(offset, limit, TotalRecordsType.AUTO.getValue()));

if (result == null) {
log.warn("Failed to retrieve Inventory Items, [query: {}, offset: {}, limit: {}]", cqlQuery, offset, limit);
Expand All @@ -130,7 +135,9 @@ private List<UUID> fetchItems(CqlQuery cqlQuery, int offset, int limit) {
}

private List<UUID> fetchHoldings(CqlQuery cqlQuery, int offset, int limit) {
var result = inventoryHoldingClient.getHoldings(cqlQuery, offset, limit);
var result = Optional.ofNullable(cqlQuery)
.map(query -> inventoryHoldingClient.getHoldings(query, offset, limit))
.orElseGet(() -> inventoryHoldingClient.getHoldings(offset, limit, TotalRecordsType.AUTO.getValue()));

if (result == null) {
log.warn("Failed to retrieve Inventory Holdings, [query: {}, offset: {}, limit: {}]", cqlQuery, offset, limit);
Expand Down

0 comments on commit c208148

Please sign in to comment.