Skip to content

Commit

Permalink
MODSOURMAN-1106 The status of Instance is '-' in the Import log after…
Browse files Browse the repository at this point in the history
… 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
  • Loading branch information
Maksat-Galymzhan authored Jan 5, 2024
1 parent cf38646 commit 2c5a046
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 15 deletions.
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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<JournalRecord> processHoldings(JournalRecord.ActionType actionType, JournalRecord.EntityType entityType,
JournalRecord.ActionStatus actionStatus, HashMap<String, String> eventPayloadContext, Record record) {
JsonArray multipleHoldings = getJsonArrayOfHoldings(eventPayloadContext.get(entityType.value()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -63,6 +64,7 @@ public List<String> 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(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<JournalRecord> 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);

Expand All @@ -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));
Expand All @@ -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<String> marcBibEntityIds = IntStream.range(0,8).mapToObj(i->UUID.randomUUID().toString()).toList();
List<String> marcBibSourceIds = IntStream.range(0,8).mapToObj(i->UUID.randomUUID().toString()).toList();

Future<JournalRecord> 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 -> {
Expand Down

0 comments on commit 2c5a046

Please sign in to comment.