// We can't delete the node, since later same-name-siblings might be changed. So delete the children ...
process(new DeleteChildrenRequest(startingLocation, workspaceName));
}
// Now update all of the properties, removing any that are no longer needed ...
Location topNode = locationIter.next();
assert topNode.equals(startingLocation);
Map<Name, Property> properties = readSubgraph.getPropertiesFor(topNode);
if (properties == null) return;
if (startingLocation.getPath().isRoot()) {
// The properties of the root node generally don't include the primary type, but we need to add it here ...
Property rootPrimaryType = context.getPropertyFactory().create(JcrLexicon.PRIMARY_TYPE, DnaLexicon.ROOT);
properties.put(JcrLexicon.PRIMARY_TYPE, rootPrimaryType);
}
UpdatePropertiesRequest request = new UpdatePropertiesRequest(topNode, workspaceName, properties, true);
request.setActualLocationOfNode(topNode);
process(request);
checkRequestForErrors(request);
// Create a queue that we'll use to walk the content ...
LinkedList<Location> locationsToRead = new LinkedList<Location>();
// Now walk the remaining nodes in the subgraph ...
while (true) {
while (locationIter.hasNext()) {
// Index the node ...
Location location = locationIter.next();
Path path = location.getPath();
Location parent = readSubgraph.getLocationFor(path.getParent());
Name childName = path.getLastSegment().getName();
Collection<Property> nodePoperties = readSubgraph.getPropertiesFor(location).values();
CreateNodeRequest create = new CreateNodeRequest(parent, workspaceName, childName, nodePoperties);
create.setActualLocationOfNode(location); // set this so we don't have to figure it out
process(create);
if (create.isCancelled() || create.hasError()) return;
// Process the children ...
for (Location child : readSubgraph.getChildren(location)) {
if (!readSubgraph.includes(child)) {
// Record this location as needing to be read ...
locationsToRead.add(child);
}
}
}
if (locationsToRead.isEmpty()) break;
Location location = locationsToRead.poll();
assert location != null;
// Recompute the depth per read ...
depthPerRead = depth - location.getPath().size();
if (depthPerRead < 1) continue;
readSubgraph = new ReadBranchRequest(location, workspaceName, depthPerRead);
try {
channel.addAndAwait(readSubgraph);
} catch (InterruptedException e) {