}
/**
- * @deprecated use {@link #mkdirs(Session, String, String, String, Boolean)}
- * instead.
+ * use {@link #mkdirs(Session, String, String, String, Boolean)} instead.
+ *
+ * @deprecated
*/
@Deprecated
public static Node mkdirs(Session session, String path, String type,
if (session.hasPendingChanges())
throw new ArgeoException(
"Session has pending changes, save them first");
+
String homePath = homeBasePath + '/'
+ firstCharsToPath(username, 2) + '/' + username;
- Node userHome = JcrUtils.mkdirs(session, homePath);
- Node userProfile = userHome.addNode(ArgeoNames.ARGEO_PROFILE);
- userProfile.addMixin(ArgeoTypes.ARGEO_USER_PROFILE);
- userProfile.setProperty(ArgeoNames.ARGEO_USER_ID, username);
- session.save();
- // we need to save the profile before adding the user home type
+ if (session.itemExists(homePath)) {
+ try {
+ throw new ArgeoException(
+ "Trying to create a user home that already exists");
+ } 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 at path:"
+ + homePath + ". Stack trace : ");
+ e.printStackTrace();
+ }
+ }
+
+ Node userHome = JcrUtils.mkdirs(session, homePath);
+ Node userProfile;
+ if (userHome.hasNode(ArgeoNames.ARGEO_PROFILE)) {
+ 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);
+ userProfile.setProperty(ArgeoNames.ARGEO_USER_ID, username);
+ session.save();
+ // we need to save the profile before adding the user home type
+ }
userHome.addMixin(ArgeoTypes.ARGEO_USER_HOME);
// see
// http://jackrabbit.510166.n4.nabble.com/Jackrabbit-2-0-beta-6-Problem-adding-a-Mixin-type-with-mandatory-properties-after-setting-propertiesn-td1290332.html
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();
+ }
+
+ /**
+ * Estimate the sub tree size from current node. Computation is based on the
+ * Jcr {@link Property.getLength()} method. Note : it is not the exact size
+ * used on the disk by the current part of the JCR Tree.
+ */
+
+ public static long getNodeApproxSize(Node node) {
+ long curNodeSize = 0;
+ try {
+ PropertyIterator pi = node.getProperties();
+ while (pi.hasNext()) {
+ Property prop = pi.nextProperty();
+ if (prop.isMultiple()) {
+ int nb = prop.getLengths().length;
+ for (int i = 0; i < nb; i++) {
+ curNodeSize += (prop.getLengths()[i] > 0 ? prop
+ .getLengths()[i] : 0);
+ }
+ } else
+ curNodeSize += (prop.getLength() > 0 ? prop.getLength() : 0);
+ }
+
+ NodeIterator ni = node.getNodes();
+ while (ni.hasNext())
+ curNodeSize += getNodeApproxSize(ni.nextNode());
+ return curNodeSize;
+ } catch (RepositoryException re) {
+ throw new ArgeoException(
+ "Unexpected error while recursively determining node size.",
+ re);
+ }
+ }
}