[507] | 1 | package gov.hhs.fha.nhinc.connectmgr;
|
---|
| 2 |
|
---|
| 3 | import gov.hhs.fha.nhinc.connectmgr.data.CMBindingDescriptions;
|
---|
| 4 | import java.util.HashMap;
|
---|
| 5 | import java.util.List;
|
---|
| 6 | import java.util.ArrayList;
|
---|
| 7 | import java.util.HashSet;
|
---|
| 8 | import java.util.Collection;
|
---|
| 9 |
|
---|
| 10 | import org.apache.commons.logging.Log;
|
---|
| 11 | import org.apache.commons.logging.LogFactory;
|
---|
| 12 |
|
---|
| 13 | import gov.hhs.fha.nhinc.connectmgr.data.CMBindingTemplates;
|
---|
| 14 | import gov.hhs.fha.nhinc.connectmgr.data.CMBindingTemplate;
|
---|
| 15 | import gov.hhs.fha.nhinc.connectmgr.data.CMBusinessEntity;
|
---|
| 16 | import gov.hhs.fha.nhinc.connectmgr.data.CMBusinessEntities;
|
---|
| 17 | import gov.hhs.fha.nhinc.connectmgr.data.CMBusinessDescriptions;
|
---|
| 18 | import gov.hhs.fha.nhinc.connectmgr.data.CMBusinessNames;
|
---|
| 19 | import gov.hhs.fha.nhinc.connectmgr.data.CMBusinessServices;
|
---|
| 20 | import gov.hhs.fha.nhinc.connectmgr.data.CMBusinessService;
|
---|
| 21 | import gov.hhs.fha.nhinc.connectmgr.data.CMInternalConnectionInfo;
|
---|
| 22 | import gov.hhs.fha.nhinc.connectmgr.data.CMInternalConnectionInfos;
|
---|
| 23 | import gov.hhs.fha.nhinc.connectmgr.data.CMInternalConnInfoService;
|
---|
| 24 | import gov.hhs.fha.nhinc.connectmgr.data.CMInternalConnectionInfosXML;
|
---|
| 25 | import gov.hhs.fha.nhinc.connectmgr.data.CMUDDIConnectionInfo;
|
---|
| 26 | import gov.hhs.fha.nhinc.connectmgr.data.CMUDDIConnectionInfoXML;
|
---|
| 27 | import gov.hhs.fha.nhinc.connectmgr.data.CMHomeCommunity;
|
---|
| 28 | import gov.hhs.fha.nhinc.properties.PropertyAccessor;
|
---|
| 29 |
|
---|
| 30 | import gov.hhs.fha.nhinc.util.StringUtil;
|
---|
| 31 | import java.io.File;
|
---|
| 32 | import java.util.Date;
|
---|
| 33 |
|
---|
| 34 | /**
|
---|
| 35 | * This class is used to manage the Connection Manager's cache. It handles
|
---|
| 36 | * both internal connection settings and UDDI connection settings. If there is
|
---|
| 37 | * a collision for a connection between the UDDI and the Internal settings, the
|
---|
| 38 | * internal one will be used.
|
---|
| 39 | *
|
---|
| 40 | * @author Les Westberg
|
---|
| 41 | */
|
---|
| 42 | public class ConnectionManagerCache
|
---|
| 43 | {
|
---|
| 44 | private static Log log = LogFactory.getLog(ConnectionManagerCache.class);
|
---|
| 45 | private static final String CRLF = System.getProperty("line.separator");
|
---|
| 46 | private static final String UDDI_XML_FILE_NAME = "uddiConnectionInfo.xml";
|
---|
| 47 | private static final String INTERNAL_XML_FILE_NAME = "internalConnectionInfo.xml";
|
---|
| 48 | private static final String NHINC_PROPERTIES_DIR = "NHINC_PROPERTIES_DIR";
|
---|
| 49 |
|
---|
| 50 | // Hash maps for the UDDI connectin information. This hash map is keyed by home community ID.
|
---|
| 51 | //--------------------------------------------------------------------------------------------
|
---|
| 52 | private static HashMap<String, CMBusinessEntity> m_hUDDIConnectInfo = new HashMap<String, CMBusinessEntity>(); // Array of connection information
|
---|
| 53 | private static boolean m_bUDDILoaded = false; // TRUE if the properties have been loaded
|
---|
| 54 | private static long m_lUDDIFileLastModified = 0;
|
---|
| 55 |
|
---|
| 56 | // Hash maps for the Internal connection information. This hash map is keyed by home community ID.
|
---|
| 57 | //--------------------------------------------------------------------------------------------------
|
---|
| 58 | private static HashMap<String, CMInternalConnectionInfo> m_hInternalConnectInfo = new HashMap<String, CMInternalConnectionInfo>(); // Array of connection information
|
---|
| 59 | private static boolean m_bInternalLoaded = false; // TRUE if the properties have been loaded
|
---|
| 60 | private static long m_lInternalFileLastModified = 0;
|
---|
| 61 |
|
---|
| 62 | // Variables for managing the location of the XML files.
|
---|
| 63 | //-------------------------------------------------------
|
---|
| 64 | private static String m_sPropertyFileDir = "";
|
---|
| 65 | private static String m_sUDDIXMLfileDir = "";
|
---|
| 66 | private static String m_sInternalXMLFileDir = "";
|
---|
| 67 | private static String m_sFileSeparator = System.getProperty("file.separator");
|
---|
| 68 | private static final String m_sFailedEnvVarMessage = "Unable to access environment variable: NHINC_PROPERTIES_DIR.";
|
---|
| 69 | private static boolean m_bFailedToLoadEnvVar = false;
|
---|
| 70 |
|
---|
| 71 | static
|
---|
| 72 | {
|
---|
| 73 | String sValue = System.getenv(NHINC_PROPERTIES_DIR);
|
---|
| 74 | if ((sValue != null) && (sValue.length() > 0))
|
---|
| 75 | {
|
---|
| 76 | // Set it up so that we always have a "/" at the end - in case
|
---|
| 77 | //------------------------------------------------------------
|
---|
| 78 | if ((sValue.endsWith("/")) || (sValue.endsWith("\\")))
|
---|
| 79 | {
|
---|
| 80 | m_sPropertyFileDir = sValue;
|
---|
| 81 | }
|
---|
| 82 | else
|
---|
| 83 | {
|
---|
| 84 | m_sPropertyFileDir = sValue + m_sFileSeparator;
|
---|
| 85 | }
|
---|
| 86 |
|
---|
| 87 | m_sUDDIXMLfileDir = m_sPropertyFileDir + UDDI_XML_FILE_NAME;
|
---|
| 88 | m_sInternalXMLFileDir = m_sPropertyFileDir + INTERNAL_XML_FILE_NAME;
|
---|
| 89 | }
|
---|
| 90 | else
|
---|
| 91 | {
|
---|
| 92 | log.error(m_sFailedEnvVarMessage);
|
---|
| 93 | m_bFailedToLoadEnvVar = true;
|
---|
| 94 | }
|
---|
| 95 | }
|
---|
| 96 |
|
---|
| 97 | /**
|
---|
| 98 | * This class is used for testing purposes so that the file locations can be overridden
|
---|
| 99 | * to point to a controlled location available for unit tests.
|
---|
| 100 | *
|
---|
| 101 | * @param sUDDIFileName The path and file name for the UDDI XML file.
|
---|
| 102 | * @param sInternalConnFileName The path and file name for the Internal Connectil File Name.
|
---|
| 103 | */
|
---|
| 104 | public static void overrideFileLocations(String sUDDIFileName, String sInternalConnFileName)
|
---|
| 105 | {
|
---|
| 106 | m_sUDDIXMLfileDir = sUDDIFileName;
|
---|
| 107 | m_sInternalXMLFileDir = sInternalConnFileName;
|
---|
| 108 | }
|
---|
| 109 |
|
---|
| 110 | /**
|
---|
| 111 | * This method is used to load the UDDI Connection Infomration form the
|
---|
| 112 | * uddiConnectionInfo.xml file.
|
---|
| 113 | */
|
---|
| 114 | private static void loadUDDIConnectionInfo()
|
---|
| 115 | throws ConnectionManagerException
|
---|
| 116 | {
|
---|
| 117 | // We can only proceed if we know where the files are...
|
---|
| 118 | //--------------------------------------------------------
|
---|
| 119 | if (m_bFailedToLoadEnvVar)
|
---|
| 120 | {
|
---|
| 121 | throw new ConnectionManagerException(m_sFailedEnvVarMessage);
|
---|
| 122 | }
|
---|
| 123 |
|
---|
| 124 | String sUddiXml = "";
|
---|
| 125 |
|
---|
| 126 | try
|
---|
| 127 | {
|
---|
| 128 | sUddiXml = StringUtil.readTextFile(m_sUDDIXMLfileDir);
|
---|
| 129 | File fUDDIFile = new File(m_sUDDIXMLfileDir);
|
---|
| 130 | if (fUDDIFile.exists())
|
---|
| 131 | {
|
---|
| 132 | m_lUDDIFileLastModified = fUDDIFile.lastModified();
|
---|
| 133 | }
|
---|
| 134 | else
|
---|
| 135 | {
|
---|
| 136 | m_lUDDIFileLastModified = 0;
|
---|
| 137 | }
|
---|
| 138 | }
|
---|
| 139 | catch (Exception e)
|
---|
| 140 | {
|
---|
| 141 | String sErrorMessage = "Failed to read from file: '" + m_sUDDIXMLfileDir + "'. Error: " + e.getMessage();
|
---|
| 142 | log.error(sErrorMessage);
|
---|
| 143 | throw new ConnectionManagerException(sErrorMessage, e);
|
---|
| 144 | }
|
---|
| 145 |
|
---|
| 146 | log.debug("Setting UDDI cache to be: " + CRLF + sUddiXml);
|
---|
| 147 |
|
---|
| 148 | CMUDDIConnectionInfo oConnInfo = CMUDDIConnectionInfoXML.deserialize(sUddiXml);
|
---|
| 149 |
|
---|
| 150 | if (oConnInfo != null)
|
---|
| 151 | {
|
---|
| 152 | synchronized (m_hUDDIConnectInfo)
|
---|
| 153 | {
|
---|
| 154 | m_hUDDIConnectInfo.clear();
|
---|
| 155 |
|
---|
| 156 | if ((oConnInfo.getBusinessEntities() != null) &&
|
---|
| 157 | (oConnInfo.getBusinessEntities().getBusinessEntity() != null) &&
|
---|
| 158 | (oConnInfo.getBusinessEntities().getBusinessEntity().size() > 0))
|
---|
| 159 | {
|
---|
| 160 | for (CMBusinessEntity oEntity : oConnInfo.getBusinessEntities().getBusinessEntity())
|
---|
| 161 | {
|
---|
| 162 | String sHomeCommunityId = oEntity.getHomeCommunityId();
|
---|
| 163 | if ((sHomeCommunityId != null) && (sHomeCommunityId.length() > 0))
|
---|
| 164 | {
|
---|
| 165 | m_hUDDIConnectInfo.put(sHomeCommunityId, oEntity);
|
---|
| 166 | }
|
---|
| 167 | } // for (CMBusinessEntity oEntity : oConnInfo.getBusinessEntities().getBusinessEntity())
|
---|
| 168 | } // if ((oConnInfo.getBusinessEntities() != null) && ...
|
---|
| 169 |
|
---|
| 170 | m_bUDDILoaded = true;
|
---|
| 171 | } // synchronized (m_ohUDDIConnectInfo)
|
---|
| 172 | } // if (oConnInfo != null)
|
---|
| 173 | else
|
---|
| 174 | {
|
---|
| 175 | log.warn("No UDDI information was found in: " + m_sUDDIXMLfileDir);
|
---|
| 176 | }
|
---|
| 177 | }
|
---|
| 178 |
|
---|
| 179 | /**
|
---|
| 180 | * This returns true if the set of services contains a service for the given service name.
|
---|
| 181 | *
|
---|
| 182 | * @param oServices The set of services to search.
|
---|
| 183 | * @param sUniformServiceName The name of the service to search for.
|
---|
| 184 | * @return True if the service is found.
|
---|
| 185 | */
|
---|
| 186 | private static boolean containsService(CMBusinessServices oServices, String sUniformServiceName)
|
---|
| 187 | {
|
---|
| 188 | boolean bFound = false;
|
---|
| 189 |
|
---|
| 190 | if ((oServices != null) &&
|
---|
| 191 | (oServices.getBusinessService() != null) &&
|
---|
| 192 | (oServices.getBusinessService().size() > 0) &&
|
---|
| 193 | (sUniformServiceName != null) &&
|
---|
| 194 | (sUniformServiceName.length() > 0))
|
---|
| 195 | {
|
---|
| 196 | for (CMBusinessService oService : oServices.getBusinessService())
|
---|
| 197 | {
|
---|
| 198 | if ((oService.getUniformServiceName() != null) &&
|
---|
| 199 | (oService.getUniformServiceName().equals(sUniformServiceName)))
|
---|
| 200 | {
|
---|
| 201 | bFound = true;
|
---|
| 202 | }
|
---|
| 203 |
|
---|
| 204 | } // for (CMBusinessService oService : oServices.getBusinessService())
|
---|
| 205 | }
|
---|
| 206 |
|
---|
| 207 | return bFound;
|
---|
| 208 |
|
---|
| 209 | }
|
---|
| 210 |
|
---|
| 211 | /**
|
---|
| 212 | * This method merges the information from the internal connection information as well
|
---|
| 213 | * as the ones from the external conenctions. The internal information always
|
---|
| 214 | * overrides the external. When it comes to services, it does not do a piece wise compare
|
---|
| 215 | * of the services. If a service is defined internally, it will use the entire service.
|
---|
| 216 | *
|
---|
| 217 | * @param oInternalEntity The internal business entitie
|
---|
| 218 | * @param oUDDIEntity The UDDI entity
|
---|
| 219 | * @return The combined information to be sent out.
|
---|
| 220 | * @throws gov.hhs.fha.nhinc.connectmgr.ConnectionManagerException
|
---|
| 221 | */
|
---|
| 222 | private static CMBusinessEntity mergeBusinessEntityServices(CMBusinessEntity oInternalEntity,
|
---|
| 223 | CMBusinessEntity oUDDIEntity)
|
---|
| 224 | throws ConnectionManagerException
|
---|
| 225 | {
|
---|
| 226 | if ((oInternalEntity == null) &&
|
---|
| 227 | (oUDDIEntity != null))
|
---|
| 228 | {
|
---|
| 229 | return oUDDIEntity;
|
---|
| 230 | }
|
---|
| 231 | else if ((oInternalEntity != null) &&
|
---|
| 232 | (oUDDIEntity == null))
|
---|
| 233 | {
|
---|
| 234 | return oInternalEntity;
|
---|
| 235 | }
|
---|
| 236 | else if ((oInternalEntity == null) &&
|
---|
| 237 | (oUDDIEntity == null))
|
---|
| 238 | {
|
---|
| 239 | return null;
|
---|
| 240 | }
|
---|
| 241 |
|
---|
| 242 | // We are here so a merge needs to take place....
|
---|
| 243 | //------------------------------------------------
|
---|
| 244 | CMBusinessEntity oCombinedEntity = new CMBusinessEntity();
|
---|
| 245 |
|
---|
| 246 | // Start with the non service information from the UDDI
|
---|
| 247 | //------------------------------------------------------
|
---|
| 248 | oCombinedEntity.setBusinessKey(oUDDIEntity.getBusinessKey());
|
---|
| 249 | oCombinedEntity.setContacts(oUDDIEntity.getContacts());
|
---|
| 250 | oCombinedEntity.setDescriptions(oUDDIEntity.getDescriptions());
|
---|
| 251 | oCombinedEntity.setDiscoveryURLs(oUDDIEntity.getDiscoveryURLs());
|
---|
| 252 | oCombinedEntity.setFederalHIE(oUDDIEntity.isFederalHIE());
|
---|
| 253 | oCombinedEntity.setHomeCommunityId(oUDDIEntity.getHomeCommunityId());
|
---|
| 254 | oCombinedEntity.setNames(oUDDIEntity.getNames());
|
---|
| 255 | oCombinedEntity.setPublicKey(oUDDIEntity.getPublicKey());
|
---|
| 256 | oCombinedEntity.setPublicKeyURI(oUDDIEntity.getPublicKeyURI());
|
---|
| 257 | oCombinedEntity.setStates(oUDDIEntity.getStates());
|
---|
| 258 |
|
---|
| 259 | // Put in all of the services from the InternalConnection one next - they are the king...
|
---|
| 260 | //----------------------------------------------------------------------------------------
|
---|
| 261 | oCombinedEntity.setBusinessServices(oInternalEntity.getBusinessServices());
|
---|
| 262 | if (oCombinedEntity.getBusinessServices() == null)
|
---|
| 263 | {
|
---|
| 264 | oCombinedEntity.setBusinessServices(new CMBusinessServices());
|
---|
| 265 | }
|
---|
| 266 |
|
---|
| 267 | // Now only add in the ones from the UDDI that we do not have
|
---|
| 268 | //-------------------------------------------------------------
|
---|
| 269 | if ((oUDDIEntity.getBusinessServices() != null) &&
|
---|
| 270 | (oUDDIEntity.getBusinessServices().getBusinessService() != null) &&
|
---|
| 271 | (oUDDIEntity.getBusinessServices().getBusinessService().size() > 0))
|
---|
| 272 | {
|
---|
| 273 | for (CMBusinessService oService : oUDDIEntity.getBusinessServices().getBusinessService())
|
---|
| 274 | {
|
---|
| 275 | if (!containsService(oCombinedEntity.getBusinessServices(), oService.getUniformServiceName()))
|
---|
| 276 | {
|
---|
| 277 | oCombinedEntity.getBusinessServices().getBusinessService().add(oService);
|
---|
| 278 | }
|
---|
| 279 | } // for (CMBusinessService oService : oUDDIEntity.getBusinessServices().getBusinessService())
|
---|
| 280 | } // if ((oUDDIEntity.getBusinessServices() != null) && ...
|
---|
| 281 |
|
---|
| 282 |
|
---|
| 283 | return oCombinedEntity;
|
---|
| 284 | }
|
---|
| 285 |
|
---|
| 286 | /**
|
---|
| 287 | * This method simply checks to see if the cache is loaded. If it is not, then
|
---|
| 288 | * it is loaded as a byproduct of calling this method.
|
---|
| 289 | *
|
---|
| 290 | * @throws gov.hhs.fha.nhinc.connectmgr.ConnectionManagerException
|
---|
| 291 | */
|
---|
| 292 | private static void checkLoaded()
|
---|
| 293 | throws ConnectionManagerException
|
---|
| 294 | {
|
---|
| 295 | if (!m_bInternalLoaded)
|
---|
| 296 | {
|
---|
| 297 | forceRefreshInternalConnectCache();
|
---|
| 298 | }
|
---|
| 299 |
|
---|
| 300 | if (!m_bUDDILoaded)
|
---|
| 301 | {
|
---|
| 302 | forceRefreshUDDICache();
|
---|
| 303 | }
|
---|
| 304 |
|
---|
| 305 | // One last check for refreshing...
|
---|
| 306 | //---------------------------------
|
---|
| 307 | refreshIfExpired();
|
---|
| 308 | }
|
---|
| 309 |
|
---|
| 310 | /**
|
---|
| 311 | * This method is used to load the UDDI Connection Infomration form the
|
---|
| 312 | * uddiConnectionInfo.xml file.
|
---|
| 313 | */
|
---|
| 314 | private static void loadInternalConnectionInfo()
|
---|
| 315 | throws ConnectionManagerException
|
---|
| 316 | {
|
---|
| 317 | // We can only proceed if we know where the files are...
|
---|
| 318 | //--------------------------------------------------------
|
---|
| 319 | if (m_bFailedToLoadEnvVar)
|
---|
| 320 | {
|
---|
| 321 | throw new ConnectionManagerException(m_sFailedEnvVarMessage);
|
---|
| 322 | }
|
---|
| 323 |
|
---|
| 324 | String sInternalConnXml = "";
|
---|
| 325 |
|
---|
| 326 | try
|
---|
| 327 | {
|
---|
| 328 | sInternalConnXml = StringUtil.readTextFile(m_sInternalXMLFileDir);
|
---|
| 329 | File fInternalFile = new File(m_sInternalXMLFileDir);
|
---|
| 330 | if (fInternalFile.exists())
|
---|
| 331 | {
|
---|
| 332 | m_lInternalFileLastModified = fInternalFile.lastModified();
|
---|
| 333 | }
|
---|
| 334 | else
|
---|
| 335 | {
|
---|
| 336 | m_lInternalFileLastModified = 0;
|
---|
| 337 | }
|
---|
| 338 | }
|
---|
| 339 | catch (Exception e)
|
---|
| 340 | {
|
---|
| 341 | String sErrorMessage = "Failed to read from file: '" + m_sInternalXMLFileDir + "'. Error: " + e.getMessage();
|
---|
| 342 | log.error(sErrorMessage);
|
---|
| 343 | throw new ConnectionManagerException(sErrorMessage, e);
|
---|
| 344 | }
|
---|
| 345 |
|
---|
| 346 | log.debug("Setting internal connection cache to be: " + CRLF + sInternalConnXml);
|
---|
| 347 |
|
---|
| 348 | CMInternalConnectionInfos oConnInfos = CMInternalConnectionInfosXML.deserialize(sInternalConnXml);
|
---|
| 349 |
|
---|
| 350 | if (oConnInfos != null)
|
---|
| 351 | {
|
---|
| 352 | synchronized (m_hInternalConnectInfo)
|
---|
| 353 | {
|
---|
| 354 | m_hInternalConnectInfo.clear();
|
---|
| 355 |
|
---|
| 356 | if ((oConnInfos.getInternalConnectionInfo() != null) &&
|
---|
| 357 | (oConnInfos.getInternalConnectionInfo().size() > 0))
|
---|
| 358 | {
|
---|
| 359 | for (CMInternalConnectionInfo oConnInfo : oConnInfos.getInternalConnectionInfo())
|
---|
| 360 | {
|
---|
| 361 | String sHomeCommunityId = oConnInfo.getHomeCommunityId();
|
---|
| 362 | if ((sHomeCommunityId != null) && (sHomeCommunityId.length() > 0))
|
---|
| 363 | {
|
---|
| 364 | m_hInternalConnectInfo.put(sHomeCommunityId, oConnInfo);
|
---|
| 365 | }
|
---|
| 366 | } // for (CMInternalConnectionInfo oConnInfo : oConnInfos.getInternalConnectionInfo())
|
---|
| 367 | } // if ((oConnInfos.getInternalConnectionInfo() != null) &&...
|
---|
| 368 |
|
---|
| 369 | m_bInternalLoaded = true;
|
---|
| 370 |
|
---|
| 371 | } // synchronized (m_hInternalConnectInfo)
|
---|
| 372 | } // if (oConnInfos != null)
|
---|
| 373 | else
|
---|
| 374 | {
|
---|
| 375 | log.warn("No UDDI information was found in: " + m_sUDDIXMLfileDir);
|
---|
| 376 | }
|
---|
| 377 | }
|
---|
| 378 |
|
---|
| 379 | /**
|
---|
| 380 | * This method will cause the ConnectionManagerCache to refresh the UDDI connection data
|
---|
| 381 | * by replacing the cached UDDI information with the information in the uddiConnectionInfo.xml file.
|
---|
| 382 | * @throws ConnectionManagerException
|
---|
| 383 | */
|
---|
| 384 | public static void forceRefreshUDDICache()
|
---|
| 385 | throws ConnectionManagerException
|
---|
| 386 | {
|
---|
| 387 | loadUDDIConnectionInfo();
|
---|
| 388 | }
|
---|
| 389 |
|
---|
| 390 | /**
|
---|
| 391 | * This method will cause the ConnectionManagerCache to refresh the internal connection data
|
---|
| 392 | * by replacing the cached internal connection information with the information in
|
---|
| 393 | * the internalConnectionInfo.xml file.
|
---|
| 394 | * @throws ConnectionManagerException
|
---|
| 395 | */
|
---|
| 396 | public static void forceRefreshInternalConnectCache()
|
---|
| 397 | throws ConnectionManagerException
|
---|
| 398 | {
|
---|
| 399 | loadInternalConnectionInfo();
|
---|
| 400 | }
|
---|
| 401 |
|
---|
| 402 | /**
|
---|
| 403 | * This method checks to see if either cache has expired and forces a refresh if it has.
|
---|
| 404 | *
|
---|
| 405 | */
|
---|
| 406 | private static void refreshIfExpired()
|
---|
| 407 | throws ConnectionManagerException
|
---|
| 408 | {
|
---|
| 409 | long lUDDILastModified = 0;
|
---|
| 410 | long lInternalLastModified = 0;
|
---|
| 411 |
|
---|
| 412 | // Find out our refrhes timing from the properties file.
|
---|
| 413 | //-------------------------------------------------------
|
---|
| 414 | try
|
---|
| 415 | {
|
---|
| 416 | File fUDDIFile = new File(m_sUDDIXMLfileDir);
|
---|
| 417 | if (fUDDIFile.exists())
|
---|
| 418 | {
|
---|
| 419 | lUDDILastModified = fUDDIFile.lastModified();
|
---|
| 420 | }
|
---|
| 421 | File fInternalFile = new File (m_sInternalXMLFileDir);
|
---|
| 422 | if (fInternalFile.exists())
|
---|
| 423 | {
|
---|
| 424 | lInternalLastModified = fInternalFile.lastModified();
|
---|
| 425 | }
|
---|
| 426 | }
|
---|
| 427 | catch (Exception e)
|
---|
| 428 | {
|
---|
| 429 | // Assume a refresh is required... But log a message.
|
---|
| 430 | //----------------------------------------------------
|
---|
| 431 | String sErrorMessage = "Failed to retrieve last modified dates on the connection manager XML files." +
|
---|
| 432 | "Error: " + e.getMessage();
|
---|
| 433 | log.warn(sErrorMessage, e);
|
---|
| 434 | }
|
---|
| 435 |
|
---|
| 436 | // If we need to refresh the UDDI cache information.
|
---|
| 437 | //--------------------------------------------------
|
---|
| 438 | if (lUDDILastModified != m_lUDDIFileLastModified)
|
---|
| 439 | {
|
---|
| 440 | forceRefreshUDDICache();
|
---|
| 441 | log.info("UDDI cache was refreshed based on last modified time stamp change.");
|
---|
| 442 | }
|
---|
| 443 |
|
---|
| 444 | if (lInternalLastModified != m_lInternalFileLastModified)
|
---|
| 445 | {
|
---|
| 446 | forceRefreshInternalConnectCache();
|
---|
| 447 | log.info("Internal connection cache was refreshed based on last modified time stamp change.");
|
---|
| 448 | }
|
---|
| 449 | }
|
---|
| 450 |
|
---|
| 451 | /**
|
---|
| 452 | * This method extracts the home community information from the CMInternalConnectionInfo object
|
---|
| 453 | * and places it into a new CMHomeCommunity object and returns it.
|
---|
| 454 | *
|
---|
| 455 | * @param oConnInfo The connection information to be transformed.
|
---|
| 456 | * @return The HomeCommunity information.
|
---|
| 457 | */
|
---|
| 458 | private static CMHomeCommunity homeCommunityFromInternalConnectionInfo(CMInternalConnectionInfo oConnInfo)
|
---|
| 459 | {
|
---|
| 460 | CMHomeCommunity oComm = new CMHomeCommunity();
|
---|
| 461 |
|
---|
| 462 | if (oConnInfo != null)
|
---|
| 463 | {
|
---|
| 464 | if (oConnInfo.getHomeCommunityId() != null)
|
---|
| 465 | {
|
---|
| 466 | oComm.setHomeCommunityId(oConnInfo.getHomeCommunityId());
|
---|
| 467 | }
|
---|
| 468 |
|
---|
| 469 | if (oConnInfo.getName() != null)
|
---|
| 470 | {
|
---|
| 471 | oComm.setName(oConnInfo.getName());
|
---|
| 472 | }
|
---|
| 473 |
|
---|
| 474 | if (oConnInfo.getDescription() != null)
|
---|
| 475 | {
|
---|
| 476 | oComm.setDescription(oConnInfo.getDescription());
|
---|
| 477 | }
|
---|
| 478 | }
|
---|
| 479 |
|
---|
| 480 | return oComm;
|
---|
| 481 | }
|
---|
| 482 |
|
---|
| 483 | /**
|
---|
| 484 | * This method extracts the fields from the CMInternalConnectionInfo object and creats a
|
---|
| 485 | * CMBusinessEntity object with the data.
|
---|
| 486 | *
|
---|
| 487 | * @param oConnInfo The connection information to be transformed.
|
---|
| 488 | * @return The CMBusinessEntity object from the information.
|
---|
| 489 | */
|
---|
| 490 | private static CMBusinessEntity businessEntityFromInternalConnectionInfo(CMInternalConnectionInfo oConnInfo)
|
---|
| 491 | {
|
---|
| 492 | CMBusinessEntity oEntity = new CMBusinessEntity();
|
---|
| 493 |
|
---|
| 494 | if (oConnInfo != null)
|
---|
| 495 | {
|
---|
| 496 | // Home Community ID
|
---|
| 497 | if (oConnInfo.getHomeCommunityId() != null)
|
---|
| 498 | {
|
---|
| 499 | oEntity.setHomeCommunityId(oConnInfo.getHomeCommunityId());
|
---|
| 500 | }
|
---|
| 501 |
|
---|
| 502 | // Name
|
---|
| 503 | //------
|
---|
| 504 | if (oConnInfo.getName() != null)
|
---|
| 505 | {
|
---|
| 506 | CMBusinessNames oNames = new CMBusinessNames();
|
---|
| 507 | oEntity.setNames(oNames);
|
---|
| 508 | oNames.getBusinessName().add(oConnInfo.getName());
|
---|
| 509 | }
|
---|
| 510 |
|
---|
| 511 | // Description
|
---|
| 512 | //-------------
|
---|
| 513 | if (oConnInfo.getDescription() != null)
|
---|
| 514 | {
|
---|
| 515 | CMBusinessDescriptions oDescriptions = new CMBusinessDescriptions();
|
---|
| 516 | oEntity.setDescriptions(oDescriptions);
|
---|
| 517 | oDescriptions.getBusinessDescription().add(oConnInfo.getDescription());
|
---|
| 518 | }
|
---|
| 519 |
|
---|
| 520 | // Services
|
---|
| 521 | //----------
|
---|
| 522 | if ((oConnInfo.getServices() != null) &&
|
---|
| 523 | (oConnInfo.getServices().getService() != null) &&
|
---|
| 524 | (oConnInfo.getServices().getService().size() > 0))
|
---|
| 525 | {
|
---|
| 526 | CMBusinessServices oBusinessServices = new CMBusinessServices();
|
---|
| 527 | oEntity.setBusinessServices(oBusinessServices);
|
---|
| 528 |
|
---|
| 529 | for (CMInternalConnInfoService oService : oConnInfo.getServices().getService())
|
---|
| 530 | {
|
---|
| 531 | CMBusinessService oBusinessService = new CMBusinessService();
|
---|
| 532 | oBusinessServices.getBusinessService().add(oBusinessService);
|
---|
| 533 |
|
---|
| 534 | // Service Name
|
---|
| 535 | //-------------
|
---|
| 536 | if (oService.getName() != null)
|
---|
| 537 | {
|
---|
| 538 | oBusinessService.setUniformServiceName(oService.getName());
|
---|
| 539 | }
|
---|
| 540 |
|
---|
| 541 | // Description
|
---|
| 542 | //-------------
|
---|
| 543 | if (oService.getDescription() != null)
|
---|
| 544 | {
|
---|
| 545 | CMBindingDescriptions oBindingDescriptions = new CMBindingDescriptions();
|
---|
| 546 | oBusinessService.setDescriptions(oBindingDescriptions);
|
---|
| 547 | oBindingDescriptions.getDescription().add(oService.getDescription());
|
---|
| 548 | }
|
---|
| 549 |
|
---|
| 550 | // Is this External or internal?
|
---|
| 551 | //-------------------------------
|
---|
| 552 | if (oService.isExternalService())
|
---|
| 553 | {
|
---|
| 554 | oBusinessService.setInternalWebService(false);
|
---|
| 555 | }
|
---|
| 556 | else
|
---|
| 557 | {
|
---|
| 558 | oBusinessService.setInternalWebService(true);
|
---|
| 559 | }
|
---|
| 560 |
|
---|
| 561 | // Endpoint URL
|
---|
| 562 | //--------------
|
---|
| 563 | if (oService.getEndpointURL() != null)
|
---|
| 564 | {
|
---|
| 565 | CMBindingTemplates oTemplates = new CMBindingTemplates();
|
---|
| 566 | oBusinessService.setBindingTemplates(oTemplates);
|
---|
| 567 | CMBindingTemplate oTemplate = new CMBindingTemplate();
|
---|
| 568 | oTemplates.getBindingTemplate().add(oTemplate);
|
---|
| 569 | oTemplate.setEndpointURL(oService.getEndpointURL());
|
---|
| 570 | } // if (oService.getEndpointURL() != null)
|
---|
| 571 | } // for (CMInternalConnInfoService oService : oConnInfo.getServices().getService())
|
---|
| 572 | } // if ((oConnInfo.getServices() != null) &&
|
---|
| 573 | } // if (oConnInfo != null)
|
---|
| 574 |
|
---|
| 575 | return oEntity;
|
---|
| 576 | }
|
---|
| 577 |
|
---|
| 578 |
|
---|
| 579 | /**
|
---|
| 580 | * This method extracts the home community information from the CMBusinessEntity object
|
---|
| 581 | * and places it into a new CMHomeCommunity object and returns it.
|
---|
| 582 | *
|
---|
| 583 | * @param oConnInfo The connection information to be transformed.
|
---|
| 584 | * @return The HomeCommunity information.
|
---|
| 585 | */
|
---|
| 586 | private static CMHomeCommunity homeCommunityFromBusinessEntity(CMBusinessEntity oEntity)
|
---|
| 587 | {
|
---|
| 588 | CMHomeCommunity oComm = new CMHomeCommunity();
|
---|
| 589 |
|
---|
| 590 | if (oEntity != null)
|
---|
| 591 | {
|
---|
| 592 | if (oEntity.getHomeCommunityId() != null)
|
---|
| 593 | {
|
---|
| 594 | oComm.setHomeCommunityId(oEntity.getHomeCommunityId());
|
---|
| 595 | }
|
---|
| 596 |
|
---|
| 597 | // Since the UDDI can contain multiple names, we will only return the first one.
|
---|
| 598 | //------------------------------------------------------------------------------
|
---|
| 599 | if ((oEntity.getNames() != null) &&
|
---|
| 600 | (oEntity.getNames().getBusinessName() != null) &&
|
---|
| 601 | (oEntity.getNames().getBusinessName().size() > 0))
|
---|
| 602 | {
|
---|
| 603 | oComm.setName(oEntity.getNames().getBusinessName().get(0));
|
---|
| 604 | }
|
---|
| 605 |
|
---|
| 606 | // Since the UDDI can contain multiple descriptions, we will only return the first one.
|
---|
| 607 | //-------------------------------------------------------------------------------------
|
---|
| 608 | if ((oEntity.getDescriptions() != null) &&
|
---|
| 609 | (oEntity.getDescriptions().getBusinessDescription() != null) &&
|
---|
| 610 | (oEntity.getDescriptions().getBusinessDescription().size() > 0))
|
---|
| 611 | {
|
---|
| 612 | oComm.setDescription(oEntity.getDescriptions().getBusinessDescription().get(0));
|
---|
| 613 | }
|
---|
| 614 | }
|
---|
| 615 |
|
---|
| 616 | return oComm;
|
---|
| 617 | }
|
---|
| 618 |
|
---|
| 619 | /**
|
---|
| 620 | * This method will return a list of all home commuinities that are known by the
|
---|
| 621 | * connection manager.
|
---|
| 622 | *
|
---|
| 623 | * @return The list of all home communities known by the connection manager.
|
---|
| 624 | * @throws ConnectionManagerException
|
---|
| 625 | */
|
---|
| 626 | public static List<CMHomeCommunity> getAllCommunities()
|
---|
| 627 | throws ConnectionManagerException
|
---|
| 628 | {
|
---|
| 629 | HashSet<String> hHomeCommunities = new HashSet<String>();
|
---|
| 630 | ArrayList<CMHomeCommunity> oaHomeCommunities = new ArrayList<CMHomeCommunity>();
|
---|
| 631 |
|
---|
| 632 | checkLoaded();
|
---|
| 633 |
|
---|
| 634 | // First get the infomration from the internal connections.
|
---|
| 635 | //---------------------------------------------------------
|
---|
| 636 | Collection<CMInternalConnectionInfo> colInternConn = m_hInternalConnectInfo.values();
|
---|
| 637 | for (CMInternalConnectionInfo oConnInfo : colInternConn)
|
---|
| 638 | {
|
---|
| 639 | CMHomeCommunity oComm = homeCommunityFromInternalConnectionInfo(oConnInfo);
|
---|
| 640 | if ((oComm.getHomeCommunityId() != null) && (oComm.getHomeCommunityId().length() > 0))
|
---|
| 641 | {
|
---|
| 642 | hHomeCommunities.add(oComm.getHomeCommunityId());
|
---|
| 643 | oaHomeCommunities.add(oComm);
|
---|
| 644 | }
|
---|
| 645 | }
|
---|
| 646 |
|
---|
| 647 | // Next get the information from the UDDI connections - Only add them if we have not
|
---|
| 648 | // already gotten them from the internal settings.
|
---|
| 649 | //-----------------------------------------------------------------------------------
|
---|
| 650 | Collection<CMBusinessEntity> colEntity = m_hUDDIConnectInfo.values();
|
---|
| 651 | for (CMBusinessEntity oEntity : colEntity)
|
---|
| 652 | {
|
---|
| 653 | CMHomeCommunity oComm = homeCommunityFromBusinessEntity(oEntity);
|
---|
| 654 | if ((oComm.getHomeCommunityId() != null) &&
|
---|
| 655 | (oComm.getHomeCommunityId().length() > 0) &&
|
---|
| 656 | (!hHomeCommunities.contains(oComm.getHomeCommunityId()))) // make sure it is not alrady in the list
|
---|
| 657 | {
|
---|
| 658 | hHomeCommunities.add(oComm.getHomeCommunityId());
|
---|
| 659 | oaHomeCommunities.add(oComm);
|
---|
| 660 | }
|
---|
| 661 | }
|
---|
| 662 |
|
---|
| 663 | return oaHomeCommunities;
|
---|
| 664 |
|
---|
| 665 | }
|
---|
| 666 |
|
---|
| 667 | /**
|
---|
| 668 | * This method looks for the entity with the given home community ID and returns it.
|
---|
| 669 | *
|
---|
| 670 | * @param oEntities The entities to be searched.
|
---|
| 671 | * @param sHomeCommunityId The home community ID to search for.
|
---|
| 672 | * @return The business entity for that home community.
|
---|
| 673 | */
|
---|
| 674 | private static CMBusinessEntity extractBusinessEntity(CMBusinessEntities oEntities, String sHomeCommunityId)
|
---|
| 675 | {
|
---|
| 676 | if ((oEntities == null) ||
|
---|
| 677 | (oEntities.getBusinessEntity() == null) ||
|
---|
| 678 | (oEntities.getBusinessEntity().size() <= 0) ||
|
---|
| 679 | (sHomeCommunityId == null) ||
|
---|
| 680 | (sHomeCommunityId.length() <= 0))
|
---|
| 681 | {
|
---|
| 682 | return null;
|
---|
| 683 | }
|
---|
| 684 |
|
---|
| 685 | for (CMBusinessEntity oEntity : oEntities.getBusinessEntity())
|
---|
| 686 | {
|
---|
| 687 | if ((oEntity.getHomeCommunityId() != null) &&
|
---|
| 688 | (oEntity.getHomeCommunityId().equals(sHomeCommunityId)))
|
---|
| 689 | {
|
---|
| 690 | return oEntity;
|
---|
| 691 | }
|
---|
| 692 | }
|
---|
| 693 |
|
---|
| 694 | return null; // If we got here - we never found it.
|
---|
| 695 | }
|
---|
| 696 |
|
---|
| 697 | /**
|
---|
| 698 | * This method searches for the business entity in the list that has the same
|
---|
| 699 | * home community Id. If it finds it, it replaces it with this one. If it
|
---|
| 700 | * does not find it, then it adds this one to the list.
|
---|
| 701 | *
|
---|
| 702 | * @param oEntities The entities to search.
|
---|
| 703 | * @param oEntity The entity to replace...
|
---|
| 704 | */
|
---|
| 705 | private static void replaceBusinessEntity(CMBusinessEntities oEntities, CMBusinessEntity oEntity)
|
---|
| 706 | {
|
---|
| 707 | if ((oEntities == null) ||
|
---|
| 708 | (oEntity == null))
|
---|
| 709 | {
|
---|
| 710 | return; // there is nothing to do...
|
---|
| 711 | }
|
---|
| 712 |
|
---|
| 713 | int iCnt = oEntities.getBusinessEntity().size();
|
---|
| 714 | if (iCnt == 0)
|
---|
| 715 | {
|
---|
| 716 | oEntities.getBusinessEntity().add(oEntity);
|
---|
| 717 | return;
|
---|
| 718 | }
|
---|
| 719 |
|
---|
| 720 | boolean bReplaced = false;
|
---|
| 721 | for (int i = 0; i < iCnt; i++)
|
---|
| 722 | {
|
---|
| 723 | CMBusinessEntity oLocalEntity = oEntities.getBusinessEntity().get(i);
|
---|
| 724 | if ((oLocalEntity.getHomeCommunityId() != null) &&
|
---|
| 725 | (oEntity.getHomeCommunityId() != null) &&
|
---|
| 726 | (oLocalEntity.getHomeCommunityId().equals(oEntity.getHomeCommunityId())))
|
---|
| 727 | {
|
---|
| 728 | oEntities.getBusinessEntity().set(i, oEntity);
|
---|
| 729 | bReplaced = true;
|
---|
| 730 | break; // We are done - get out of here.
|
---|
| 731 | }
|
---|
| 732 | } // for (int i = 0; i < iCnt; i++)
|
---|
| 733 |
|
---|
| 734 | if (!bReplaced)
|
---|
| 735 | {
|
---|
| 736 | oEntities.getBusinessEntity().add(oEntity);
|
---|
| 737 | }
|
---|
| 738 | }
|
---|
| 739 |
|
---|
| 740 | /**
|
---|
| 741 | * This method will return a list of all business entities that are known by the
|
---|
| 742 | * connection manager.
|
---|
| 743 | *
|
---|
| 744 | * @return The list of all business entities known by the connection manager.
|
---|
| 745 | * @throws ConnectionManagerException
|
---|
| 746 | */
|
---|
| 747 | public static CMBusinessEntities getAllBusinessEntities()
|
---|
| 748 | throws ConnectionManagerException
|
---|
| 749 | {
|
---|
| 750 | HashSet<String> hEntities = new HashSet<String>();
|
---|
| 751 | CMBusinessEntities oEntities = new CMBusinessEntities();
|
---|
| 752 |
|
---|
| 753 | checkLoaded();
|
---|
| 754 |
|
---|
| 755 | // First get the infomration from the internal connections.
|
---|
| 756 | //---------------------------------------------------------
|
---|
| 757 | Collection<CMInternalConnectionInfo> colInternConn = m_hInternalConnectInfo.values();
|
---|
| 758 | for (CMInternalConnectionInfo oConnInfo : colInternConn)
|
---|
| 759 | {
|
---|
| 760 | CMBusinessEntity oEntity = businessEntityFromInternalConnectionInfo(oConnInfo);
|
---|
| 761 | if ((oEntity.getHomeCommunityId() != null) && (oEntity.getHomeCommunityId().length() > 0))
|
---|
| 762 | {
|
---|
| 763 | hEntities.add(oEntity.getHomeCommunityId());
|
---|
| 764 | oEntities.getBusinessEntity().add(oEntity);
|
---|
| 765 | }
|
---|
| 766 | }
|
---|
| 767 |
|
---|
| 768 | // Next get the information from the UDDI connections -
|
---|
| 769 | // If it is in the list, then merge the services. If not, then
|
---|
| 770 | // add it as is.
|
---|
| 771 | //-----------------------------------------------------------------------------------
|
---|
| 772 | Collection<CMBusinessEntity> colEntity = m_hUDDIConnectInfo.values();
|
---|
| 773 | for (CMBusinessEntity oEntity : colEntity)
|
---|
| 774 | {
|
---|
| 775 | if ((oEntity.getHomeCommunityId() != null) &&
|
---|
| 776 | (oEntity.getHomeCommunityId().length() > 0))
|
---|
| 777 | {
|
---|
| 778 | if (hEntities.contains(oEntity.getHomeCommunityId()))
|
---|
| 779 | {
|
---|
| 780 | CMBusinessEntity oExistingEntity = extractBusinessEntity(oEntities, oEntity.getHomeCommunityId());
|
---|
| 781 | if (oExistingEntity != null)
|
---|
| 782 | {
|
---|
| 783 | oExistingEntity = mergeBusinessEntityServices(oExistingEntity, oEntity);
|
---|
| 784 | replaceBusinessEntity(oEntities, oExistingEntity);
|
---|
| 785 | }
|
---|
| 786 | else
|
---|
| 787 | {
|
---|
| 788 | // We should never get here - but just in case...
|
---|
| 789 | oEntities.getBusinessEntity().add(oEntity);
|
---|
| 790 | }
|
---|
| 791 | }
|
---|
| 792 | else
|
---|
| 793 | {
|
---|
| 794 | hEntities.add(oEntity.getHomeCommunityId());
|
---|
| 795 | oEntities.getBusinessEntity().add(oEntity);
|
---|
| 796 | }
|
---|
| 797 | }
|
---|
| 798 | }
|
---|
| 799 |
|
---|
| 800 | return oEntities;
|
---|
| 801 |
|
---|
| 802 | }
|
---|
| 803 |
|
---|
| 804 | /**
|
---|
| 805 | * This class returns the business entity information associated with
|
---|
| 806 | * the specified home community ID.
|
---|
| 807 | *
|
---|
| 808 | * @param sHomeCommunityId The home commuinity ID that is being searched for.
|
---|
| 809 | * @return the business entity information for the specified home community.
|
---|
| 810 | * @throws gov.hhs.fha.nhinc.connectmgr.ConnectionManagerException
|
---|
| 811 | */
|
---|
| 812 | public static CMBusinessEntity getBusinessEntity(String sHomeCommunityId)
|
---|
| 813 | throws ConnectionManagerException
|
---|
| 814 | {
|
---|
| 815 | CMBusinessEntity oReturnEntity = null;
|
---|
| 816 |
|
---|
| 817 | checkLoaded();
|
---|
| 818 |
|
---|
| 819 | CMBusinessEntity oInternalEntity = null;
|
---|
| 820 | CMBusinessEntity oUDDIEntity = null;
|
---|
| 821 |
|
---|
| 822 | // First look in Internal connections...
|
---|
| 823 | //--------------------------------------
|
---|
| 824 | if (m_hInternalConnectInfo.containsKey(sHomeCommunityId))
|
---|
| 825 | {
|
---|
| 826 | CMInternalConnectionInfo oConnInfo = m_hInternalConnectInfo.get(sHomeCommunityId);
|
---|
| 827 | oInternalEntity = businessEntityFromInternalConnectionInfo(oConnInfo);
|
---|
| 828 | }
|
---|
| 829 |
|
---|
| 830 | // Look for a UDDI one
|
---|
| 831 | //--------------------
|
---|
| 832 | if (m_hUDDIConnectInfo.containsKey(sHomeCommunityId))
|
---|
| 833 | {
|
---|
| 834 | oUDDIEntity = m_hUDDIConnectInfo.get(sHomeCommunityId);
|
---|
| 835 | }
|
---|
| 836 |
|
---|
| 837 | if ((oInternalEntity != null) && (oUDDIEntity != null))
|
---|
| 838 | {
|
---|
| 839 | oReturnEntity = mergeBusinessEntityServices(oInternalEntity, oUDDIEntity);
|
---|
| 840 | }
|
---|
| 841 | else if (oInternalEntity != null)
|
---|
| 842 | {
|
---|
| 843 | oReturnEntity = oInternalEntity;
|
---|
| 844 | }
|
---|
| 845 | else if (oUDDIEntity != null)
|
---|
| 846 | {
|
---|
| 847 | oReturnEntity = oUDDIEntity;
|
---|
| 848 | }
|
---|
| 849 |
|
---|
| 850 | return oReturnEntity;
|
---|
| 851 | }
|
---|
| 852 |
|
---|
| 853 |
|
---|
| 854 | /**
|
---|
| 855 | * This method returns the business entity information for the set of home
|
---|
| 856 | * communities.
|
---|
| 857 | *
|
---|
| 858 | * @param saHomeCommunityId The set of home communities to be retrieved.
|
---|
| 859 | * @return The business entities found.
|
---|
| 860 | * @throws gov.hhs.fha.nhinc.connectmgr.ConnectionManagerException
|
---|
| 861 | */
|
---|
| 862 | public static CMBusinessEntities getBusinessEntitySet(List<String> saHomeCommunityId)
|
---|
| 863 | throws ConnectionManagerException
|
---|
| 864 | {
|
---|
| 865 | CMBusinessEntities oEntities = new CMBusinessEntities();
|
---|
| 866 |
|
---|
| 867 | checkLoaded();
|
---|
| 868 |
|
---|
| 869 | if ((saHomeCommunityId == null) || (saHomeCommunityId.size() <= 0))
|
---|
| 870 | {
|
---|
| 871 | return null;
|
---|
| 872 | }
|
---|
| 873 |
|
---|
| 874 | // We always first look in our internal list - then in the UDDI one...
|
---|
| 875 | //---------------------------------------------------------------------
|
---|
| 876 | for (String sHomeCommunityId : saHomeCommunityId)
|
---|
| 877 | {
|
---|
| 878 | CMBusinessEntity oEntity = getBusinessEntity(sHomeCommunityId);
|
---|
| 879 | if (oEntity != null)
|
---|
| 880 | {
|
---|
| 881 | oEntities.getBusinessEntity().add(oEntity);
|
---|
| 882 | }
|
---|
| 883 | }
|
---|
| 884 |
|
---|
| 885 | if (oEntities.getBusinessEntity().size() > 0)
|
---|
| 886 | {
|
---|
| 887 | return oEntities;
|
---|
| 888 | }
|
---|
| 889 | else
|
---|
| 890 | {
|
---|
| 891 | return null;
|
---|
| 892 | }
|
---|
| 893 | }
|
---|
| 894 |
|
---|
| 895 | /**
|
---|
| 896 | * This method retrieves the business entity information and service information
|
---|
| 897 | * for the specific home community and service name. Note: This will only return
|
---|
| 898 | * the information for the specified service. It will not return all services.
|
---|
| 899 | * Also note: This currently does not deal with version. If there are multiple
|
---|
| 900 | * versions of the same serviec, this will return the first one it sees in the list
|
---|
| 901 | * of services. As always, it will always first look in the InternalConnectionInfo
|
---|
| 902 | * cache for the business entity. If it finds the business entity there, it will not
|
---|
| 903 | * look in the UDDI cache. (This means that if the internal cache contains the
|
---|
| 904 | * given business entity, but it does not contain the requested service, it will
|
---|
| 905 | * behave as if the service does not exist - regardless of whether it is in the
|
---|
| 906 | * UDDI cache or not.
|
---|
| 907 | *
|
---|
| 908 | * @param sHomeCommunityId The home community ID of the gateway that is being looked up.
|
---|
| 909 | * @param sUniformServiceName The name of the service to locate.
|
---|
| 910 | * @return The Business Entity information along with only the requested service. if the
|
---|
| 911 | * service is not found, then null is returned.
|
---|
| 912 | * @throws ConnectionManagerException
|
---|
| 913 | */
|
---|
| 914 | public static CMBusinessEntity getBusinessEntityByServiceName(String sHomeCommunityId,
|
---|
| 915 | String sUniformServiceName)
|
---|
| 916 | throws ConnectionManagerException
|
---|
| 917 | {
|
---|
| 918 | CMBusinessEntity oEntity = null;
|
---|
| 919 |
|
---|
| 920 | checkLoaded();
|
---|
| 921 |
|
---|
| 922 | if ((sHomeCommunityId == null) || (sHomeCommunityId.length() <= 0) ||
|
---|
| 923 | (sUniformServiceName == null) || (sUniformServiceName.length() <= 0))
|
---|
| 924 | {
|
---|
| 925 | return null;
|
---|
| 926 | }
|
---|
| 927 |
|
---|
| 928 | CMBusinessEntity oInternalEntity = null;
|
---|
| 929 | CMBusinessEntity oUDDIEntity = null;
|
---|
| 930 |
|
---|
| 931 | if (m_hInternalConnectInfo.containsKey(sHomeCommunityId))
|
---|
| 932 | {
|
---|
| 933 | CMInternalConnectionInfo oConnInfo = m_hInternalConnectInfo.get(sHomeCommunityId);
|
---|
| 934 | oInternalEntity = businessEntityFromInternalConnectionInfo(oConnInfo);
|
---|
| 935 | }
|
---|
| 936 |
|
---|
| 937 | if (m_hUDDIConnectInfo.containsKey(sHomeCommunityId))
|
---|
| 938 | {
|
---|
| 939 | oUDDIEntity = m_hUDDIConnectInfo.get(sHomeCommunityId);
|
---|
| 940 | }
|
---|
| 941 |
|
---|
| 942 | CMBusinessEntity oCombinedEntity = null;
|
---|
| 943 | if ((oInternalEntity != null) && (oUDDIEntity != null))
|
---|
| 944 | {
|
---|
| 945 | oCombinedEntity = mergeBusinessEntityServices(oInternalEntity, oUDDIEntity);
|
---|
| 946 | }
|
---|
| 947 | else if (oInternalEntity != null)
|
---|
| 948 | {
|
---|
| 949 | oCombinedEntity = oInternalEntity;
|
---|
| 950 | }
|
---|
| 951 | else if (oUDDIEntity != null)
|
---|
| 952 | {
|
---|
| 953 | oCombinedEntity = oUDDIEntity;
|
---|
| 954 | }
|
---|
| 955 | else
|
---|
| 956 | {
|
---|
| 957 | return null; // We found nothing...
|
---|
| 958 | }
|
---|
| 959 |
|
---|
| 960 | // Now lets see if it has the service we are looking for.
|
---|
| 961 | //--------------------------------------------------------
|
---|
| 962 | CMBusinessService oTempService = null;
|
---|
| 963 |
|
---|
| 964 | if ((oCombinedEntity != null) &&
|
---|
| 965 | (oCombinedEntity.getBusinessServices() != null) &&
|
---|
| 966 | (oCombinedEntity.getBusinessServices().getBusinessService() != null) &&
|
---|
| 967 | (oCombinedEntity.getBusinessServices().getBusinessService().size() > 0))
|
---|
| 968 | {
|
---|
| 969 | for (CMBusinessService oService : oCombinedEntity.getBusinessServices().getBusinessService())
|
---|
| 970 | {
|
---|
| 971 | if (oService.getUniformServiceName().equals(sUniformServiceName))
|
---|
| 972 | {
|
---|
| 973 | oTempService = oService;
|
---|
| 974 | break; // We found it - get out of here...
|
---|
| 975 | }
|
---|
| 976 | }
|
---|
| 977 |
|
---|
| 978 | // Did we find the service we were looking for?
|
---|
| 979 | //----------------------------------------------
|
---|
| 980 | if (oTempService != null)
|
---|
| 981 | {
|
---|
| 982 | // Let's make a copy of the information - because we only want to return the
|
---|
| 983 | // one service.
|
---|
| 984 | //---------------------------------------------------------------------------
|
---|
| 985 | oEntity = new CMBusinessEntity();
|
---|
| 986 | oEntity.setBusinessKey(oCombinedEntity.getBusinessKey());
|
---|
| 987 | oEntity.setDiscoveryURLs(oCombinedEntity.getDiscoveryURLs());
|
---|
| 988 | oEntity.setNames(oCombinedEntity.getNames());
|
---|
| 989 | oEntity.setDescriptions(oCombinedEntity.getDescriptions());
|
---|
| 990 | oEntity.setContacts(oCombinedEntity.getContacts());
|
---|
| 991 | oEntity.setHomeCommunityId(oCombinedEntity.getHomeCommunityId());
|
---|
| 992 | oEntity.setStates(oCombinedEntity.getStates());
|
---|
| 993 | oEntity.setFederalHIE(oCombinedEntity.isFederalHIE());
|
---|
| 994 | oEntity.setPublicKeyURI(oCombinedEntity.getPublicKeyURI());
|
---|
| 995 | oEntity.setPublicKey(oCombinedEntity.getPublicKey());
|
---|
| 996 | oEntity.setBusinessServices(new CMBusinessServices());
|
---|
| 997 | oEntity.getBusinessServices().getBusinessService().add(oTempService);
|
---|
| 998 | }
|
---|
| 999 | }
|
---|
| 1000 |
|
---|
| 1001 | return oEntity;
|
---|
| 1002 |
|
---|
| 1003 | }
|
---|
| 1004 |
|
---|
| 1005 | /**
|
---|
| 1006 | * This method retrieves the business entity information and service information
|
---|
| 1007 | * for the specific home community and service name. Note: This will only return
|
---|
| 1008 | * the information for the specified service. It will not return all services.
|
---|
| 1009 | * Also note: This currently does not deal with version. If there are multiple
|
---|
| 1010 | * versions of the same serviec, this will return the first one it sees in the list
|
---|
| 1011 | * of services. As always, it will always first look in the InternalConnectionInfo
|
---|
| 1012 | * cache for the business entity. If it finds the business entity there, it will not
|
---|
| 1013 | * look in the UDDI cache. (This means that if the internal cache contains the
|
---|
| 1014 | * given business entity, but it does not contain the requested service, it will
|
---|
| 1015 | * behave as if the service does not exist - regardless of whether it is in the
|
---|
| 1016 | * UDDI cache or not.
|
---|
| 1017 | *
|
---|
| 1018 | * @param sHomeCommunityId The home community ID of the gateway that is being looked up.
|
---|
| 1019 | * @param sUniformServiceName The name of the service to locate.
|
---|
| 1020 | * @return The Business Entity information along with only the requested service. if the
|
---|
| 1021 | * service is not found, then null is returned.
|
---|
| 1022 | * @throws ConnectionManagerException
|
---|
| 1023 | */
|
---|
| 1024 | public static String getEndpointURLByServiceName(String sHomeCommunityId,
|
---|
| 1025 | String sUniformServiceName)
|
---|
| 1026 | throws ConnectionManagerException
|
---|
| 1027 | {
|
---|
| 1028 | String sEndpointURL = "";
|
---|
| 1029 |
|
---|
| 1030 | CMBusinessEntity oEntity = getBusinessEntityByServiceName(sHomeCommunityId, sUniformServiceName);
|
---|
| 1031 |
|
---|
| 1032 | if ((oEntity != null) &&
|
---|
| 1033 | (oEntity.getBusinessServices() != null) &&
|
---|
| 1034 | (oEntity.getBusinessServices().getBusinessService() != null) &&
|
---|
| 1035 | (oEntity.getBusinessServices().getBusinessService().size() > 0) &&
|
---|
| 1036 | (oEntity.getBusinessServices().getBusinessService().get(0) != null) &&
|
---|
| 1037 | (oEntity.getBusinessServices().getBusinessService().get(0).getBindingTemplates() != null) &&
|
---|
| 1038 | (oEntity.getBusinessServices().getBusinessService().get(0).getBindingTemplates().getBindingTemplate() != null) &&
|
---|
| 1039 | (oEntity.getBusinessServices().getBusinessService().get(0).getBindingTemplates().getBindingTemplate().size() > 0) &&
|
---|
| 1040 | (oEntity.getBusinessServices().getBusinessService().get(0).getBindingTemplates().getBindingTemplate().get(0) != null) &&
|
---|
| 1041 | (oEntity.getBusinessServices().getBusinessService().get(0).getBindingTemplates().getBindingTemplate().get(0).getEndpointURL() != null) &&
|
---|
| 1042 | (oEntity.getBusinessServices().getBusinessService().get(0).getBindingTemplates().getBindingTemplate().get(0).getEndpointURL().trim().length() > 0))
|
---|
| 1043 | {
|
---|
| 1044 | sEndpointURL = oEntity.getBusinessServices().getBusinessService().get(0).getBindingTemplates().getBindingTemplate().get(0).getEndpointURL().trim();
|
---|
| 1045 | }
|
---|
| 1046 |
|
---|
| 1047 | return sEndpointURL;
|
---|
| 1048 | }
|
---|
| 1049 |
|
---|
| 1050 |
|
---|
| 1051 | /**
|
---|
| 1052 | * This method retrieves the business entity information and service information
|
---|
| 1053 | * for the set of home communities and service name. Note: This will only return
|
---|
| 1054 | * the information for the specified service. It will not return all services.
|
---|
| 1055 | * Also note: This currently does not deal with version. If there are multiple
|
---|
| 1056 | * versions of the same service, this will return the first one it sees in the list
|
---|
| 1057 | * of services. As always, it will always first look in the InternalConnectionInfo
|
---|
| 1058 | * cache for the business entity. If it finds the business entity there, it will not
|
---|
| 1059 | * look in the UDDI cache. (This means that if the internal cache contains the
|
---|
| 1060 | * given business entity, but it does not contain the requested service, it will
|
---|
| 1061 | * behave as if the service does not exist - regardless of whether it is in the
|
---|
| 1062 | * UDDI cache or not.
|
---|
| 1063 | *
|
---|
| 1064 | * @param saHomeCommunityId The home community IDs of the gateways that is being looked up.
|
---|
| 1065 | * @param sUniformServiceName The name of the service to locate.
|
---|
| 1066 | * @return The Business Entity information along with only the requested service. If the
|
---|
| 1067 | * service is not found, it will not be returned even if the business entity
|
---|
| 1068 | * information exists.
|
---|
| 1069 | * @throws ConnectionManagerException
|
---|
| 1070 | */
|
---|
| 1071 | public static CMBusinessEntities getBusinessEntitySetByServiceName(List<String> saHomeCommunityId, String sUniformServiceName)
|
---|
| 1072 | throws ConnectionManagerException
|
---|
| 1073 | {
|
---|
| 1074 | CMBusinessEntities oEntities = new CMBusinessEntities();
|
---|
| 1075 |
|
---|
| 1076 | checkLoaded();
|
---|
| 1077 |
|
---|
| 1078 | if ((saHomeCommunityId == null) || (saHomeCommunityId.size() <= 0) ||
|
---|
| 1079 | (sUniformServiceName == null) || (sUniformServiceName.length() <= 0))
|
---|
| 1080 | {
|
---|
| 1081 | return null;
|
---|
| 1082 | }
|
---|
| 1083 |
|
---|
| 1084 | for (String sHomeCommunityId : saHomeCommunityId)
|
---|
| 1085 | {
|
---|
| 1086 | CMBusinessEntity oEntity = getBusinessEntityByServiceName(sHomeCommunityId, sUniformServiceName);
|
---|
| 1087 | if (oEntity != null)
|
---|
| 1088 | {
|
---|
| 1089 | oEntities.getBusinessEntity().add(oEntity);
|
---|
| 1090 | }
|
---|
| 1091 | }
|
---|
| 1092 |
|
---|
| 1093 | if (oEntities.getBusinessEntity().size() > 0)
|
---|
| 1094 | {
|
---|
| 1095 | return oEntities;
|
---|
| 1096 | }
|
---|
| 1097 | else
|
---|
| 1098 | {
|
---|
| 1099 | return null;
|
---|
| 1100 | }
|
---|
| 1101 | }
|
---|
| 1102 |
|
---|
| 1103 | /**
|
---|
| 1104 | * This method retrieves the business entity information and service information
|
---|
| 1105 | * for the set of home communities that contains a service by that service name.
|
---|
| 1106 | * Note: This will only return the information for the specified service. It will
|
---|
| 1107 | * not return all services. Also note: This currently does not deal with version. If
|
---|
| 1108 | * there are multiple versions of the same service, this will return the first one it sees in the list
|
---|
| 1109 | * of services. As always, it will always first look in the InternalConnectionInfo
|
---|
| 1110 | * cache for the business entity. If it finds the business entity there, it will not
|
---|
| 1111 | * look in the UDDI cache. (This means that if the internal cache contains the
|
---|
| 1112 | * given business entity, but it does not contain the requested service, it will
|
---|
| 1113 | * behave as if the service does not exist - regardless of whether it is in the
|
---|
| 1114 | * UDDI cache or not.
|
---|
| 1115 | *
|
---|
| 1116 | * @param sUniformServiceName The name of the service being searched for.
|
---|
| 1117 | * @return The business entities that have this service defined.
|
---|
| 1118 | * @throws gov.hhs.fha.nhinc.connectmgr.ConnectionManagerException
|
---|
| 1119 | */
|
---|
| 1120 | public static CMBusinessEntities getAllBusinessEntitySetByServiceName(String sUniformServiceName)
|
---|
| 1121 | throws ConnectionManagerException
|
---|
| 1122 | {
|
---|
| 1123 | CMBusinessEntities oEntities = new CMBusinessEntities();
|
---|
| 1124 |
|
---|
| 1125 | checkLoaded();
|
---|
| 1126 |
|
---|
| 1127 | HashSet<String> hKeys = new HashSet<String>();
|
---|
| 1128 |
|
---|
| 1129 | // This is a slick way to add them all and remove any duplicates...
|
---|
| 1130 | //------------------------------------------------------------------
|
---|
| 1131 | hKeys.addAll(m_hInternalConnectInfo.keySet());
|
---|
| 1132 | hKeys.addAll(m_hUDDIConnectInfo.keySet());
|
---|
| 1133 |
|
---|
| 1134 | ArrayList<String> saHomeCommunityIds = new ArrayList<String>(hKeys);
|
---|
| 1135 | oEntities = getBusinessEntitySetByServiceName(saHomeCommunityIds, sUniformServiceName);
|
---|
| 1136 |
|
---|
| 1137 | if ((oEntities != null) && (oEntities.getBusinessEntity().size() > 0))
|
---|
| 1138 | {
|
---|
| 1139 | return oEntities;
|
---|
| 1140 | }
|
---|
| 1141 | else
|
---|
| 1142 | {
|
---|
| 1143 | return null;
|
---|
| 1144 | }
|
---|
| 1145 | }
|
---|
| 1146 | }
|
---|