Search in sources :

Example 11 with PropertyIsLikeType

use of org.geotoolkit.ogc.xml.v100.PropertyIsLikeType in project geotoolkit by Geomatys.

the class FilterToOGC110Converter method visit.

public JAXBElement<?> visit(final Filter filter) {
    if (filter.equals(Filter.include())) {
        return null;
    }
    if (filter.equals(Filter.exclude())) {
        return null;
    }
    final CodeList<?> type = filter.getOperatorType();
    if (filter instanceof BetweenComparisonOperator) {
        final BetweenComparisonOperator pib = (BetweenComparisonOperator) filter;
        final LowerBoundaryType lbt = ogc_factory.createLowerBoundaryType();
        lbt.setExpression(extract(pib.getLowerBoundary()));
        final UpperBoundaryType ubt = ogc_factory.createUpperBoundaryType();
        ubt.setExpression(extract(pib.getUpperBoundary()));
        final PropertyIsBetweenType bot = new PropertyIsBetweenType(extract(pib.getExpression()), lbt, ubt);
        return ogc_factory.createPropertyIsBetween(bot);
    } else if (type == ComparisonOperatorName.PROPERTY_IS_EQUAL_TO) {
        final BinaryComparisonOperator pit = (BinaryComparisonOperator) filter;
        final PropertyIsEqualToType bot = ogc_factory.createPropertyIsEqualToType();
        bot.getExpression().add(extract(pit.getOperand1()));
        bot.getExpression().add(extract(pit.getOperand2()));
        return ogc_factory.createPropertyIsEqualTo(bot);
    } else if (type == ComparisonOperatorName.PROPERTY_IS_GREATER_THAN) {
        final BinaryComparisonOperator pit = (BinaryComparisonOperator) filter;
        final PropertyIsGreaterThanType bot = ogc_factory.createPropertyIsGreaterThanType();
        bot.getExpression().add(extract(pit.getOperand1()));
        bot.getExpression().add(extract(pit.getOperand2()));
        return ogc_factory.createPropertyIsGreaterThan(bot);
    } else if (type == ComparisonOperatorName.PROPERTY_IS_GREATER_THAN_OR_EQUAL_TO) {
        final BinaryComparisonOperator pit = (BinaryComparisonOperator) filter;
        final PropertyIsGreaterThanOrEqualToType bot = ogc_factory.createPropertyIsGreaterThanOrEqualToType();
        bot.getExpression().add(extract(pit.getOperand1()));
        bot.getExpression().add(extract(pit.getOperand2()));
        return ogc_factory.createPropertyIsGreaterThanOrEqualTo(bot);
    } else if (type == ComparisonOperatorName.PROPERTY_IS_LESS_THAN) {
        final BinaryComparisonOperator pit = (BinaryComparisonOperator) filter;
        final PropertyIsLessThanType bot = ogc_factory.createPropertyIsLessThanType();
        bot.getExpression().add(extract(pit.getOperand1()));
        bot.getExpression().add(extract(pit.getOperand2()));
        return ogc_factory.createPropertyIsLessThan(bot);
    } else if (type == ComparisonOperatorName.PROPERTY_IS_LESS_THAN_OR_EQUAL_TO) {
        final BinaryComparisonOperator pit = (BinaryComparisonOperator) filter;
        final PropertyIsLessThanOrEqualToType bot = ogc_factory.createPropertyIsLessThanOrEqualToType();
        bot.getExpression().add(extract(pit.getOperand1()));
        bot.getExpression().add(extract(pit.getOperand2()));
        return ogc_factory.createPropertyIsLessThanOrEqualTo(bot);
    } else if (filter instanceof LikeOperator) {
        final LikeOperator pis = (LikeOperator) filter;
        final List<Expression> expressions = filter.getExpressions();
        final PropertyIsLikeType bot = ogc_factory.createPropertyIsLikeType();
        bot.setEscapeChar(String.valueOf(pis.getEscapeChar()));
        final LiteralType lt = ogc_factory.createLiteralType();
        lt.setContent(((Literal) expressions.get(1)).getValue());
        bot.setLiteral(lt.getStringValue());
        final Expression expression = expressions.get(0);
        if (!(expression instanceof ValueReference)) {
            throw new IllegalArgumentException("LikeOperator can support ValueReference only, but was a " + expression);
        }
        final PropertyNameType pnt = (PropertyNameType) extract(expression).getValue();
        bot.setPropertyName(pnt);
        bot.setSingleChar(String.valueOf(pis.getSingleChar()));
        bot.setWildCard(String.valueOf(pis.getWildCard()));
        return ogc_factory.createPropertyIsLike(bot);
    } else if (type == ComparisonOperatorName.PROPERTY_IS_NOT_EQUAL_TO) {
        final BinaryComparisonOperator pit = (BinaryComparisonOperator) filter;
        final PropertyIsNotEqualToType bot = ogc_factory.createPropertyIsNotEqualToType();
        bot.getExpression().add(extract(pit.getOperand1()));
        bot.getExpression().add(extract(pit.getOperand2()));
        return ogc_factory.createPropertyIsNotEqualTo(bot);
    } else if (filter instanceof NullOperator) {
        final NullOperator pis = (NullOperator) filter;
        final PropertyIsNullType bot = ogc_factory.createPropertyIsNullType();
        final Object obj = extract((Expression) pis.getExpressions().get(0)).getValue();
        bot.setPropertyName((PropertyNameType) obj);
        return ogc_factory.createPropertyIsNull(bot);
    } else if (type == LogicalOperatorName.AND) {
        final LogicalOperator and = (LogicalOperator) filter;
        final List<JAXBElement> children = new ArrayList<>();
        for (final Filter f : (List<Filter>) and.getOperands()) {
            final JAXBElement<? extends LogicOpsType> ele = (JAXBElement<? extends LogicOpsType>) visit(f);
            if (ele != null) {
                children.add(ele);
            }
        }
        return ogc_factory.createAnd(new AndType(children.toArray()));
    } else if (type == LogicalOperatorName.OR) {
        final LogicalOperator or = (LogicalOperator) filter;
        final List<JAXBElement> children = new ArrayList<>();
        for (final Filter f : (List<Filter>) or.getOperands()) {
            final JAXBElement<? extends LogicOpsType> ele = (JAXBElement<? extends LogicOpsType>) visit(f);
            if (ele != null) {
                children.add(ele);
            }
        }
        return ogc_factory.createOr(new OrType(children.toArray()));
    } else if (type == LogicalOperatorName.NOT) {
        final LogicalOperator not = (LogicalOperator) filter;
        JAXBElement<?> sf = visit((Filter) not.getOperands().get(0));
        return ogc_factory.createNot(new NotType(sf.getValue()));
    } else if (filter instanceof ResourceId) {
        throw new IllegalArgumentException("Not parsed yet : " + filter);
    } else if (type == SpatialOperatorName.BBOX) {
        final BBOX bbox = BBOX.wrap((BinarySpatialOperator) filter);
        final Expression left = bbox.getOperand1();
        final Expression right = bbox.getOperand2();
        final String property;
        final double minx;
        final double maxx;
        final double miny;
        final double maxy;
        String srs;
        if (left instanceof ValueReference) {
            property = ((ValueReference) left).getXPath();
            final Object objGeom = ((Literal) right).getValue();
            if (objGeom instanceof org.opengis.geometry.Envelope) {
                final org.opengis.geometry.Envelope env = (org.opengis.geometry.Envelope) objGeom;
                minx = env.getMinimum(0);
                maxx = env.getMaximum(0);
                miny = env.getMinimum(1);
                maxy = env.getMaximum(1);
                try {
                    srs = IdentifiedObjects.lookupURN(env.getCoordinateReferenceSystem(), null);
                    if (srs == null) {
                        srs = ReferencingUtilities.lookupIdentifier(env.getCoordinateReferenceSystem(), true);
                    }
                } catch (FactoryException ex) {
                    throw new IllegalArgumentException("invalid bbox element : " + filter + " " + ex.getMessage(), ex);
                }
            } else if (objGeom instanceof Geometry) {
                final Geometry geom = (Geometry) objGeom;
                final Envelope env = geom.getEnvelopeInternal();
                minx = env.getMinX();
                maxx = env.getMaxX();
                miny = env.getMinY();
                maxy = env.getMaxY();
                srs = SRIDGenerator.toSRS(geom.getSRID(), SRIDGenerator.Version.V1);
            } else {
                throw new IllegalArgumentException("invalide bbox element : " + filter);
            }
        } else if (right instanceof ValueReference) {
            property = ((ValueReference) right).getXPath();
            final Object objGeom = ((Literal) left).getValue();
            if (objGeom instanceof org.opengis.geometry.Envelope) {
                final org.opengis.geometry.Envelope env = (org.opengis.geometry.Envelope) objGeom;
                minx = env.getMinimum(0);
                maxx = env.getMaximum(0);
                miny = env.getMinimum(1);
                maxy = env.getMaximum(1);
                try {
                    srs = IdentifiedObjects.lookupURN(env.getCoordinateReferenceSystem(), null);
                } catch (FactoryException ex) {
                    throw new IllegalArgumentException("invalide bbox element : " + filter + " " + ex.getMessage(), ex);
                }
            } else if (objGeom instanceof Geometry) {
                final Geometry geom = (Geometry) objGeom;
                final Envelope env = geom.getEnvelopeInternal();
                minx = env.getMinX();
                maxx = env.getMaxX();
                miny = env.getMinY();
                maxy = env.getMaxY();
                srs = SRIDGenerator.toSRS(geom.getSRID(), SRIDGenerator.Version.V1);
            } else {
                throw new IllegalArgumentException("invalide bbox element : " + filter);
            }
        } else {
            throw new IllegalArgumentException("invalide bbox element : " + filter);
        }
        final BBOXType bbtype = new BBOXType(property, minx, miny, maxx, maxy, srs);
        return ogc_factory.createBBOX(bbtype);
    } else if (filter instanceof ResourceId) {
        // todo OGC filter can not handle ID when we are inside another filter type
        // so here we make a small tric to change an id filter in a serie of propertyequal filter
        // this is not really legal but we dont have the choice here
        // we should propose an evolution of ogc filter do consider id filter as a comparison filter
        final ValueReference n = FF.property(AttributeConvention.IDENTIFIER);
        String ident = ((ResourceId) filter).getIdentifier();
        return visit(FF.equal(n, FF.literal(ident)));
    } else if (filter instanceof SpatialOperator) {
        final BinarySpatialOperator spatialOp = (BinarySpatialOperator) filter;
        Expression exp1 = spatialOp.getOperand1();
        Expression exp2 = spatialOp.getOperand2();
        if (!(exp1 instanceof ValueReference)) {
            // flip order
            final Expression ex = exp1;
            exp1 = exp2;
            exp2 = ex;
        }
        if (!(exp1 instanceof ValueReference)) {
            throw new IllegalArgumentException("Filter can not be transformed in wml filter, " + "expression are not of the requiered type ");
        }
        final JAXBElement<PropertyNameType> pnt = (JAXBElement<PropertyNameType>) extract(exp1);
        final JAXBElement<EnvelopeType> jaxEnv;
        final JAXBElement<? extends AbstractGeometryType> jaxGeom;
        final Object geom = ((Literal) exp2).getValue();
        if (geom instanceof Geometry) {
            final Geometry jts = (Geometry) geom;
            final String srid = SRIDGenerator.toSRS(jts.getSRID(), SRIDGenerator.Version.V1);
            CoordinateReferenceSystem crs;
            try {
                crs = CRS.forCode(srid);
            } catch (Exception ex) {
                Logger.getLogger("org.geotoolkit.sld.xml").log(Level.WARNING, null, ex);
                crs = null;
            }
            final AbstractGeometryType gt = GMLUtilities.getGMLFromISO(JTSUtils.toISO(jts, crs));
            // TODO use gml method to return any JAXBElement
            if (gt instanceof PointType) {
                jaxGeom = gml_factory.createPoint((PointType) gt);
            } else if (gt instanceof CurveType) {
                jaxGeom = gml_factory.createCurve((CurveType) gt);
            } else if (gt instanceof LineStringType) {
                jaxGeom = gml_factory.createLineString((LineStringType) gt);
            } else if (gt instanceof PolygonType) {
                jaxGeom = gml_factory.createPolygon((PolygonType) gt);
            } else if (gt instanceof MultiPolygonType) {
                jaxGeom = gml_factory.createMultiPolygon((MultiPolygonType) gt);
            } else if (gt instanceof MultiLineStringType) {
                jaxGeom = gml_factory.createMultiLineString((MultiLineStringType) gt);
            } else if (gt instanceof MultiCurveType) {
                jaxGeom = gml_factory.createMultiLineString((MultiLineStringType) gt);
            } else if (gt instanceof MultiPointType) {
                jaxGeom = gml_factory.createMultiLineString((MultiLineStringType) gt);
            } else if (gt instanceof MultiGeometryType) {
                jaxGeom = gml_factory.createMultiGeometry((MultiGeometryType) gt);
            } else if (gt instanceof PolyhedralSurfaceType) {
                jaxGeom = gml_factory.createPolyhedralSurface((PolyhedralSurfaceType) gt);
            } else if (gt != null) {
                throw new IllegalArgumentException("unexpected Geometry type:" + gt.getClass().getName());
            } else {
                jaxGeom = null;
            }
            jaxEnv = null;
        } else if (geom instanceof org.opengis.geometry.Geometry) {
            final AbstractGeometryType gt = GMLUtilities.getGMLFromISO((org.opengis.geometry.Geometry) geom);
            // TODO use gml method to return any JAXBElement
            if (gt instanceof PointType) {
                jaxGeom = gml_factory.createPoint((PointType) gt);
            } else if (gt instanceof CurveType) {
                jaxGeom = gml_factory.createCurve((CurveType) gt);
            } else if (gt instanceof LineStringType) {
                jaxGeom = gml_factory.createLineString((LineStringType) gt);
            } else if (gt instanceof PolygonType) {
                jaxGeom = gml_factory.createPolygon((PolygonType) gt);
            } else if (gt instanceof MultiPolygonType) {
                jaxGeom = gml_factory.createMultiPolygon((MultiPolygonType) gt);
            } else if (gt instanceof MultiLineStringType) {
                jaxGeom = gml_factory.createMultiLineString((MultiLineStringType) gt);
            } else if (gt instanceof MultiCurveType) {
                jaxGeom = gml_factory.createMultiLineString((MultiLineStringType) gt);
            } else if (gt instanceof MultiPointType) {
                jaxGeom = gml_factory.createMultiLineString((MultiLineStringType) gt);
            } else if (gt instanceof MultiGeometryType) {
                jaxGeom = gml_factory.createMultiGeometry((MultiGeometryType) gt);
            } else if (gt instanceof PolyhedralSurfaceType) {
                jaxGeom = gml_factory.createPolyhedralSurface((PolyhedralSurfaceType) gt);
            } else if (gt != null) {
                throw new IllegalArgumentException("unexpected Geometry type:" + gt.getClass().getName());
            } else {
                jaxGeom = null;
            }
            jaxEnv = null;
        } else if (geom instanceof org.opengis.geometry.Envelope) {
            final org.opengis.geometry.Envelope genv = (org.opengis.geometry.Envelope) geom;
            EnvelopeType ee = gml_factory.createEnvelopeType();
            try {
                ee.setSrsName(IdentifiedObjects.lookupURN(genv.getCoordinateReferenceSystem(), null));
            } catch (FactoryException ex) {
                Logger.getLogger("org.geotoolkit.sld.xml").log(Level.WARNING, null, ex);
            }
            ee.setLowerCorner(new DirectPositionType(genv.getLowerCorner()));
            ee.setUpperCorner(new DirectPositionType(genv.getUpperCorner()));
            jaxGeom = null;
            jaxEnv = gml_factory.createEnvelope(ee);
        } else {
            throw new IllegalArgumentException("Type is not geometric or envelope.");
        }
        if (type == DistanceOperatorName.BEYOND) {
            final BeyondType jaxelement = ogc_factory.createBeyondType();
            jaxelement.setAbstractGeometry(jaxGeom);
            jaxelement.setPropertyName(pnt.getValue());
            return ogc_factory.createBeyond(jaxelement);
        } else if (type == SpatialOperatorName.CONTAINS) {
            final ContainsType jaxelement = ogc_factory.createContainsType();
            jaxelement.setAbstractGeometry(jaxGeom);
            jaxelement.setEnvelope(jaxEnv);
            jaxelement.setPropertyName(pnt);
            return ogc_factory.createContains(jaxelement);
        } else if (type == SpatialOperatorName.CROSSES) {
            final CrossesType jaxelement = ogc_factory.createCrossesType();
            jaxelement.setAbstractGeometry(jaxGeom);
            jaxelement.setEnvelope(jaxEnv);
            jaxelement.setPropertyName(pnt);
            return ogc_factory.createCrosses(jaxelement);
        } else if (type == DistanceOperatorName.WITHIN) {
            final DWithinType jaxelement = ogc_factory.createDWithinType();
            jaxelement.setAbstractGeometry(jaxGeom);
            jaxelement.setPropertyName(pnt.getValue());
            return ogc_factory.createDWithin(jaxelement);
        } else if (type == SpatialOperatorName.DISJOINT) {
            final DisjointType jaxelement = ogc_factory.createDisjointType();
            jaxelement.setAbstractGeometry(jaxGeom);
            jaxelement.setEnvelope(jaxEnv);
            jaxelement.setPropertyName(pnt);
            return ogc_factory.createDisjoint(jaxelement);
        } else if (type == SpatialOperatorName.EQUALS) {
            final EqualsType jaxelement = ogc_factory.createEqualsType();
            jaxelement.setAbstractGeometry(jaxGeom);
            jaxelement.setEnvelope(jaxEnv);
            jaxelement.setPropertyName(pnt);
            return ogc_factory.createEquals(jaxelement);
        } else if (type == SpatialOperatorName.INTERSECTS) {
            final IntersectsType jaxelement = ogc_factory.createIntersectsType();
            jaxelement.setAbstractGeometry(jaxGeom);
            jaxelement.setEnvelope(jaxEnv);
            jaxelement.setPropertyName(pnt);
            return ogc_factory.createIntersects(jaxelement);
        } else if (type == SpatialOperatorName.OVERLAPS) {
            final OverlapsType jaxelement = new OverlapsType();
            jaxelement.setAbstractGeometry(jaxGeom);
            jaxelement.setEnvelope(jaxEnv);
            jaxelement.setPropertyName(pnt);
            return ogc_factory.createOverlaps(jaxelement);
        } else if (type == SpatialOperatorName.TOUCHES) {
            final TouchesType jaxelement = ogc_factory.createTouchesType();
            jaxelement.setAbstractGeometry(jaxGeom);
            jaxelement.setEnvelope(jaxEnv);
            jaxelement.setPropertyName(pnt);
            return ogc_factory.createTouches(jaxelement);
        } else if (type == SpatialOperatorName.WITHIN) {
            final WithinType jaxelement = ogc_factory.createWithinType();
            jaxelement.setAbstractGeometry(jaxGeom);
            jaxelement.setEnvelope(jaxEnv);
            jaxelement.setPropertyName(pnt);
            return ogc_factory.createWithin(jaxelement);
        } else {
            throw new IllegalArgumentException("Unknowed filter element : " + filter + " class :" + filter.getClass());
        }
    } else {
        throw new IllegalArgumentException("Unknowed filter element : " + filter + " class :" + filter.getClass());
    }
}
Also used : OverlapsType(org.geotoolkit.ogc.xml.v110.OverlapsType) FactoryException(org.opengis.util.FactoryException) MultiCurveType(org.geotoolkit.gml.xml.v311.MultiCurveType) BeyondType(org.geotoolkit.ogc.xml.v110.BeyondType) ArrayList(java.util.ArrayList) MultiGeometryType(org.geotoolkit.gml.xml.v311.MultiGeometryType) CrossesType(org.geotoolkit.ogc.xml.v110.CrossesType) DWithinType(org.geotoolkit.ogc.xml.v110.DWithinType) NotType(org.geotoolkit.ogc.xml.v110.NotType) Literal(org.opengis.filter.Literal) DisjointType(org.geotoolkit.ogc.xml.v110.DisjointType) MultiLineStringType(org.geotoolkit.gml.xml.v311.MultiLineStringType) CodeList(org.opengis.util.CodeList) List(java.util.List) ArrayList(java.util.ArrayList) PropertyIsBetweenType(org.geotoolkit.ogc.xml.v110.PropertyIsBetweenType) CoordinateReferenceSystem(org.opengis.referencing.crs.CoordinateReferenceSystem) BetweenComparisonOperator(org.opengis.filter.BetweenComparisonOperator) ValueReference(org.opengis.filter.ValueReference) PropertyNameType(org.geotoolkit.ogc.xml.v110.PropertyNameType) DWithinType(org.geotoolkit.ogc.xml.v110.DWithinType) WithinType(org.geotoolkit.ogc.xml.v110.WithinType) AbstractGeometryType(org.geotoolkit.gml.xml.v311.AbstractGeometryType) PropertyIsGreaterThanType(org.geotoolkit.ogc.xml.v110.PropertyIsGreaterThanType) LogicalOperator(org.opengis.filter.LogicalOperator) PolygonType(org.geotoolkit.gml.xml.v311.PolygonType) MultiPolygonType(org.geotoolkit.gml.xml.v311.MultiPolygonType) JAXBElement(javax.xml.bind.JAXBElement) IntersectsType(org.geotoolkit.ogc.xml.v110.IntersectsType) LineStringType(org.geotoolkit.gml.xml.v311.LineStringType) MultiLineStringType(org.geotoolkit.gml.xml.v311.MultiLineStringType) PropertyIsGreaterThanOrEqualToType(org.geotoolkit.ogc.xml.v110.PropertyIsGreaterThanOrEqualToType) MultiPointType(org.geotoolkit.gml.xml.v311.MultiPointType) LogicOpsType(org.geotoolkit.ogc.xml.v110.LogicOpsType) UpperBoundaryType(org.geotoolkit.ogc.xml.v110.UpperBoundaryType) PropertyIsNotEqualToType(org.geotoolkit.ogc.xml.v110.PropertyIsNotEqualToType) ContainsType(org.geotoolkit.ogc.xml.v110.ContainsType) BBOXType(org.geotoolkit.ogc.xml.v110.BBOXType) LikeOperator(org.opengis.filter.LikeOperator) BinaryComparisonOperator(org.opengis.filter.BinaryComparisonOperator) PolyhedralSurfaceType(org.geotoolkit.gml.xml.v311.PolyhedralSurfaceType) PropertyIsLikeType(org.geotoolkit.ogc.xml.v110.PropertyIsLikeType) PropertyIsLessThanType(org.geotoolkit.ogc.xml.v110.PropertyIsLessThanType) AndType(org.geotoolkit.ogc.xml.v110.AndType) DirectPositionType(org.geotoolkit.gml.xml.v311.DirectPositionType) CurveType(org.geotoolkit.gml.xml.v311.CurveType) MultiCurveType(org.geotoolkit.gml.xml.v311.MultiCurveType) PropertyIsLessThanOrEqualToType(org.geotoolkit.ogc.xml.v110.PropertyIsLessThanOrEqualToType) Envelope(org.locationtech.jts.geom.Envelope) PropertyIsNullType(org.geotoolkit.ogc.xml.v110.PropertyIsNullType) EqualsType(org.geotoolkit.ogc.xml.v110.EqualsType) BinarySpatialOperator(org.opengis.filter.BinarySpatialOperator) OrType(org.geotoolkit.ogc.xml.v110.OrType) EnvelopeType(org.geotoolkit.gml.xml.v311.EnvelopeType) MultiPolygonType(org.geotoolkit.gml.xml.v311.MultiPolygonType) LiteralType(org.geotoolkit.ogc.xml.v110.LiteralType) NullOperator(org.opengis.filter.NullOperator) FactoryException(org.opengis.util.FactoryException) Geometry(org.locationtech.jts.geom.Geometry) PropertyIsEqualToType(org.geotoolkit.ogc.xml.v110.PropertyIsEqualToType) Expression(org.opengis.filter.Expression) Filter(org.opengis.filter.Filter) ResourceId(org.opengis.filter.ResourceId) PointType(org.geotoolkit.gml.xml.v311.PointType) MultiPointType(org.geotoolkit.gml.xml.v311.MultiPointType) LowerBoundaryType(org.geotoolkit.ogc.xml.v110.LowerBoundaryType) BinarySpatialOperator(org.opengis.filter.BinarySpatialOperator) TouchesType(org.geotoolkit.ogc.xml.v110.TouchesType)

