checkOpen();
final Map<String, NodeData> aggregateRoots = new HashMap<String, NodeData>();
final Set<String> removedNodeIds = new HashSet<String>();
final Set<String> addedNodeIds = new HashSet<String>();
index.update(IteratorUtils.toList(new TransformIterator(remove, new Transformer()
{
public Object transform(Object input)
{
String uuid = ((String)input);
removedNodeIds.add(uuid);
return uuid;
}
})), IteratorUtils.toList(new TransformIterator(add, new Transformer()
{
public Object transform(Object input)
{
NodeData state = (NodeData)input;
if (state == null)
{
return null;
}
String uuid = state.getIdentifier();
addedNodeIds.add(uuid);
removedNodeIds.remove(uuid);
Document doc = null;
try
{
doc = createDocument(state, getNamespaceMappings(), index.getIndexFormatVersion());
retrieveAggregateRoot(state, aggregateRoots);
}
catch (RepositoryException e)
{
log
.warn("Exception while creating document for node: " + state.getIdentifier() + ": " + e.toString(), e);
}
return doc;
}
})));
// remove any aggregateRoot nodes that are new
// and therefore already up-to-date
aggregateRoots.keySet().removeAll(addedNodeIds);
// based on removed UUIDs get affected aggregate root nodes
retrieveAggregateRoot(removedNodeIds, aggregateRoots);
// update aggregates if there are any affected
if (aggregateRoots.size() > 0)
{
Collection modified = TransformedCollection.decorate(new ArrayList(), new Transformer()
{
public Object transform(Object input)
{
NodeData state = (NodeData)input;
try