Search in sources :

Example 16 with ComparisonOpsType

use of org.geotoolkit.ogc.xml.v110.ComparisonOpsType in project geotoolkit by Geomatys.

the class FilterToOGC100Converter method visit.

@Override
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 PropertyIsBetweenType bot = ogc_factory.createPropertyIsBetweenType();
        final LowerBoundaryType lbt = ogc_factory.createLowerBoundaryType();
        lbt.setExpression(extract(pib.getLowerBoundary()));
        final UpperBoundaryType ubt = ogc_factory.createUpperBoundaryType();
        ubt.setExpression(extract(pib.getUpperBoundary()));
        bot.setExpression(extract(pib.getExpression()));
        bot.setLowerBoundary(lbt);
        bot.setUpperBoundary(ubt);
        return ogc_factory.createPropertyIsBetween(bot);
    } else if (type == ComparisonOperatorName.PROPERTY_IS_EQUAL_TO) {
        final BinaryComparisonOperator pit = (BinaryComparisonOperator) filter;
        final PropertyIsEqualToType bot = new PropertyIsEqualToType();
        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 = new PropertyIsGreaterThanType();
        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 = new PropertyIsGreaterThanOrEqualToType();
        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 = new PropertyIsLessThanType();
        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 = new PropertyIsLessThanOrEqualToType();
        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.setEscape(String.valueOf(pis.getEscapeChar()));
        final LiteralType lt = ogc_factory.createLiteralType();
        lt.getContent().add(((Literal) expressions.get(1)).getValue());
        bot.setLiteral(lt);
        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 = new PropertyIsNotEqualToType();
        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();
        if (obj instanceof LiteralType) {
            bot.setLiteral((LiteralType) obj);
        } else if (obj instanceof PropertyNameType) {
            bot.setPropertyName((PropertyNameType) obj);
        } else {
            // should not be possible
            throw new IllegalArgumentException("Invalid expression element : " + obj);
        }
        return ogc_factory.createPropertyIsNull(bot);
    } else if (type == LogicalOperatorName.AND) {
        final LogicalOperator and = (LogicalOperator) filter;
        final AndType lot = new AndType();
        for (final Filter f : (List<Filter>) and.getOperands()) {
            lot.getComparisonOpsOrSpatialOpsOrLogicOps().add(visit(f));
        }
        return ogc_factory.createAnd(lot);
    } else if (type == LogicalOperatorName.OR) {
        final LogicalOperator or = (LogicalOperator) filter;
        final OrType lot = new OrType();
        for (final Filter f : (List<Filter>) or.getOperands()) {
            lot.getComparisonOpsOrSpatialOpsOrLogicOps().add(visit(f));
        }
        return ogc_factory.createOr(lot);
    } else if (type == LogicalOperatorName.NOT) {
        final LogicalOperator not = (LogicalOperator) filter;
        final NotType lot = new NotType();
        JAXBElement<?> sf = visit((Filter) not.getOperands().get(0));
        if (sf.getValue() instanceof ComparisonOpsType) {
            lot.setComparisonOps((JAXBElement<? extends ComparisonOpsType>) sf);
        } else if (sf.getValue() instanceof LogicOpsType) {
            lot.setLogicOps((JAXBElement<? extends LogicOpsType>) sf);
        } else if (sf.getValue() instanceof SpatialOpsType) {
            lot.setSpatialOps((JAXBElement<? extends SpatialOpsType>) sf);
        } else {
            // should not happen
            throw new IllegalArgumentException("invalid filter element : " + sf);
        }
        return ogc_factory.createNot(lot);
    } else if (type == SpatialOperatorName.BBOX) {
        final BBOX bbox = BBOX.wrap((BinarySpatialOperator) filter);
        final BBOXType bboxType = ogc_factory.createBBOXType();
        final Expression sourceExp1 = bbox.getOperand1();
        final JAXBElement<?> exp1 = extract(sourceExp1);
        final Expression sourceExp2 = bbox.getOperand2();
        JAXBElement<?> exp2 = extract(sourceExp2);
        final PropertyNameType pName;
        final BoxType boxType;
        if (exp1 != null && exp1.getValue() instanceof PropertyNameType) {
            pName = (PropertyNameType) exp1.getValue();
        } else if (exp2 != null && exp2.getValue() instanceof PropertyNameType) {
            pName = (PropertyNameType) exp2.getValue();
        } else
            throw new IllegalArgumentException("No property name found in given bbox filter");
        if (sourceExp1 instanceof Literal) {
            boxType = toBox((Literal) sourceExp1);
        } else if (sourceExp2 instanceof Literal) {
            boxType = toBox((Literal) sourceExp2);
        } else
            throw new IllegalArgumentException("No bbox found in given bbox filter");
        bboxType.setPropertyName(pName);
        bboxType.setBox(boxType);
        return ogc_factory.createBBOX(bboxType);
    }
    throw new IllegalArgumentException("Unknowed filter element : " + filter + " class :" + filter.getClass());
}
Also used : PropertyIsLessThanType(org.geotoolkit.ogc.xml.v100.PropertyIsLessThanType) AndType(org.geotoolkit.ogc.xml.v100.AndType) PropertyIsLessThanOrEqualToType(org.geotoolkit.ogc.xml.v100.PropertyIsLessThanOrEqualToType) BoxType(org.geotoolkit.gml.xml.v212.BoxType) PropertyIsNullType(org.geotoolkit.ogc.xml.v100.PropertyIsNullType) NotType(org.geotoolkit.ogc.xml.v100.NotType) SpatialOpsType(org.geotoolkit.ogc.xml.v100.SpatialOpsType) Literal(org.opengis.filter.Literal) CodeList(org.opengis.util.CodeList) List(java.util.List) PropertyIsBetweenType(org.geotoolkit.ogc.xml.v100.PropertyIsBetweenType) BetweenComparisonOperator(org.opengis.filter.BetweenComparisonOperator) ValueReference(org.opengis.filter.ValueReference) PropertyNameType(org.geotoolkit.ogc.xml.v100.PropertyNameType) OrType(org.geotoolkit.ogc.xml.v100.OrType) PropertyIsGreaterThanType(org.geotoolkit.ogc.xml.v100.PropertyIsGreaterThanType) LogicalOperator(org.opengis.filter.LogicalOperator) ComparisonOpsType(org.geotoolkit.ogc.xml.v100.ComparisonOpsType) LiteralType(org.geotoolkit.ogc.xml.v100.LiteralType) JAXBElement(javax.xml.bind.JAXBElement) PropertyIsGreaterThanOrEqualToType(org.geotoolkit.ogc.xml.v100.PropertyIsGreaterThanOrEqualToType) NullOperator(org.opengis.filter.NullOperator) LogicOpsType(org.geotoolkit.ogc.xml.v100.LogicOpsType) UpperBoundaryType(org.geotoolkit.ogc.xml.v100.UpperBoundaryType) PropertyIsNotEqualToType(org.geotoolkit.ogc.xml.v100.PropertyIsNotEqualToType) PropertyIsEqualToType(org.geotoolkit.ogc.xml.v100.PropertyIsEqualToType) BBOXType(org.geotoolkit.ogc.xml.v100.BBOXType) Expression(org.opengis.filter.Expression) Filter(org.opengis.filter.Filter) LowerBoundaryType(org.geotoolkit.ogc.xml.v100.LowerBoundaryType) LikeOperator(org.opengis.filter.LikeOperator) BinaryComparisonOperator(org.opengis.filter.BinaryComparisonOperator) PropertyIsLikeType(org.geotoolkit.ogc.xml.v100.PropertyIsLikeType)

