Search in sources :

Example 11 with MetacardType

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

the class QualifiedMetacardTypeTest method testEqualsQualifiedMetacardTypeAndMetacardTypeImpl.

@Test
public void testEqualsQualifiedMetacardTypeAndMetacardTypeImpl() {
    MetacardType mt1 = new MetacardTypeImpl(QUALIFIED_METACARD_TYPE_NAME_3, qmtAttributes);
    QualifiedMetacardTypeImpl qmt1 = new QualifiedMetacardTypeImpl(QualifiedMetacardType.DEFAULT_METACARD_TYPE_NAMESPACE, mt1);
    MetacardType mt2 = new MetacardTypeImpl(QUALIFIED_METACARD_TYPE_NAME_3, qmtAttributes);
    assertTrue(qmt1.equals(mt2));
    assertTrue(mt2.equals(qmt1));
}
Also used : QualifiedMetacardType(ddf.catalog.data.QualifiedMetacardType) MetacardType(ddf.catalog.data.MetacardType) Test(org.junit.Test)

Example 12 with MetacardType

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

the class QualifiedMetacardTypeTest method testDefaultNamespace.

@Test
public void testDefaultNamespace() {
    MetacardType mt1 = new MetacardTypeImpl(QUALIFIED_METACARD_TYPE_NAME_3, qmtAttributes);
    QualifiedMetacardTypeImpl qmt1 = new QualifiedMetacardTypeImpl(QualifiedMetacardType.DEFAULT_METACARD_TYPE_NAMESPACE, mt1);
    MetacardType mt2 = new MetacardTypeImpl(QUALIFIED_METACARD_TYPE_NAME_3, qmtAttributes);
    QualifiedMetacardTypeImpl qmt2 = new QualifiedMetacardTypeImpl(null, mt2);
    assertTrue(qmt1.equals(qmt2));
    assertTrue(qmt2.equals(qmt1));
    assertTrue(qmt1.hashCode() == qmt2.hashCode());
}
Also used : QualifiedMetacardType(ddf.catalog.data.QualifiedMetacardType) MetacardType(ddf.catalog.data.MetacardType) Test(org.junit.Test)

Example 13 with MetacardType

use of ddf.catalog.data.MetacardType 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 14 with MetacardType

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

the class MetacardTypeImplTest method testValidationType.

@Test
public void testValidationType() {
    List<MetacardType> metacardTypeList = new ArrayList<>();
    metacardTypeList.add(VALIDATION_ATTRIBUTES);
    MetacardType metacardType = new MetacardTypeImpl(TEST_NAME, metacardTypeList);
    assertMetacardAttributes(metacardType, CORE_ATTRIBUTES.getAttributeDescriptors());
    assertMetacardAttributes(metacardType, VALIDATION_ATTRIBUTES.getAttributeDescriptors());
}
Also used : ArrayList(java.util.ArrayList) MetacardType(ddf.catalog.data.MetacardType) Test(org.junit.Test)

Example 15 with MetacardType

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

the class MetacardTypeImplTest method testTopicType.

@Test
public void testTopicType() {
    List<MetacardType> metacardTypeList = new ArrayList<>();
    metacardTypeList.add(TOPIC_ATTRIBUTES);
    MetacardType metacardType = new MetacardTypeImpl(TEST_NAME, metacardTypeList);
    assertMetacardAttributes(metacardType, CORE_ATTRIBUTES.getAttributeDescriptors());
    assertMetacardAttributes(metacardType, TOPIC_ATTRIBUTES.getAttributeDescriptors());
}
Also used : ArrayList(java.util.ArrayList) MetacardType(ddf.catalog.data.MetacardType) Test(org.junit.Test)

Aggregations

MetacardType (ddf.catalog.data.MetacardType)88 Test (org.junit.Test)57 AttributeDescriptor (ddf.catalog.data.AttributeDescriptor)41 Metacard (ddf.catalog.data.Metacard)35 ArrayList (java.util.ArrayList)29 MetacardImpl (ddf.catalog.data.impl.MetacardImpl)20 MetacardTypeImpl (ddf.catalog.data.impl.MetacardTypeImpl)17 HashSet (java.util.HashSet)15 Attribute (ddf.catalog.data.Attribute)12 Serializable (java.io.Serializable)10 IOException (java.io.IOException)8 Date (java.util.Date)8 HashMap (java.util.HashMap)8 List (java.util.List)8 Map (java.util.Map)8 AttributeDescriptorImpl (ddf.catalog.data.impl.AttributeDescriptorImpl)7 InputStream (java.io.InputStream)7 Set (java.util.Set)7 ContentItem (ddf.catalog.content.data.ContentItem)6 ContentItemImpl (ddf.catalog.content.data.impl.ContentItemImpl)6