Project

General

Profile

Bug #1821 » diff2.txt

Rod Spears, 12/09/2004 01:09 PM

 
1
Index: src/org/ecoinformatics/seek/datasource/darwincore/DarwinCoreDataSource.java
2
===================================================================
3
RCS file: /cvs/kepler/src/org/ecoinformatics/seek/datasource/darwincore/DarwinCoreDataSource.java,v
4
retrieving revision 1.16
5
diff -u -r1.16 DarwinCoreDataSource.java
6
--- src/org/ecoinformatics/seek/datasource/darwincore/DarwinCoreDataSource.java	17 Nov 2004 20:29:21 -0000	1.16
7
+++ src/org/ecoinformatics/seek/datasource/darwincore/DarwinCoreDataSource.java	9 Dec 2004 21:05:44 -0000
8
@@ -1191,20 +1191,20 @@
9
               for (Enumeration e = table.getFields().elements(); e.hasMoreElements();)
10
               {
11
                   DSTableFieldIFace field = (DSTableFieldIFace)e.nextElement();
12
-                  queryBuf.append("  <returnfield>/" + field.getName() + "</returnfield>");
13
+                  queryBuf.append("  <returnField>/" + field.getName() + "</returnField>");
14
               }
15
           } else 
16
           {
17
-              queryBuf.append("  <returnfield>/Species</returnfield>");
18
-              queryBuf.append("  <returnfield>/ScientificName</returnfield>");
19
-              queryBuf.append("  <returnfield>/Collector</returnfield>");
20
-              queryBuf.append("  <returnfield>/YearCollected</returnfield>");
21
-              queryBuf.append("  <returnfield>/InstitutionCode</returnfield>");
22
-              queryBuf.append("  <returnfield>/CollectionCode</returnfield>");
23
-              queryBuf.append("  <returnfield>/CatalogNumber</returnfield>");
24
-              queryBuf.append("  <returnfield>/CatalogNumberText</returnfield>");
25
-              queryBuf.append("  <returnfield>/DecimalLatitude</returnfield>");
26
-              queryBuf.append("  <returnfield>/DecimalLongitude</returnfield>");
27
+              queryBuf.append("  <returnField>/Species</returnField>");
28
+              queryBuf.append("  <returnField>/ScientificName</returnField>");
29
+              queryBuf.append("  <returnField>/Collector</returnField>");
30
+              queryBuf.append("  <returnField>/YearCollected</returnField>");
31
+              queryBuf.append("  <returnField>/InstitutionCode</returnField>");
32
+              queryBuf.append("  <returnField>/CollectionCode</returnField>");
33
+              queryBuf.append("  <returnField>/CatalogNumber</returnField>");
34
+              queryBuf.append("  <returnField>/CatalogNumberText</returnField>");
35
+              queryBuf.append("  <returnField>/DecimalLatitude</returnField>");
36
+              queryBuf.append("  <returnField>/DecimalLongitude</returnField>");
37
           }
38
           queryBuf.append("  <condition operator=\"LIKE\" concept=\"ScientificName\">" + searchStr +"</condition>");
39
           queryBuf.append("</egq:query>");
40
@@ -1221,6 +1221,7 @@
41
                   inx = providerStr.lastIndexOf('=');
42
                   String resource = providerStr.substring(inx+1, providerStr.length()).replaceAll("%20", " ");
43
                   //System.out.println(queryBuf.toString());
44
+                  
45
                   StringReader       strReader = new StringReader(queryBuf.toString());
46
                   EcogridQueryParser parser    = new EcogridQueryParser(strReader);
47
                   parser.parseXML();
