Skip to content

Commit

Permalink
MODSOURMAN-1082 fix log details not shown for errors occurred prior t…
Browse files Browse the repository at this point in the history
…o matching (#817)
  • Loading branch information
tatsiana-tarhonskaya authored Nov 1, 2023
1 parent 2c4cc4a commit f6f6410
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<JournalRecord> 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));
}
}
Expand Down Expand Up @@ -250,14 +254,15 @@ private static Map<String, String> initalizeHoldingsIdInstanceIdMap(HashMap<Stri
}

private static JournalRecord constructBlankJournalRecord(Record record, JournalRecord.EntityType entityType,
JournalRecord.ActionStatus actionStatus) {
JournalRecord.ActionStatus actionStatus, String error) {
return new JournalRecord()
.withJobExecutionId(record.getSnapshotId())
.withSourceId(record.getId())
.withSourceRecordOrder(record.getOrder())
.withEntityType(entityType)
.withActionType(JournalRecord.ActionType.NON_MATCH)
.withActionDate(new Date())
.withActionStatus(actionStatus);
.withActionStatus(actionStatus)
.withError(error);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import java.util.UUID;

import static org.folio.DataImportEventTypes.DI_ERROR;
import static org.folio.DataImportEventTypes.DI_SRS_MARC_AUTHORITY_RECORD_MODIFIED_READY_FOR_POST_PROCESSING;
import static org.folio.DataImportEventTypes.DI_SRS_MARC_BIB_RECORD_UPDATED;
import static org.folio.rest.jaxrs.model.JournalRecord.ActionStatus.COMPLETED;
import static org.folio.rest.jaxrs.model.JournalRecord.ActionStatus.ERROR;
Expand Down Expand Up @@ -886,4 +885,39 @@ public void shouldBuildJournalRecordWithCentralTenantIdFromPayload() throws Jour
Assert.assertEquals(COMPLETED, journalRecords.get(0).getActionStatus());
}

@Test
public void shouldBuildJournalRecordForNonMatchWithErrorAndMatchedNumberNotAvailable() throws JournalRecordMapperException {
String recordId = UUID.randomUUID().toString();
String snapshotId = UUID.randomUUID().toString();
String expectedErrorMessage = "matching error message";

JsonObject recordJson = new JsonObject()
.put("id", recordId)
.put("snapshotId", snapshotId)
.put("order", 1);

HashMap<String, String> 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<JournalRecord> 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());
}
}

0 comments on commit f6f6410

Please sign in to comment.