use of ddf.catalog.data.Attribute in project ddf by codice.
the class MetacardResourceStatusTest method testMetacardResourceIsNotLocal2.
/**
* Metacard source id is local, Metacard contains remote resource uri, Metacard resource is not
* cached
*/
@Test
public void testMetacardResourceIsNotLocal2() throws Exception {
setupCache(false);
setupSingleResultResponseMock(getBasicMetacard(LOCAL_SITE_NAME, REMOTE_RESOURCE_URI));
MetacardResourceStatus plugin = getMetacardResourceStatusPlugin();
Attribute resourceStatusAttribute = getInternalLocalResurceAttribute(plugin.process(queryResponse));
assertThat(resourceStatusAttribute.getValue(), is(false));
}
use of ddf.catalog.data.Attribute in project ddf by codice.
the class TestMetacardResourceSizePlugin method testMetacardResourceSizePopulatedAndHasProduct.
@Test
public void testMetacardResourceSizePopulatedAndHasProduct() throws Exception {
ResourceCacheInterface cache = mock(ResourceCacheInterface.class);
ReliableResource cachedResource = mock(ReliableResource.class);
when(cachedResource.getSize()).thenReturn(999L);
when(cachedResource.hasProduct()).thenReturn(true);
when(cache.getValid(anyString(), (Metacard) anyObject())).thenReturn(cachedResource);
MetacardImpl metacard = new MetacardImpl();
metacard.setId("abc123");
metacard.setSourceId("ddf-1");
metacard.setResourceSize("N/A");
Result result = new ResultImpl(metacard);
List<Result> results = new ArrayList<Result>();
results.add(result);
QueryResponse input = mock(QueryResponse.class);
when(input.getResults()).thenReturn(results);
MetacardResourceSizePlugin plugin = new MetacardResourceSizePlugin(cache);
QueryResponse queryResponse = plugin.process(input);
assertThat(queryResponse.getResults().size(), is(1));
Metacard resultMetacard = queryResponse.getResults().get(0).getMetacard();
assertThat(metacard, is(notNullValue()));
// Since using Metacard vs. MetacardImpl have to get resource-size as an
// Attribute vs. Long
Attribute resourceSizeAttr = resultMetacard.getAttribute(Metacard.RESOURCE_SIZE);
assertThat((String) resourceSizeAttr.getValue(), is("999"));
}
use of ddf.catalog.data.Attribute in project ddf by codice.
the class RESTEndpoint method parseAttachments.
CreateInfo parseAttachments(List<Attachment> contentParts, String transformerParam) {
if (contentParts.size() == 1) {
Attachment contentPart = contentParts.get(0);
return parseAttachment(contentPart);
}
List<Attribute> attributes = new ArrayList<>(contentParts.size());
Metacard metacard = null;
CreateInfo createInfo = null;
for (Attachment attachment : contentParts) {
String name = attachment.getContentDisposition().getParameter("name");
String parsedName = (name.startsWith("parse.")) ? name.substring(6) : name;
try {
InputStream inputStream = attachment.getDataHandler().getInputStream();
if (name.equals("parse.resource")) {
createInfo = parseAttachment(attachment);
} else if (name.equals("parse.metadata")) {
metacard = parseMetadata(transformerParam, metacard, attachment, inputStream);
} else {
parseOverrideAttributes(attributes, parsedName, inputStream);
}
} catch (IOException e) {
LOGGER.debug("Unable to get input stream for mime attachment. Ignoring override attribute: {}", name, e);
}
}
if (createInfo == null) {
throw new IllegalArgumentException("No parse.resource specified in request.");
}
if (metacard == null) {
metacard = new MetacardImpl();
}
for (Attribute attribute : attributes) {
metacard.setAttribute(attribute);
}
createInfo.setMetacard(metacard);
return createInfo;
}
use of ddf.catalog.data.Attribute in project ddf by codice.
the class FilterPlugin method processPostResource.
@Override
public ResourceResponse processPostResource(ResourceResponse input, Metacard metacard) throws StopProcessingException {
if (input.getRequest() == null || input.getRequest().getProperties() == null) {
throw new StopProcessingException("Unable to filter contents of current message, no user Subject available.");
}
KeyValueCollectionPermission securityPermission = new KeyValueCollectionPermission(CollectionPermission.READ_ACTION);
Subject subject = getSubject(input);
Attribute attr = metacard.getAttribute(Metacard.SECURITY);
if (!checkPermissions(attr, securityPermission, subject, CollectionPermission.READ_ACTION)) {
for (FilterStrategy filterStrategy : filterStrategies.values()) {
FilterResult filterResult = filterStrategy.process(input, metacard);
if (filterResult.processed()) {
if (filterResult.response() == null) {
throw new StopProcessingException("Subject not permitted to receive resource");
} else {
input = (ResourceResponse) filterResult.response();
}
break;
//returned metacards are ignored for resource requests
}
}
if (filterStrategies.size() == 0) {
throw new StopProcessingException("Subject not permitted to receive resource");
}
}
return input;
}
use of ddf.catalog.data.Attribute in project ddf by codice.
the class RegistryPublicationServiceImplTest method testPublishAlreadyPublished.
@Test
public void testPublishAlreadyPublished() throws Exception {
String publishThisRegistryId = "publishThisRegistryId";
Date now = new Date();
Date before = new Date(now.getTime() - 100000);
Attribute publishedLocationsAttribute = new AttributeImpl(RegistryObjectMetacardType.PUBLISHED_LOCATIONS, Collections.singletonList(REGISTRY_STORE_REGISTRY_ID));
metacard.setAttribute(publishedLocationsAttribute);
metacard.setAttribute(new AttributeImpl(RegistryObjectMetacardType.LAST_PUBLISHED, before));
when(federationAdminService.getRegistryMetacardsByRegistryIds(any(List.class))).thenReturn(Collections.singletonList(metacard));
registryPublicationService.publish(publishThisRegistryId, REGISTRY_STORE_REGISTRY_ID);
verify(federationAdminService, never()).addRegistryEntry(metacard, Collections.singleton(REGISTRY_STORE_REGISTRY_ID));
verify(federationAdminService, never()).updateRegistryEntry(metacard);
Attribute publicationsAfter = metacard.getAttribute(RegistryObjectMetacardType.PUBLISHED_LOCATIONS);
assertThat(publicationsAfter, is(equalTo(publishedLocationsAttribute)));
Attribute lastPublished = metacard.getAttribute(RegistryObjectMetacardType.LAST_PUBLISHED);
assertThat(lastPublished, notNullValue());
Date lastPublishedDate = (Date) lastPublished.getValue();
assertThat(lastPublishedDate, is(equalTo(before)));
}
Aggregations