Search in sources :

Example 1 with BinaryLogicOpType

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

the class TestWfsFilterDelegate method testLogicalNotOfLogicals.

@Test
public void testLogicalNotOfLogicals() 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);
    //Perform Test
    FilterType filter = delegate.not(delegate.or(subFiltersToBeOred));
    //Verify
    assertThat(filter.getLogicOps().getName().toString(), is(LOGICAL_NOT_NAME));
    UnaryLogicOpType logicOpType = (UnaryLogicOpType) filter.getLogicOps().getValue();
    BinaryLogicOpType logicOrType = (BinaryLogicOpType) logicOpType.getLogicOps().getValue();
    assertThat(logicOpType.getLogicOps().getName().toString(), is(LOGICAL_OR_NAME));
    PropertyIsLikeType compOpsType1 = (PropertyIsLikeType) logicOrType.getComparisonOpsOrSpatialOpsOrTemporalOps().get(0).getValue();
    String valRef1 = fetchPropertyIsLikeExpression(compOpsType1, VALUE_REFERENCE);
    assertThat(valRef1, is(mockProperty));
    String literal1 = fetchPropertyIsLikeExpression(compOpsType1, LITERAL);
    assertThat(literal1, is(LITERAL));
    PropertyIsLikeType compOpsType2 = (PropertyIsLikeType) logicOrType.getComparisonOpsOrSpatialOpsOrTemporalOps().get(1).getValue();
    String valRef2 = fetchPropertyIsLikeExpression(compOpsType2, VALUE_REFERENCE);
    assertThat(valRef2, is(mockProperty));
    String literal2 = fetchPropertyIsLikeExpression(compOpsType2, LITERAL);
    assertThat(literal2, is(LITERAL));
}
Also used : UnaryLogicOpType(net.opengis.filter.v_2_0_0.UnaryLogicOpType) FilterType(net.opengis.filter.v_2_0_0.FilterType) BinaryLogicOpType(net.opengis.filter.v_2_0_0.BinaryLogicOpType) ArrayList(java.util.ArrayList) PropertyIsLikeType(net.opengis.filter.v_2_0_0.PropertyIsLikeType) Test(org.junit.Test)

Example 2 with BinaryLogicOpType

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

the class WfsFilterDelegate method applyTemporalFallbacks.

protected List<FilterType> applyTemporalFallbacks(List<FilterType> filters) {
    if (null == filters || filters.isEmpty()) {
        return filters;
    }
    String startDate = "";
    String endDate = "";
    String property = "";
    List<FilterType> newFilters = new ArrayList<>();
    for (FilterType filterType : filters) {
        if (null == filterType) {
            continue;
        }
        if (filterType.isSetTemporalOps() && (!isTemporalOpSupported(TEMPORAL_OPERATORS.Before) && !isTemporalOpSupported(TEMPORAL_OPERATORS.After)) && !isDuringFilter(filterType)) {
            BinaryTemporalOpType binaryTemporalOpType = (BinaryTemporalOpType) filterType.getTemporalOps().getValue();
            property = binaryTemporalOpType.getValueReference();
            JAXBElement temporalExpression = binaryTemporalOpType.getExpression();
            TimeInstantType timeInstant = (TimeInstantType) temporalExpression.getValue();
            TimePositionType timePositionType = timeInstant.getTimePosition();
            List<String> value = timePositionType.getValue();
            if (isAfterFilter(filterType)) {
                startDate = value.get(0);
            } else if (isBeforeFilter(filterType)) {
                endDate = value.get(0);
            }
        } else {
            newFilters.add(filterType);
        }
    }
    if (isTemporalOpSupported(TEMPORAL_OPERATORS.During) && (StringUtils.isNotEmpty(startDate))) {
        if (StringUtils.isEmpty(endDate)) {
            endDate = convertDateToIso8601Format(new Date());
        }
        FilterType duringFilter = buildDuringFilterType(featureMetacardType.getFeatureType().getLocalPart() + "." + property, startDate, endDate);
        newFilters.add(duringFilter);
    } else if (isTemporalOpSupported(TEMPORAL_OPERATORS.During) && (StringUtils.isEmpty(startDate) && StringUtils.isNotEmpty(endDate))) {
        for (FilterType filterType : filters) {
            if (!filterType.isSetTemporalOps()) {
                BinaryLogicOpType binaryLogicOpType = (BinaryLogicOpType) filterType.getLogicOps().getValue();
                List<JAXBElement<?>> list = binaryLogicOpType.getComparisonOpsOrSpatialOpsOrTemporalOps();
                for (JAXBElement<?> element : list) {
                    if (StringUtils.contains(element.getDeclaredType().toString(), ("BinaryTemporalOpType"))) {
                        BinaryTemporalOpType binTemp = (BinaryTemporalOpType) element.getValue();
                        JAXBElement temporalExpression = binTemp.getExpression();
                        TimePeriodType timePeriod = (TimePeriodType) temporalExpression.getValue();
                        TimePositionType timeEndPosition = timePeriod.getEndPosition();
                        List<String> newValue = new ArrayList<String>();
                        newValue.add(endDate);
                        timeEndPosition.unsetValue();
                        timeEndPosition.setValue(newValue);
                        timePeriod.setEndPosition(timeEndPosition);
                    }
                }
            } else if ((!isTemporalOpSupported(TEMPORAL_OPERATORS.Before) && !isTemporalOpSupported(TEMPORAL_OPERATORS.After)) && isDuringFilter(filterType)) {
                BinaryTemporalOpType binaryTemporalOpType = (BinaryTemporalOpType) filterType.getTemporalOps().getValue();
                JAXBElement temporalExpression = binaryTemporalOpType.getExpression();
                TimePeriodType timePeriod = (TimePeriodType) temporalExpression.getValue();
                TimePositionType timeEndPosition = timePeriod.getEndPosition();
                List<String> newValue = new ArrayList<String>();
                newValue.add(endDate);
                timeEndPosition.unsetValue();
                timeEndPosition.setValue(newValue);
                timePeriod.setEndPosition(timeEndPosition);
            }
        }
    }
    return newFilters;
}
Also used : ArrayList(java.util.ArrayList) LineString(com.vividsolutions.jts.geom.LineString) JAXBElement(javax.xml.bind.JAXBElement) Date(java.util.Date) TimeInstantType(net.opengis.gml.v_3_2_1.TimeInstantType) FilterType(net.opengis.filter.v_2_0_0.FilterType) BinaryLogicOpType(net.opengis.filter.v_2_0_0.BinaryLogicOpType) TimePeriodType(net.opengis.gml.v_3_2_1.TimePeriodType) List(java.util.List) ArrayList(java.util.ArrayList) BinaryTemporalOpType(net.opengis.filter.v_2_0_0.BinaryTemporalOpType) TimePositionType(net.opengis.gml.v_3_2_1.TimePositionType)

