Search in sources :

Example 6 with BinaryLogicOpType

use of org.geotoolkit.ogc.xml.v110.BinaryLogicOpType in project ddf by codice.

the class WfsFilterDelegateTest method testLogicalAndOfSpatialTemporal.

/**
 * Verifies that a temporal criteria can be AND'ed to other criteria.
 */
@Test
public void testLogicalAndOfSpatialTemporal() {
    String mockProperty = "myPropertyName";
    String mockType = "myType";
    WfsFilterDelegate delegate = mockFeatureMetacardCreateDelegate(mockProperty, mockType);
    FilterType spatialFilter = delegate.dwithin(Metacard.ANY_GEO, "POINT (30 10)", 1000);
    FilterType temporalFilter = delegate.during(mockProperty, new DateTime().minusDays(365).toDate(), new DateTime().minusDays(10).toDate());
    List<FilterType> filtersToBeAnded = new ArrayList<>(Arrays.asList(spatialFilter, temporalFilter));
    // Perform Test
    FilterType filter = delegate.and(filtersToBeAnded);
    // Verify AND op used
    if (filter.getLogicOps() == null) {
        fail("No AND/OR element found in the generated FilterType.");
    }
    assertEquals(LOGICAL_AND_NAME, filter.getLogicOps().getName().toString());
    BinaryLogicOpType logicOpType = (BinaryLogicOpType) filter.getLogicOps().getValue();
    // Verify two items were AND'ed
    assertEquals(2, logicOpType.getComparisonOpsOrSpatialOpsOrTemporalOps().size());
    // Verify first is spatial, second is temporal
    assertTrue(logicOpType.getComparisonOpsOrSpatialOpsOrTemporalOps().get(0).getValue() instanceof DistanceBufferType);
    assertTrue(logicOpType.getComparisonOpsOrSpatialOpsOrTemporalOps().get(1).getValue() instanceof BinaryTemporalOpType);
}
Also used : FilterType(net.opengis.filter.v_2_0_0.FilterType) BinaryLogicOpType(net.opengis.filter.v_2_0_0.BinaryLogicOpType) ArrayList(java.util.ArrayList) DistanceBufferType(net.opengis.filter.v_2_0_0.DistanceBufferType) DateTime(org.joda.time.DateTime) BinaryTemporalOpType(net.opengis.filter.v_2_0_0.BinaryTemporalOpType) Test(org.junit.Test)

Example 7 with BinaryLogicOpType

use of org.geotoolkit.ogc.xml.v110.BinaryLogicOpType in project ddf by codice.

the class WfsFilterDelegateTest method testLogicalCombinationOfLogicals.

