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();
}
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));
}
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);
}
use of ddf.catalog.data.AttributeDescriptor in project ddf by codice.
the class AttributeRegistryImplTest method testRemoveAttribute.
@Test
public void testRemoveAttribute() {
final String attributeName = "attribute";
final AttributeDescriptor descriptor = new AttributeDescriptorImpl(attributeName, true, false, true, false, BasicTypes.STRING_TYPE);
registry.register(descriptor);
Optional<AttributeDescriptor> descriptorOptional = registry.lookup(attributeName);
assertThat(descriptorOptional.isPresent(), is(true));
registry.deregister(descriptor);
descriptorOptional = registry.lookup(attributeName);
assertThat(descriptorOptional.isPresent(), is(false));
}
use of ddf.catalog.data.AttributeDescriptor in project ddf by codice.
the class AttributeRegistryImplTest method testAddAttributeWithSameName.
@Test
public void testAddAttributeWithSameName() {
final String attributeName = "foo";
final AttributeDescriptor descriptor1 = new AttributeDescriptorImpl(attributeName, true, true, true, true, BasicTypes.STRING_TYPE);
registry.register(descriptor1);
final AttributeDescriptor descriptor2 = new AttributeDescriptorImpl(attributeName, false, false, false, false, BasicTypes.BINARY_TYPE);
registry.register(descriptor2);
final Optional<AttributeDescriptor> descriptorOptional = registry.lookup(attributeName);
assertThat(descriptorOptional.isPresent(), is(true));
assertThat(descriptorOptional.get(), is(descriptor1));
}
Aggregations