Search in sources :

Example 1 with AttributeDescriptor

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

the class AtomTransformer method getGeoRssPositions.

private List<Position> getGeoRssPositions(Metacard metacard) {
    List<Position> georssPositions = new ArrayList<Position>();
    for (AttributeDescriptor ad : metacard.getMetacardType().getAttributeDescriptors()) {
        if (ad != null && ad.getType() != null && BasicTypes.GEO_TYPE.getAttributeFormat().equals(ad.getType().getAttributeFormat())) {
            Attribute geoAttribute = metacard.getAttribute(ad.getName());
            if (geoAttribute == null) {
                continue;
            }
            for (Serializable geo : geoAttribute.getValues()) {
                if (geo != null) {
                    try {
                        Geometry geometry = reader.read(geo.toString());
                        CompositeGeometry formatter = CompositeGeometry.getCompositeGeometry(geometry);
                        if (null != formatter) {
                            georssPositions.addAll(formatter.toGeoRssPositions());
                        } else {
                            LOGGER.debug("When cycling through geometries, could not get composite geometry [{}]", geo);
                        }
                    } catch (ParseException e) {
                        LOGGER.info("When cycling through geometries, could not parse [{}]", geo, e);
                    }
                }
            }
        }
    }
    return georssPositions;
}
Also used : Geometry(com.vividsolutions.jts.geom.Geometry) CompositeGeometry(ddf.geo.formatter.CompositeGeometry) Serializable(java.io.Serializable) Position(org.apache.abdera.ext.geo.Position) Attribute(ddf.catalog.data.Attribute) CompositeGeometry(ddf.geo.formatter.CompositeGeometry) ArrayList(java.util.ArrayList) AttributeDescriptor(ddf.catalog.data.AttributeDescriptor) ParseException(com.vividsolutions.jts.io.ParseException) MimeTypeParseException(javax.activation.MimeTypeParseException)

Example 2 with AttributeDescriptor

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

the class MetacardVersionImpl method sanitizeVersionAttributes.

private static void sanitizeVersionAttributes(/*Mutable*/
Metacard source) {
    Consumer<String> nullifySourceAttribute = (s) -> source.setAttribute(new AttributeImpl(s, (Serializable) null));
    Sets.difference(VERSION_DESCRIPTORS, BasicTypes.BASIC_METACARD.getAttributeDescriptors()).stream().map(AttributeDescriptor::getName).forEach(nullifySourceAttribute);
}
Also used : MetacardTypeImpl(ddf.catalog.data.impl.MetacardTypeImpl) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Date(java.util.Date) URISyntaxException(java.net.URISyntaxException) ObjectInputStream(java.io.ObjectInputStream) LoggerFactory(org.slf4j.LoggerFactory) AttributeImpl(ddf.catalog.data.impl.AttributeImpl) Strings.isNullOrEmpty(com.google.common.base.Strings.isNullOrEmpty) Supplier(java.util.function.Supplier) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) MetacardVersion(ddf.catalog.core.versioning.MetacardVersion) ByteArrayInputStream(java.io.ByteArrayInputStream) Subject(org.apache.shiro.subject.Subject) Metacard(ddf.catalog.data.Metacard) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) AttributeDescriptorImpl(ddf.catalog.data.impl.AttributeDescriptorImpl) ObjectOutputStream(java.io.ObjectOutputStream) URI(java.net.URI) SubjectUtils(ddf.security.SubjectUtils) Nullable(javax.annotation.Nullable) Logger(org.slf4j.Logger) AttributeDescriptor(ddf.catalog.data.AttributeDescriptor) Set(java.util.Set) IOException(java.io.IOException) Instant(java.time.Instant) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) MetacardType(ddf.catalog.data.MetacardType) Serializable(java.io.Serializable) Consumer(java.util.function.Consumer) List(java.util.List) Attribute(ddf.catalog.data.Attribute) Optional(java.util.Optional) Collections(java.util.Collections) BasicTypes(ddf.catalog.data.impl.BasicTypes) Serializable(java.io.Serializable) AttributeImpl(ddf.catalog.data.impl.AttributeImpl)

