Search in sources :

Example 56 with AttributeImpl

use of ddf.catalog.data.impl.AttributeImpl in project ddf by codice.

the class PptxInputTransformer method extractThumbnail.

/**
     * SlideShowFactory.create() will perform the tests for password protected files.
     * <p/>
     * Because Apache POI dynamically loads the classes needed to handle a PPTX file, the default
     * class loader is unable to find the dependencies during runtime. Therefore, the original class
     * loader is saved, then current class loader is set to this class's class loader, and finally
     * the original class loader is restored.
     *
     * @param metacard
     * @param input
     * @throws IOException
     */
private void extractThumbnail(Metacard metacard, InputStream input) throws IOException {
    ClassLoader originalContextClassLoader = Thread.currentThread().getContextClassLoader();
    try {
        Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
        SlideShow<?, ?> genericSlideShow = SlideShowFactory.create(input);
        if (genericSlideShow instanceof XMLSlideShow) {
            XMLSlideShow xmlSlideShow = (XMLSlideShow) genericSlideShow;
            byte[] thumbnail = generatePptxThumbnail(xmlSlideShow);
            if (thumbnail != null) {
                metacard.setAttribute(new AttributeImpl(Metacard.THUMBNAIL, thumbnail));
            }
        } else {
            LOGGER.debug("Cannot transform old style (OLE2) ppt : id = {}", metacard.getId());
        }
    } finally {
        Thread.currentThread().setContextClassLoader(originalContextClassLoader);
    }
}
Also used : XMLSlideShow(org.apache.poi.xslf.usermodel.XMLSlideShow) AttributeImpl(ddf.catalog.data.impl.AttributeImpl)

Example 57 with AttributeImpl

use of ddf.catalog.data.impl.AttributeImpl in project ddf by codice.

the class TestDuplicationValidator method setup.

@Before
public void setup() throws UnsupportedQueryException, SourceUnavailableException, FederationException {
    QueryResponse response = mock(QueryResponse.class);
    when(mockFramework.query(any(QueryRequest.class))).thenReturn(response);
    testMetacard = new MetacardImpl();
    matchingMetacard = new MetacardImpl();
    matchingMetacard.setId(ID);
    testMetacard.setId("test metacard ID");
    matchingMetacard.setAttribute(new AttributeImpl(Metacard.CHECKSUM, "checksum-value"));
    testMetacard.setAttribute(new AttributeImpl(Metacard.CHECKSUM, "checksum-value"));
    matchingMetacard.setTags(tags);
    testMetacard.setTags(tags);
    List<Result> results = Arrays.asList(new ResultImpl(matchingMetacard));
    when(response.getResults()).thenReturn(results);
    validator = new DuplicationValidator(mockFramework, mockFilterBuilder);
}
Also used : QueryRequest(ddf.catalog.operation.QueryRequest) QueryResponse(ddf.catalog.operation.QueryResponse) AttributeImpl(ddf.catalog.data.impl.AttributeImpl) ResultImpl(ddf.catalog.data.impl.ResultImpl) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) Result(ddf.catalog.data.Result) Before(org.junit.Before)

Example 58 with AttributeImpl

use of ddf.catalog.data.impl.AttributeImpl in project ddf by codice.

the class HistorianTest method getMetacardUpdatePair.

private List<Metacard> getMetacardUpdatePair() {
    Metacard old = new MetacardImpl();
    old.setAttribute(new AttributeImpl(Metacard.ID, METACARD_ID));
    old.setAttribute(new AttributeImpl(Metacard.RESOURCE_URI, RESOURCE_URI));
    Metacard update = new MetacardImpl();
    update.setAttribute(new AttributeImpl(Metacard.ID, METACARD_ID));
    update.setAttribute(new AttributeImpl(Metacard.RESOURCE_URI, RESOURCE_URI));
    update.setAttribute(new AttributeImpl(Metacard.DESCRIPTION, UPDATE_DESCRIPTION));
    return Arrays.asList(old, update);
}
Also used : DeletedMetacard(ddf.catalog.core.versioning.DeletedMetacard) Metacard(ddf.catalog.data.Metacard) AttributeImpl(ddf.catalog.data.impl.AttributeImpl) DeletedMetacardImpl(ddf.catalog.core.versioning.impl.DeletedMetacardImpl) MetacardImpl(ddf.catalog.data.impl.MetacardImpl)

Example 59 with AttributeImpl

use of ddf.catalog.data.impl.AttributeImpl in project ddf by codice.

the class QueryOperations method populateQueryResponsePolicyMap.

