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 7ebbc4b17..0eac990bd 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 @@ -99,10 +99,14 @@ record = new ObjectMapper().readValue(recordAsString, Record.class); if ((actionType == JournalRecord.ActionType.MATCH || actionType == JournalRecord.ActionType.NON_MATCH) && (entityType == HOLDINGS || entityType == ITEM)) { List resultedJournalRecords = new ArrayList<>(); - if (isNotBlank(eventPayloadContext.get(NOT_MATCHED_NUMBER))) { - int notMatchedNumber = Integer.parseInt(eventPayloadContext.get(NOT_MATCHED_NUMBER)); + + String notMatchedNumberField = eventPayloadContext.get(NOT_MATCHED_NUMBER); + boolean isNotMatchedNumberPresent = isNotBlank(notMatchedNumberField); + + if (isNotMatchedNumberPresent || actionType == JournalRecord.ActionType.NON_MATCH) { + int notMatchedNumber = isNotMatchedNumberPresent ? Integer.parseInt(notMatchedNumberField) : 1; for (int i = 0; i < notMatchedNumber; i++) { - resultedJournalRecords.add(constructBlankJournalRecord(record, entityType, actionStatus) + resultedJournalRecords.add(constructBlankJournalRecord(record, entityType, actionStatus, journalRecord.getError()) .withEntityType(entityType)); } } @@ -250,7 +254,7 @@ private static Map initalizeHoldingsIdInstanceIdMap(HashMap context = new HashMap<>(); + context.put(MARC_BIBLIOGRAPHIC.value(), recordJson.encode()); + context.put(ERROR_KEY, expectedErrorMessage); + + DataImportEventPayload eventPayload = new DataImportEventPayload() + .withEventType("DI_ERROR") + .withContext(context); + + List journalRecords = JournalUtil.buildJournalRecordsByEvent(eventPayload, + NON_MATCH, ITEM, ERROR); + + Assert.assertNotNull(journalRecords); + Assert.assertEquals(1, journalRecords.size()); + + JournalRecord journalRecord = journalRecords.get(0); + Assert.assertEquals(snapshotId, journalRecord.getJobExecutionId()); + Assert.assertEquals(recordId, journalRecord.getSourceId()); + Assert.assertEquals(1, journalRecord.getSourceRecordOrder().intValue()); + Assert.assertEquals(ITEM, journalRecord.getEntityType()); + Assert.assertEquals(NON_MATCH, journalRecord.getActionType()); + Assert.assertEquals(ERROR, journalRecord.getActionStatus()); + Assert.assertEquals(expectedErrorMessage, journalRecord.getError()); + Assert.assertNotNull(journalRecord.getActionDate()); + } }