Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MODINV-1069 Fix DataImportConsumerVerticleTest in mod-inventory and Fix NPE in HoldingsItemMatcher #757

Merged
merged 9 commits into from
Sep 3, 2024
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 (checkIfValueIsNullOrEmpty(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 checkIfValueIsNullOrEmpty(String value) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JavokhirAbdullayev , could you use another name for this method like "isNullOrEmpty"?

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