private QueryResponse populateQueryResponsePolicyMap(QueryResponse queryResponse) throws FederationException {
    HashMap<String, Set<String>> responsePolicyMap = new HashMap<>();
    Map<String, Serializable> unmodifiableProperties = Collections.unmodifiableMap(queryResponse.getProperties());
    for (Result result : queryResponse.getResults()) {
        HashMap<String, Set<String>> itemPolicyMap = new HashMap<>();
        for (PolicyPlugin plugin : frameworkProperties.getPolicyPlugins()) {
            try {
                PolicyResponse policyResponse = plugin.processPostQuery(result, unmodifiableProperties);
                opsSecuritySupport.buildPolicyMap(itemPolicyMap, policyResponse.itemPolicy().entrySet());
                opsSecuritySupport.buildPolicyMap(responsePolicyMap, policyResponse.operationPolicy().entrySet());
            } catch (StopProcessingException e) {
                throw new FederationException("Query could not be executed.", e);
            }
        }
        result.getMetacard().setAttribute(new AttributeImpl(Metacard.SECURITY, itemPolicyMap));
    }
    queryResponse.getProperties().put(PolicyPlugin.OPERATION_SECURITY, responsePolicyMap);
    return queryResponse;
}
Also used : Serializable(java.io.Serializable) Set(java.util.Set) HashSet(java.util.HashSet) HashMap(java.util.HashMap) AttributeImpl(ddf.catalog.data.impl.AttributeImpl) PolicyPlugin(ddf.catalog.plugin.PolicyPlugin) StopProcessingException(ddf.catalog.plugin.StopProcessingException) FederationException(ddf.catalog.federation.FederationException) PolicyResponse(ddf.catalog.plugin.PolicyResponse) Result(ddf.catalog.data.Result)

Example 60 with AttributeImpl

use of ddf.catalog.data.impl.AttributeImpl in project ddf by codice.

the class CachedResourceMetacardComparatorTest method createMetacard.

private MetacardImpl createMetacard(String metacardId, Instant createdDate, Instant effectiveDate, Instant expireDate, Instant modDate) throws Exception {
    String locWkt = "POLYGON ((30 10, 10 20, 20 40, 40 40, 30 10))";
    URI nsUri = new URI("http://" + CachedResourceMetacardComparatorTest.class.getName());
    URI resourceUri = new URI(nsUri.toString() + "/resource1.png");
    URI derivedResourceUri = new URI(nsUri.toString() + "/derived.png");
    URL deriverResourceUrl = derivedResourceUri.toURL();
    HashMap<String, List<String>> securityMap = new HashMap<>();
    securityMap.put("key1", ImmutableList.of("value1"));
    securityMap.put("key2", ImmutableList.of("value1", "value2"));
    MetacardImpl metacard = new MetacardImpl(BasicTypes.BASIC_METACARD);
    metacard.setContentTypeName("testContentType");
    metacard.setContentTypeVersion("testContentTypeVersion");
    metacard.setCreatedDate(Date.from(createdDate));
    metacard.setDescription("testDescription");
    metacard.setEffectiveDate(Date.from(effectiveDate));
    metacard.setExpirationDate(Date.from(expireDate));
    metacard.setId(metacardId);
    metacard.setLocation(locWkt);
    metacard.setMetadata("testMetadata");
    metacard.setModifiedDate(Date.from(modDate));
    metacard.setPointOfContact("pointOfContact");
    metacard.setResourceURI(resourceUri);
    metacard.setSourceId("testSourceId");
    metacard.setTargetNamespace(nsUri);
    metacard.setThumbnail(new byte[] { 1, 2, 3, 4, 5 });
    metacard.setTitle("testTitle");
    metacard.setResourceSize("1");
    metacard.setSecurity(securityMap);
    metacard.setTags(ImmutableSet.of("tag1", "tag2"));
    metacard.setAttribute(Metacard.CHECKSUM, "1");
    metacard.setAttribute(new AttributeImpl(Metacard.CHECKSUM_ALGORITHM, "sha1"));
    metacard.setAttribute(new AttributeImpl(Metacard.DEFAULT_TAG, "tag1"));
    metacard.setAttribute(new AttributeImpl(Metacard.DERIVED, "derivedMetacard"));
    metacard.setAttribute(new AttributeImpl(Metacard.DERIVED_RESOURCE_DOWNLOAD_URL, deriverResourceUrl));
    metacard.setAttribute(new AttributeImpl(Metacard.DERIVED_RESOURCE_URI, derivedResourceUri));
    metacard.setAttribute(new AttributeImpl(Metacard.RELATED, "otherMetacardId"));
    return metacard;
}
Also used : HashMap(java.util.HashMap) AttributeImpl(ddf.catalog.data.impl.AttributeImpl) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) URI(java.net.URI) URL(java.net.URL) MetacardImpl(ddf.catalog.data.impl.MetacardImpl)

Aggregations

AttributeImpl (ddf.catalog.data.impl.AttributeImpl)181 Metacard (ddf.catalog.data.Metacard)109 Test (org.junit.Test)75 ArrayList (java.util.ArrayList)56 MetacardImpl (ddf.catalog.data.impl.MetacardImpl)49 Serializable (java.io.Serializable)30 Date (java.util.Date)30 Attribute (ddf.catalog.data.Attribute)29 List (java.util.List)23 HashMap (java.util.HashMap)20 IOException (java.io.IOException)18 InputStream (java.io.InputStream)17 Result (ddf.catalog.data.Result)15 HashSet (java.util.HashSet)15 PolicyResponse (ddf.catalog.plugin.PolicyResponse)14 ResultImpl (ddf.catalog.data.impl.ResultImpl)11 UpdateRequestImpl (ddf.catalog.operation.impl.UpdateRequestImpl)11 Set (java.util.Set)11 ContentItem (ddf.catalog.content.data.ContentItem)10 QueryResponse (ddf.catalog.operation.QueryResponse)10