use of org.geotoolkit.ogc.xml.v110.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 org.geotoolkit.ogc.xml.v110.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 org.geotoolkit.ogc.xml.v110.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 org.geotoolkit.ogc.xml.v110.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;
}
use of org.geotoolkit.ogc.xml.v110.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));
}
Aggregations