@Test public void should_map_json_unit_to_xml_with_originating_agency_organization_description_metadata() throws InvalidParseOperationException { ArchiveUnitMapper archiveUnitMapper = new ArchiveUnitMapper(); UnitDipServiceImpl unitDipService = new UnitDipServiceImpl(archiveUnitMapper, buildObjectMapper()); InputStream inputStream = getClass().getResourceAsStream( "/unit_originating_agency_with_organization_descriptive_metadata.json"); JsonNode jsonNode = JsonHandler.getFromInputStream(inputStream); Map<String, String> prefix2Uri = new HashMap<>(); prefix2Uri.put("vitam", "fr:gouv:culture:archivesdefrance:seda:v2.1"); Response response = unitDipService.jsonToXml(jsonNode, ""); String entity = (String) response.getEntity(); assertThat(fromString(entity), hasXPath(" equalTo("RATP")).withNamespaceContext(prefix2Uri)); assertThat(fromString(entity), hasXPath(" equalTo("description libre YYYY")).withNamespaceContext(prefix2Uri)); assertThat(fromString(entity), hasXPath(" equalTo("La RATP est un etablissement public")).withNamespaceContext(prefix2Uri)); }
@Override public Response jsonToXml(JsonNode object, String id) { Status status; StringWriter writer = new StringWriter(); try { if (object != null) { ArchiveUnitModel archiveUnitModel = objectMapper.treeToValue(object, ArchiveUnitModel.class); Marshaller marshaller = jaxbContext.createMarshaller(); final ArchiveUnitType xmlUnit = archiveUnitMapper.map(archiveUnitModel); marshaller.marshal(xmlUnit, writer); LOGGER.debug(END_OF_EXECUTION_OF_DSL_VITAM_FROM_ACCESS); return Response.status(Status.OK).entity(writer.toString()).build(); } else { return Response.status(Status.BAD_REQUEST.getStatusCode()) .entity(JsonHandler.unprettyPrint( new VitamError(VitamCode.ACCESS_EXTERNAL_SELECT_UNIT_BY_ID_ERROR.getItem()) .setHttpCode(Status.BAD_REQUEST.getStatusCode()) .setMessage(VitamCode.ACCESS_EXTERNAL_SELECT_UNIT_BY_ID_ERROR.getMessage()) .setState(StatusCode.KO.name()) .setContext(ACCESS_EXTERNAL_MODULE) .setDescription(VitamCode.ACCESS_EXTERNAL_SELECT_UNIT_BY_ID_ERROR.getMessage()))) .build(); } } catch (JsonProcessingException e) { LOGGER.error(BAD_REQUEST_EXCEPTION, e); status = Status.BAD_REQUEST; return Response.status(status).entity(JsonHandler.unprettyPrint(getErrorEntity(status, e.getMessage()))) .build(); } catch (JAXBException e) { LOGGER.error(BAD_REQUEST_EXCEPTION, e); status = Status.BAD_REQUEST; return Response.status(status).entity(JsonHandler.unprettyPrint(getErrorEntity(status, e.getMessage()))) .build(); } catch (DatatypeConfigurationException e) { LOGGER.error(BAD_REQUEST_EXCEPTION, e); status = Status.BAD_REQUEST; return Response.status(status).entity(JsonHandler.unprettyPrint(getErrorEntity(status, e.getMessage()))) .build(); } catch (NullPointerException e) { LOGGER.error(BAD_REQUEST_EXCEPTION, e); status = Status.BAD_REQUEST; return Response.status(status).entity(JsonHandler.unprettyPrint(getErrorEntity(status, e.getMessage()))) .build(); } catch (Exception e) { status = Status.BAD_REQUEST; return Response.status(status) .entity(JsonHandler.unprettyPrint(getErrorEntity(status, e.getMessage()))) .build(); } }
UnitDipServiceImpl implements DipService { @Override public Response jsonToXml(JsonNode object, String id) { Status status; StringWriter writer = new StringWriter(); try { if (object != null) { ArchiveUnitModel archiveUnitModel = objectMapper.treeToValue(object, ArchiveUnitModel.class); Marshaller marshaller = jaxbContext.createMarshaller(); final ArchiveUnitType xmlUnit = archiveUnitMapper.map(archiveUnitModel); marshaller.marshal(xmlUnit, writer); LOGGER.debug(END_OF_EXECUTION_OF_DSL_VITAM_FROM_ACCESS); return Response.status(Status.OK).entity(writer.toString()).build(); } else { return Response.status(Status.BAD_REQUEST.getStatusCode()) .entity(JsonHandler.unprettyPrint( new VitamError(VitamCode.ACCESS_EXTERNAL_SELECT_UNIT_BY_ID_ERROR.getItem()) .setHttpCode(Status.BAD_REQUEST.getStatusCode()) .setMessage(VitamCode.ACCESS_EXTERNAL_SELECT_UNIT_BY_ID_ERROR.getMessage()) .setState(StatusCode.KO.name()) .setContext(ACCESS_EXTERNAL_MODULE) .setDescription(VitamCode.ACCESS_EXTERNAL_SELECT_UNIT_BY_ID_ERROR.getMessage()))) .build(); } } catch (JsonProcessingException e) { LOGGER.error(BAD_REQUEST_EXCEPTION, e); status = Status.BAD_REQUEST; return Response.status(status).entity(JsonHandler.unprettyPrint(getErrorEntity(status, e.getMessage()))) .build(); } catch (JAXBException e) { LOGGER.error(BAD_REQUEST_EXCEPTION, e); status = Status.BAD_REQUEST; return Response.status(status).entity(JsonHandler.unprettyPrint(getErrorEntity(status, e.getMessage()))) .build(); } catch (DatatypeConfigurationException e) { LOGGER.error(BAD_REQUEST_EXCEPTION, e); status = Status.BAD_REQUEST; return Response.status(status).entity(JsonHandler.unprettyPrint(getErrorEntity(status, e.getMessage()))) .build(); } catch (NullPointerException e) { LOGGER.error(BAD_REQUEST_EXCEPTION, e); status = Status.BAD_REQUEST; return Response.status(status).entity(JsonHandler.unprettyPrint(getErrorEntity(status, e.getMessage()))) .build(); } catch (Exception e) { status = Status.BAD_REQUEST; return Response.status(status) .entity(JsonHandler.unprettyPrint(getErrorEntity(status, e.getMessage()))) .build(); } } }
UnitDipServiceImpl implements DipService { @Override public Response jsonToXml(JsonNode object, String id) { Status status; StringWriter writer = new StringWriter(); try { if (object != null) { ArchiveUnitModel archiveUnitModel = objectMapper.treeToValue(object, ArchiveUnitModel.class); Marshaller marshaller = jaxbContext.createMarshaller(); final ArchiveUnitType xmlUnit = archiveUnitMapper.map(archiveUnitModel); marshaller.marshal(xmlUnit, writer); LOGGER.debug(END_OF_EXECUTION_OF_DSL_VITAM_FROM_ACCESS); return Response.status(Status.OK).entity(writer.toString()).build(); } else { return Response.status(Status.BAD_REQUEST.getStatusCode()) .entity(JsonHandler.unprettyPrint( new VitamError(VitamCode.ACCESS_EXTERNAL_SELECT_UNIT_BY_ID_ERROR.getItem()) .setHttpCode(Status.BAD_REQUEST.getStatusCode()) .setMessage(VitamCode.ACCESS_EXTERNAL_SELECT_UNIT_BY_ID_ERROR.getMessage()) .setState(StatusCode.KO.name()) .setContext(ACCESS_EXTERNAL_MODULE) .setDescription(VitamCode.ACCESS_EXTERNAL_SELECT_UNIT_BY_ID_ERROR.getMessage()))) .build(); } } catch (JsonProcessingException e) { LOGGER.error(BAD_REQUEST_EXCEPTION, e); status = Status.BAD_REQUEST; return Response.status(status).entity(JsonHandler.unprettyPrint(getErrorEntity(status, e.getMessage()))) .build(); } catch (JAXBException e) { LOGGER.error(BAD_REQUEST_EXCEPTION, e); status = Status.BAD_REQUEST; return Response.status(status).entity(JsonHandler.unprettyPrint(getErrorEntity(status, e.getMessage()))) .build(); } catch (DatatypeConfigurationException e) { LOGGER.error(BAD_REQUEST_EXCEPTION, e); status = Status.BAD_REQUEST; return Response.status(status).entity(JsonHandler.unprettyPrint(getErrorEntity(status, e.getMessage()))) .build(); } catch (NullPointerException e) { LOGGER.error(BAD_REQUEST_EXCEPTION, e); status = Status.BAD_REQUEST; return Response.status(status).entity(JsonHandler.unprettyPrint(getErrorEntity(status, e.getMessage()))) .build(); } catch (Exception e) { status = Status.BAD_REQUEST; return Response.status(status) .entity(JsonHandler.unprettyPrint(getErrorEntity(status, e.getMessage()))) .build(); } } UnitDipServiceImpl(ArchiveUnitMapper archiveUnitMapper, ObjectMapper objectMapper); }
UnitDipServiceImpl implements DipService { @Override public Response jsonToXml(JsonNode object, String id) { Status status; StringWriter writer = new StringWriter(); try { if (object != null) { ArchiveUnitModel archiveUnitModel = objectMapper.treeToValue(object, ArchiveUnitModel.class); Marshaller marshaller = jaxbContext.createMarshaller(); final ArchiveUnitType xmlUnit = archiveUnitMapper.map(archiveUnitModel); marshaller.marshal(xmlUnit, writer); LOGGER.debug(END_OF_EXECUTION_OF_DSL_VITAM_FROM_ACCESS); return Response.status(Status.OK).entity(writer.toString()).build(); } else { return Response.status(Status.BAD_REQUEST.getStatusCode()) .entity(JsonHandler.unprettyPrint( new VitamError(VitamCode.ACCESS_EXTERNAL_SELECT_UNIT_BY_ID_ERROR.getItem()) .setHttpCode(Status.BAD_REQUEST.getStatusCode()) .setMessage(VitamCode.ACCESS_EXTERNAL_SELECT_UNIT_BY_ID_ERROR.getMessage()) .setState(StatusCode.KO.name()) .setContext(ACCESS_EXTERNAL_MODULE) .setDescription(VitamCode.ACCESS_EXTERNAL_SELECT_UNIT_BY_ID_ERROR.getMessage()))) .build(); } } catch (JsonProcessingException e) { LOGGER.error(BAD_REQUEST_EXCEPTION, e); status = Status.BAD_REQUEST; return Response.status(status).entity(JsonHandler.unprettyPrint(getErrorEntity(status, e.getMessage()))) .build(); } catch (JAXBException e) { LOGGER.error(BAD_REQUEST_EXCEPTION, e); status = Status.BAD_REQUEST; return Response.status(status).entity(JsonHandler.unprettyPrint(getErrorEntity(status, e.getMessage()))) .build(); } catch (DatatypeConfigurationException e) { LOGGER.error(BAD_REQUEST_EXCEPTION, e); status = Status.BAD_REQUEST; return Response.status(status).entity(JsonHandler.unprettyPrint(getErrorEntity(status, e.getMessage()))) .build(); } catch (NullPointerException e) { LOGGER.error(BAD_REQUEST_EXCEPTION, e); status = Status.BAD_REQUEST; return Response.status(status).entity(JsonHandler.unprettyPrint(getErrorEntity(status, e.getMessage()))) .build(); } catch (Exception e) { status = Status.BAD_REQUEST; return Response.status(status) .entity(JsonHandler.unprettyPrint(getErrorEntity(status, e.getMessage()))) .build(); } } UnitDipServiceImpl(ArchiveUnitMapper archiveUnitMapper, ObjectMapper objectMapper); @Override Response jsonToXml(JsonNode object, String id); }
UnitDipServiceImpl implements DipService { @Override public Response jsonToXml(JsonNode object, String id) { Status status; StringWriter writer = new StringWriter(); try { if (object != null) { ArchiveUnitModel archiveUnitModel = objectMapper.treeToValue(object, ArchiveUnitModel.class); Marshaller marshaller = jaxbContext.createMarshaller(); final ArchiveUnitType xmlUnit = archiveUnitMapper.map(archiveUnitModel); marshaller.marshal(xmlUnit, writer); LOGGER.debug(END_OF_EXECUTION_OF_DSL_VITAM_FROM_ACCESS); return Response.status(Status.OK).entity(writer.toString()).build(); } else { return Response.status(Status.BAD_REQUEST.getStatusCode()) .entity(JsonHandler.unprettyPrint( new VitamError(VitamCode.ACCESS_EXTERNAL_SELECT_UNIT_BY_ID_ERROR.getItem()) .setHttpCode(Status.BAD_REQUEST.getStatusCode()) .setMessage(VitamCode.ACCESS_EXTERNAL_SELECT_UNIT_BY_ID_ERROR.getMessage()) .setState(StatusCode.KO.name()) .setContext(ACCESS_EXTERNAL_MODULE) .setDescription(VitamCode.ACCESS_EXTERNAL_SELECT_UNIT_BY_ID_ERROR.getMessage()))) .build(); } } catch (JsonProcessingException e) { LOGGER.error(BAD_REQUEST_EXCEPTION, e); status = Status.BAD_REQUEST; return Response.status(status).entity(JsonHandler.unprettyPrint(getErrorEntity(status, e.getMessage()))) .build(); } catch (JAXBException e) { LOGGER.error(BAD_REQUEST_EXCEPTION, e); status = Status.BAD_REQUEST; return Response.status(status).entity(JsonHandler.unprettyPrint(getErrorEntity(status, e.getMessage()))) .build(); } catch (DatatypeConfigurationException e) { LOGGER.error(BAD_REQUEST_EXCEPTION, e); status = Status.BAD_REQUEST; return Response.status(status).entity(JsonHandler.unprettyPrint(getErrorEntity(status, e.getMessage()))) .build(); } catch (NullPointerException e) { LOGGER.error(BAD_REQUEST_EXCEPTION, e); status = Status.BAD_REQUEST; return Response.status(status).entity(JsonHandler.unprettyPrint(getErrorEntity(status, e.getMessage()))) .build(); } catch (Exception e) { status = Status.BAD_REQUEST; return Response.status(status) .entity(JsonHandler.unprettyPrint(getErrorEntity(status, e.getMessage()))) .build(); } } UnitDipServiceImpl(ArchiveUnitMapper archiveUnitMapper, ObjectMapper objectMapper); @Override Response jsonToXml(JsonNode object, String id);  }