48
Index: src/org/ecoinformatics/seek/ecogrid/SearchQueryGenerator.java
49
===================================================================
50
RCS file: /cvs/kepler/src/org/ecoinformatics/seek/ecogrid/SearchQueryGenerator.java,v
51
retrieving revision 1.6
52
diff -u -r1.6 SearchQueryGenerator.java
53
--- src/org/ecoinformatics/seek/ecogrid/SearchQueryGenerator.java	11 Oct 2004 23:46:12 -0000	1.6
54
+++ src/org/ecoinformatics/seek/ecogrid/SearchQueryGenerator.java	9 Dec 2004 21:05:44 -0000
55
@@ -33,24 +33,15 @@
56
 package org.ecoinformatics.seek.ecogrid;
57
 
58
 import java.util.Hashtable;
59
-import java.util.Vector;
60
 
61
 import javax.xml.transform.TransformerException;
62
 
63
 import org.apache.axis.types.URI;
64
-import org.apache.xpath.XPathAPI;
65
-import org.ecoinformatics.ecogrid.ANDType;
66
-import org.ecoinformatics.ecogrid.ConditionType;
67
-import org.ecoinformatics.ecogrid.LimitedXPathExpression;
68
-import org.ecoinformatics.ecogrid.ORType;
69
-import org.ecoinformatics.ecogrid.OperatorType;
70
+import org.ecoinformatics.ecogrid.EcogridQueryParser;
71
 import org.ecoinformatics.ecogrid.QueryType;
72
-import org.ecoinformatics.ecogrid.QueryType_namespace;
73
 import org.ecoinformatics.seek.ecogrid.exception.InvalidEcogridQueryException;
74
 import org.ecoinformatics.util.Config;
75
 import org.ecoinformatics.util.DebugPrinter;
76
-import org.w3c.dom.Element;
77
-import org.w3c.dom.NamedNodeMap;
78
 import org.w3c.dom.Node;
79
 import org.w3c.dom.NodeList;
80
 
81
@@ -63,24 +54,13 @@
82
 
83
 public class SearchQueryGenerator 
