X-Git-Url: http://git.argeo.org/?a=blobdiff_plain;f=server%2Fruntime%2Forg.argeo.server.jcr%2Fsrc%2Fmain%2Fjava%2Forg%2Fargeo%2Fjcr%2FUserJcrUtils.java;h=b357227a570a62d42ad36fd71d5b633519b45ba4;hb=72b40d55c0481e506ba9eabd6fcd684ef23e2f5a;hp=016347ada7064c089b74e404ce9ea57416849895;hpb=2134dd19734711b05710c1250b665c32fbe7263c;p=lgpl%2Fargeo-commons.git diff --git a/server/runtime/org.argeo.server.jcr/src/main/java/org/argeo/jcr/UserJcrUtils.java b/server/runtime/org.argeo.server.jcr/src/main/java/org/argeo/jcr/UserJcrUtils.java index 016347ada..b357227a5 100644 --- a/server/runtime/org.argeo.server.jcr/src/main/java/org/argeo/jcr/UserJcrUtils.java +++ b/server/runtime/org.argeo.server.jcr/src/main/java/org/argeo/jcr/UserJcrUtils.java @@ -3,19 +3,22 @@ package org.argeo.jcr; import javax.jcr.Node; import javax.jcr.RepositoryException; import javax.jcr.Session; +import javax.jcr.query.Query; +import javax.jcr.query.qom.Constraint; +import javax.jcr.query.qom.DynamicOperand; +import javax.jcr.query.qom.QueryObjectModelFactory; +import javax.jcr.query.qom.Selector; +import javax.jcr.query.qom.StaticOperand; import org.argeo.ArgeoException; /** Utilities related to the user home and properties based on Argeo JCR model. */ public class UserJcrUtils { /** The home base path. Not yet configurable */ - public final static String DEFAULT_HOME_BASE_PATH = "/argeo:home"; - - private UserJcrUtils() { - } + public final static String DEFAULT_HOME_BASE_PATH = "/home"; /** - * Returns the home node of the session user or null if none was found. + * Returns the home node of the user or null if none was found. * * @param session * the session to use in order to perform the search, this can be @@ -26,23 +29,41 @@ public class UserJcrUtils { */ public static Node getUserHome(Session session, String username) { try { - String homePath = UserJcrUtils.getUserHomePath(username); - return session.itemExists(homePath) ? session.getNode(homePath) - : null; + // String homePath = UserJcrUtils.getUserHomePath(username); + // return session.itemExists(homePath) ? session.getNode(homePath) + // : null; // kept for example of QOM queries - // QueryObjectModelFactory qomf = session.getWorkspace() - // .getQueryManager().getQOMFactory(); - // Selector userHomeSel = qomf.selector(ArgeoTypes.ARGEO_USER_HOME, - // "userHome"); - // DynamicOperand userIdDop = qomf.propertyValue("userHome", - // ArgeoNames.ARGEO_USER_ID); - // StaticOperand userIdSop = qomf.literal(session.getValueFactory() - // .createValue(username)); - // Constraint constraint = qomf.comparison(userIdDop, - // QueryObjectModelFactory.JCR_OPERATOR_EQUAL_TO, userIdSop); - // Query query = qomf.createQuery(userHomeSel, constraint, null, - // null); - // Node userHome = JcrUtils.querySingleNode(query); + QueryObjectModelFactory qomf = session.getWorkspace() + .getQueryManager().getQOMFactory(); + Selector userHomeSel = qomf.selector(ArgeoTypes.ARGEO_USER_HOME, + "userHome"); + DynamicOperand userIdDop = qomf.propertyValue( + userHomeSel.getSelectorName(), ArgeoNames.ARGEO_USER_ID); + StaticOperand userIdSop = qomf.literal(session.getValueFactory() + .createValue(username)); + Constraint constraint = qomf.comparison(userIdDop, + QueryObjectModelFactory.JCR_OPERATOR_EQUAL_TO, userIdSop); + Query query = qomf.createQuery(userHomeSel, constraint, null, null); + return JcrUtils.querySingleNode(query); + } catch (RepositoryException e) { + throw new ArgeoException("Cannot find home for user " + username, e); + } + } + + public static Node getUserProfile(Session session, String username) { + try { + QueryObjectModelFactory qomf = session.getWorkspace() + .getQueryManager().getQOMFactory(); + Selector userHomeSel = qomf.selector(ArgeoTypes.ARGEO_USER_PROFILE, + "userProfile"); + DynamicOperand userIdDop = qomf.propertyValue( + userHomeSel.getSelectorName(), ArgeoNames.ARGEO_USER_ID); + StaticOperand userIdSop = qomf.literal(session.getValueFactory() + .createValue(username)); + Constraint constraint = qomf.comparison(userIdDop, + QueryObjectModelFactory.JCR_OPERATOR_EQUAL_TO, userIdSop); + Query query = qomf.createQuery(userHomeSel, constraint, null, null); + return JcrUtils.querySingleNode(query); } catch (RepositoryException e) { throw new ArgeoException("Cannot find home for user " + username, e); } @@ -54,11 +75,6 @@ public class UserJcrUtils { return getUserHome(session, userID); } - /** @deprecated Use {@link getUserHome} directly */ - @Deprecated - static String getUserHomePath(String username) { - String homeBasePath = DEFAULT_HOME_BASE_PATH; - return homeBasePath + '/' + JcrUtils.firstCharsToPath(username, 2) - + '/' + username; + private UserJcrUtils() { } }