XdsbPolicyProvider implements PolicyProvider { @Override public List<Evaluatable> getPolicies(XacmlRequest xacmlRequest) throws NoPolicyFoundException, PolicyProviderException { final String patientUniqueId = xacmlRequest.getPatientUniqueId(); final String recipientSubjectNPI = xacmlRequest .getRecipientSubjectNPI(); final String intermediarySubjectNPI = xacmlRequest .getIntermediarySubjectNPI(); final String messageId = xacmlRequest.getMessageId(); List<Evaluatable> policies = new LinkedList<Evaluatable>(); List<String> policiesString = new LinkedList<String>(); try { AdhocQueryResponse response = xdsbRegistry.registryStoredQuery( patientUniqueId, null, XdsbDocumentType.PRIVACY_CONSENT, true, messageId); RetrieveDocumentSetRequest retrieveDocumentSetRequest = xdsbRegistry .extractXdsbDocumentReferenceListAsRetrieveDocumentSetRequest(response); StringBuilder noConsentsFoundErrorStringBuilder = new StringBuilder(); noConsentsFoundErrorStringBuilder .append("No consents found for patient "); noConsentsFoundErrorStringBuilder.append(patientUniqueId); noConsentsFoundErrorStringBuilder.append("."); final String errMsg = noConsentsFoundErrorStringBuilder.toString(); if (retrieveDocumentSetRequest.getDocumentRequest().size() <= 0) { logger.error(xacmlRequest.getMessageId(), errMsg); throw new NoPolicyFoundException(errMsg); } RetrieveDocumentSetResponse retrieveDocumentSetResponse = xdsbRepository .retrieveDocumentSet(retrieveDocumentSetRequest); List<String> deprecatedDocumentUniqueIds = this.xdsbRegistry .findDeprecatedDocumentUniqueIds(patientUniqueId, patientUniqueId, messageId); for (DocumentResponse docResponse : retrieveDocumentSetResponse .getDocumentResponse()) { if (!deprecatedDocumentUniqueIds.contains(docResponse .getDocumentUniqueId())) { String docString = new String(docResponse.getDocument()); docString = docString.replace( "<?xml version=\"1.0\" encoding=\"UTF-8\"?>", ""); policiesString.add(docString); } } policyListFilter.filterByNPI(policiesString, recipientSubjectNPI, intermediarySubjectNPI); if (policiesString.size() <= 0) { throw new NoPolicyFoundException( noConsentsFoundErrorStringBuilder.toString()); } String policySet = makePolicySet(policiesString); Evaluatable policy = unmarshal(new ByteArrayInputStream( policySet.getBytes())); policies.add(policy); } catch (NoPolicyFoundException e) { logger.info(messageId, e.getMessage()); throw e; } catch (Throwable t) { logger.error(messageId, t.getMessage(), t); throw new PolicyProviderException( "Consent files cannot be queried/retrieved from XDS.b"); } return policies; } XdsbPolicyProvider(XdsbRegistryAdapter xdsbRegistry,
			XdsbRepositoryAdapter xdsbRepository,
			XacmlPolicyListFilter policyListFilter);  XdsbPolicyProvider(XdsbRegistryAdapter xdsbRegistry,
			XdsbRepositoryAdapter xdsbRepository,
			XacmlPolicyListFilter policyListFilter,
			String urnPolicyCombiningAlgorithm); @Override List<Evaluatable> getPolicies(XacmlRequest xacmlRequest); static final String URN_POLICY_COMBINING_ALGORITHM_PERMIT_OVERRIDES; }
@Test public void testGetPolicies() throws Exception, Throwable { XdsbPolicyProvider sut = spy(policyDecisionPointImplDataXdsb); byte[] xacmlPolicy = "<Policy xmlns=\"urn:oasis:names:tc:xacml:2.0:policy:schema:os\" PolicyId=\"a07478e8-3642-42ff-980e-911e26ec3f47\" RuleCombiningAlgId=\"urn:oasis:names:tc:xacml:1.0:rule-combining-algorithm:first-applicable\">\r\n <Description>This is a reference policy forconsent2share@outlook.com</Description>\r\n <Target></Target>\r\n <Rule Effect=\"Permit\" RuleId=\"primary-group-rule\">\r\n <Target>\r\n <Resources>\r\n <Resource>\r\n <ResourceMatch MatchId=\"urn:oasis:names:tc:xacml:1.0:function:string-regexp-match\">\r\n <AttributeValue DataType=\"http: .getBytes(); RetrieveDocumentSetResponse retrieveDocumentSetResponse = mock(RetrieveDocumentSetResponse.class); RetrieveDocumentSetRequest retrieveDocumentSetRequest = mock(RetrieveDocumentSetRequest.class); AdhocQueryResponse response = mock(AdhocQueryResponse.class); DocumentResponse docResponse1 = mock(DocumentResponse.class); DocumentResponse docResponse2 = mock(DocumentResponse.class); List<RetrieveDocumentSetResponse.DocumentResponse> policyDocuments = new ArrayList<RetrieveDocumentSetResponse.DocumentResponse>(); policyDocuments.add(docResponse1); policyDocuments.add(docResponse2); Evaluatable evaluatable = mock(Evaluatable.class); doReturn(evaluatable).when(sut).unmarshal(any(InputStream.class)); when( xdsbRegistry.registryStoredQuery("1", null, XdsbDocumentType.PRIVACY_CONSENT, true, "")).thenReturn( response); when( xdsbRegistry .extractXdsbDocumentReferenceListAsRetrieveDocumentSetRequest(response)) .thenReturn(retrieveDocumentSetRequest); when(xdsbRepository.retrieveDocumentSet(retrieveDocumentSetRequest)) .thenReturn(retrieveDocumentSetResponse); when(retrieveDocumentSetResponse.getDocumentResponse()).thenReturn( policyDocuments); when(docResponse2.getDocument()).thenReturn(xacmlPolicy); when(docResponse1.getDocument()).thenReturn(xacmlPolicy); @SuppressWarnings("unchecked") List<DocumentRequest> docReqListMock = mock(List.class); when(retrieveDocumentSetRequest.getDocumentRequest()).thenReturn( docReqListMock); when(docReqListMock.size()).thenReturn(1); XacmlRequest xacmlRequest = new XacmlRequest(); xacmlRequest.setPatientUniqueId("1"); xacmlRequest.setRecipientSubjectNPI("1568797520"); xacmlRequest.setIntermediarySubjectNPI("1285969170"); xacmlRequest.setMessageId(""); sut.getPolicies(xacmlRequest); verify(xdsbRegistry, times(1)) .extractXdsbDocumentReferenceListAsRetrieveDocumentSetRequest( response); verify(xdsbRepository, times(1)).retrieveDocumentSet( retrieveDocumentSetRequest); }