Search in sources :

Example 56 with Attribute

use of ddf.catalog.data.Attribute in project ddf by codice.

the class Associated method removeEdge.

private void removeEdge(Edge edge, Map<String, Metacard> metacards, /*Mutable*/
Map<String, Metacard> changedMetacards) {
    String id = edge.parent.get(Metacard.ID).toString();
    Metacard target = changedMetacards.getOrDefault(id, metacards.get(id));
    ArrayList<String> values = Optional.of(target).map(m -> m.getAttribute(edge.relation)).map(Attribute::getValues).map(util::getStringList).orElseGet(ArrayList::new);
    values.remove(edge.child.get(Metacard.ID).toString());
    target.setAttribute(new AttributeImpl(edge.relation, values));
    changedMetacards.put(id, target);
}
Also used : QueryRequestImpl(ddf.catalog.operation.impl.QueryRequestImpl) SourceUnavailableException(ddf.catalog.source.SourceUnavailableException) CatalogFramework(ddf.catalog.CatalogFramework) UpdateRequestImpl(ddf.catalog.operation.impl.UpdateRequestImpl) UnsupportedQueryException(ddf.catalog.source.UnsupportedQueryException) AttributeImpl(ddf.catalog.data.impl.AttributeImpl) HashMap(java.util.HashMap) Function(java.util.function.Function) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) MetacardVersion(ddf.catalog.core.versioning.MetacardVersion) SortBy(org.opengis.filter.sort.SortBy) EndpointUtil(org.codice.ddf.catalog.ui.util.EndpointUtil) Metacard(ddf.catalog.data.Metacard) Map(java.util.Map) HashCodeBuilder(org.apache.commons.lang3.builder.HashCodeBuilder) Result(ddf.catalog.data.Result) EqualsBuilder(org.apache.commons.lang3.builder.EqualsBuilder) QueryImpl(ddf.catalog.operation.impl.QueryImpl) ImmutableSet(com.google.common.collect.ImmutableSet) Collection(java.util.Collection) IngestException(ddf.catalog.source.IngestException) DeletedMetacard(ddf.catalog.core.versioning.DeletedMetacard) Set(java.util.Set) FederationException(ddf.catalog.federation.FederationException) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) Objects(java.util.Objects) TimeUnit(java.util.concurrent.TimeUnit) QueryResponse(ddf.catalog.operation.QueryResponse) List(java.util.List) Stream(java.util.stream.Stream) Attribute(ddf.catalog.data.Attribute) Optional(java.util.Optional) Filter(org.opengis.filter.Filter) Collections(java.util.Collections) Metacard(ddf.catalog.data.Metacard) DeletedMetacard(ddf.catalog.core.versioning.DeletedMetacard) Attribute(ddf.catalog.data.Attribute) AttributeImpl(ddf.catalog.data.impl.AttributeImpl) ArrayList(java.util.ArrayList)

Example 57 with Attribute

use of ddf.catalog.data.Attribute in project ddf by codice.

the class Associated method addEdge.

private void addEdge(Edge edge, Map<String, Metacard> metacards, Map<String, Metacard> changedMetacards) {
    String id = edge.parent.get(Metacard.ID).toString();
    Metacard target = changedMetacards.getOrDefault(id, metacards.get(id));
    ArrayList<String> values = Optional.of(target).map(m -> m.getAttribute(edge.relation)).map(Attribute::getValues).map(util::getStringList).orElseGet(ArrayList::new);
    values.add(edge.child.get(Metacard.ID).toString());
    target.setAttribute(new AttributeImpl(edge.relation, values));
    changedMetacards.put(id, target);
}
Also used : QueryRequestImpl(ddf.catalog.operation.impl.QueryRequestImpl) SourceUnavailableException(ddf.catalog.source.SourceUnavailableException) CatalogFramework(ddf.catalog.CatalogFramework) UpdateRequestImpl(ddf.catalog.operation.impl.UpdateRequestImpl) UnsupportedQueryException(ddf.catalog.source.UnsupportedQueryException) AttributeImpl(ddf.catalog.data.impl.AttributeImpl) HashMap(java.util.HashMap) Function(java.util.function.Function) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) MetacardVersion(ddf.catalog.core.versioning.MetacardVersion) SortBy(org.opengis.filter.sort.SortBy) EndpointUtil(org.codice.ddf.catalog.ui.util.EndpointUtil) Metacard(ddf.catalog.data.Metacard) Map(java.util.Map) HashCodeBuilder(org.apache.commons.lang3.builder.HashCodeBuilder) Result(ddf.catalog.data.Result) EqualsBuilder(org.apache.commons.lang3.builder.EqualsBuilder) QueryImpl(ddf.catalog.operation.impl.QueryImpl) ImmutableSet(com.google.common.collect.ImmutableSet) Collection(java.util.Collection) IngestException(ddf.catalog.source.IngestException) DeletedMetacard(ddf.catalog.core.versioning.DeletedMetacard) Set(java.util.Set) FederationException(ddf.catalog.federation.FederationException) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) Objects(java.util.Objects) TimeUnit(java.util.concurrent.TimeUnit) QueryResponse(ddf.catalog.operation.QueryResponse) List(java.util.List) Stream(java.util.stream.Stream) Attribute(ddf.catalog.data.Attribute) Optional(java.util.Optional) Filter(org.opengis.filter.Filter) Collections(java.util.Collections) Metacard(ddf.catalog.data.Metacard) DeletedMetacard(ddf.catalog.core.versioning.DeletedMetacard) Attribute(ddf.catalog.data.Attribute) AttributeImpl(ddf.catalog.data.impl.AttributeImpl) ArrayList(java.util.ArrayList)

