use of ddf.catalog.source.UnsupportedQueryException in project ddf by codice.
the class TagsFilterQueryPlugin method process.
@Override
public QueryRequest process(Source source, QueryRequest input) throws PluginExecutionException, StopProcessingException {
if (!isLocalSource(source)) {
return input;
}
QueryRequest request = input;
try {
Query query = request.getQuery();
if (filterAdapter.adapt(query, new TagsFilterDelegate())) {
return request;
}
List<Filter> filters = new ArrayList<>();
//no tags filter given in props or in query. Add the default ones.
filters.add(filterBuilder.attribute(Metacard.TAGS).is().like().text(Metacard.DEFAULT_TAG));
filters.add(filterBuilder.attribute(Metacard.TAGS).empty());
Filter newFilter = filterBuilder.allOf(filterBuilder.anyOf(filters), query);
QueryImpl newQuery = new QueryImpl(newFilter, query.getStartIndex(), query.getPageSize(), query.getSortBy(), query.requestsTotalResultsCount(), query.getTimeoutMillis());
request = new QueryRequestImpl(newQuery, request.isEnterprise(), request.getSourceIds(), request.getProperties());
} catch (UnsupportedQueryException uqe) {
LOGGER.debug("Unable to update query with default tags filter", uqe);
}
return request;
}
use of ddf.catalog.source.UnsupportedQueryException in project ddf by codice.
the class WfsSource method query.
@Override
public SourceResponse query(QueryRequest request) throws UnsupportedQueryException {
Wfs wfs = factory.getClient();
Query query = request.getQuery();
LOGGER.debug("WFS Source {}: Received query: \n{}", getId(), query);
if (query.getStartIndex() < 1) {
throw new UnsupportedQueryException("Start Index is one-based and must be an integer greater than 0; should not be [" + query.getStartIndex() + "]");
}
SourceResponseImpl simpleResponse = null;
// WFS v1.0 specification does not support response indicating total
// number
// of features satisfying query constraints.
// Hence, we save off the original
// page size from the query request and create a copy of the query,
// changing
// the page size by a multiplier and the current page number of results
// so that
// more features are returned as the user pages through the results,
// getting
// a better sense of how many total features exist that satisfy the
// query.
int origPageSize = query.getPageSize();
if (origPageSize <= 0 || origPageSize > WFS_MAX_FEATURES_RETURNED) {
origPageSize = WFS_MAX_FEATURES_RETURNED;
}
QueryImpl modifiedQuery = new QueryImpl(query);
// Determine current page number of results being requested.
// Example: startIndex = 21 and origPageSize=10, then requesting to go
// to page number 3.
// Note: Integer division will truncate remainders so 4 / 2 will return 0 and not .5. Also,
// pages are numbered 1 - N so we add 1 to the result
int pageNumber = query.getStartIndex() / origPageSize + 1;
// Modified page size is based on current page number and a constant
// multiplier,
// but limited to a max value to prevent time consuming queries just to
// get an
// approximation of total number of features.
// So as page number increases the pageSize increases.
// Example:
// pageNumber=2, modifiedPageSize=60
// pageNumber=3, modifiedPageSize=90
int modifiedPageSize = Math.min(pageNumber * origPageSize * WFS_QUERY_PAGE_SIZE_MULTIPLIER, WFS_MAX_FEATURES_RETURNED);
LOGGER.debug("WFS Source {}: modified page size = {}", getId(), modifiedPageSize);
modifiedQuery.setPageSize(modifiedPageSize);
GetFeatureType getFeature = buildGetFeatureRequest(modifiedQuery);
try {
LOGGER.debug("WFS Source {}: Sending query ...", getId());
WfsFeatureCollection featureCollection = wfs.getFeature(getFeature);
if (featureCollection == null) {
throw new UnsupportedQueryException("Invalid results returned from server");
}
availabilityTask.updateLastAvailableTimestamp(System.currentTimeMillis());
LOGGER.debug("WFS Source {}: Received featureCollection with {} metacards.", getId(), featureCollection.getFeatureMembers().size());
// Only return the number of results originally asked for in the
// query, or the entire list of results if it is smaller than the
// original page size.
int numberOfResultsToReturn = Math.min(origPageSize, featureCollection.getFeatureMembers().size());
List<Result> results = new ArrayList<Result>(numberOfResultsToReturn);
int stopIndex = Math.min((origPageSize * pageNumber) + query.getStartIndex(), featureCollection.getFeatureMembers().size() + 1);
LOGGER.debug("WFS Source {}: startIndex = {}, stopIndex = {}, origPageSize = {}, pageNumber = {}", getId(), query.getStartIndex(), stopIndex, origPageSize, pageNumber);
for (int i = query.getStartIndex(); i < stopIndex; i++) {
Metacard mc = featureCollection.getFeatureMembers().get(i - 1);
mc = transform(mc, DEFAULT_WFS_TRANSFORMER_ID);
Result result = new ResultImpl(mc);
results.add(result);
debugResult(result);
}
Long totalHits = (long) featureCollection.getFeatureMembers().size();
simpleResponse = new SourceResponseImpl(request, results, totalHits);
} catch (WfsException wfse) {
LOGGER.debug(WFS_ERROR_MESSAGE, wfse);
throw new UnsupportedQueryException("Error received from WFS Server", wfse);
} catch (Exception ce) {
String msg = handleClientException(ce);
throw new UnsupportedQueryException(msg, ce);
}
return simpleResponse;
}
use of ddf.catalog.source.UnsupportedQueryException in project ddf by codice.
the class WfsSource method buildGetFeatureRequest.
private GetFeatureType buildGetFeatureRequest(Query query) throws UnsupportedQueryException {
List<ContentType> contentTypes = getContentTypesFromQuery(query);
List<QueryType> queries = new ArrayList<QueryType>();
for (Entry<QName, WfsFilterDelegate> filterDelegateEntry : featureTypeFilters.entrySet()) {
if (contentTypes.isEmpty() || isFeatureTypeInQuery(contentTypes, filterDelegateEntry.getKey().getLocalPart())) {
QueryType wfsQuery = new QueryType();
wfsQuery.setTypeName(filterDelegateEntry.getKey());
FilterType filter = filterAdapter.adapt(query, filterDelegateEntry.getValue());
if (filter != null) {
if (areAnyFiltersSet(filter)) {
wfsQuery.setFilter(filter);
}
queries.add(wfsQuery);
} else {
LOGGER.debug("WFS Source {}: {} has an invalid filter.", getId(), filterDelegateEntry.getKey());
}
}
}
if (queries != null && !queries.isEmpty()) {
GetFeatureType getFeatureType = new GetFeatureType();
getFeatureType.setMaxFeatures(BigInteger.valueOf(query.getPageSize()));
getFeatureType.getQuery().addAll(queries);
getFeatureType.setService(Wfs10Constants.WFS);
getFeatureType.setVersion(Wfs10Constants.VERSION_1_0_0);
logMessage(getFeatureType);
return getFeatureType;
} else {
throw new UnsupportedQueryException("Unable to build query. No filters could be created from query criteria.");
}
}
use of ddf.catalog.source.UnsupportedQueryException in project ddf by codice.
the class DummyPreQueryPlugin method process.
@Override
public QueryRequest process(QueryRequest input) throws PluginExecutionException, StopProcessingException {
String methodName = "process";
LOGGER.trace(ENTERING, methodName);
QueryRequest newQueryRequest = input;
if (input != null) {
Query query = input.getQuery();
if (query != null) {
FilterDelegate<Filter> delegate = new CopyFilterDelegate(filterBuilder);
try {
// Make a defensive copy of the original filter (just in case anyone else
// expects
// it to remain unmodified)
Filter copiedFilter = filterAdapter.adapt(query, delegate);
// Define the extra query clause(s) to add to the copied filter
// This will create a filter with a search phrase of:
// ((("schematypesearch") and ("test" and ("ISAF" or "CAN"))))
Filter contextualFilter = filterBuilder.attribute(Metacard.ANY_TEXT).like().text("test");
Filter releasableToFilter1 = filterBuilder.attribute(Metacard.ANY_TEXT).like().text("ISAF");
Filter releasableToFilter2 = filterBuilder.attribute(Metacard.ANY_TEXT).like().text("CAN");
Filter orFilter = filterBuilder.anyOf(releasableToFilter1, releasableToFilter2);
Filter extraFilter = filterBuilder.allOf(contextualFilter, orFilter);
// AND this PreQueryPlugin's extra query clause(s) to the copied filter
Filter modifiedFilter = filterBuilder.allOf(copiedFilter, extraFilter);
// Create a new QueryRequest using the modified filter and the attributes from
// the original query
QueryImpl newQuery = new QueryImpl(modifiedFilter, query.getStartIndex(), query.getPageSize(), query.getSortBy(), query.requestsTotalResultsCount(), query.getTimeoutMillis());
newQueryRequest = new QueryRequestImpl(newQuery, input.isEnterprise(), input.getSourceIds(), input.getProperties());
} catch (UnsupportedQueryException e) {
throw new PluginExecutionException(e);
}
}
}
LOGGER.trace(EXITING, methodName);
return newQueryRequest;
}
use of ddf.catalog.source.UnsupportedQueryException in project ddf by codice.
the class DummyPreSubscriptionPlugin method process.
public Subscription process(Subscription input) throws PluginExecutionException {
String methodName = "process";
LOGGER.trace(ENTERING, methodName);
Subscription newSubscription = input;
if (input != null) {
FilterDelegate<Filter> delegate = new CopyFilterDelegate(filterBuilder);
try {
// Make a defensive copy of the original filter (just in case anyone else expects
// it to remain unmodified)
Filter copiedFilter = filterAdapter.adapt(input, delegate);
// Define the extra query clause(s) to add to the copied filter
Filter extraFilter = filterBuilder.attribute(Metacard.ANY_TEXT).like().text("CAN");
// AND the extra query clause(s) to the copied filter
Filter modifiedFilter = filterBuilder.allOf(copiedFilter, extraFilter);
// Create a new subscription with the modified filter
newSubscription = new SubscriptionImpl(modifiedFilter, input.getDeliveryMethod(), input.getSourceIds(), input.isEnterprise());
} catch (UnsupportedQueryException e) {
throw new PluginExecutionException(e);
}
}
LOGGER.trace(EXITING, methodName);
return newSubscription;
}
Aggregations