in src/main/java/org/apache/sling/pipes/internal/MovePipe.java [125:147]
private Iterator<Resource> reorder(Resource input, Resource target) throws RepositoryException, PersistenceException {
if (target != null && !isDryRun()) {
logger.info("ordering {} before {}", input.getPath(), target != null);
Resource parent = target.getParent();
if (parent != null) {
Node targetParent = parent.adaptTo(Node.class);
String oldNodeName = target.getName();
if (targetParent != null && targetParent.getPrimaryNodeType().hasOrderableChildNodes()) {
String targetNodeName = ResourceUtil.createUniqueChildName(parent, input.getName());
String targetNodePath = targetParent.getPath() + SLASH + targetNodeName;
Session session = resolver.adaptTo(Session.class);
if (session != null) {
session.move(input.getPath(), targetNodePath);
targetParent.orderBefore(targetNodeName, oldNodeName);
return Collections.singleton(parent.getChild(targetNodeName)).iterator();
}
} else {
logger.warn("parent resource {} doesn't support ordering", parent.getPath());
}
}
}
return EMPTY_ITERATOR;
}