View Javadoc
1   /*
2    * Copyright 2017 the original author or authors.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.openehealth.ipf.commons.ihe.xds.core.validate.requests;
17  
18  import lombok.extern.slf4j.Slf4j;
19  import org.joda.time.DateTime;
20  import org.junit.Test;
21  import org.openehealth.ipf.commons.ihe.xds.XDM;
22  import org.openehealth.ipf.commons.ihe.xds.core.ebxml.EbXMLSubmitObjectsRequest;
23  import org.openehealth.ipf.commons.ihe.xds.core.ebxml.ebxml30.EbXMLFactory30;
24  import org.openehealth.ipf.commons.ihe.xds.core.metadata.*;
25  import org.openehealth.ipf.commons.ihe.xds.core.requests.RegisterDocumentSet;
26  import org.openehealth.ipf.commons.ihe.xds.core.transform.requests.RegisterDocumentSetTransformer;
27  
28  import java.util.UUID;
29  
30  /**
31   * @author Dmytro Rud
32   */
33  @Slf4j
34  public class LimitedMetadataTest {
35  
36      private RegisterDocumentSet createXdmRequest() {
37          DocumentEntry documentEntry1 = new DocumentEntry();
38          documentEntry1.setLimitedMetadata(true);
39          documentEntry1.setEntryUuid(UUID.randomUUID().toString());
40          documentEntry1.setHash("01234567890ABCDEF01234567890ABCDEF012345");
41          documentEntry1.setMimeType("text/xml");
42          documentEntry1.setSize(7777L);
43          documentEntry1.setUniqueId("1.2.3.4.5.111");
44          documentEntry1.setUri("CDA-1.XML");
45  
46          DocumentEntry documentEntry2 = new DocumentEntry();
47          documentEntry2.setLimitedMetadata(true);
48          documentEntry2.setEntryUuid(UUID.randomUUID().toString());
49          documentEntry2.setHash("ABCDEF0123456789ABCDEF0123456789ABCDEF01");
50          documentEntry2.setMimeType("text/xml");
51          documentEntry2.setSize(12345L);
52          documentEntry2.setUniqueId("1.2.3.4.5.222");
53          documentEntry2.setUri("CDA-2.XML");
54  
55          SubmissionSet submissionSet = new SubmissionSet();
56          submissionSet.setLimitedMetadata(true);
57          submissionSet.setEntryUuid(UUID.randomUUID().toString());
58          submissionSet.setSourceId("1.2.3.4.5");
59          submissionSet.setSubmissionTime(new Timestamp(new DateTime(), Timestamp.Precision.SECOND));
60          submissionSet.setUniqueId("1.2.3.4.5.777");
61  
62          Association association1 = new Association();
63          association1.setLabel(AssociationLabel.ORIGINAL);
64          association1.setAssociationType(AssociationType.HAS_MEMBER);
65          association1.setSourceUuid(submissionSet.getEntryUuid());
66          association1.setTargetUuid(documentEntry1.getEntryUuid());
67  
68          Association association2 = new Association();
69          association2.setLabel(AssociationLabel.ORIGINAL);
70          association2.setAssociationType(AssociationType.HAS_MEMBER);
71          association2.setSourceUuid(submissionSet.getEntryUuid());
72          association2.setTargetUuid(documentEntry2.getEntryUuid());
73  
74          RegisterDocumentSet request = new RegisterDocumentSet();
75          request.getDocumentEntries().add(documentEntry1);
76          request.getDocumentEntries().add(documentEntry2);
77          request.setSubmissionSet(submissionSet);
78          request.getAssociations().add(association1);
79          request.getAssociations().add(association2);
80  
81          return request;
82      }
83  
84      @Test
85      public void testXdmRequestValidation() throws Exception {
86          RegisterDocumentSet xdmRequest = createXdmRequest();
87  
88          RegisterDocumentSetTransformer transformer = new RegisterDocumentSetTransformer(new EbXMLFactory30());
89          EbXMLSubmitObjectsRequest ebXmlRequest = transformer.toEbXML(xdmRequest);
90  
91          /*
92          JAXBContext jaxbContext = JAXBContext.newInstance(SubmitObjectsRequest.class);
93          Marshaller marshaller = jaxbContext.createMarshaller();
94          marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
95          StringWriter writer = new StringWriter();
96          marshaller.marshal(ebXmlRequest.getInternal(), writer);
97          System.out.println(writer.toString());
98          */
99  
100         SubmitObjectsRequestValidator validator = new SubmitObjectsRequestValidator();
101         validator.validate(ebXmlRequest, XDM.Interactions.ITI_41);
102     }
103 
104 }