Example 12 with PropertyIsLikeType

use of org.geotoolkit.ogc.xml.v100.PropertyIsLikeType in project geotoolkit by Geomatys.

the class CswXMLBindingTest method getRecordsMarshalingTest.

/**
 * Test simple Record Marshalling.
 */
@Test
public void getRecordsMarshalingTest() throws JAXBException, IOException, ParserConfigurationException, SAXException {
    Marshaller marshaller = pool.acquireMarshaller();
    /*
         * Test marshalling csw getRecordByIdResponse v2.0.2
         */
    /*
         * we build the first filter : < dublinCore:Title IS LIKE '*' >
         */
    List<QName> typeNames = new ArrayList<>();
    PropertyNameType pname = new PropertyNameType("dc:Title");
    PropertyIsLikeType pil = new PropertyIsLikeType(pname, "something?", "*", "?", "\\");
    NotType n = new NotType(pil);
    FilterType filter1 = new FilterType(n);
    QueryConstraintType constraint = new QueryConstraintType(filter1, "1.1.0");
    typeNames.add(_Record_QNAME);
    QueryType query = new QueryType(typeNames, new ElementSetNameType(ElementSetType.FULL), null, constraint);
    GetRecordsType getRecordsRequest = new GetRecordsType("CSW", "2.0.2", ResultType.RESULTS, null, "application/xml", "http://www.opengis.net/cat/csw/2.0.2", 1, 20, query, null);
    StringWriter sw = new StringWriter();
    marshaller.marshal(getRecordsRequest, sw);
    String result = sw.toString();
    String expResult = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n" + "<csw2:GetRecords xmlns:ogc=\"http://www.opengis.net/ogc\" xmlns:csw2=\"http://www.opengis.net/cat/csw/2.0.2\"" + " maxRecords=\"20\" startPosition=\"1\" outputSchema=\"http://www.opengis.net/cat/csw/2.0.2\" outputFormat=\"application/xml\"" + " resultType=\"results\" version=\"2.0.2\" service=\"CSW\">\n" + "  <csw2:Query typeNames=\"csw2:Record\">\n" + "    <csw2:ElementSetName>full</csw2:ElementSetName>\n" + "    <csw2:Constraint version=\"1.1.0\">\n" + "      <ogc:Filter>\n" + "        <ogc:Not>\n" + "          <ogc:PropertyIsLike wildCard=\"*\" singleChar=\"?\" escapeChar=\"\\\">\n" + "            <ogc:PropertyName>dc:Title</ogc:PropertyName>\n" + "            <ogc:Literal>something?</ogc:Literal>\n" + "          </ogc:PropertyIsLike>\n" + "        </ogc:Not>\n" + "      </ogc:Filter>\n" + "    </csw2:Constraint>\n" + "  </csw2:Query>\n" + "</csw2:GetRecords>\n";
    assertXmlEquals(expResult, result, "xmlns:*");
    /*
         * Test marshalling csw getRecordByIdResponse v2.0.0
         */
    org.geotoolkit.csw.xml.v200.QueryConstraintType constraint200 = new org.geotoolkit.csw.xml.v200.QueryConstraintType(filter1, "1.1.0");
    typeNames = new ArrayList<>();
    typeNames.add(org.geotoolkit.csw.xml.v200.ObjectFactory._Record_QNAME);
    org.geotoolkit.csw.xml.v200.QueryType query200 = new org.geotoolkit.csw.xml.v200.QueryType(typeNames, new org.geotoolkit.csw.xml.v200.ElementSetNameType(ElementSetType.FULL), constraint200);
    org.geotoolkit.csw.xml.v200.GetRecordsType getRecordsRequest200 = new org.geotoolkit.csw.xml.v200.GetRecordsType("CSW", "2.0.0", ResultType.RESULTS, null, "application/xml", "http://www.opengis.net/cat/csw", 1, 20, query200, null);
    sw = new StringWriter();
    marshaller.marshal(getRecordsRequest200, sw);
    result = sw.toString();
    expResult = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n" + "<cat:GetRecords xmlns:ogc=\"http://www.opengis.net/ogc\" xmlns:cat=\"http://www.opengis.net/cat/csw\"" + " maxRecords=\"20\" startPosition=\"1\" outputSchema=\"http://www.opengis.net/cat/csw\" outputFormat=\"application/xml\"" + " resultType=\"results\" version=\"2.0.0\" service=\"CSW\">\n" + "  <cat:Query typeNames=\"cat:Record\">\n" + "    <cat:ElementSetName>full</cat:ElementSetName>\n" + "    <cat:Constraint version=\"1.1.0\">\n" + "      <ogc:Filter>\n" + "        <ogc:Not>\n" + "          <ogc:PropertyIsLike wildCard=\"*\" singleChar=\"?\" escapeChar=\"\\\">\n" + "            <ogc:PropertyName>dc:Title</ogc:PropertyName>\n" + "            <ogc:Literal>something?</ogc:Literal>\n" + "          </ogc:PropertyIsLike>\n" + "        </ogc:Not>\n" + "      </ogc:Filter>\n" + "    </cat:Constraint>\n" + "  </cat:Query>\n" + "</cat:GetRecords>\n";
    assertXmlEquals(expResult, result, "xmlns:*");
    pool.recycle(marshaller);
}
Also used : Marshaller(javax.xml.bind.Marshaller) QName(javax.xml.namespace.QName) ArrayList(java.util.ArrayList) GetRecordsType(org.geotoolkit.csw.xml.v202.GetRecordsType) QueryConstraintType(org.geotoolkit.csw.xml.v202.QueryConstraintType) FilterType(org.geotoolkit.ogc.xml.v110.FilterType) StringWriter(java.io.StringWriter) NotType(org.geotoolkit.ogc.xml.v110.NotType) ElementSetNameType(org.geotoolkit.csw.xml.v202.ElementSetNameType) QueryType(org.geotoolkit.csw.xml.v202.QueryType) PropertyIsLikeType(org.geotoolkit.ogc.xml.v110.PropertyIsLikeType) PropertyNameType(org.geotoolkit.ogc.xml.v110.PropertyNameType) Test(org.junit.Test)

