Search in sources :

Example 71 with AttributeDescriptor

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

the class EndpointUtil method getMetacardMap.

public Map<String, Object> getMetacardMap(Metacard metacard) {
    Set<AttributeDescriptor> attributeDescriptors = metacard.getMetacardType().getAttributeDescriptors();
    Map<String, Object> result = new HashMap<>();
    for (AttributeDescriptor descriptor : attributeDescriptors) {
        if (metacard.getAttribute(descriptor.getName()) == null) {
            if (descriptor.isMultiValued()) {
                result.put(descriptor.getName(), Collections.emptyList());
            } else {
                result.put(descriptor.getName(), null);
            }
            continue;
        }
        if (Metacard.THUMBNAIL.equals(descriptor.getName())) {
            if (metacard.getThumbnail() != null) {
                result.put(descriptor.getName(), Base64.getEncoder().encodeToString(metacard.getThumbnail()));
            } else {
                result.put(descriptor.getName(), null);
            }
            continue;
        }
        if (descriptor.getType().getAttributeFormat().equals(AttributeType.AttributeFormat.DATE)) {
            Attribute attribute = metacard.getAttribute(descriptor.getName());
            if (descriptor.isMultiValued()) {
                result.put(descriptor.getName(), attribute.getValues().stream().map(this::parseDate).collect(Collectors.toList()));
            } else {
                result.put(descriptor.getName(), parseDate(attribute.getValue()));
            }
        }
        if (descriptor.isMultiValued()) {
            result.put(descriptor.getName(), metacard.getAttribute(descriptor.getName()).getValues());
        } else {
            result.put(descriptor.getName(), metacard.getAttribute(descriptor.getName()).getValue());
        }
    }
    return result;
}
Also used : HashMap(java.util.HashMap) InjectableAttribute(ddf.catalog.data.InjectableAttribute) Attribute(ddf.catalog.data.Attribute) AttributeDescriptor(ddf.catalog.data.AttributeDescriptor)

Example 72 with AttributeDescriptor

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

the class ValidationParser method parseAttributeTypes.

private List<Callable<Boolean>> parseAttributeTypes(Changeset changeset, Map<String, Outer.AttributeType> attributeTypes) {
    List<Callable<Boolean>> staged = new ArrayList<>();
    for (Map.Entry<String, Outer.AttributeType> entry : attributeTypes.entrySet()) {
        final AttributeDescriptor descriptor = new AttributeDescriptorImpl(entry.getKey(), entry.getValue().indexed, entry.getValue().stored, entry.getValue().tokenized, entry.getValue().multivalued, BasicTypes.getAttributeType(entry.getValue().type));
        staged.add(() -> {
            attributeRegistry.register(descriptor);
            changeset.attributes.add(descriptor);
            return true;
        });
    }
    return staged;
}
Also used : ArrayList(java.util.ArrayList) AttributeDescriptor(ddf.catalog.data.AttributeDescriptor) AttributeDescriptorImpl(ddf.catalog.data.impl.AttributeDescriptorImpl) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) Callable(java.util.concurrent.Callable)

Example 73 with AttributeDescriptor

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

the class FeatureMetacardTypeTest method assertBasicAttributeDescriptor.

private void assertBasicAttributeDescriptor(FeatureMetacardType featureMetacardType, String propertyName, AttributeType type) {
    AttributeDescriptor attrDesc = featureMetacardType.getAttributeDescriptor(propertyName);
    assertNotNull(attrDesc);
    assertTrue(attrDesc.getType() == type);
}
Also used : AttributeDescriptor(ddf.catalog.data.AttributeDescriptor)

Example 74 with AttributeDescriptor

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

the class FeatureMetacardTypeTest method testFeatureMetacardTypeStringNonQueryProperty.

@Test
public void testFeatureMetacardTypeStringNonQueryProperty() {
    XmlSchema schema = new XmlSchema();
    XmlSchemaElement stringElement = new XmlSchemaElement(schema, true);
    stringElement.setSchemaType(new XmlSchemaSimpleType(schema, false));
    stringElement.setSchemaTypeName(Constants.XSD_STRING);
    stringElement.setName(ELEMENT_NAME_1);
    XmlSchemaElement stringElement2 = new XmlSchemaElement(schema, true);
    stringElement2.setSchemaType(new XmlSchemaSimpleType(schema, false));
    stringElement2.setSchemaTypeName(Constants.XSD_STRING);
    stringElement2.setName(ELEMENT_NAME_2);
    List<String> nonQueryProps = new ArrayList<String>();
    nonQueryProps.add(ELEMENT_NAME_1);
    FeatureMetacardType featureMetacardType = new FeatureMetacardType(schema, FEATURE_TYPE, nonQueryProps, Wfs10Constants.GML_NAMESPACE);
    assertTrue(featureMetacardType.getTextualProperties().size() == 2);
    AttributeDescriptor attrDesc = featureMetacardType.getAttributeDescriptor(prefix(ELEMENT_NAME_1));
    assertNotNull(attrDesc);
    assertFalse(attrDesc.isIndexed());
    AttributeDescriptor attrDesc2 = featureMetacardType.getAttributeDescriptor(prefix(ELEMENT_NAME_2));
    assertNotNull(attrDesc2);
    assertTrue(attrDesc2.isIndexed());
}
Also used : XmlSchema(org.apache.ws.commons.schema.XmlSchema) XmlSchemaElement(org.apache.ws.commons.schema.XmlSchemaElement) XmlSchemaSimpleType(org.apache.ws.commons.schema.XmlSchemaSimpleType) ArrayList(java.util.ArrayList) AttributeDescriptor(ddf.catalog.data.AttributeDescriptor) FeatureMetacardType(org.codice.ddf.spatial.ogc.wfs.catalog.common.FeatureMetacardType) Test(org.junit.Test)

Example 75 with AttributeDescriptor

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

the class FeatureMetacardTypeTest method testFeatureMetacardTypeFindTaxonomyMetacardAttributes.

@Test
public void testFeatureMetacardTypeFindTaxonomyMetacardAttributes() {
    XmlSchema schema = new XmlSchema();
    XmlSchemaElement element = new XmlSchemaElement(schema, true);
    element.setSchemaType(new XmlSchemaSimpleType(schema, false));
    element.setSchemaTypeName(Constants.XSD_STRING);
    element.setName(ELEMENT_NAME);
    schema.getElements().put(new QName(ELEMENT_NAME), element);
    FeatureMetacardType fmt = new FeatureMetacardType(schema, FEATURE_TYPE, NON_QUERYABLE_PROPS, Wfs10Constants.GML_NAMESPACE);
    Set<AttributeDescriptor> descriptors = initDescriptors();
    for (AttributeDescriptor ad : descriptors) {
        assertBasicAttributeDescriptor(fmt, ad.getName(), ad.getType());
        assertFalse(fmt.getAttributeDescriptor(ad.getName()).isStored());
    }
    // +1 to account for one element added to schema.
    assertThat(fmt.getAttributeDescriptors().size(), is(descriptors.size() + 1));
}
Also used : XmlSchema(org.apache.ws.commons.schema.XmlSchema) XmlSchemaElement(org.apache.ws.commons.schema.XmlSchemaElement) XmlSchemaSimpleType(org.apache.ws.commons.schema.XmlSchemaSimpleType) QName(javax.xml.namespace.QName) AttributeDescriptor(ddf.catalog.data.AttributeDescriptor) FeatureMetacardType(org.codice.ddf.spatial.ogc.wfs.catalog.common.FeatureMetacardType) 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