Example 17 with ComparisonOpsType

use of org.geotoolkit.ogc.xml.v110.ComparisonOpsType in project geotoolkit by Geomatys.

the class OGC100Test method testFilterComparisonPropertyIsLike.

@Test
public void testFilterComparisonPropertyIsLike() throws JAXBException {
    final Unmarshaller UNMARSHALLER = POOL.acquireUnmarshaller();
    final Marshaller MARSHALLER = POOL.acquireMarshaller();
    // Read test
    Object obj = UNMARSHALLER.unmarshal(FILE_FIL_COMP_ISLIKE);
    assertNotNull(obj);
    JAXBElement<? extends FilterType> jaxfilter = (JAXBElement<? extends FilterType>) obj;
    assertNotNull(jaxfilter);
    Filter filter = TRANSFORMER_GT.visitFilter(jaxfilter.getValue());
    assertNotNull(filter);
    LikeOperator prop = (LikeOperator) filter;
    ValueReference exp = (ValueReference) prop.getExpressions().get(0);
    char escape = prop.getEscapeChar();
    String literal = (String) ((Literal) prop.getExpressions().get(1)).getValue();
    char single = prop.getSingleChar();
    char wild = prop.getWildCard();
    assertEquals(exp.getXPath(), "LAST_NAME");
    assertEquals(literal, "JOHN*");
    assertEquals(escape, '!');
    assertEquals(single, '#');
    assertEquals(wild, '*');
    // write test
    FilterType ft = TRANSFORMER_OGC.apply(filter);
    assertNotNull(ft.getComparisonOps());
    ComparisonOpsType cot = ft.getComparisonOps().getValue();
    PropertyIsLikeType pibt = (PropertyIsLikeType) cot;
    PropertyNameType lf = pibt.getPropertyName();
    LiteralType lt = pibt.getLiteralType();
    char esc = pibt.getEscapeChar();
    char sin = pibt.getSingleChar();
    char wi = pibt.getWildCard();
    assertEquals(lf.getContent(), "LAST_NAME");
    assertEquals(lt.getContent().get(0).toString().trim(), "JOHN*");
    assertEquals(esc, '!');
    assertEquals(sin, '#');
    assertEquals(wi, '*');
    MARSHALLER.marshal(ft.getComparisonOps(), TEST_FILE_FIL_COMP_ISLIKE);
    POOL.recycle(MARSHALLER);
    POOL.recycle(UNMARSHALLER);
}
Also used : Marshaller(javax.xml.bind.Marshaller) ComparisonOpsType(org.geotoolkit.ogc.xml.v100.ComparisonOpsType) LiteralType(org.geotoolkit.ogc.xml.v100.LiteralType) JAXBElement(javax.xml.bind.JAXBElement) FilterType(org.geotoolkit.ogc.xml.v100.FilterType) Filter(org.opengis.filter.Filter) LikeOperator(org.opengis.filter.LikeOperator) Unmarshaller(javax.xml.bind.Unmarshaller) PropertyIsLikeType(org.geotoolkit.ogc.xml.v100.PropertyIsLikeType) ValueReference(org.opengis.filter.ValueReference) PropertyNameType(org.geotoolkit.ogc.xml.v100.PropertyNameType) Test(org.junit.Test)

