Author: chetanm
Date: Mon Feb 29 14:06:32 2016
New Revision: 1732898

URL: http://svn.apache.org/viewvc?rev=1732898&view=rev
Log:
OAK-4071 - Include node path in VersionException

Modified:
    
jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/session/NodeImpl.java

Modified: 
jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/session/NodeImpl.java
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/session/NodeImpl.java?rev=1732898&r1=1732897&r2=1732898&view=diff
==============================================================================
--- 
jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/session/NodeImpl.java
 (original)
+++ 
jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/session/NodeImpl.java
 Mon Feb 29 14:06:32 2016
@@ -19,6 +19,7 @@ package org.apache.jackrabbit.oak.jcr.se
 import static com.google.common.base.Preconditions.checkNotNull;
 import static com.google.common.collect.Iterators.transform;
 import static com.google.common.collect.Sets.newLinkedHashSet;
+import static java.lang.String.format;
 import static java.util.Arrays.asList;
 import static java.util.Collections.singleton;
 import static org.apache.jackrabbit.JcrConstants.JCR_MIXINTYPES;
@@ -226,7 +227,7 @@ public class NodeImpl<T extends NodeDele
 
             @Override
             public String toString() {
-                return String.format("Removing node [%s]", dlg.getPath());
+                return format("Removing node [%s]", dlg.getPath());
             }
         });
     }
@@ -295,14 +296,14 @@ public class NodeImpl<T extends NodeDele
 
                 NodeDelegate added = parent.addChild(oakName, oakTypeName);
                 if (added == null) {
-                    throw new ItemExistsException();
+                    throw new ItemExistsException(format("Node [%s/%s] 
exists", getNodePath(),oakName));
                 }
                 return createNode(added, sessionContext);
             }
 
             @Override
             public String toString() {
-                return String.format("Adding node [%s/%s]", dlg.getPath(), 
relPath);
+                return format("Adding node [%s/%s]", dlg.getPath(), relPath);
             }
         });
     }
@@ -743,7 +744,7 @@ public class NodeImpl<T extends NodeDele
                 if (isNodeType(NodeType.MIX_REFERENCEABLE)) {
                     return getIdentifier();
                 }
-                throw new UnsupportedRepositoryOperationException("Node is not 
referenceable.");
+                throw new UnsupportedRepositoryOperationException(format("Node 
[%s] is not referenceable.", getNodePath()));
             }
         });
     }
@@ -884,7 +885,7 @@ public class NodeImpl<T extends NodeDele
                 if (primaryTypeName != null) {
                     return 
getNodeTypeManager().getNodeType(sessionContext.getJcrName(primaryTypeName));
                 } else {
-                    throw new RepositoryException("Unable to retrieve primary 
type for Node " + getPath());
+                    throw new RepositoryException("Unable to retrieve primary 
type for Node " + getNodePath());
                 }
             }
         });
