svn - r34358 - in branches/2.6.x/modules/unsupported/app-schema: . app-schema/src/main/java/org/geotools/data/complex app-schema/src/main/java/org/geotools/data/complex/filter app-schema/src/test/java/org/geotools/data/complex app-schema/src/test/resources/test-data

1 message Options
Embed this post
Permalink
svn_geotools

svn - r34358 - in branches/2.6.x/modules/unsupported/app-schema: . app-schema/src/main/java/org/geotools/data/complex app-schema/src/main/java/org/geotools/data/complex/filter app-schema/src/test/java/org/geotools/data/complex app-schema/src/test/resources/test-data

Reply Threaded More More options
Print post
Permalink
Author: bencaradocdavies
Date: 2009-11-09 21:58:00 -0500 (Mon, 09 Nov 2009)
New Revision: 34358

Modified:
   branches/2.6.x/modules/unsupported/app-schema/
   branches/2.6.x/modules/unsupported/app-schema/app-schema/src/main/java/org/geotools/data/complex/XmlFeatureTypeMapping.java
   branches/2.6.x/modules/unsupported/app-schema/app-schema/src/main/java/org/geotools/data/complex/filter/UnmappingFilterVisitor.java
   branches/2.6.x/modules/unsupported/app-schema/app-schema/src/main/java/org/geotools/data/complex/filter/XPath.java
   branches/2.6.x/modules/unsupported/app-schema/app-schema/src/test/java/org/geotools/data/complex/XmlDataStoreTest.java
   branches/2.6.x/modules/unsupported/app-schema/app-schema/src/test/resources/test-data/xmlDataAccessConfig.xml
Log:
Merged r34195-r34355 from trunk, including patch for GEOT-2777, but not including poms


Property changes on: branches/2.6.x/modules/unsupported/app-schema
___________________________________________________________________
Added: svn:mergeinfo
   + /trunk/modules/unsupported/app-schema:34195-34355

Modified: branches/2.6.x/modules/unsupported/app-schema/app-schema/src/main/java/org/geotools/data/complex/XmlFeatureTypeMapping.java
===================================================================
--- branches/2.6.x/modules/unsupported/app-schema/app-schema/src/main/java/org/geotools/data/complex/XmlFeatureTypeMapping.java 2009-11-10 02:53:48 UTC (rev 34357)
+++ branches/2.6.x/modules/unsupported/app-schema/app-schema/src/main/java/org/geotools/data/complex/XmlFeatureTypeMapping.java 2009-11-10 02:58:00 UTC (rev 34358)
@@ -110,6 +110,20 @@
                 mappings.add(mapping.get(listPath));
             }
         }
+        
+        if (mappings.isEmpty()) {
+            // look in the setter attributes
+            Iterator<TreeAttributeMapping> leafAtts = setterAttributes.iterator();
+            while (leafAtts.hasNext()) {
+                TreeAttributeMapping att = leafAtts.next();
+                String listPath = att.getTargetXPath().toString();
+                String unindexedListPath = removeIndexFromPath(listPath);
+                if (path.equals(unindexedListPath)) {
+                    mappings.add(att.getSourceExpression().toString());
+                }
+            }
+
+        }
         return mappings;
     }
 

Modified: branches/2.6.x/modules/unsupported/app-schema/app-schema/src/main/java/org/geotools/data/complex/filter/UnmappingFilterVisitor.java
===================================================================
--- branches/2.6.x/modules/unsupported/app-schema/app-schema/src/main/java/org/geotools/data/complex/filter/UnmappingFilterVisitor.java 2009-11-10 02:53:48 UTC (rev 34357)
+++ branches/2.6.x/modules/unsupported/app-schema/app-schema/src/main/java/org/geotools/data/complex/filter/UnmappingFilterVisitor.java 2009-11-10 02:58:00 UTC (rev 34358)
@@ -30,6 +30,8 @@
 import javax.xml.XMLConstants;
 import javax.xml.namespace.QName;
 
