Search in sources :

Example 1 with JsonMappingException

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));
    }
}
Also used : Authority(org.folio.Authority) JsonMappingException(org.folio.inventory.validation.exceptions.JsonMappingException) JsonObject(io.vertx.core.json.JsonObject) JsonMappingException(org.folio.inventory.validation.exceptions.JsonMappingException) EventProcessingException(org.folio.processing.exceptions.EventProcessingException)

Example 2 with JsonMappingException

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);
    }
}
Also used : Holdings(org.folio.Holdings) JsonMappingException(org.folio.inventory.validation.exceptions.JsonMappingException) JsonObject(io.vertx.core.json.JsonObject) JsonMappingException(org.folio.inventory.validation.exceptions.JsonMappingException) DuplicateEventException(org.folio.kafka.exception.DuplicateEventException) EventProcessingException(org.folio.processing.exceptions.EventProcessingException) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 3 with JsonMappingException

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);
    }
}
Also used : JsonMappingException(org.folio.inventory.validation.exceptions.JsonMappingException) JsonObject(io.vertx.core.json.JsonObject) JsonMappingException(org.folio.inventory.validation.exceptions.JsonMappingException)

Aggregations

JsonObject (io.vertx.core.json.JsonObject)3 JsonMappingException (org.folio.inventory.validation.exceptions.JsonMappingException)3 EventProcessingException (org.folio.processing.exceptions.EventProcessingException)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 Authority (org.folio.Authority)1 Holdings (org.folio.Holdings)1 DuplicateEventException (org.folio.kafka.exception.DuplicateEventException)1