Example 13 with PropertyIsLikeType

use of org.geotoolkit.ogc.xml.v100.PropertyIsLikeType in project ddf by codice.

the class WfsFilterDelegate method createPropertyIsFilter.

private JAXBElement<? extends ComparisonOpsType> createPropertyIsFilter(String property, Object literal, PROPERTY_IS_OPS operation) {
    switch(operation) {
        case PROPERTY_IS_EQUAL_TO:
            JAXBElement<BinaryComparisonOpType> propIsEqualTo = filterObjectFactory.createPropertyIsEqualTo(new BinaryComparisonOpType());
            propIsEqualTo.getValue().getExpression().add(createPropertyNameType(property));
            propIsEqualTo.getValue().getExpression().add(createLiteralType(literal));
            return propIsEqualTo;
        case PROPERTY_IS_NOT_EQUAL_TO:
            JAXBElement<BinaryComparisonOpType> propIsNotEqualTo = filterObjectFactory.createPropertyIsNotEqualTo(new BinaryComparisonOpType());
            propIsNotEqualTo.getValue().getExpression().add(createPropertyNameType(property));
            propIsNotEqualTo.getValue().getExpression().add(createLiteralType(literal));
            return propIsNotEqualTo;
        case PROPERTY_IS_GREATER_THAN:
            JAXBElement<BinaryComparisonOpType> propIsGreaterThan = filterObjectFactory.createPropertyIsGreaterThan(new BinaryComparisonOpType());
            propIsGreaterThan.getValue().getExpression().add(createPropertyNameType(property));
            propIsGreaterThan.getValue().getExpression().add(createLiteralType(literal));
            return propIsGreaterThan;
        case PROPERTY_IS_GREATER_THAN_OR_EQUAL_TO:
            JAXBElement<BinaryComparisonOpType> propIsGreaterThanOrEqualTo = filterObjectFactory.createPropertyIsGreaterThanOrEqualTo(new BinaryComparisonOpType());
            propIsGreaterThanOrEqualTo.getValue().getExpression().add(createPropertyNameType(property));
            propIsGreaterThanOrEqualTo.getValue().getExpression().add(createLiteralType(literal));
            return propIsGreaterThanOrEqualTo;
        case PROPERTY_IS_LESS_THAN:
            JAXBElement<BinaryComparisonOpType> propIsLessThan = filterObjectFactory.createPropertyIsLessThan(new BinaryComparisonOpType());
            propIsLessThan.getValue().getExpression().add(createPropertyNameType(property));
            propIsLessThan.getValue().getExpression().add(createLiteralType(literal));
            return propIsLessThan;
        case PROPERTY_IS_LESS_THAN_OR_EQUAL_TO:
            JAXBElement<BinaryComparisonOpType> propIsLessThanOrEqualTo = filterObjectFactory.createPropertyIsLessThanOrEqualTo(new BinaryComparisonOpType());
            propIsLessThanOrEqualTo.getValue().getExpression().add(createPropertyNameType(property));
            propIsLessThanOrEqualTo.getValue().getExpression().add(createLiteralType(literal));
            return propIsLessThanOrEqualTo;
        case PROPERTY_IS_LIKE:
            JAXBElement<PropertyIsLikeType> propIsLike = filterObjectFactory.createPropertyIsLike(new PropertyIsLikeType());
            propIsLike.getValue().setEscapeChar(Wfs20Constants.ESCAPE);
            propIsLike.getValue().setSingleChar(SINGLE_CHAR);
            propIsLike.getValue().setWildCard(Wfs20Constants.WILD_CARD);
            propIsLike.getValue().getExpression().add(createLiteralType(literal));
            propIsLike.getValue().getExpression().add(createPropertyNameType(property));
            return propIsLike;
        default:
            throw new UnsupportedOperationException("Unsupported Property Comparison Type");
    }
}
Also used : BinaryComparisonOpType(net.opengis.filter.v_2_0_0.BinaryComparisonOpType) PropertyIsLikeType(net.opengis.filter.v_2_0_0.PropertyIsLikeType)

