use of ddf.catalog.operation.impl.SourceResponseImpl in project ddf by codice.
the class NoOpSolrMetacardClient method query.
@Override
public SourceResponse query(QueryRequest request) throws UnsupportedQueryException {
LOGGER.debug("Query was not executed. SolrMetacardClient has not been initialized.");
SourceResponseImpl sourceResponseImpl = new SourceResponseImpl(request, Collections.emptyList());
sourceResponseImpl.setHits(0);
return sourceResponseImpl;
}
use of ddf.catalog.operation.impl.SourceResponseImpl in project ddf by codice.
the class TestGeoJsonQueryResponseTransformer method testNullMetacard.
@Test(expected = CatalogTransformerException.class)
public void testNullMetacard() throws CatalogTransformerException {
List<Result> results = new LinkedList<Result>();
Result result = new ResultImpl(null);
results.add(result);
SourceResponse sourceResponse = new SourceResponseImpl(null, results, 1L);
new GeoJsonQueryResponseTransformer().transform(sourceResponse, null);
}
use of ddf.catalog.operation.impl.SourceResponseImpl in project ddf by codice.
the class TestGeoJsonQueryResponseTransformer method testNullResult.
@Test(expected = CatalogTransformerException.class)
public void testNullResult() throws CatalogTransformerException {
List<Result> results = new LinkedList<Result>();
results.add(null);
results.add(null);
SourceResponse sourceResponse = new SourceResponseImpl(null, results, 2L);
new GeoJsonQueryResponseTransformer().transform(sourceResponse, null);
}
use of ddf.catalog.operation.impl.SourceResponseImpl in project ddf by codice.
the class CatalogFrameworkImplTest method testQueryTransformWithTransformException.
@Test(expected = CatalogTransformerException.class)
public void testQueryTransformWithTransformException() throws Exception {
BundleContext context = mock(BundleContext.class);
QueryResponseTransformer transformer = mock(QueryResponseTransformer.class);
ServiceReference reference = mock(ServiceReference.class);
ServiceReference[] serviceReferences = new ServiceReference[] { reference };
when(context.getServiceReferences(anyString(), anyString())).thenReturn(serviceReferences);
when(context.getService(isA(ServiceReference.class))).thenReturn(transformer);
when(transformer.transform(isA(SourceResponse.class), isA(Map.class))).thenThrow(new CatalogTransformerException("Could not transform"));
CatalogFramework framework = this.createDummyCatalogFramework(provider, storageProvider, context, eventAdmin, true);
SourceResponse response = new SourceResponseImpl(null, null);
framework.transform(response, "NONE", new HashMap<String, Serializable>());
}
use of ddf.catalog.operation.impl.SourceResponseImpl in project ddf by codice.
the class OpenSearchSource method query.
@Override
public SourceResponse query(QueryRequest queryRequest) throws UnsupportedQueryException {
String methodName = "query";
LOGGER.trace(methodName);
Serializable metacardId = queryRequest.getPropertyValue(Metacard.ID);
SourceResponseImpl response = null;
Subject subject = null;
WebClient restWebClient = null;
if (queryRequest.hasProperties()) {
Object subjectObj = queryRequest.getProperties().get(SecurityConstants.SECURITY_SUBJECT);
subject = (Subject) subjectObj;
}
restWebClient = factory.getWebClientForSubject(subject);
Query query = queryRequest.getQuery();
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Received query: " + query);
}
boolean canDoOpenSearch = setOpenSearchParameters(query, subject, restWebClient);
if (canDoOpenSearch) {
InputStream responseStream = performRequest(restWebClient);
response = new SourceResponseImpl(queryRequest, new ArrayList<Result>());
if (responseStream != null) {
response = processResponse(responseStream, queryRequest);
}
} else {
if (StringUtils.isEmpty((String) metacardId)) {
OpenSearchFilterVisitor visitor = new OpenSearchFilterVisitor();
query.accept(visitor, null);
metacardId = visitor.getMetacardId();
}
restWebClient = newRestClient(query, (String) metacardId, false, subject);
if (restWebClient != null) {
InputStream responseStream = performRequest(restWebClient);
Metacard metacard = null;
List<Result> resultQueue = new ArrayList<Result>();
try (TemporaryFileBackedOutputStream fileBackedOutputStream = new TemporaryFileBackedOutputStream()) {
if (responseStream != null) {
IOUtils.copyLarge(responseStream, fileBackedOutputStream);
InputTransformer inputTransformer = null;
try (InputStream inputStream = fileBackedOutputStream.asByteSource().openStream()) {
inputTransformer = getInputTransformer(inputStream);
} catch (IOException e) {
LOGGER.debug("Problem with transformation.", e);
}
if (inputTransformer != null) {
try (InputStream inputStream = fileBackedOutputStream.asByteSource().openStream()) {
metacard = inputTransformer.transform(inputStream);
} catch (IOException e) {
LOGGER.debug("Problem with transformation.", e);
}
}
}
} catch (IOException | CatalogTransformerException e) {
LOGGER.debug("Problem with transformation.", e);
}
if (metacard != null) {
metacard.setSourceId(getId());
ResultImpl result = new ResultImpl(metacard);
resultQueue.add(result);
response = new SourceResponseImpl(queryRequest, resultQueue);
response.setHits(resultQueue.size());
}
}
}
LOGGER.trace(methodName);
return response;
}
Aggregations