Search in sources :

Example 1 with DownloadToLocalSiteException

use of org.codice.ddf.catalog.resource.download.DownloadToLocalSiteException in project ddf by codice.

the class ResourceDownload method copyToLocalSite.

@Override
public void copyToLocalSite(String sourceId, String metacardId) throws MBeanException {
    LOGGER.debug("Downloading resource associated with metacard id [{}] from source [{}] to the local site.", metacardId, sourceId);
    ResourceRequest resourceRequest = new ResourceRequestById(metacardId);
    if (!resourceCacheMBean.isCacheEnabled()) {
        String message = "Caching of resources is not enabled.";
        LOGGER.info(message);
        throw new MBeanException(new DownloadToLocalSiteException(Status.BAD_REQUEST, message), message);
    }
    try {
        LOGGER.debug("Attempting to download the resource associated with metacard [{}] from source [{}] to the local site.", metacardId, sourceId);
        ResourceResponse resourceResponse = catalogFramework.getResource(resourceRequest, sourceId);
        if (resourceResponse == null) {
            String message = String.format(ERROR_MESSAGE_TEMPLATE, metacardId, sourceId);
            LOGGER.debug(message);
            throw new MBeanException(new DownloadToLocalSiteException(Status.INTERNAL_SERVER_ERROR, message), message);
        }
    } catch (IOException | ResourceNotSupportedException e) {
        String message = String.format(ERROR_MESSAGE_TEMPLATE, metacardId, sourceId);
        LOGGER.debug(message, e);
        throw new MBeanException(new DownloadToLocalSiteException(Status.INTERNAL_SERVER_ERROR, message), message);
    } catch (ResourceNotFoundException e) {
        String message = String.format(ERROR_MESSAGE_TEMPLATE, metacardId, sourceId) + " The resource could not be found.";
        LOGGER.debug(message, e);
        throw new MBeanException(new DownloadToLocalSiteException(Status.NOT_FOUND, message), message);
    }
}
Also used : ResourceResponse(ddf.catalog.operation.ResourceResponse) ResourceNotSupportedException(ddf.catalog.resource.ResourceNotSupportedException) ResourceRequestById(ddf.catalog.operation.impl.ResourceRequestById) NotCompliantMBeanException(javax.management.NotCompliantMBeanException) MBeanException(javax.management.MBeanException) ResourceRequest(ddf.catalog.operation.ResourceRequest) DownloadToLocalSiteException(org.codice.ddf.catalog.resource.download.DownloadToLocalSiteException) IOException(java.io.IOException) ResourceNotFoundException(ddf.catalog.resource.ResourceNotFoundException)

Example 2 with DownloadToLocalSiteException

use of org.codice.ddf.catalog.resource.download.DownloadToLocalSiteException in project ddf by codice.

the class ResourceDownloadActionEndpointTest method getDownloadToLocalSiteExceptionWrappedInMBeanException.

private MBeanException getDownloadToLocalSiteExceptionWrappedInMBeanException() {
    String message = "exception message";
    DownloadToLocalSiteException downloadToCacheException = new DownloadToLocalSiteException(Status.INTERNAL_SERVER_ERROR, message);
    MBeanException mBeanException = new MBeanException(downloadToCacheException, message);
    return mBeanException;
}
Also used : MBeanException(javax.management.MBeanException) DownloadToLocalSiteException(org.codice.ddf.catalog.resource.download.DownloadToLocalSiteException)

Aggregations

MBeanException (javax.management.MBeanException)2 DownloadToLocalSiteException (org.codice.ddf.catalog.resource.download.DownloadToLocalSiteException)2 ResourceRequest (ddf.catalog.operation.ResourceRequest)1 ResourceResponse (ddf.catalog.operation.ResourceResponse)1 ResourceRequestById (ddf.catalog.operation.impl.ResourceRequestById)1 ResourceNotFoundException (ddf.catalog.resource.ResourceNotFoundException)1 ResourceNotSupportedException (ddf.catalog.resource.ResourceNotSupportedException)1 IOException (java.io.IOException)1 NotCompliantMBeanException (javax.management.NotCompliantMBeanException)1