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;
}
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;
}
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;
}
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;
}
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));
}
Aggregations