use of ddf.catalog.data.Attribute in project ddf by codice.
the class TestGenericXmlLib method getNewHandler.
private SaxEventHandler getNewHandler() {
Attribute attribute = new AttributeImpl(Metacard.TITLE, "foo");
Attribute attribute2 = new AttributeImpl(Metacard.TITLE, "bar");
SaxEventHandler handler = mock(SaxEventHandler.class);
when(handler.getAttributes()).thenReturn(Arrays.asList(attribute, attribute2));
return handler;
}
use of ddf.catalog.data.Attribute in project ddf by codice.
the class RangeCommand method executeWithSubject.
@Override
protected Object executeWithSubject() throws Exception {
String formatString = "%1$-7s %2$-33s %3$-26s %4$-" + MAX_LENGTH + "s%n";
console.printf(formatString, "", "", "", "");
printHeaderMessage(String.format(formatString, NUMBER, ID, attributeName, TITLE));
Filter filter;
Date wayInTheFuture = new DateTime().plusYears(5000).toDate();
Date wayInThePast = new DateTime().minusYears(5000).toDate();
Date endDate = wayInTheFuture;
Date startDate = wayInThePast;
SimpleDateFormat formatter = new SimpleDateFormat(DATE_FORMAT);
if (WILDCARD.equals(rangeBeginning) && WILDCARD.equals(rangeEnd)) {
filter = filterBuilder.attribute(attributeName).before().date(endDate);
} else if (WILDCARD.equals(rangeBeginning) && !WILDCARD.equals(rangeEnd)) {
try {
endDate = formatter.parse(rangeEnd);
} catch (ParseException e) {
throw new InterruptedException("Could not parse second parameter [" + rangeEnd + "]");
}
filter = filterBuilder.attribute(attributeName).before().date(endDate);
} else if (!WILDCARD.equals(rangeBeginning) && WILDCARD.equals(rangeEnd)) {
try {
startDate = formatter.parse(rangeBeginning);
} catch (ParseException e) {
throw new InterruptedException("Could not parse first parameter [" + rangeBeginning + "]");
}
filter = filterBuilder.attribute(attributeName).during().dates(startDate, endDate);
} else {
try {
startDate = formatter.parse(rangeBeginning);
endDate = formatter.parse(rangeEnd);
} catch (ParseException e) {
throw new InterruptedException("Could not parse date parameters.");
}
filter = filterBuilder.attribute(attributeName).during().dates(startDate, endDate);
}
QueryImpl query = new QueryImpl(filter);
query.setPageSize(MAX_RESULTS);
query.setSortBy(new SortByImpl(attributeName, SortOrder.DESCENDING.name()));
QueryRequest queryRequest = new QueryRequestImpl(query);
SourceResponse response = getCatalog().query(queryRequest);
List<Result> results = response.getResults();
int i = 1;
for (Result result : results) {
Attribute attribute = result.getMetacard().getAttribute(attributeName);
if (attribute != null && attribute.getValue() != null) {
String returnedDate = new DateTime(attribute.getValue()).toString(DATETIME_FORMATTER);
String title = result.getMetacard().getTitle();
console.printf(formatString, i, result.getMetacard().getId(), returnedDate, title.substring(0, Math.min(title.length(), MAX_LENGTH)));
}
i++;
}
return null;
}
use of ddf.catalog.data.Attribute in project ddf by codice.
the class InspectCommand method executeWithSubject.
@Override
protected Object executeWithSubject() throws Exception {
if (id == null) {
return null;
}
Filter filter = filterBuilder.attribute(Metacard.ID).is().equalTo().text(id);
QueryImpl query = new QueryImpl(filter);
SourceResponse response = getCatalog().query(new QueryRequestImpl(query));
String formatString = "%1$s%2$-30s%3$s: %4$-25s %n";
String newLineFormatString = "%1$s%2$-30s%3$s %4$-25s %n";
if (response.getResults() != null && response.getResults().size() > 0) {
Metacard card = response.getResults().get(0).getMetacard();
MetacardType mType = card.getMetacardType();
String rClass = card.getClass().getName();
String siteShortName = card.getSourceId();
console.println("------------------------------");
console.printf(formatString, color(rClass), "Class", color(rClass), rClass);
console.printf(formatString, color(siteShortName), "Sitename", color(siteShortName), siteShortName);
for (AttributeDescriptor ad : mType.getAttributeDescriptors()) {
Attribute attribute = card.getAttribute(ad.getName());
Serializable value = null;
if (attribute != null) {
value = attribute.getValue();
}
// indent items with new lines in the value
if (value != null && (value.toString().contains("\r\n") || value.toString().contains("\n"))) {
String valueString = value.toString();
String[] values = valueString.split("\r\n");
if (values.length < 2) {
values = valueString.split("\n");
}
console.printf(formatString, color(attribute), ad.getName(), color(attribute), values[0]);
for (int i = 1; i < values.length; i++) {
console.printf(newLineFormatString, color(""), "", color(""), values[i]);
}
} else {
console.printf(formatString, color(attribute), ad.getName(), color(attribute), value);
}
}
// make sure we put the console default color back.
console.print(defaultColor());
console.println("------------------------------");
}
return null;
}
use of ddf.catalog.data.Attribute in project ddf by codice.
the class OperationsMetacardSupport method setDefaultValues.
/**
* Updates any empty metacard attributes with those defined in the
* {@link DefaultAttributeValueRegistry}.
*
* @param metacard the metacard to update with default attribute values
*/
void setDefaultValues(Metacard metacard) {
MetacardType metacardType = metacard.getMetacardType();
DefaultAttributeValueRegistry registry = frameworkProperties.getDefaultAttributeValueRegistry();
metacardType.getAttributeDescriptors().stream().map(AttributeDescriptor::getName).filter(attributeName -> hasNoValue(metacard.getAttribute(attributeName))).forEach(attributeName -> {
registry.getDefaultValue(metacardType.getName(), attributeName).ifPresent(defaultValue -> metacard.setAttribute(new AttributeImpl(attributeName, defaultValue)));
});
}
use of ddf.catalog.data.Attribute in project ddf by codice.
the class PointOfContactPolicyPlugin method pointOfContactChanged.
private boolean pointOfContactChanged(Metacard newMetacard, Metacard previousMetacard) {
Attribute newPointOfContact = newMetacard.getAttribute(Metacard.POINT_OF_CONTACT);
Attribute oldPointOfContact = previousMetacard.getAttribute(Metacard.POINT_OF_CONTACT);
if (newPointOfContact != null && oldPointOfContact != null) {
return !newPointOfContact.getValue().equals(oldPointOfContact.getValue());
}
//Return true if only one of them is null
return newPointOfContact != oldPointOfContact;
}
Aggregations