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);
}
}
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);
}
}
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);
}
}
Aggregations