Index: DarwinCoreMetaDataSpecification.java =================================================================== RCS file: /cvs/kepler/src/org/ecoinformatics/seek/datasource/darwincore/DarwinCoreMetaDataSpecification.java,v retrieving revision 1.14 diff -c -r1.14 DarwinCoreMetaDataSpecification.java *** DarwinCoreMetaDataSpecification.java 19 Jul 2005 17:16:06 -0000 1.14 --- DarwinCoreMetaDataSpecification.java 8 Sep 2005 16:34:15 -0000 *************** *** 32,41 **** package org.ecoinformatics.seek.datasource.darwincore; - import java.io.File; import java.io.IOException; import java.util.Enumeration; import java.util.Hashtable; import java.util.Vector; import org.apache.axis.types.URI; --- 32,42 ---- package org.ecoinformatics.seek.datasource.darwincore; import java.io.IOException; + import java.util.Collections; import java.util.Enumeration; import java.util.Hashtable; + import java.util.Iterator; import java.util.Vector; import org.apache.axis.types.URI; *************** *** 47,53 **** import org.ecoinformatics.ecogrid.ResultsetType_record_returnField; import org.ecoinformatics.ecogrid.ResultsetType_resultsetMetadata; import org.ecoinformatics.ecogrid.ResultsetType_resultsetMetadata_system; - import org.ecoinformatics.ecogrid.digir.impl.DigirProxyImpl; import org.kepler.objectmanager.cache.DataCacheManager; import org.ecoinformatics.seek.datasource.EcogridDataCacheItem; --- 48,53 ---- *************** *** 75,124 **** public class DarwinCoreMetaDataSpecification extends MetadataSpecificationInterface { ! private DebugPrinter dbg = DebugPrinter.getInstance(); ! private static final String REPLACE = "#value#"; ! private static final String QUERYID = "darwincore-quick-search-query"; ! ! private String _searchString = ""; ! private boolean _returnResultsBySpecies = true; ! private int _numResults = 0; ! ! /** ! * Default constructor ! */ ! public DarwinCoreMetaDataSpecification() ! { ! ! } // DarwinCoreMetaDataSpecification ! ! /** ! * Method to create a quick query search ! * @param value String ! * @return QueryType ! */ ! public QueryType getQuickSearchEcoGridQuery(String aValue) ! throws InvalidEcogridQueryException ! { ! _searchString = aValue; ! ! Hashtable replaceMapping = new Hashtable(); ! replaceMapping.put(REPLACE, aValue); ! SearchQueryGenerator darwinCoreQueryGenerator = new SearchQueryGenerator(QUERYID, replaceMapping); ! QueryType ecogridQuery = darwinCoreQueryGenerator.getQuery(); ! return ecogridQuery; ! ! } // getQuickSearchEcoGridQuery ! ! /** ! * Method to create a ecogrid query ! * @return QueryType ! */ ! public QueryType getEcoGridQuery() ! { ! QueryType ecogridQuery = null; ! return ecogridQuery; ! } // getEcoGridQuery ! /** * Returns the human readable Provider and Resource name for a given provider URL and Reource Code * @param aURI the provider URL --- 75,124 ---- public class DarwinCoreMetaDataSpecification extends MetadataSpecificationInterface { ! private DebugPrinter dbg = DebugPrinter.getInstance(); ! private static final String REPLACE = "#value#"; ! private static final String QUERYID = "darwincore-quick-search-query"; ! ! private String _searchString = ""; ! private boolean _returnResultsBySpecies = true; ! private int _numResults = 0; ! ! /** ! * Default constructor ! */ ! public DarwinCoreMetaDataSpecification() ! { ! ! } // DarwinCoreMetaDataSpecification ! ! /** ! * Method to create a quick query search ! * @param value String ! * @return QueryType ! */ ! public QueryType getQuickSearchEcoGridQuery(String aValue) ! throws InvalidEcogridQueryException ! { ! _searchString = aValue; ! ! Hashtable replaceMapping = new Hashtable(); ! replaceMapping.put(REPLACE, aValue); ! SearchQueryGenerator darwinCoreQueryGenerator = new SearchQueryGenerator(QUERYID, replaceMapping); ! QueryType ecogridQuery = darwinCoreQueryGenerator.getQuery(); ! return ecogridQuery; ! ! } // getQuickSearchEcoGridQuery ! ! /** ! * Method to create a ecogrid query ! * @return QueryType ! */ ! public QueryType getEcoGridQuery() ! { ! QueryType ecogridQuery = null; ! return ecogridQuery; ! } // getEcoGridQuery ! /** * Returns the human readable Provider and Resource name for a given provider URL and Reource Code * @param aURI the provider URL *************** *** 146,213 **** String resourceCode = str.substring(inx+1, str.length()).replaceAll("%20", " "); - - DigirProxyImpl digir = new DigirProxyImpl(); ! boolean useCache = true; ! if (!useCache) ! { ! int status = digir.doHTTPRequest(urlStr); ! File dataCacheFile = digir.getCacheFile(); ! if (dataCacheFile != null) ! { ! dataCacheName = dataCacheFile.getAbsolutePath(); ! dataWasOK = true; ! } ! ! } else { ! dataCacheName = "ResourceInfo " + resourceCode; ! EcogridDataCacheItem dataCacheItem = (EcogridDataCacheItem)DataCacheManager.getCacheItem(null, dataCacheName, urlStr, EcogridDataCacheItem.class.getName()); ! if (dataCacheItem != null) { ! dataCacheItem.doWork(); ! dataWasOK = dataCacheItem.isReady(); ! if (dataWasOK) ! { ! dataCacheName = dataCacheItem.getLocalFileName(); ! } } - } if (dataWasOK) { ! Document dom = EcogridUtils.readXMLFile2DOM(dataCacheName); ! if (dom != null) ! { ! Node name = EcogridUtils.findNodeWithXPath(dom, "/response/content/metadata/provider/name"); ! if (name != null) ! { ! String providerName = EcogridUtils.getNodeValue(name); ! Node provider = EcogridUtils.findNodeWithXPath(dom, "/response/content/metadata/provider"); ! if (provider != null) ! { ! EcogridUtilsNamedNodeIterator nodeIter = new EcogridUtilsNamedNodeIterator(provider, "resource"); ! while (nodeIter.hasMoreNodes()) ! { ! Node resNode = nodeIter.nextNode(); ! String resCode = EcogridUtils.findNodeValue(resNode, "code"); ! if (resCode != null && resCode.equals(resourceCode)) ! { ! String fullName = providerName + " - " + EcogridUtils.findNodeValue(resNode, "name"); ! resourceName = fullName.replace('.', ' '); ! dataWasOK = true; ! } ! } ! } ! ! } ! } ! } else ! { ! System.err.println("Could not contact URL for provide/resource name: " + aURI); ! } } catch (Exception e) { System.err.println(e); --- 146,197 ---- String resourceCode = str.substring(inx+1, str.length()).replaceAll("%20", " "); ! dataCacheName = "ResourceInfo " + resourceCode; ! EcogridDataCacheItem dataCacheItem = (EcogridDataCacheItem)DataCacheManager.getCacheItem(null, dataCacheName, urlStr, EcogridDataCacheItem.class.getName()); ! if (dataCacheItem != null) { ! dataCacheItem.doWork(); ! dataWasOK = dataCacheItem.isReady(); ! if (dataWasOK) { ! dataCacheName = dataCacheItem.getLocalFileName(); } } + if (dataWasOK) { ! Document dom = EcogridUtils.readXMLFile2DOM(dataCacheName); ! if (dom != null) ! { ! Node name = EcogridUtils.findNodeWithXPath(dom, "/response/content/metadata/provider/name"); ! if (name != null) ! { ! String providerName = EcogridUtils.getNodeValue(name); ! Node provider = EcogridUtils.findNodeWithXPath(dom, "/response/content/metadata/provider"); ! if (provider != null) ! { ! EcogridUtilsNamedNodeIterator nodeIter = new EcogridUtilsNamedNodeIterator(provider, "resource"); ! while (nodeIter.hasMoreNodes()) ! { ! Node resNode = nodeIter.nextNode(); ! String resCode = EcogridUtils.findNodeValue(resNode, "code"); ! if (resCode != null && resCode.equals(resourceCode)) ! { ! String fullName = providerName + " - " + EcogridUtils.findNodeValue(resNode, "name"); ! resourceName = fullName.replace('.', ' '); ! dataWasOK = true; ! } ! } ! } ! ! } ! } ! } else ! { ! System.err.println("Could not contact URL for provide/resource name: " + aURI); ! } } catch (Exception e) { System.err.println(e); *************** *** 218,224 **** System.err.println(e); e.printStackTrace(); } ! if (dataWasOK) { --- 202,208 ---- System.err.println(e); e.printStackTrace(); } ! if (dataWasOK) { *************** *** 243,272 **** * @throws IllegalActionException */ public boolean addResultsetByProvider(ResultsetType aResults, ! String aEndPointURLStr, ! CompositeEntity aContainer, ! Vector aResultList) ! throws NameDuplicationException, IllegalActionException ! { ! if (aResults == null) ! { ! return false; ! } ! ! int numAdded = 0; ! ResultsetType_resultsetMetadata metaData = aResults.getResultsetMetadata(); ! if (metaData != null) ! { ! ResultsetType_resultsetMetadata_system[] system = metaData.getSystem(); ! if (system != null) ! { ! String providerURI = ""; ! for (int i=0;i 0; ! } /** * Helper class to return a named field's value (content) --- 258,273 ---- darwinDS.setProvider(system[i].getValue().toString()); aResultList.addElement(darwinDS); numAdded++; ! } else ! { ! System.err.println("Couldn't get full name for provider and resource - Id:[" + system[i].getId() + "] value: [" + system[i].getValue().toString()+"]"); ! } ! } ! } ! } ! _numResults = numAdded; ! return numAdded > 0; ! } /** * Helper class to return a named field's value (content) *************** *** 320,408 **** * @throws IllegalActionException */ public boolean addResultsetByScientificName(ResultsetType aResults, ! String aEndPointURLStr, ! CompositeEntity aContainer, ! Vector aResultList) ! throws NameDuplicationException, IllegalActionException ! { ! if (aResults == null) ! { ! return false; ! } ! ! Hashtable speciesHash = new Hashtable(); ! Hashtable systemProviderHash = new Hashtable(); ! ! // collect all the providers into a hash table ! int numAdded = 0; ! ResultsetType_resultsetMetadata metaData = aResults.getResultsetMetadata(); ! if (metaData != null) ! { ! ResultsetType_resultsetMetadata_system[] system = metaData.getSystem(); ! if (system != null) ! { ! String providerURI = ""; ! for (int i=0;i 0) ! { ! Hashtable providers = (Hashtable)speciesHash.get(scientificName); ! if (providers == null) ! { ! providers = new Hashtable(); ! speciesHash.put(scientificName, providers); ! //System.out.println("*** Putting ScientificName["+scientificName+"]"); ! } ! providers.put(rec.getSystem(), rec.getSystem()); ! //System.out.println(" System["+rec.getSystem()+"]"); ! } ! } ! } ! ! for (Enumeration e = speciesHash.keys();e.hasMoreElements();) ! { ! String scientificName = (String)e.nextElement(); ! Hashtable providers = (Hashtable)speciesHash.get(scientificName); ! StringBuffer providerList = new StringBuffer(); ! for (Enumeration ep = providers.keys();ep.hasMoreElements();) ! { ! String providerId = (String)ep.nextElement(); ! String provider = (String)systemProviderHash.get(providerId); ! if (providerList.length() > 0) ! { ! providerList.append(","); ! } ! providerList.append(provider); ! } ! ! //System.out.println("*** ProviderList["+scientificName+"]["+providerList+"]"); ! DarwinCoreDataSource darwinDS = new DarwinCoreDataSource(aContainer, scientificName); ! darwinDS.setInitFromData("yes"); ! darwinDS.setSearchData(_searchString); ! darwinDS.setEndpoint(aEndPointURLStr); ! darwinDS.setProvider(providerList.toString()); ! aResultList.addElement(darwinDS); ! _numResults++; ! ! } ! ! return numAdded > 0; ! } /** * Creates a DarwinCore DataSource which extends Source --- 304,399 ---- * @throws IllegalActionException */ public boolean addResultsetByScientificName(ResultsetType aResults, ! String aEndPointURLStr, ! CompositeEntity aContainer, ! Vector aResultList) ! throws NameDuplicationException, IllegalActionException ! { ! if (aResults == null) ! { ! return false; ! } ! ! Hashtable speciesHash = new Hashtable(); ! Hashtable systemProviderHash = new Hashtable(); ! ! // collect all the providers into a hash table ! int numAdded = 0; ! ResultsetType_resultsetMetadata metaData = aResults.getResultsetMetadata(); ! if (metaData != null) ! { ! ResultsetType_resultsetMetadata_system[] system = metaData.getSystem(); ! if (system != null) ! { ! String providerURI = ""; ! for (int i=0;i 0) ! { ! providerList.append(","); ! } ! providerList.append(provider); ! } ! ! //System.out.println("*** ProviderList["+scientificName+"]["+providerList+"]"); ! DarwinCoreDataSource darwinDS = new DarwinCoreDataSource(aContainer, scientificName); ! darwinDS.setInitFromData("yes"); ! darwinDS.setSearchData(_searchString); ! darwinDS.setEndpoint(aEndPointURLStr); ! darwinDS.setProvider(providerList.toString()); ! aResultList.addElement(darwinDS); ! _numResults++; ! ! } ! ! return numAdded > 0; ! } /** * Creates a DarwinCore DataSource which extends Source *************** *** 417,426 **** * @throws IllegalActionException */ public boolean addResultsetRecordsToContainer(ResultsetType aResults, ! String aEndPointURLStr, ! CompositeEntity aContainer, ! Vector aResultList) ! throws NameDuplicationException, IllegalActionException { if (_returnResultsBySpecies) { --- 408,417 ---- * @throws IllegalActionException */ public boolean addResultsetRecordsToContainer(ResultsetType aResults, ! String aEndPointURLStr, ! CompositeEntity aContainer, ! Vector aResultList) ! throws NameDuplicationException, IllegalActionException { if (_returnResultsBySpecies) { *************** *** 440,446 **** { return getClass().getName(); } ! /** * */ --- 431,437 ---- { return getClass().getName(); } ! /** * */ *************** *** 464,470 **** class SpeciesCollector { public Hashtable _providers = new Hashtable(); ! } ! } // DarwinCoreMetaDataSpecification --- 455,461 ---- class SpeciesCollector { public Hashtable _providers = new Hashtable(); ! } ! } // DarwinCoreMetaDataSpecification