+import org.geotools.data.DataAccess;
+import org.geotools.data.complex.AppSchemaDataAccess;
 import org.geotools.data.complex.AppSchemaDataAccessRegistry;
 import org.geotools.data.complex.AttributeMapping;
 import org.geotools.data.complex.FeatureTypeMapping;
@@ -39,6 +41,7 @@
 import org.geotools.factory.CommonFactoryFinder;
 import org.geotools.feature.NameImpl;
 import org.geotools.feature.Types;
+import org.geotools.filter.AttributeExpressionImpl;
 import org.geotools.filter.NestedAttributeExpression;
 import org.opengis.feature.type.AttributeDescriptor;
 import org.opengis.feature.type.Name;
@@ -782,21 +785,22 @@
         NamespaceSupport namespaces = mappings.getNamespaces();
         AttributeDescriptor root = mappings.getTargetFeature();
 
+        // break into single steps
         StepList simplifiedSteps = XPath.steps(root, targetXPath, namespaces);
 
         List<Expression> matchingMappings = findMappingsFor(mappings, simplifiedSteps);
 
-        if (matchingMappings.size() == 0 && simplifiedSteps.size() > 1) {
-            // means some attributes are probably mapped separately
-
+        if (matchingMappings.isEmpty() && simplifiedSteps.size() > 1) {
+            // means some attributes are probably mapped separately in feature chaining
             if (simplifiedSteps.size() % 2 == 0) {
-                // the last one could be a client property
+                // there should be at least 3 steps:
+                // - 1st one is the attribute of root feature
+                // - 2nd one denotes the element type of the next feature type
+                // - 3rd one is the attribute of the nested feature
+                // exception is when the last attribute is an xml attribute
+                // eg. @srsName
                 Step lastStep = simplifiedSteps.get(simplifiedSteps.size() - 1);
                 if (!lastStep.isXmlAttribute()) {
-                    // there should be at least 3 steps:
-                    // - 1st one is the attribute of parent feature
-                    // - 2nd one denotes the element type of the nested feature
-                    // - 3rd one is the attribute of the nested feature
                     throw new UnsupportedOperationException(
                             "Are you sure the filter property makes sense? "
                                     + "Please check the property path again. "
@@ -805,27 +809,31 @@
             }
             boolean hasNestedFeature = false;
 
-            List<Expression> nestedMappings = new ArrayList<Expression>();
-
-            StepList processedSteps = simplifiedSteps.clone();
-
-            processedSteps.remove(processedSteps.size() - 1);
-
-            int firstIndex = 0;
-
-            FeatureTypeMapping fMapping = mappings;
-            Name featureTypeName = root.getName();
+            List<Expression> nestedMappings = new ArrayList<Expression>();            
             // since we can mix chained(when a type is mapped separately), and normal
             // inline attributes in the path expression, we have to try to find the mapping from the
-            // complete
-            // path down, eg. for "gsml:specification/gsml:GeologicUnit/gsml:description",
-            // we can't tell if the path is an inline attribute specified in the mapping
+            // root step and check if the mapping exists for the path.. if they don't, try one step
+            // further. If they are feature-chained, the leaf attributes could be mapped in the
+            // chained type,
+            // eg. for "gsml:specification/gsml:GeologicUnit/gsml:description",
+            // we can't tell if the path is an inline attribute specified in the main mapping
             // or if the mapping only has "gsml:specification", and the mapping for
-            // gsml:GeologicUnit is mapped somewhere else separately.
+            // gsml:GeologicUnit is mapped separately in a different file.
             // If the latter is the case, we need to also find the mapping for
             // gsml:description in gsml:GeologicUnit.
-            while (!processedSteps.isEmpty()) {
-                AttributeMapping mapping = fMapping.getAttributeMapping(processedSteps);
+            StepList nextSteps = simplifiedSteps.subList(0, 1);
+            // where the search index starts eg. for a/b/c, if we're searching for b/c, index = 1
+            int nextRootIndex = 0;
+            // increment step from index, eg. if we want to search for b/c from originally searching
+            // for b, increment by 1
+            int stepIncrement = 0;
+            boolean isNestedMapping = false;
+            boolean incrementStep = false;
+            FeatureTypeMapping fMapping = mappings;
+            Name featureTypeName = root.getName();
+            
+            while (nextRootIndex + stepIncrement < simplifiedSteps.size()) {
+                AttributeMapping mapping = fMapping.getAttributeMapping(nextSteps);
                 if (mapping != null) {
                     if (mapping instanceof NestedAttributeMapping) {
                         // mapping is found to be a chained feature
@@ -834,12 +842,15 @@
                         nestedMappings.add(ff.literal(featureTypeName));
                         nestedMappings.add(mapping.getSourceExpression());
 
-                        if (firstIndex < simplifiedSteps.size() - 1) {
+                        if (nextRootIndex < simplifiedSteps.size() - 1) {
+                            isNestedMapping = true;
                             // if this is not the last element and it's chained, we need to get its
                             // feature type mapping for the next attribute
                             try {
-                                Step nextRootStep = simplifiedSteps.get(firstIndex
-                                        + processedSteps.size());
+                                Step nextRootStep = simplifiedSteps.get(nextRootIndex
+                                        + nextSteps.size());
+                                // skip the nested feature type
+                                nextRootIndex++;
                                 Expression clientPropertyExpression = getClientPropertyExpression(
                                         nextRootStep, fMapping, mapping, targetXPath);
                                 if (clientPropertyExpression != null) {
@@ -853,11 +864,15 @@
                                 if (AppSchemaDataAccessRegistry.hasName(featureTypeName)) {
                                     fMapping = AppSchemaDataAccessRegistry
                                             .getMapping(featureTypeName);
+                                    // feature chaining detected.. search the attribute in the chained
+                                    // feature type
+                                    nextSteps = simplifiedSteps.subList(++nextRootIndex,
+                                            nextRootIndex + 1);
+                                    // starting from the root only
+                                    stepIncrement = 0;
                                 } else {
-                                    // not configured inside an app-schema data access
-                                    // therefore simple features may not be available
-                                    // so we will just evaluate the complex features
-                                    // and we don't need the source expression
+                                    // might be because the complex features aren't from an
+                                    // app-schema data access, which is possible.. stop looking
                                     break;
                                 }
                             } catch (IOException e) {
@@ -867,44 +882,79 @@
                         }
                     } else {
                         // find regular attribute mapping
-                        List<Expression> matchedExpressions = findMappingsFor(fMapping,
-                                processedSteps);
+                        List<Expression> matchedExpressions = findMappingsFor(fMapping, nextSteps);
                         if (matchedExpressions.size() > 1) {
                             throw new UnsupportedOperationException(
                                     "Unmapping attributes that map "
                                             + "to more than one source expressions is not supported yet");
                         }
-                        if (processedSteps.size() == 1 && (matchedExpressions.size() < 1)) {
-                            // last one.. and no matching mapping is found
-                            throw new IllegalArgumentException("Don't know how to map "
-                                    + targetXPath);
+                        boolean isLast = (nextRootIndex + stepIncrement + 1) >= simplifiedSteps.size();
+                        if (isLast) {
+                            if (matchedExpressions.size() < 1) {
+                                // no matching expression is found and we can't go further
+                                throw new IllegalArgumentException(
+                                        "Can't find source expression for: " + targetXPath);
+                            }
                         }
-                        if (!matchedExpressions.get(0).equals(Expression.NIL)) {
-                            nestedMappings.add(ff.literal(featureTypeName));
-                            nestedMappings.add(matchedExpressions.get(0));
+                        if (isNestedMapping) {
+                            if (!matchedExpressions.get(0).equals(Expression.NIL)) {
+                                nestedMappings.add(ff.literal(featureTypeName));
+                                nestedMappings.add(matchedExpressions.get(0));
+                                nextRootIndex++;
+                                stepIncrement = 0;
+                                isNestedMapping = false;
+                            }
+                        } else if (isLast) {
+                            // must be it
+                            matchingMappings.add(matchedExpressions.get(0));
+                        } else {
+                            // not the last.. check if the leaf attributes are mapped in the back
+                            // end
+                            DataAccess da = this.mappings.getSource().getDataStore();
+                            if (da instanceof AppSchemaDataAccess) {
+                                // check if the leaf attributes are mapped in the
+                                // back end complex features mapping
+                                FeatureTypeMapping backEndMappings;
+                                try {
+                                    backEndMappings = ((AppSchemaDataAccess) da)
+                                            .getMapping(featureTypeName);
+                                } catch (IOException e) {
+                                    throw new UnsupportedOperationException("Mapping for '"
+                                            + featureTypeName + "' not found!!");
+                                }
+                                AttributeMapping wrappedMapping = backEndMappings
+                                        .getAttributeMapping(simplifiedSteps.subList(nextRootIndex,
+                                                simplifiedSteps.size()));
+                                if (wrappedMapping != null) {
+                                    // it is mapped, but in the back end
+                                    matchingMappings.add(new AttributeExpressionImpl(wrappedMapping
+                                            .getTargetXPath().toString()));
+                                    break;
+                                }
+                            }
                         }
+                        if (isLast) {
+                            break;
+                        }
+                        // not last, keep going
+                        incrementStep = true;
                     }
-
-                    // break if this is the last
-                    if (processedSteps.size() + firstIndex == simplifiedSteps.size()) {
+                }
+                if (incrementStep || mapping == null) {
+                    // if mapping is not found, it could be that only the full leaf attribute
+                    // is mapped, so keep looking
+                    stepIncrement++;
+                    incrementStep = false;
+                    int nextStepIndex = nextRootIndex + stepIncrement;
+                    if (nextStepIndex < simplifiedSteps.size()) {
+                        // add the next step and try finding the next combination
+                        nextSteps.add(simplifiedSteps.get(nextStepIndex));
+                    } else {
+                        // no more steps.. leave it empty and it will throw exception later
+                        matchingMappings.clear();
                         break;
                     }
-
                 }
-                // try without the last attribute in case the expression is an inline attribute
-                if (processedSteps.size() > 1) {
-                    processedSteps.remove(processedSteps.size() - 1);
-                } else if (firstIndex == simplifiedSteps.size() - 1) {
-                    // break if this is last
-                    break;
-                } else {
-                    // move to the next attribute in the expression as a starting point
-                    processedSteps = simplifiedSteps.clone();
-                    for (int i = 0; i <= firstIndex; i++) {
-                        processedSteps.remove(0);
-                    }
-                    firstIndex++;
-                }
             }
             if (hasNestedFeature) {
                 // we should only go on if the path legitimately has a chained feature
@@ -915,7 +965,7 @@
         }
 
         if (matchingMappings.size() == 0) {
-            throw new IllegalArgumentException("Don't know how to map " + targetXPath);
+            throw new IllegalArgumentException("Can't find source expression for: " + targetXPath);
         }
 
         return matchingMappings;

Modified: branches/2.6.x/modules/unsupported/app-schema/app-schema/src/main/java/org/geotools/data/complex/filter/XPath.java
===================================================================
--- branches/2.6.x/modules/unsupported/app-schema/app-schema/src/main/java/org/geotools/data/complex/filter/XPath.java 2009-11-10 02:53:48 UTC (rev 34357)
+++ branches/2.6.x/modules/unsupported/app-schema/app-schema/src/main/java/org/geotools/data/complex/filter/XPath.java 2009-11-10 02:58:00 UTC (rev 34358)
@@ -130,6 +130,21 @@
             }
             return sb.toString();
         }
+        
+        public StepList subList(int fromIndex, int toIndex) {
+            if (fromIndex < 0)
+                throw new IndexOutOfBoundsException("fromIndex = " + fromIndex);
+            if (toIndex > size())
+                throw new IndexOutOfBoundsException("toIndex = " + toIndex);
+            if (fromIndex > toIndex)
+                throw new IllegalArgumentException("fromIndex(" + fromIndex +
+                                                   ") > toIndex(" + toIndex + ")");
+            StepList subList = new StepList();
+            for (int i = fromIndex; i < toIndex; i++) {
+                subList.add(this.get(i));
+            }
+            return subList;
+        }
 
         public StepList clone() {
             StepList copy = new StepList();

Modified: branches/2.6.x/modules/unsupported/app-schema/app-schema/src/test/java/org/geotools/data/complex/XmlDataStoreTest.java
===================================================================
--- branches/2.6.x/modules/unsupported/app-schema/app-schema/src/test/java/org/geotools/data/complex/XmlDataStoreTest.java 2009-11-10 02:53:48 UTC (rev 34357)
+++ branches/2.6.x/modules/unsupported/app-schema/app-schema/src/test/java/org/geotools/data/complex/XmlDataStoreTest.java 2009-11-10 02:58:00 UTC (rev 34358)
@@ -133,7 +133,7 @@
     }
 
     public void testFilterTranslation() throws Exception {
-        final String expectedTranslatedFilter = getExpectedFilter();
+      //tests that the translation of the filter from GeoSciML to the xml datasorce works.
         Filter inputFilter = ff.equals(ff.property("gml:name"), ff
                 .literal("Unit Name1233811724109 UC1233811724109 description name"));
         
@@ -149,7 +149,8 @@
 
         assertEquals(MAX_FEATURES, query.getMaxFeatures());
         String translatedFilter = query.getFilter().toString();
-        assertEquals(expectedTranslatedFilter, translatedFilter);
+        assertTrue(getExpectedFilter().equals(translatedFilter) ||
+                getReversedExpectedFilter().equals(translatedFilter));
     }
 
     public void testFeatureCounting() throws Exception {
@@ -646,6 +647,16 @@
                 + "gss:urn[@domain='GSV'] = Unit Name1233811724109 UC1233811724109 description name ]]";
     }
 
+    private String getReversedExpectedFilter() {
+        final String prefix = "/soapenv:Envelope/soapenv:Body/qaz:getGeologicalFeaturesByFilterStringResponse/qaz:out/qaz:item/";
+        return "[[ "
+                + prefix
+                + "gss:urn[@domain='GSV'] = Unit Name1233811724109 UC1233811724109 description name ] OR "
+                + "[ "
+                + prefix
+                + "gss:formattedName = Unit Name1233811724109 UC1233811724109 description name ]]";
+    }
+    
     private FeatureCollection getFeatures(final int maxFeatures, Filter inputFilter)
             throws Exception {
         FeatureSource fSource = (FeatureSource) mappingDataStore.getFeatureSource(typeName);

Modified: branches/2.6.x/modules/unsupported/app-schema/app-schema/src/test/resources/test-data/xmlDataAccessConfig.xml
===================================================================
--- branches/2.6.x/modules/unsupported/app-schema/app-schema/src/test/resources/test-data/xmlDataAccessConfig.xml 2009-11-10 02:53:48 UTC (rev 34357)
+++ branches/2.6.x/modules/unsupported/app-schema/app-schema/src/test/resources/test-data/xmlDataAccessConfig.xml 2009-11-10 02:58:00 UTC (rev 34358)
@@ -94,7 +94,7 @@
            <name>codeSpace</name>
            <value>'gsv:NameSpace'</value>
          </ClientProperty>
-         </AttributeMapping>            
+         </AttributeMapping>    
 
          <AttributeMapping>
             <parentLabel>gsml:GeologicUnit</parentLabel>          


------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
GeoTools-commits mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/geotools-commits