Search in sources :

Example 16 with ResourceNotFoundException

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);
    }
}
Also used : Serializable(java.io.Serializable) HashMap(java.util.HashMap) MultivaluedHashMap(javax.ws.rs.core.MultivaluedHashMap) Matchers.containsString(org.hamcrest.Matchers.containsString) IOException(java.io.IOException) ResourceNotFoundException(ddf.catalog.resource.ResourceNotFoundException) URI(java.net.URI) Test(org.junit.Test)

Example 17 with ResourceNotFoundException

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);
}
Also used : Metacard(ddf.catalog.data.Metacard) QueryRequest(ddf.catalog.operation.QueryRequest) QueryRequestImpl(ddf.catalog.operation.impl.QueryRequestImpl) QueryResponse(ddf.catalog.operation.QueryResponse) UnsupportedQueryException(ddf.catalog.source.UnsupportedQueryException) ResourceNotFoundException(ddf.catalog.resource.ResourceNotFoundException) FederationException(ddf.catalog.federation.FederationException) Result(ddf.catalog.data.Result)

Example 18 with ResourceNotFoundException

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);
}
Also used : Metacard(ddf.catalog.data.Metacard) QueryResponse(ddf.catalog.operation.QueryResponse) ResourceNotFoundException(ddf.catalog.resource.ResourceNotFoundException) URI(java.net.URI) Result(ddf.catalog.data.Result)

Example 19 with ResourceNotFoundException

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;
}
Also used : Set(java.util.Set) QueryRequest(ddf.catalog.operation.QueryRequest) UnsupportedQueryException(ddf.catalog.source.UnsupportedQueryException) FederationException(ddf.catalog.federation.FederationException) Result(ddf.catalog.data.Result) Metacard(ddf.catalog.data.Metacard) QueryRequestImpl(ddf.catalog.operation.impl.QueryRequestImpl) QueryResponse(ddf.catalog.operation.QueryResponse) ResourceNotFoundException(ddf.catalog.resource.ResourceNotFoundException)

Example 20 with ResourceNotFoundException

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;
}
Also used : Set(java.util.Set) QueryRequest(ddf.catalog.operation.QueryRequest) UnsupportedQueryException(ddf.catalog.source.UnsupportedQueryException) FederationException(ddf.catalog.federation.FederationException) Result(ddf.catalog.data.Result) Metacard(ddf.catalog.data.Metacard) QueryRequestImpl(ddf.catalog.operation.impl.QueryRequestImpl) QueryResponse(ddf.catalog.operation.QueryResponse) ResourceNotFoundException(ddf.catalog.resource.ResourceNotFoundException)

Aggregations

ResourceNotFoundException (ddf.catalog.resource.ResourceNotFoundException)41 IOException (java.io.IOException)25 ResourceResponse (ddf.catalog.operation.ResourceResponse)17 URI (java.net.URI)16 ResourceNotSupportedException (ddf.catalog.resource.ResourceNotSupportedException)14 Serializable (java.io.Serializable)14 Metacard (ddf.catalog.data.Metacard)13 Test (org.junit.Test)12 HashMap (java.util.HashMap)11 URISyntaxException (java.net.URISyntaxException)10 Result (ddf.catalog.data.Result)8 ResourceRequest (ddf.catalog.operation.ResourceRequest)8 QueryRequestImpl (ddf.catalog.operation.impl.QueryRequestImpl)8 ResourceRequestById (ddf.catalog.operation.impl.ResourceRequestById)7 Resource (ddf.catalog.resource.Resource)7 QueryRequest (ddf.catalog.operation.QueryRequest)6 QueryResponse (ddf.catalog.operation.QueryResponse)6 ResourceResponseImpl (ddf.catalog.operation.impl.ResourceResponseImpl)6 CatalogFramework (ddf.catalog.CatalogFramework)5 FederationException (ddf.catalog.federation.FederationException)5