use of org.folio.inventory.validation.exceptions.JsonMappingException in project mod-inventory by folio-org.
the class AbstractAuthorityEventHandler method mapAuthority.
private Future<Authority> mapAuthority(DataImportEventPayload payload, MappingMetadataDto mappingMetadata) {
try {
var mappingRules = new JsonObject(mappingMetadata.getMappingRules());
var mappingParameters = Json.decodeValue(mappingMetadata.getMappingParams(), MappingParameters.class);
var parsedRecord = new JsonObject((String) new JsonObject(payload.getContext().get(sourceRecordType().value())).mapTo(Record.class).getParsedRecord().getContent());
RecordMapper<Authority> recordMapper = RecordMapperBuilder.buildMapper(sourceRecordType().value());
var authority = recordMapper.mapRecord(parsedRecord, mappingParameters, mappingRules);
authority.setSource(Authority.Source.MARC);
return Future.succeededFuture(authority);
} catch (Exception e) {
var message = format(MAPPING_FAILED_MSG_PATTERN, sourceRecordType(), targetRecordType());
LOGGER.error(constructMsg(message, payload), e);
return Future.failedFuture(new JsonMappingException(message, e));
}
}
use of org.folio.inventory.validation.exceptions.JsonMappingException in project mod-inventory by folio-org.
the class CreateMarcHoldingsEventHandler method defaultMapRecordToHoldings.
private void defaultMapRecordToHoldings(DataImportEventPayload dataImportEventPayload, MappingMetadataDto mappingMetadata) {
try {
HashMap<String, String> context = dataImportEventPayload.getContext();
var mappingRules = new JsonObject(mappingMetadata.getMappingRules());
var parsedRecord = new JsonObject((String) new JsonObject(context.get(MARC_HOLDINGS.value())).mapTo(Record.class).getParsedRecord().getContent());
var mappingParameters = Json.decodeValue(mappingMetadata.getMappingParams(), MappingParameters.class);
RecordMapper<Holdings> recordMapper = RecordMapperBuilder.buildMapper(MARC_FORMAT);
var holdings = recordMapper.mapRecord(parsedRecord, mappingParameters, mappingRules);
dataImportEventPayload.getContext().put(HOLDINGS.value(), Json.encode(new JsonObject().put(HOLDINGS_PATH, JsonObject.mapFrom(holdings))));
} catch (Exception e) {
LOGGER.error("Failed to map Record to Holdings", e);
throw new JsonMappingException("Error in default mapper.", e);
}
}
use of org.folio.inventory.validation.exceptions.JsonMappingException in project mod-inventory by folio-org.
the class AbstractInstanceEventHandler method defaultMapRecordToInstance.
protected org.folio.Instance defaultMapRecordToInstance(DataImportEventPayload dataImportEventPayload, JsonObject mappingRules, MappingParameters mappingParameters) {
try {
HashMap<String, String> context = dataImportEventPayload.getContext();
JsonObject parsedRecord = new JsonObject((String) new JsonObject(context.get(MARC_BIBLIOGRAPHIC.value())).mapTo(Record.class).getParsedRecord().getContent());
RecordMapper<org.folio.Instance> recordMapper = RecordMapperBuilder.buildMapper(MARC_BIB_RECORD_FORMAT);
var instance = recordMapper.mapRecord(parsedRecord, mappingParameters, mappingRules);
dataImportEventPayload.getContext().put(INSTANCE.value(), Json.encode(new JsonObject().put(INSTANCE_PATH, JsonObject.mapFrom(instance))));
return instance;
} catch (Exception e) {
LOGGER.error("Failed to map Record to Instance", e);
throw new JsonMappingException("Error in default mapper.", e);
}
}
Aggregations