src/org/ecoinformatics/seek/datasource/darwincore/DarwinCoreDataSource.java - Revision 1.16


src/org/ecoinformatics/seek/datasource/darwincore/DarwinCoreDataSource.java,1.16
.
Disk File
Skipping to line 1189. 
{ . {
DSTableIFace table = (DSTableIFace)_darwinCoreSchema.getTables() .elementAt(0); // there is only one table . DSTableIFace table = (DSTableIFace)_darwinCoreSchema.getTables() .elementAt(0); // there is only one table
for (Enumeration e = table.getFields().elements(); e.hasMoreElem ents();) . for (Enumeration e = table.getFields().elements(); e.hasMoreElem ents();)
{ . {
DSTableFieldIFace field = (DSTableFieldIFace)e.nextElement() ; . DSTableFieldIFace field = (DSTableFieldIFace)e.nextElement() ;
queryBuf.append(" <returnfield>/" + field.getName() + "</re turnfield>"); . queryBuf.append(" <returnField>/" + field.getName() + "</re turnField>");
} . }
} else . } else
{ . {
queryBuf.append(" <returnfield>/Species</returnfield>"); . queryBuf.append(" <returnField>/Species</returnField>");
queryBuf.append(" <returnfield>/ScientificName</returnfield>"); . queryBuf.append(" <returnField>/ScientificName</returnField>");
queryBuf.append(" <returnfield>/Collector</returnfield>"); . queryBuf.append(" <returnField>/Collector</returnField>");
queryBuf.append(" <returnfield>/YearCollected</returnfield>"); . queryBuf.append(" <returnField>/YearCollected</returnField>");
queryBuf.append(" <returnfield>/InstitutionCode</returnfield>") ; . queryBuf.append(" <returnField>/InstitutionCode</returnField>") ;
queryBuf.append(" <returnfield>/CollectionCode</returnfield>"); . queryBuf.append(" <returnField>/CollectionCode</returnField>");
queryBuf.append(" <returnfield>/CatalogNumber</returnfield>"); . queryBuf.append(" <returnField>/CatalogNumber</returnField>");
queryBuf.append(" <returnfield>/CatalogNumberText</returnfield> "); . queryBuf.append(" <returnField>/CatalogNumberText</returnField> ");
queryBuf.append(" <returnfield>/DecimalLatitude</returnfield>") ; . queryBuf.append(" <returnField>/DecimalLatitude</returnField>") ;
queryBuf.append(" <returnfield>/DecimalLongitude</returnfield>" ); . queryBuf.append(" <returnField>/DecimalLongitude</returnField>" );
} . }
queryBuf.append(" <condition operator=\"LIKE\" concept=\"Scientific Name\">" + searchStr +"</condition>"); . queryBuf.append(" <condition operator=\"LIKE\" concept=\"Scientific Name\">" + searchStr +"</condition>");
queryBuf.append("</egq:query>"); . queryBuf.append("</egq:query>");
.
if (providerList.size() > 0) . if (providerList.size() > 0)
Skipping to line 1219. 
int inx = providerStr.indexOf('?'); . int inx = providerStr.indexOf('?');
String baseURL = providerStr.substring(0, inx); . String baseURL = providerStr.substring(0, inx);
inx = providerStr.lastIndexOf('='); . inx = providerStr.lastIndexOf('=');
String resource = providerStr.substring(inx+1, providerStr.l ength()).replaceAll("%20", " "); . String resource = providerStr.substring(inx+1, providerStr.l ength()).replaceAll("%20", " ");
//System.out.println(queryBuf.toString()); . //System.out.println(queryBuf.toString());
  .
StringReader strReader = new StringReader(queryBuf.toS tring()); . StringReader strReader = new StringReader(queryBuf.toS tring());
EcogridQueryParser parser = new EcogridQueryParser(strRea der); . EcogridQueryParser parser = new EcogridQueryParser(strRea der);
parser.parseXML(); . parser.parseXML();
query = parser.getEcogridQuery(); . query = parser.getEcogridQuery();
.

src/org/ecoinformatics/seek/ecogrid/SearchQueryGenerator.java - Revision 1.6


src/org/ecoinformatics/seek/ecogrid/SearchQueryGenerator.java,1.6
.
Disk File
Skipping to line 30. 
* UPDATES, ENHANCEMENTS, OR MODIFICATIONS. . * UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
*/ . */
  .  
package org.ecoinformatics.seek.ecogrid; . package org.ecoinformatics.seek.ecogrid;
  .  