private void testLogicalCombinationOfLogicals(String methName, String compOpName) throws Exception {
    String mockProperty = "myPropertyName";
    String mockType = "myType";
    WfsFilterDelegate delegate = mockFeatureMetacardCreateDelegate(mockProperty, mockType);
    FilterType compFilter1 = delegate.propertyIsLike(Metacard.ANY_TEXT, LITERAL, true);
    FilterType compFilter2 = delegate.propertyIsLike(Metacard.ANY_TEXT, LITERAL, true);
    List<FilterType> subFiltersToBeOred = new ArrayList<>();
    subFiltersToBeOred.add(compFilter1);
    subFiltersToBeOred.add(compFilter2);
    FilterType spatialFilter1 = delegate.dwithin(Metacard.ANY_GEO, "POINT (30 10)", 1000);
    FilterType spatialFilter2 = delegate.dwithin(Metacard.ANY_GEO, "POINT (50 10)", 1500);
    List<FilterType> subFiltersToBeAnded = new ArrayList<>();
    subFiltersToBeAnded.add(spatialFilter1);
    subFiltersToBeAnded.add(spatialFilter2);
    List<FilterType> filtersToCombine = new ArrayList<>();
    filtersToCombine.add(delegate.or(subFiltersToBeOred));
    filtersToCombine.add(delegate.and(subFiltersToBeAnded));
    Method method = WfsFilterDelegate.class.getMethod(methName, List.class);
    FilterType filter = (FilterType) method.invoke(delegate, filtersToCombine);
    // Verify
    assertThat(filter.getLogicOps().getName().toString(), is(compOpName));
    BinaryLogicOpType logicOpType = (BinaryLogicOpType) filter.getLogicOps().getValue();
    BinaryLogicOpType logicOrType = (BinaryLogicOpType) logicOpType.getComparisonOpsOrSpatialOpsOrTemporalOps().get(0).getValue();
    assertThat(logicOpType.getComparisonOpsOrSpatialOpsOrTemporalOps().get(0).getName().toString(), is(LOGICAL_OR_NAME));
    assertThat(logicOrType.getComparisonOpsOrSpatialOpsOrTemporalOps().size(), is(2));
    for (JAXBElement<?> jaxbElement : logicOrType.getComparisonOpsOrSpatialOpsOrTemporalOps()) {
        PropertyIsLikeType compOpsType = (PropertyIsLikeType) jaxbElement.getValue();
        String valRef = fetchPropertyIsLikeExpression(compOpsType, VALUE_REFERENCE);
        assertThat(valRef, is(mockProperty));
        String literal = fetchPropertyIsLikeExpression(compOpsType, LITERAL);
        assertThat(literal, is(LITERAL));
    }
    BinaryLogicOpType logicAndType = (BinaryLogicOpType) logicOpType.getComparisonOpsOrSpatialOpsOrTemporalOps().get(1).getValue();
    assertThat(logicOpType.getComparisonOpsOrSpatialOpsOrTemporalOps().get(1).getName().toString(), is(LOGICAL_AND_NAME));
    DistanceBufferType spatialOpsType1 = (DistanceBufferType) logicAndType.getComparisonOpsOrSpatialOpsOrTemporalOps().get(0).getValue();
    assertThat(spatialOpsType1.getDistance().getValue(), is(1000d));
    DistanceBufferType spatialOpsType2 = (DistanceBufferType) logicAndType.getComparisonOpsOrSpatialOpsOrTemporalOps().get(1).getValue();
    assertThat(spatialOpsType2.getDistance().getValue(), is(1500d));
}
Also used : FilterType(net.opengis.filter.v_2_0_0.FilterType) BinaryLogicOpType(net.opengis.filter.v_2_0_0.BinaryLogicOpType) ArrayList(java.util.ArrayList) Method(java.lang.reflect.Method) DistanceBufferType(net.opengis.filter.v_2_0_0.DistanceBufferType) PropertyIsLikeType(net.opengis.filter.v_2_0_0.PropertyIsLikeType)

Example 8 with BinaryLogicOpType

use of org.geotoolkit.ogc.xml.v110.BinaryLogicOpType in project geo-platform by geosdi.

the class AndOperatorHandler method processQueryRestrictions.

/**
 * @param filter
 * @param queryRestrictionDTOs
 */
@Override
protected void processQueryRestrictions(FilterType filter, List<QueryRestrictionDTO> queryRestrictionDTOs) {
    logger.debug("################### {} Processing............\n", getFilterName());
    List<JAXBElement<?>> elements = super.buildJAXBElementList(queryRestrictionDTOs);
    logger.debug("##################{} builds : {} " + (elements.size() > 1 ? "elements" : "element") + "\n", getFilterName(), elements.size());
    if (elements.size() == 1) {
        if (filter.isSetSpatialOps()) {
            elements.add(filter.getSpatialOps());
            filter.setSpatialOps(null);
            BinaryLogicOpType and = new BinaryLogicOpType();
            and.setComparisonOpsOrSpatialOpsOrLogicOps(elements);
            filter.setLogicOps(filterFactory.createAnd(and));
        } else {
            JAXBElement<ComparisonOpsType> opsTypeJAXBElement = (JAXBElement<ComparisonOpsType>) elements.get(0);
            filter.setComparisonOps(opsTypeJAXBElement);
        }
    } else if (elements.size() > 1) {
        if (filter.isSetSpatialOps()) {
            elements.add(filter.getSpatialOps());
            filter.setSpatialOps(null);
        }
        BinaryLogicOpType and = new BinaryLogicOpType();
        and.setComparisonOpsOrSpatialOpsOrLogicOps(elements);
        filter.setLogicOps(filterFactory.createAnd(and));
    }
}
Also used : BinaryLogicOpType(org.geosdi.geoplatform.xml.filter.v110.BinaryLogicOpType) ComparisonOpsType(org.geosdi.geoplatform.xml.filter.v110.ComparisonOpsType) JAXBElement(javax.xml.bind.JAXBElement)

