use of org.codice.ddf.catalog.ui.metacard.edit.AttributeChange in project ddf by codice.
the class MetacardApplication method patchMetacards.
protected UpdateResponse patchMetacards(List<MetacardChanges> metacardChanges) throws SourceUnavailableException, IngestException, FederationException, UnsupportedQueryException {
Set<String> changedIds = metacardChanges.stream().flatMap(mc -> mc.getIds().stream()).collect(Collectors.toSet());
Map<String, Result> results = util.getMetacards(changedIds, "*");
for (MetacardChanges changeset : metacardChanges) {
for (AttributeChange attributeChange : changeset.getAttributes()) {
for (String id : changeset.getIds()) {
List<String> values = attributeChange.getValues();
Metacard result = results.get(id).getMetacard();
Function<Serializable, Serializable> mapFunc = Function.identity();
if (isChangeTypeDate(attributeChange, result)) {
mapFunc = mapFunc.andThen(util::parseDate);
}
result.setAttribute(new AttributeImpl(attributeChange.getAttribute(), values.stream().filter(Objects::nonNull).map(mapFunc).collect(Collectors.toList())));
}
}
}
List<Metacard> changedMetacards = results.values().stream().map(Result::getMetacard).collect(Collectors.toList());
return catalogFramework.update(new UpdateRequestImpl(changedMetacards.stream().map(Metacard::getId).collect(Collectors.toList()).toArray(new String[0]), changedMetacards));
}
Aggregations