From cb2b9368c07872adc0c7d5d0048fd99d714481f6 Mon Sep 17 00:00:00 2001 From: Javokhir Abdullaev <101543142+JavokhirAbdullayev@users.noreply.github.com> Date: Tue, 24 Dec 2024 14:49:48 +0500 Subject: [PATCH] MODDATAIMP-1145 Import of MARC records fails with "Invalid token" error. (#793) * MODINV-1001 The sorting for Items on Instance details page is not worked * add userId during create instance event handler * add userId header in some handlers * fix headers * remove wildcards --- .../consumers/MarcBibInstanceHridSetKafkaHandler.java | 5 ++++- .../consumers/MarcBibUpdateKafkaHandler.java | 7 ++++--- .../MarcHoldingsRecordHridSetKafkaHandler.java | 4 +++- .../dataimport/consumers/QuickMarcKafkaHandler.java | 8 ++++++-- .../actions/AbstractAuthorityEventHandler.java | 4 ++-- .../handlers/actions/CreateHoldingEventHandler.java | 5 +++-- .../handlers/actions/CreateInstanceEventHandler.java | 4 +++- .../handlers/actions/CreateItemEventHandler.java | 4 +++- .../actions/CreateMarcHoldingsEventHandler.java | 5 +++-- .../handlers/actions/DeleteAuthorityEventHandler.java | 5 +++-- .../MarcBibModifiedPostProcessingEventHandler.java | 5 +++-- .../handlers/actions/ReplaceInstanceEventHandler.java | 10 ++++++---- .../handlers/actions/UpdateHoldingEventHandler.java | 5 +++-- .../handlers/actions/UpdateItemEventHandler.java | 4 +++- .../actions/UpdateMarcHoldingsEventHandler.java | 5 +++-- .../actions/modify/AbstractModifyEventHandler.java | 7 ++++--- .../matching/AbstractMarcMatchEventHandler.java | 4 +++- .../handlers/matching/AbstractMatchEventHandler.java | 4 ++-- .../matching/MarcBibliographicMatchEventHandler.java | 4 +++- .../handlers/matching/util/EventHandlingUtil.java | 4 +++- 20 files changed, 67 insertions(+), 36 deletions(-) diff --git a/src/main/java/org/folio/inventory/dataimport/consumers/MarcBibInstanceHridSetKafkaHandler.java b/src/main/java/org/folio/inventory/dataimport/consumers/MarcBibInstanceHridSetKafkaHandler.java index a5195b888..42fc2066d 100644 --- a/src/main/java/org/folio/inventory/dataimport/consumers/MarcBibInstanceHridSetKafkaHandler.java +++ b/src/main/java/org/folio/inventory/dataimport/consumers/MarcBibInstanceHridSetKafkaHandler.java @@ -2,6 +2,8 @@ import static java.lang.String.format; import static org.apache.commons.lang3.StringUtils.isEmpty; +import static org.folio.inventory.dataimport.handlers.matching.util.EventHandlingUtil.OKAPI_REQUEST_ID; +import static org.folio.inventory.dataimport.handlers.matching.util.EventHandlingUtil.OKAPI_USER_ID; import static org.folio.inventory.dataimport.util.MappingConstants.MARC_BIB_RECORD_FORMAT; import static org.folio.rest.util.OkapiConnectionParams.OKAPI_TENANT_HEADER; import static org.folio.rest.util.OkapiConnectionParams.OKAPI_TOKEN_HEADER; @@ -106,7 +108,8 @@ public Future handle(KafkaConsumerRecord record) { private Future updateInstance(HashMap eventPayload, Record marcRecord, Map headersMap) { String tenantId = eventPayload.getOrDefault(CENTRAL_TENANT_ID_KEY, eventPayload.get(OKAPI_TENANT_HEADER)); - Context context = EventHandlingUtil.constructContext(tenantId, headersMap.get(OKAPI_TOKEN_HEADER), headersMap.get(OKAPI_URL_HEADER)); + Context context = EventHandlingUtil.constructContext(tenantId, headersMap.get(OKAPI_TOKEN_HEADER), headersMap.get(OKAPI_URL_HEADER), + headersMap.get(OKAPI_USER_ID), headersMap.get(OKAPI_REQUEST_ID)); return instanceUpdateDelegate.handle(eventPayload, marcRecord, context); } diff --git a/src/main/java/org/folio/inventory/dataimport/consumers/MarcBibUpdateKafkaHandler.java b/src/main/java/org/folio/inventory/dataimport/consumers/MarcBibUpdateKafkaHandler.java index cdc277354..04e1840dc 100644 --- a/src/main/java/org/folio/inventory/dataimport/consumers/MarcBibUpdateKafkaHandler.java +++ b/src/main/java/org/folio/inventory/dataimport/consumers/MarcBibUpdateKafkaHandler.java @@ -3,6 +3,8 @@ import static java.lang.String.format; import static java.util.Objects.isNull; import static org.folio.inventory.EntityLinksKafkaTopic.LINKS_STATS; +import static org.folio.inventory.dataimport.handlers.matching.util.EventHandlingUtil.OKAPI_REQUEST_ID; +import static org.folio.inventory.dataimport.handlers.matching.util.EventHandlingUtil.OKAPI_USER_ID; import static org.folio.inventory.dataimport.util.AdditionalFieldsUtil.SUBFIELD_I; import static org.folio.inventory.dataimport.util.AdditionalFieldsUtil.TAG_999; import static org.folio.inventory.dataimport.util.MappingConstants.MARC_BIB_RECORD_TYPE; @@ -55,8 +57,6 @@ public class MarcBibUpdateKafkaHandler implements AsyncRecordHandler handle(KafkaConsumerRecord consumerRecord) LOGGER.error(message); return Future.failedFuture(message); } - Context context = EventHandlingUtil.constructContext(instanceEvent.getTenant(), headersMap.get(OKAPI_TOKEN_HEADER), headersMap.get(OKAPI_URL_HEADER), headersMap.get(OKAPI_USER_ID), headersMap.get(OKAPI_REQUEST_ID)); + Context context = EventHandlingUtil.constructContext(instanceEvent.getTenant(), headersMap.get(OKAPI_TOKEN_HEADER), headersMap.get(OKAPI_URL_HEADER), + headersMap.get(OKAPI_USER_ID), headersMap.get(OKAPI_REQUEST_ID)); Record marcBibRecord = instanceEvent.getRecord(); io.vertx.core.Context vertxContext = Vertx.currentContext(); diff --git a/src/main/java/org/folio/inventory/dataimport/consumers/MarcHoldingsRecordHridSetKafkaHandler.java b/src/main/java/org/folio/inventory/dataimport/consumers/MarcHoldingsRecordHridSetKafkaHandler.java index a5d30235d..f68b6e5e9 100644 --- a/src/main/java/org/folio/inventory/dataimport/consumers/MarcHoldingsRecordHridSetKafkaHandler.java +++ b/src/main/java/org/folio/inventory/dataimport/consumers/MarcHoldingsRecordHridSetKafkaHandler.java @@ -3,6 +3,8 @@ import static java.lang.String.format; import static org.apache.commons.lang3.StringUtils.isEmpty; +import static org.folio.inventory.dataimport.handlers.matching.util.EventHandlingUtil.OKAPI_USER_ID; +import static org.folio.inventory.dataimport.handlers.matching.util.EventHandlingUtil.OKAPI_REQUEST_ID; import static org.folio.inventory.dataimport.handlers.matching.util.EventHandlingUtil.constructContext; import static org.folio.rest.util.OkapiConnectionParams.OKAPI_TENANT_HEADER; import static org.folio.rest.util.OkapiConnectionParams.OKAPI_TOKEN_HEADER; @@ -89,7 +91,7 @@ public Future handle(KafkaConsumerRecord record) { } Context context = constructContext(headersMap.get(OKAPI_TENANT_HEADER), headersMap.get(OKAPI_TOKEN_HEADER), - headersMap.get(OKAPI_URL_HEADER)); + headersMap.get(OKAPI_URL_HEADER), headersMap.get(OKAPI_USER_ID), headersMap.get(OKAPI_REQUEST_ID)); Record marcRecord = Json.decodeValue(eventPayload.get(MARC_KEY), Record.class); mappingMetadataCache.get(jobExecutionId, context) diff --git a/src/main/java/org/folio/inventory/dataimport/consumers/QuickMarcKafkaHandler.java b/src/main/java/org/folio/inventory/dataimport/consumers/QuickMarcKafkaHandler.java index 3cd3679c6..bb7a516e5 100644 --- a/src/main/java/org/folio/inventory/dataimport/consumers/QuickMarcKafkaHandler.java +++ b/src/main/java/org/folio/inventory/dataimport/consumers/QuickMarcKafkaHandler.java @@ -4,6 +4,8 @@ import static org.folio.inventory.dataimport.handlers.QMEventTypes.QM_INVENTORY_AUTHORITY_UPDATED; import static org.folio.inventory.dataimport.handlers.QMEventTypes.QM_INVENTORY_HOLDINGS_UPDATED; import static org.folio.inventory.dataimport.handlers.QMEventTypes.QM_INVENTORY_INSTANCE_UPDATED; +import static org.folio.inventory.dataimport.handlers.matching.util.EventHandlingUtil.OKAPI_USER_ID; +import static org.folio.inventory.dataimport.handlers.matching.util.EventHandlingUtil.OKAPI_REQUEST_ID; import static org.folio.inventory.dataimport.handlers.matching.util.EventHandlingUtil.constructContext; import static org.folio.kafka.KafkaHeaderUtils.kafkaHeadersFromMap; import static org.folio.kafka.KafkaHeaderUtils.kafkaHeadersToMap; @@ -79,8 +81,10 @@ public QuickMarcKafkaHandler(Vertx vertx, Storage storage, int maxDistributionNu @Override public Future handle(KafkaConsumerRecord record) { - var params = new OkapiConnectionParams(kafkaHeadersToMap(record.headers()), vertx); - var context = constructContext(params.getTenantId(), params.getToken(), params.getOkapiUrl()); + var kafkaHeaders = kafkaHeadersToMap(record.headers()); + var params = new OkapiConnectionParams(kafkaHeaders, vertx); + var context = constructContext(params.getTenantId(), params.getToken(), params.getOkapiUrl(), + kafkaHeaders.get(OKAPI_USER_ID), kafkaHeaders.get(OKAPI_REQUEST_ID)); Event event = Json.decodeValue(record.value(), Event.class); LOGGER.info("Quick marc event payload has been received with event type: {}", event.getEventType()); return getEventPayload(event) diff --git a/src/main/java/org/folio/inventory/dataimport/handlers/actions/AbstractAuthorityEventHandler.java b/src/main/java/org/folio/inventory/dataimport/handlers/actions/AbstractAuthorityEventHandler.java index 9fba4acdd..5bc76fe05 100644 --- a/src/main/java/org/folio/inventory/dataimport/handlers/actions/AbstractAuthorityEventHandler.java +++ b/src/main/java/org/folio/inventory/dataimport/handlers/actions/AbstractAuthorityEventHandler.java @@ -3,6 +3,7 @@ import static io.vertx.core.json.JsonObject.mapFrom; import static java.lang.String.format; +import static org.folio.inventory.dataimport.handlers.matching.util.EventHandlingUtil.PAYLOAD_USER_ID; import static org.folio.inventory.dataimport.handlers.matching.util.EventHandlingUtil.constructContext; import static org.folio.inventory.dataimport.util.LoggerUtil.logParametersEventHandler; import static org.folio.rest.jaxrs.model.ProfileType.ACTION_PROFILE; @@ -28,7 +29,6 @@ import org.folio.MappingProfile; import org.folio.inventory.common.Context; import org.folio.inventory.dataimport.cache.MappingMetadataCache; -import org.folio.inventory.dataimport.handlers.matching.util.EventHandlingUtil; import org.folio.inventory.domain.AuthorityRecordCollection; import org.folio.inventory.storage.Storage; import org.folio.inventory.validation.exceptions.JsonMappingException; @@ -79,7 +79,7 @@ public CompletableFuture handle(DataImportEventPayload p prepareEvent(payload); - var context = constructContext(payload.getTenant(), payload.getToken(), payload.getOkapiUrl(), payload.getContext().get(EventHandlingUtil.USER_ID)); + var context = constructContext(payload.getTenant(), payload.getToken(), payload.getOkapiUrl(), payload.getContext().get(PAYLOAD_USER_ID)); var jobExecutionId = payload.getJobExecutionId(); mappingMetadataCache.get(jobExecutionId, context) .map(mapMetadataOrFail()) diff --git a/src/main/java/org/folio/inventory/dataimport/handlers/actions/CreateHoldingEventHandler.java b/src/main/java/org/folio/inventory/dataimport/handlers/actions/CreateHoldingEventHandler.java index 51fbbad17..48a063ed6 100644 --- a/src/main/java/org/folio/inventory/dataimport/handlers/actions/CreateHoldingEventHandler.java +++ b/src/main/java/org/folio/inventory/dataimport/handlers/actions/CreateHoldingEventHandler.java @@ -16,7 +16,6 @@ import org.folio.inventory.consortium.services.ConsortiumService; import org.folio.inventory.dataimport.cache.MappingMetadataCache; import org.folio.inventory.dataimport.entities.PartialError; -import org.folio.inventory.dataimport.handlers.matching.util.EventHandlingUtil; import org.folio.inventory.dataimport.services.OrderHelperService; import org.folio.inventory.consortium.util.ConsortiumUtil; import org.folio.inventory.dataimport.util.ParsedRecordUtil; @@ -46,6 +45,7 @@ import static org.folio.ActionProfile.FolioRecord.HOLDINGS; import static org.folio.ActionProfile.FolioRecord.MARC_BIBLIOGRAPHIC; import static org.folio.DataImportEventTypes.DI_INVENTORY_HOLDING_CREATED; +import static org.folio.inventory.dataimport.handlers.matching.util.EventHandlingUtil.PAYLOAD_USER_ID; import static org.folio.inventory.dataimport.handlers.matching.util.EventHandlingUtil.constructContext; import static org.folio.inventory.dataimport.util.DataImportConstants.UNIQUE_ID_ERROR_MESSAGE; import static org.folio.rest.jaxrs.model.ProfileType.ACTION_PROFILE; @@ -97,7 +97,8 @@ public CompletableFuture handle(DataImportEventPayload d return CompletableFuture.failedFuture(new EventProcessingException(ACTION_HAS_NO_MAPPING_MSG)); } - Context context = constructContext(dataImportEventPayload.getTenant(), dataImportEventPayload.getToken(), dataImportEventPayload.getOkapiUrl(), payloadContext.get(EventHandlingUtil.USER_ID)); + Context context = constructContext(dataImportEventPayload.getTenant(), dataImportEventPayload.getToken(), dataImportEventPayload.getOkapiUrl(), + payloadContext.get(PAYLOAD_USER_ID)); String jobExecutionId = dataImportEventPayload.getJobExecutionId(); String recordId = payloadContext.get(RECORD_ID_HEADER); String chunkId = payloadContext.get(CHUNK_ID_HEADER); diff --git a/src/main/java/org/folio/inventory/dataimport/handlers/actions/CreateInstanceEventHandler.java b/src/main/java/org/folio/inventory/dataimport/handlers/actions/CreateInstanceEventHandler.java index 34ec4bd97..49949b89f 100644 --- a/src/main/java/org/folio/inventory/dataimport/handlers/actions/CreateInstanceEventHandler.java +++ b/src/main/java/org/folio/inventory/dataimport/handlers/actions/CreateInstanceEventHandler.java @@ -8,6 +8,7 @@ import static org.folio.ActionProfile.FolioRecord.MARC_BIBLIOGRAPHIC; import static org.folio.DataImportEventTypes.DI_INVENTORY_INSTANCE_CREATED; import static org.folio.DataImportEventTypes.DI_INVENTORY_INSTANCE_CREATED_READY_FOR_POST_PROCESSING; +import static org.folio.inventory.dataimport.handlers.matching.util.EventHandlingUtil.PAYLOAD_USER_ID; import static org.folio.inventory.dataimport.util.AdditionalFieldsUtil.SUBFIELD_I; import static org.folio.inventory.dataimport.util.AdditionalFieldsUtil.TAG_999; import static org.folio.inventory.dataimport.util.AdditionalFieldsUtil.reorderMarcRecordFields; @@ -94,7 +95,8 @@ public CompletableFuture handle(DataImportEventPayload d return CompletableFuture.failedFuture(new EventProcessingException(format(ACTION_HAS_NO_MAPPING_MSG, jobExecutionId, recordId))); } - Context context = EventHandlingUtil.constructContext(dataImportEventPayload.getTenant(), dataImportEventPayload.getToken(), dataImportEventPayload.getOkapiUrl(), payloadContext.get(EventHandlingUtil.USER_ID)); + Context context = EventHandlingUtil.constructContext(dataImportEventPayload.getTenant(), dataImportEventPayload.getToken(), dataImportEventPayload.getOkapiUrl(), + payloadContext.get(PAYLOAD_USER_ID)); Record targetRecord = Json.decodeValue(payloadContext.get(EntityType.MARC_BIBLIOGRAPHIC.value()), Record.class); var sourceContent = targetRecord.getParsedRecord().getContent().toString(); diff --git a/src/main/java/org/folio/inventory/dataimport/handlers/actions/CreateItemEventHandler.java b/src/main/java/org/folio/inventory/dataimport/handlers/actions/CreateItemEventHandler.java index 594e51dc3..650b901ab 100644 --- a/src/main/java/org/folio/inventory/dataimport/handlers/actions/CreateItemEventHandler.java +++ b/src/main/java/org/folio/inventory/dataimport/handlers/actions/CreateItemEventHandler.java @@ -56,6 +56,7 @@ import static org.folio.ActionProfile.Action.CREATE; import static org.folio.ActionProfile.FolioRecord.ITEM; import static org.folio.DataImportEventTypes.DI_INVENTORY_ITEM_CREATED; +import static org.folio.inventory.dataimport.handlers.matching.util.EventHandlingUtil.PAYLOAD_USER_ID; import static org.folio.inventory.dataimport.util.DataImportConstants.UNIQUE_ID_ERROR_MESSAGE; import static org.folio.inventory.dataimport.util.LoggerUtil.logParametersEventHandler; import static org.folio.rest.jaxrs.model.ProfileType.ACTION_PROFILE; @@ -134,7 +135,8 @@ public CompletableFuture handle(DataImportEventPayload d Future recordToItemFuture = idStorageService.store(recordId, UUID.randomUUID().toString(), dataImportEventPayload.getTenant()); recordToItemFuture.onSuccess(res -> { String deduplicationItemId = res.getEntityId(); - Context context = EventHandlingUtil.constructContext(dataImportEventPayload.getTenant(), dataImportEventPayload.getToken(), dataImportEventPayload.getOkapiUrl(), payloadContext.get(EventHandlingUtil.USER_ID)); + Context context = EventHandlingUtil.constructContext(dataImportEventPayload.getTenant(), dataImportEventPayload.getToken(), dataImportEventPayload.getOkapiUrl(), + payloadContext.get(PAYLOAD_USER_ID)); ItemCollection itemCollection = storage.getItemCollection(context); mappingMetadataCache.get(jobExecutionId, context) diff --git a/src/main/java/org/folio/inventory/dataimport/handlers/actions/CreateMarcHoldingsEventHandler.java b/src/main/java/org/folio/inventory/dataimport/handlers/actions/CreateMarcHoldingsEventHandler.java index 662402d2f..e5ffa285c 100644 --- a/src/main/java/org/folio/inventory/dataimport/handlers/actions/CreateMarcHoldingsEventHandler.java +++ b/src/main/java/org/folio/inventory/dataimport/handlers/actions/CreateMarcHoldingsEventHandler.java @@ -8,6 +8,7 @@ import static org.folio.ActionProfile.FolioRecord.MARC_HOLDINGS; import static org.folio.DataImportEventTypes.DI_INVENTORY_HOLDINGS_CREATED_READY_FOR_POST_PROCESSING; import static org.folio.DataImportEventTypes.DI_INVENTORY_HOLDING_CREATED; +import static org.folio.inventory.dataimport.handlers.matching.util.EventHandlingUtil.PAYLOAD_USER_ID; import static org.folio.inventory.dataimport.handlers.matching.util.EventHandlingUtil.constructContext; import static org.folio.inventory.dataimport.util.DataImportConstants.UNIQUE_ID_ERROR_MESSAGE; import static org.folio.inventory.dataimport.util.LoggerUtil.logParametersEventHandler; @@ -28,7 +29,6 @@ import org.folio.MappingMetadataDto; import org.folio.inventory.common.Context; import org.folio.inventory.dataimport.cache.MappingMetadataCache; -import org.folio.inventory.dataimport.handlers.matching.util.EventHandlingUtil; import org.folio.inventory.domain.HoldingsRecordCollection; import org.folio.inventory.domain.relationship.RecordToEntity; import org.folio.inventory.services.HoldingsCollectionService; @@ -100,7 +100,8 @@ public CompletableFuture handle(DataImportEventPayload d return CompletableFuture.failedFuture(new EventProcessingException(ACTION_HAS_NO_MAPPING_MSG)); } - Context context = constructContext(dataImportEventPayload.getTenant(), dataImportEventPayload.getToken(), dataImportEventPayload.getOkapiUrl(), payloadContext.get(EventHandlingUtil.USER_ID)); + Context context = constructContext(dataImportEventPayload.getTenant(), dataImportEventPayload.getToken(), dataImportEventPayload.getOkapiUrl(), + payloadContext.get(PAYLOAD_USER_ID)); Record targetRecord = new JsonObject(payloadContext.get(EntityType.MARC_HOLDINGS.value())).mapTo(Record.class); prepareEvent(dataImportEventPayload); diff --git a/src/main/java/org/folio/inventory/dataimport/handlers/actions/DeleteAuthorityEventHandler.java b/src/main/java/org/folio/inventory/dataimport/handlers/actions/DeleteAuthorityEventHandler.java index 6b854c351..067e01ad4 100644 --- a/src/main/java/org/folio/inventory/dataimport/handlers/actions/DeleteAuthorityEventHandler.java +++ b/src/main/java/org/folio/inventory/dataimport/handlers/actions/DeleteAuthorityEventHandler.java @@ -10,7 +10,6 @@ import org.folio.Authority; import org.folio.DataImportEventPayload; import org.folio.inventory.dataimport.exceptions.DataImportException; -import org.folio.inventory.dataimport.handlers.matching.util.EventHandlingUtil; import org.folio.inventory.domain.AuthorityRecordCollection; import org.folio.inventory.storage.Storage; import org.folio.processing.events.services.handler.EventHandler; @@ -23,6 +22,7 @@ import static java.lang.String.format; import static org.folio.ActionProfile.Action.DELETE; import static org.folio.ActionProfile.FolioRecord.MARC_AUTHORITY; +import static org.folio.inventory.dataimport.handlers.matching.util.EventHandlingUtil.PAYLOAD_USER_ID; import static org.folio.inventory.dataimport.handlers.matching.util.EventHandlingUtil.constructContext; import static org.folio.inventory.dataimport.util.LoggerUtil.logParametersEventHandler; import static org.folio.rest.jaxrs.model.ProfileType.ACTION_PROFILE; @@ -55,7 +55,8 @@ public CompletableFuture handle(DataImportEventPayload p throw new EventProcessingException(UNEXPECTED_PAYLOAD_MSG); } - var context = constructContext(payload.getTenant(), payload.getToken(), payload.getOkapiUrl(), payload.getContext().get(EventHandlingUtil.USER_ID)); + var context = constructContext(payload.getTenant(), payload.getToken(), payload.getOkapiUrl(), + payload.getContext().get(PAYLOAD_USER_ID)); AuthorityRecordCollection authorityRecordCollection = storage.getAuthorityRecordCollection(context); String id = payload.getContext().get(AUTHORITY_RECORD_ID); LOGGER.info("Delete authority with id: {}", id); diff --git a/src/main/java/org/folio/inventory/dataimport/handlers/actions/MarcBibModifiedPostProcessingEventHandler.java b/src/main/java/org/folio/inventory/dataimport/handlers/actions/MarcBibModifiedPostProcessingEventHandler.java index fd76c4c11..3e76f9e50 100644 --- a/src/main/java/org/folio/inventory/dataimport/handlers/actions/MarcBibModifiedPostProcessingEventHandler.java +++ b/src/main/java/org/folio/inventory/dataimport/handlers/actions/MarcBibModifiedPostProcessingEventHandler.java @@ -32,6 +32,7 @@ import static org.apache.commons.lang3.StringUtils.isBlank; import static org.folio.ActionProfile.FolioRecord.INSTANCE; import static org.folio.DataImportEventTypes.DI_SRS_MARC_BIB_RECORD_MODIFIED_READY_FOR_POST_PROCESSING; +import static org.folio.inventory.dataimport.handlers.matching.util.EventHandlingUtil.PAYLOAD_USER_ID; import static org.folio.inventory.dataimport.handlers.matching.util.EventHandlingUtil.getTenant; import static org.folio.inventory.dataimport.util.LoggerUtil.logParametersEventHandler; import static org.folio.rest.jaxrs.model.EntityType.MARC_BIBLIOGRAPHIC; @@ -79,8 +80,8 @@ public CompletableFuture handle(DataImportEventPayload d } record.setExternalIdsHolder(new ExternalIdsHolder().withInstanceId(instanceId)); - Context localTenantContext = EventHandlingUtil.constructContext(dataImportEventPayload.getTenant(), dataImportEventPayload.getToken(), dataImportEventPayload.getOkapiUrl(), payloadContext.get(EventHandlingUtil.USER_ID)); - Context targetInstanceContext = EventHandlingUtil.constructContext(getTenant(dataImportEventPayload), dataImportEventPayload.getToken(), dataImportEventPayload.getOkapiUrl(), payloadContext.get(EventHandlingUtil.USER_ID)); + Context localTenantContext = EventHandlingUtil.constructContext(dataImportEventPayload.getTenant(), dataImportEventPayload.getToken(), dataImportEventPayload.getOkapiUrl(), payloadContext.get(PAYLOAD_USER_ID)); + Context targetInstanceContext = EventHandlingUtil.constructContext(getTenant(dataImportEventPayload), dataImportEventPayload.getToken(), dataImportEventPayload.getOkapiUrl(), payloadContext.get(PAYLOAD_USER_ID)); Promise instanceUpdatePromise = Promise.promise(); mappingMetadataCache.get(dataImportEventPayload.getJobExecutionId(), localTenantContext) diff --git a/src/main/java/org/folio/inventory/dataimport/handlers/actions/ReplaceInstanceEventHandler.java b/src/main/java/org/folio/inventory/dataimport/handlers/actions/ReplaceInstanceEventHandler.java index b09201a6e..bc9421adb 100644 --- a/src/main/java/org/folio/inventory/dataimport/handlers/actions/ReplaceInstanceEventHandler.java +++ b/src/main/java/org/folio/inventory/dataimport/handlers/actions/ReplaceInstanceEventHandler.java @@ -52,6 +52,7 @@ import static org.folio.ActionProfile.FolioRecord.MARC_BIBLIOGRAPHIC; import static org.folio.DataImportEventTypes.DI_INVENTORY_INSTANCE_UPDATED; import static org.folio.DataImportEventTypes.DI_INVENTORY_INSTANCE_UPDATED_READY_FOR_POST_PROCESSING; +import static org.folio.inventory.dataimport.handlers.matching.util.EventHandlingUtil.PAYLOAD_USER_ID; import static org.folio.inventory.dataimport.util.LoggerUtil.INCOMING_RECORD_ID; import static org.folio.inventory.dataimport.util.LoggerUtil.logParametersEventHandler; import static org.folio.inventory.dataimport.util.MappingConstants.INSTANCE_PATH; @@ -117,7 +118,8 @@ public CompletableFuture handle(DataImportEventPayload d LOGGER.info("handle:: Processing ReplaceInstanceEventHandler starting with jobExecutionId: {} and incomingRecordId: {}.", dataImportEventPayload.getJobExecutionId(), payloadContext.get(INCOMING_RECORD_ID)); - Context context = EventHandlingUtil.constructContext(dataImportEventPayload.getTenant(), dataImportEventPayload.getToken(), dataImportEventPayload.getOkapiUrl(), payloadContext.get(EventHandlingUtil.USER_ID)); + Context context = EventHandlingUtil.constructContext(dataImportEventPayload.getTenant(), dataImportEventPayload.getToken(), dataImportEventPayload.getOkapiUrl(), + payloadContext.get(PAYLOAD_USER_ID)); Instance instanceToUpdate = Instance.fromJson(new JsonObject(dataImportEventPayload.getContext().get(INSTANCE.value()))); if (instanceToUpdate.getSource() != null && instanceToUpdate.getSource().equals(LINKED_DATA.getValue())) { @@ -132,7 +134,7 @@ public CompletableFuture handle(DataImportEventPayload d .compose(consortiumConfigurationOptional -> { if (consortiumConfigurationOptional.isPresent()) { String centralTenantId = consortiumConfigurationOptional.get().getCentralTenantId(); - Context centralTenantContext = EventHandlingUtil.constructContext(centralTenantId, context.getToken(), context.getOkapiLocation(), payloadContext.get(EventHandlingUtil.USER_ID)); + Context centralTenantContext = EventHandlingUtil.constructContext(centralTenantId, context.getToken(), context.getOkapiLocation(), payloadContext.get(PAYLOAD_USER_ID)); InstanceCollection instanceCollection = storage.getInstanceCollection(centralTenantContext); InstanceUtil.findInstanceById(instanceToUpdate.getId(), instanceCollection) .onSuccess(existedCentralTenantInstance -> { @@ -154,7 +156,7 @@ public CompletableFuture handle(DataImportEventPayload d }); } else { String targetInstanceTenantId = dataImportEventPayload.getContext().getOrDefault(CENTRAL_TENANT_ID, dataImportEventPayload.getTenant()); - Context instanceUpdateContext = EventHandlingUtil.constructContext(targetInstanceTenantId, dataImportEventPayload.getToken(), dataImportEventPayload.getOkapiUrl(), payloadContext.get(EventHandlingUtil.USER_ID)); + Context instanceUpdateContext = EventHandlingUtil.constructContext(targetInstanceTenantId, dataImportEventPayload.getToken(), dataImportEventPayload.getOkapiUrl(), payloadContext.get(PAYLOAD_USER_ID)); InstanceCollection instanceCollection = storage.getInstanceCollection(instanceUpdateContext); InstanceUtil.findInstanceById(instanceToUpdate.getId(), instanceCollection) @@ -262,7 +264,7 @@ private Future copySnapshotToOtherTenant(String snapshotId, DataImport .withStatus(Snapshot.Status.COMMITTED) .withProcessingStartedDate(new Date()); - var context = EventHandlingUtil.constructContext(tenantId, dataImportEventPayload.getToken(), dataImportEventPayload.getOkapiUrl(), dataImportEventPayload.getContext().get(EventHandlingUtil.USER_ID)); + var context = EventHandlingUtil.constructContext(tenantId, dataImportEventPayload.getToken(), dataImportEventPayload.getOkapiUrl(), dataImportEventPayload.getContext().get(PAYLOAD_USER_ID)); return postSnapshotInSrsAndHandleResponse(context, snapshot); } diff --git a/src/main/java/org/folio/inventory/dataimport/handlers/actions/UpdateHoldingEventHandler.java b/src/main/java/org/folio/inventory/dataimport/handlers/actions/UpdateHoldingEventHandler.java index 5d9593578..f78c4a09c 100644 --- a/src/main/java/org/folio/inventory/dataimport/handlers/actions/UpdateHoldingEventHandler.java +++ b/src/main/java/org/folio/inventory/dataimport/handlers/actions/UpdateHoldingEventHandler.java @@ -19,7 +19,6 @@ import org.folio.inventory.common.api.request.PagingParameters; import org.folio.inventory.dataimport.cache.MappingMetadataCache; import org.folio.inventory.dataimport.entities.PartialError; -import org.folio.inventory.dataimport.handlers.matching.util.EventHandlingUtil; import org.folio.inventory.domain.HoldingsRecordCollection; import org.folio.inventory.dataimport.entities.OlHoldingsAccumulativeResults; import org.folio.inventory.domain.items.ItemCollection; @@ -47,6 +46,7 @@ import static org.folio.ActionProfile.FolioRecord.MARC_BIBLIOGRAPHIC; import static org.folio.DataImportEventTypes.DI_INVENTORY_HOLDING_UPDATED; import static org.folio.inventory.dataimport.handlers.actions.CreateItemEventHandler.getItemFromJson; +import static org.folio.inventory.dataimport.handlers.matching.util.EventHandlingUtil.PAYLOAD_USER_ID; import static org.folio.inventory.dataimport.handlers.matching.util.EventHandlingUtil.constructContext; import static org.folio.inventory.dataimport.util.LoggerUtil.INCOMING_RECORD_ID; import static org.folio.inventory.dataimport.util.LoggerUtil.logParametersEventHandler; @@ -114,7 +114,8 @@ public CompletableFuture handle(DataImportEventPayload d future.complete(dataImportEventPayload); return future; } - Context context = constructContext(dataImportEventPayload.getTenant(), dataImportEventPayload.getToken(), dataImportEventPayload.getOkapiUrl(), dataImportEventPayload.getContext().get(EventHandlingUtil.USER_ID)); + Context context = constructContext(dataImportEventPayload.getTenant(), dataImportEventPayload.getToken(), dataImportEventPayload.getOkapiUrl(), + dataImportEventPayload.getContext().get(PAYLOAD_USER_ID)); String jobExecutionId = dataImportEventPayload.getJobExecutionId(); String recordId = dataImportEventPayload.getContext().get(RECORD_ID_HEADER); String chunkId = dataImportEventPayload.getContext().get(CHUNK_ID_HEADER); diff --git a/src/main/java/org/folio/inventory/dataimport/handlers/actions/UpdateItemEventHandler.java b/src/main/java/org/folio/inventory/dataimport/handlers/actions/UpdateItemEventHandler.java index dee4bdf13..c21199c53 100644 --- a/src/main/java/org/folio/inventory/dataimport/handlers/actions/UpdateItemEventHandler.java +++ b/src/main/java/org/folio/inventory/dataimport/handlers/actions/UpdateItemEventHandler.java @@ -58,6 +58,7 @@ import static org.folio.ActionProfile.Action.UPDATE; import static org.folio.DataImportEventTypes.DI_INVENTORY_ITEM_UPDATED; import static org.folio.inventory.dataimport.handlers.actions.CreateItemEventHandler.getItemFromJson; +import static org.folio.inventory.dataimport.handlers.matching.util.EventHandlingUtil.PAYLOAD_USER_ID; import static org.folio.inventory.dataimport.util.LoggerUtil.INCOMING_RECORD_ID; import static org.folio.inventory.dataimport.util.LoggerUtil.logParametersEventHandler; import static org.folio.inventory.domain.items.Item.STATUS_KEY; @@ -131,7 +132,8 @@ public CompletableFuture handle(DataImportEventPayload d } LOGGER.info("handle:: Processing UpdateItemEventHandler starting with jobExecutionId: {}, incomingRecordId: {}.", dataImportEventPayload.getJobExecutionId(), dataImportEventPayload.getContext().get(INCOMING_RECORD_ID)); - Context context = EventHandlingUtil.constructContext(dataImportEventPayload.getTenant(), dataImportEventPayload.getToken(), dataImportEventPayload.getOkapiUrl(), payloadContext.get(EventHandlingUtil.USER_ID)); + Context context = EventHandlingUtil.constructContext(dataImportEventPayload.getTenant(), dataImportEventPayload.getToken(), dataImportEventPayload.getOkapiUrl(), + payloadContext.get(PAYLOAD_USER_ID)); String jobExecutionId = dataImportEventPayload.getJobExecutionId(); String recordId = dataImportEventPayload.getContext().get(RECORD_ID_HEADER); String chunkId = dataImportEventPayload.getContext().get(CHUNK_ID_HEADER); diff --git a/src/main/java/org/folio/inventory/dataimport/handlers/actions/UpdateMarcHoldingsEventHandler.java b/src/main/java/org/folio/inventory/dataimport/handlers/actions/UpdateMarcHoldingsEventHandler.java index e906a3044..ee637545f 100644 --- a/src/main/java/org/folio/inventory/dataimport/handlers/actions/UpdateMarcHoldingsEventHandler.java +++ b/src/main/java/org/folio/inventory/dataimport/handlers/actions/UpdateMarcHoldingsEventHandler.java @@ -9,6 +9,7 @@ import static org.folio.ActionProfile.FolioRecord.MARC_HOLDINGS; import static org.folio.DataImportEventTypes.DI_INVENTORY_HOLDINGS_UPDATED_READY_FOR_POST_PROCESSING; import static org.folio.DataImportEventTypes.DI_INVENTORY_HOLDING_UPDATED; +import static org.folio.inventory.dataimport.handlers.matching.util.EventHandlingUtil.PAYLOAD_USER_ID; import static org.folio.inventory.dataimport.handlers.matching.util.EventHandlingUtil.constructContext; import static org.folio.inventory.dataimport.util.LoggerUtil.INCOMING_RECORD_ID; import static org.folio.inventory.dataimport.util.LoggerUtil.logParametersEventHandler; @@ -42,7 +43,6 @@ import org.folio.inventory.common.domain.Failure; import org.folio.inventory.dataimport.cache.MappingMetadataCache; import org.folio.inventory.dataimport.exceptions.DataImportException; -import org.folio.inventory.dataimport.handlers.matching.util.EventHandlingUtil; import org.folio.inventory.domain.HoldingsRecordCollection; import org.folio.inventory.domain.instances.InstanceCollection; import org.folio.inventory.storage.Storage; @@ -104,7 +104,8 @@ public CompletableFuture handle(DataImportEventPayload p prepareEvent(payload); - var context = constructContext(payload.getTenant(), payload.getToken(), payload.getOkapiUrl(), payload.getContext().get(EventHandlingUtil.USER_ID)); + var context = constructContext(payload.getTenant(), payload.getToken(), payload.getOkapiUrl(), + payload.getContext().get(PAYLOAD_USER_ID)); var jobExecutionId = payload.getJobExecutionId(); LOGGER.info("Update marc holding with jobExecutionId: {}, incomingRecordId: {}", jobExecutionId, payload.getContext().get(INCOMING_RECORD_ID)); diff --git a/src/main/java/org/folio/inventory/dataimport/handlers/actions/modify/AbstractModifyEventHandler.java b/src/main/java/org/folio/inventory/dataimport/handlers/actions/modify/AbstractModifyEventHandler.java index e7de37795..efb51b248 100644 --- a/src/main/java/org/folio/inventory/dataimport/handlers/actions/modify/AbstractModifyEventHandler.java +++ b/src/main/java/org/folio/inventory/dataimport/handlers/actions/modify/AbstractModifyEventHandler.java @@ -17,7 +17,6 @@ import org.folio.inventory.dataimport.exceptions.OptimisticLockingException; import org.folio.inventory.dataimport.handlers.actions.InstanceUpdateDelegate; import org.folio.inventory.dataimport.handlers.actions.PrecedingSucceedingTitlesHelper; -import org.folio.inventory.dataimport.handlers.matching.util.EventHandlingUtil; import org.folio.inventory.dataimport.util.ParsedRecordUtil; import org.folio.inventory.domain.instances.Instance; import org.folio.processing.events.services.handler.EventHandler; @@ -43,7 +42,9 @@ import static org.apache.commons.lang3.StringUtils.isBlank; import static org.folio.ActionProfile.Action.MODIFY; import static org.folio.ActionProfile.FolioRecord.INSTANCE; +import static org.folio.inventory.dataimport.handlers.matching.util.EventHandlingUtil.constructContext; import static org.folio.inventory.dataimport.handlers.matching.util.EventHandlingUtil.getTenant; +import static org.folio.inventory.dataimport.handlers.matching.util.EventHandlingUtil.PAYLOAD_USER_ID; import static org.folio.inventory.dataimport.util.LoggerUtil.logParametersEventHandler; import static org.folio.rest.jaxrs.model.ProfileType.ACTION_PROFILE; @@ -80,14 +81,14 @@ public CompletableFuture handle(DataImportEventPayload p return CompletableFuture.failedFuture(new EventProcessingException(PAYLOAD_HAS_NO_DATA_MSG)); } LOGGER.info("handle:: Processing {} modifying starting with jobExecutionId: {}.", modifiedEntityType(), payload.getJobExecutionId()); - Context localTenantContext = EventHandlingUtil.constructContext(payload.getTenant(), payload.getToken(), payload.getOkapiUrl(), payloadContext.get(EventHandlingUtil.USER_ID)); + Context localTenantContext = constructContext(payload.getTenant(), payload.getToken(), payload.getOkapiUrl(), payloadContext.get(PAYLOAD_USER_ID)); mappingMetadataCache.get(payload.getJobExecutionId(), localTenantContext) .map(mapMappingMetaDataOrFail(format(MAPPING_PARAMETERS_NOT_FOUND_MSG, payload.getJobExecutionId()))) .compose(mappingMetadataDto -> modifyRecord(payload, getMappingParameters(mappingMetadataDto)).map(mappingMetadataDto)) .compose(mappingMetadataDto -> { if (payloadContext.containsKey(relatedEntityType().value())) { - Context targetInstanceContext = EventHandlingUtil.constructContext(getTenant(payload), payload.getToken(), payload.getOkapiUrl(), payloadContext.get(EventHandlingUtil.USER_ID)); + Context targetInstanceContext = constructContext(getTenant(payload), payload.getToken(), payload.getOkapiUrl(), payloadContext.get(PAYLOAD_USER_ID)); return updateRelatedEntity(payload, mappingMetadataDto, targetInstanceContext) .compose(v -> updateRecord(getRecord(payload.getContext()), targetInstanceContext)); } diff --git a/src/main/java/org/folio/inventory/dataimport/handlers/matching/AbstractMarcMatchEventHandler.java b/src/main/java/org/folio/inventory/dataimport/handlers/matching/AbstractMarcMatchEventHandler.java index d47436085..d8cb9ac31 100644 --- a/src/main/java/org/folio/inventory/dataimport/handlers/matching/AbstractMarcMatchEventHandler.java +++ b/src/main/java/org/folio/inventory/dataimport/handlers/matching/AbstractMarcMatchEventHandler.java @@ -45,6 +45,7 @@ import static java.lang.String.format; import static org.apache.http.HttpStatus.SC_OK; +import static org.folio.inventory.dataimport.handlers.matching.util.EventHandlingUtil.PAYLOAD_USER_ID; import static org.folio.processing.value.Value.ValueType.MISSING; import static org.folio.rest.jaxrs.model.Filter.*; import static org.folio.rest.jaxrs.model.MatchExpression.DataValueType.VALUE_FROM_RECORD; @@ -323,7 +324,8 @@ private void populatePayloadWithExternalIdentifiers(RecordsIdentifiersCollection private Future> matchCentralTenantIfNeededAndCombineWithLocalMatchedRecords(RecordMatchingDto recordMatchingDto, DataImportEventPayload payload, Optional localMatchedRecord) { - Context context = EventHandlingUtil.constructContext(payload.getTenant(), payload.getToken(), payload.getOkapiUrl(), payload.getContext().get(EventHandlingUtil.USER_ID)); + Context context = EventHandlingUtil.constructContext(payload.getTenant(), payload.getToken(), payload.getOkapiUrl(), + payload.getContext().get(PAYLOAD_USER_ID)); return consortiumService.getConsortiumConfiguration(context) .compose(consortiumConfigurationOptional -> { if (consortiumConfigurationOptional.isPresent() && !consortiumConfigurationOptional.get().getCentralTenantId().equals(payload.getTenant())) { diff --git a/src/main/java/org/folio/inventory/dataimport/handlers/matching/AbstractMatchEventHandler.java b/src/main/java/org/folio/inventory/dataimport/handlers/matching/AbstractMatchEventHandler.java index cd83682a8..869c96142 100644 --- a/src/main/java/org/folio/inventory/dataimport/handlers/matching/AbstractMatchEventHandler.java +++ b/src/main/java/org/folio/inventory/dataimport/handlers/matching/AbstractMatchEventHandler.java @@ -12,7 +12,6 @@ import org.folio.inventory.consortium.services.ConsortiumService; import org.folio.inventory.dataimport.cache.MappingMetadataCache; import org.folio.inventory.dataimport.handlers.matching.preloaders.PreloadingFields; -import org.folio.inventory.dataimport.handlers.matching.util.EventHandlingUtil; import org.folio.inventory.dataimport.handlers.matching.util.MatchingParametersRelations; import org.folio.processing.events.services.handler.EventHandler; import org.folio.processing.exceptions.EventProcessingException; @@ -26,6 +25,7 @@ import static org.folio.inventory.dataimport.handlers.matching.util.EventHandlingUtil.constructContext; import static org.folio.inventory.dataimport.handlers.matching.util.EventHandlingUtil.extractMatchProfile; +import static org.folio.inventory.dataimport.handlers.matching.util.EventHandlingUtil.PAYLOAD_USER_ID; import static org.folio.inventory.dataimport.util.LoggerUtil.logParametersEventHandler; import static org.folio.rest.jaxrs.model.ProfileType.MATCH_PROFILE; @@ -52,7 +52,7 @@ public CompletableFuture handle(DataImportEventPayload d dataImportEventPayload.getEventsChain().add(dataImportEventPayload.getEventType()); dataImportEventPayload.setEventType(getNotMatchedEventType()); Context context = constructContext(dataImportEventPayload.getTenant(), - dataImportEventPayload.getToken(), dataImportEventPayload.getOkapiUrl(), dataImportEventPayload.getContext().get(EventHandlingUtil.USER_ID)); + dataImportEventPayload.getToken(), dataImportEventPayload.getOkapiUrl(), dataImportEventPayload.getContext().get(PAYLOAD_USER_ID)); mappingMetadataCache.get(dataImportEventPayload.getJobExecutionId(), context) .toCompletionStage() diff --git a/src/main/java/org/folio/inventory/dataimport/handlers/matching/MarcBibliographicMatchEventHandler.java b/src/main/java/org/folio/inventory/dataimport/handlers/matching/MarcBibliographicMatchEventHandler.java index c88dc9d41..07e8d4664 100644 --- a/src/main/java/org/folio/inventory/dataimport/handlers/matching/MarcBibliographicMatchEventHandler.java +++ b/src/main/java/org/folio/inventory/dataimport/handlers/matching/MarcBibliographicMatchEventHandler.java @@ -28,6 +28,7 @@ import static org.folio.ActionProfile.FolioRecord.MARC_BIBLIOGRAPHIC; import static org.folio.DataImportEventTypes.DI_SRS_MARC_BIB_RECORD_MATCHED; import static org.folio.DataImportEventTypes.DI_SRS_MARC_BIB_RECORD_NOT_MATCHED; +import static org.folio.inventory.dataimport.handlers.matching.util.EventHandlingUtil.PAYLOAD_USER_ID; import static org.folio.inventory.dataimport.handlers.matching.util.EventHandlingUtil.getTenant; public class MarcBibliographicMatchEventHandler extends AbstractMarcMatchEventHandler { @@ -67,7 +68,8 @@ protected Future ensureRelatedEntities(List records, DataImportEve Record matchedRecord = records.get(0); String instanceId = ParsedRecordUtil.getAdditionalSubfieldValue(matchedRecord.getParsedRecord(), AdditionalSubfields.I); String matchedRecordTenantId = getTenant(eventPayload); - Context context = EventHandlingUtil.constructContext(matchedRecordTenantId, eventPayload.getToken(), eventPayload.getOkapiUrl(), eventPayload.getContext().get(EventHandlingUtil.USER_ID)); + Context context = EventHandlingUtil.constructContext(matchedRecordTenantId, eventPayload.getToken(), eventPayload.getOkapiUrl(), + eventPayload.getContext().get(PAYLOAD_USER_ID)); InstanceCollection instanceCollection = storage.getInstanceCollection(context); if (isBlank(instanceId)) { diff --git a/src/main/java/org/folio/inventory/dataimport/handlers/matching/util/EventHandlingUtil.java b/src/main/java/org/folio/inventory/dataimport/handlers/matching/util/EventHandlingUtil.java index 441536b89..1d82ffd7d 100644 --- a/src/main/java/org/folio/inventory/dataimport/handlers/matching/util/EventHandlingUtil.java +++ b/src/main/java/org/folio/inventory/dataimport/handlers/matching/util/EventHandlingUtil.java @@ -14,7 +14,9 @@ import java.util.Optional; public final class EventHandlingUtil { - public static final String USER_ID = "userId"; + public static final String PAYLOAD_USER_ID = "userId"; + public static final String OKAPI_USER_ID = "x-okapi-user-id"; + public static final String OKAPI_REQUEST_ID = "x-okapi-request-id"; private static final String CENTRAL_TENANT_ID = "CENTRAL_TENANT_ID"; private EventHandlingUtil() {}