Search in sources :

Example 6 with AttributeDescriptor

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

the class MetacardImplTest method testUpdatingWrappedMetacardFields.

@Test
public void testUpdatingWrappedMetacardFields() {
    HashSet<AttributeDescriptor> descriptors = new HashSet<AttributeDescriptor>();
    descriptors.add(new AttributeDescriptorImpl("test-string", true, /* indexed */
    true, /* stored */
    false, /* tokenized */
    false, /* multivalued */
    BasicTypes.STRING_TYPE));
    MetacardType testType = new MetacardTypeImpl("test.type", descriptors);
    MetacardImpl mi = new MetacardImpl(mc);
    mi.setSourceId("testSource");
    mi.setType(testType);
    assertEquals("testSource", mi.getSourceId());
    assertEquals(testType, mi.getMetacardType());
}
Also used : AttributeDescriptor(ddf.catalog.data.AttributeDescriptor) MetacardType(ddf.catalog.data.MetacardType) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 7 with AttributeDescriptor

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

the class MetacardTypeImplTest method compareExtendedMetacardTypeToEquivalentMetacardType.

private void compareExtendedMetacardTypeToEquivalentMetacardType(BiConsumer<MetacardType, MetacardType> assertions) {
    final Set<AttributeDescriptor> originalDescriptors = new HashSet<>(BASIC_METACARD.getAttributeDescriptors());
    final MetacardType baseMetacardType = new MetacardTypeImpl("base", originalDescriptors);
    final Set<AttributeDescriptor> additionalDescriptors = new HashSet<>();
    additionalDescriptors.add(new AttributeDescriptorImpl("foo", true, false, true, false, BasicTypes.BOOLEAN_TYPE));
    additionalDescriptors.add(new AttributeDescriptorImpl("bar", false, true, false, true, BasicTypes.STRING_TYPE));
    final MetacardType extendedMetacardType = new MetacardTypeImpl("type", baseMetacardType, additionalDescriptors);
    final Set<AttributeDescriptor> combinedDescriptors = new HashSet<>(originalDescriptors);
    combinedDescriptors.addAll(additionalDescriptors);
    final MetacardType equivalentMetacardType = new MetacardTypeImpl("type", combinedDescriptors);
    assertions.accept(extendedMetacardType, equivalentMetacardType);
}
Also used : AttributeDescriptor(ddf.catalog.data.AttributeDescriptor) MetacardType(ddf.catalog.data.MetacardType) HashSet(java.util.HashSet)

Example 8 with AttributeDescriptor

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

the class RequiredAttributesMetacardValidator method validateMetacard.

@Override
public Optional<MetacardValidationReport> validateMetacard(final Metacard metacard) {
    Preconditions.checkArgument(metacard != null, "The metacard cannot be null.");
    final MetacardType metacardType = metacard.getMetacardType();
    if (metacardTypeName.equals(metacardType.getName())) {
        final Set<ValidationViolation> violations = new HashSet<>();
        for (final String attributeName : requiredAttributes) {
            final Attribute attribute = metacard.getAttribute(attributeName);
            if (attribute != null) {
                final AttributeDescriptor descriptor = metacardType.getAttributeDescriptor(attributeName);
                if (descriptor.isMultiValued()) {
                    if (attribute.getValues().size() == 0) {
                        addRequiredAttributeViolation(attributeName, violations);
                    }
                } else if (attribute.getValue() == null) {
                    addRequiredAttributeViolation(attributeName, violations);
                }
            } else {
                addRequiredAttributeViolation(attributeName, violations);
            }
        }
        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) MetacardType(ddf.catalog.data.MetacardType) HashSet(java.util.HashSet)

Example 9 with AttributeDescriptor

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

the class MetacardTypeImplTest method testNullAttributeDescriptors.

@Test
public void testNullAttributeDescriptors() {
    MetacardType mt = new MetacardTypeImpl(NAME, (Set<AttributeDescriptor>) null);
    assertThat(mt.getAttributeDescriptors(), hasSize(0));
}
Also used : AttributeDescriptor(ddf.catalog.data.AttributeDescriptor) MetacardType(ddf.catalog.data.MetacardType) Test(org.junit.Test)

Example 10 with AttributeDescriptor

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

the class QualifiedMetacardTypeTest method prepareTest.

@BeforeClass
public static void prepareTest() {
    qmtAttributes = new HashSet<AttributeDescriptor>();
    AttributeDescriptor ad1 = new AttributeDescriptorImpl(GEO_ATTRIBUTE_DESCRIPTOR_NAME, true, true, false, false, BasicTypes.GEO_TYPE);
    qmtAttributes.add(ad1);
    AttributeDescriptor ad2 = new AttributeDescriptorImpl(METADATA_ATTRIBUTE_DESCRIPTOR_NAME, true, true, false, false, BasicTypes.XML_TYPE);
    qmtAttributes.add(ad2);
}
Also used : AttributeDescriptor(ddf.catalog.data.AttributeDescriptor) BeforeClass(org.junit.BeforeClass)

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