Search in sources :

Example 1 with AttributeImpl

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

the class Checksum method addChecksumAttributes.

private void addChecksumAttributes(Metacard metacard, final String checksumAlgorithm, final String checksumValue) {
    metacard.setAttribute(new AttributeImpl(Metacard.CHECKSUM_ALGORITHM, checksumAlgorithm));
    metacard.setAttribute(new AttributeImpl(Metacard.CHECKSUM, checksumValue));
}
Also used : AttributeImpl(ddf.catalog.data.impl.AttributeImpl)

Example 2 with AttributeImpl

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

the class Historian method setResourceUriForContent.

private void setResourceUriForContent(/*mutable*/
Map<String, Metacard> versionMetacards, CreateStorageResponse createStorageResponse) {
    for (ContentItem contentItem : createStorageResponse.getCreatedContentItems()) {
        Metacard metacard = versionMetacards.values().stream().filter(m -> contentItem.getId().equals(m.getId())).findFirst().orElse(null);
        if (metacard == null) {
            LOGGER.info("Could not find version metacard to set resource URI for (contentItem id: {})", contentItem.getId());
            continue;
        }
        metacard.setAttribute(new AttributeImpl(Metacard.RESOURCE_URI, contentItem.getUri()));
    }
}
Also used : Metacard(ddf.catalog.data.Metacard) AttributeImpl(ddf.catalog.data.impl.AttributeImpl) ContentItem(ddf.catalog.content.data.ContentItem)

Example 3 with AttributeImpl

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

the class MetacardVersionImpl method sanitizeVersionAttributes.

private static void sanitizeVersionAttributes(/*Mutable*/
Metacard source) {
    Consumer<String> nullifySourceAttribute = (s) -> source.setAttribute(new AttributeImpl(s, (Serializable) null));
    Sets.difference(VERSION_DESCRIPTORS, BasicTypes.BASIC_METACARD.getAttributeDescriptors()).stream().map(AttributeDescriptor::getName).forEach(nullifySourceAttribute);
}
Also used : MetacardTypeImpl(ddf.catalog.data.impl.MetacardTypeImpl) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Date(java.util.Date) URISyntaxException(java.net.URISyntaxException) ObjectInputStream(java.io.ObjectInputStream) LoggerFactory(org.slf4j.LoggerFactory) AttributeImpl(ddf.catalog.data.impl.AttributeImpl) Strings.isNullOrEmpty(com.google.common.base.Strings.isNullOrEmpty) Supplier(java.util.function.Supplier) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) MetacardVersion(ddf.catalog.core.versioning.MetacardVersion) ByteArrayInputStream(java.io.ByteArrayInputStream) Subject(org.apache.shiro.subject.Subject) Metacard(ddf.catalog.data.Metacard) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) AttributeDescriptorImpl(ddf.catalog.data.impl.AttributeDescriptorImpl) ObjectOutputStream(java.io.ObjectOutputStream) URI(java.net.URI) SubjectUtils(ddf.security.SubjectUtils) Nullable(javax.annotation.Nullable) Logger(org.slf4j.Logger) AttributeDescriptor(ddf.catalog.data.AttributeDescriptor) Set(java.util.Set) IOException(java.io.IOException) Instant(java.time.Instant) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) MetacardType(ddf.catalog.data.MetacardType) Serializable(java.io.Serializable) Consumer(java.util.function.Consumer) List(java.util.List) Attribute(ddf.catalog.data.Attribute) Optional(java.util.Optional) Collections(java.util.Collections) BasicTypes(ddf.catalog.data.impl.BasicTypes) Serializable(java.io.Serializable) AttributeImpl(ddf.catalog.data.impl.AttributeImpl)

Example 4 with AttributeImpl

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

the class CswEndpoint method updateRecords.

