use of ddf.catalog.operation.QueryResponse in project ddf by codice.
the class AbstractCatalogService method getHeaders.
@Override
public BinaryContent getHeaders(String sourceid, String id, URI absolutePath, MultivaluedMap<String, String> queryParameters) throws CatalogServiceException {
QueryResponse queryResponse;
Metacard card = null;
LOGGER.trace("getHeaders");
if (id != null) {
LOGGER.debug("Got id: {}", LogSanitizer.sanitize(id));
LOGGER.debug("Map of query parameters: \n{}", LogSanitizer.sanitize(queryParameters));
Map<String, Serializable> convertedMap = convert(queryParameters);
convertedMap.put("url", absolutePath.toString());
LOGGER.debug("Map converted, retrieving product.");
// default to xml if no transformer specified
try {
String transformer = DEFAULT_METACARD_TRANSFORMER;
Filter filter = getFilterBuilder().attribute(Metacard.ID).is().equalTo().text(id);
Collection<String> sources = null;
if (sourceid != null) {
sources = new ArrayList<>();
sources.add(sourceid);
}
QueryRequestImpl request = new QueryRequestImpl(new QueryImpl(filter), sources);
request.setProperties(convertedMap);
queryResponse = catalogFramework.query(request, null);
// pull the metacard out of the blocking queue
List<Result> results = queryResponse.getResults();
// return null if timeout elapsed)
if (results != null && !results.isEmpty()) {
card = results.get(0).getMetacard();
}
if (card == null) {
return null;
}
LOGGER.debug("Calling transform.");
final BinaryContent content = catalogFramework.transform(card, transformer, convertedMap);
LOGGER.debug("Read and transform complete, preparing response.");
return content;
} catch (FederationException e) {
String exceptionMessage = "READ failed due to unexpected exception: ";
LOGGER.info(exceptionMessage, e);
throw new InternalServerErrorException(exceptionMessage);
} catch (CatalogTransformerException e) {
String exceptionMessage = "Unable to transform Metacard. Try different transformer: ";
LOGGER.info(exceptionMessage, e);
throw new InternalServerErrorException(exceptionMessage);
} catch (SourceUnavailableException e) {
String exceptionMessage = "Cannot obtain query results because source is unavailable: ";
LOGGER.info(exceptionMessage, e);
throw new InternalServerErrorException(exceptionMessage);
} catch (UnsupportedQueryException e) {
String errorMessage = "Specified query is unsupported. Change query and resubmit: ";
LOGGER.info(errorMessage, e);
throw new CatalogServiceException(errorMessage);
// The catalog framework will throw this if any of the transformers blow up. We need to
// catch this exception
// here or else execution will return to CXF and we'll lose this message and end up with
// a huge stack trace
// in a GUI or whatever else is connected to this endpoint
} catch (IllegalArgumentException e) {
throw new CatalogServiceException(e.getMessage());
}
} else {
throw new CatalogServiceException("No ID specified.");
}
}
use of ddf.catalog.operation.QueryResponse in project ddf by codice.
the class MetacardIngestNetworkPluginTest method testPassthroughMethods.
@Test
public void testPassthroughMethods() throws Exception {
ThreadContext.put(CLIENT_INFO_KEY, INFO_MAP);
UpdateRequest updateRequest = mock(UpdateRequest.class);
DeleteRequest deleteRequest = mock(DeleteRequest.class);
QueryRequest queryRequest = mock(QueryRequest.class);
ResourceRequest resourceRequest = mock(ResourceRequest.class);
DeleteResponse deleteResponse = mock(DeleteResponse.class);
QueryResponse queryResponse = mock(QueryResponse.class);
ResourceResponse resourceResponse = mock(ResourceResponse.class);
assertThat(plugin.processPreUpdate(updateRequest, mock(Map.class)), is(updateRequest));
assertThat(plugin.processPreDelete(deleteRequest), is(deleteRequest));
assertThat(plugin.processPreQuery(queryRequest), is(queryRequest));
assertThat(plugin.processPreResource(resourceRequest), is(resourceRequest));
assertThat(plugin.processPostDelete(deleteResponse), is(deleteResponse));
assertThat(plugin.processPostQuery(queryResponse), is(queryResponse));
assertThat(plugin.processPostResource(resourceResponse, mock(Metacard.class)), is(resourceResponse));
verifyZeroInteractions(mockMetacardCondition, mockMetacardServices, updateRequest, deleteRequest, queryRequest, resourceRequest, deleteResponse, queryResponse, resourceResponse);
}
use of ddf.catalog.operation.QueryResponse in project ddf by codice.
the class SendEvent method sendEvent.
private void sendEvent(String operation, Metacard... metacards) {
if (subject == null) {
return;
}
try {
List<Result> results = Arrays.asList(metacards).stream().map(ResultImpl::new).collect(Collectors.toList());
QueryResponse queryResponse = new QueryResponseImpl(query, results, true, metacards.length);
CswRecordCollection recordCollection = new CswRecordCollection();
recordCollection.setElementName(elementName);
recordCollection.setElementSetType(elementSetType);
recordCollection.setById(false);
recordCollection.setRequest(request);
recordCollection.setResultType(resultType);
recordCollection.setDoWriteNamespaces(false);
recordCollection.setMimeType(mimeType);
recordCollection.setOutputSchema(outputSchema);
queryResponse.getRequest().getProperties().put(SecurityConstants.SECURITY_SUBJECT, subject);
for (AccessPlugin plugin : getAccessPlugins()) {
queryResponse = plugin.processPostQuery(queryResponse);
}
if (queryResponse.getResults().isEmpty()) {
return;
}
recordCollection.setSourceResponse(queryResponse);
send(operation, recordCollection);
} catch (StopProcessingException | InvalidSyntaxException e) {
LOGGER.debug("Unable to send event error running AccessPlugin processPostQuery. ", e);
}
}
use of ddf.catalog.operation.QueryResponse in project ddf by codice.
the class GeoNamesCatalogIndexerTest method setUp.
@Before
public void setUp() throws Exception {
geoEntryCreator = mock(GeoEntryCreator.class);
when(geoEntryCreator.createGeoEntry(anyString(), anyString())).thenReturn(GEO_ENTRY);
geoEntryExtractor = new GeoNamesFileExtractor();
geoEntryExtractor.setGeoEntryCreator(geoEntryCreator);
catalogFramework = mock(CatalogFramework.class);
uuidGenerator = mock(UuidGenerator.class);
createResponse = mock(CreateResponse.class);
when(createResponse.getCreatedMetacards()).thenReturn(Collections.singletonList(METACARD));
when(catalogFramework.create(any(CreateRequest.class))).thenReturn(createResponse);
when(uuidGenerator.generateUuid()).thenReturn(UUID.randomUUID().toString());
catalogProvider = mock(CatalogProvider.class);
DeleteResponse deleteResponse = mock(DeleteResponse.class);
when(deleteResponse.getDeletedMetacards()).thenReturn(Collections.singletonList(METACARD));
when(catalogProvider.delete(any(DeleteRequest.class))).thenReturn(deleteResponse);
queryResponse = mock(QueryResponse.class);
when(queryResponse.getResults()).thenReturn(Collections.singletonList(new ResultImpl(new MetacardImpl())));
when(catalogFramework.query(any(QueryRequest.class))).thenReturn(queryResponse);
progressCallback = progress -> {
};
geoNamesCatalogIndexer = new GeoNamesCatalogIndexer(catalogFramework, uuidGenerator, new GeoEntryAttributes(), new GeotoolsFilterBuilder(), Collections.singletonList(catalogProvider));
}
use of ddf.catalog.operation.QueryResponse in project ddf by codice.
the class GazetteerQueryCatalog method queryById.
@Override
public GeoEntry queryById(String id) throws GeoEntryQueryException {
if (StringUtils.isBlank(id)) {
throw new IllegalArgumentException("id cannot be blank or null");
}
Filter idFilter = filterBuilder.attribute(Core.ID).is().text(id);
Filter queryFilter = filterBuilder.allOf(tagFilter, idFilter);
QueryResponse queryResponse;
try {
queryResponse = catalogFramework.query(new QueryRequestImpl(new QueryImpl(queryFilter)));
} catch (UnsupportedQueryException | SourceUnavailableException | FederationException e) {
throw new GeoEntryQueryException(ERROR_MESSAGE, e);
}
if (!queryResponse.getResults().isEmpty()) {
Result result = queryResponse.getResults().get(0);
return transformMetacardToGeoEntry(result.getMetacard());
}
return null;
}
Aggregations