@Test public void testToPolicyDtoPolicyContentDto() throws SAXException, IOException { final byte[] bytes = POLICY_STRING.getBytes(DOMUtils.DEFAULT_ENCODING); final PolicyContentDto addPolicyRequestDto = new PolicyContentDto(); addPolicyRequestDto.setPolicy(bytes); final PolicyDto policyDto = MappingUtils .toPolicyDto(addPolicyRequestDto); assertEquals(POLICY_ID, policyDto.getId()); assertXMLEqual(POLICY_STRING, new String(policyDto.getPolicy(), DOMUtils.DEFAULT_ENCODING)); }
public static PolicyDto toPolicyDto(byte[] policy) { String id = null; final Document policyDoc = bytesToDocument(policy); final Optional<Node> policySetId = DOMUtils.getNode(policyDoc, XPATH_POLICY_SET_ID); if (policySetId.isPresent()) { id = policySetId.get().getNodeValue(); } else { final Optional<Node> policyId = DOMUtils.getNode(policyDoc, XPATH_POLICY_ID); if (policyId.isPresent()) { id = policyId.get().getNodeValue(); } } if (id == null) { throw new PolicyIdNotFoundException( "Cannot find the PolicyId/PolicySetId in one or more of the submitted policies!"); } else { final PolicyDto dto = new PolicyDto(); dto.setId(id); dto.setPolicy(policy); return dto; } }
MappingUtils { public static PolicyDto toPolicyDto(byte[] policy) { String id = null; final Document policyDoc = bytesToDocument(policy); final Optional<Node> policySetId = DOMUtils.getNode(policyDoc, XPATH_POLICY_SET_ID); if (policySetId.isPresent()) { id = policySetId.get().getNodeValue(); } else { final Optional<Node> policyId = DOMUtils.getNode(policyDoc, XPATH_POLICY_ID); if (policyId.isPresent()) { id = policyId.get().getNodeValue(); } } if (id == null) { throw new PolicyIdNotFoundException( "Cannot find the PolicyId/PolicySetId in one or more of the submitted policies!"); } else { final PolicyDto dto = new PolicyDto(); dto.setId(id); dto.setPolicy(policy); return dto; } } }
MappingUtils { public static PolicyDto toPolicyDto(byte[] policy) { String id = null; final Document policyDoc = bytesToDocument(policy); final Optional<Node> policySetId = DOMUtils.getNode(policyDoc, XPATH_POLICY_SET_ID); if (policySetId.isPresent()) { id = policySetId.get().getNodeValue(); } else { final Optional<Node> policyId = DOMUtils.getNode(policyDoc, XPATH_POLICY_ID); if (policyId.isPresent()) { id = policyId.get().getNodeValue(); } } if (id == null) { throw new PolicyIdNotFoundException( "Cannot find the PolicyId/PolicySetId in one or more of the submitted policies!"); } else { final PolicyDto dto = new PolicyDto(); dto.setId(id); dto.setPolicy(policy); return dto; } }  }
MappingUtils { public static PolicyDto toPolicyDto(byte[] policy) { String id = null; final Document policyDoc = bytesToDocument(policy); final Optional<Node> policySetId = DOMUtils.getNode(policyDoc, XPATH_POLICY_SET_ID); if (policySetId.isPresent()) { id = policySetId.get().getNodeValue(); } else { final Optional<Node> policyId = DOMUtils.getNode(policyDoc, XPATH_POLICY_ID); if (policyId.isPresent()) { id = policyId.get().getNodeValue(); } } if (id == null) { throw new PolicyIdNotFoundException( "Cannot find the PolicyId/PolicySetId in one or more of the submitted policies!"); } else { final PolicyDto dto = new PolicyDto(); dto.setId(id); dto.setPolicy(policy); return dto; } }  static PolicyDto toPolicyDto(byte[] policy); static PolicyDto toPolicyDto(PolicyContentDto policyContentDto); }
MappingUtils { public static PolicyDto toPolicyDto(byte[] policy) { String id = null; final Document policyDoc = bytesToDocument(policy); final Optional<Node> policySetId = DOMUtils.getNode(policyDoc, XPATH_POLICY_SET_ID); if (policySetId.isPresent()) { id = policySetId.get().getNodeValue(); } else { final Optional<Node> policyId = DOMUtils.getNode(policyDoc, XPATH_POLICY_ID); if (policyId.isPresent()) { id = policyId.get().getNodeValue(); } } if (id == null) { throw new PolicyIdNotFoundException( "Cannot find the PolicyId/PolicySetId in one or more of the submitted policies!"); } else { final PolicyDto dto = new PolicyDto(); dto.setId(id); dto.setPolicy(policy); return dto; } }  static PolicyDto toPolicyDto(byte[] policy); static PolicyDto toPolicyDto(PolicyContentDto policyContentDto);  }