Skip to content

Commit

Permalink
[GEOT-5920] WFSClient fails when a function is used in a query (#1883)
Browse files Browse the repository at this point in the history
  • Loading branch information
ianturton committed May 8, 2018
1 parent 6a7e2e3 commit 3d33f39
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 4 deletions.
Expand Up @@ -312,7 +312,7 @@ protected Document encode(Object object, QName element, QName type) throws Excep
}

ByteArrayOutputStream output = new ByteArrayOutputStream();
encoder.write(object, element, output);
encoder.encode(object, element, output);

DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
dbf.setNamespaceAware(true);
Expand Down
Expand Up @@ -22,8 +22,8 @@
import org.geotools.xml.Node;
import org.opengis.filter.FilterFactory;
import org.opengis.filter.PropertyIsLike;
import org.opengis.filter.expression.Expression;
import org.opengis.filter.expression.Literal;
import org.opengis.filter.expression.PropertyName;

/**
* Binding object for the type http://www.opengis.net/ogc:PropertyIsLikeType.
Expand Down Expand Up @@ -83,7 +83,7 @@ public Class getType() {
* @generated modifiable
*/
public Object parse(ElementInstance instance, Node node, Object value) throws Exception {
PropertyName name = (PropertyName) node.getChildValue(PropertyName.class);
Expression name = (Expression) node.getChildValue(Expression.class);
Literal literal = (Literal) node.getChildValue(Literal.class);

String wildcard = (String) node.getAttributeValue("wildCard");
Expand All @@ -106,6 +106,10 @@ public Object parse(ElementInstance instance, Node node, Object value) throws Ex
public Object getProperty(Object object, QName name) throws Exception {
PropertyIsLike isLike = (PropertyIsLike) object;

if (OGC.expression.equals(name)) {
return isLike.getExpression();
}

if (OGC.PropertyName.equals(name)) {
return isLike.getExpression();
}
Expand Down
Expand Up @@ -74,7 +74,7 @@
<xsd:complexContent>
<xsd:extension base="ogc:ComparisonOpsType">
<xsd:sequence>
<xsd:element ref="ogc:PropertyName"/>
<xsd:element ref="ogc:expression"/>
<xsd:element ref="ogc:Literal"/>
</xsd:sequence>
<xsd:attribute name="wildCard" type="xsd:string" use="required"/>
Expand Down
Expand Up @@ -180,6 +180,21 @@ public void testPropertyIsGreaterThanEncode() throws Exception {
PropertyIsGreaterThan equalTo = FilterMockData.propertyIsGreaterThan();

Document dom = encode(equalTo, OGC.PropertyIsGreaterThan);

assertEquals(
1,
dom.getElementsByTagNameNS(OGC.NAMESPACE, OGC.PropertyName.getLocalPart())
.getLength());
assertEquals(
1,
dom.getElementsByTagNameNS(OGC.NAMESPACE, OGC.Literal.getLocalPart()).getLength());
}

public void testPropertyFunctionIsGreaterThanEncode() throws Exception {
PropertyIsGreaterThan equalTo = FilterMockData.propertyFuncIsGreaterThan();

Document dom = encode(equalTo, OGC.PropertyIsGreaterThan);
// print(dom);
assertEquals(
1,
dom.getElementsByTagNameNS(OGC.NAMESPACE, OGC.PropertyName.getLocalPart())
Expand Down
Expand Up @@ -37,6 +37,7 @@
import org.opengis.filter.PropertyIsNull;
import org.opengis.filter.expression.Add;
import org.opengis.filter.expression.Divide;
import org.opengis.filter.expression.Expression;
import org.opengis.filter.expression.Function;
import org.opengis.filter.expression.Literal;
import org.opengis.filter.expression.Multiply;
Expand Down Expand Up @@ -82,6 +83,11 @@ static PropertyName propertyName() {
return propertyName("foo");
}

private static Expression propertyNameIsFunc() {

return f.function("strToLowerCase", propertyName("foo"));
}

static PropertyName propertyName(String property) {
return f.property(property);
}
Expand Down Expand Up @@ -145,6 +151,10 @@ static PropertyIsGreaterThan propertyIsGreaterThan() {
return f.greater(propertyName(), literal());
}

static PropertyIsGreaterThan propertyFuncIsGreaterThan() {
return f.greater(propertyNameIsFunc(), literal());
}

static Element propertyIsGreaterThanOrEqualTo(Document document, Node parent) {
return binaryComparisonOp(document, parent, OGC.PropertyIsGreaterThanOrEqualTo);
}
Expand Down Expand Up @@ -194,6 +204,12 @@ static PropertyIsLike propertyIsLike() {
return f.like(propertyName(), "foo", "x", "y", "z");
}

static PropertyIsLike propertyIsLike2() {
PropertyIsLike filter = f.like(propertyNameIsFunc(), "foo", "x", "y", "z");

return filter;
}

static Element propertyIsLike(Document document, Node parent) {
Element isLike = element(document, parent, OGC.PropertyIsLike);

Expand Down
Expand Up @@ -20,6 +20,7 @@
import org.opengis.filter.PropertyIsLike;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;

/** @source $URL$ */
public class OGCPropertyIsLikeTypeBindingTest extends FilterTestSupport {
Expand Down Expand Up @@ -79,4 +80,33 @@ public void testEncodeAsFilter() throws Exception {
assertEquals("y", e.getAttribute("singleChar"));
assertEquals("z", e.getAttribute("escape"));
}

public void testEncodeWithFunctionAsFilter() throws Exception {
Document doc = encode(FilterMockData.propertyIsLike2(), OGC.Filter);
// print(doc);

NodeList property =
doc.getDocumentElement()
.getElementsByTagNameNS(OGC.NAMESPACE, OGC.Function.getLocalPart());
assertEquals(1, property.getLength());

assertNotNull(property.item(0).getChildNodes());
assertNotSame("", property.item(0).getNodeValue());
assertEquals(
1,
doc.getDocumentElement()
.getElementsByTagNameNS(OGC.NAMESPACE, OGC.Literal.getLocalPart())
.getLength());

Element e = getElementByQName(doc, OGC.PropertyIsLike);
assertEquals("x", e.getAttribute("wildCard"));
assertEquals("y", e.getAttribute("singleChar"));
assertEquals("z", e.getAttribute("escape"));

Element p = getElementByQName(e, OGC.Function);
assertEquals("strToLowerCase", p.getAttribute("name"));
Element pn = getElementByQName(p, OGC.PropertyName);

assertEquals("foo", pn.getTextContent());
}
}

0 comments on commit 3d33f39

Please sign in to comment.