]> git.argeo.org Git - lgpl/argeo-commons.git/blobdiff - server/runtime/org.argeo.server.jcr/src/main/java/org/argeo/jcr/JcrUtils.java
Add a command to get node property type as cnd like string
[lgpl/argeo-commons.git] / server / runtime / org.argeo.server.jcr / src / main / java / org / argeo / jcr / JcrUtils.java
index b03be7396bdce3cd4b17733bd73058d5692d60d7..f62196cafe3663de56e1e2ce544832c02ad40fce 100644 (file)
@@ -858,7 +858,8 @@ public class JcrUtils implements ArgeoJcrConstants {
                                } catch (Exception e) {
                                        // we use this workaround to be sure to get the stack trace
                                        // to identify the sink of the bug.
-                                       log.warn("trying to create an already existing userHome. Stack trace : ");
+                                       log.warn("trying to create an already existing userHome at path:"
+                                                       + homePath + ". Stack trace : ");
                                        e.printStackTrace();
                                }
                        }
@@ -866,8 +867,8 @@ public class JcrUtils implements ArgeoJcrConstants {
                        Node userHome = JcrUtils.mkdirs(session, homePath);
                        Node userProfile;
                        if (userHome.hasNode(ArgeoNames.ARGEO_PROFILE)) {
-                               log.warn("User profile node already exists. We do not add a new one");
-
+                               log.warn("userProfile node already exists for userHome path: "
+                                               + homePath + ". We do not add a new one");
                        } else {
                                userProfile = userHome.addNode(ArgeoNames.ARGEO_PROFILE);
                                userProfile.addMixin(ArgeoTypes.ARGEO_USER_PROFILE);
@@ -940,4 +941,31 @@ public class JcrUtils implements ArgeoJcrConstants {
                        throw new ArgeoException("Cannot update last modified", e);
                }
        }
+
+       /**
+        * Returns a String representing the short version (see <a
+        * href="http://jackrabbit.apache.org/node-type-notation.html"> Node type
+        * Notation </a> attributes grammar) of the main business attributes of this
+        * property definition
+        * 
+        * @param prop
+        */
+       public static String getPropertyDefinitionAsString(Property prop) {
+               StringBuffer sbuf = new StringBuffer();
+               try {
+                       if (prop.getDefinition().isAutoCreated())
+                               sbuf.append("a");
+                       if (prop.getDefinition().isMandatory())
+                               sbuf.append("m");
+                       if (prop.getDefinition().isProtected())
+                               sbuf.append("p");
+                       if (prop.getDefinition().isMultiple())
+                               sbuf.append("*");
+               } catch (RepositoryException re) {
+                       throw new ArgeoException(
+                                       "unexpected error while getting property definition as String",
+                                       re);
+               }
+               return sbuf.toString();
+       }
 }