Search in sources :

Example 71 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 72 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)

Example 73 with AttributeImpl

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

the class RESTEndpoint method generateMetacard.

private Metacard generateMetacard(MimeType mimeType, String id, InputStream message, String transformerId) throws MetacardCreationException {
    Metacard generatedMetacard = null;
    List<InputTransformer> listOfCandidates = mimeTypeToTransformerMapper.findMatches(InputTransformer.class, mimeType);
    List<String> stackTraceList = new ArrayList<>();
    LOGGER.trace("Entering generateMetacard.");
    LOGGER.debug("List of matches for mimeType [{}]: {}", mimeType, listOfCandidates);
    try (TemporaryFileBackedOutputStream fileBackedOutputStream = new TemporaryFileBackedOutputStream()) {
        try {
            if (null != message) {
                IOUtils.copy(message, fileBackedOutputStream);
            } else {
                throw new MetacardCreationException("Could not copy bytes of content message.  Message was NULL.");
            }
        } catch (IOException e) {
            throw new MetacardCreationException("Could not copy bytes of content message.", e);
        }
        Iterator<InputTransformer> it = listOfCandidates.iterator();
        if (StringUtils.isNotEmpty(transformerId)) {
            BundleContext bundleContext = getBundleContext();
            Collection<ServiceReference<InputTransformer>> serviceReferences = bundleContext.getServiceReferences(InputTransformer.class, "(id=" + transformerId + ")");
            it = serviceReferences.stream().map(bundleContext::getService).iterator();
        }
        while (it.hasNext()) {
            InputTransformer transformer = it.next();
            try (InputStream inputStreamMessageCopy = fileBackedOutputStream.asByteSource().openStream()) {
                generatedMetacard = transformer.transform(inputStreamMessageCopy);
            } catch (CatalogTransformerException | IOException e) {
                List<String> stackTraces = Arrays.asList(ExceptionUtils.getRootCauseStackTrace(e));
                stackTraceList.add(String.format("Transformer [%s] could not create metacard.", transformer));
                stackTraceList.addAll(stackTraces);
                LOGGER.debug("Transformer [{}] could not create metacard.", transformer, e);
            }
            if (generatedMetacard != null) {
                break;
            }
        }
        if (generatedMetacard == null) {
            throw new MetacardCreationException(String.format("Could not create metacard with mimeType %s : %s", mimeType, StringUtils.join(stackTraceList, "\n")));
        }
        if (id != null) {
            generatedMetacard.setAttribute(new AttributeImpl(Metacard.ID, id));
        } else {
            LOGGER.debug("Metacard had a null id");
        }
    } catch (IOException e) {
        throw new MetacardCreationException("Could not create metacard.", e);
    } catch (InvalidSyntaxException e) {
        throw new MetacardCreationException("Could not determine transformer", e);
    }
    return generatedMetacard;
}
Also used : MetacardCreationException(ddf.catalog.data.MetacardCreationException) TemporaryFileBackedOutputStream(org.codice.ddf.platform.util.TemporaryFileBackedOutputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) AttributeImpl(ddf.catalog.data.impl.AttributeImpl) ArrayList(java.util.ArrayList) CatalogTransformerException(ddf.catalog.transform.CatalogTransformerException) IOException(java.io.IOException) InputTransformer(ddf.catalog.transform.InputTransformer) ServiceReference(org.osgi.framework.ServiceReference) Metacard(ddf.catalog.data.Metacard) ArrayList(java.util.ArrayList) List(java.util.List) InvalidSyntaxException(org.osgi.framework.InvalidSyntaxException) BundleContext(org.osgi.framework.BundleContext)

Example 74 with AttributeImpl

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

the class FederationAdminServiceImplTest method testGetRegistryObjectsWithEmptyMetadata.

@Test(expected = FederationAdminException.class)
public void testGetRegistryObjectsWithEmptyMetadata() throws Exception {
    Metacard metacard = getTestMetacard();
    metacard.setAttribute(new AttributeImpl(Metacard.METADATA, ""));
    QueryRequest request = getTestQueryRequest();
    QueryResponse response = getPopulatedTestQueryResponse(request, metacard);
    when(catalogFramework.query(any(QueryRequest.class))).thenReturn(response);
    federationAdminServiceImpl.getRegistryObjects();
    verify(catalogFramework).query(any(QueryRequest.class));
    verify(parser, never()).unmarshal(any(ParserConfigurator.class), eq(JAXBElement.class), any(InputStream.class));
}
Also used : ParserConfigurator(org.codice.ddf.parser.ParserConfigurator) Metacard(ddf.catalog.data.Metacard) QueryRequest(ddf.catalog.operation.QueryRequest) InputStream(java.io.InputStream) AttributeImpl(ddf.catalog.data.impl.AttributeImpl) QueryResponse(ddf.catalog.operation.QueryResponse) JAXBElement(javax.xml.bind.JAXBElement) Test(org.junit.Test)

Example 75 with AttributeImpl

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

the class FederationAdminServiceImplTest method testGetRegistryMetacards.

@Test
public void testGetRegistryMetacards() throws Exception {
    Metacard findThisMetacard = testMetacard;
    findThisMetacard.setAttribute(new AttributeImpl(RegistryObjectMetacardType.REGISTRY_IDENTITY_NODE, true));
    QueryRequest request = getTestQueryRequest();
    QueryResponse response = getPopulatedTestQueryResponse(request, findThisMetacard, getTestMetacard());
    when(security.getSystemSubject()).thenReturn(subject);
    when(catalogFramework.query(any(QueryRequest.class))).thenReturn(response);
    List<Metacard> metacards = federationAdminServiceImpl.getRegistryMetacards();
    assertThat(metacards, hasSize(2));
}
Also used : Metacard(ddf.catalog.data.Metacard) QueryRequest(ddf.catalog.operation.QueryRequest) AttributeImpl(ddf.catalog.data.impl.AttributeImpl) QueryResponse(ddf.catalog.operation.QueryResponse) Test(org.junit.Test)

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