Example 3 with BinaryLogicOpType

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

the class TestWfsSource method testTwoPropertyQuery.

@Test
public void testTwoPropertyQuery() throws UnsupportedQueryException, WfsException, SecurityServiceException {
    setUp(TWO_TEXT_PROPERTY_SCHEMA, null, null, ONE_FEATURE, null);
    QueryImpl propertyIsLikeQuery = new QueryImpl(builder.attribute(Metacard.ANY_TEXT).is().like().text(LITERAL));
    propertyIsLikeQuery.setPageSize(MAX_FEATURES);
    ArgumentCaptor<GetFeatureType> captor = ArgumentCaptor.forClass(GetFeatureType.class);
    source.query(new QueryRequestImpl(propertyIsLikeQuery));
    verify(mockWfs).getFeature(captor.capture());
    GetFeatureType getFeatureType = captor.getValue();
    assertMaxFeatures(getFeatureType, propertyIsLikeQuery);
    assertTrue(getFeatureType.getQuery().size() == ONE_FEATURE);
    QueryType query = getFeatureType.getQuery().get(0);
    assertTrue(query.getTypeName().equals(sampleFeatures.get(0)));
    // The Text Properties should be ORed
    assertTrue(query.getFilter().isSetLogicOps());
    assertTrue(query.getFilter().getLogicOps().getValue() instanceof BinaryLogicOpType);
}
Also used : QueryImpl(ddf.catalog.operation.impl.QueryImpl) BinaryLogicOpType(ogc.schema.opengis.filter.v_1_0_0.BinaryLogicOpType) QueryRequestImpl(ddf.catalog.operation.impl.QueryRequestImpl) QueryType(ogc.schema.opengis.wfs.v_1_0_0.QueryType) GetFeatureType(ogc.schema.opengis.wfs.v_1_0_0.GetFeatureType) Test(org.junit.Test)

Example 4 with BinaryLogicOpType

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

the class TestWfsSource method testAndQuery.

@Test
public void testAndQuery() throws UnsupportedQueryException, WfsException, SecurityServiceException {
    setUp(ONE_TEXT_PROPERTY_SCHEMA, null, null, ONE_FEATURE, null);
    Filter propertyIsLikeFilter = builder.attribute(Metacard.ANY_TEXT).is().like().text(LITERAL);
    Filter contentTypeFilter = builder.attribute(Metacard.ANY_TEXT).is().like().text(sampleFeatures.get(0).getLocalPart());
    QueryImpl propertyIsLikeQuery = new QueryImpl(builder.allOf(propertyIsLikeFilter, contentTypeFilter));
    propertyIsLikeQuery.setPageSize(MAX_FEATURES);
    ArgumentCaptor<GetFeatureType> captor = ArgumentCaptor.forClass(GetFeatureType.class);
    source.query(new QueryRequestImpl(propertyIsLikeQuery));
    verify(mockWfs).getFeature(captor.capture());
    GetFeatureType getFeatureType = captor.getValue();
    assertMaxFeatures(getFeatureType, propertyIsLikeQuery);
    assertTrue(getFeatureType.getQuery().size() == ONE_FEATURE);
    QueryType query = getFeatureType.getQuery().get(0);
    assertTrue(query.getTypeName().equals(sampleFeatures.get(0)));
    assertTrue(query.getFilter().isSetLogicOps());
    assertTrue(query.getFilter().getLogicOps().getValue() instanceof BinaryLogicOpType);
}
Also used : QueryImpl(ddf.catalog.operation.impl.QueryImpl) BinaryLogicOpType(ogc.schema.opengis.filter.v_1_0_0.BinaryLogicOpType) Filter(org.opengis.filter.Filter) QueryRequestImpl(ddf.catalog.operation.impl.QueryRequestImpl) QueryType(ogc.schema.opengis.wfs.v_1_0_0.QueryType) GetFeatureType(ogc.schema.opengis.wfs.v_1_0_0.GetFeatureType) Test(org.junit.Test)

Example 5 with BinaryLogicOpType

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

the class TestWfsFilterDelegate 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)", Double.valueOf(1000));
    FilterType spatialFilter2 = delegate.dwithin(Metacard.ANY_GEO, "POINT (50 10)", Double.valueOf(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(Double.toString(spatialOpsType1.getDistance().getValue()), is(Double.valueOf(1000).toString()));
    DistanceBufferType spatialOpsType2 = (DistanceBufferType) logicAndType.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) PropertyIsLikeType(net.opengis.filter.v_2_0_0.PropertyIsLikeType)

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