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.subscriptiondte.*;
|
---|
8 | import gov.hhs.fha.nhinc.common.subscription.SubscriptionItemType;
|
---|
9 | import gov.hhs.fha.nhinc.common.subscriptiondte.DetermineRootTopicFromNotifyResponseType;
|
---|
10 | import gov.hhs.fha.nhinc.nhinclib.NullChecker;
|
---|
11 | import java.util.ArrayList;
|
---|
12 | import java.util.List;
|
---|
13 |
|
---|
14 |
|
---|
15 | //import org.oasis_open.docs.wsn.b_2.TopicExpressionType;
|
---|
16 | import javax.xml.bind.JAXBElement;
|
---|
17 | import javax.xml.namespace.QName;
|
---|
18 | import org.oasis_open.docs.wsn.b_2.FilterType;
|
---|
19 | import org.oasis_open.docs.wsn.b_2.NotificationMessageHolderType;
|
---|
20 | import org.oasis_open.docs.wsn.b_2.NotificationMessageHolderType.Message;
|
---|
21 | import org.oasis_open.docs.wsn.b_2.Notify;
|
---|
22 | import org.oasis_open.docs.wsn.b_2.Subscribe;
|
---|
23 | //import gov.hhs.fha.nhinc.NHINCLib.NullChecker;
|
---|
24 | //import gov.hhs.fha.nhinc.subscription.SubscriptionItemType;
|
---|
25 | //import java.util.List;
|
---|
26 | //import javax.xml.bind.JAXBElement;
|
---|
27 | //import javax.xml.namespace.QName;
|
---|
28 | //import org.oasis_open.docs.wsn.b_2.FilterType;
|
---|
29 | //import org.oasis_open.docs.wsn.b_2.NotificationMessageHolderType;
|
---|
30 | //import org.oasis_open.docs.wsn.b_2.NotificationMessageHolderType.Message;
|
---|
31 | //import org.oasis_open.docs.wsn.b_2.Notify;
|
---|
32 | //import org.oasis_open.docs.wsn.b_2.TopicExpressionType;
|
---|
33 | //import org.oasis_open.docs.wsn.b_2.Subscribe;
|
---|
34 | /**
|
---|
35 | *
|
---|
36 | * @author rayj
|
---|
37 | */
|
---|
38 | public class TopicHelper {
|
---|
39 |
|
---|
40 | public static DetermineRootTopicFromNotifyResponseType determineRootTopicFromNotify(gov.hhs.fha.nhinc.common.subscriptiondte.DetermineRootTopicFromNotifyRequestType request) {
|
---|
41 | Notify notify = request.getNotify();
|
---|
42 | DetermineRootTopicFromNotifyResponseType response = new DetermineRootTopicFromNotifyResponseType();
|
---|
43 | response.setRootTopic(DetermineRootTopic(notify));
|
---|
44 | return response;
|
---|
45 | }
|
---|
46 |
|
---|
47 | public static String GetTopicValue(SubscriptionItemType subscriptionItem) {
|
---|
48 | gov.hhs.fha.nhinc.common.subscription.TopicExpressionType topic;
|
---|
49 | topic = GetTopic(subscriptionItem);
|
---|
50 | String topicValue = null;
|
---|
51 | if (topic != null) {
|
---|
52 | topicValue = topic.getValue();
|
---|
53 | }
|
---|
54 | return topicValue;
|
---|
55 | }
|
---|
56 |
|
---|
57 | public static gov.hhs.fha.nhinc.common.subscription.TopicExpressionType GetTopic(SubscriptionItemType subscriptionItem) {
|
---|
58 | gov.hhs.fha.nhinc.common.subscription.TopicExpressionType topic = null;
|
---|
59 | if ((subscriptionItem != null) && (subscriptionItem.getSubscriptionCriteria() != null) & (subscriptionItem.getSubscriptionCriteria().getTopicExpression() != null)) {
|
---|
60 | topic = subscriptionItem.getSubscriptionCriteria().getTopicExpression();
|
---|
61 | }
|
---|
62 | return topic;
|
---|
63 | }
|
---|
64 |
|
---|
65 | public static gov.hhs.fha.nhinc.common.subscription.TopicExpressionType ConvertNhinTopicToEntityTopic(org.oasis_open.docs.wsn.b_2.TopicExpressionType nhinTopic) {
|
---|
66 | gov.hhs.fha.nhinc.common.subscription.TopicExpressionType entityTopic = null;
|
---|
67 |
|
---|
68 | if (nhinTopic != null) {
|
---|
69 | entityTopic = new gov.hhs.fha.nhinc.common.subscription.TopicExpressionType();
|
---|
70 | entityTopic.setDialect(nhinTopic.getDialect());
|
---|
71 | entityTopic.setValue(GetTopicSimpleValue(nhinTopic));
|
---|
72 | }
|
---|
73 |
|
---|
74 | return entityTopic;
|
---|
75 | }
|
---|
76 |
|
---|
77 | public static org.oasis_open.docs.wsn.b_2.TopicExpressionType GetTopic(Subscribe subscribe) {
|
---|
78 | org.oasis_open.docs.wsn.b_2.TopicExpressionType topicExpression = null;
|
---|
79 | FilterType filter = subscribe.getFilter();
|
---|
80 | if (filter != null) {
|
---|
81 | for (Object filterItem : filter.getAny()) {
|
---|
82 | org.oasis_open.docs.wsn.b_2.TopicExpressionType value = null;
|
---|
83 | value = GetRawTopicExpressionFromAny(filterItem);
|
---|
84 | if (value != null) {
|
---|
85 | topicExpression = value;
|
---|
86 | }
|
---|
87 | }
|
---|
88 | }
|
---|
89 |
|
---|
90 | if (topicExpression == null) {
|
---|
91 | String rootTopicExpression = DetermineRootTopicFromObject(subscribe.getAny());
|
---|
92 | if (rootTopicExpression != null) {
|
---|
93 | topicExpression = new org.oasis_open.docs.wsn.b_2.TopicExpressionType();
|
---|
94 | topicExpression.getContent().add(rootTopicExpression);
|
---|
95 | topicExpression.setDialect("http://doc.oasis-open.org/wsn/t-1/TopicExpression/Simple");
|
---|
96 | }
|
---|
97 | }
|
---|
98 | return topicExpression;
|
---|
99 | }
|
---|
100 |
|
---|
101 | public static org.oasis_open.docs.wsn.b_2.TopicExpressionType GetTopic(org.oasis_open.docs.wsn.b_2.Notify notify) {
|
---|
102 | org.oasis_open.docs.wsn.b_2.TopicExpressionType topic = null;
|
---|
103 | org.oasis_open.docs.wsn.b_2.NotificationMessageHolderType notificationMessage = NotifyHelper.getNotificationMessageHolder(notify);
|
---|
104 | if (notificationMessage != null) {
|
---|
105 | topic = notificationMessage.getTopic();
|
---|
106 | }
|
---|
107 | return topic;
|
---|
108 | }
|
---|
109 |
|
---|
110 | private static String GetTopicSimpleValue(org.oasis_open.docs.wsn.b_2.Notify notify) {
|
---|
111 | return GetTopicSimpleValue(GetTopic(notify));
|
---|
112 | }
|
---|
113 |
|
---|
114 | private static String GetTopicSimpleValue(org.oasis_open.docs.wsn.b_2.TopicExpressionType topic) {
|
---|
115 | String value = null;
|
---|
116 | if (topic != null) {
|
---|
117 | List<Object> content;
|
---|
118 | content = topic.getContent();
|
---|
119 | if ((content != null) && (content.size() == 1)) {
|
---|
120 | Object singleContent;
|
---|
121 | singleContent = content.get(0);
|
---|
122 | if (singleContent instanceof String) {
|
---|
123 | value = (String) singleContent;
|
---|
124 | value = value.trim();
|
---|
125 | }
|
---|
126 | }
|
---|
127 | }
|
---|
128 | return value;
|
---|
129 | }
|
---|
130 |
|
---|
131 | private static String DetermineRootTopic(org.oasis_open.docs.wsn.b_2.Notify notify) {
|
---|
132 | String topic = GetTopicSimpleValue(notify);
|
---|
133 | Message message;
|
---|
134 |
|
---|
135 | if (NullChecker.isNullish(topic)) {
|
---|
136 | //topic not supplied, so need to determine based on some node
|
---|
137 | NotificationMessageHolderType notificationMessage = NotifyHelper.getNotificationMessageHolder(notify);
|
---|
138 | message = notificationMessage.getMessage();
|
---|
139 | if (message != null) {
|
---|
140 | topic = DetermineRootTopicFromObject(message.getAny());
|
---|
141 | }
|
---|
142 |
|
---|
143 | }
|
---|
144 | return topic;
|
---|
145 | }
|
---|
146 |
|
---|
147 | private static String DetermineRootTopicFromObject(Object value) {
|
---|
148 | String topic = null;
|
---|
149 | if (value instanceof JAXBElement) {
|
---|
150 | JAXBElement jb = (JAXBElement) value;
|
---|
151 | if (CompareQName(jb.getName(), "urn:ihe:iti:xds-b:2007", "RetrieveDocumentSetRequest")) {
|
---|
152 | topic = "document";
|
---|
153 | } else if (CompareQName(jb.getName(), "urn:oasis:names:tc:ebxml-regrep:xsd:rim:3.0", "AdhocQuery")) {
|
---|
154 | topic = "document";
|
---|
155 | }
|
---|
156 | } else if (value instanceof ArrayList) {
|
---|
157 | ArrayList valueList = (ArrayList) value;
|
---|
158 | if (valueList.size() >= 1) {
|
---|
159 | return DetermineRootTopicFromObject(valueList.get(0));
|
---|
160 | }
|
---|
161 | }
|
---|
162 | return topic;
|
---|
163 | }
|
---|
164 |
|
---|
165 | private static org.oasis_open.docs.wsn.b_2.TopicExpressionType GetRawTopicExpressionFromAny(Object value) {
|
---|
166 | org.oasis_open.docs.wsn.b_2.TopicExpressionType topicExpression = null;
|
---|
167 | if (value instanceof JAXBElement) {
|
---|
168 | JAXBElement jb = (JAXBElement) value;
|
---|
169 | topicExpression = GetRawTopicExpressionFromAny(jb.getValue());
|
---|
170 | } else if (value instanceof org.oasis_open.docs.wsn.b_2.TopicExpressionType) {
|
---|
171 | topicExpression = (org.oasis_open.docs.wsn.b_2.TopicExpressionType) value;
|
---|
172 | }
|
---|
173 |
|
---|
174 | return topicExpression;
|
---|
175 | }
|
---|
176 |
|
---|
177 | private static boolean CompareQName(QName qname, String namespace, String localname) {
|
---|
178 | return ((qname.getLocalPart().contentEquals(localname)) && (qname.getNamespaceURI().contentEquals(namespace)));
|
---|
179 | }
|
---|
180 | }
|
---|