use of ddf.catalog.data.AttributeDescriptor in project ddf by codice.
the class TestMetacardTypeAdapter method testUnmarshalWithUnknownTypeName.
@Test
public void testUnmarshalWithUnknownTypeName() throws CatalogTransformerException {
MetacardType unknownMetacardType = new MetacardTypeImpl(KNOWN_TYPE_NAME, (Set<AttributeDescriptor>) null);
List<MetacardType> metacardTypes = new ArrayList<MetacardType>(1);
metacardTypes.add(unknownMetacardType);
MetacardTypeAdapter metacardTypeAdpater = new MetacardTypeAdapter(metacardTypes);
MetacardType metacardType = metacardTypeAdpater.unmarshal(UNKNOWN_TYPE_NAME);
assertThat(metacardType.getName(), is(BasicTypes.BASIC_METACARD.getName()));
}
use of ddf.catalog.data.AttributeDescriptor in project ddf by codice.
the class TestXmlInputTransformer method testTransformWithExtensibleMetacardType.
@Test
public void testTransformWithExtensibleMetacardType() throws IOException, CatalogTransformerException {
List<MetacardType> metacardTypes = new ArrayList<MetacardType>(1);
MetacardType extensibleType = new MetacardTypeImpl("extensible.metacard", BasicTypes.BASIC_METACARD.getAttributeDescriptors());
metacardTypes.add(extensibleType);
xit.setMetacardTypes(metacardTypes);
Metacard metacard = xit.transform(new FileInputStream("src/test/resources/extensibleMetacard.xml"));
LOGGER.info("ID: {}", metacard.getId());
LOGGER.info("Type: {}", metacard.getMetacardType().getName());
LOGGER.info("Source: {}", metacard.getSourceId());
LOGGER.info("Attributes: ");
for (AttributeDescriptor descriptor : metacard.getMetacardType().getAttributeDescriptors()) {
Attribute attribute = metacard.getAttribute(descriptor.getName());
LOGGER.info("\t" + descriptor.getName() + ": " + ((attribute == null) ? attribute : attribute.getValue()));
}
}
use of ddf.catalog.data.AttributeDescriptor in project ddf by codice.
the class AbstractFeatureConverter method createMetacardFromFeature.
protected Metacard createMetacardFromFeature(HierarchicalStreamReader hreader, MetacardType metacardType) {
StringWriter metadataWriter = new StringWriter();
HierarchicalStreamReader reader = copyXml(hreader, metadataWriter);
MetacardImpl mc = new MetacardImpl(metacardType);
mc.setContentTypeName(metacardType.getName());
while (reader.hasMoreChildren()) {
reader.moveDown();
String featureProperty = prefix + reader.getNodeName();
AttributeDescriptor attributeDescriptor = metacardType.getAttributeDescriptor(featureProperty);
//Check MetacardMapper for mappings of incoming values
String mappedMetacardAttribute = null;
if (metacardMapper != null) {
LOGGER.debug("Looking up metacard attribute for feature property {} using metacard mapper", featureProperty);
mappedMetacardAttribute = metacardMapper.getMetacardAttribute(featureProperty);
LOGGER.debug("Found metacard attribute {} for feature property {}", mappedMetacardAttribute, featureProperty);
}
Serializable value = null;
if (attributeDescriptor != null && (StringUtils.isNotBlank(reader.getValue()) || BasicTypes.GEO_TYPE.getAttributeFormat().equals(attributeDescriptor.getType().getAttributeFormat()) || BasicTypes.DATE_TYPE.getAttributeFormat().equals(attributeDescriptor.getType().getAttributeFormat()))) {
if (StringUtils.isNotBlank(mappedMetacardAttribute)) {
if (StringUtils.equals(mappedMetacardAttribute, Core.RESOURCE_SIZE)) {
String sizeBeforeConversion = reader.getValue();
String bytes = convertToBytes(reader, metacardMapper.getDataUnit());
if (StringUtils.isNotBlank(bytes)) {
LOGGER.debug("Setting mapped metacard attribute {} with value {}", mappedMetacardAttribute, bytes);
mc.setAttribute(mappedMetacardAttribute, bytes);
}
if (StringUtils.isNotBlank(sizeBeforeConversion)) {
LOGGER.debug("Setting metacard attribute {} with value {}", featureProperty, sizeBeforeConversion);
mc.setAttribute(featureProperty, sizeBeforeConversion);
}
} else {
value = getValueForMetacardAttribute(attributeDescriptor.getType().getAttributeFormat(), reader);
if (value != null) {
LOGGER.debug("Setting mapped metacard attribute {} with value {}", mappedMetacardAttribute, value);
mc.setAttribute(mappedMetacardAttribute, value);
mc.setAttribute(featureProperty, value);
}
}
} else {
value = getValueForMetacardAttribute(attributeDescriptor.getType().getAttributeFormat(), reader);
if (value != null) {
LOGGER.debug("Setting metacard attribute {} with value {}", featureProperty, value);
mc.setAttribute(featureProperty, value);
}
}
if (BasicTypes.GEO_TYPE.getAttributeFormat().equals(attributeDescriptor.getType().getAttributeFormat())) {
mc.setLocation((String) value);
}
// populate that field as well
if (isBasicMetacardAttribute(reader.getNodeName())) {
LOGGER.debug("Setting metacard basic attribute: {} = {}", reader.getNodeName(), value);
mc.setAttribute(reader.getNodeName(), value);
}
}
reader.moveUp();
}
mc.setMetadata(metadataWriter.toString());
try {
if (metacardType instanceof FeatureMetacardType) {
URI namespaceUri = new URI(((FeatureMetacardType) metacardType).getNamespaceURI());
mc.setTargetNamespace(namespaceUri);
}
} catch (URISyntaxException e) {
LOGGER.debug("Error setting target namespace uri on metacard.", e);
}
return mc;
}
use of ddf.catalog.data.AttributeDescriptor in project ddf by codice.
the class MetacardCreatorTest method testNullIntAttribute.
@Test
public void testNullIntAttribute() {
Set<AttributeDescriptor> extraAttributes = new HashSet<>();
extraAttributes.add(new AttributeDescriptorImpl(Media.DURATION, false, false, false, false, BasicTypes.INTEGER_TYPE));
final Metadata metadata = new Metadata();
metadata.add(MetacardCreator.COMPRESSION_TYPE_METADATA_KEY, null);
MetacardTypeImpl extendedMetacardType = new MetacardTypeImpl(BasicTypes.BASIC_METACARD.getName(), BasicTypes.BASIC_METACARD, extraAttributes);
final String id = "id";
final String metadataXml = "<xml>test</xml>";
Metacard metacard = MetacardCreator.createMetacard(metadata, id, metadataXml, extendedMetacardType);
assertThat(metacard.getMetadata(), is(metadataXml));
assertThat(metacard.getAttribute(Media.COMPRESSION), is(nullValue()));
}
use of ddf.catalog.data.AttributeDescriptor in project ddf by codice.
the class MetacardCreatorTest method testDoubleAttributeWithNumberFormatException.
@Test
public void testDoubleAttributeWithNumberFormatException() {
Set<AttributeDescriptor> extraAttributes = new HashSet<>();
extraAttributes.add(new AttributeDescriptorImpl(Media.DURATION, false, false, false, false, BasicTypes.DOUBLE_TYPE));
final Metadata metadata = new Metadata();
String durationValue = "Not actually a double";
metadata.add(MetacardCreator.DURATION_METDATA_KEY, durationValue);
MetacardTypeImpl extendedMetacardType = new MetacardTypeImpl(BasicTypes.BASIC_METACARD.getName(), BasicTypes.BASIC_METACARD, extraAttributes);
final String id = "id";
final String metadataXml = "<xml>test</xml>";
Metacard metacard = MetacardCreator.createMetacard(metadata, id, metadataXml, extendedMetacardType);
assertThat(metacard.getMetadata(), is(metadataXml));
assertThat(metacard.getAttribute(Media.DURATION), is(nullValue()));
}
Aggregations