Example 18 with ComparisonOpsType

use of org.geotoolkit.ogc.xml.v110.ComparisonOpsType in project geotoolkit by Geomatys.

the class OGC100Test method testFilterComparisonPropertyIsGreaterThan.

@Test
public void testFilterComparisonPropertyIsGreaterThan() throws JAXBException {
    final Unmarshaller UNMARSHALLER = POOL.acquireUnmarshaller();
    final Marshaller MARSHALLER = POOL.acquireMarshaller();
    // Read test
    Object obj = UNMARSHALLER.unmarshal(FILE_FIL_COMP_ISGREATER);
    assertNotNull(obj);
    JAXBElement<? extends FilterType> jaxfilter = (JAXBElement<? extends FilterType>) obj;
    assertNotNull(jaxfilter);
    Filter filter = TRANSFORMER_GT.visitFilter(jaxfilter.getValue());
    assertNotNull(filter);
    BinaryComparisonOperator prop = (BinaryComparisonOperator) filter;
    ValueReference left = (ValueReference) prop.getOperand1();
    Literal right = (Literal) prop.getOperand2();
    assertEquals(left.getXPath(), valueStr);
    assertEquals(((Number) right.apply(null)).floatValue(), valueF, DELTA);
    // write test
    FilterType ft = TRANSFORMER_OGC.apply(filter);
    assertNotNull(ft.getComparisonOps());
    ComparisonOpsType cot = ft.getComparisonOps().getValue();
    BinaryComparisonOpType pibt = (BinaryComparisonOpType) cot;
    PropertyNameType lf = (PropertyNameType) pibt.getExpression().get(0).getValue();
    LiteralType rg = (LiteralType) pibt.getExpression().get(1).getValue();
    assertEquals(valueStr, lf.getContent());
    numberEquals(valueF, rg.getContent().get(0).toString().trim());
    MARSHALLER.marshal(ft.getComparisonOps(), TEST_FILE_FIL_COMP_ISGREATER);
    POOL.recycle(MARSHALLER);
    POOL.recycle(UNMARSHALLER);
}
Also used : Marshaller(javax.xml.bind.Marshaller) ComparisonOpsType(org.geotoolkit.ogc.xml.v100.ComparisonOpsType) LiteralType(org.geotoolkit.ogc.xml.v100.LiteralType) JAXBElement(javax.xml.bind.JAXBElement) FilterType(org.geotoolkit.ogc.xml.v100.FilterType) Filter(org.opengis.filter.Filter) Literal(org.opengis.filter.Literal) Unmarshaller(javax.xml.bind.Unmarshaller) BinaryComparisonOperator(org.opengis.filter.BinaryComparisonOperator) BinaryComparisonOpType(org.geotoolkit.ogc.xml.v100.BinaryComparisonOpType) ValueReference(org.opengis.filter.ValueReference) PropertyNameType(org.geotoolkit.ogc.xml.v100.PropertyNameType) Test(org.junit.Test)

