Search in sources :

Example 1 with EntityType

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;
}
Also used : EntityType(org.folio.rest.jaxrs.model.JournalRecord.EntityType) JsonArray(io.vertx.core.json.JsonArray) Json(io.vertx.core.json.Json) Date(java.util.Date) Autowired(org.springframework.beans.factory.annotation.Autowired) MARC_HOLDING(org.folio.rest.jaxrs.model.Record.RecordType.MARC_HOLDING) RecordsBatchResponse(org.folio.rest.jaxrs.model.RecordsBatchResponse) DI_EDIFACT_RECORD_CREATED(org.folio.rest.jaxrs.model.DataImportEventTypes.DI_EDIFACT_RECORD_CREATED) MARC_AUTHORITY(org.folio.rest.jaxrs.model.Record.RecordType.MARC_AUTHORITY) RecordType(org.folio.rest.jaxrs.model.Record.RecordType) DI_SRS_MARC_BIB_RECORD_CREATED(org.folio.rest.jaxrs.model.DataImportEventTypes.DI_SRS_MARC_BIB_RECORD_CREATED) Map(java.util.Map) Qualifier(org.springframework.beans.factory.annotation.Qualifier) MappingRuleCacheKey(org.folio.services.entity.MappingRuleCacheKey) DI_SRS_MARC_AUTHORITY_RECORD_CREATED(org.folio.rest.jaxrs.model.DataImportEventTypes.DI_SRS_MARC_AUTHORITY_RECORD_CREATED) JsonObject(io.vertx.core.json.JsonObject) EntityType(org.folio.rest.jaxrs.model.JournalRecord.EntityType) RecordsPublishingService(org.folio.services.RecordsPublishingService) Event(org.folio.rest.jaxrs.model.Event) JournalRecord(org.folio.rest.jaxrs.model.JournalRecord) Record(org.folio.rest.jaxrs.model.Record) Vertx(io.vertx.core.Vertx) COMPLETED(org.folio.rest.jaxrs.model.JournalRecord.ActionStatus.COMPLETED) AsyncRecordHandler(org.folio.kafka.AsyncRecordHandler) Future(io.vertx.core.Future) Collectors(java.util.stream.Collectors) OkapiConnectionParams(org.folio.dataimport.util.OkapiConnectionParams) MappingRuleCache(org.folio.services.MappingRuleCache) EDIFACT(org.folio.rest.jaxrs.model.Record.RecordType.EDIFACT) JsonArray(io.vertx.core.json.JsonArray) Component(org.springframework.stereotype.Component) List(java.util.List) MARC_BIB(org.folio.rest.jaxrs.model.Record.RecordType.MARC_BIB) Logger(org.apache.logging.log4j.Logger) JournalService(org.folio.services.journal.JournalService) ObjectUtils.allNotNull(org.apache.commons.lang3.ObjectUtils.allNotNull) KafkaConsumerRecord(io.vertx.kafka.client.consumer.KafkaConsumerRecord) DataImportEventTypes(org.folio.rest.jaxrs.model.DataImportEventTypes) ParsedRecordUtil(org.folio.services.util.ParsedRecordUtil) EventProcessedService(org.folio.services.EventProcessedService) Optional(java.util.Optional) DI_SRS_MARC_HOLDING_RECORD_CREATED(org.folio.rest.jaxrs.model.DataImportEventTypes.DI_SRS_MARC_HOLDING_RECORD_CREATED) KafkaHeader(io.vertx.kafka.client.producer.KafkaHeader) LogManager(org.apache.logging.log4j.LogManager) KafkaHeaderUtils(org.folio.kafka.KafkaHeaderUtils) CREATE(org.folio.rest.jaxrs.model.JournalRecord.ActionType.CREATE) JsonObject(io.vertx.core.json.JsonObject) JournalRecord(org.folio.rest.jaxrs.model.JournalRecord) Record(org.folio.rest.jaxrs.model.Record) KafkaConsumerRecord(io.vertx.kafka.client.consumer.KafkaConsumerRecord) JournalRecord(org.folio.rest.jaxrs.model.JournalRecord) Date(java.util.Date)

Aggregations

Future (io.vertx.core.Future)1 Vertx (io.vertx.core.Vertx)1 Json (io.vertx.core.json.Json)1 JsonArray (io.vertx.core.json.JsonArray)1 JsonObject (io.vertx.core.json.JsonObject)1 KafkaConsumerRecord (io.vertx.kafka.client.consumer.KafkaConsumerRecord)1 KafkaHeader (io.vertx.kafka.client.producer.KafkaHeader)1 Date (java.util.Date)1 List (java.util.List)1 Map (java.util.Map)1 Optional (java.util.Optional)1 Collectors (java.util.stream.Collectors)1 ObjectUtils.allNotNull (org.apache.commons.lang3.ObjectUtils.allNotNull)1 LogManager (org.apache.logging.log4j.LogManager)1 Logger (org.apache.logging.log4j.Logger)1 OkapiConnectionParams (org.folio.dataimport.util.OkapiConnectionParams)1 AsyncRecordHandler (org.folio.kafka.AsyncRecordHandler)1 KafkaHeaderUtils (org.folio.kafka.KafkaHeaderUtils)1 DataImportEventTypes (org.folio.rest.jaxrs.model.DataImportEventTypes)1 DI_EDIFACT_RECORD_CREATED (org.folio.rest.jaxrs.model.DataImportEventTypes.DI_EDIFACT_RECORD_CREATED)1