private int updateRecords(UpdateAction updateAction) throws CswException, FederationException, IngestException, SourceUnavailableException, UnsupportedQueryException {
    if (updateAction.getMetacard() != null) {
        Metacard newRecord = updateAction.getMetacard();
        if (newRecord.getId() != null) {
            UpdateRequest updateRequest = new UpdateRequestImpl(newRecord.getId(), newRecord);
            LOGGER.debug("Attempting to update {} ", newRecord.getId());
            UpdateResponse updateResponse = framework.update(updateRequest);
            return updateResponse.getUpdatedMetacards().size();
        } else {
            throw new CswException("Unable to update record.  No ID was specified in the request.", CswConstants.MISSING_PARAMETER_VALUE, updateAction.getHandle());
        }
    } else if (updateAction.getConstraint() != null) {
        QueryConstraintType constraint = updateAction.getConstraint();
        QueryRequest queryRequest = queryFactory.getQuery(constraint);
        queryRequest = queryFactory.updateQueryRequestTags(queryRequest, schemaTransformerManager.getTransformerSchemaForId(updateAction.getTypeName()));
        QueryResponse response = framework.query(queryRequest);
        if (response.getHits() > 0) {
            Map<String, Serializable> recordProperties = updateAction.getRecordProperties();
            List<String> updatedMetacardIdsList = new ArrayList<>();
            List<Metacard> updatedMetacards = new ArrayList<>();
            for (Result result : response.getResults()) {
                Metacard metacard = result.getMetacard();
                if (metacard != null) {
                    for (Entry<String, Serializable> recordProperty : recordProperties.entrySet()) {
                        Attribute attribute = new AttributeImpl(recordProperty.getKey(), recordProperty.getValue());
                        metacard.setAttribute(attribute);
                    }
                    updatedMetacardIdsList.add(metacard.getId());
                    updatedMetacards.add(metacard);
                }
            }
            if (updatedMetacardIdsList.size() > 0) {
                String[] updatedMetacardIds = updatedMetacardIdsList.toArray(new String[updatedMetacardIdsList.size()]);
                UpdateRequest updateRequest = new UpdateRequestImpl(updatedMetacardIds, updatedMetacards);
                LOGGER.debug("Attempting to update {} metacards.", updatedMetacardIdsList.size());
                UpdateResponse updateResponse = framework.update(updateRequest);
                return updateResponse.getUpdatedMetacards().size();
            }
        }
    }
    return 0;
}
Also used : QueryRequest(ddf.catalog.operation.QueryRequest) UpdateRequest(ddf.catalog.operation.UpdateRequest) Attribute(ddf.catalog.data.Attribute) AttributeImpl(ddf.catalog.data.impl.AttributeImpl) CswException(org.codice.ddf.spatial.ogc.csw.catalog.common.CswException) QueryConstraintType(net.opengis.cat.csw.v_2_0_2.QueryConstraintType) Result(ddf.catalog.data.Result) UpdateResponse(ddf.catalog.operation.UpdateResponse) Metacard(ddf.catalog.data.Metacard) Entry(java.util.Map.Entry) QueryResponse(ddf.catalog.operation.QueryResponse) ArrayList(java.util.ArrayList) List(java.util.List) LinkedList(java.util.LinkedList) UpdateRequestImpl(ddf.catalog.operation.impl.UpdateRequestImpl) Map(java.util.Map) HashMap(java.util.HashMap)

Example 5 with AttributeImpl

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

the class TestRegistryUtility method testInternalMetacardHasEmptyRegistryId.

@Test
public void testInternalMetacardHasEmptyRegistryId() {
    metacard.setAttribute(blankRegistryIdAttribute);
    tags.clear();
    tags.add(RegistryConstants.REGISTRY_TAG_INTERNAL);
    metacard.setAttribute(new AttributeImpl(Metacard.TAGS, tags));
    assertThat(RegistryUtility.isInternalRegistryMetacard(metacard), is(false));
}
Also used : AttributeImpl(ddf.catalog.data.impl.AttributeImpl) Test(org.junit.Test)

Aggregations

AttributeImpl (ddf.catalog.data.impl.AttributeImpl)244 Metacard (ddf.catalog.data.Metacard)123 Test (org.junit.Test)106 ArrayList (java.util.ArrayList)63 MetacardImpl (ddf.catalog.data.impl.MetacardImpl)59 Attribute (ddf.catalog.data.Attribute)56 Serializable (java.io.Serializable)37 Date (java.util.Date)36 List (java.util.List)30 HashMap (java.util.HashMap)22 IOException (java.io.IOException)18 InputStream (java.io.InputStream)18 ResultImpl (ddf.catalog.data.impl.ResultImpl)17 Result (ddf.catalog.data.Result)16 HashSet (java.util.HashSet)16 PolicyResponse (ddf.catalog.plugin.PolicyResponse)14 AttributeDescriptor (ddf.catalog.data.AttributeDescriptor)12 Map (java.util.Map)12 QueryResponse (ddf.catalog.operation.QueryResponse)11 UpdateRequestImpl (ddf.catalog.operation.impl.UpdateRequestImpl)11