Search in sources :

Example 16 with ResourceRequest

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

the class TestResourceUsagePlugin method testPreResourceLocalSourceSizeNotFound.

@Test
public void testPreResourceLocalSourceSizeNotFound() throws PersistenceException, PluginExecutionException, StopProcessingException {
    ResourceRequest originalRequest = getMockLocalResourceRequest(null, TEST_USER);
    ResourceRequest request = plugin.process(originalRequest);
    assertThat(request, is(notNullValue()));
    assertThat(request, is(originalRequest));
    verify(attributeStore, never()).getDataLimitByUser(anyString());
    verify(attributeStore, never()).getCurrentDataUsageByUser(anyString());
}
Also used : ResourceRequest(ddf.catalog.operation.ResourceRequest) Test(org.junit.Test)

Example 17 with ResourceRequest

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

the class TestResourceUsagePlugin method testPreResourceNoSubject.

@Test
public void testPreResourceNoSubject() throws StopProcessingException, PluginExecutionException, PersistenceException {
    ResourceRequest originalRequest = getMockResourceRequestNoSubject(RESOURCE_SIZE);
    ResourceRequest request = plugin.process(originalRequest);
    assertThat(request, is(notNullValue()));
    assertThat(request, is(originalRequest));
    verify(attributeStore, never()).getDataLimitByUser(anyString());
    verify(attributeStore, never()).getCurrentDataUsageByUser(anyString());
}
Also used : ResourceRequest(ddf.catalog.operation.ResourceRequest) Test(org.junit.Test)

Example 18 with ResourceRequest

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

the class TestResourceUsagePlugin method getMockResourceRequestNoSubject.

private ResourceRequest getMockResourceRequestNoSubject(String resourceSize) {
    ResourceRequest resourceRequest = getMockResourceRequest(resourceSize, null);
    when(resourceRequest.getPropertyValue(SecurityConstants.SECURITY_SUBJECT)).thenReturn(null);
    return resourceRequest;
}
Also used : ResourceRequest(ddf.catalog.operation.ResourceRequest)

Example 19 with ResourceRequest

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

the class TestResourceUsagePlugin method testPreResourceLocalSourceInvalidSize.

@Test
public void testPreResourceLocalSourceInvalidSize() throws StopProcessingException, PluginExecutionException, PersistenceException {
    ResourceRequest originalRequest = getMockLocalResourceRequest("47 bytes", TEST_USER);
    ResourceRequest request = plugin.process(originalRequest);
    assertThat(request, is(notNullValue()));
    assertThat(request, is(originalRequest));
    verify(attributeStore, never()).getDataLimitByUser(anyString());
    verify(attributeStore, never()).getCurrentDataUsageByUser(anyString());
}
Also used : ResourceRequest(ddf.catalog.operation.ResourceRequest) Test(org.junit.Test)

Example 20 with ResourceRequest

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

the class ProcessingPostIngestPlugin method getProcessResource.

private ProcessResource getProcessResource(Metacard metacard, Subject subject) {
    LOGGER.trace("Attempting to retrieve process resource metacard with id \"{}\" and sourceId \"{}\".", metacard.getId(), metacard.getSourceId());
    ResourceRequest request = new ResourceRequestById(metacard.getId());
    if (subject == null) {
        LOGGER.debug("No available subject to fetch metacard resource. Returning null");
        return null;
    }
    return subject.execute(() -> {
        try {
            ResourceResponse response = catalogFramework.getResource(request, metacard.getSourceId());
            Resource resource = response.getResource();
            ProcessResource processResource = new ProcessResourceImpl(metacard.getId(), resource.getInputStream(), resource.getMimeTypeValue(), resource.getName(), resource.getSize(), false);
            return processResource;
        } catch (IOException | ResourceNotFoundException | ResourceNotSupportedException | RuntimeException e) {
            LOGGER.debug("Unable to get resource id:{}, sourceId:{}. Returning null", metacard.getId(), metacard.getSourceId(), e);
        }
        return null;
    });
}
Also used : ResourceResponse(ddf.catalog.operation.ResourceResponse) ResourceNotSupportedException(ddf.catalog.resource.ResourceNotSupportedException) ResourceRequestById(ddf.catalog.operation.impl.ResourceRequestById) Resource(ddf.catalog.resource.Resource) ProcessResource(org.codice.ddf.catalog.async.data.api.internal.ProcessResource) ProcessResource(org.codice.ddf.catalog.async.data.api.internal.ProcessResource) ResourceRequest(ddf.catalog.operation.ResourceRequest) IOException(java.io.IOException) ResourceNotFoundException(ddf.catalog.resource.ResourceNotFoundException) ProcessResourceImpl(org.codice.ddf.catalog.async.data.impl.ProcessResourceImpl)

Aggregations

ResourceRequest (ddf.catalog.operation.ResourceRequest)34 Test (org.junit.Test)20 ResourceResponse (ddf.catalog.operation.ResourceResponse)11 Metacard (ddf.catalog.data.Metacard)10 Resource (ddf.catalog.resource.Resource)7 Serializable (java.io.Serializable)7 HashMap (java.util.HashMap)7 ResourceRequestById (ddf.catalog.operation.impl.ResourceRequestById)6 ResourceNotFoundException (ddf.catalog.resource.ResourceNotFoundException)6 ResourceNotSupportedException (ddf.catalog.resource.ResourceNotSupportedException)6 IOException (java.io.IOException)6 Matchers.anyString (org.mockito.Matchers.anyString)6 QueryRequest (ddf.catalog.operation.QueryRequest)5 ResourceRetriever (ddf.catalog.resourceretriever.ResourceRetriever)5 Result (ddf.catalog.data.Result)4 DeleteRequest (ddf.catalog.operation.DeleteRequest)4 QueryResponse (ddf.catalog.operation.QueryResponse)4 MimeType (javax.activation.MimeType)4 Subject (ddf.security.Subject)3 ArrayList (java.util.ArrayList)3