Search in sources :

Example 71 with Attribute

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));
}
Also used : Attribute(ddf.catalog.data.Attribute) Test(org.junit.Test)

Example 72 with Attribute

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"));
}
Also used : Metacard(ddf.catalog.data.Metacard) Attribute(ddf.catalog.data.Attribute) QueryResponse(ddf.catalog.operation.QueryResponse) ArrayList(java.util.ArrayList) ResultImpl(ddf.catalog.data.impl.ResultImpl) ResourceCacheInterface(ddf.catalog.cache.ResourceCacheInterface) ReliableResource(ddf.catalog.resource.data.ReliableResource) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) Result(ddf.catalog.data.Result) Test(org.junit.Test)

Example 73 with Attribute

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;
}
Also used : Metacard(ddf.catalog.data.Metacard) Attribute(ddf.catalog.data.Attribute) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) Attachment(org.apache.cxf.jaxrs.ext.multipart.Attachment) IOException(java.io.IOException) MetacardImpl(ddf.catalog.data.impl.MetacardImpl)

Example 74 with Attribute

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;
}
Also used : KeyValueCollectionPermission(ddf.security.permission.KeyValueCollectionPermission) Attribute(ddf.catalog.data.Attribute) FilterStrategy(ddf.catalog.security.FilterStrategy) StopProcessingException(ddf.catalog.plugin.StopProcessingException) FilterResult(ddf.catalog.security.FilterResult) Subject(org.apache.shiro.subject.Subject)

Example 75 with Attribute

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)));
}
Also used : Attribute(ddf.catalog.data.Attribute) AttributeImpl(ddf.catalog.data.impl.AttributeImpl) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List) Date(java.util.Date) Test(org.junit.Test)

Aggregations

Attribute (ddf.catalog.data.Attribute)103 Metacard (ddf.catalog.data.Metacard)39 Test (org.junit.Test)37 ArrayList (java.util.ArrayList)30 AttributeImpl (ddf.catalog.data.impl.AttributeImpl)29 AttributeDescriptor (ddf.catalog.data.AttributeDescriptor)26 Serializable (java.io.Serializable)23 MetacardImpl (ddf.catalog.data.impl.MetacardImpl)15 HashMap (java.util.HashMap)15 Result (ddf.catalog.data.Result)14 List (java.util.List)14 MetacardType (ddf.catalog.data.MetacardType)11 QueryResponse (ddf.catalog.operation.QueryResponse)11 Date (java.util.Date)11 Map (java.util.Map)11 HashSet (java.util.HashSet)10 Optional (java.util.Optional)8 Set (java.util.Set)8 Filter (org.opengis.filter.Filter)8 UpdateRequestImpl (ddf.catalog.operation.impl.UpdateRequestImpl)7