Example 14 with PropertyIsLikeType

use of org.geotoolkit.ogc.xml.v100.PropertyIsLikeType in project ddf by codice.

the class WfsSourceTest method testQueryTwoFeaturesOneInvalid.

@Test
public void testQueryTwoFeaturesOneInvalid() throws Exception {
    mapSchemaToSingleFeature(TWO_TEXT_PROPERTY_SCHEMA, 0);
    mapSchemaToSingleFeature(ONE_TEXT_PROPERTY_SCHEMA_PERSON, 1);
    setUpMocks(null, null, TWO_FEATURES, TWO_FEATURES);
    Filter orderDogFilter = builder.attribute(ORDER_DOG).is().like().text(LITERAL);
    Filter mctFeature1Filter = builder.attribute(Metacard.CONTENT_TYPE).is().like().text(sampleFeatures.get(0).getLocalPart());
    Filter feature1Filter = builder.allOf(Arrays.asList(orderDogFilter, mctFeature1Filter));
    Filter fakeFilter = builder.attribute("FAKE").is().like().text(LITERAL);
    Filter mctFeature2Filter = builder.attribute(Metacard.CONTENT_TYPE).is().like().text(sampleFeatures.get(1).getLocalPart());
    Filter feature2Filter = builder.allOf(Arrays.asList(fakeFilter, mctFeature2Filter));
    Filter totalFilter = builder.anyOf(Arrays.asList(feature1Filter, feature2Filter));
    QueryImpl inQuery = new QueryImpl(totalFilter);
    inQuery.setPageSize(MAX_FEATURES);
    ArgumentCaptor<ExtendedGetFeatureType> captor = ArgumentCaptor.forClass(ExtendedGetFeatureType.class);
    source.query(new QueryRequestImpl(inQuery));
    verify(mockWfs, times(2)).getFeature(captor.capture());
    ExtendedGetFeatureType getFeatureType = captor.getAllValues().get(1);
    assertMaxFeatures(getFeatureType, inQuery);
    List<QueryType> filterQueries = getFeatureType.getQuery().stream().filter(QueryType::isSetFilter).collect(Collectors.toList());
    assertThat(filterQueries, hasSize(ONE_FEATURE));
    QueryType query = filterQueries.get(0);
    assertThat(query.getTypeName().get(0), is(sampleFeatures.get(0)));
    // The Text Properties should be ORed
    assertThat(query.getFilter().isSetComparisonOps(), is(true));
    assertThat(query.getFilter().getComparisonOps().getValue(), is(instanceOf(PropertyIsLikeType.class)));
    PropertyIsLikeType pilt = (PropertyIsLikeType) query.getFilter().getComparisonOps().getValue();
    assertThat(ORDER_DOG, is(pilt.getPropertyName().getContent().get(0)));
}
Also used : QueryImpl(ddf.catalog.operation.impl.QueryImpl) Filter(org.opengis.filter.Filter) QueryRequestImpl(ddf.catalog.operation.impl.QueryRequestImpl) QueryType(net.opengis.wfs.v_1_1_0.QueryType) PropertyIsLikeType(net.opengis.filter.v_1_1_0.PropertyIsLikeType) Test(org.junit.Test)

