1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.openehealth.ipf.commons.ihe.xds.core.ebxml.ebxml30;
17
18 import static org.apache.commons.lang3.Validate.notNull;
19
20 import java.util.Collections;
21 import java.util.HashMap;
22 import java.util.List;
23 import java.util.Map;
24
25 import javax.activation.DataHandler;
26 import javax.xml.bind.JAXBElement;
27
28 import lombok.experimental.Delegate;
29 import org.openehealth.ipf.commons.ihe.xds.core.ebxml.EbXMLObjectLibrary;
30 import org.openehealth.ipf.commons.ihe.xds.core.ebxml.EbXMLProvideAndRegisterDocumentSetRequest;
31 import org.openehealth.ipf.commons.ihe.xds.core.ebxml.ebxml30.ProvideAndRegisterDocumentSetRequestType.Document;
32 import org.openehealth.ipf.commons.ihe.xds.core.stub.ebrs30.lcm.SubmitObjectsRequest;
33 import org.openehealth.ipf.commons.ihe.xds.core.stub.ebrs30.rim.IdentifiableType;
34 import org.openehealth.ipf.commons.ihe.xds.core.stub.ebrs30.rim.RegistryObjectListType;
35 import org.openehealth.ipf.commons.ihe.xds.core.stub.ebrs30.rim.SlotListType;
36
37
38
39
40
41 public class EbXMLProvideAndRegisterDocumentSetRequest30 extends EbXMLObjectContainer30 implements EbXMLProvideAndRegisterDocumentSetRequest {
42 private final ProvideAndRegisterDocumentSetRequestType request;
43
44
45
46
47
48
49
50
51 public EbXMLProvideAndRegisterDocumentSetRequest30(ProvideAndRegisterDocumentSetRequestType request, EbXMLObjectLibrary objectLibrary) {
52 super(objectLibrary);
53 notNull(request, "request cannot be null");
54 this.request = request;
55 }
56
57
58
59
60
61
62 public EbXMLProvideAndRegisterDocumentSetRequest30(ProvideAndRegisterDocumentSetRequestType request) {
63 this(request, new EbXMLObjectLibrary());
64 fillObjectLibrary();
65 }
66
67 @Override
68 public void addDocument(String id, DataHandler dataHandler) {
69 if (dataHandler != null && id != null) {
70 List<Document> documents = request.getDocument();
71 Document document = new Document();
72 document.setId(id);
73 document.setValue(dataHandler);
74 documents.add(document);
75 }
76 }
77
78 @Override
79 public void removeDocument(String id) {
80 for (Document doc : request.getDocument()) {
81 if (doc.getId().equals(id)) {
82 request.getDocument().remove(doc);
83 return;
84 }
85 }
86 }
87
88 @Override
89 public Map<String, DataHandler> getDocuments() {
90 Map<String, DataHandler> map = new HashMap<>();
91 for (Document document : request.getDocument()) {
92 map.put(document.getId(), document.getValue());
93 }
94 return map;
95 }
96
97 @Override
98 public ProvideAndRegisterDocumentSetRequestType getInternal() {
99 return request;
100 }
101
102 @Override
103 List<JAXBElement<? extends IdentifiableType>> getContents() {
104 SubmitObjectsRequest submitObjectsRequest = request.getSubmitObjectsRequest();
105 if (submitObjectsRequest == null) {
106 return Collections.emptyList();
107 }
108 RegistryObjectListType list = submitObjectsRequest.getRegistryObjectList();
109 if (list == null) {
110 return Collections.emptyList();
111 }
112 return list.getIdentifiable();
113 }
114
115
116
117
118
119 @Delegate
120 private EbXMLSlotList30 getSlotList() {
121 SubmitObjectsRequest submitObjectsRequest = request.getSubmitObjectsRequest();
122 if (submitObjectsRequest.getRequestSlotList() == null) {
123 submitObjectsRequest.setRequestSlotList(new SlotListType());
124 }
125 return new EbXMLSlotList30(submitObjectsRequest.getRequestSlotList().getSlot());
126 }
127 }