Search in sources :

Example 61 with Attribute

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

the class AdaptedMetacard method setAttribute.

/*
     * (non-Javadoc)
     * 
     * @see ddf.catalog.data.MetacardImpl#setAttribute(ddf.catalog.data.Attribute)
     */
@Override
public final void setAttribute(Attribute attribute) {
    if (attribute != null) {
        if (Metacard.ID.equals(attribute.getName())) {
            this.id = attribute;
        } else {
            Attribute currentAttribute = getAttribute(attribute.getName());
            if (currentAttribute != null) {
                attributes.remove(currentAttribute);
            }
            attributes.add(attribute);
        }
    }
}
Also used : XmlAttribute(javax.xml.bind.annotation.XmlAttribute) Attribute(ddf.catalog.data.Attribute)

Example 62 with Attribute

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

the class DuplicationValidator method reportDuplicates.

private ValidationViolation reportDuplicates(final Metacard metacard, String[] attributeNames, ValidationViolation.Severity severity) {
    Set<String> duplicates = new HashSet<>();
    ValidationViolation violation = null;
    final Set<String> uniqueAttributeNames = Stream.of(attributeNames).filter(attribute -> metacard.getAttribute(attribute) != null).collect(Collectors.toSet());
    final Set<Attribute> uniqueAttributes = uniqueAttributeNames.stream().map(attribute -> metacard.getAttribute(attribute)).collect(Collectors.toSet());
    if (!uniqueAttributes.isEmpty()) {
        LOGGER.debug("Checking for duplicates for id {} against attributes [{}]", metacard.getId(), collectionToString(uniqueAttributeNames));
        SourceResponse response = query(uniqueAttributes, metacard.getId());
        if (response != null) {
            response.getResults().forEach(result -> duplicates.add(result.getMetacard().getId()));
        }
        if (!duplicates.isEmpty()) {
            violation = createViolation(uniqueAttributeNames, duplicates, severity);
            LOGGER.debug(violation.getMessage());
        }
    }
    return violation;
}
Also used : QueryRequestImpl(ddf.catalog.operation.impl.QueryRequestImpl) Arrays(java.util.Arrays) ValidationException(ddf.catalog.validation.ValidationException) ValidationExceptionImpl(ddf.catalog.validation.impl.ValidationExceptionImpl) MetacardValidationReportImpl(ddf.catalog.validation.impl.report.MetacardValidationReportImpl) FilterBuilder(ddf.catalog.filter.FilterBuilder) SourceUnavailableException(ddf.catalog.source.SourceUnavailableException) CatalogFramework(ddf.catalog.CatalogFramework) UnsupportedQueryException(ddf.catalog.source.UnsupportedQueryException) LoggerFactory(org.slf4j.LoggerFactory) HashSet(java.util.HashSet) CollectionUtils(org.apache.commons.collections.CollectionUtils) Metacard(ddf.catalog.data.Metacard) QueryRequest(ddf.catalog.operation.QueryRequest) MetacardValidationReport(ddf.catalog.validation.report.MetacardValidationReport) QueryImpl(ddf.catalog.operation.impl.QueryImpl) Properties(java.util.Properties) Logger(org.slf4j.Logger) MetacardValidator(ddf.catalog.validation.MetacardValidator) Collection(java.util.Collection) Set(java.util.Set) IOException(java.io.IOException) FederationException(ddf.catalog.federation.FederationException) Collectors(java.util.stream.Collectors) ReportingMetacardValidator(ddf.catalog.validation.ReportingMetacardValidator) ValidationViolation(ddf.catalog.validation.violation.ValidationViolation) List(java.util.List) SourceResponse(ddf.catalog.operation.SourceResponse) Stream(java.util.stream.Stream) Attribute(ddf.catalog.data.Attribute) ValidationViolationImpl(ddf.catalog.validation.impl.violation.ValidationViolationImpl) Optional(java.util.Optional) Filter(org.opengis.filter.Filter) Preconditions(com.google.common.base.Preconditions) InputStream(java.io.InputStream) ArrayUtils(org.apache.commons.lang.ArrayUtils) ValidationViolation(ddf.catalog.validation.violation.ValidationViolation) SourceResponse(ddf.catalog.operation.SourceResponse) Attribute(ddf.catalog.data.Attribute) HashSet(java.util.HashSet)

Example 63 with Attribute

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

the class ISO3CountryCodeValidator method buildReport.

private AttributeValidationReport buildReport(Attribute attribute) {
    AttributeValidationReportImpl report = new AttributeValidationReportImpl();
    attribute.getValues().stream().filter(String.class::isInstance).map(String.class::cast).map(ignoreCase ? String::toUpperCase : String::toString).filter(s -> !COUNTRY_CODES.contains(s)).map(s -> new ValidationViolationImpl(Collections.singleton(attribute.getName()), s + " is not a valid ISO_3166-1 Alpha3 country code.", ValidationViolation.Severity.ERROR)).forEach(report::addViolation);
    COUNTRY_CODES.forEach(report::addSuggestedValue);
    return report;
}
Also used : Arrays(java.util.Arrays) Set(java.util.Set) HashCodeBuilder(org.apache.commons.lang.builder.HashCodeBuilder) Collectors(java.util.stream.Collectors) AttributeValidationReport(ddf.catalog.validation.report.AttributeValidationReport) ValidationViolation(ddf.catalog.validation.violation.ValidationViolation) AttributeValidator(ddf.catalog.validation.AttributeValidator) Attribute(ddf.catalog.data.Attribute) AttributeValidationReportImpl(ddf.catalog.validation.impl.report.AttributeValidationReportImpl) ValidationViolationImpl(ddf.catalog.validation.impl.violation.ValidationViolationImpl) Locale(java.util.Locale) EqualsBuilder(org.apache.commons.lang.builder.EqualsBuilder) Optional(java.util.Optional) Preconditions(com.google.common.base.Preconditions) Collections(java.util.Collections) AttributeValidationReportImpl(ddf.catalog.validation.impl.report.AttributeValidationReportImpl) ValidationViolationImpl(ddf.catalog.validation.impl.violation.ValidationViolationImpl)

Example 64 with Attribute

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

the class AttributeImplTest method testSerializationSingle.

@Test
public void testSerializationSingle() throws IOException, ClassNotFoundException {
    Attribute read = serializationLoop(toTest);
    assertEquals(toTest.getName(), read.getName());
    assertEquals(toTest.getValue(), read.getValue());
    assertEquals(toTest.getValues(), read.getValues());
}
Also used : Attribute(ddf.catalog.data.Attribute) Test(org.junit.Test)

Example 65 with Attribute

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

the class AttributeTest method testSerialization.

@Test
public void testSerialization() {
    try {
        // serialize
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        ObjectOutputStream oos = null;
        oos = new ObjectOutputStream(out);
        oos.writeObject(toTest);
        oos.close();
        // deserialize
        byte[] pickled = out.toByteArray();
        InputStream in = new ByteArrayInputStream(pickled);
        ObjectInputStream ois = null;
        ois = new ObjectInputStream(in);
        Object o = null;
        o = ois.readObject();
        Attribute copy = (Attribute) o;
        // test the result
        assertEquals("foo", copy.getName());
        assertEquals("bar", copy.getValue().toString());
    } catch (Exception e) {
        fail(e.getMessage());
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) Attribute(ddf.catalog.data.Attribute) ObjectInputStream(java.io.ObjectInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ObjectOutputStream(java.io.ObjectOutputStream) ObjectInputStream(java.io.ObjectInputStream) 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