/* * To change this template, choose Tools | Templates * and open the template in the editor. */ package gov.hhs.fha.nhinc.subscription.dte; //import gov.hhs.fha.nhinc.subscriptiondte.*; import gov.hhs.fha.nhinc.common.subscription.SubscriptionItemType; import gov.hhs.fha.nhinc.common.subscriptiondte.DetermineRootTopicFromNotifyResponseType; import gov.hhs.fha.nhinc.nhinclib.NullChecker; import java.util.ArrayList; import java.util.List; //import org.oasis_open.docs.wsn.b_2.TopicExpressionType; import javax.xml.bind.JAXBElement; import javax.xml.namespace.QName; import org.oasis_open.docs.wsn.b_2.FilterType; import org.oasis_open.docs.wsn.b_2.NotificationMessageHolderType; import org.oasis_open.docs.wsn.b_2.NotificationMessageHolderType.Message; import org.oasis_open.docs.wsn.b_2.Notify; import org.oasis_open.docs.wsn.b_2.Subscribe; //import gov.hhs.fha.nhinc.NHINCLib.NullChecker; //import gov.hhs.fha.nhinc.subscription.SubscriptionItemType; //import java.util.List; //import javax.xml.bind.JAXBElement; //import javax.xml.namespace.QName; //import org.oasis_open.docs.wsn.b_2.FilterType; //import org.oasis_open.docs.wsn.b_2.NotificationMessageHolderType; //import org.oasis_open.docs.wsn.b_2.NotificationMessageHolderType.Message; //import org.oasis_open.docs.wsn.b_2.Notify; //import org.oasis_open.docs.wsn.b_2.TopicExpressionType; //import org.oasis_open.docs.wsn.b_2.Subscribe; /** * * @author rayj */ public class TopicHelper { public static DetermineRootTopicFromNotifyResponseType determineRootTopicFromNotify(gov.hhs.fha.nhinc.common.subscriptiondte.DetermineRootTopicFromNotifyRequestType request) { Notify notify = request.getNotify(); DetermineRootTopicFromNotifyResponseType response = new DetermineRootTopicFromNotifyResponseType(); response.setRootTopic(DetermineRootTopic(notify)); return response; } public static String GetTopicValue(SubscriptionItemType subscriptionItem) { gov.hhs.fha.nhinc.common.subscription.TopicExpressionType topic; topic = GetTopic(subscriptionItem); String topicValue = null; if (topic != null) { topicValue = topic.getValue(); } return topicValue; } public static gov.hhs.fha.nhinc.common.subscription.TopicExpressionType GetTopic(SubscriptionItemType subscriptionItem) { gov.hhs.fha.nhinc.common.subscription.TopicExpressionType topic = null; if ((subscriptionItem != null) && (subscriptionItem.getSubscriptionCriteria() != null) & (subscriptionItem.getSubscriptionCriteria().getTopicExpression() != null)) { topic = subscriptionItem.getSubscriptionCriteria().getTopicExpression(); } return topic; } public static gov.hhs.fha.nhinc.common.subscription.TopicExpressionType ConvertNhinTopicToEntityTopic(org.oasis_open.docs.wsn.b_2.TopicExpressionType nhinTopic) { gov.hhs.fha.nhinc.common.subscription.TopicExpressionType entityTopic = null; if (nhinTopic != null) { entityTopic = new gov.hhs.fha.nhinc.common.subscription.TopicExpressionType(); entityTopic.setDialect(nhinTopic.getDialect()); entityTopic.setValue(GetTopicSimpleValue(nhinTopic)); } return entityTopic; } public static org.oasis_open.docs.wsn.b_2.TopicExpressionType GetTopic(Subscribe subscribe) { org.oasis_open.docs.wsn.b_2.TopicExpressionType topicExpression = null; FilterType filter = subscribe.getFilter(); if (filter != null) { for (Object filterItem : filter.getAny()) { org.oasis_open.docs.wsn.b_2.TopicExpressionType value = null; value = GetRawTopicExpressionFromAny(filterItem); if (value != null) { topicExpression = value; } } } if (topicExpression == null) { String rootTopicExpression = DetermineRootTopicFromObject(subscribe.getAny()); if (rootTopicExpression != null) { topicExpression = new org.oasis_open.docs.wsn.b_2.TopicExpressionType(); topicExpression.getContent().add(rootTopicExpression); topicExpression.setDialect("http://doc.oasis-open.org/wsn/t-1/TopicExpression/Simple"); } } return topicExpression; } public static org.oasis_open.docs.wsn.b_2.TopicExpressionType GetTopic(org.oasis_open.docs.wsn.b_2.Notify notify) { org.oasis_open.docs.wsn.b_2.TopicExpressionType topic = null; org.oasis_open.docs.wsn.b_2.NotificationMessageHolderType notificationMessage = NotifyHelper.getNotificationMessageHolder(notify); if (notificationMessage != null) { topic = notificationMessage.getTopic(); } return topic; } private static String GetTopicSimpleValue(org.oasis_open.docs.wsn.b_2.Notify notify) { return GetTopicSimpleValue(GetTopic(notify)); } private static String GetTopicSimpleValue(org.oasis_open.docs.wsn.b_2.TopicExpressionType topic) { String value = null; if (topic != null) { List content; content = topic.getContent(); if ((content != null) && (content.size() == 1)) { Object singleContent; singleContent = content.get(0); if (singleContent instanceof String) { value = (String) singleContent; value = value.trim(); } } } return value; } private static String DetermineRootTopic(org.oasis_open.docs.wsn.b_2.Notify notify) { String topic = GetTopicSimpleValue(notify); Message message; if (NullChecker.isNullish(topic)) { //topic not supplied, so need to determine based on some node NotificationMessageHolderType notificationMessage = NotifyHelper.getNotificationMessageHolder(notify); message = notificationMessage.getMessage(); if (message != null) { topic = DetermineRootTopicFromObject(message.getAny()); } } return topic; } private static String DetermineRootTopicFromObject(Object value) { String topic = null; if (value instanceof JAXBElement) { JAXBElement jb = (JAXBElement) value; if (CompareQName(jb.getName(), "urn:ihe:iti:xds-b:2007", "RetrieveDocumentSetRequest")) { topic = "document"; } else if (CompareQName(jb.getName(), "urn:oasis:names:tc:ebxml-regrep:xsd:rim:3.0", "AdhocQuery")) { topic = "document"; } } else if (value instanceof ArrayList) { ArrayList valueList = (ArrayList) value; if (valueList.size() >= 1) { return DetermineRootTopicFromObject(valueList.get(0)); } } return topic; } private static org.oasis_open.docs.wsn.b_2.TopicExpressionType GetRawTopicExpressionFromAny(Object value) { org.oasis_open.docs.wsn.b_2.TopicExpressionType topicExpression = null; if (value instanceof JAXBElement) { JAXBElement jb = (JAXBElement) value; topicExpression = GetRawTopicExpressionFromAny(jb.getValue()); } else if (value instanceof org.oasis_open.docs.wsn.b_2.TopicExpressionType) { topicExpression = (org.oasis_open.docs.wsn.b_2.TopicExpressionType) value; } return topicExpression; } private static boolean CompareQName(QName qname, String namespace, String localname) { return ((qname.getLocalPart().contentEquals(localname)) && (qname.getNamespaceURI().contentEquals(namespace))); } }