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