Example 9 with BinaryLogicOpType

use of org.geotoolkit.ogc.xml.v110.BinaryLogicOpType in project geo-platform by geosdi.

the class OrOperatorHandler method processQueryRestrictions.

/**
 * @param filter
 * @param queryRestrictionDTOs
 */
@Override
protected void processQueryRestrictions(FilterType filter, List<QueryRestrictionDTO> queryRestrictionDTOs) {
    logger.debug("################### {} Processing............\n", getFilterName());
    List<JAXBElement<?>> elements = super.buildJAXBElementList(queryRestrictionDTOs);
    logger.debug("##################{} builds : {} " + (elements.size() > 1 ? "elements" : "element") + "\n", getFilterName(), elements.size());
    if (elements.size() == 1) {
        if (filter.isSetSpatialOps()) {
            elements.add(filter.getSpatialOps());
            filter.setSpatialOps(null);
            BinaryLogicOpType or = new BinaryLogicOpType();
            or.setComparisonOpsOrSpatialOpsOrLogicOps(elements);
            filter.setLogicOps(filterFactory.createOr(or));
        } else {
            JAXBElement<ComparisonOpsType> element = (JAXBElement<ComparisonOpsType>) elements.get(0);
            filter.setComparisonOps(element);
        }
    } else if (elements.size() > 1) {
        if (filter.isSetSpatialOps()) {
            elements.add(filter.getSpatialOps());
            filter.setSpatialOps(null);
        }
        BinaryLogicOpType or = new BinaryLogicOpType();
        or.setComparisonOpsOrSpatialOpsOrLogicOps(elements);
        filter.setLogicOps(filterFactory.createOr(or));
    }
}
Also used : BinaryLogicOpType(org.geosdi.geoplatform.xml.filter.v110.BinaryLogicOpType) ComparisonOpsType(org.geosdi.geoplatform.xml.filter.v110.ComparisonOpsType) JAXBElement(javax.xml.bind.JAXBElement)

Example 10 with BinaryLogicOpType

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

the class OGC110Test method testFilterLogicalOr.

