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));
}
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;
}
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);
}
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);
}
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()));
}
Aggregations