}
}
private ImportInfoImpl commit(Session session, TxInfo info) throws RepositoryException, IOException {
log.debug("committing {}", info.path);
ImportInfoImpl imp = null;
if (info.artifacts == null) {
log.debug("S {}", info.path);
} else if (info.artifacts.isEmpty()) {
// intermediate directory, check if node exists and filter
// matches. in this case remove the node (bug #25370)
// but only if intermediate is not processed yet (bug #42562)
if (filter.contains(info.path) && session.nodeExists(info.path) && info.isIntermediate < 2) {
Node node = session.getNode(info.path);
imp = new ImportInfoImpl();
if (aclManagement.isACLNode(node)) {
if (opts.getAccessControlHandling() == AccessControlHandling.OVERWRITE
|| opts.getAccessControlHandling() == AccessControlHandling.CLEAR) {
imp.onDeleted(info.path);
aclManagement.clearACL(node.getParent());
}
} else {
imp.onDeleted(info.path);
node.remove();
}
}
} else if (info.artifacts.getPrimaryData() !=null && info.artifacts.size() == 1) {
// simple case, only 1 primary artifact
Node node = info.getParentNode(session);
if (node == null) {
imp = new ImportInfoImpl();
imp.onError(info.path, new IllegalStateException("Parent node not found."));
} else {
imp = genericHandler.accept(filter, node, info.artifacts.getPrimaryData().getRelativePath(), info.artifacts);
if (imp == null) {
throw new IllegalStateException("generic handler did not accept " + info.path);
}
}
} else if (info.artifacts.getDirectory() != null) {
for (TxInfo child: info.children().values()) {
// add the directory artifacts as hint to this one.
if (child.artifacts == null) {
// in this case it's some deleted intermediate directory???
String path = info.name + "/" + child.name;
info.artifacts.add(new HintArtifact(path));
} else {
for (Artifact a: child.artifacts.values()) {
String path = info.name + "/" + a.getRelativePath();
info.artifacts.add(new HintArtifact(path));
}
}
}
Node node = info.getParentNode(session);
if (node == null) {
imp = new ImportInfoImpl();
imp.onError(info.path, new IllegalStateException("Parent node not found."));
} else {
if (info.isIntermediate == 2) {
// skip existing intermediate
log.debug("skipping intermediate node at {}", info.path);
} else if (info.artifacts.getPrimaryData() == null) {
// create nt:folder node if not exists
imp = folderHandler.accept(filter, node, info.name, info.artifacts);
if (imp == null) {
throw new IllegalStateException("folder handler did not accept " + info.path);
}
} else {
imp = genericHandler.accept(filter, node, info.artifacts.getDirectory().getRelativePath(), info.artifacts);
if (imp == null) {
throw new IllegalStateException("generic handler did not accept " + info.path);
}
}
}
} else if (info.artifacts.size(ArtifactType.FILE) > 0) {
Node node = info.getParentNode(session);
if (node == null) {
imp = new ImportInfoImpl();
imp.onError(info.path, new IllegalStateException("Parent node not found."));
} else {
imp = fileHandler.accept(filter, node, info.name, info.artifacts);
if (imp == null) {
throw new IllegalStateException("file handler did not accept " + info.path);
}
}
} else {
throw new UnsupportedOperationException("ArtifactSet not supported: " + info.artifacts);
}
if (imp != null) {
for (Map.Entry<String, ImportInfoImpl.Type> entry: imp.getModifications().entrySet()) {
String path = entry.getKey();
ImportInfoImpl.Type type = entry.getValue();
if (type != ImportInfoImpl.Type.DEL) {
// mark intermediates as processed
TxInfo im = intermediates.remove(path);
if (im != null) {
log.debug("P {}", path);
removedIntermediates.put(path, im);
im.isIntermediate = 2;
}
}
switch (type) {
case CRE:
track("A", path);
autoSave.markResolved(path);
break;
case DEL:
track("D", path);
autoSave.markResolved(path);
break;
case MOD:
track("U", path);
autoSave.markResolved(path);
break;
case NOP:
track("-", path);
autoSave.markResolved(path);
break;
case REP:
track("R", path);
autoSave.markResolved(path);
break;
case MIS:
track("!", path);
autoSave.markMissing(path);
break;
case ERR:
Exception error = imp.getError(path);
if (error == null) {
track("E", path);
} else {
track(error, path);
}
hasErrors = true;
break;
}
}
// see if any child nodes need to be reordered and remember namelist. we can only reorder the children
if (imp.getNameList() != null && imp.getNode() != null && imp.getNameList().needsReorder(imp.getNode())) {
// only restore order if in filter scope (bug #31906)
// or if freshly created (bug #32075)
if (filter.contains(info.path) || imp.getModifications().get(info.path) == ImportInfo.Type.CRE) {
assert(info.path.equals(imp.getNode().getPath()));
log.debug("remember to be reordered. path={} node.path={}", info.path, imp.getNode().getPath());
info.nameList = imp.getNameList();
}
}
// check if node was remapped. currently we just skip them as it's not clear how the filter should be
// reapplied or what happens if the remapping links to a tree we already processed.
// in this case we don't descend in any children and can clear them right away
if (imp.getRemapped().containsKey(info.path)) {
info.children = null;
}
}
log.debug("committed {}", info.path);
return imp;