use of net.opengis.filter.v_2_0_0.FilterType in project ddf by codice.
the class WfsFilterDelegate method buildAfterFilterType.
private FilterType buildAfterFilterType(String propertyName, String date) {
TemporalOperand timeInstantTemporalOperand = new TemporalOperand();
timeInstantTemporalOperand.setName(new QName(Wfs20Constants.GML_3_2_NAMESPACE, Wfs20Constants.TIME_INSTANT));
if (!isTemporalOperandSupported(timeInstantTemporalOperand)) {
throw new UnsupportedOperationException("Temporal Operand [" + timeInstantTemporalOperand.getName() + "] is not supported.");
}
if (!isValidInputParameters(propertyName, date)) {
throw new IllegalArgumentException(MISSING_PARAMETERS_MSG);
}
if (!isPropertyTemporalType(propertyName)) {
throw new IllegalArgumentException("Property [" + propertyName + "] is not of type " + timeInstantTemporalOperand.getName() + ".");
}
FilterType filter = filterObjectFactory.createFilterType();
if (featureMetacardType.getProperties().contains(propertyName)) {
FeatureAttributeDescriptor featureAttributeDescriptor = (FeatureAttributeDescriptor) featureMetacardType.getAttributeDescriptor(propertyName);
if (featureAttributeDescriptor.isIndexed()) {
filter.setTemporalOps(createAfter(featureAttributeDescriptor.getPropertyName(), featureMetacardType.getName(), date));
} else {
throw new IllegalArgumentException(String.format(PROPERTY_NOT_QUERYABLE, propertyName));
}
} else {
return null;
}
if (!isTemporalOpSupported(TEMPORAL_OPERATORS.After)) {
if (isTemporalOpSupported(TEMPORAL_OPERATORS.During)) {
return buildDuringFilterType(propertyName, date, convertDateToIso8601Format(new Date()));
}
}
return filter;
}
use of net.opengis.filter.v_2_0_0.FilterType in project ddf by codice.
the class WfsFilterDelegate method buildGeospatialFilterType.
private FilterType buildGeospatialFilterType(String spatialOpType, String propertyName, String wkt, Double distance) {
FilterType returnFilter = new FilterType();
if (Metacard.ANY_GEO.equals(propertyName)) {
if (CollectionUtils.isEmpty(featureMetacardType.getGmlProperties())) {
LOGGER.debug("Feature Type does not have GEO properties to query");
return null;
}
if (featureMetacardType.getGmlProperties().size() == 1) {
FeatureAttributeDescriptor attrDesc = (FeatureAttributeDescriptor) featureMetacardType.getAttributeDescriptor(featureMetacardType.getGmlProperties().get(0));
if (attrDesc != null && attrDesc.isIndexed()) {
returnFilter.setSpatialOps(createSpatialOpType(spatialOpType, attrDesc.getPropertyName(), wkt, distance));
} else {
LOGGER.debug("All GEO properties have been blacklisted. Removing from query");
return null;
}
} else {
List<FilterType> filtersToBeOred = new ArrayList<FilterType>();
for (String property : featureMetacardType.getGmlProperties()) {
FeatureAttributeDescriptor attrDesc = (FeatureAttributeDescriptor) featureMetacardType.getAttributeDescriptor(property);
if (attrDesc != null && attrDesc.isIndexed()) {
FilterType filter = new FilterType();
filter.setSpatialOps(createSpatialOpType(spatialOpType, attrDesc.getPropertyName(), wkt, distance));
filtersToBeOred.add(filter);
} else {
LOGGER.debug(String.format(PROPERTY_NOT_QUERYABLE, property));
}
}
if (!filtersToBeOred.isEmpty()) {
returnFilter = or(filtersToBeOred);
} else {
LOGGER.debug("All GEO properties have been blacklisted. Removing from query.");
returnFilter = null;
}
}
} else if (featureMetacardType.getGmlProperties().contains(propertyName)) {
FeatureAttributeDescriptor attrDesc = (FeatureAttributeDescriptor) featureMetacardType.getAttributeDescriptor(propertyName);
if (attrDesc != null && attrDesc.isIndexed()) {
FilterType filter = new FilterType();
filter.setSpatialOps(createSpatialOpType(spatialOpType, attrDesc.getPropertyName(), wkt, distance));
return filter;
} else {
// blacklisted property encountered
throw new IllegalArgumentException(String.format(PROPERTY_NOT_QUERYABLE, propertyName));
}
} else {
return null;
}
return returnFilter;
}
use of net.opengis.filter.v_2_0_0.FilterType in project ddf by codice.
the class WfsFilterDelegate method removeEmptyFilters.
private void removeEmptyFilters(List<FilterType> filters) {
// Loop through the filters and remove any empty filters
List<FilterType> filtersToBeRemoved = new ArrayList<FilterType>(filters.size());
Boolean foundInvalidFilter = false;
for (FilterType filterType : filters) {
if (filterType == null) {
foundInvalidFilter = true;
} else if (!isFilterSet(filterType)) {
filtersToBeRemoved.add(filterType);
}
}
// If we found an invalid filter we want to return an invalid filter.
if (foundInvalidFilter) {
filters.clear();
filters.add(null);
} else {
filters.removeAll(filtersToBeRemoved);
filters.removeAll(Collections.singleton(null));
if (filters.isEmpty()) {
filters.add(new FilterType());
}
}
}
use of net.opengis.filter.v_2_0_0.FilterType 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.FilterType in project ddf by codice.
the class WfsFilterDelegate method buildPropertyIsFilterType.
private FilterType buildPropertyIsFilterType(String propertyName, Object literal, PROPERTY_IS_OPS propertyIsType) {
if (!isValidInputParameters(propertyName, literal)) {
throw new IllegalArgumentException(MISSING_PARAMETERS_MSG);
}
FilterType returnFilter = new FilterType();
if (Metacard.CONTENT_TYPE.equals(propertyName)) {
return returnFilter;
}
// series of OR's
if ((Metacard.ANY_TEXT.equalsIgnoreCase(propertyName))) {
if (CollectionUtils.isEmpty(featureMetacardType.getTextualProperties())) {
LOGGER.debug("Feature Type does not have Textual Properties to query.");
return null;
}
if (featureMetacardType.getTextualProperties().size() == 1) {
FeatureAttributeDescriptor attrDescriptor = (FeatureAttributeDescriptor) featureMetacardType.getAttributeDescriptor(featureMetacardType.getTextualProperties().get(0));
if (attrDescriptor.isIndexed()) {
returnFilter.setComparisonOps(createPropertyIsFilter(attrDescriptor.getPropertyName(), literal, propertyIsType));
} else {
LOGGER.debug("All textual properties have been blacklisted. Removing from query.");
return null;
}
} else {
List<FilterType> binaryCompOpsToBeOred = new ArrayList<FilterType>();
for (String property : featureMetacardType.getTextualProperties()) {
// only build filters for queryable properties
FeatureAttributeDescriptor attrDesc = (FeatureAttributeDescriptor) featureMetacardType.getAttributeDescriptor(property);
if (attrDesc.isIndexed()) {
FilterType filter = new FilterType();
filter.setComparisonOps(createPropertyIsFilter(attrDesc.getPropertyName(), literal, propertyIsType));
binaryCompOpsToBeOred.add(filter);
} else {
LOGGER.debug(String.format(PROPERTY_NOT_QUERYABLE, property));
}
}
if (!binaryCompOpsToBeOred.isEmpty()) {
returnFilter = or(binaryCompOpsToBeOred);
} else {
LOGGER.debug("All textual properties have been blacklisted. Removing from query.");
return null;
}
}
// filter is for a specific property; check to see if it is valid
} else if (featureMetacardType.getProperties().contains(propertyName)) {
FeatureAttributeDescriptor attrDesc = (FeatureAttributeDescriptor) featureMetacardType.getAttributeDescriptor(propertyName);
if (attrDesc.isIndexed()) {
returnFilter.setComparisonOps(createPropertyIsFilter(attrDesc.getPropertyName(), literal, propertyIsType));
} else {
// blacklisted property encountered
throw new IllegalArgumentException(String.format(PROPERTY_NOT_QUERYABLE, propertyName));
}
} else if (Metacard.ID.equals(propertyName)) {
LOGGER.debug("feature id query for : {}", literal);
String[] idTokens = literal.toString().split("\\.");
if (idTokens.length > 1) {
if (idTokens[0].equals(featureMetacardType.getName())) {
LOGGER.debug("feature type matches metacard type; creating featureID filter");
returnFilter.getId().add(createFeatureIdFilter(literal.toString()));
} else {
LOGGER.debug("feature type does not match metacard type; invalidating filter");
return null;
}
} else {
returnFilter.getId().add(createFeatureIdFilter(literal.toString()));
}
} else {
return null;
}
return returnFilter;
}
Aggregations