Search in sources :

Example 1 with RecordMapper

use of org.folio.processing.mapping.defaultmapper.RecordMapper in project mod-inventory by folio-org.

the class HoldingsUpdateDelegate method handle.

public Future<HoldingsRecord> handle(Map<String, String> eventPayload, Record marcRecord, Context context) {
    try {
        JsonObject mappingRules = new JsonObject(eventPayload.get(MAPPING_RULES_KEY));
        MappingParameters mappingParameters = new JsonObject(eventPayload.get(MAPPING_PARAMS_KEY)).mapTo(MappingParameters.class);
        JsonObject parsedRecord = retrieveParsedContent(marcRecord.getParsedRecord());
        String holdingsId = marcRecord.getExternalIdsHolder().getHoldingsId();
        RecordMapper<Holdings> recordMapper = RecordMapperBuilder.buildMapper(MARC_FORMAT);
        var mappedHoldings = recordMapper.mapRecord(parsedRecord, mappingParameters, mappingRules);
        HoldingsRecordCollection holdingsRecordCollection = storage.getHoldingsRecordCollection(context);
        return getHoldingsRecordById(holdingsId, holdingsRecordCollection).onSuccess(existingHoldingsRecord -> fillVersion(existingHoldingsRecord, eventPayload)).compose(existingHoldingsRecord -> mergeRecords(existingHoldingsRecord, mappedHoldings)).compose(updatedHoldingsRecord -> updateHoldingsRecord(updatedHoldingsRecord, holdingsRecordCollection));
    } catch (Exception e) {
        LOGGER.error("Error updating inventory holdings", e);
        return Future.failedFuture(e);
    }
}
Also used : Context(org.folio.inventory.common.Context) Holdings(org.folio.Holdings) Record(org.folio.rest.jaxrs.model.Record) Promise(io.vertx.core.Promise) HttpStatus(org.apache.http.HttpStatus) Future(io.vertx.core.Future) HoldingsRecord(org.folio.HoldingsRecord) String.format(java.lang.String.format) RecordMapperBuilder(org.folio.processing.mapping.defaultmapper.RecordMapperBuilder) Storage(org.folio.inventory.storage.Storage) Logger(org.apache.logging.log4j.Logger) HoldingsRecordCollection(org.folio.inventory.domain.HoldingsRecordCollection) Map(java.util.Map) JsonObject(io.vertx.core.json.JsonObject) OptimisticLockingException(org.folio.inventory.dataimport.exceptions.OptimisticLockingException) LogManager(org.apache.logging.log4j.LogManager) ParsedRecord(org.folio.rest.jaxrs.model.ParsedRecord) RecordMapper(org.folio.processing.mapping.defaultmapper.RecordMapper) MappingParameters(org.folio.processing.mapping.defaultmapper.processor.parameters.MappingParameters) HoldingsRecordCollection(org.folio.inventory.domain.HoldingsRecordCollection) Holdings(org.folio.Holdings) JsonObject(io.vertx.core.json.JsonObject) MappingParameters(org.folio.processing.mapping.defaultmapper.processor.parameters.MappingParameters) OptimisticLockingException(org.folio.inventory.dataimport.exceptions.OptimisticLockingException)

Example 2 with RecordMapper

use of org.folio.processing.mapping.defaultmapper.RecordMapper in project mod-inventory by folio-org.

the class InstanceUpdateDelegate method handle.

public Future<Instance> handle(Map<String, String> eventPayload, Record marcRecord, Context context) {
    try {
        JsonObject mappingRules = new JsonObject(eventPayload.get(MAPPING_RULES_KEY));
        MappingParameters mappingParameters = new JsonObject(eventPayload.get(MAPPING_PARAMS_KEY)).mapTo(MappingParameters.class);
        JsonObject parsedRecord = retrieveParsedContent(marcRecord.getParsedRecord());
        String instanceId = marcRecord.getExternalIdsHolder().getInstanceId();
        RecordMapper<org.folio.Instance> recordMapper = RecordMapperBuilder.buildMapper(MARC_FORMAT);
        var mappedInstance = recordMapper.mapRecord(parsedRecord, mappingParameters, mappingRules);
        InstanceCollection instanceCollection = storage.getInstanceCollection(context);
        return getInstanceById(instanceId, instanceCollection).onSuccess(existingInstance -> fillVersion(existingInstance, eventPayload)).compose(existingInstance -> updateInstance(existingInstance, mappedInstance)).compose(updatedInstance -> updateInstanceInStorage(updatedInstance, instanceCollection));
    } catch (Exception e) {
        LOGGER.error("Error updating inventory instance", e);
        return Future.failedFuture(e);
    }
}
Also used : Context(org.folio.inventory.common.Context) Record(org.folio.rest.jaxrs.model.Record) Promise(io.vertx.core.Promise) HttpStatus(org.apache.http.HttpStatus) InstanceCollection(org.folio.inventory.domain.instances.InstanceCollection) InstanceUtil(org.folio.inventory.support.InstanceUtil) Future(io.vertx.core.Future) String.format(java.lang.String.format) RecordMapperBuilder(org.folio.processing.mapping.defaultmapper.RecordMapperBuilder) Storage(org.folio.inventory.storage.Storage) Logger(org.apache.logging.log4j.Logger) Map(java.util.Map) JsonObject(io.vertx.core.json.JsonObject) Instance(org.folio.inventory.domain.instances.Instance) OptimisticLockingException(org.folio.inventory.dataimport.exceptions.OptimisticLockingException) LogManager(org.apache.logging.log4j.LogManager) ParsedRecord(org.folio.rest.jaxrs.model.ParsedRecord) RecordMapper(org.folio.processing.mapping.defaultmapper.RecordMapper) MappingParameters(org.folio.processing.mapping.defaultmapper.processor.parameters.MappingParameters) Instance(org.folio.inventory.domain.instances.Instance) InstanceCollection(org.folio.inventory.domain.instances.InstanceCollection) JsonObject(io.vertx.core.json.JsonObject) MappingParameters(org.folio.processing.mapping.defaultmapper.processor.parameters.MappingParameters) OptimisticLockingException(org.folio.inventory.dataimport.exceptions.OptimisticLockingException)