Example 3 with AttributeDescriptor

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

the class ValidationParser method parseMetacardTypes.

private List<Callable<Boolean>> parseMetacardTypes(Changeset changeset, List<Outer.MetacardType> metacardTypes) {
    List<Callable<Boolean>> staged = new ArrayList<>();
    BundleContext context = getBundleContext();
    for (Outer.MetacardType metacardType : metacardTypes) {
        Set<AttributeDescriptor> attributeDescriptors = new HashSet<>(BasicTypes.BASIC_METACARD.getAttributeDescriptors());
        Set<String> requiredAttributes = new HashSet<>();
        metacardType.attributes.forEach((attributeName, attribute) -> {
            AttributeDescriptor descriptor = attributeRegistry.lookup(attributeName).orElseThrow(() -> new IllegalStateException(String.format("Metacard type [%s] includes the attribute [%s], but that attribute is not in the attribute registry.", metacardType.type, attributeName)));
            attributeDescriptors.add(descriptor);
            if (attribute.required) {
                requiredAttributes.add(attributeName);
            }
        });
        if (!requiredAttributes.isEmpty()) {
            final MetacardValidator validator = new RequiredAttributesMetacardValidator(metacardType.type, requiredAttributes);
            staged.add(() -> {
                ServiceRegistration<MetacardValidator> registration = context.registerService(MetacardValidator.class, validator, null);
                changeset.metacardValidatorServices.add(registration);
                return registration != null;
            });
        }
        Dictionary<String, Object> properties = new Hashtable<>();
        properties.put(NAME_PROPERTY, metacardType.type);
        MetacardType type = new MetacardTypeImpl(metacardType.type, attributeDescriptors);
        staged.add(() -> {
            ServiceRegistration<MetacardType> registration = context.registerService(MetacardType.class, type, properties);
            changeset.metacardTypeServices.add(registration);
            return registration != null;
        });
    }
    return staged;
}
Also used : Hashtable(java.util.Hashtable) ArrayList(java.util.ArrayList) AttributeDescriptor(ddf.catalog.data.AttributeDescriptor) MetacardTypeImpl(ddf.catalog.data.impl.MetacardTypeImpl) Callable(java.util.concurrent.Callable) MetacardType(ddf.catalog.data.MetacardType) MetacardValidator(ddf.catalog.validation.MetacardValidator) RequiredAttributesMetacardValidator(ddf.catalog.validation.impl.validator.RequiredAttributesMetacardValidator) RequiredAttributesMetacardValidator(ddf.catalog.validation.impl.validator.RequiredAttributesMetacardValidator) BundleContext(org.osgi.framework.BundleContext) HashSet(java.util.HashSet)

Example 4 with AttributeDescriptor

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

the class ReportingMetacardValidatorImpl method validateMetacard.

@Override
public Optional<MetacardValidationReport> validateMetacard(final Metacard metacard) {
    Preconditions.checkArgument(metacard != null, "The metacard cannot be null.");
    final Set<ValidationViolation> violations = new HashSet<>();
    for (final AttributeDescriptor descriptor : metacard.getMetacardType().getAttributeDescriptors()) {
        final String attributeName = descriptor.getName();
        final Attribute attribute = metacard.getAttribute(attributeName);
        if (attribute != null) {
            for (final AttributeValidator validator : validatorRegistry.getValidators(attributeName)) {
                validator.validate(attribute).ifPresent(report -> violations.addAll(report.getAttributeValidationViolations()));
            }
        }
    }
    if (violations.size() > 0) {
        return getReport(violations);
    }
    return Optional.empty();
}
Also used : ValidationViolation(ddf.catalog.validation.violation.ValidationViolation) Attribute(ddf.catalog.data.Attribute) AttributeDescriptor(ddf.catalog.data.AttributeDescriptor) AttributeValidator(ddf.catalog.validation.AttributeValidator) HashSet(java.util.HashSet)

