oodt-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mattm...@apache.org
Subject svn commit: r1446253 - in /oodt/trunk: CHANGES.txt xmlps/src/main/java/org/apache/oodt/xmlps/product/XMLPSProductHandler.java xmlps/src/main/java/org/apache/oodt/xmlps/structs/CDEResult.java
Date Thu, 14 Feb 2013 16:08:32 GMT
Author: mattmann
Date: Thu Feb 14 16:08:31 2013
New Revision: 1446253

URL: http://svn.apache.org/r1446253
Log:
- fix for OODT-564: XMLPS should provided ordered results based on requested fields

Modified:
    oodt/trunk/CHANGES.txt
    oodt/trunk/xmlps/src/main/java/org/apache/oodt/xmlps/product/XMLPSProductHandler.java
    oodt/trunk/xmlps/src/main/java/org/apache/oodt/xmlps/structs/CDEResult.java

Modified: oodt/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/oodt/trunk/CHANGES.txt?rev=1446253&r1=1446252&r2=1446253&view=diff
==============================================================================
--- oodt/trunk/CHANGES.txt (original)
+++ oodt/trunk/CHANGES.txt Thu Feb 14 16:08:31 2013
@@ -3,6 +3,9 @@ Apache OODT Change Log
 Release 0.6 - Current Development
 --------------------------------------------
 
+* OODT-564 XMLPS should provided ordered results based on 
+  requested fields (mattmann, joyce)
+
 * OODT-369 Building with Maven3 (mattmann, Adam Estrada)
 
 * OODT-555, OODT-557 - Changed behavior of Lucene Catalog update methods to retrieve a product
from the index to the cache, 

Modified: oodt/trunk/xmlps/src/main/java/org/apache/oodt/xmlps/product/XMLPSProductHandler.java
URL: http://svn.apache.org/viewvc/oodt/trunk/xmlps/src/main/java/org/apache/oodt/xmlps/product/XMLPSProductHandler.java?rev=1446253&r1=1446252&r2=1446253&view=diff
==============================================================================
--- oodt/trunk/xmlps/src/main/java/org/apache/oodt/xmlps/product/XMLPSProductHandler.java
(original)
+++ oodt/trunk/xmlps/src/main/java/org/apache/oodt/xmlps/product/XMLPSProductHandler.java
Thu Feb 14 16:08:31 2013
@@ -229,6 +229,7 @@ public class XMLPSProductHandler impleme
         if (executor != null) {
             try {
                 CDEResult res = executor.executeLocalQuery(sqlBuf.toString());
+                res.setOrderedFields(query.getSelectElementSet());
                 res.setMapping(mapping);
                 res.setConstValues(getConstValuesForQuery(query));
                 query.getResults().add(res);

Modified: oodt/trunk/xmlps/src/main/java/org/apache/oodt/xmlps/structs/CDEResult.java
URL: http://svn.apache.org/viewvc/oodt/trunk/xmlps/src/main/java/org/apache/oodt/xmlps/structs/CDEResult.java?rev=1446253&r1=1446252&r2=1446253&view=diff
==============================================================================
--- oodt/trunk/xmlps/src/main/java/org/apache/oodt/xmlps/structs/CDEResult.java (original)
+++ oodt/trunk/xmlps/src/main/java/org/apache/oodt/xmlps/structs/CDEResult.java Thu Feb 14
16:08:31 2013
@@ -17,19 +17,24 @@
 
 package org.apache.oodt.xmlps.structs;
 
-//JDK imports
+//OODT imports
 import org.apache.oodt.xmlps.mapping.Mapping;
 import org.apache.oodt.xmlps.mapping.MappingField;
 import org.apache.oodt.xmlps.mapping.funcs.MappingFunc;
+import org.apache.oodt.xmlquery.QueryElement;
 import org.apache.oodt.xmlquery.Result;
 
+//JDK imports
 import java.io.IOException;
 import java.io.InputStream;
 import java.sql.Connection;
 import java.sql.ResultSet;
 import java.sql.ResultSetMetaData;
 import java.sql.SQLException;
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
+import java.util.Vector;
 
 /**
  * A {@link Result} that wraps a {@link ResultSet} and returns rows as Strings,
@@ -46,12 +51,17 @@ public class CDEResult extends Result {
   private final Connection con;
   private Mapping mapping;
   private List<CDEValue> constValues;
+  private List<QueryElement> orderedFields;
 
   public CDEResult(ResultSet rs, Connection con) {
     this.rs = rs;
     this.con = con;
     setMimeType("text/plain");
   }
+  
+  public void setOrderedFields(List<QueryElement> orderedFields){
+    this.orderedFields = orderedFields;    
+  }
 
   public void setMapping(Mapping mapping) {
     this.mapping = mapping;
@@ -85,8 +95,11 @@ public class CDEResult extends Result {
       CDERow row = createCDERow();
       if (mapping != null)
         applyMappingFuncs(row);
-      if (constValues != null)
+      if (this.constValues != null && 
+          ((this.orderedFields == null) || 
+          (this.orderedFields != null && this.orderedFields.size() == 0))){
         addConstValues(row);
+      }
       // if there is some kind of configurable response writer,
       // here would be a nice place to put it...
       return row.toString() + ROW_TERMINATOR;
@@ -98,15 +111,36 @@ public class CDEResult extends Result {
     CDERow row = new CDERow();
     ResultSetMetaData met = rs.getMetaData();
     int count = met.getColumnCount();
+    Map<String, CDEValue> dbValMap = new HashMap<String, CDEValue>();
+    Map<String, CDEValue> constValMap = cdeListToMap(this.constValues);
+    List<CDEValue> orderedDbVals = new Vector<CDEValue>();
+    
     for (int i = 1; i <= count; i++) {
       // since the SQL query was built with "SELECT ${fieldlocalname} as ${fieldname}"
       // we know that ResultSet column names equal CDE field names
       // and appear in the correct order as well
-      String colName = met.getColumnName(i);
+      String fieldLocalColName = met.getColumnLabel(i);
       String colValue = rs.getString(i);
-      CDEValue val = new CDEValue(colName, colValue);
-      row.getVals().add(val);
+      CDEValue val = new CDEValue(fieldLocalColName, colValue);
+      dbValMap.put(fieldLocalColName, val);
+      orderedDbVals.add(val);
     }
+    
+    // now have the constant values, and the db values, order the row
+    if(this.orderedFields != null){
+      for(QueryElement qe: this.orderedFields){
+        String qeCdeVal = this.mapping.getFieldByLocalName(qe.getValue()).getName();
+        if(dbValMap.containsKey(qeCdeVal)){
+          row.getVals().add(dbValMap.get(qeCdeVal));
+        }
+        else if(constValMap.containsKey(qeCdeVal)){
+          row.getVals().add(constValMap.get(qeCdeVal));
+        }
+      }
+    }
+    else row.getVals().addAll(orderedDbVals);
+    
+    
     return row;
   }
 
@@ -121,9 +155,20 @@ public class CDEResult extends Result {
       }
     }
   }
-
+  
   private void addConstValues(CDERow row) {
     row.getVals().addAll(constValues);
+  }  
+  
+  private Map<String, CDEValue> cdeListToMap(List<CDEValue> vals){
+    Map<String, CDEValue> map = new HashMap<String, CDEValue>();
+    if(vals != null){
+      for(CDEValue val: vals){
+        map.put(val.getCdeName(), val);
+      }
+    }
+    
+    return map;
   }
 
 }



Mime
View raw message