use of org.folio.rest.jaxrs.model.JournalRecord.EntityType 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;
}
Aggregations