From 2c5a04638d92a68e6e95d649c25d46c693d47529 Mon Sep 17 00:00:00 2001 From: Maksat <144414992+Maksat-Galymzhan@users.noreply.github.com> Date: Fri, 5 Jan 2024 11:50:11 +0600 Subject: [PATCH] MODSOURMAN-1106 The status of Instance is '-' in the Import log after uploading file. The numbers of updated SRS and Instance are not displayed in the Summary table. (#837) MODSOURMAN-1106: Changed behaviour of marc bib update by adding entity id to marc bib during update event --- NEWS.md | 1 + .../folio/services/journal/JournalUtil.java | 15 ++++++++++- .../DataImportJournalConsumersVerticle.java | 2 ++ ...ate_get_job_execution_summary_function.sql | 2 +- .../create_get_job_log_entries_function.sql | 4 +-- ...ate_get_record_processing_log_function.sql | 2 +- .../MetadataProviderJobExecutionAPITest.java | 25 +++++++++++-------- 7 files changed, 36 insertions(+), 15 deletions(-) diff --git a/NEWS.md b/NEWS.md index 320aa5044..17d6c81ff 100644 --- a/NEWS.md +++ b/NEWS.md @@ -6,6 +6,7 @@ * [MODSOURMAN-1043](https://issues.folio.org/browse/MODSOURMAN-1043) Improper behavior in multiples for holdings when update action on match and create on non-match * [MODSOURMAN-1091](https://issues.folio.org/browse/MODSOURMAN-1091) The '1' number of Instance is displayed in cell in the row with the 'Updated' row header at the individual import job's log * [MODSOURMAN-1108](https://issues.folio.org/browse/MODSOURMAN-1108) MARC authority record is not created when use Job profile with match profile and action only on no-match branch +* [MODSOURMAN-1106](https://issues.folio.org/browse/MODSOURMAN-1106) The status of Instance is '-' in the Import log after uploading file. The numbers of updated SRS and Instance are not displayed in the Summary table. ## 2023-10-13 v3.7.0 * [MODSOURMAN-1045](https://issues.folio.org/browse/MODSOURMAN-1045) Allow create action with non-matches for instance without match profile diff --git a/mod-source-record-manager-server/src/main/java/org/folio/services/journal/JournalUtil.java b/mod-source-record-manager-server/src/main/java/org/folio/services/journal/JournalUtil.java index 0eac990bd..cd1522ee7 100644 --- a/mod-source-record-manager-server/src/main/java/org/folio/services/journal/JournalUtil.java +++ b/mod-source-record-manager-server/src/main/java/org/folio/services/journal/JournalUtil.java @@ -24,6 +24,8 @@ import static org.apache.commons.lang3.StringUtils.EMPTY; import static org.apache.commons.lang3.StringUtils.isEmpty; import static org.folio.rest.jaxrs.model.DataImportEventTypes.DI_ERROR; +import static org.folio.rest.jaxrs.model.DataImportEventTypes.DI_LOG_SRS_MARC_BIB_RECORD_UPDATED; +import static org.folio.rest.jaxrs.model.DataImportEventTypes.DI_SRS_MARC_BIB_RECORD_UPDATED; import static org.folio.rest.jaxrs.model.JournalRecord.EntityType.AUTHORITY; import static org.folio.rest.jaxrs.model.JournalRecord.EntityType.HOLDINGS; import static org.folio.rest.jaxrs.model.JournalRecord.EntityType.INSTANCE; @@ -114,7 +116,8 @@ record = new ObjectMapper().readValue(recordAsString, Record.class); } if (!isEmpty(entityAsString)) { - if (entityType == INSTANCE || entityType == PO_LINE || entityType == AUTHORITY) { + if (entityType == INSTANCE || entityType == PO_LINE || entityType == AUTHORITY || + (entityType == MARC_BIBLIOGRAPHIC && isMarcBibUpdateEventReceived(eventPayload))) { JsonObject entityJson = new JsonObject(entityAsString); journalRecord.setEntityId(entityJson.getString(ID_KEY)); if (entityType == INSTANCE || entityType == PO_LINE) { @@ -149,6 +152,16 @@ record = new ObjectMapper().readValue(recordAsString, Record.class); } } + private static boolean isMarcBibUpdateEventReceived(DataImportEventPayload eventPayload) { + if (DI_LOG_SRS_MARC_BIB_RECORD_UPDATED == DataImportEventTypes.fromValue(eventPayload.getEventType()) + || DI_SRS_MARC_BIB_RECORD_UPDATED == DataImportEventTypes.fromValue(eventPayload.getEventType())) { + return true; + } + return eventPayload.getEventsChain().stream() + .reduce((first, second) -> second) + .map(mp -> DI_SRS_MARC_BIB_RECORD_UPDATED == DataImportEventTypes.fromValue(mp)).orElse(false); + } + private static List processHoldings(JournalRecord.ActionType actionType, JournalRecord.EntityType entityType, JournalRecord.ActionStatus actionStatus, HashMap eventPayloadContext, Record record) { JsonArray multipleHoldings = getJsonArrayOfHoldings(eventPayloadContext.get(entityType.value())); diff --git a/mod-source-record-manager-server/src/main/java/org/folio/verticle/DataImportJournalConsumersVerticle.java b/mod-source-record-manager-server/src/main/java/org/folio/verticle/DataImportJournalConsumersVerticle.java index ed8112cb9..4a24cab79 100644 --- a/mod-source-record-manager-server/src/main/java/org/folio/verticle/DataImportJournalConsumersVerticle.java +++ b/mod-source-record-manager-server/src/main/java/org/folio/verticle/DataImportJournalConsumersVerticle.java @@ -23,6 +23,7 @@ import static org.folio.rest.jaxrs.model.DataImportEventTypes.DI_SRS_MARC_AUTHORITY_RECORD_CREATED; import static org.folio.rest.jaxrs.model.DataImportEventTypes.DI_SRS_MARC_AUTHORITY_RECORD_NOT_MATCHED; import static org.folio.rest.jaxrs.model.DataImportEventTypes.DI_SRS_MARC_BIB_RECORD_MODIFIED; +import static org.folio.rest.jaxrs.model.DataImportEventTypes.DI_SRS_MARC_BIB_RECORD_MODIFIED_READY_FOR_POST_PROCESSING; import static org.folio.rest.jaxrs.model.DataImportEventTypes.DI_SRS_MARC_BIB_RECORD_NOT_MATCHED; import static org.folio.rest.jaxrs.model.DataImportEventTypes.DI_SRS_MARC_HOLDINGS_RECORD_MATCHED; import static org.folio.rest.jaxrs.model.DataImportEventTypes.DI_SRS_MARC_HOLDINGS_RECORD_NOT_MATCHED; @@ -63,6 +64,7 @@ public List getEvents() { DI_INVENTORY_INSTANCE_CREATED.value(), DI_INVENTORY_INSTANCE_UPDATED.value(), DI_INVENTORY_INSTANCE_NOT_MATCHED.value(), + DI_SRS_MARC_BIB_RECORD_MODIFIED_READY_FOR_POST_PROCESSING.value(), DI_INVENTORY_HOLDING_CREATED.value(), DI_INVENTORY_HOLDING_UPDATED.value(), DI_INVENTORY_HOLDING_NOT_MATCHED.value(), diff --git a/mod-source-record-manager-server/src/main/resources/templates/db_scripts/create_get_job_execution_summary_function.sql b/mod-source-record-manager-server/src/main/resources/templates/db_scripts/create_get_job_execution_summary_function.sql index f19926708..3f9d30bc9 100644 --- a/mod-source-record-manager-server/src/main/resources/templates/db_scripts/create_get_job_execution_summary_function.sql +++ b/mod-source-record-manager-server/src/main/resources/templates/db_scripts/create_get_job_execution_summary_function.sql @@ -55,7 +55,7 @@ BEGIN INNER JOIN (SELECT entity_id as entity_id_max, entity_type as entity_type_max, action_status as action_status_max,(array_agg(id ORDER BY array_position(array['CREATE', 'UPDATE', 'MODIFY', 'NON_MATCH'], action_type)))[1] as id FROM journal_records WHERE journal_records.job_execution_id = job_id - GROUP BY id, entity_id, entity_type, action_status) AS actions + GROUP BY entity_id, entity_type, action_status) AS actions ON actions.id = journal_records.id INNER JOIN (SELECT (array_agg(action_type ORDER BY array_position(array['CREATE', 'UPDATE', 'MODIFY', 'NON_MATCH'], action_type)))[1] as action_type_max, source_id as source_id_max, entity_type as entity_type_max FROM journal_records diff --git a/mod-source-record-manager-server/src/main/resources/templates/db_scripts/create_get_job_log_entries_function.sql b/mod-source-record-manager-server/src/main/resources/templates/db_scripts/create_get_job_log_entries_function.sql index 7e4f04bb9..358fd4508 100644 --- a/mod-source-record-manager-server/src/main/resources/templates/db_scripts/create_get_job_log_entries_function.sql +++ b/mod-source-record-manager-server/src/main/resources/templates/db_scripts/create_get_job_log_entries_function.sql @@ -50,7 +50,7 @@ SELECT records_actions.job_execution_id, records_actions.source_id, records_acti CASE WHEN marc_errors_number != 0 OR marc_actions[array_length(marc_actions, 1)] = ''NON_MATCH'' THEN ''DISCARDED'' WHEN marc_actions[array_length(marc_actions, 1)] = ''CREATE'' THEN ''CREATED'' - WHEN marc_actions[array_length(marc_actions, 1)] IN (''UPDATE'', ''MODIFY'') THEN ''UPDATED'' + WHEN marc_actions[array_length(marc_actions, 1)] = ''UPDATE'' THEN ''UPDATED'' END AS source_record_action_status, get_entity_status(instance_actions, instance_errors_number) AS instance_action_status, get_entity_status(holdings_actions, holdings_errors_number) AS holdings_action_status, @@ -104,7 +104,7 @@ SELECT records_actions.job_execution_id, records_actions.source_id, source_recor CASE WHEN marc_errors_number != 0 OR marc_actions[array_length(marc_actions, 1)] = ''NON_MATCH'' THEN ''DISCARDED'' WHEN marc_actions[array_length(marc_actions, 1)] = ''CREATE'' THEN ''CREATED'' - WHEN marc_actions[array_length(marc_actions, 1)] IN (''UPDATE'', ''MODIFY'') THEN ''UPDATED'' + WHEN marc_actions[array_length(marc_actions, 1)] = ''UPDATE'' THEN ''UPDATED'' END AS source_record_action_status, null AS instance_action_status, null AS holdings_action_status, diff --git a/mod-source-record-manager-server/src/main/resources/templates/db_scripts/create_get_record_processing_log_function.sql b/mod-source-record-manager-server/src/main/resources/templates/db_scripts/create_get_record_processing_log_function.sql index bf4b8d7b3..630399856 100644 --- a/mod-source-record-manager-server/src/main/resources/templates/db_scripts/create_get_record_processing_log_function.sql +++ b/mod-source-record-manager-server/src/main/resources/templates/db_scripts/create_get_record_processing_log_function.sql @@ -10,7 +10,7 @@ BEGIN THEN 'DISCARDED' WHEN action_type = 'CREATE' THEN 'CREATED' - WHEN action_type IN ('UPDATE', 'MODIFY') + WHEN action_type = 'UPDATE' THEN 'UPDATED' END AS action_type, journal_records.action_status, journal_records.action_date, journal_records.source_record_order, journal_records.error, journal_records.title, journal_records.tenant_id, journal_records.instance_id, journal_records.holdings_id, journal_records.order_id, journal_records.permanent_location_id FROM journal_records diff --git a/mod-source-record-manager-server/src/test/java/org/folio/rest/impl/metadataProvider/MetadataProviderJobExecutionAPITest.java b/mod-source-record-manager-server/src/test/java/org/folio/rest/impl/metadataProvider/MetadataProviderJobExecutionAPITest.java index 18942bac7..c4ec92b7f 100644 --- a/mod-source-record-manager-server/src/test/java/org/folio/rest/impl/metadataProvider/MetadataProviderJobExecutionAPITest.java +++ b/mod-source-record-manager-server/src/test/java/org/folio/rest/impl/metadataProvider/MetadataProviderJobExecutionAPITest.java @@ -45,6 +45,7 @@ import java.util.List; import java.util.UUID; import java.util.stream.Collectors; +import java.util.stream.IntStream; import static com.github.tomakehurst.wiremock.client.WireMock.get; import static com.github.tomakehurst.wiremock.client.WireMock.okJson; @@ -1031,8 +1032,10 @@ public void shouldReturnUpdatedSourceRecordSummaryWhenRecordWasUpdated(TestConte Async async = context.async(); JobExecution createdJobExecution = constructAndPostInitJobExecutionRqDto(1).getJobExecutions().get(0); String sourceRecordId = UUID.randomUUID().toString(); + String recordTitle = "test title"; Future future = Future.succeededFuture() + .compose(v -> createJournalRecord(createdJobExecution.getId(), sourceRecordId, null, null, recordTitle, 0, CREATE, MARC_BIBLIOGRAPHIC, COMPLETED, null)) .compose(v -> createJournalRecord(createdJobExecution.getId(), sourceRecordId, null, null, null, 0, UPDATE, MARC_BIBLIOGRAPHIC, COMPLETED, null)) .onFailure(context::fail); @@ -1043,8 +1046,8 @@ public void shouldReturnUpdatedSourceRecordSummaryWhenRecordWasUpdated(TestConte .get(GET_JOB_EXECUTION_SUMMARY_PATH + "/" + createdJobExecution.getId()) .then() .statusCode(HttpStatus.SC_OK) - .body("sourceRecordSummary.totalCreatedEntities", is(0)) - .body("sourceRecordSummary.totalUpdatedEntities", is(1)) + .body("sourceRecordSummary.totalCreatedEntities", is(1)) + .body("sourceRecordSummary.totalUpdatedEntities", is(0)) .body("sourceRecordSummary.totalDiscardedEntities", is(0)) .body("sourceRecordSummary.totalErrors", is(0)) .body("totalErrors", is(0)); @@ -1057,16 +1060,18 @@ public void shouldReturnUpdatedSourceRecordSummaryWhenRecordWasUpdated(TestConte public void shouldReturnEightUpdatedSourceRecordSummaryWhenRecordWasUpdated(TestContext context) { Async async = context.async(); JobExecution createdJobExecution = constructAndPostInitJobExecutionRqDto(1).getJobExecutions().get(0); + List marcBibEntityIds = IntStream.range(0,8).mapToObj(i->UUID.randomUUID().toString()).toList(); + List marcBibSourceIds = IntStream.range(0,8).mapToObj(i->UUID.randomUUID().toString()).toList(); Future future = Future.succeededFuture() - .compose(v -> createJournalRecord(createdJobExecution.getId(), UUID.randomUUID().toString(), null, null, null, 0, UPDATE, MARC_BIBLIOGRAPHIC, COMPLETED, null)) - .compose(v -> createJournalRecord(createdJobExecution.getId(), UUID.randomUUID().toString(), null, null, null, 1, UPDATE, MARC_BIBLIOGRAPHIC, COMPLETED, null)) - .compose(v -> createJournalRecord(createdJobExecution.getId(), UUID.randomUUID().toString(), null, null, null, 2, UPDATE, MARC_BIBLIOGRAPHIC, COMPLETED, null)) - .compose(v -> createJournalRecord(createdJobExecution.getId(), UUID.randomUUID().toString(), null, null, null, 3, UPDATE, MARC_BIBLIOGRAPHIC, COMPLETED, null)) - .compose(v -> createJournalRecord(createdJobExecution.getId(), UUID.randomUUID().toString(), null, null, null, 4, UPDATE, MARC_BIBLIOGRAPHIC, COMPLETED, null)) - .compose(v -> createJournalRecord(createdJobExecution.getId(), UUID.randomUUID().toString(), null, null, null, 5, UPDATE, MARC_BIBLIOGRAPHIC, COMPLETED, null)) - .compose(v -> createJournalRecord(createdJobExecution.getId(), UUID.randomUUID().toString(), null, null, null, 6, UPDATE, MARC_BIBLIOGRAPHIC, COMPLETED, null)) - .compose(v -> createJournalRecord(createdJobExecution.getId(), UUID.randomUUID().toString(), null, null, null, 7, UPDATE, MARC_BIBLIOGRAPHIC, COMPLETED, null)) + .compose(v -> createJournalRecord(createdJobExecution.getId(), marcBibSourceIds.get(0), marcBibEntityIds.get(0), null, null, 0, UPDATE, MARC_BIBLIOGRAPHIC, COMPLETED, null)) + .compose(v -> createJournalRecord(createdJobExecution.getId(), marcBibSourceIds.get(1), marcBibEntityIds.get(1), null, null, 1, UPDATE, MARC_BIBLIOGRAPHIC, COMPLETED, null)) + .compose(v -> createJournalRecord(createdJobExecution.getId(), marcBibSourceIds.get(2), marcBibEntityIds.get(2), null, null, 2, UPDATE, MARC_BIBLIOGRAPHIC, COMPLETED, null)) + .compose(v -> createJournalRecord(createdJobExecution.getId(), marcBibSourceIds.get(3), marcBibEntityIds.get(3), null, null, 3, UPDATE, MARC_BIBLIOGRAPHIC, COMPLETED, null)) + .compose(v -> createJournalRecord(createdJobExecution.getId(), marcBibSourceIds.get(4), marcBibEntityIds.get(4), null, null, 4, UPDATE, MARC_BIBLIOGRAPHIC, COMPLETED, null)) + .compose(v -> createJournalRecord(createdJobExecution.getId(), marcBibSourceIds.get(5), marcBibEntityIds.get(5), null, null, 5, UPDATE, MARC_BIBLIOGRAPHIC, COMPLETED, null)) + .compose(v -> createJournalRecord(createdJobExecution.getId(), marcBibSourceIds.get(6), marcBibEntityIds.get(6), null, null, 6, UPDATE, MARC_BIBLIOGRAPHIC, COMPLETED, null)) + .compose(v -> createJournalRecord(createdJobExecution.getId(), marcBibSourceIds.get(7), marcBibEntityIds.get(7), null, null, 7, UPDATE, MARC_BIBLIOGRAPHIC, COMPLETED, null)) .onFailure(context::fail); future.onComplete(ar -> context.verify(v -> {