Example 5 with AttributeDescriptor

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

the class FeatureMetacardTypeTest method testFeatureMetacardTypeNonQueryGmlProperty.

@Test
public void testFeatureMetacardTypeNonQueryGmlProperty() {
    XmlSchema schema = new XmlSchema();
    XmlSchemaElement gmlElement = new XmlSchemaElement(schema, true);
    gmlElement.setSchemaType(new XmlSchemaComplexType(schema, false));
    gmlElement.setSchemaTypeName(new QName(Wfs10Constants.GML_NAMESPACE, GML));
    gmlElement.setName(ELEMENT_NAME_1);
    XmlSchemaElement gmlElement2 = new XmlSchemaElement(schema, true);
    gmlElement2.setSchemaType(new XmlSchemaComplexType(schema, false));
    gmlElement2.setSchemaTypeName(new QName(Wfs10Constants.GML_NAMESPACE, GML));
    gmlElement2.setName(ELEMENT_NAME_2);
    List<String> nonQueryProps = new ArrayList<String>();
    nonQueryProps.add(ELEMENT_NAME_2);
    FeatureMetacardType featureMetacardType = new FeatureMetacardType(schema, FEATURE_TYPE, nonQueryProps, Wfs10Constants.GML_NAMESPACE);
    assertTrue(featureMetacardType.getGmlProperties().size() == 2);
    AttributeDescriptor attrDesc = featureMetacardType.getAttributeDescriptor(prefix(ELEMENT_NAME_1));
    assertNotNull(attrDesc);
    assertTrue(attrDesc.getType() == BasicTypes.GEO_TYPE);
    assertTrue(attrDesc.isIndexed());
    AttributeDescriptor attrDesc2 = featureMetacardType.getAttributeDescriptor(prefix(ELEMENT_NAME_2));
    assertNotNull(attrDesc2);
    assertTrue(attrDesc2.getType() == BasicTypes.GEO_TYPE);
    assertFalse(attrDesc2.isIndexed());
}
Also used : XmlSchema(org.apache.ws.commons.schema.XmlSchema) XmlSchemaElement(org.apache.ws.commons.schema.XmlSchemaElement) QName(javax.xml.namespace.QName) ArrayList(java.util.ArrayList) AttributeDescriptor(ddf.catalog.data.AttributeDescriptor) XmlSchemaComplexType(org.apache.ws.commons.schema.XmlSchemaComplexType) FeatureMetacardType(org.codice.ddf.spatial.ogc.wfs.catalog.common.FeatureMetacardType) Test(org.junit.Test)

Aggregations

AttributeDescriptor (ddf.catalog.data.AttributeDescriptor)120 Test (org.junit.Test)51 MetacardType (ddf.catalog.data.MetacardType)43 Metacard (ddf.catalog.data.Metacard)40 Attribute (ddf.catalog.data.Attribute)31 HashSet (java.util.HashSet)29 MetacardImpl (ddf.catalog.data.impl.MetacardImpl)25 AttributeDescriptorImpl (ddf.catalog.data.impl.AttributeDescriptorImpl)24 MetacardTypeImpl (ddf.catalog.data.impl.MetacardTypeImpl)24 ArrayList (java.util.ArrayList)23 Serializable (java.io.Serializable)18 AttributeImpl (ddf.catalog.data.impl.AttributeImpl)9 FeatureMetacardType (org.codice.ddf.spatial.ogc.wfs.catalog.common.FeatureMetacardType)9 CatalogTransformerException (ddf.catalog.transform.CatalogTransformerException)8 HashMap (java.util.HashMap)8 List (java.util.List)8 Map (java.util.Map)8 IOException (java.io.IOException)7 Date (java.util.Date)7 Set (java.util.Set)7