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();
if (query == null) {
LOGGER.debug("WFS Source {}: Incoming query is null.", getId());
return null;
}
LOGGER.debug("WFS Source {}: Received query: \n{}", getId(), query);
SourceResponseImpl simpleResponse = null;
GetFeatureType getFeature = buildGetFeatureRequest(query);
try {
LOGGER.debug("WFS Source {}: Sending query ...", getId());
Wfs20FeatureCollection featureCollection = wfs.getFeature(getFeature);
int numResults = -1;
if (featureCollection == null) {
throw new UnsupportedQueryException("Invalid results returned from server");
}
numResults = featureCollection.getMembers().size();
if (featureCollection.getNumberReturned() == null) {
LOGGER.debug("Number Returned Attribute was not added to the response");
} else if (!featureCollection.getNumberReturned().equals(BigInteger.valueOf(numResults))) {
LOGGER.debug("Number Returned Attribute ({}) did not match actual number returned ({})", featureCollection.getNumberReturned(), numResults);
}
availabilityTask.updateLastAvailableTimestamp(System.currentTimeMillis());
LOGGER.debug("WFS Source {}: Received featureCollection with {} metacards.", getId(), numResults);
List<Result> results = new ArrayList<Result>(numResults);
for (int i = 0; i < numResults; i++) {
Metacard mc = featureCollection.getMembers().get(i);
mc = transform(mc, DEFAULT_WFS_TRANSFORMER_ID);
Result result = new ResultImpl(mc);
results.add(result);
debugResult(result);
}
//Fetch total results available
long totalResults = 0;
if (featureCollection.getNumberMatched() == null) {
totalResults = Long.valueOf(numResults);
} else if (featureCollection.getNumberMatched().equals(UNKNOWN)) {
totalResults = Long.valueOf(numResults);
} else if (StringUtils.isNumeric(featureCollection.getNumberMatched())) {
totalResults = Long.parseLong(featureCollection.getNumberMatched());
}
simpleResponse = new SourceResponseImpl(request, results, totalResults);
} 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 MetacardApplication method attemptDeleteDeletedMetacard.
private void attemptDeleteDeletedMetacard(String id) throws UnsupportedQueryException, SourceUnavailableException, FederationException {
LOGGER.trace("Attemping to delete metacard [{}]", id);
Filter tags = filterBuilder.attribute(Metacard.TAGS).is().like().text(DeletedMetacard.DELETED_TAG);
Filter deletion = filterBuilder.attribute(DeletedMetacard.DELETION_OF_ID).is().like().text(id);
Filter filter = filterBuilder.allOf(tags, deletion);
QueryResponse response = null;
try {
response = catalogFramework.query(new QueryRequestImpl(new QueryImpl(filter), false));
} catch (UnsupportedQueryException | SourceUnavailableException | FederationException e) {
LOGGER.debug("Could not find the deleted metacard marker to delete", e);
}
if (response == null || response.getResults() == null || response.getResults().size() != 1) {
LOGGER.debug("There should have been one deleted metacard marker");
return;
}
final QueryResponse _response = response;
try {
executeAsSystem(() -> catalogFramework.delete(new DeleteRequestImpl(_response.getResults().get(0).getMetacard().getId())));
} catch (ExecutionException e) {
LOGGER.debug("Could not delete the deleted metacard marker", e);
}
LOGGER.trace("Deleted delete marker metacard successfully");
}
use of ddf.catalog.source.UnsupportedQueryException in project ddf by codice.
the class Associated method putAssociations.
public void putAssociations(String id, Collection<Edge> edges) throws UnsupportedQueryException, SourceUnavailableException, FederationException, IngestException {
Collection<Edge> oldEdges = getAssociations(id);
List<String> ids = Stream.concat(oldEdges.stream(), edges.stream()).flatMap(e -> Stream.of(e.child, e.parent)).filter(Objects::nonNull).map(m -> m.get(Metacard.ID)).filter(Objects::nonNull).map(Object::toString).distinct().collect(Collectors.toList());
Map<String, Metacard> metacards = util.getMetacards(ids, getNonrestrictedTagsFilter()).entrySet().stream().collect(Collectors.toMap(Map.Entry::getKey, e -> e.getValue().getMetacard()));
Map<String, Metacard> changedMetacards = new HashMap<>();
Set<Edge> oldEdgeSet = new HashSet<>(oldEdges);
Set<Edge> newEdgeSet = new HashSet<>(edges);
Set<Edge> oldDiff = Sets.difference(oldEdgeSet, newEdgeSet);
Set<Edge> newDiff = Sets.difference(newEdgeSet, oldEdgeSet);
for (Edge edge : oldDiff) {
removeEdge(edge, metacards, changedMetacards);
}
for (Edge edge : newDiff) {
addEdge(edge, metacards, changedMetacards);
}
if (changedMetacards.isEmpty()) {
return;
}
catalogFramework.update(new UpdateRequestImpl(changedMetacards.keySet().toArray(new String[0]), new ArrayList<>(changedMetacards.values())));
}
use of ddf.catalog.source.UnsupportedQueryException in project ddf by codice.
the class SolrCacheSource method query.
@Override
public SourceResponse query(QueryRequest request) throws UnsupportedQueryException {
final QueryResponseImpl queryResponse = new QueryResponseImpl(request);
try {
SourceResponse result = cache.query(request);
queryResponse.setHits(result.getHits());
queryResponse.setProperties(result.getProperties());
queryResponse.addResults(result.getResults(), true);
} catch (UnsupportedQueryException e) {
queryResponse.getProcessingDetails().add(new ProcessingDetailsImpl(getId(), e));
queryResponse.closeResultQueue();
}
return queryResponse;
}
use of ddf.catalog.source.UnsupportedQueryException in project ddf by codice.
the class CswEndpoint method getRecordById.
@Override
@POST
@Consumes({ MediaType.TEXT_XML, MediaType.APPLICATION_XML })
@Produces({ MediaType.TEXT_XML, MediaType.APPLICATION_XML })
public CswRecordCollection getRecordById(GetRecordByIdType request, @HeaderParam(CswConstants.RANGE_HEADER) String rangeValue) throws CswException {
if (request == null) {
throw new CswException("GetRecordByIdRequest request is null");
}
String outputFormat = request.getOutputFormat();
String outputSchema = request.getOutputSchema();
validator.validateOutputFormat(outputFormat, mimeTypeTransformerManager);
validator.validateOutputSchema(outputSchema, schemaTransformerManager);
List<String> ids = request.getId();
if (!ids.isEmpty()) {
String id = ids.get(0);
// Check if the request wants to retrieve a product.
if (isProductRetrieval(ids, outputFormat, outputSchema)) {
LOGGER.debug("{} is attempting to retrieve product for: {}", request.getService(), id);
try {
return queryProductById(id, rangeValue);
} catch (UnsupportedQueryException e) {
throw new CswException(String.format(ERROR_ID_PRODUCT_RETRIEVAL, id), e);
}
}
LOGGER.debug("{} is attempting to retrieve records: {}", request.getService(), ids);
CswRecordCollection response = queryById(ids, outputSchema);
response.setOutputSchema(outputSchema);
if (request.isSetElementSetName() && request.getElementSetName().getValue() != null) {
response.setElementSetType(request.getElementSetName().getValue());
} else {
response.setElementSetType(ElementSetType.SUMMARY);
}
LOGGER.debug("{} successfully retrieved record(s): {}", request.getService(), request.getId());
return response;
} else {
throw new CswException("A GetRecordById Query must contain an ID.", CswConstants.MISSING_PARAMETER_VALUE, "id");
}
}
Aggregations