84
 {
85
-  private String queryId           = null;
86
-  private Hashtable replacementMap = null;
87
-  private QueryType query          = new QueryType();
88
-  private DebugPrinter dbg         = DebugPrinter.getInstance();
89
-  private Vector returnFieldList   = new Vector();
90
+  private String       _queryId        = null;
91
+  private Hashtable    _replacementMap = null;
92
+  private QueryType    _query          = new QueryType();
93
+  private DebugPrinter _dbg            = DebugPrinter.getInstance();
94
   
95
   private final static String QUERYPATH   = "//ecogridService/queryList/query[@queryId='";
96
-  private final static String NAMESPACE   = "namespace";
97
-  private final static String RETURNFIELD = "returnField";
98
-  private final static String TITLE       = "title";
99
-  private final static String AND         = "AND";
100
-  private final static String OR          = "OR";
101
   private final static String CONDITION   = "condition";
102
-  private final static String SYSTEM      = "system";
103
-  private final static String OPERATOR    = "operator";
104
-  private final static String CONCEPT     = "concept";
105
-  private static final int NAMESPACEARRAYLENGTH = 1;
106
-  private static final int TITLEEARRAYLENGTH = 1;
107
   
108
   /**
109
    * Constructor of SearchQueryGenerator
110
@@ -91,12 +71,13 @@
111
    * For example, if key is "#value#", and value is "soil". This means any
112
    * element and attribute in xml has value "#value#" will be replaced by soil
113
    */
114
-  public SearchQueryGenerator(String queryId, Hashtable replacementMap)
115
+  public SearchQueryGenerator(String    queryId, 
116
+                              Hashtable replacementMap)
117
                                   throws  InvalidEcogridQueryException
118
 
119
   {
120
-    this.queryId        = queryId;
121
-    this.replacementMap = replacementMap;
122
+    _queryId        = queryId;
123
+    _replacementMap = replacementMap;
124
     try
125
     {
126
       generateQuery();
127
@@ -113,9 +94,48 @@
128
    */
129
   public QueryType getQuery()
130
   {
131
-    return this.query;
132
+    return _query;
133
   }//getQuery
134
   
135
+  /**
136
+   * Recursively walks the tree looking for Condition values inorder to subsitute in the search value
137
+   * @param aNode the parent node
138
+   * @param aIsChildCond indicates whether the current parent node is a Condition node
139
+   */
140
+  private void mapInValue(Node aNode, boolean aIsChildCond)
141
+  {
142
+      NodeList childList = aNode.getChildNodes();
143
+      if ( childList == null)
144
+      {
145
+        return;
146
+      }
147
+      
148
+      // go through every child element
149
+      int length = childList.getLength();
150
+      for (int i=0; i<length; i++)
151
+      {
152
+        Node kid = childList.item(i);
153
+        if (kid.getNodeName().equals(CONDITION) || aIsChildCond)
154
+        {
155
+          String value = kid.getNodeValue();
156
+          // replace the value by search value if this value in replacementMap
157
+          if (value != null && _replacementMap.containsKey(value))
158
+          {
159
+            value = (String)_replacementMap.get(value);
160
+             kid.setNodeValue(value);
161
+          } 
162
+          else 
163
+          {
164
+            mapInValue(kid, true);
165
+          }
166
+        }
167
+        else
168
+        {
169
+          mapInValue(kid, false);
170
+        }
171
+      }
172
+  }
173
+  
174
   /*
175
    * Method to read config file and generate a query(It will chose the first one
176
    * if it has more than one in configure file)
177
@@ -124,343 +144,33 @@
178
                                       TransformerException,
179
                                       InvalidEcogridQueryException
180
   {
181
-    String xpath = QUERYPATH + queryId+ "']";
182
+    String xpath   = QUERYPATH + _queryId+ "']";
183
     Node queryNode = null;
184
-    NodeList list = Config.getNodeListFromPath(xpath);
185
+    NodeList list   = Config.getNodeListFromPath(xpath);
186
     if (list == null)
187
     {
188
       return;
189
     }
190
+    
191
     // chose first query
192
     queryNode = list.item(0);
193
-    //set query attributes
194
-    setQuerySystem(queryNode);
195
-    setQueryId();
196
-    
197
     NodeList queryChildrenList = queryNode.getChildNodes();
198
     if ( queryChildrenList == null)
199
     {
200
       return;
201
     }
202
-    int length = queryChildrenList.getLength();
203
-    // go through every child element
204
-    for (int i=0; i<length; i++)
205
-    {
206
-      Node kid = queryChildrenList.item(i);
207
-      if (kid !=null && kid.getNodeType() ==Node.ELEMENT_NODE)
208
-      {
209
-        if (kid.getNodeName() != null && kid.getNodeName().equals(NAMESPACE))
210
-        {
211
-          setQueryNamespace(kid);
212
-        }//namespace
213
-        else if (kid.getNodeName() != null && kid.getNodeName().equals(TITLE))
214
-        {
215
-          setQueryTitle(kid);
216
-        }//title
217
-        else if (kid.getNodeName() != null && kid.getNodeName().equals(RETURNFIELD))
218
-        {
219
-          putReturnFieldIntoVector(kid);
220
-        }//returnfield
221
-        else if (kid.getNodeName() != null && kid.getNodeName().equals(AND))
222
-        {
223
-          ANDType topAnd = new ANDType();
224
-          setQueryANDType(kid,topAnd);
225
-          dbg.print("In top AND", 2);
226
-          query.setAND(topAnd);
227
-        }//AND
228
-        else if (kid.getNodeName() != null && kid.getNodeName().equals(OR))
229
-        {
230
-          ORType topOr = new ORType();
231
-          setQueryORType(kid, topOr);
232
-          dbg.print("In top OR", 2);
233
-          query.setOR(topOr);
234
-        }//OR
235
-        else if (kid.getNodeName() != null && kid.getNodeName().equals(CONDITION))
236
-        {
237
-          ConditionType topCondition = setQueryConditionType(kid);
238
-          dbg.print("In top condtion", 2);
239
-          query.setCondition(topCondition);
240
-        }//condition
241
-      }//if
242
-    }//for
243
-    //put vector of return fields into array and set it to query
244
-    setQueryReturnField();
245
-  }//generateQuery
246
-  
247
-  /*
248
-   * Method to set query namesapce
249
-   */
250
-  private void setQueryNamespace(Node node) throws URI.MalformedURIException
251
-  {
252
-    Node value = node.getFirstChild();
253
-    if (value.getNodeType() == Node.TEXT_NODE)
254
-    {
255
-      String namespaceStr = value.getNodeValue();
256
-      URI namespaceURI    = new URI(namespaceStr);
257
-      dbg.print("The ecogrid query search namespace is " + 
258
-                 namespaceURI.toString(), 2);
259
-      QueryType_namespace namespaceQuery = new QueryType_namespace(namespaceURI);
260
-      QueryType_namespace[] namespaceArray = 
261
-                                  new QueryType_namespace[NAMESPACEARRAYLENGTH];
262
-      namespaceArray[0]= namespaceQuery;
263
-      query.setNamespace(namespaceArray);
264
-    }//if
265
-  }//setQuerynamespace
266
-  
267
-  /*
268
-   * Method to set query system
269
-   */
270
-  private void setQuerySystem(Node node) throws URI.MalformedURIException 
271
-  {
272
-    NamedNodeMap attributes = node.getAttributes();
273
-    Node system = attributes.getNamedItem(SYSTEM);
274
-    String systemStr = system.getNodeValue();
275
-    URI systemURI = null;
276
-    systemURI = new URI(systemStr);
277
-    dbg.print("The ecogrid query system is " + systemURI.toString(), 2);
278
-    query.setSystem(systemURI);
279
-  }//setQuerySystem
280
-  
281
-  /* 
282
-   * Method to set query title
283
-   */
284
-  private void setQueryTitle(Node node)
285
-  {
286
-    Node value = node.getFirstChild();
287
-    if (value.getNodeType() == Node.TEXT_NODE)
288
-    {
289
-      String queryTitle = value.getNodeValue();
290
-      dbg.print("The ecogrid query title is "+ queryTitle, 2);
291
-      String [] queryTitleArray = new String[TITLEEARRAYLENGTH];
292
-      queryTitleArray[0] = queryTitle;
293
-      query.setTitle(queryTitleArray);
294
-    }//if
295
-  }//setQueryTitle
296
-  
297
-  /*
298
-   * Method to set query id
299
-   */
300
-  private void setQueryId()
301
-  {
302
-    query.setQueryId(queryId);
303
-  }//setQueryId
304
-  
305
-  
306
-  /*
307
-   * Put one return field to a vector
308
-   */
309
-  private void putReturnFieldIntoVector(Node node)
310
-  {
311
-    Node value = node.getFirstChild();
312
-    if (value.getNodeType() == Node.TEXT_NODE)
313
-    {
314
-      String returnField = value.getNodeValue();
315
-      dbg.print("The return ecogrid query is "+ returnField, 2);
316
-      if (returnField != null && !returnField.trim().equals(""))
317
-      {
318
-        returnField = returnField.trim();
319
-        dbg.print("The return ecogrid query is "+ returnField, 2);
320
-        returnFieldList.addElement(returnField);
321
-      }
322
-    }//if
323
-
324
-  }//putReturnFieldIntoVector
325
-  /*
326
-   * Method to transfer a return field actor a array and set the array to query
327
-   */
328
-  private void setQueryReturnField()
329
-  {
330
-    if (returnFieldList != null)
331
-    {
332
-      int size = returnFieldList.size();
333
-      String[] returnFieldArray = new String[size];
334
-      for (int i=0; i<size; i++)
335
-      {
336
-        returnFieldArray[i] = (String)returnFieldList.elementAt(i);
337
-      }
338
-      query.setReturnfield(returnFieldArray);
339
-    }
340
-  }//setQueryReturnField
341
-  
342
-  /*
343
-   * Method to set AND type to query
344
-   */
345
-  private void setQueryANDType(Node node, ANDType and) 
346
-                     throws TransformerException, InvalidEcogridQueryException
347
-  {
348
-    dbg.print("In AND", 2);
349
-    setType(node, and, null);
350
-  }//setQueryANDType
351
-  
352
-  /*
353
-   * Method to set OR type to query
354
-   */
355
-  private void setQueryORType(Node node, ORType or) 
356
-                     throws TransformerException, InvalidEcogridQueryException
357
-  {
358
-    dbg.print("In OR", 2);
359
-    setType(node, null, or);
360
-  }//setQueryORType
361
-  
362
-  /*
363
-   * Method can handle both OR and AND
364
-   */
365
-  private void setType(Node node, ANDType and, ORType or) 
366
-                    throws TransformerException, InvalidEcogridQueryException
367
-  {
368
-    //make sure parameter works
369
-     if (node == null)
370
-     {
371
-       return;
372
-     }
373
-     NodeList andList = XPathAPI.selectNodeList(node, AND);
374
-     NodeList orList  = XPathAPI.selectNodeList(node, OR);
375
-     NodeList conList = XPathAPI.selectNodeList(node, CONDITION);
376
-     int andLength = andList.getLength();
377
-     int orLength  = orList.getLength();
378
-     int conLength = conList.getLength();
379
-     // and type children
380
-     if (andLength != 0)
381
-     {
382
-       ANDType[] andArray = new ANDType[andLength];
383
-       // get and type children
384
-       for ( int i=0; i<andLength; i++)
385
-       {
386
-         ANDType andChild = new ANDType();
387
-         andArray[i] = andChild;
388
-         Node childNode = andList.item(i);
389
-         // call handleANDype again
390
-         setType(childNode, andChild, null);//make usre or type is null
391
-       }
392
-       //set children to parent
393
-       if (and != null)
394
-       {
395
-         and.setAND(andArray);
396
-       }
397
-       else if (or != null)
398
-       {
399
-         or.setAND(andArray);
400
-       }
401
-     }
402
-     //or type children
403
-     if (orLength != 0)
404
-     {
405
-       ORType[] orArray = new ORType[orLength];
406
-       // get or type children
407
-       for ( int i=0; i< orLength; i++)
408
-       {
409
-         ORType orChild = new ORType();
410
-         orArray[i] = orChild;
411
-         Node childNode = orList.item(i);
412
-         setType(childNode, null, orChild);//make sure ANDType is null
413
-       }
414
-       if (and !=null)
415
-       {
416
-         and.setOR(orArray);
417
-       }
418
-       else if (or != null)
419
-       {
420
-         or.setOR(orArray);
421
-       }
422
-
423
-     }
424
-     // conditiontype
425
-     if ( conLength != 0 )
426
-     {
427
-       ConditionType[] conditionArray = new ConditionType[conLength];
428
-       for ( int i=0; i< conLength; i++)
429
-       {
430
-         Node childNode = conList.item(i);
431
-         ConditionType condition = setQueryConditionType(childNode);
432
-         conditionArray[i] = condition;
433
-       }//for
434
-       if (and !=null)
435
-       {
436
-         and.setCondition(conditionArray);
437
-       }
438
-       else if (or != null)
439
-       {
440
-         or.setCondition(conditionArray);
441
-      }
442
-     }//if
443
-
444
-  }//setType
445
-  
446
-  /*
447
-   * Method to set Condition type to query
448
-   */
449
-  private ConditionType setQueryConditionType(Node node) throws InvalidEcogridQueryException
450
-  {
451
-    ConditionType condition = null;
452
-    dbg.print("In condition type", 2);
453
-    Element coditionElement = (Element) node;
454
-    // get attribute operator from node
455
-    String operatorString = coditionElement.getAttribute(OPERATOR);
456
-    dbg.print("operator string is "+ operatorString, 2);
457
-    // get attribute concept
458
-    String conceptString = coditionElement.getAttribute(CONCEPT);
459
-    dbg.print("concept string is "+ conceptString, 2);
460
-    // get element value
461
-    String value = coditionElement.getFirstChild().getNodeValue();
462
-    dbg.print("value string is "+ value, 2);
463
-    condition = generateConditionType(conceptString, operatorString, value);
464
-    return condition;
465
-  }//setConditionType
466
-  
467
-  /*
468
-   * Generate a condition type base on concept, operator, value
469
-   */
470
-  private ConditionType generateConditionType(String concept,
471
-                                       String operator, String value)
472
-                                       throws InvalidEcogridQueryException
473
-  {
474
-    // check the parameters
475
-    if ( concept == null || concept.trim().equals(""))
476
-    {
477
-      throw new InvalidEcogridQueryException("Should set up concept value in " +
478
-                                         "condition type in ecogrid query");
479
-    }
480
-    else if (operator == null || operator.trim().equals(""))
481
-    {
482
-      throw new InvalidEcogridQueryException("Should set up operator value in "+
483
-                                         "condition type in ecogrid query");
484
-    }
485
-    else if (value == null || value.trim().equals(""))
486
-    {
487
-      throw new InvalidEcogridQueryException("Should set up search value in " +
488
-                                        "condition type in ecogrid query");
489
-    }
490
+    mapInValue(queryNode, false);
491
     
492
-    // replace the value by search value if this value in replacementMap
493
-    if(replacementMap.containsKey(value))
494
-    {
495
-      dbg.print("replace " + value + " by ", 2 );
496
-      value = (String)replacementMap.get(value);
497
-      dbg.print(" new value "+ value, 2);
498
+    try {
499
+        EcogridQueryParser queryParser = new EcogridQueryParser(queryNode);
500
+        queryParser.parseXML();
501
+        _query = queryParser.getEcogridQuery();
502
+        //System.out.println(EcogridQueryTransformer.toXMLString(query));
503
+    } catch (Exception e)
504
+    {
505
+        System.err.println(e);
506
     }
507
-    
508
-    // set up the limitedPathExpression (xpath)
509
-    LimitedXPathExpression path = new LimitedXPathExpression(concept);
510
 
511
-    // set up the operator
512
-    OperatorType operatorType = null;
513
-    try
514
-    {
515
-      operatorType = OperatorType.fromString(operator);
516
-    }
517
-    catch(IllegalStateException e)
518
-    {
519
-     throw new InvalidEcogridQueryException(e.getMessage());
520
-    }
521
-
522
-    //set up condition type
523
-    ConditionType condition = new ConditionType();
524
-    condition.setConcept(path);
525
-    condition.setOperator(operatorType);
526
-    condition.setValue(value);
527
-    return condition;
528
-
529
-  }//generateConditionType
530
-
531
-  
532
-}//SearchQueryGenerator
533
\ No newline at end of file
534
+  }  // generateQuery
535
+   
536
+}  // SearchQueryGenerator
537
Index: src/org/ecoinformatics/util/DebugPrinter.java
538
===================================================================
539
RCS file: /cvs/kepler/src/org/ecoinformatics/util/DebugPrinter.java,v
540
retrieving revision 1.6
541
diff -u -r1.6 DebugPrinter.java
542
--- src/org/ecoinformatics/util/DebugPrinter.java	20 Sep 2004 15:05:50 -0000	1.6
543
+++ src/org/ecoinformatics/util/DebugPrinter.java	9 Dec 2004 21:05:44 -0000
544
@@ -78,6 +78,7 @@
545
         "environment variable DBGPRN was not set to 0, 1 or 2.");
546
       DEBUG_LEVEL=0;
547
     }
548
+    //DEBUG_LEVEL=0;
549
   }
550
 
551
   /**
(2-2/4)