@@ -937,7 +938,7 @@ public class NodeImpl<T extends NodeDele
             public void checkPreconditions() throws RepositoryException {
                 super.checkPreconditions();
                 if (!isCheckedOut()) {
-                    throw new VersionException("Cannot set primary type. Node 
is checked in.");
+                    throw new VersionException(format("Cannot set primary 
type. Node [%s] is checked in.", getNodePath()));
                 }
             }
 
@@ -956,8 +957,8 @@ public class NodeImpl<T extends NodeDele
             public void checkPreconditions() throws RepositoryException {
                 super.checkPreconditions();
                 if (!isCheckedOut()) {
-                    throw new VersionException(
-                            "Cannot add mixin type. Node is checked in.");
+                    throw new VersionException(format(
+                            "Cannot add mixin type. Node [%s] is checked in.", 
getNodePath()));
                 }
             }
             @Override
@@ -975,8 +976,8 @@ public class NodeImpl<T extends NodeDele
             public void checkPreconditions() throws RepositoryException {
                 super.checkPreconditions();
                 if (!isCheckedOut()) {
-                    throw new VersionException(
-                            "Cannot remove mixin type. Node is checked in.");
+                    throw new VersionException(format(
+                            "Cannot remove mixin type. Node [%s] is checked 
in.", getNodePath()));
                 }
 
                 // check for NODE_TYPE_MANAGEMENT permission here as we cannot
@@ -1042,7 +1043,7 @@ public class NodeImpl<T extends NodeDele
                 if (workspaceName.equals(sessionDelegate.getWorkspaceName())) {
                     return item.getPath();
                 } else {
-                    throw new 
UnsupportedRepositoryOperationException("OAK-118: 
Node.getCorrespondingNodePath");
+                    throw new 
UnsupportedRepositoryOperationException("OAK-118: Node.getCorrespondingNodePath 
at " + getNodePath());
                 }
             }
         }));
@@ -1058,13 +1059,13 @@ public class NodeImpl<T extends NodeDele
 
                 // check for pending changes
                 if (sessionDelegate.hasPendingChanges()) {
-                    String msg = "Unable to perform operation. Session has 
pending changes.";
+                    String msg = format("Unable to perform operation. Session 
has pending changes. Node [%s]", getNodePath());
                     LOG.debug(msg);
                     throw new InvalidItemStateException(msg);
                 }
 
                 if (!srcWorkspace.equals(sessionDelegate.getWorkspaceName())) {
-                    throw new 
UnsupportedRepositoryOperationException("OAK-118: Node.update");
+                    throw new 
UnsupportedRepositoryOperationException("OAK-118: Node.update at " + 
getNodePath());
                 }
             }
         });
@@ -1132,7 +1133,7 @@ public class NodeImpl<T extends NodeDele
     @Override
     public void restore(String versionName, boolean removeExisting) throws 
RepositoryException {
         if (!isNodeType(NodeType.MIX_VERSIONABLE)) {
-            throw new UnsupportedRepositoryOperationException("Node is not 
mix:versionable");
+            throw new UnsupportedRepositoryOperationException(format("Node 
[%s] is not mix:versionable", getNodePath()));
         }
         getVersionManager().restore(getPath(), versionName, removeExisting);
     }
@@ -1143,14 +1144,14 @@ public class NodeImpl<T extends NodeDele
     @Override
     public void restore(Version version, boolean removeExisting) throws 
RepositoryException {
         if (!isNodeType(NodeType.MIX_VERSIONABLE)) {
-            throw new UnsupportedRepositoryOperationException("Node is not 
mix:versionable");
+            throw new UnsupportedRepositoryOperationException(format("Node 
[%s] is not mix:versionable", getNodePath()));
         }
         String id = version.getContainingHistory().getVersionableIdentifier();
         if (getIdentifier().equals(id)) {
             getVersionManager().restore(version, removeExisting);
         } else {
-            throw new VersionException("Version does not belong to the " +
-                    "VersionHistory of this node.");
+            throw new VersionException(format("Version does not belong to the 
" +
+                    "VersionHistory of this node [%s].", getNodePath()));
         }
     }
 
@@ -1343,7 +1344,7 @@ public class NodeImpl<T extends NodeDele
         // TODO: figure out the right place for this check
         NodeType nt = getNodeTypeManager().getNodeType(nodeTypeName); // 
throws on not found
         if (nt.isAbstract() || nt.isMixin()) {
-            throw new ConstraintViolationException();
+            throw new ConstraintViolationException(getNodePath());
         }
         // TODO: END
 
@@ -1364,8 +1365,8 @@ public class NodeImpl<T extends NodeDele
             public void checkPreconditions() throws RepositoryException {
                 super.checkPreconditions();
                 if (!isCheckedOut()) {
-                    throw new VersionException(
-                            "Cannot set property. Node is checked in.");
+                    throw new VersionException(format(
+                            "Cannot set property. Node [%s] is checked in.", 
getNodePath()));
                 }
             }
             @Nonnull
@@ -1378,7 +1379,7 @@ public class NodeImpl<T extends NodeDele
 
             @Override
             public String toString() {
-                return String.format("Setting property [%s/%s]", 
dlg.getPath(), jcrName);
+                return format("Setting property [%s/%s]", dlg.getPath(), 
jcrName);
             }
         });
     }
@@ -1400,8 +1401,8 @@ public class NodeImpl<T extends NodeDele
             public void checkPreconditions() throws RepositoryException {
                 super.checkPreconditions();
                 if (!isCheckedOut()) {
-                    throw new VersionException(
-                            "Cannot set property. Node is checked in.");
+                    throw new VersionException(format(
+                            "Cannot set property. Node [%s] is checked in.", 
getNodePath()));
                 }
             }
             @Nonnull
@@ -1414,7 +1415,7 @@ public class NodeImpl<T extends NodeDele
 
             @Override
             public String toString() {
-                return String.format("Setting property [%s/%s]", 
dlg.getPath(), jcrName);
+                return format("Setting property [%s/%s]", dlg.getPath(), 
jcrName);
             }
         });
     }
@@ -1444,8 +1445,8 @@ public class NodeImpl<T extends NodeDele
             public void checkPreconditions() throws RepositoryException {
                 super.checkPreconditions();
                 if (!isCheckedOut()) {
-                    throw new VersionException(
-                            "Cannot remove property. Node is checked in.");
+                    throw new VersionException(format(
+                            "Cannot remove property. Node [%s] is checked 
in.", getNodePath()));
                 }
             }
             @Nonnull
@@ -1463,7 +1464,7 @@ public class NodeImpl<T extends NodeDele
 
             @Override
             public String toString() {
-                return String.format("Removing property [%s]", jcrName);
+                return format("Removing property [%s]", jcrName);
             }
         });
     }
@@ -1570,7 +1571,7 @@ public class NodeImpl<T extends NodeDele
             public void checkPreconditions() throws RepositoryException {
                 super.checkPreconditions();
                 if (!isCheckedOut()) {
-                    throw new VersionException("Cannot set mixin types. Node 
is checked in.");
+                    throw new VersionException(format("Cannot set mixin types. 
Node [%s] is checked in.", getNodePath()));
                 }
 
                 // check for NODE_TYPE_MANAGEMENT permission here as we cannot
@@ -1589,6 +1590,15 @@ public class NodeImpl<T extends NodeDele
         });
     }
 
+    /**
+     * Provide current node path. Should be invoked from within
+     * the SessionDelegate#perform and preferred instead of getPath
+     * as it provides direct access to path
+     */
+    private String getNodePath(){
+        return dlg.getPath();
+    }
+
     private static class PropertyIteratorDelegate {
         private final NodeDelegate node;
         private final Predicate<PropertyDelegate> predicate;


Reply via email to