Example 15 with PropertyIsLikeType

use of org.geotoolkit.ogc.xml.v100.PropertyIsLikeType in project ddf by codice.

the class WfsSourceTest method testQueryTwoFeaturesWithMixedPropertyNames.

@Test
public void testQueryTwoFeaturesWithMixedPropertyNames() throws Exception {
    mapSchemaToSingleFeature(ONE_TEXT_PROPERTY_SCHEMA_PERSON, 0);
    mapSchemaToSingleFeature(ONE_TEXT_PROPERTY_SCHEMA_DOG, 1);
    setUpMocks(null, null, TWO_FEATURES, TWO_FEATURES);
    Filter orderPersonFilter = builder.attribute(ORDER_PERSON).is().like().text(LITERAL);
    Filter mctFeature1Filter = builder.attribute(Metacard.CONTENT_TYPE).is().like().text(sampleFeatures.get(0).getLocalPart());
    Filter feature1Filter = builder.allOf(Arrays.asList(orderPersonFilter, mctFeature1Filter));
    Filter orderDogFilter = builder.attribute(ORDER_DOG).is().like().text(LITERAL);
    Filter mctFeature2Filter = builder.attribute(Metacard.CONTENT_TYPE).is().like().text(sampleFeatures.get(1).getLocalPart());
    Filter feature2Filter = builder.allOf(Arrays.asList(orderDogFilter, mctFeature2Filter));
    Filter totalFilter = builder.anyOf(Arrays.asList(feature1Filter, feature2Filter));
    QueryImpl inQuery = new QueryImpl(totalFilter);
    inQuery.setPageSize(MAX_FEATURES);
    ArgumentCaptor<ExtendedGetFeatureType> captor = ArgumentCaptor.forClass(ExtendedGetFeatureType.class);
    source.query(new QueryRequestImpl(inQuery));
    verify(mockWfs, times(2)).getFeature(captor.capture());
    ExtendedGetFeatureType getFeatureType = captor.getAllValues().get(1);
    assertMaxFeatures(getFeatureType, inQuery);
    getFeatureType.getQuery().sort(QUERY_TYPE_COMPARATOR);
    assertThat(TWO_FEATURES, is(getFeatureType.getQuery().size()));
    // Feature 1
    QueryType query = getFeatureType.getQuery().get(0);
    assertThat(query.getTypeName().get(0), equalTo(sampleFeatures.get(0)));
    // this should only have 1 filter which is a comparison
    assertThat(query.getFilter().isSetComparisonOps(), is(true));
    assertThat(query.getFilter().getComparisonOps().getValue(), is(instanceOf(PropertyIsLikeType.class)));
    PropertyIsLikeType pilt = (PropertyIsLikeType) query.getFilter().getComparisonOps().getValue();
    assertThat(pilt, notNullValue());
    assertThat(ORDER_PERSON, is(pilt.getPropertyName().getContent().get(0)));
    // Feature 2
    QueryType query2 = getFeatureType.getQuery().get(1);
    assertThat(query2.getTypeName().get(0), is(sampleFeatures.get(1)));
    // this should only have 1 filter which is a comparison
    assertThat(query2.getFilter().isSetComparisonOps(), is(true));
    assertThat(query2.getFilter().getComparisonOps().getValue(), is(instanceOf(PropertyIsLikeType.class)));
    PropertyIsLikeType pilt2 = (PropertyIsLikeType) query2.getFilter().getComparisonOps().getValue();
    assertThat(ORDER_DOG, is(pilt2.getPropertyName().getContent().get(0)));
}
Also used : QueryImpl(ddf.catalog.operation.impl.QueryImpl) Filter(org.opengis.filter.Filter) QueryRequestImpl(ddf.catalog.operation.impl.QueryRequestImpl) QueryType(net.opengis.wfs.v_1_1_0.QueryType) PropertyIsLikeType(net.opengis.filter.v_1_1_0.PropertyIsLikeType) Test(org.junit.Test)

