4 import javax
.jcr
.RepositoryException
;
5 import javax
.jcr
.Session
;
6 import javax
.jcr
.query
.Query
;
7 import javax
.jcr
.query
.qom
.Constraint
;
8 import javax
.jcr
.query
.qom
.DynamicOperand
;
9 import javax
.jcr
.query
.qom
.QueryObjectModelFactory
;
10 import javax
.jcr
.query
.qom
.Selector
;
11 import javax
.jcr
.query
.qom
.StaticOperand
;
13 import org
.argeo
.ArgeoException
;
15 /** Utilities related to the user home and properties based on Argeo JCR model. */
16 public class UserJcrUtils
{
17 /** The home base path. Not yet configurable */
18 public final static String DEFAULT_HOME_BASE_PATH
= "/home";
21 * Returns the home node of the user or null if none was found.
24 * the session to use in order to perform the search, this can be
25 * a session with a different user ID than the one searched,
26 * typically when a system or admin session is used.
28 * the username of the user
30 public static Node
getUserHome(Session session
, String username
) {
32 // String homePath = UserJcrUtils.getUserHomePath(username);
33 // return session.itemExists(homePath) ? session.getNode(homePath)
35 // kept for example of QOM queries
36 QueryObjectModelFactory qomf
= session
.getWorkspace()
37 .getQueryManager().getQOMFactory();
38 Selector userHomeSel
= qomf
.selector(ArgeoTypes
.ARGEO_USER_HOME
,
40 DynamicOperand userIdDop
= qomf
.propertyValue(
41 userHomeSel
.getSelectorName(), ArgeoNames
.ARGEO_USER_ID
);
42 StaticOperand userIdSop
= qomf
.literal(session
.getValueFactory()
43 .createValue(username
));
44 Constraint constraint
= qomf
.comparison(userIdDop
,
45 QueryObjectModelFactory
.JCR_OPERATOR_EQUAL_TO
, userIdSop
);
46 Query query
= qomf
.createQuery(userHomeSel
, constraint
, null, null);
47 return JcrUtils
.querySingleNode(query
);
48 } catch (RepositoryException e
) {
49 throw new ArgeoException("Cannot find home for user " + username
, e
);
53 public static Node
getUserProfile(Session session
, String username
) {
55 QueryObjectModelFactory qomf
= session
.getWorkspace()
56 .getQueryManager().getQOMFactory();
57 Selector userHomeSel
= qomf
.selector(ArgeoTypes
.ARGEO_USER_PROFILE
,
59 DynamicOperand userIdDop
= qomf
.propertyValue(
60 userHomeSel
.getSelectorName(), ArgeoNames
.ARGEO_USER_ID
);
61 StaticOperand userIdSop
= qomf
.literal(session
.getValueFactory()
62 .createValue(username
));
63 Constraint constraint
= qomf
.comparison(userIdDop
,
64 QueryObjectModelFactory
.JCR_OPERATOR_EQUAL_TO
, userIdSop
);
65 Query query
= qomf
.createQuery(userHomeSel
, constraint
, null, null);
66 return JcrUtils
.querySingleNode(query
);
67 } catch (RepositoryException e
) {
68 throw new ArgeoException(
69 "Cannot find profile for user " + username
, e
);
73 /** Returns the home node of the session user or null if none was found. */
74 public static Node
getUserHome(Session session
) {
75 String userID
= session
.getUserID();
76 return getUserHome(session
, userID
);
79 private UserJcrUtils() {