Search in sources :

Example 91 with AttributeDescriptor

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

the class PropertyJsonMetacardTransformer method convertToJSON.

public static Map<String, Object> convertToJSON(Metacard metacard, List<AttributeType.AttributeFormat> dontInclude) throws CatalogTransformerException {
    if (metacard == null) {
        throw new CatalogTransformerException("Cannot transform null metacard.");
    }
    Map<String, Object> rootObject = new HashMap<>();
    Map<String, Object> properties = new HashMap<>();
    for (AttributeDescriptor ad : metacard.getMetacardType().getAttributeDescriptors()) {
        Attribute attribute = metacard.getAttribute(ad.getName());
        if (attribute != null) {
            Object value = convertAttribute(attribute, ad, dontInclude);
            if (value != null) {
                properties.put(attribute.getName(), value);
            }
        }
    }
    properties.put(METACARD_TYPE_PROPERTY_KEY, metacard.getMetacardType().getName());
    if (StringUtils.isNotBlank(metacard.getSourceId())) {
        properties.put(SOURCE_ID_PROPERTY, metacard.getSourceId());
    }
    rootObject.put("properties", properties);
    return rootObject;
}
Also used : HashMap(java.util.HashMap) Attribute(ddf.catalog.data.Attribute) AttributeDescriptor(ddf.catalog.data.AttributeDescriptor) CatalogTransformerException(ddf.catalog.transform.CatalogTransformerException)

Example 92 with AttributeDescriptor

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

the class PdfInputTransformer method initializeMetacard.

private MetacardImpl initializeMetacard(String id, String contentInput) {
    MetacardImpl metacard;
    if (StringUtils.isNotBlank(contentInput)) {
        Set<AttributeDescriptor> attributes = contentMetadataExtractors.values().stream().map(ContentMetadataExtractor::getMetacardAttributes).flatMap(Collection::stream).collect(Collectors.toSet());
        metacard = new MetacardImpl(new MetacardTypeImpl(metacardType.getName(), metacardType, attributes));
        for (ContentMetadataExtractor contentMetadataExtractor : contentMetadataExtractors.values()) {
            contentMetadataExtractor.process(contentInput, metacard);
        }
    } else {
        metacard = new MetacardImpl(metacardType);
    }
    metacard.setId(id);
    metacard.setContentTypeName(MediaType.PDF.toString());
    metacard.setAttribute(Media.TYPE, MediaType.PDF.toString());
    metacard.setAttribute(Core.DATATYPE, DataType.DOCUMENT.toString());
    return metacard;
}
Also used : AttributeDescriptor(ddf.catalog.data.AttributeDescriptor) ContentMetadataExtractor(ddf.catalog.content.operation.ContentMetadataExtractor) MetacardTypeImpl(ddf.catalog.data.impl.MetacardTypeImpl) MetacardImpl(ddf.catalog.data.impl.MetacardImpl)

Example 93 with AttributeDescriptor

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

the class Search method getType.

private Map<String, Object> getType(MetacardType metacardType) throws CatalogTransformerException {
    Map<String, Object> fields = new HashMap<>();
    for (AttributeDescriptor descriptor : metacardType.getAttributeDescriptors()) {
        Map<String, Object> description = new HashMap<>();
        description.put(ATTRIBUTE_FORMAT, descriptor.getType().getAttributeFormat().toString());
        description.put(ATTRIBUTE_INDEXED, descriptor.isIndexed());
        fields.put(descriptor.getName(), description);
    }
    return fields;
}
Also used : HashMap(java.util.HashMap) AttributeDescriptor(ddf.catalog.data.AttributeDescriptor)

Example 94 with AttributeDescriptor

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

the class AttributeRegistryImplTest method generateMetacardTypeWithNulls.

private static MetacardType generateMetacardTypeWithNulls() {
    Set<AttributeDescriptor> attributeDescriptorSet = new HashSet<>();
    attributeDescriptorSet.add(new AttributeDescriptorImpl(null, true, true, true, true, BasicTypes.STRING_TYPE));
    attributeDescriptorSet.add(new AttributeDescriptorImpl("test", true, true, true, true, BasicTypes.STRING_TYPE));
    attributeDescriptorSet.add(null);
    MetacardType metacardType = new MetacardTypeImpl("nullAttributeMetacardType", attributeDescriptorSet);
    return metacardType;
}
Also used : AttributeDescriptor(ddf.catalog.data.AttributeDescriptor) MetacardType(ddf.catalog.data.MetacardType) HashSet(java.util.HashSet)

Example 95 with AttributeDescriptor

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

the class AttributeRegistryImplTest method testRemoveDuplicateAttribute.

@Test
public void testRemoveDuplicateAttribute() {
    final String attributeName = "foo";
    final AttributeDescriptor descriptor1 = new AttributeDescriptorImpl(attributeName, true, true, true, true, BasicTypes.STRING_TYPE);
    registry.register(descriptor1);
    registry.register(descriptor1);
    registry.deregister(descriptor1);
    final Optional<AttributeDescriptor> descriptorOptional = registry.lookup(attributeName);
    assertThat(descriptorOptional.isPresent(), is(true));
    assertThat(descriptorOptional.get(), is(descriptor1));
    registry.deregister(descriptor1);
    final Optional<AttributeDescriptor> descriptorOptional2 = registry.lookup(attributeName);
    assertThat(descriptorOptional2.isPresent(), is(false));
}
Also used : AttributeDescriptor(ddf.catalog.data.AttributeDescriptor) Test(org.junit.Test)

Aggregations

AttributeDescriptor (ddf.catalog.data.AttributeDescriptor)111 Test (org.junit.Test)51 MetacardType (ddf.catalog.data.MetacardType)40 Metacard (ddf.catalog.data.Metacard)38 HashSet (java.util.HashSet)29 Attribute (ddf.catalog.data.Attribute)26 AttributeDescriptorImpl (ddf.catalog.data.impl.AttributeDescriptorImpl)24 MetacardImpl (ddf.catalog.data.impl.MetacardImpl)24 MetacardTypeImpl (ddf.catalog.data.impl.MetacardTypeImpl)24 ArrayList (java.util.ArrayList)23 Serializable (java.io.Serializable)16 FeatureMetacardType (org.codice.ddf.spatial.ogc.wfs.catalog.common.FeatureMetacardType)9 CatalogTransformerException (ddf.catalog.transform.CatalogTransformerException)8 HashMap (java.util.HashMap)8 Map (java.util.Map)8 AttributeImpl (ddf.catalog.data.impl.AttributeImpl)7 IOException (java.io.IOException)7 Date (java.util.Date)7 List (java.util.List)7 QName (javax.xml.namespace.QName)7