Example 3 with RecordMapper

use of org.folio.processing.mapping.defaultmapper.RecordMapper in project mod-inventory by folio-org.

the class AuthorityUpdateDelegate method handle.

public Future<Authority> handle(Map<String, String> eventPayload, Record marcRecord, Context context) {
    try {
        JsonObject mappingRules = new JsonObject(eventPayload.get(MAPPING_RULES_KEY));
        MappingParameters mappingParameters = new JsonObject(eventPayload.get(MAPPING_PARAMS_KEY)).mapTo(MappingParameters.class);
        JsonObject parsedRecord = retrieveParsedContent(marcRecord.getParsedRecord());
        String authorityId = marcRecord.getExternalIdsHolder().getAuthorityId();
        RecordMapper<Authority> recordMapper = RecordMapperBuilder.buildMapper(MARC_FORMAT);
        var mappedAuthority = recordMapper.mapRecord(parsedRecord, mappingParameters, mappingRules);
        AuthorityRecordCollection authorityRecordCollection = storage.getAuthorityRecordCollection(context);
        return getAuthorityRecordById(authorityId, authorityRecordCollection).onSuccess(existingAuthorityRecord -> fillVersion(existingAuthorityRecord, eventPayload)).compose(existingAuthorityRecord -> mergeRecords(existingAuthorityRecord, mappedAuthority)).compose(updatedAuthorityRecord -> updateAuthorityRecord(updatedAuthorityRecord, authorityRecordCollection));
    } catch (Exception e) {
        LOGGER.error("Error updating Authority", e);
        return Future.failedFuture(e);
    }
}
Also used : Context(org.folio.inventory.common.Context) AuthorityRecordCollection(org.folio.inventory.domain.AuthorityRecordCollection) Record(org.folio.rest.jaxrs.model.Record) Promise(io.vertx.core.Promise) Future(io.vertx.core.Future) String.format(java.lang.String.format) RecordMapperBuilder(org.folio.processing.mapping.defaultmapper.RecordMapperBuilder) Storage(org.folio.inventory.storage.Storage) Logger(org.apache.logging.log4j.Logger) Authority(org.folio.Authority) Map(java.util.Map) JsonObject(io.vertx.core.json.JsonObject) DataImportException(org.folio.inventory.dataimport.exceptions.DataImportException) LogManager(org.apache.logging.log4j.LogManager) ParsedRecord(org.folio.rest.jaxrs.model.ParsedRecord) RecordMapper(org.folio.processing.mapping.defaultmapper.RecordMapper) MappingParameters(org.folio.processing.mapping.defaultmapper.processor.parameters.MappingParameters) Authority(org.folio.Authority) JsonObject(io.vertx.core.json.JsonObject) MappingParameters(org.folio.processing.mapping.defaultmapper.processor.parameters.MappingParameters) AuthorityRecordCollection(org.folio.inventory.domain.AuthorityRecordCollection) DataImportException(org.folio.inventory.dataimport.exceptions.DataImportException)

Aggregations

Future (io.vertx.core.Future)3 Promise (io.vertx.core.Promise)3 JsonObject (io.vertx.core.json.JsonObject)3 String.format (java.lang.String.format)3 Map (java.util.Map)3 LogManager (org.apache.logging.log4j.LogManager)3 Logger (org.apache.logging.log4j.Logger)3 Context (org.folio.inventory.common.Context)3 Storage (org.folio.inventory.storage.Storage)3 RecordMapper (org.folio.processing.mapping.defaultmapper.RecordMapper)3 RecordMapperBuilder (org.folio.processing.mapping.defaultmapper.RecordMapperBuilder)3 MappingParameters (org.folio.processing.mapping.defaultmapper.processor.parameters.MappingParameters)3 ParsedRecord (org.folio.rest.jaxrs.model.ParsedRecord)3 Record (org.folio.rest.jaxrs.model.Record)3 HttpStatus (org.apache.http.HttpStatus)2 OptimisticLockingException (org.folio.inventory.dataimport.exceptions.OptimisticLockingException)2 Authority (org.folio.Authority)1 Holdings (org.folio.Holdings)1 HoldingsRecord (org.folio.HoldingsRecord)1 DataImportException (org.folio.inventory.dataimport.exceptions.DataImportException)1