use of ddf.catalog.data.Attribute 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.Attribute in project ddf by codice.
the class TestMetacardResourceSizePlugin method testWhenNoCachedResourceFound.
@Test
public void testWhenNoCachedResourceFound() throws Exception {
ResourceCacheInterface cache = mock(ResourceCacheInterface.class);
when(cache.getValid(anyString(), (Metacard) anyObject())).thenReturn(null);
MetacardImpl metacard = new MetacardImpl();
metacard.setId("abc123");
metacard.setSourceId("ddf-1");
metacard.setResourceSize("N/A");
Result result = new ResultImpl(metacard);
List<Result> results = new ArrayList<Result>();
results.add(result);
QueryResponse input = mock(QueryResponse.class);
when(input.getResults()).thenReturn(results);
MetacardResourceSizePlugin plugin = new MetacardResourceSizePlugin(cache);
QueryResponse queryResponse = plugin.process(input);
assertThat(queryResponse.getResults().size(), is(1));
Metacard resultMetacard = queryResponse.getResults().get(0).getMetacard();
assertThat(metacard, is(notNullValue()));
// Since using Metacard vs. MetacardImpl have to get resource-size as an
// Attribute vs. Long
Attribute resourceSizeAttr = resultMetacard.getAttribute(Metacard.RESOURCE_SIZE);
assertThat((String) resourceSizeAttr.getValue(), equalTo("N/A"));
}
use of ddf.catalog.data.Attribute in project ddf by codice.
the class MetacardResourceStatusTest method testMetacardResourceIsNotLocal4.
/**
* Metacard source id is remote, Metacard contains remote resource uri, Metacard resource is not
* cached
*/
@Test
public void testMetacardResourceIsNotLocal4() throws Exception {
setupCache(false);
setupSingleResultResponseMock(getBasicMetacard(REMOTE_SITE_NAME, REMOTE_RESOURCE_URI));
MetacardResourceStatus plugin = getMetacardResourceStatusPlugin();
Attribute resourceStatusAttribute = getInternalLocalResurceAttribute(plugin.process(queryResponse));
assertThat(resourceStatusAttribute.getValue(), is(false));
}
use of ddf.catalog.data.Attribute in project ddf by codice.
the class MetacardResourceStatusTest method testMetacardResourceIsNotLocal3.
/**
* Metacard source id is remote, Metacard contains content resource uri, Metacard resource is not
* cached
*/
@Test
public void testMetacardResourceIsNotLocal3() throws Exception {
setupCache(false);
setupSingleResultResponseMock(getBasicMetacard(REMOTE_SITE_NAME, CONTENT_RESOURCE_URI));
MetacardResourceStatus plugin = getMetacardResourceStatusPlugin();
Attribute resourceStatusAttribute = getInternalLocalResurceAttribute(plugin.process(queryResponse));
assertThat(resourceStatusAttribute.getValue(), is(false));
}
use of ddf.catalog.data.Attribute in project ddf by codice.
the class MetacardResourceStatusTest method testMetacardResourceIsNotLocal1.
/**
* Metacard source id is local, Metacard contains no resource uri, Metacard resource is not cached
*/
@Test
public void testMetacardResourceIsNotLocal1() throws Exception {
setupCache(false);
setupSingleResultResponseMock(getBasicMetacard(LOCAL_SITE_NAME, null));
MetacardResourceStatus plugin = getMetacardResourceStatusPlugin();
Attribute resourceStatusAttribute = getInternalLocalResurceAttribute(plugin.process(queryResponse));
assertThat(resourceStatusAttribute.getValue(), is(false));
}
Aggregations