You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@sling.apache.org by GitBox <gi...@apache.org> on 2019/08/22 10:17:00 UTC

[GitHub] [sling-org-apache-sling-pipes] dichaudhary commented on a change in pull request #10: SLING-8648

dichaudhary commented on a change in pull request #10: SLING-8648
URL: https://github.com/apache/sling-org-apache-sling-pipes/pull/10#discussion_r316598444
 
 

 ##########
 File path: src/main/java/org/apache/sling/pipes/internal/MovePipe.java
 ##########
 @@ -63,23 +67,38 @@ public boolean modifiesContent() {
             try {
                 Session session = resolver.adaptTo(Session.class);
                 if (session.itemExists(targetPath)){
-                    if (overwriteTarget && !isDryRun()) {
-                        logger.debug("overwriting {}", targetPath);
+                    if (overwriteTarget || orderBefore && !isDryRun()) {
+                        Resource target = resolver.getResource(targetPath);
+                        Resource parent = target.getParent();
                         Node targetParent = session.getItem(targetPath).getParent();
-                        if (targetParent.getPrimaryNodeType().hasOrderableChildNodes()) {
-                            String targetPathNewNode = targetPath + UUID.randomUUID() ;
-                            session.move(resource.getPath(), targetPathNewNode);
-                            String newNodeName = targetPathNewNode.substring(targetPathNewNode.lastIndexOf("/") + 1);
-                            String oldNodeName = targetPath.substring(targetPath.lastIndexOf("/") + 1);
-                            targetParent.orderBefore(newNodeName, oldNodeName);
-                            session.removeItem(targetPath);
-                            // Need to use JackrabbitNode.rename() here, since session.move(targetPathNewNode, targetPath)
-                            // would move the new node back to the end of its siblings list
-                            JackrabbitNode newNode = (JackrabbitNode) session.getNode(targetPathNewNode);
-                            newNode.rename(oldNodeName);
+                        String targetPathNewNode = targetPath + UUID.randomUUID();
+                        String newNodeName = targetPathNewNode.substring(targetPathNewNode.lastIndexOf("/") + 1);
+                        String oldNodeName = targetPath.substring(targetPath.lastIndexOf("/") + 1);
+                        if (orderBefore) {
+                            logger.debug("ordering {} before {}", resource.getPath(), targetPath);
+                            if (targetParent.getPrimaryNodeType().hasOrderableChildNodes()) {
+                                String targetNodeName = ResourceUtil.createUniqueChildName(parent, resource.getName());
+                                String targetNodePath = targetParent.getPath() + SLASH + targetNodeName;
+                                session.move(resource.getPath(), targetNodePath);
+                                targetParent.orderBefore(targetNodeName, oldNodeName);
+                                output = Collections.singleton(parent.getChild(targetNodeName)).iterator();
+                            } else {
+                                logger.warn("parent resource {} doesn't support ordering", target.getPath());
+                            }
                         } else {
-                            session.removeItem(targetPath);
-                            session.move(resource.getPath(), targetPath);
+                            logger.debug("overwriting {}", targetPath);
+                            if (targetParent.getPrimaryNodeType().hasOrderableChildNodes()) {
+                                session.move(resource.getPath(), targetPathNewNode);
+                                targetParent.orderBefore(newNodeName, oldNodeName);
 
 Review comment:
   @npeltier  , this part of code was already there which gets triggered when we have overwrite flag set to true , so this basically overwrites the target node .

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services