1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.openehealth.ipf.commons.ihe.xds.core.transform.requests;
17
18 import static org.apache.commons.lang3.Validate.notNull;
19
20 import java.util.List;
21
22 import org.openehealth.ipf.commons.ihe.xds.core.ebxml.EbXMLAssociation;
23 import org.openehealth.ipf.commons.ihe.xds.core.ebxml.EbXMLClassification;
24 import org.openehealth.ipf.commons.ihe.xds.core.ebxml.EbXMLExtrinsicObject;
25 import org.openehealth.ipf.commons.ihe.xds.core.ebxml.EbXMLFactory;
26 import org.openehealth.ipf.commons.ihe.xds.core.ebxml.EbXMLObjectLibrary;
27 import org.openehealth.ipf.commons.ihe.xds.core.ebxml.EbXMLRegistryPackage;
28 import org.openehealth.ipf.commons.ihe.xds.core.ebxml.EbXMLSubmitObjectsRequest;
29 import org.openehealth.ipf.commons.ihe.xds.core.metadata.*;
30 import org.openehealth.ipf.commons.ihe.xds.core.requests.RegisterDocumentSet;
31 import org.openehealth.ipf.commons.ihe.xds.core.transform.ebxml.AssociationTransformer;
32 import org.openehealth.ipf.commons.ihe.xds.core.transform.ebxml.DocumentEntryTransformer;
33 import org.openehealth.ipf.commons.ihe.xds.core.transform.ebxml.FolderTransformer;
34 import org.openehealth.ipf.commons.ihe.xds.core.transform.ebxml.SubmissionSetTransformer;
35
36
37
38
39
40 public class RegisterDocumentSetTransformer {
41 private final EbXMLFactory factory;
42 private final SubmissionSetTransformer submissionSetTransformer;
43 private final DocumentEntryTransformer documentEntryTransformer;
44 private final FolderTransformer folderTransformer;
45 private final AssociationTransformer associationTransformer;
46
47
48
49
50
51
52 public RegisterDocumentSetTransformer(EbXMLFactory factory) {
53 notNull(factory, "factory cannot be null");
54 this.factory = factory;
55
56 submissionSetTransformer = new SubmissionSetTransformer(factory);
57 documentEntryTransformer = new DocumentEntryTransformer(factory);
58 folderTransformer = new FolderTransformer(factory);
59 associationTransformer = new AssociationTransformer(factory);
60 }
61
62
63
64
65
66
67
68 public EbXMLSubmitObjectsRequest toEbXML(RegisterDocumentSet request) {
69 notNull(request, "request cannot be null");
70
71 EbXMLSubmitObjectsRequest ebXML = factory.createSubmitObjectsRequest();
72 EbXMLObjectLibrary library = ebXML.getObjectLibrary();
73
74 for (DocumentEntry docEntry : request.getDocumentEntries()) {
75 ebXML.addExtrinsicObject(documentEntryTransformer.toEbXML(docEntry, library));
76 }
77
78 for (Folder folder : request.getFolders()) {
79 ebXML.addRegistryPackage(folderTransformer.toEbXML(folder, library));
80 addClassification(ebXML, folder.getEntryUuid(), Vocabulary.FOLDER_CLASS_NODE, library);
81 }
82
83 SubmissionSet submissionSet = request.getSubmissionSet();
84 ebXML.addRegistryPackage(submissionSetTransformer.toEbXML(submissionSet, library));
85 String entryUUID = submissionSet != null ? submissionSet.getEntryUuid() : null;
86 addClassification(ebXML, entryUUID, Vocabulary.SUBMISSION_SET_CLASS_NODE, library);
87
88 for (Association association : request.getAssociations()) {
89 ebXML.addAssociation(associationTransformer.toEbXML(association, library));
90 }
91
92 if (request.getTargetHomeCommunityId() != null) {
93 ebXML.addSlot(Vocabulary.SLOT_NAME_HOME_COMMUNITY_ID, request.getTargetHomeCommunityId());
94 }
95
96 return ebXML;
97 }
98
99
100
101
102
103
104
105 public RegisterDocumentSet fromEbXML(EbXMLSubmitObjectsRequest ebXML) {
106 notNull(ebXML, "ebXML cannot be null");
107
108 RegisterDocumentSet request = new RegisterDocumentSet();
109
110 for (EbXMLExtrinsicObject extrinsic : ebXML.getExtrinsicObjects(DocumentEntryType.STABLE_OR_ON_DEMAND)) {
111 request.getDocumentEntries().add(documentEntryTransformer.fromEbXML(extrinsic));
112 }
113
114 for (EbXMLRegistryPackage regPackage : ebXML.getRegistryPackages(Vocabulary.FOLDER_CLASS_NODE)) {
115 request.getFolders().add(folderTransformer.fromEbXML(regPackage));
116 }
117
118 List<EbXMLRegistryPackage> regPackages = ebXML.getRegistryPackages(Vocabulary.SUBMISSION_SET_CLASS_NODE);
119 if (regPackages.size() > 0) {
120 request.setSubmissionSet(submissionSetTransformer.fromEbXML(regPackages.get(0)));
121 }
122
123 for (EbXMLAssociation association : ebXML.getAssociations()) {
124 request.getAssociations().add(associationTransformer.fromEbXML(association));
125 }
126
127 request.setTargetHomeCommunityId(ebXML.getSingleSlotValue(Vocabulary.SLOT_NAME_HOME_COMMUNITY_ID));
128
129 return request;
130 }
131
132 private void addClassification(EbXMLSubmitObjectsRequest ebXML, String classified, String node, EbXMLObjectLibrary library) {
133 EbXMLClassification classification = factory.createClassification(library);
134 classification.setClassifiedObject(classified);
135 classification.setClassificationNode(node);
136 classification.assignUniqueId();
137 ebXML.addClassification(classification);
138 }
139 }