Aggregations

ArrayList (java.util.ArrayList)15 Test (org.junit.Test)15 PropertyIsLikeType (net.opengis.filter.v_2_0_0.PropertyIsLikeType)11 FilterType (net.opengis.filter.v_2_0_0.FilterType)10 Filter (org.opengis.filter.Filter)10 QueryImpl (ddf.catalog.operation.impl.QueryImpl)7 QueryRequestImpl (ddf.catalog.operation.impl.QueryRequestImpl)7 Method (java.lang.reflect.Method)6 JAXBElement (javax.xml.bind.JAXBElement)6 BinaryLogicOpType (net.opengis.filter.v_2_0_0.BinaryLogicOpType)6 PropertyIsLikeType (ogc.schema.opengis.filter.v_1_0_0.PropertyIsLikeType)6 QName (javax.xml.namespace.QName)5 GetFeatureType (ogc.schema.opengis.wfs.v_1_0_0.GetFeatureType)5 QueryType (ogc.schema.opengis.wfs.v_1_0_0.QueryType)5 PropertyIsLikeType (org.geotoolkit.ogc.xml.v110.PropertyIsLikeType)5 StringWriter (java.io.StringWriter)4 PropertyIsLikeType (net.opengis.filter.v_1_1_0.PropertyIsLikeType)4 PropertyNameType (org.geotoolkit.ogc.xml.v110.PropertyNameType)4 LikeOperator (org.opengis.filter.LikeOperator)4 ValueReference (org.opengis.filter.ValueReference)4