Search in sources :

Example 6 with BinaryLogicOpType

use of net.opengis.filter.v_2_0_0.BinaryLogicOpType in project ddf by codice.

the class TestWfsFilterDelegate method testLogicalAndOfSpatialTemporal.

/**
     * Verifies that a temporal criteria can be AND'ed to other criteria.
     *
     * @throws Exception
     */
@Test
public void testLogicalAndOfSpatialTemporal() throws Exception {
    String mockProperty = "myPropertyName";
    String mockType = "myType";
    WfsFilterDelegate delegate = mockFeatureMetacardCreateDelegate(mockProperty, mockType);
    FilterType spatialFilter = delegate.dwithin(Metacard.ANY_GEO, "POINT (30 10)", Double.valueOf(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 net.opengis.filter.v_2_0_0.BinaryLogicOpType in project ddf by codice.

the class TestWfsFilterDelegate method testLogicalAndOrComparison.

private void testLogicalAndOrComparison(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> filtersToCombine = new ArrayList<>();
    filtersToCombine.add(compFilter1);
    filtersToCombine.add(compFilter2);
    //Perform Test
    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();
    Assert.assertThat(logicOpType.getComparisonOpsOrSpatialOpsOrTemporalOps().size(), is(2));
    for (JAXBElement<?> jaxbElement : logicOpType.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));
    }
}
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) PropertyIsLikeType(net.opengis.filter.v_2_0_0.PropertyIsLikeType)

Example 8 with BinaryLogicOpType

use of net.opengis.filter.v_2_0_0.BinaryLogicOpType in project ddf by codice.

the class WfsFilterDelegate method buildAndOrFilter.

private FilterType buildAndOrFilter(List<FilterType> filters, JAXBElement<BinaryLogicOpType> andOrFilter) {
    areLogicalOperationsSupported();
    if (filters == null || filters.isEmpty()) {
        return null;
    }
    removeEmptyFilters(filters);
    // Check if these filters contain featureID(s)
    Set<String> featureIds = getFeatureIds(filters);
    if (!CollectionUtils.isEmpty(featureIds)) {
        return buildFeatureIdFilter(featureIds);
    }
    // If we have 1 filter don't wrap it with AND/OR
    if (filters.size() == 1) {
        return filters.get(0);
    }
    for (FilterType filterType : filters) {
        // Determine which filterType is set
        if (filterType.isSetComparisonOps()) {
            andOrFilter.getValue().getComparisonOpsOrSpatialOpsOrTemporalOps().add(filterType.getComparisonOps());
        } else if (filterType.isSetLogicOps()) {
            andOrFilter.getValue().getComparisonOpsOrSpatialOpsOrTemporalOps().add(filterType.getLogicOps());
        } else if (filterType.isSetSpatialOps()) {
            andOrFilter.getValue().getComparisonOpsOrSpatialOpsOrTemporalOps().add(filterType.getSpatialOps());
        } else if (filterType.isSetTemporalOps()) {
            andOrFilter.getValue().getComparisonOpsOrSpatialOpsOrTemporalOps().add(filterType.getTemporalOps());
        }
    }
    FilterType returnFilter = new FilterType();
    returnFilter.setLogicOps(andOrFilter);
    return returnFilter;
}
Also used : FilterType(net.opengis.filter.v_2_0_0.FilterType) LineString(com.vividsolutions.jts.geom.LineString)

Example 9 with BinaryLogicOpType

use of net.opengis.filter.v_2_0_0.BinaryLogicOpType in project ddf by codice.

the class TestWfsFilterDelegate method testLogicalAndOrSpatial.

private void testLogicalAndOrSpatial(String methName, String compOpName) throws Exception {
    String mockProperty = "myPropertyName";
    String mockType = "myType";
    WfsFilterDelegate delegate = mockFeatureMetacardCreateDelegate(mockProperty, mockType);
    FilterType spatialFilter1 = delegate.dwithin(Metacard.ANY_GEO, "POINT (30 10)", Double.valueOf(1000));
    FilterType spatialFilter2 = delegate.dwithin(Metacard.ANY_GEO, "POINT (50 10)", Double.valueOf(1500));
    List<FilterType> filtersToCombine = new ArrayList<>();
    filtersToCombine.add(spatialFilter1);
    filtersToCombine.add(spatialFilter2);
    //Perform Test
    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();
    DistanceBufferType spatialOpsType1 = (DistanceBufferType) logicOpType.getComparisonOpsOrSpatialOpsOrTemporalOps().get(0).getValue();
    assertThat(Double.toString(spatialOpsType1.getDistance().getValue()), is(Double.valueOf(1000).toString()));
    DistanceBufferType spatialOpsType2 = (DistanceBufferType) logicOpType.getComparisonOpsOrSpatialOpsOrTemporalOps().get(1).getValue();
    assertThat(Double.toString(spatialOpsType2.getDistance().getValue()), is(Double.valueOf(1500).toString()));
}
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)

Aggregations

FilterType (net.opengis.filter.v_2_0_0.FilterType)7 ArrayList (java.util.ArrayList)6 BinaryLogicOpType (net.opengis.filter.v_2_0_0.BinaryLogicOpType)6 Test (org.junit.Test)4 Method (java.lang.reflect.Method)3 DistanceBufferType (net.opengis.filter.v_2_0_0.DistanceBufferType)3 PropertyIsLikeType (net.opengis.filter.v_2_0_0.PropertyIsLikeType)3 LineString (com.vividsolutions.jts.geom.LineString)2 QueryImpl (ddf.catalog.operation.impl.QueryImpl)2 QueryRequestImpl (ddf.catalog.operation.impl.QueryRequestImpl)2 BinaryTemporalOpType (net.opengis.filter.v_2_0_0.BinaryTemporalOpType)2 BinaryLogicOpType (ogc.schema.opengis.filter.v_1_0_0.BinaryLogicOpType)2 GetFeatureType (ogc.schema.opengis.wfs.v_1_0_0.GetFeatureType)2 QueryType (ogc.schema.opengis.wfs.v_1_0_0.QueryType)2 Date (java.util.Date)1 List (java.util.List)1 JAXBElement (javax.xml.bind.JAXBElement)1 UnaryLogicOpType (net.opengis.filter.v_2_0_0.UnaryLogicOpType)1 TimeInstantType (net.opengis.gml.v_3_2_1.TimeInstantType)1 TimePeriodType (net.opengis.gml.v_3_2_1.TimePeriodType)1