Skip to content

Commit

Permalink
MODINV-1069 Fix DataImportConsumerVerticleTest in mod-inventory and F…
Browse files Browse the repository at this point in the history
…ix NPE in HoldingsItemMatcher (#757)

* Fix DataImportConsumerVerticleTest in mod-inventory and Fix NPE in HoldingsItemMatcher

* Fix DataImportConsumerVerticleTest in mod-inventory and Fix NPE in HoldingsItemMatcher

* small fix

* small fix
  • Loading branch information
JavokhirAbdullayev authored Sep 3, 2024
1 parent 8e019f9 commit 6a37749
Showing 1 changed file with 10 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,11 @@
import static org.apache.commons.lang3.StringUtils.EMPTY;
import static org.apache.commons.lang3.StringUtils.isNotEmpty;

import io.vertx.core.json.Json;
import io.vertx.core.json.JsonObject;
import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.stream.Collectors;

import io.vertx.core.json.Json;
import io.vertx.core.json.JsonObject;

import org.folio.DataImportEventPayload;
import org.folio.HoldingsRecord;
import org.folio.inventory.common.Context;
Expand All @@ -26,6 +24,7 @@ public class HoldingLoader extends AbstractLoader<HoldingsRecord> {
private static final String HOLDINGS_FIELD = "holdings";
private static final String INSTANCE_ID_FIELD = "instanceId";
private static final String INSTANCES_IDS_KEY = "INSTANCES_IDS";
private static final String EMPTY_ARRAY = "[]";

private Storage storage;
private AbstractPreloader preloader;
Expand Down Expand Up @@ -59,7 +58,7 @@ protected String addCqlSubMatchCondition(DataImportEventPayload eventPayload) {
cqlSubMatch = getConditionByMultiMatchResult(eventPayload);
} else if (isNotEmpty(eventPayload.getContext().get(INSTANCES_IDS_KEY))) {
cqlSubMatch = getConditionByMultipleMarcBibMatchResult(eventPayload);
} else if (isNotEmpty(eventPayload.getContext().get(EntityType.HOLDINGS.value()))) {
} else if (isNotNullOrEmpty(eventPayload.getContext().get(EntityType.HOLDINGS.value()))) {
JsonObject holdingAsJson = new JsonObject(eventPayload.getContext().get(EntityType.HOLDINGS.value()));
if (holdingAsJson.getJsonObject(HOLDINGS_FIELD) != null) {
holdingAsJson = holdingAsJson.getJsonObject(HOLDINGS_FIELD);
Expand All @@ -73,6 +72,12 @@ protected String addCqlSubMatchCondition(DataImportEventPayload eventPayload) {
return cqlSubMatch;
}

private static boolean isNotNullOrEmpty(String value) {
if (value == null || value.equals(EMPTY_ARRAY))
return false;
return isNotEmpty(value);
}

private String getConditionByMultipleMarcBibMatchResult(DataImportEventPayload eventPayload) {
return getConditionByMultipleValues(INSTANCE_ID_FIELD, eventPayload, INSTANCES_IDS_KEY);
}
Expand Down

0 comments on commit 6a37749

Please sign in to comment.