use of org.folio.rest.jaxrs.model.JournalRecord in project mod-source-record-manager by folio-org.
the class StoredRecordChunksKafkaHandler method buildJournalRecords.
private JsonArray buildJournalRecords(List<Record> storedRecords, Optional<JsonObject> mappingRulesOptional, String tenantId) {
EntityType entityType = getEntityType(storedRecords);
JsonArray journalRecords = new JsonArray();
String titleFieldTag = null;
List<String> subfieldCodes = null;
if (mappingRulesOptional.isPresent()) {
JsonObject mappingRules = mappingRulesOptional.get();
Optional<String> titleFieldOptional = getTitleFieldTagByInstanceFieldPath(mappingRules);
if (titleFieldOptional.isPresent()) {
titleFieldTag = titleFieldOptional.get();
subfieldCodes = mappingRules.getJsonArray(titleFieldTag).stream().map(JsonObject.class::cast).filter(fieldMappingRule -> fieldMappingRule.getString("target").equals(INSTANCE_TITLE_FIELD_PATH)).flatMap(fieldMappingRule -> fieldMappingRule.getJsonArray("subfield").stream()).map(subfieldCode -> subfieldCode.toString()).collect(Collectors.toList());
}
}
for (Record record : storedRecords) {
JournalRecord journalRecord = new JournalRecord().withJobExecutionId(record.getSnapshotId()).withSourceRecordOrder(record.getOrder()).withSourceId(record.getId()).withEntityType(entityType).withEntityId(record.getId()).withActionType(CREATE).withActionStatus(COMPLETED).withActionDate(new Date()).withTitle(allNotNull(record.getParsedRecord(), titleFieldTag) ? ParsedRecordUtil.retrieveDataByField(record.getParsedRecord(), titleFieldTag, subfieldCodes) : null);
journalRecords.add(JsonObject.mapFrom(journalRecord));
}
return journalRecords;
}
use of org.folio.rest.jaxrs.model.JournalRecord in project mod-source-record-manager by folio-org.
the class InvoiceImportEventHandler method handle.
@Override
public void handle(JournalService journalService, DataImportEventPayload eventPayload, String tenantId) throws JournalRecordMapperException, JsonProcessingException {
List<JournalRecord> journalRecords = InvoiceUtil.buildJournalRecordByEvent(eventPayload);
List<JsonObject> jsonObjects = new ArrayList<>();
journalRecords.forEach(journalRecord -> jsonObjects.add(JsonObject.mapFrom(journalRecord)));
journalService.saveBatch(new JsonArray(jsonObjects), tenantId);
}
use of org.folio.rest.jaxrs.model.JournalRecord in project mod-source-record-manager by folio-org.
the class InvoiceUtil method buildInvoiceLineRecords.
private static LinkedList<JournalRecord> buildInvoiceLineRecords(DataImportEventPayload eventPayload, String invoiceNo, Integer invoiceOrder, String sourceId, boolean isInvoiceIncorrect) throws JournalRecordMapperException, JsonProcessingException {
HashMap<String, String> errorInvoiceLinesMap = initErrorInvoiceLinesMap(eventPayload);
LinkedList<JournalRecord> invoiceLines = new LinkedList<>();
try {
String recordAsString = eventPayload.getContext().get(INVOICE_LINES_KEY);
JsonObject jsonInvoiceLineCollection = new JsonObject(recordAsString);
int sz = jsonInvoiceLineCollection.getJsonArray(FIELD_INVOICE_LINES).size();
for (int i = 0; i < sz; i++) {
JsonObject invoiceLine = jsonInvoiceLineCollection.getJsonArray(FIELD_INVOICE_LINES).getJsonObject(i);
String invoiceLineNumber = getInvoiceLinesNumber(invoiceLine, i);
String description = invoiceLine.getString(FIELD_DESCRIPTION);
JournalRecord journalRecord = new JournalRecord().withJobExecutionId(eventPayload.getJobExecutionId()).withSourceId(sourceId).withEntityId(invoiceLine.getString(FIELD_ID)).withEntityHrId(invoiceNo + "-" + invoiceLineNumber).withSourceRecordOrder((invoiceOrder + 1) * 10 + Integer.parseInt(invoiceLineNumber)).withEntityType(INVOICE).withTitle(StringUtils.isNotBlank(description) ? description : NO_INVOICE_TITLE_MESSAGE).withActionType(ActionType.CREATE).withActionDate(new Date()).withActionStatus(isInvoiceIncorrect || (errorInvoiceLinesMap.containsKey(invoiceLineNumber)) ? ActionStatus.ERROR : ActionStatus.COMPLETED).withError(isInvoiceIncorrect ? eventPayload.getContext().get(ERROR_KEY) : errorInvoiceLinesMap.getOrDefault(invoiceLineNumber, ""));
invoiceLines.add(journalRecord);
}
return invoiceLines;
} catch (Exception e) {
throw new JournalRecordMapperException(INVOICE_LINE_MAPPING_EXCEPTION_MSG, e);
}
}
use of org.folio.rest.jaxrs.model.JournalRecord in project mod-source-record-manager by folio-org.
the class JournalUtilTest method shouldBuildJournalRecordForItemWhenInstanceIsPopulated.
@Test
public void shouldBuildJournalRecordForItemWhenInstanceIsPopulated() throws JournalRecordMapperException {
String itemId = UUID.randomUUID().toString();
String itemHrid = UUID.randomUUID().toString();
String instanceId = UUID.randomUUID().toString();
String instanceHrid = UUID.randomUUID().toString();
String holdingsId = UUID.randomUUID().toString();
JsonObject itemJson = new JsonObject().put("id", itemId).put("hrid", itemHrid).put("holdingsRecordId", holdingsId);
JsonObject instanceJson = new JsonObject().put("id", instanceId).put("hrid", instanceHrid);
String recordId = UUID.randomUUID().toString();
String snapshotId = UUID.randomUUID().toString();
JsonObject recordJson = new JsonObject().put("id", recordId).put("snapshotId", snapshotId).put("order", 1);
HashMap<String, String> context = new HashMap<>();
context.put(ITEM.value(), itemJson.encode());
context.put(INSTANCE.value(), instanceJson.encode());
context.put(MARC_BIBLIOGRAPHIC.value(), recordJson.encode());
DataImportEventPayload eventPayload = new DataImportEventPayload().withEventType("DI_INVENTORY_ITEM_CREATED").withContext(context);
JournalRecord journalRecord = JournalUtil.buildJournalRecordByEvent(eventPayload, CREATE, ITEM, COMPLETED);
Assert.assertNotNull(journalRecord);
Assert.assertEquals(snapshotId, journalRecord.getJobExecutionId());
Assert.assertEquals(recordId, journalRecord.getSourceId());
Assert.assertEquals(1, journalRecord.getSourceRecordOrder().intValue());
Assert.assertEquals(ITEM, journalRecord.getEntityType());
Assert.assertEquals(itemId, journalRecord.getEntityId());
Assert.assertEquals(itemHrid, journalRecord.getEntityHrId());
Assert.assertEquals(instanceId, journalRecord.getInstanceId());
Assert.assertEquals(holdingsId, journalRecord.getHoldingsId());
Assert.assertEquals(CREATE, journalRecord.getActionType());
Assert.assertEquals(COMPLETED, journalRecord.getActionStatus());
Assert.assertNotNull(journalRecord.getActionDate());
}
use of org.folio.rest.jaxrs.model.JournalRecord in project mod-source-record-manager by folio-org.
the class MetaDataProviderJobLogEntriesAPITest method shouldReturnAuthorityCreated.
@Test
public void shouldReturnAuthorityCreated(TestContext context) {
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_AUTHORITY, COMPLETED, null)).compose(v -> createJournalRecord(createdJobExecution.getId(), sourceRecordId, null, null, null, 0, CREATE, AUTHORITY, COMPLETED, null)).onFailure(context::fail);
future.onComplete(ar -> context.verify(v -> {
RestAssured.given().spec(spec).when().get(GET_JOB_EXECUTION_JOURNAL_RECORDS_PATH + "/" + createdJobExecution.getId()).then().statusCode(HttpStatus.SC_OK).body("entries.size()", is(1)).body("totalRecords", is(1)).body("entries[0].sourceRecordId", is(sourceRecordId)).body("entries[0].sourceRecordTitle", is(recordTitle)).body("entries[0].sourceRecordActionStatus", is(ActionStatus.CREATED.value())).body("entries[0].authorityActionStatus", is(ActionStatus.CREATED.value()));
async.complete();
}));
}
Aggregations