Skip to content

Commit

Permalink
fix(inventory-reindex-records): fix holdings type naming in reindex e…
Browse files Browse the repository at this point in the history
…ndpoint (#1073)

- fix holdings type naming
- fix instance serialization

Relates: MODINVSTOR-1230
  • Loading branch information
psmagin authored Sep 5, 2024
1 parent ed806c0 commit 46e84f1
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 11 deletions.
2 changes: 1 addition & 1 deletion ramls/reindex-records/publishReindexRecords.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"recordType": {
"description": "Inventory storage record type (e.g. instance, item, holding)",
"type": "string",
"enum": ["instance", "item", "holding"]
"enum": ["instance", "item", "holdings"]
},
"recordIdsRange": {
"description": "Range of records IDs",
Expand Down
9 changes: 5 additions & 4 deletions src/main/java/org/folio/persist/InstanceRepository.java
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,8 @@ public Future<Response> getInstanceSet(boolean instance, boolean holdingsRecords
}
}

public Future<List<String>> getReindexInstances(String fromId, String toId, boolean notConsortiumCentralTenant) {
public Future<List<Map<String, Object>>> getReindexInstances(String fromId, String toId,
boolean notConsortiumRecords) {
var sql = new StringBuilder("SELECT i.jsonb || jsonb_build_object('isBoundWith', EXISTS(SELECT 1 FROM ");
sql.append(postgresClientFuturized.getFullTableName(BOUND_WITH_TABLE));
sql.append(" as bw JOIN ");
Expand All @@ -126,15 +127,15 @@ public Future<List<String>> getReindexInstances(String fromId, String toId, bool
sql.append(" as hr ON hr.id = bw.holdingsrecordid WHERE hr.instanceId = i.id LIMIT 1)) FROM ");
sql.append(postgresClientFuturized.getFullTableName(INSTANCE_TABLE));
sql.append(" i WHERE i.id >= '").append(fromId).append("' AND i.id <= '").append(toId).append("'");
if (notConsortiumCentralTenant) {
if (notConsortiumRecords) {
sql.append(" AND i.jsonb->>'source' NOT LIKE 'CONSORTIUM-%'");
}
sql.append(";");

return postgresClient.select(sql.toString()).map(rows -> {
var resultList = new LinkedList<String>();
var resultList = new LinkedList<Map<String, Object>>();
for (var row : rows) {
resultList.add(row.getJsonObject(0).encode());
resultList.add(row.getJsonObject(0).getMap());
}
return resultList;
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public void postInventoryReindexRecordsPublish(PublishReindexRecords entity,
case ITEM ->
publishFuture = new ItemService(vertxContext, okapiHeaders)
.publishReindexItemRecords(rangeId, fromId, toId);
case HOLDING ->
case HOLDINGS ->
publishFuture = new HoldingsService(vertxContext, okapiHeaders)
.publishReindexHoldingsRecords(rangeId, fromId, toId);
default -> publishFuture = Future.failedFuture(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public Future<Void> publishReindexHoldings(String key, List<HoldingsRecord> hold
return succeededFuture();
}

return domainEventService.publishReindexRecords(key, PublishReindexRecords.RecordType.HOLDING, holdings);
return domainEventService.publishReindexRecords(key, PublishReindexRecords.RecordType.HOLDINGS, holdings);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
public class InstanceDomainEventPublisher extends AbstractDomainEventPublisher<Instance, Instance> {
private static final Logger log = getLogger(InstanceDomainEventPublisher.class);

private final CommonDomainEventPublisher<String> instanceReindexPublisher;
private final CommonDomainEventPublisher<Map<String, Object>> instanceReindexPublisher;

public InstanceDomainEventPublisher(Context context, Map<String, String> okapiHeaders) {
super(new InstanceRepository(context, okapiHeaders),
Expand All @@ -32,7 +32,7 @@ public InstanceDomainEventPublisher(Context context, Map<String, String> okapiHe
REINDEX_RECORDS.fullTopicName(tenantId(okapiHeaders)));
}

public Future<Void> publishReindexInstances(String key, List<String> instances) {
public Future<Void> publishReindexInstances(String key, List<Map<String, Object>> instances) {
if (CollectionUtils.isEmpty(instances) || StringUtils.isBlank(key)) {
return succeededFuture();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ void post_shouldReturn201_whenPublishingInstancesForReindex(Vertx vertx,
EVENT_MESSAGE_MATCHERS.hasReindexEventMessageFor());
var event = kafkaMessages.stream().toList().get(0).getBody();
var records = event.getJsonArray("records").stream()
.map(o -> new JsonObject((String) o))
.map(JsonObject::mapFrom)
.toList();
Assertions.assertThat(event.getString("recordType")).isEqualTo(PublishReindexRecords.RecordType.INSTANCE.value());
Assertions.assertThat(records).contains(mainInstance, anotherInstance);
Expand All @@ -151,7 +151,7 @@ private static Stream<Arguments> reindexTypesProvider() {
List.of(new Item().withId(RECORD1_ID), new Item().withId(RECORD2_ID))),
arguments(
HOLDING_TABLE,
PublishReindexRecords.RecordType.HOLDING,
PublishReindexRecords.RecordType.HOLDINGS,
List.of(new Holding().withId(RECORD1_ID), new Holding().withId(RECORD2_ID)))
);
}
Expand Down

0 comments on commit 46e84f1

Please sign in to comment.