import java.util.Hashtable; . import java.util.Hashtable;
import java.util.Vector; .  
  .  
import javax.xml.transform.TransformerException; . import javax.xml.transform.TransformerException;
  .  
import org.apache.axis.types.URI; . import org.apache.axis.types.URI;
import org.apache.xpath.XPathAPI; . import org.ecoinformatics.ecogrid.EcogridQueryParser;
import org.ecoinformatics.ecogrid.ANDType; .  
import org.ecoinformatics.ecogrid.ConditionType; .  
import org.ecoinformatics.ecogrid.LimitedXPathExpression; .  
import org.ecoinformatics.ecogrid.ORType; .  
import org.ecoinformatics.ecogrid.OperatorType; .  
import org.ecoinformatics.ecogrid.QueryType; . import org.ecoinformatics.ecogrid.QueryType;
import org.ecoinformatics.ecogrid.QueryType_namespace; .  
import org.ecoinformatics.seek.ecogrid.exception.InvalidEcogridQueryException; . import org.ecoinformatics.seek.ecogrid.exception.InvalidEcogridQueryException;
import org.ecoinformatics.util.Config; . import org.ecoinformatics.util.Config;
import org.ecoinformatics.util.DebugPrinter; . import org.ecoinformatics.util.DebugPrinter;
import org.w3c.dom.Element; .  
import org.w3c.dom.NamedNodeMap; .  
import org.w3c.dom.Node; . import org.w3c.dom.Node;
import org.w3c.dom.NodeList; . import org.w3c.dom.NodeList;
  .  
/** . /**
* This class will read kepler configure file and get the query part from it . * This class will read kepler configure file and get the query part from it
Skipping to line 52. 
* . *
*/ . */
  .  