Example 19 with ComparisonOpsType

use of org.geotoolkit.ogc.xml.v110.ComparisonOpsType in project geotoolkit by Geomatys.

the class OGC100Test method testFilterComparisonPropertyIsNull.

@Test
public void testFilterComparisonPropertyIsNull() throws JAXBException {
    final Unmarshaller UNMARSHALLER = POOL.acquireUnmarshaller();
    final Marshaller MARSHALLER = POOL.acquireMarshaller();
    // Read test
    Object obj = UNMARSHALLER.unmarshal(FILE_FIL_COMP_ISNULL);
    assertNotNull(obj);
    JAXBElement<? extends FilterType> jaxfilter = (JAXBElement<? extends FilterType>) obj;
    assertNotNull(jaxfilter);
    Filter filter = TRANSFORMER_GT.visitFilter(jaxfilter.getValue());
    assertNotNull(filter);
    NullOperator prop = (NullOperator) filter;
    ValueReference center = (ValueReference) prop.getExpressions().get(0);
    assertEquals(center.getXPath(), valueStr);
    // write test
    FilterType ft = TRANSFORMER_OGC.apply(filter);
    assertNotNull(ft.getComparisonOps());
    ComparisonOpsType cot = ft.getComparisonOps().getValue();
    PropertyIsNullType pibt = (PropertyIsNullType) cot;
    PropertyNameType pnt = (PropertyNameType) pibt.getPropertyName();
    assertEquals(pnt.getContent(), valueStr);
    MARSHALLER.marshal(ft.getComparisonOps(), TEST_FILE_FIL_COMP_ISNULL);
    POOL.recycle(MARSHALLER);
    POOL.recycle(UNMARSHALLER);
}
Also used : Marshaller(javax.xml.bind.Marshaller) FilterType(org.geotoolkit.ogc.xml.v100.FilterType) PropertyIsNullType(org.geotoolkit.ogc.xml.v100.PropertyIsNullType) Filter(org.opengis.filter.Filter) ComparisonOpsType(org.geotoolkit.ogc.xml.v100.ComparisonOpsType) JAXBElement(javax.xml.bind.JAXBElement) Unmarshaller(javax.xml.bind.Unmarshaller) NullOperator(org.opengis.filter.NullOperator) ValueReference(org.opengis.filter.ValueReference) PropertyNameType(org.geotoolkit.ogc.xml.v100.PropertyNameType) Test(org.junit.Test)

Example 20 with ComparisonOpsType

use of org.geotoolkit.ogc.xml.v110.ComparisonOpsType in project geotoolkit by Geomatys.

the class OGC110Test method testFilterComparisonPropertyIsLike.

