use of ddf.catalog.operation.impl.ResourceRequestById in project ddf by codice.
the class XmlAttributeSecurityPolicyPluginTest method testProcessUnusedMethods.
@Test
public void testProcessUnusedMethods() throws StopProcessingException {
PolicyResponse policyResponse = plugin.processPreQuery(new QueryImpl(Filter.INCLUDE), new HashMap<>());
org.junit.Assert.assertThat(policyResponse.itemPolicy().entrySet().size(), Matchers.is(0));
policyResponse = plugin.processPreResource(new ResourceRequestById(""));
org.junit.Assert.assertThat(policyResponse.itemPolicy().entrySet().size(), Matchers.is(0));
}
use of ddf.catalog.operation.impl.ResourceRequestById in project ddf by codice.
the class MetacardResourceSizePlugin method process.
@Override
public QueryResponse process(QueryResponse input) throws PluginExecutionException, StopProcessingException {
List<Result> results = input.getResults();
for (Result result : results) {
Metacard metacard = result.getMetacard();
if (metacard != null) {
// Can only search cache based on Metacard - no way to generate ResourceRequest with
// any properties for use in generating the CacheKey
final ResourceRequest resourceRequest = new ResourceRequestById(metacard.getId());
CacheKey cacheKey;
String key = null;
ReliableResource cachedResource = null;
try {
cacheKey = new CacheKey(metacard, resourceRequest);
ClassLoader tccl = Thread.currentThread().getContextClassLoader();
key = cacheKey.generateKey();
try {
Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
cachedResource = (ReliableResource) cache.getValid(key, metacard);
} finally {
Thread.currentThread().setContextClassLoader(tccl);
}
} catch (IllegalArgumentException e) {
LOGGER.debug("Unable to retrieve cached resource for metacard id = {}", metacard.getId());
}
if (cachedResource != null) {
long resourceSize = cachedResource.getSize();
if (resourceSize > 0 && cachedResource.hasProduct()) {
LOGGER.debug("Setting resourceSize = {} for metacard ID = {}", resourceSize, metacard.getId());
Attribute resourceSizeAttribute = new AttributeImpl(Metacard.RESOURCE_SIZE, String.valueOf(resourceSize));
metacard.setAttribute(resourceSizeAttribute);
} else {
LOGGER.debug("resourceSize <= 0 for metacard ID = {}", metacard.getId());
}
} else {
LOGGER.debug("No cached resource for cache key = {}", key);
}
}
}
return input;
}
use of ddf.catalog.operation.impl.ResourceRequestById in project ddf by codice.
the class ResourceCacheImplTest method getSpecificResourceInCache.
@Test
public void getSpecificResourceInCache() {
ReliableResource cachedResource = createCachedResource(cachedMetacard);
resourceCache.put(cachedResource);
Optional<Resource> optionalResource = newResourceCache.get(cachedMetacard, new ResourceRequestById(METACARD_ID));
assertTrue(optionalResource.isPresent());
assertTrue(assertReliableResourceEquals(cachedResource, optionalResource.get()));
}
use of ddf.catalog.operation.impl.ResourceRequestById in project ddf by codice.
the class ResourceMetacardTransformer method transform.
@Override
public BinaryContent transform(Metacard metacard, Map<String, Serializable> arguments) throws CatalogTransformerException {
LOGGER.trace("Entering resource ResourceMetacardTransformer.transform");
if (!isValid(metacard)) {
throw new CatalogTransformerException("Could not transform metacard to a resource because the metacard is not valid.");
}
if (StringUtils.isNotEmpty(metacard.getResourceSize())) {
arguments.put(Metacard.RESOURCE_SIZE, metacard.getResourceSize());
}
String id = metacard.getId();
LOGGER.debug("executing resource request with id '{}'", id);
final ResourceRequest resourceRequest = new ResourceRequestById(id, arguments);
ResourceResponse resourceResponse = null;
String sourceName = metacard.getSourceId();
if (StringUtils.isBlank(sourceName)) {
sourceName = catalogFramework.getId();
}
String resourceUriAscii = "";
if (metacard.getResourceURI() != null) {
resourceUriAscii = metacard.getResourceURI().toASCIIString();
}
try {
resourceResponse = catalogFramework.getResource(resourceRequest, sourceName);
} catch (IOException e) {
throw new CatalogTransformerException(retrieveResourceFailureMessage(id, sourceName, resourceUriAscii, e.getMessage()), e);
} catch (ResourceNotFoundException e) {
throw new CatalogTransformerException(retrieveResourceFailureMessage(id, sourceName, resourceUriAscii, e.getMessage()), e);
} catch (ResourceNotSupportedException e) {
throw new CatalogTransformerException(retrieveResourceFailureMessage(id, sourceName, resourceUriAscii, e.getMessage()), e);
}
if (resourceResponse == null) {
throw new CatalogTransformerException(retrieveResourceFailureMessage(id, sourceName, resourceUriAscii));
}
Resource transformedContent = resourceResponse.getResource();
MimeType mimeType = transformedContent.getMimeType();
if (mimeType == null) {
try {
mimeType = new MimeType(DEFAULT_MIME_TYPE_STR);
// There is no method to set the MIME type, so in order to set it to our default
// one, we need to create a new object.
transformedContent = new ResourceImpl(transformedContent.getInputStream(), mimeType, transformedContent.getName());
} catch (MimeTypeParseException e) {
throw new CatalogTransformerException("Could not create default mime type upon null mimeType, for default mime type '" + DEFAULT_MIME_TYPE_STR + "'.", e);
}
}
LOGGER.debug("Found mime type: '{}' for product of metacard with id: '{}'.\nGetting associated resource from input stream. \n", mimeType, id);
LOGGER.trace("Exiting resource transform for metacard id: '{}'", id);
return transformedContent;
}
Aggregations