@Test
public void testFilterLogicalOr() throws JAXBException, NoSuchAuthorityCodeException, FactoryException {
    final Unmarshaller UNMARSHALLER = POOL.acquireUnmarshaller();
    final Marshaller MARSHALLER = POOL.acquireMarshaller();
    // Read test
    Object obj = UNMARSHALLER.unmarshal(FILE_FIL_LOG_OR);
    assertNotNull(obj);
    JAXBElement<? extends FilterType> jaxfilter = (JAXBElement<? extends FilterType>) obj;
    assertNotNull(jaxfilter);
    Filter filter = TRANSFORMER_GT.visitFilter(jaxfilter.getValue());
    assertNotNull(filter);
    LogicalOperator prop = (LogicalOperator) filter;
    BinaryComparisonOperator leftop = (BinaryComparisonOperator) prop.getOperands().get(0);
    BinaryComparisonOperator rightop = (BinaryComparisonOperator) prop.getOperands().get(1);
    ValueReference left = (ValueReference) leftop.getOperand1();
    Literal right = (Literal) leftop.getOperand2();
    assertEquals(left.getXPath(), valueStr);
    assertEquals(((Number) right.apply(null)).floatValue(), 455f, DELTA);
    left = (ValueReference) rightop.getOperand1();
    right = (Literal) rightop.getOperand2();
    assertEquals(left.getXPath(), valueStr);
    assertEquals(((Number) right.apply(null)).floatValue(), 457f, DELTA);
    // write test
    FilterType ft = TRANSFORMER_OGC.apply(filter);
    assertNotNull(ft.getLogicOps());
    LogicOpsType cot = ft.getLogicOps().getValue();
    assertEquals(ft.getLogicOps().getName().getLocalPart(), OGCJAXBStatics.FILTER_LOGIC_OR);
    BinaryLogicOpType pibt = (BinaryLogicOpType) cot;
    BinaryComparisonOpType leftoptype = (BinaryComparisonOpType) pibt.getComparisonOps().get(0).getValue();
    BinaryComparisonOpType rightoptype = (BinaryComparisonOpType) pibt.getComparisonOps().get(1).getValue();
    PropertyNameType lf = (PropertyNameType) leftoptype.getExpression().get(0).getValue();
    LiteralType rg = (LiteralType) leftoptype.getExpression().get(1).getValue();
    assertEquals(valueStr, lf.getContent());
    numberEquals(455, rg.getContent().get(0));
    lf = (PropertyNameType) rightoptype.getExpression().get(0).getValue();
    rg = (LiteralType) rightoptype.getExpression().get(1).getValue();
    assertEquals(valueStr, lf.getContent());
    numberEquals(457, rg.getContent().get(0));
    MARSHALLER.marshal(ft.getLogicOps(), TEST_FILE_FIL_LOG_OR);
    POOL.recycle(MARSHALLER);
    POOL.recycle(UNMARSHALLER);
}
Also used : Marshaller(javax.xml.bind.Marshaller) LogicalOperator(org.opengis.filter.LogicalOperator) LiteralType(org.geotoolkit.ogc.xml.v110.LiteralType) JAXBElement(javax.xml.bind.JAXBElement) LogicOpsType(org.geotoolkit.ogc.xml.v110.LogicOpsType) FilterType(org.geotoolkit.ogc.xml.v110.FilterType) BinaryLogicOpType(org.geotoolkit.ogc.xml.v110.BinaryLogicOpType) 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.v110.BinaryComparisonOpType) ValueReference(org.opengis.filter.ValueReference) PropertyNameType(org.geotoolkit.ogc.xml.v110.PropertyNameType) Test(org.junit.Test)

Aggregations

ArrayList (java.util.ArrayList)13 BinaryLogicOpType (net.opengis.filter.v_2_0_0.BinaryLogicOpType)11 FilterType (net.opengis.filter.v_2_0_0.FilterType)11 Test (org.junit.Test)10 JAXBElement (javax.xml.bind.JAXBElement)9 Method (java.lang.reflect.Method)6 DistanceBufferType (net.opengis.filter.v_2_0_0.DistanceBufferType)6 PropertyIsLikeType (net.opengis.filter.v_2_0_0.PropertyIsLikeType)6 Filter (org.opengis.filter.Filter)6 Marshaller (javax.xml.bind.Marshaller)4 Unmarshaller (javax.xml.bind.Unmarshaller)4 BinaryLogicOpType (org.geosdi.geoplatform.xml.filter.v110.BinaryLogicOpType)4 BinaryComparisonOperator (org.opengis.filter.BinaryComparisonOperator)4 Literal (org.opengis.filter.Literal)4 LogicalOperator (org.opengis.filter.LogicalOperator)4 ValueReference (org.opengis.filter.ValueReference)4 BinaryTemporalOpType (net.opengis.filter.v_2_0_0.BinaryTemporalOpType)3 LogicOpsType (org.geotoolkit.ogc.xml.v110.LogicOpsType)3 QueryImpl (ddf.catalog.operation.impl.QueryImpl)2 QueryRequestImpl (ddf.catalog.operation.impl.QueryRequestImpl)2