@Test
public void testFilterComparisonPropertyIsLike() throws JAXBException, NoSuchAuthorityCodeException, FactoryException {
    final Unmarshaller UNMARSHALLER = POOL.acquireUnmarshaller();
    final Marshaller MARSHALLER = POOL.acquireMarshaller();
    // Read test
    Object obj = UNMARSHALLER.unmarshal(FILE_FIL_COMP_ISLIKE);
    assertNotNull(obj);
    JAXBElement<? extends FilterType> jaxfilter = (JAXBElement<? extends FilterType>) obj;
    assertNotNull(jaxfilter);
    Filter filter = TRANSFORMER_GT.visitFilter(jaxfilter.getValue());
    assertNotNull(filter);
    LikeOperator prop = (LikeOperator) filter;
    ValueReference exp = (ValueReference) prop.getExpressions().get(0);
    char escape = prop.getEscapeChar();
    String literal = (String) ((Literal) prop.getExpressions().get(1)).getValue();
    char single = prop.getSingleChar();
    char wild = prop.getWildCard();
    assertEquals(exp.getXPath(), "LAST_NAME");
    assertEquals(literal, "JOHN*");
    assertEquals(escape, '!');
    assertEquals(single, '#');
    assertEquals(wild, '*');
    // write test
    FilterType ft = TRANSFORMER_OGC.apply(filter);
    assertNotNull(ft.getComparisonOps());
    ComparisonOpsType cot = ft.getComparisonOps().getValue();
    PropertyIsLikeType pibt = (PropertyIsLikeType) cot;
    PropertyNameType lf = pibt.getPropertyName();
    LiteralType lt = pibt.getLiteralType();
    char esc = pibt.getEscapeChar();
    char sin = pibt.getSingleChar();
    char wi = pibt.getWildCard();
    assertEquals(lf.getContent(), "LAST_NAME");
    assertEquals(lt.getContent().get(0).toString().trim(), "JOHN*");
    assertEquals(esc, '!');
    assertEquals(sin, '#');
    assertEquals(wi, '*');
    MARSHALLER.marshal(ft.getComparisonOps(), TEST_FILE_FIL_COMP_ISLIKE);
    POOL.recycle(MARSHALLER);
    POOL.recycle(UNMARSHALLER);
}
Also used : Marshaller(javax.xml.bind.Marshaller) ComparisonOpsType(org.geotoolkit.ogc.xml.v110.ComparisonOpsType) LiteralType(org.geotoolkit.ogc.xml.v110.LiteralType) JAXBElement(javax.xml.bind.JAXBElement) FilterType(org.geotoolkit.ogc.xml.v110.FilterType) Filter(org.opengis.filter.Filter) LikeOperator(org.opengis.filter.LikeOperator) Unmarshaller(javax.xml.bind.Unmarshaller) PropertyIsLikeType(org.geotoolkit.ogc.xml.v110.PropertyIsLikeType) ValueReference(org.opengis.filter.ValueReference) PropertyNameType(org.geotoolkit.ogc.xml.v110.PropertyNameType) Test(org.junit.Test)

Aggregations

JAXBElement (javax.xml.bind.JAXBElement)23 Filter (org.opengis.filter.Filter)20 ValueReference (org.opengis.filter.ValueReference)19 Marshaller (javax.xml.bind.Marshaller)18 Unmarshaller (javax.xml.bind.Unmarshaller)18 Test (org.junit.Test)18 Literal (org.opengis.filter.Literal)15 BinaryComparisonOperator (org.opengis.filter.BinaryComparisonOperator)13 ComparisonOpsType (org.geotoolkit.ogc.xml.v100.ComparisonOpsType)11 ComparisonOpsType (org.geotoolkit.ogc.xml.v110.ComparisonOpsType)11 FilterType (org.geotoolkit.ogc.xml.v100.FilterType)10 PropertyNameType (org.geotoolkit.ogc.xml.v100.PropertyNameType)10 LiteralType (org.geotoolkit.ogc.xml.v100.LiteralType)9 FilterType (org.geotoolkit.ogc.xml.v110.FilterType)9 PropertyNameType (org.geotoolkit.ogc.xml.v110.PropertyNameType)9 LiteralType (org.geotoolkit.ogc.xml.v110.LiteralType)8 BinaryComparisonOpType (org.geotoolkit.ogc.xml.v100.BinaryComparisonOpType)6 BinaryComparisonOpType (org.geotoolkit.ogc.xml.v110.BinaryComparisonOpType)6 LikeOperator (org.opengis.filter.LikeOperator)3 NullOperator (org.opengis.filter.NullOperator)3