Search in sources :

Example 1 with BinaryLogicOpType

use of org.geotoolkit.ogc.xml.v100.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 2 with BinaryLogicOpType

use of org.geotoolkit.ogc.xml.v100.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 3 with BinaryLogicOpType

use of org.geotoolkit.ogc.xml.v100.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 4 with BinaryLogicOpType

use of org.geotoolkit.ogc.xml.v100.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(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<>();
                        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<>();
                newValue.add(endDate);
                timeEndPosition.unsetValue();
                timeEndPosition.setValue(newValue);
                timePeriod.setEndPosition(timeEndPosition);
            }
        }
    }
    return newFilters;
}
Also used : ArrayList(java.util.ArrayList) LineString(org.locationtech.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 5 with BinaryLogicOpType

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

the class WfsFilterDelegateTest method testLogicalNotOfLogicals.

@Test
public void testLogicalNotOfLogicals() {
    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)

Aggregations

ArrayList (java.util.ArrayList)12 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)8 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)5 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 QueryImpl (ddf.catalog.operation.impl.QueryImpl)2 QueryRequestImpl (ddf.catalog.operation.impl.QueryRequestImpl)2 UnaryLogicOpType (net.opengis.filter.v_2_0_0.UnaryLogicOpType)2