public class SearchQueryGenerator . public class SearchQueryGenerator
{ . {
private String queryId = null; . private String _queryId = null;
private Hashtable replacementMap = null; . private Hashtable _replacementMap = null;
private QueryType query = new QueryType(); . private QueryType _query = new QueryType();
private DebugPrinter dbg = DebugPrinter.getInstance(); . private DebugPrinter _dbg = DebugPrinter.getInstance();
private Vector returnFieldList = new Vector(); .  
.
private final static String QUERYPATH = "//ecogridService/queryList/query[ @queryId='"; . private final static String QUERYPATH = "//ecogridService/queryList/query[ @queryId='";
private final static String NAMESPACE = "namespace"; .  
private final static String RETURNFIELD = "returnField"; .  
private final static String TITLE = "title"; .  
private final static String AND = "AND"; .  
private final static String OR = "OR"; .  
private final static String CONDITION = "condition"; . private final static String CONDITION = "condition";
private final static String SYSTEM = "system"; .  
private final static String OPERATOR = "operator"; .  
private final static String CONCEPT = "concept"; .  
private static final int NAMESPACEARRAYLENGTH = 1; .  
private static final int TITLEEARRAYLENGTH = 1; .  
.
/** . /**
* Constructor of SearchQueryGenerator . * Constructor of SearchQueryGenerator
* @param queryId String the queryId which will be found in config . * @param queryId String the queryId which will be found in config
* @param replacementMap Hashtable the hash table which contain the . * @param replacementMap Hashtable the hash table which contain the
Skipping to line 70. 
* value - replacement . * value - replacement
* For example, if key is "#value#", and value is "soil". This means any . * For example, if key is "#value#", and value is "soil". This means any
* element and attribute in xml has value "#value#" will be replaced by soil . * element and attribute in xml has value "#value#" will be replaced by soil
*/ . */
public SearchQueryGenerator(String queryId, Hashtable replacementMap) . public SearchQueryGenerator(String queryId,
  . Hashtable replacementMap)
throws InvalidEcogridQueryException . throws InvalidEcogridQueryException
  .  
{ . {
this.queryId = queryId; . _queryId = queryId;
this.replacementMap = replacementMap; . _replacementMap = replacementMap;
try . try
{ . {
generateQuery(); . generateQuery();
} . }
catch(Exception e) . catch(Exception e)
Skipping to line 92. 
* Method to get query which generate by this class . * Method to get query which generate by this class
* @return QueryType . * @return QueryType
*/ . */
public QueryType getQuery() . public QueryType getQuery()
{ . {
return this.query; . return _query;
}//getQuery . }//getQuery
.
  . /**
    . * Recursively walks the tree looking for Condition values inorder to subsit ute in the search value
  . * @param aNode the parent node
    . * @param aIsChildCond indicates whether the current parent node is a Condit ion node
  . */
  . private void mapInValue(Node aNode, boolean aIsChildCond)
  . {
  . NodeList childList = aNode.getChildNodes();
  . if ( childList == null)
  . {
  . return;
  . }
  .
  . // go through every child element
  . int length = childList.getLength();
  . for (int i=0; i<length; i++)
  . {
  . Node kid = childList.item(i);
  . if (kid.getNodeName().equals(CONDITION) || aIsChildCond)
  . {
  . String value = kid.getNodeValue();
    . // replace the value by search value if this value in replacementMap
  . if (value != null && _replacementMap.containsKey(value))
  . {
  . value = (String)_replacementMap.get(value);
  . kid.setNodeValue(value);
  . }
  . else
  . {
  . mapInValue(kid, true);
  . }
  . }
  . else
  . {
  . mapInValue(kid, false);
  . }
  . }
  . }
  .
/* . /*
* Method to read config file and generate a query(It will chose the first o ne . * Method to read config file and generate a query(It will chose the first o ne
* if it has more than one in configure file) . * if it has more than one in configure file)
*/ . */
private void generateQuery() throws URI.MalformedURIException, . private void generateQuery() throws URI.MalformedURIException,
Skipping to line 145. 
InvalidEcogridQueryException . InvalidEcogridQueryException
{ . {
String xpath = QUERYPATH + queryId+ "']"; . String xpath = QUERYPATH + _queryId+ "']";
Node queryNode = null; . Node queryNode = null;
NodeList list = Config.getNodeListFromPath(xpath); . NodeList list = Config.getNodeListFromPath(xpath);
if (list == null) . if (list == null)
{ . {
return; . return;
} . }
  .
// chose first query . // chose first query
queryNode = list.item(0); . queryNode = list.item(0);
//set query attributes .  
setQuerySystem(queryNode); .  
setQueryId(); .  
.  
NodeList queryChildrenList = queryNode.getChildNodes(); . NodeList queryChildrenList = queryNode.getChildNodes();
if ( queryChildrenList == null) . if ( queryChildrenList == null)
{ . {
return; . return;
} . }
int length = queryChildrenList.getLength(); . mapInValue(queryNode, false);
// go through every child element .  
for (int i=0; i<length; i++) .  
{ .  
Node kid = queryChildrenList.item(i); .  
if (kid !=null && kid.getNodeType() ==Node.ELEMENT_NODE) .  
{ .  
if (kid.getNodeName() != null && kid.getNodeName().equals(NAMESPACE)) .  
{ .  
setQueryNamespace(kid); .  
}//namespace .  
else if (kid.getNodeName() != null && kid.getNodeName().equals(TITLE)) .    
{ .  
setQueryTitle(kid); .  
}//title .  
else if (kid.getNodeName() != null && kid.getNodeName().equals(RETURNF IELD)) .    
{ .  
putReturnFieldIntoVector(kid); .  
}//returnfield .  
else if (kid.getNodeName() != null && kid.getNodeName().equals(AND)) .  
{ .  
ANDType topAnd = new ANDType(); .  
setQueryANDType(kid,topAnd); .  
dbg.print("In top AND", 2); .  
query.setAND(topAnd); .  
}//AND .  
else if (kid.getNodeName() != null && kid.getNodeName().equals(OR)) .  
{ .  
ORType topOr = new ORType(); .  
setQueryORType(kid, topOr); .  
dbg.print("In top OR", 2); .  
query.setOR(topOr); .  
}//OR .  
else if (kid.getNodeName() != null && kid.getNodeName().equals(CONDITI ON)) .    
{ .  
ConditionType topCondition = setQueryConditionType(kid); .  
dbg.print("In top condtion", 2); .  
query.setCondition(topCondition); .  
}//condition .  
}//if .  
}//for .  
//put vector of return fields into array and set it to query .  
setQueryReturnField(); .  
}//generateQuery .  
.  
/* .  
* Method to set query namesapce .  
*/ .  
private void setQueryNamespace(Node node) throws URI.MalformedURIException .  
{ .  
Node value = node.getFirstChild(); .  
if (value.getNodeType() == Node.TEXT_NODE) .  
{ .  
String namespaceStr = value.getNodeValue(); .  
URI namespaceURI = new URI(namespaceStr); .  
dbg.print("The ecogrid query search namespace is " + .  
namespaceURI.toString(), 2); .  
QueryType_namespace namespaceQuery = new QueryType_namespace(namespaceUR I); .    
QueryType_namespace[] namespaceArray = .  
new QueryType_namespace[NAMESPACEARRAYLENGTH ]; .    
namespaceArray[0]= namespaceQuery; .  
query.setNamespace(namespaceArray); .  
}//if .  
}//setQuerynamespace .  
.  
/* .  
* Method to set query system .  
*/ .  
private void setQuerySystem(Node node) throws URI.MalformedURIException .  
{ .  
NamedNodeMap attributes = node.getAttributes(); .  
Node system = attributes.getNamedItem(SYSTEM); .  
String systemStr = system.getNodeValue(); .  
URI systemURI = null; .  
systemURI = new URI(systemStr); .  
dbg.print("The ecogrid query system is " + systemURI.toString(), 2); .  
query.setSystem(systemURI); .  
}//setQuerySystem .  
.  
/* .  
* Method to set query title .  
*/ .  
private void setQueryTitle(Node node) .  
{ .  
Node value = node.getFirstChild(); .  
if (value.getNodeType() == Node.TEXT_NODE) .  
{ .  
String queryTitle = value.getNodeValue(); .  
dbg.print("The ecogrid query title is "+ queryTitle, 2); .  
String [] queryTitleArray = new String[TITLEEARRAYLENGTH]; .  
queryTitleArray[0] = queryTitle; .  
query.setTitle(queryTitleArray); .  
}//if .  
}//setQueryTitle .  
.  
/* .  
* Method to set query id .  
*/ .  
private void setQueryId() .  
{ .  
query.setQueryId(queryId); .  
}//setQueryId .  
.  
.  
/* .  
* Put one return field to a vector .  
*/ .  
private void putReturnFieldIntoVector(Node node) .  
{ .  
Node value = node.getFirstChild(); .  
if (value.getNodeType() == Node.TEXT_NODE) .  
{ .  
String returnField = value.getNodeValue(); .  
dbg.print("The return ecogrid query is "+ returnField, 2); .  
if (returnField != null && !returnField.trim().equals("")) .  
{ .  
returnField = returnField.trim(); .  
dbg.print("The return ecogrid query is "+ returnField, 2); .  
returnFieldList.addElement(returnField); .  
} .  
}//if .  
  .  
}//putReturnFieldIntoVector .  
/* .  
* Method to transfer a return field actor a array and set the array to quer y .    
*/ .  
private void setQueryReturnField() .  
{ .  
if (returnFieldList != null) .  
{ .  
int size = returnFieldList.size(); .  
String[] returnFieldArray = new String[size]; .  
for (int i=0; i<size; i++) .  
{ .  
returnFieldArray[i] = (String)returnFieldList.elementAt(i); .  
} .  
query.setReturnfield(returnFieldArray); .  
} .  
}//setQueryReturnField .  
.  
/* .  
* Method to set AND type to query .  
*/ .  
private void setQueryANDType(Node node, ANDType and) .  
throws TransformerException, InvalidEcogridQueryException .    
{ .  
dbg.print("In AND", 2); .  
setType(node, and, null); .  
}//setQueryANDType .  
.  
/* .  
* Method to set OR type to query .  
*/ .  
private void setQueryORType(Node node, ORType or) .  
throws TransformerException, InvalidEcogridQueryException .    
{ .  
dbg.print("In OR", 2); .  
setType(node, null, or); .  
}//setQueryORType .  
.  
/* .  
* Method can handle both OR and AND .  
*/ .  
private void setType(Node node, ANDType and, ORType or) .  
throws TransformerException, InvalidEcogridQueryException .  
{ .  
//make sure parameter works .  
if (node == null) .  
{ .  
return; .  
} .  
NodeList andList = XPathAPI.selectNodeList(node, AND); .  
NodeList orList = XPathAPI.selectNodeList(node, OR); .  
NodeList conList = XPathAPI.selectNodeList(node, CONDITION); .  
int andLength = andList.getLength(); .  
int orLength = orList.getLength(); .  
int conLength = conList.getLength(); .  
// and type children .  
if (andLength != 0) .  
{ .  
ANDType[] andArray = new ANDType[andLength]; .  
// get and type children .  
for ( int i=0; i<andLength; i++) .  
{ .  
ANDType andChild = new ANDType(); .  
andArray[i] = andChild; .  
Node childNode = andList.item(i); .  
// call handleANDype again .  
setType(childNode, andChild, null);//make usre or type is null .  
} .  
//set children to parent .  
if (and != null) .  
{ .  
and.setAND(andArray); .  
} .  
else if (or != null) .  
{ .  
or.setAND(andArray); .  
} .  
} .  
//or type children .  
if (orLength != 0) .  
{ .  
ORType[] orArray = new ORType[orLength]; .  
// get or type children .  
for ( int i=0; i< orLength; i++) .  
{ .  
ORType orChild = new ORType(); .  
orArray[i] = orChild; .  
Node childNode = orList.item(i); .  
setType(childNode, null, orChild);//make sure ANDType is null .  
} .  
if (and !=null) .  
{ .  
and.setOR(orArray); .  
} .  
else if (or != null) .  
{ .  
or.setOR(orArray); .  
} .  
  .  
} .  
// conditiontype .  
if ( conLength != 0 ) .  
{ .  
ConditionType[] conditionArray = new ConditionType[conLength]; .  
for ( int i=0; i< conLength; i++) .  
{ .  
Node childNode = conList.item(i); .  
ConditionType condition = setQueryConditionType(childNode); .  
conditionArray[i] = condition; .  
}//for .  
if (and !=null) .  
{ .  
and.setCondition(conditionArray); .  
} .  
else if (or != null) .  
{ .  
or.setCondition(conditionArray); .  
} .  
}//if .  
  .  
}//setType .  
.  
/* .  
* Method to set Condition type to query .  
*/ .  
private ConditionType setQueryConditionType(Node node) throws InvalidEcogrid QueryException .    
{ .  
ConditionType condition = null; .  
dbg.print("In condition type", 2); .  
Element coditionElement = (Element) node; .  
// get attribute operator from node .  
String operatorString = coditionElement.getAttribute(OPERATOR); .  
dbg.print("operator string is "+ operatorString, 2); .  
// get attribute concept .  
String conceptString = coditionElement.getAttribute(CONCEPT); .  
dbg.print("concept string is "+ conceptString, 2); .  
// get element value .  
String value = coditionElement.getFirstChild().getNodeValue(); .  
dbg.print("value string is "+ value, 2); .  
condition = generateConditionType(conceptString, operatorString, value); .  
return condition; .  
}//setConditionType .  
.  
/* .  
* Generate a condition type base on concept, operator, value .  
*/ .  
private ConditionType generateConditionType(String concept, .  
String operator, String value) .  
throws InvalidEcogridQueryException .  
{ .  
// check the parameters .  
if ( concept == null || concept.trim().equals("")) .  
{ .  
throw new InvalidEcogridQueryException("Should set up concept value in " + .    
"condition type in ecogrid query"); .  
} .  
else if (operator == null || operator.trim().equals("")) .  
{ .  
throw new InvalidEcogridQueryException("Should set up operator value in "+ .    
"condition type in ecogrid query"); .  
} .  
else if (value == null || value.trim().equals("")) .  
{ .  
throw new InvalidEcogridQueryException("Should set up search value in " + .    
"condition type in ecogrid query"); .  
} .  
Skipping to line 163. 
.
// replace the value by search value if this value in replacementMap . try {
if(replacementMap.containsKey(value)) . EcogridQueryParser queryParser = new EcogridQueryParser(queryNode);
{ . queryParser.parseXML();
dbg.print("replace " + value + " by ", 2 ); . _query = queryParser.getEcogridQuery();
value = (String)replacementMap.get(value); . //System.out.println(EcogridQueryTransformer.toXMLString(query));
dbg.print(" new value "+ value, 2); . } catch (Exception e)
  . {
  . System.err.println(e);
} . }
.  
// set up the limitedPathExpression (xpath) .  
LimitedXPathExpression path = new LimitedXPathExpression(concept); .  
  .  
// set up the operator . -
OperatorType operatorType = null; . } // generateQuery
try .
{ .  
operatorType = OperatorType.fromString(operator); .  
} .  
catch(IllegalStateException e) .  
{ .  
throw new InvalidEcogridQueryException(e.getMessage()); .  
} .  
  .  
//set up condition type .  
ConditionType condition = new ConditionType(); .  
condition.setConcept(path); .  
condition.setOperator(operatorType); .  
condition.setValue(value); .  
return condition; .  
  .  
}//generateConditionType .  
  .  
.  
}//SearchQueryGenerator .