Search in sources :

Example 6 with Attribute

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();
}
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 7 with Attribute

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"));
}
Also used : Metacard(ddf.catalog.data.Metacard) Attribute(ddf.catalog.data.Attribute) QueryResponse(ddf.catalog.operation.QueryResponse) ArrayList(java.util.ArrayList) ResultImpl(ddf.catalog.data.impl.ResultImpl) ResourceCacheInterface(ddf.catalog.cache.ResourceCacheInterface) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) Result(ddf.catalog.data.Result) Test(org.junit.Test)

Example 8 with Attribute

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));
}
Also used : Attribute(ddf.catalog.data.Attribute) Test(org.junit.Test)

Example 9 with Attribute

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));
}
Also used : Attribute(ddf.catalog.data.Attribute) Test(org.junit.Test)

Example 10 with Attribute

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));
}
Also used : Attribute(ddf.catalog.data.Attribute) Test(org.junit.Test)

Aggregations

Attribute (ddf.catalog.data.Attribute)103 Metacard (ddf.catalog.data.Metacard)39 Test (org.junit.Test)37 ArrayList (java.util.ArrayList)30 AttributeImpl (ddf.catalog.data.impl.AttributeImpl)29 AttributeDescriptor (ddf.catalog.data.AttributeDescriptor)26 Serializable (java.io.Serializable)23 MetacardImpl (ddf.catalog.data.impl.MetacardImpl)15 HashMap (java.util.HashMap)15 Result (ddf.catalog.data.Result)14 List (java.util.List)14 MetacardType (ddf.catalog.data.MetacardType)11 QueryResponse (ddf.catalog.operation.QueryResponse)11 Date (java.util.Date)11 Map (java.util.Map)11 HashSet (java.util.HashSet)10 Optional (java.util.Optional)8 Set (java.util.Set)8 Filter (org.opengis.filter.Filter)8 UpdateRequestImpl (ddf.catalog.operation.impl.UpdateRequestImpl)7