use of ddf.catalog.operation.impl.ResourceRequestById in project ddf by codice.
the class ResourceCacheImplTest method getSpecificResourceNotInCache.
@Test
public void getSpecificResourceNotInCache() {
Optional<Resource> optionalResource = newResourceCache.get(notCachedMetacard, new ResourceRequestById(NOT_CACHED_METACARD_ID));
assertFalse(optionalResource.isPresent());
}
use of ddf.catalog.operation.impl.ResourceRequestById in project ddf by codice.
the class MetacardApplication method revertContentandMetacard.
private void revertContentandMetacard(Metacard latestContent, Metacard versionMetacard, String id) throws SourceUnavailableException, IngestException, ResourceNotFoundException, IOException, ResourceNotSupportedException, FederationException, UnsupportedQueryException {
LOGGER.trace("Reverting content and metacard for metacard [{}]. \nLatest content: [{}] \nVersion metacard: [{}]", id, latestContent.getId(), versionMetacard.getId());
Map<String, Serializable> properties = new HashMap<>();
properties.put("no-default-tags", true);
ResourceResponse latestResource = catalogFramework.getLocalResource(new ResourceRequestById(latestContent.getId(), properties));
ContentItemImpl contentItem = new ContentItemImpl(id, new ByteSourceWrapper(() -> latestResource.getResource().getInputStream()), latestResource.getResource().getMimeTypeValue(), latestResource.getResource().getName(), latestResource.getResource().getSize(), MetacardVersionImpl.toMetacard(versionMetacard, types));
// Try to delete the "deleted metacard" marker first.
boolean alreadyCreated = false;
Action action = Action.fromKey((String) versionMetacard.getAttribute(MetacardVersion.ACTION).getValue());
if (DELETE_ACTIONS.contains(action)) {
alreadyCreated = true;
catalogFramework.create(new CreateStorageRequestImpl(Collections.singletonList(contentItem), id, new HashMap<>()));
} else {
// Currently we can't guarantee the metacard will exist yet because of the 1 second
// soft commit in solr. this busy wait loop should be fixed when alternate solution
// is found.
tryUpdate(4, () -> {
catalogFramework.update(new UpdateStorageRequestImpl(Collections.singletonList(contentItem), id, new HashMap<>()));
return true;
});
}
LOGGER.trace("Successfully reverted metacard content for [{}]", id);
revertMetacard(versionMetacard, id, alreadyCreated);
}
use of ddf.catalog.operation.impl.ResourceRequestById in project ddf by codice.
the class ZipCompression method getResource.
private Resource getResource(Metacard metacard) {
Resource resource = null;
try {
ResourceRequest resourceRequest = new ResourceRequestById(metacard.getId());
ResourceResponse resourceResponse = catalogFramework.getLocalResource(resourceRequest);
resource = resourceResponse.getResource();
} catch (IOException | ResourceNotFoundException | ResourceNotSupportedException e) {
LOGGER.debug("Unable to retrieve content from metacard : {}", metacard.getId(), e);
}
return resource;
}
use of ddf.catalog.operation.impl.ResourceRequestById in project ddf by codice.
the class SeedCommand method executeWithSubject.
@Override
protected Object executeWithSubject() throws Exception {
if (resourceLimit <= 0) {
printErrorMessage("A limit of " + resourceLimit + " was supplied. The limit must be greater than 0.");
return null;
}
final long start = System.currentTimeMillis();
int resourceDownloads = 0;
int downloadErrors = 0;
int pageCount = 0;
while (resourceDownloads < resourceLimit) {
final QueryImpl query = new QueryImpl(getFilter());
query.setPageSize(resourceLimit);
query.setStartIndex(pageCount * resourceLimit + 1);
++pageCount;
final QueryRequestImpl queryRequest;
if (isNotEmpty(sources)) {
queryRequest = new QueryRequestImpl(query, sources);
} else {
queryRequest = new QueryRequestImpl(query, true);
}
queryRequest.setProperties(new HashMap<>(CACHE_UPDATE_PROPERTIES));
final QueryResponse queryResponse = catalogFramework.query(queryRequest);
if (queryResponse.getResults().isEmpty()) {
break;
}
final List<Entry<? extends ResourceRequest, String>> resourceRequests = queryResponse.getResults().stream().map(Result::getMetacard).filter(isNonCachedResource).map(metacard -> new SimpleEntry<>(new ResourceRequestById(metacard.getId()), metacard.getSourceId())).collect(toList());
for (Entry<? extends ResourceRequest, String> requestAndSourceId : resourceRequests) {
final ResourceRequest request = requestAndSourceId.getKey();
try {
ResourceResponse response = catalogFramework.getResource(request, requestAndSourceId.getValue());
++resourceDownloads;
EXECUTOR.execute(new ResourceCloseHandler(response));
} catch (IOException | ResourceNotFoundException | ResourceNotSupportedException e) {
++downloadErrors;
LOGGER.debug("Could not download resource for metacard [id={}]", request.getAttributeValue(), e);
}
printProgressAndFlush(start, resourceLimit, resourceDownloads);
if (resourceDownloads == resourceLimit) {
break;
}
}
}
printProgressAndFlush(start, resourceDownloads, resourceDownloads);
console.println();
if (downloadErrors > 0) {
printErrorMessage(downloadErrors + " resource download(s) had errors. Check the logs for details.");
}
printSuccessMessage("Done seeding. " + resourceDownloads + " resource download(s) started.");
return null;
}
use of ddf.catalog.operation.impl.ResourceRequestById in project ddf by codice.
the class OperationPluginTest method testPluginWithRole.
private void testPluginWithRole(String role) throws Exception {
Map<String, Serializable> properties = new HashMap<>();
properties.put(SecurityConstants.SECURITY_SUBJECT, subject);
HashMap<String, Set<String>> perms = new HashMap<>();
Set<String> roles = new HashSet<>();
roles.add(role);
perms.put("Roles", roles);
properties.put(PolicyPlugin.OPERATION_SECURITY, perms);
CreateRequestImpl request = new CreateRequestImpl(new ArrayList<>(), properties);
QueryRequestImpl queryRequest = new QueryRequestImpl(mock(Query.class), properties);
UpdateRequestImpl updateRequest = new UpdateRequestImpl(new ArrayList<>(), "", properties);
DeleteRequestImpl deleteRequest = new DeleteRequestImpl(new String[] { "" }, properties);
ResourceRequestById resourceRequestById = new ResourceRequestById("", properties);
plugin.processPreCreate(request);
plugin.processPreQuery(queryRequest);
plugin.processPreUpdate(updateRequest, new HashMap<>());
plugin.processPreDelete(deleteRequest);
plugin.processPreResource(resourceRequestById);
}
Aggregations