use of ddf.catalog.operation.QueryRequest in project ddf by codice.
the class ResourceOperations method getEnterpriseResourceOptions.
public Map<String, Set<String>> getEnterpriseResourceOptions(String metacardId, boolean fanoutEnabled) throws ResourceNotFoundException {
LOGGER.trace("ENTERING: getEnterpriseResourceOptions");
Set<String> supportedOptions = Collections.emptySet();
try {
QueryRequest queryRequest = new QueryRequestImpl(createMetacardIdQuery(metacardId), true, null, null);
QueryResponse queryResponse = queryOperations.query(queryRequest, null, false, fanoutEnabled);
List<Result> results = queryResponse.getResults();
if (!results.isEmpty()) {
Metacard metacard = results.get(0).getMetacard();
String sourceIdOfResult = metacard.getSourceId();
if (sourceIdOfResult != null && sourceIdOfResult.equals(getId())) {
// found entry on local source
supportedOptions = getOptionsFromLocalProvider(metacard);
} else if (sourceIdOfResult != null && !sourceIdOfResult.equals(getId())) {
// found entry on federated source
supportedOptions = getOptionsFromFederatedSource(metacard, sourceIdOfResult);
}
} else {
String message = "Unable to find metacard " + metacardId + " on enterprise.";
LOGGER.debug(message);
LOGGER.trace("EXITING: getEnterpriseResourceOptions");
throw new ResourceNotFoundException(message);
}
} catch (UnsupportedQueryException e) {
LOGGER.debug("Error finding metacard {}", metacardId, e);
LOGGER.trace("EXITING: getEnterpriseResourceOptions");
throw new ResourceNotFoundException("Error finding metacard due to Unsuppported Query", e);
} catch (FederationException e) {
LOGGER.debug("Error federating query for metacard {}", metacardId, e);
LOGGER.trace("EXITING: getEnterpriseResourceOptions");
throw new ResourceNotFoundException("Error finding metacard due to Federation issue", e);
} catch (IllegalArgumentException e) {
LOGGER.debug("Metacard couldn't be found {}", metacardId, e);
LOGGER.trace("EXITING: getEnterpriseResourceOptions");
throw new ResourceNotFoundException("Query returned null metacard", e);
}
LOGGER.trace("EXITING: getEnterpriseResourceOptions");
return Collections.singletonMap(ResourceRequest.OPTION_ARGUMENT, supportedOptions);
}
use of ddf.catalog.operation.QueryRequest in project ddf by codice.
the class ResourceOperations method getResourceOptions.
public Map<String, Set<String>> getResourceOptions(String metacardId, String sourceId, boolean fanoutEnabled) throws ResourceNotFoundException {
LOGGER.trace("ENTERING: getResourceOptions");
Map<String, Set<String>> optionsMap;
try {
LOGGER.debug("source id to get options from: {}", sourceId);
QueryRequest queryRequest = new QueryRequestImpl(createMetacardIdQuery(metacardId), false, Collections.singletonList(sourceId == null ? this.getId() : sourceId), null);
QueryResponse queryResponse = queryOperations.query(queryRequest, null, false, fanoutEnabled);
List<Result> results = queryResponse.getResults();
if (!results.isEmpty()) {
Metacard metacard = results.get(0).getMetacard();
// or the local provider.
if (StringUtils.isEmpty(sourceId) || sourceId.equals(getId())) {
optionsMap = Collections.singletonMap(ResourceRequest.OPTION_ARGUMENT, getOptionsFromLocalProvider(metacard));
} else {
optionsMap = Collections.singletonMap(ResourceRequest.OPTION_ARGUMENT, getOptionsFromFederatedSource(metacard, sourceId));
}
} else {
String message = "Could not find metacard " + metacardId + " on source " + sourceId;
throw new ResourceNotFoundException(message);
}
} catch (UnsupportedQueryException e) {
LOGGER.debug("Error finding metacard {}", metacardId, e);
throw new ResourceNotFoundException("Error finding metacard due to Unsuppported Query", e);
} catch (FederationException e) {
LOGGER.debug("Error federating query for metacard {}", metacardId, e);
throw new ResourceNotFoundException("Error finding metacard due to Federation issue", e);
} catch (IllegalArgumentException e) {
LOGGER.debug("Metacard couldn't be found {}", metacardId, e);
throw new ResourceNotFoundException("Query returned null metacard", e);
} finally {
LOGGER.trace("EXITING: getResourceOptions");
}
return optionsMap;
}
use of ddf.catalog.operation.QueryRequest in project ddf by codice.
the class ResourceOperations method getLocalResourceOptions.
public Map<String, Set<String>> getLocalResourceOptions(String metacardId, boolean fanoutEnabled) throws ResourceNotFoundException {
LOGGER.trace("ENTERING: getLocalResourceOptions");
Map<String, Set<String>> optionsMap;
try {
QueryRequest queryRequest = new QueryRequestImpl(createMetacardIdQuery(metacardId), false, Collections.singletonList(getId()), null);
QueryResponse queryResponse = queryOperations.query(queryRequest, null, false, fanoutEnabled);
List<Result> results = queryResponse.getResults();
if (!results.isEmpty()) {
Metacard metacard = results.get(0).getMetacard();
optionsMap = Collections.singletonMap(ResourceRequest.OPTION_ARGUMENT, getOptionsFromLocalProvider(metacard));
} else {
String message = "Could not find metacard " + metacardId + " on local source";
ResourceNotFoundException resourceNotFoundException = new ResourceNotFoundException(message);
LOGGER.trace("EXITING: getLocalResourceOptions");
throw resourceNotFoundException;
}
} catch (UnsupportedQueryException e) {
LOGGER.debug("Error finding metacard {}", metacardId, e);
LOGGER.trace("EXITING: getLocalResourceOptions");
throw new ResourceNotFoundException("Error finding metacard due to Unsuppported Query", e);
} catch (FederationException e) {
LOGGER.debug("Error federating query for metacard {}", metacardId, e);
LOGGER.trace("EXITING: getLocalResourceOptions");
throw new ResourceNotFoundException("Error finding metacard due to Federation issue", e);
} catch (IllegalArgumentException e) {
LOGGER.debug("Metacard couldn't be found {}", metacardId, e);
LOGGER.trace("EXITING: getLocalResourceOptions");
throw new ResourceNotFoundException("Query returned null metacard", e);
}
LOGGER.trace("EXITING: getLocalResourceOptions");
return optionsMap;
}
use of ddf.catalog.operation.QueryRequest in project ddf by codice.
the class PointOfContactUpdatePluginTest method testPassthroughMethods.
@Test
public void testPassthroughMethods() throws Exception {
CreateRequest createRequest = mock(CreateRequest.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(pointOfContactUpdatePlugin.processPreCreate(createRequest), is(createRequest));
assertThat(pointOfContactUpdatePlugin.processPreDelete(deleteRequest), is(deleteRequest));
assertThat(pointOfContactUpdatePlugin.processPostDelete(deleteResponse), is(deleteResponse));
assertThat(pointOfContactUpdatePlugin.processPreQuery(queryRequest), is(queryRequest));
assertThat(pointOfContactUpdatePlugin.processPostQuery(queryResponse), is(queryResponse));
assertThat(pointOfContactUpdatePlugin.processPreResource(resourceRequest), is(resourceRequest));
assertThat(pointOfContactUpdatePlugin.processPostResource(resourceResponse, mock(Metacard.class)), is(resourceResponse));
verifyZeroInteractions(createRequest, deleteRequest, queryRequest, resourceRequest, deleteResponse, queryResponse, resourceResponse);
}
use of ddf.catalog.operation.QueryRequest in project ddf by codice.
the class MetacardIngestNetworkPluginTest method testPassthroughMethods.
@Test
public void testPassthroughMethods() throws Exception {
ThreadContext.put(CLIENT_INFO_KEY, INFO_MAP);
when(mockMetacardCondition.applies(INFO_MAP)).thenReturn(true);
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);
}
Aggregations