1 | /*
|
---|
2 | * To change this template, choose Tools | Templates
|
---|
3 | * and open the template in the editor.
|
---|
4 | */
|
---|
5 | package gov.hhs.fha.nhinc.subscription.dte;
|
---|
6 |
|
---|
7 | //import gov.hhs.fha.nhinc.NHINCLib.NullChecker;
|
---|
8 | import gov.hhs.fha.nhinc.nhinclib.NullChecker;
|
---|
9 | import java.util.ArrayList;
|
---|
10 | import java.util.List;
|
---|
11 | import javax.xml.bind.JAXBElement;
|
---|
12 | import oasis.names.tc.ebxml_regrep.xsd.rim._3.*;
|
---|
13 | import org.oasis_open.docs.wsn.b_2.Subscribe;
|
---|
14 | import org.w3c.dom.Element;
|
---|
15 |
|
---|
16 | /**
|
---|
17 | *
|
---|
18 | * @author rayj
|
---|
19 | */
|
---|
20 | public class AdhocQueryHelper {
|
---|
21 |
|
---|
22 | private static org.apache.commons.logging.Log log = org.apache.commons.logging.LogFactory.getLog(AdhocQueryHelper.class);
|
---|
23 |
|
---|
24 | public static AdhocQueryType getAdhocQuery(Subscribe nhinSubscribe) {
|
---|
25 | AdhocQueryType adhocQuery = null;
|
---|
26 | log.info("begin getAdhocQuery");
|
---|
27 | List<Object> any = nhinSubscribe.getAny();
|
---|
28 | log.info("found " + any.size() + " any item(s)");
|
---|
29 |
|
---|
30 |
|
---|
31 | for (Object anyItem : any) {
|
---|
32 | log.info("anyItem=" + anyItem);
|
---|
33 | if (anyItem instanceof oasis.names.tc.ebxml_regrep.xsd.rim._3.AdhocQueryType) {
|
---|
34 | adhocQuery = (AdhocQueryType) anyItem;
|
---|
35 | }
|
---|
36 | if (anyItem instanceof Element) {
|
---|
37 | Element element = (Element) anyItem;
|
---|
38 | log.info("element.getNodeName()=" + element.getNodeName());
|
---|
39 |
|
---|
40 | Object o = (JAXBElement<oasis.names.tc.ebxml_regrep.xsd.rim._3.AdhocQueryType>) nhinSubscribe.getAny();
|
---|
41 |
|
---|
42 | // Object o = (JAXBElement<oasis.names.tc.ebxml_regrep.xsd.rim._3.AdhocQueryType>) anyItem;
|
---|
43 | }
|
---|
44 | if (anyItem instanceof JAXBElement) {
|
---|
45 | log.info("jaxbelement.getValue=" + ((JAXBElement) anyItem).getValue());
|
---|
46 | if (((JAXBElement) anyItem).getValue() instanceof AdhocQueryType) {
|
---|
47 | adhocQuery = (AdhocQueryType) ((JAXBElement) anyItem).getValue();
|
---|
48 | } else {
|
---|
49 | log.warn("unhandled anyitem jaxbelement value " + ((JAXBElement) anyItem).getValue());
|
---|
50 | }
|
---|
51 | } else {
|
---|
52 | log.warn("unhandled anyitem " + anyItem);
|
---|
53 | }
|
---|
54 | }
|
---|
55 | log.info("end getAdhocQuery");
|
---|
56 | return adhocQuery;
|
---|
57 | }
|
---|
58 |
|
---|
59 | public static List<SlotType1> getAllSlots(Subscribe nhinSubscribe) {
|
---|
60 | AdhocQueryType adhocQuery = getAdhocQuery(nhinSubscribe);
|
---|
61 | if ((adhocQuery == null) || (adhocQuery.getSlot() == null)) {
|
---|
62 | return new ArrayList<SlotType1>();
|
---|
63 | }
|
---|
64 | return adhocQuery.getSlot();
|
---|
65 | }
|
---|
66 |
|
---|
67 | public static List<String> findSlotValues(Subscribe nhinSubscribe, String slotName) {
|
---|
68 | log.info("begin findSlotValue");
|
---|
69 | List<SlotType1> allSlots = getAllSlots(nhinSubscribe);
|
---|
70 | List<String> matchingSlotValues = findSlotValues(allSlots, slotName);
|
---|
71 | log.info("total slotValues found " + matchingSlotValues.size());
|
---|
72 | log.info("end findSlotValue");
|
---|
73 | return matchingSlotValues;
|
---|
74 | }
|
---|
75 |
|
---|
76 | public static List<String> findSlotValues(List<SlotType1> slots, String slotName) {
|
---|
77 | log.info("begin findSlotValue");
|
---|
78 | List<String> matchingSlotValues = new ArrayList<String>();
|
---|
79 |
|
---|
80 | for (SlotType1 slot : slots) {
|
---|
81 | if (slot.getName().contentEquals(slotName)) {
|
---|
82 | if (slot.getValueList() != null) {
|
---|
83 | List<String> slotValues = slot.getValueList().getValue();
|
---|
84 | for (String slotValue : slotValues) {
|
---|
85 | if (NullChecker.isNotNullish(slotValue)) {
|
---|
86 | log.info("adding slotValue " + slotValue);
|
---|
87 | matchingSlotValues.add(slotValue);
|
---|
88 | }
|
---|
89 | }
|
---|
90 | }
|
---|
91 | }
|
---|
92 | }
|
---|
93 |
|
---|
94 | log.info("total slotValues found " + matchingSlotValues.size());
|
---|
95 | log.info("end findSlotValue");
|
---|
96 | return matchingSlotValues;
|
---|
97 | }
|
---|
98 |
|
---|
99 | public static String findSlotValue(Subscribe nhinSubscribe, String slotName) throws MultipleSlotValuesFoundException {
|
---|
100 | List<String> slotValues = findSlotValues(nhinSubscribe, slotName);
|
---|
101 | return findSingleSlotValue(slotValues);
|
---|
102 | }
|
---|
103 |
|
---|
104 | public static String findSlotValue(List<SlotType1> slots, String slotName) throws MultipleSlotValuesFoundException {
|
---|
105 | List<String> slotValues = findSlotValues(slots, slotName);
|
---|
106 | return findSingleSlotValue(slotValues);
|
---|
107 | }
|
---|
108 |
|
---|
109 | private static String findSingleSlotValue(List<String> slotValues ) throws MultipleSlotValuesFoundException {
|
---|
110 | String slotValue=null;
|
---|
111 | if ((slotValues == null) || (slotValues.size() == 0)) {
|
---|
112 | slotValue = null;
|
---|
113 | } else if (slotValues.size() > 1) {
|
---|
114 | throw new MultipleSlotValuesFoundException();
|
---|
115 | } else {
|
---|
116 | slotValue = slotValues.get(0);
|
---|
117 | }
|
---|
118 | return slotValue;
|
---|
119 | }
|
---|
120 | }
|
---|