Search in sources :

Example 31 with ResourceResponse

use of ddf.catalog.operation.ResourceResponse 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 + " The resource could not be found.", metacardId, sourceId);
        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 32 with ResourceResponse

use of ddf.catalog.operation.ResourceResponse in project ddf by codice.

the class FilterPluginTest method testPluginFilterResourceNoStrategiesGood.

@Test
public void testPluginFilterResourceNoStrategiesGood() throws StopProcessingException {
    plugin = new FilterPlugin();
    ResourceResponse response = plugin.processPostResource(resourceResponse, getExactRolesMetacard());
}
Also used : FilterPlugin(ddf.catalog.security.filter.plugin.FilterPlugin) ResourceResponse(ddf.catalog.operation.ResourceResponse) Test(org.junit.Test)

Example 33 with ResourceResponse

use of ddf.catalog.operation.ResourceResponse in project ddf by codice.

the class TestResourceUsagePlugin method testPostResourceRemoteSourceNoRemoteDestinationKey.

@Test
public void testPostResourceRemoteSourceNoRemoteDestinationKey() throws Exception {
    plugin.setMonitorLocalSources(false);
    ResourceResponse originalResponse = getMockRemoteResourceResponseNoRemoteDestinationKey(RESOURCE_SIZE, TEST_USER);
    ResourceResponse response = plugin.process(originalResponse);
    assertThat(response, is(notNullValue()));
    assertThat(response, is(originalResponse));
    verify(attributeStore, never()).getDataLimitByUser(anyString());
    verify(attributeStore, never()).getCurrentDataUsageByUser(anyString());
}
Also used : ResourceResponse(ddf.catalog.operation.ResourceResponse) Test(org.junit.Test)

Example 34 with ResourceResponse

use of ddf.catalog.operation.ResourceResponse in project ddf by codice.

the class TestResourceUsagePlugin method testPostResourceNoSubject.

@Test
public void testPostResourceNoSubject() throws StopProcessingException, PluginExecutionException, PersistenceException {
    ResourceResponse originalResponse = getMockResourceResponseNoSubject(RESOURCE_SIZE);
    ResourceResponse response = plugin.process(originalResponse);
    assertThat(response, is(notNullValue()));
    assertThat(response, is(originalResponse));
    verify(attributeStore, never()).updateUserDataUsage(anyString(), anyLong());
}
Also used : ResourceResponse(ddf.catalog.operation.ResourceResponse) Test(org.junit.Test)

Example 35 with ResourceResponse

use of ddf.catalog.operation.ResourceResponse in project ddf by codice.

the class TestResourceUsagePlugin method testPostResourceLocalSourceSizeNotFound.

@Test
public void testPostResourceLocalSourceSizeNotFound() throws PersistenceException, PluginExecutionException, StopProcessingException {
    ResourceResponse resourceResponse = getMockLocalResourceResponse(null, TEST_USER);
    ResourceResponse request = plugin.process(resourceResponse);
    assertThat(request, is(notNullValue()));
    assertThat(request, is(resourceResponse));
    verify(attributeStore, never()).updateUserDataUsage(anyString(), anyLong());
}
Also used : ResourceResponse(ddf.catalog.operation.ResourceResponse) Test(org.junit.Test)

Aggregations

ResourceResponse (ddf.catalog.operation.ResourceResponse)71 Test (org.junit.Test)36 HashMap (java.util.HashMap)17 Resource (ddf.catalog.resource.Resource)16 URI (java.net.URI)16 Serializable (java.io.Serializable)15 Metacard (ddf.catalog.data.Metacard)13 IOException (java.io.IOException)13 MultivaluedHashMap (javax.ws.rs.core.MultivaluedHashMap)13 ResourceRequest (ddf.catalog.operation.ResourceRequest)12 ResourceNotFoundException (ddf.catalog.resource.ResourceNotFoundException)12 MimeType (javax.activation.MimeType)11 ResourceNotSupportedException (ddf.catalog.resource.ResourceNotSupportedException)10 Response (javax.ws.rs.core.Response)10 ResourceRequestById (ddf.catalog.operation.impl.ResourceRequestById)8 URLResourceReader (ddf.catalog.resource.impl.URLResourceReader)7 Matchers.anyString (org.mockito.Matchers.anyString)7 InputStream (java.io.InputStream)6 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)6 Matchers.containsString (org.hamcrest.Matchers.containsString)6