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 org.openehealth.ipf.commons.ihe.xds.core.ebxml.EbXMLSlot;
19 import org.openehealth.ipf.commons.ihe.xds.core.ebxml.EbXMLSlotList;
20 import org.openehealth.ipf.commons.ihe.xds.core.stub.ebrs30.rim.SlotType1;
21 import org.openehealth.ipf.commons.ihe.xds.core.stub.ebrs30.rim.ValueListType;
22
23 import java.util.Collections;
24 import java.util.List;
25 import java.util.stream.Collectors;
26
27 import static org.apache.commons.lang3.Validate.notNull;
28
29
30
31
32
33 public class EbXMLSlotList30 implements EbXMLSlotList {
34 private final List<SlotType1> slotListObj;
35
36
37
38
39
40
41 public EbXMLSlotList30(List<SlotType1> slotListObj) {
42 notNull(slotListObj, "slotListObj cannot be null");
43 this.slotListObj = slotListObj;
44 }
45
46 @Override
47 public void addSlot(String slotName, String... slotValues) {
48 if (slotValues == null || slotValues.length == 0) {
49 return;
50 }
51
52 ValueListType valueList = EbXMLFactory30.RIM_FACTORY.createValueListType();
53 List<String> values = valueList.getValue();
54 for (String slotValue : slotValues) {
55 if (slotValue != null) {
56 values.add(slotValue);
57 }
58 }
59
60 SlotType1 slotEbXML = EbXMLFactory30.RIM_FACTORY.createSlotType1();
61 slotEbXML.setName(slotName);
62 slotEbXML.setValueList(valueList);
63 EbXMLSlot30 slot = new EbXMLSlot30(slotEbXML);
64
65 if (!slot.getValueList().isEmpty()) {
66 slotListObj.add(slotEbXML);
67 }
68 }
69
70 @Override
71 public List<String> getSlotValues(String slotName) {
72 notNull(slotName, "slotName cannot be null");
73 for (SlotType1 slot30 : slotListObj) {
74 if (slotName.equals(slot30.getName())) {
75 return slot30.getValueList().getValue();
76 }
77 }
78
79 return Collections.emptyList();
80 }
81
82 @Override
83 public String getSingleSlotValue(String slotName) {
84 List<String> slotValues = getSlotValues(slotName);
85 return slotValues.size() > 0 ? slotValues.get(0) : null;
86 }
87
88 @Override
89 public List<EbXMLSlot> getSlots() {
90 return slotListObj.stream()
91 .map(EbXMLSlot30::new)
92 .collect(Collectors.toList());
93 }
94
95 @Override
96 public List<EbXMLSlot> getSlots(String slotName) {
97 notNull(slotName, "slotName cannot be null");
98 return slotListObj.stream()
99 .filter(slot30 -> slotName.equals(slot30.getName()))
100 .map(EbXMLSlot30::new)
101 .collect(Collectors.toList());
102 }
103 }