Example 58 with Attribute

use of ddf.catalog.data.Attribute in project ddf by codice.

the class AttributeFactoryTest method testCreateAttributeWithIllegalArgument.

@Test(expected = IllegalArgumentException.class)
public void testCreateAttributeWithIllegalArgument() throws Exception {
    when(mockType.getAttributeFormat()).thenReturn(INTEGER);
    Attribute attribute = attributeFactory.createAttribute(mockDescriptor, "1874xyz");
}
Also used : Attribute(ddf.catalog.data.Attribute) Test(org.junit.Test)

Example 59 with Attribute

use of ddf.catalog.data.Attribute in project ddf by codice.

the class AttributeMetacardTransformer method transform.

@Override
public BinaryContent transform(Metacard metacard, Map<String, Serializable> arguments) throws CatalogTransformerException {
    if (metacard == null) {
        throw new CatalogTransformerException("No attribute [" + attributeName + "] found in Metacard.");
    }
    LOGGER.debug("Attempting transformation of [{}] with transformer [{}]", metacard, this);
    Attribute attribute = metacard.getAttribute(attributeName);
    if (attribute != null && attribute.getValue() != null) {
        if (byte[].class.isAssignableFrom(attribute.getValue().getClass())) {
            return new BinaryContentImpl(new ByteArrayInputStream((byte[]) attribute.getValue()), mimeType);
        }
        if (String.class.isAssignableFrom(attribute.getValue().getClass())) {
            return new BinaryContentImpl(new ByteArrayInputStream(attribute.getValue().toString().getBytes(StandardCharsets.UTF_8)), mimeType);
        }
    }
    throw new CatalogTransformerException("No attribute [" + attributeName + "] found in Metacard.");
}
Also used : Attribute(ddf.catalog.data.Attribute) ByteArrayInputStream(java.io.ByteArrayInputStream) CatalogTransformerException(ddf.catalog.transform.CatalogTransformerException) BinaryContentImpl(ddf.catalog.data.impl.BinaryContentImpl)

Example 60 with Attribute

use of ddf.catalog.data.Attribute in project ddf by codice.

the class GenericFeatureConverter method marshal.

/**
     * This method will convert a {@link Metacard} instance into xml that will validate against the
     * GML 2.1.2 AbstractFeatureType.
     *
     * @param value   the {@link Metacard} to convert
     * @param writer  the stream writer responsible for writing this xml doc
     * @param context a reference back to the Xstream marshalling context. Allows you to call
     *                "convertAnother" which will lookup other registered converters.
     */
@Override
public void marshal(Object value, HierarchicalStreamWriter writer, MarshallingContext context) {
    Metacard metacard = (Metacard) value;
    // TODO when we have a reference to the MCT we can get the namespace too
    QName qname = WfsQnameBuilder.buildQName(metacard.getMetacardType().getName(), metacard.getContentTypeName());
    writer.startNode(qname.getPrefix() + ":" + qname.getLocalPart());
    // Add the "fid" attribute if we have an ID
    String fid = (String) metacard.getAttribute(Metacard.ID).getValue();
    if (fid != null) {
        writer.addAttribute(FID, fid);
    }
    if (null != metacard.getLocation()) {
        Geometry geo = XmlNode.readGeometry(metacard.getLocation());
        if (geo != null && !geo.isEmpty()) {
            XmlNode.writeEnvelope(WfsConstants.GML_PREFIX + ":" + "boundedBy", context, writer, geo.getEnvelopeInternal());
        }
    }
    Set<AttributeDescriptor> descriptors = new TreeSet<AttributeDescriptor>(new AttributeDescriptorComparator());
    descriptors.addAll(metacard.getMetacardType().getAttributeDescriptors());
    for (AttributeDescriptor attributeDescriptor : descriptors) {
        Attribute attribute = metacard.getAttribute(attributeDescriptor.getName());
        if (attribute != null) {
            writeAttributeToXml(attribute, qname, attributeDescriptor.getType().getAttributeFormat(), context, writer);
        }
    }
    writer.endNode();
}
Also used : Geometry(com.vividsolutions.jts.geom.Geometry) Metacard(ddf.catalog.data.Metacard) Attribute(ddf.catalog.data.Attribute) QName(javax.xml.namespace.QName) TreeSet(java.util.TreeSet) AttributeDescriptorComparator(org.codice.ddf.spatial.ogc.wfs.catalog.common.AttributeDescriptorComparator) AttributeDescriptor(ddf.catalog.data.AttributeDescriptor)

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