@Test public void should_map_json_object_group_to_xml_with_fileInfo() throws InvalidParseOperationException { ObjectGroupMapper objectGroupMapper = new ObjectGroupMapper(); ObjectGroupDipServiceImpl objectGrouDipService = new ObjectGroupDipServiceImpl(objectGroupMapper, buildObjectMapper()); InputStream inputStream = getClass().getResourceAsStream("/simple_objectGroup_with_phisical_and_objectGroup.json"); JsonNode jsonNode = JsonHandler.getFromInputStream(inputStream); Map<String, String> prefix2Uri = new HashMap<>(); prefix2Uri.put("vitam", "fr:gouv:culture:archivesdefrance:seda:v2.1"); Response response = objectGrouDipService.jsonToXml(jsonNode, ""); String entity = (String) response.getEntity(); assertThat(fromString(entity), hasXPath(" equalTo("Filename0")) .withNamespaceContext(prefix2Uri)); assertThat(fromString(entity), hasXPath(" equalTo("CreatingApplicationName0")) .withNamespaceContext(prefix2Uri)); assertThat(fromString(entity), hasXPath(" equalTo("CreatingApplicationVersion0")) .withNamespaceContext(prefix2Uri)); assertThat(fromString(entity), hasXPath(" equalTo("2006-05-04T18:13:51.0")) .withNamespaceContext(prefix2Uri)); assertThat(fromString(entity), hasXPath(" equalTo("CreatingOs0")) .withNamespaceContext(prefix2Uri)); assertThat(fromString(entity), hasXPath(" equalTo("CreatingOsVersion0")) .withNamespaceContext(prefix2Uri)); assertThat(fromString(entity), hasXPath(" equalTo("2006-05-04T18:13:51.0")) .withNamespaceContext(prefix2Uri)); assertThat(fromString(entity), hasXPath(" equalTo("test value")) .withNamespaceContext(prefix2Uri)); }
@Override public Response jsonToXml(JsonNode object, String id) { Status status; StringWriter writer = new StringWriter(); try { if (object != null) { ObjectGroupResponse objectGroup = objectMapper.treeToValue(object, ObjectGroupResponse.class); final DataObjectPackageType xmlObject = objectGroupMapper.map(objectGroup); Marshaller marshaller = jaxbContext.createMarshaller(); marshaller.marshal(xmlObject, 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 | JAXBException e) { LOGGER.error(BAD_REQUEST_EXCEPTION, e); status = Response.Status.BAD_REQUEST; return Response.status(status).entity(JsonHandler.unprettyPrint(getErrorEntity(status, e.getMessage()))) .build(); } catch (InternalServerException e) { status = Status.BAD_REQUEST; return Response.status(status).entity(JsonHandler.unprettyPrint(getErrorEntity(status, e.getMessage()))) .build(); } }
ObjectGroupDipServiceImpl implements DipService { @Override public Response jsonToXml(JsonNode object, String id) { Status status; StringWriter writer = new StringWriter(); try { if (object != null) { ObjectGroupResponse objectGroup = objectMapper.treeToValue(object, ObjectGroupResponse.class); final DataObjectPackageType xmlObject = objectGroupMapper.map(objectGroup); Marshaller marshaller = jaxbContext.createMarshaller(); marshaller.marshal(xmlObject, 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 | JAXBException e) { LOGGER.error(BAD_REQUEST_EXCEPTION, e); status = Response.Status.BAD_REQUEST; return Response.status(status).entity(JsonHandler.unprettyPrint(getErrorEntity(status, e.getMessage()))) .build(); } catch (InternalServerException e) { status = Status.BAD_REQUEST; return Response.status(status).entity(JsonHandler.unprettyPrint(getErrorEntity(status, e.getMessage()))) .build(); } } }
ObjectGroupDipServiceImpl implements DipService { @Override public Response jsonToXml(JsonNode object, String id) { Status status; StringWriter writer = new StringWriter(); try { if (object != null) { ObjectGroupResponse objectGroup = objectMapper.treeToValue(object, ObjectGroupResponse.class); final DataObjectPackageType xmlObject = objectGroupMapper.map(objectGroup); Marshaller marshaller = jaxbContext.createMarshaller(); marshaller.marshal(xmlObject, 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 | JAXBException e) { LOGGER.error(BAD_REQUEST_EXCEPTION, e); status = Response.Status.BAD_REQUEST; return Response.status(status).entity(JsonHandler.unprettyPrint(getErrorEntity(status, e.getMessage()))) .build(); } catch (InternalServerException e) { status = Status.BAD_REQUEST; return Response.status(status).entity(JsonHandler.unprettyPrint(getErrorEntity(status, e.getMessage()))) .build(); } } ObjectGroupDipServiceImpl(ObjectGroupMapper objectGroupMapper, ObjectMapper objectMapper); }
ObjectGroupDipServiceImpl implements DipService { @Override public Response jsonToXml(JsonNode object, String id) { Status status; StringWriter writer = new StringWriter(); try { if (object != null) { ObjectGroupResponse objectGroup = objectMapper.treeToValue(object, ObjectGroupResponse.class); final DataObjectPackageType xmlObject = objectGroupMapper.map(objectGroup); Marshaller marshaller = jaxbContext.createMarshaller(); marshaller.marshal(xmlObject, 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 | JAXBException e) { LOGGER.error(BAD_REQUEST_EXCEPTION, e); status = Response.Status.BAD_REQUEST; return Response.status(status).entity(JsonHandler.unprettyPrint(getErrorEntity(status, e.getMessage()))) .build(); } catch (InternalServerException e) { status = Status.BAD_REQUEST; return Response.status(status).entity(JsonHandler.unprettyPrint(getErrorEntity(status, e.getMessage()))) .build(); } } ObjectGroupDipServiceImpl(ObjectGroupMapper objectGroupMapper, ObjectMapper objectMapper); @Override Response jsonToXml(JsonNode object, String id); }
ObjectGroupDipServiceImpl implements DipService { @Override public Response jsonToXml(JsonNode object, String id) { Status status; StringWriter writer = new StringWriter(); try { if (object != null) { ObjectGroupResponse objectGroup = objectMapper.treeToValue(object, ObjectGroupResponse.class); final DataObjectPackageType xmlObject = objectGroupMapper.map(objectGroup); Marshaller marshaller = jaxbContext.createMarshaller(); marshaller.marshal(xmlObject, 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 | JAXBException e) { LOGGER.error(BAD_REQUEST_EXCEPTION, e); status = Response.Status.BAD_REQUEST; return Response.status(status).entity(JsonHandler.unprettyPrint(getErrorEntity(status, e.getMessage()))) .build(); } catch (InternalServerException e) { status = Status.BAD_REQUEST; return Response.status(status).entity(JsonHandler.unprettyPrint(getErrorEntity(status, e.getMessage()))) .build(); } } ObjectGroupDipServiceImpl(ObjectGroupMapper objectGroupMapper, ObjectMapper objectMapper); @Override Response jsonToXml(JsonNode object, String id);  }