use of ddf.catalog.resource.ResourceNotFoundException in project ddf by codice.
the class URLResourceReaderTest method testURLResourceReaderBadQualifier.
@Test
public void testURLResourceReaderBadQualifier() {
URLResourceReader resourceReader = new TestURLResourceReader(mimeTypeMapper, clientBuilderFactory);
resourceReader.setRootResourceDirectories(ImmutableSet.of(ABSOLUTE_PATH + TEST_PATH));
URI uri = TEST_PATH.resolve(MPEG_FILE_NAME_1).toUri();
HashMap<String, Serializable> arguments = new HashMap<String, Serializable>();
try {
LOGGER.info("Getting resource: {}", uri);
resourceReader.retrieveResource(uri, arguments);
} catch (IOException e) {
LOGGER.info("Successfully caught expected IOException");
fail();
} catch (ResourceNotFoundException e) {
LOGGER.info("Caught unexpected ResourceNotFoundException");
assert (true);
}
}
use of ddf.catalog.resource.ResourceNotFoundException 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_STR, GET_ENTERPRISE_RESOURCE_OPTIONS);
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_STR, GET_ENTERPRISE_RESOURCE_OPTIONS);
throw new ResourceNotFoundException(message);
}
} catch (UnsupportedQueryException e) {
LOGGER.debug(ERR_FINDING_MC, metacardId, e);
LOGGER.trace(EXITING_STR, GET_ENTERPRISE_RESOURCE_OPTIONS);
throw new ResourceNotFoundException(ERR_FINDING_MC_UNSUPPORTED, e);
} catch (FederationException e) {
LOGGER.debug(ERR_FEDERATING_QUERY, metacardId, e);
LOGGER.trace(EXITING_STR, GET_ENTERPRISE_RESOURCE_OPTIONS);
throw new ResourceNotFoundException(ERR_FINDING_MC_FEDERATION, e);
} catch (IllegalArgumentException e) {
LOGGER.debug(NO_MC_FOUND, metacardId, e);
LOGGER.trace(EXITING_STR, GET_ENTERPRISE_RESOURCE_OPTIONS);
throw new ResourceNotFoundException(QUERY_RETURNED_NULL, e);
}
LOGGER.trace(EXITING_STR, GET_ENTERPRISE_RESOURCE_OPTIONS);
return Collections.singletonMap(ResourceRequest.OPTION_ARGUMENT, supportedOptions);
}
use of ddf.catalog.resource.ResourceNotFoundException in project ddf by codice.
the class ResourceOperations method getResourceInfo.
private ResourceInfo getResourceInfo(QueryRequest queryRequest, URI uri, Map<String, Serializable> requestProperties, StringBuilder federatedSite, boolean fanoutEnabled) throws ResourceNotFoundException, UnsupportedQueryException, FederationException {
Metacard metacard;
URI resourceUri = uri;
QueryResponse queryResponse = queryOperations.query(queryRequest, null, true, fanoutEnabled);
if (queryResponse.getResults().isEmpty()) {
throw new ResourceNotFoundException("Could not resolve source id for URI by doing a URI based query.");
}
metacard = queryResponse.getResults().get(0).getMetacard();
if (uri != null && queryResponse.getResults().size() > 1) {
for (Result result : queryResponse.getResults()) {
if (uri.equals(result.getMetacard().getResourceURI())) {
metacard = result.getMetacard();
break;
}
}
}
if (resourceUri == null) {
resourceUri = metacard.getResourceURI();
}
federatedSite.append(metacard.getSourceId());
LOGGER.debug("Trying to lookup resource URI {} for metacardId: {}", resourceUri, metacard.getId());
if (!requestProperties.containsKey(Metacard.ID)) {
requestProperties.put(Metacard.ID, metacard.getId());
}
if (!requestProperties.containsKey(Metacard.RESOURCE_URI)) {
requestProperties.put(Metacard.RESOURCE_URI, metacard.getResourceURI());
}
return new ResourceInfo(metacard, resourceUri);
}
use of ddf.catalog.resource.ResourceNotFoundException 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_STR, "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(ERR_FINDING_MC, metacardId, e);
throw new ResourceNotFoundException(ERR_FINDING_MC_UNSUPPORTED, e);
} catch (FederationException e) {
LOGGER.debug(ERR_FEDERATING_QUERY, metacardId, e);
throw new ResourceNotFoundException(ERR_FINDING_MC_FEDERATION, e);
} catch (IllegalArgumentException e) {
LOGGER.debug(NO_MC_FOUND, metacardId, e);
throw new ResourceNotFoundException(QUERY_RETURNED_NULL, e);
} finally {
LOGGER.trace(EXITING_STR, "getResourceOptions");
}
return optionsMap;
}
use of ddf.catalog.resource.ResourceNotFoundException 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_STR, GET_LOCAL_RESOURCE_OPTIONS);
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_STR, GET_LOCAL_RESOURCE_OPTIONS);
throw resourceNotFoundException;
}
} catch (UnsupportedQueryException e) {
LOGGER.debug(ERR_FINDING_MC, metacardId, e);
LOGGER.trace(EXITING_STR, GET_LOCAL_RESOURCE_OPTIONS);
throw new ResourceNotFoundException(ERR_FINDING_MC_UNSUPPORTED, e);
} catch (FederationException e) {
LOGGER.debug(ERR_FEDERATING_QUERY, metacardId, e);
LOGGER.trace(EXITING_STR, GET_LOCAL_RESOURCE_OPTIONS);
throw new ResourceNotFoundException(ERR_FINDING_MC_FEDERATION, e);
} catch (IllegalArgumentException e) {
LOGGER.debug(NO_MC_FOUND, metacardId, e);
LOGGER.trace(EXITING_STR, GET_LOCAL_RESOURCE_OPTIONS);
throw new ResourceNotFoundException(QUERY_RETURNED_NULL, e);
}
LOGGER.trace(EXITING_STR, GET_LOCAL_RESOURCE_OPTIONS);
return optionsMap;
}
Aggregations