2 * Copyright (C) 2007-2012 Argeo GmbH
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package org
.argeo
.jcr
;
18 import javax
.jcr
.Node
;
19 import javax
.jcr
.RepositoryException
;
20 import javax
.jcr
.Session
;
21 import javax
.jcr
.query
.Query
;
22 import javax
.jcr
.query
.qom
.Constraint
;
23 import javax
.jcr
.query
.qom
.DynamicOperand
;
24 import javax
.jcr
.query
.qom
.QueryObjectModelFactory
;
25 import javax
.jcr
.query
.qom
.Selector
;
26 import javax
.jcr
.query
.qom
.StaticOperand
;
28 import org
.argeo
.ArgeoException
;
31 * Utilities related to the user home and properties based on Argeo JCR model.
32 * Do not use anymore. Does not fit with current security model
35 public class UserJcrUtils
{
36 /** The home base path. Not yet configurable */
37 public final static String DEFAULT_HOME_BASE_PATH
= "/home";
40 * Returns the home node of the user or null if none was found.
43 * the session to use in order to perform the search, this can be
44 * a session with a different user ID than the one searched,
45 * typically when a system or admin session is used.
47 * the username of the user
49 public static Node
getUserHome(Session session
, String username
) {
51 // String homePath = UserJcrUtils.getUserHomePath(username);
52 // return session.itemExists(homePath) ? session.getNode(homePath)
54 // kept for example of QOM queries
55 QueryObjectModelFactory qomf
= session
.getWorkspace()
56 .getQueryManager().getQOMFactory();
57 Selector userHomeSel
= qomf
.selector(ArgeoTypes
.ARGEO_USER_HOME
,
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("Cannot find home for user " + username
, e
);
72 public static Node
getUserProfile(Session session
, String username
) {
74 QueryObjectModelFactory qomf
= session
.getWorkspace()
75 .getQueryManager().getQOMFactory();
76 Selector userHomeSel
= qomf
.selector(ArgeoTypes
.ARGEO_USER_PROFILE
,
78 DynamicOperand userIdDop
= qomf
.propertyValue(
79 userHomeSel
.getSelectorName(), ArgeoNames
.ARGEO_USER_ID
);
80 StaticOperand userIdSop
= qomf
.literal(session
.getValueFactory()
81 .createValue(username
));
82 Constraint constraint
= qomf
.comparison(userIdDop
,
83 QueryObjectModelFactory
.JCR_OPERATOR_EQUAL_TO
, userIdSop
);
84 Query query
= qomf
.createQuery(userHomeSel
, constraint
, null, null);
85 return JcrUtils
.querySingleNode(query
);
86 } catch (RepositoryException e
) {
87 throw new ArgeoException(
88 "Cannot find profile for user " + username
, e
);
92 /** Returns the home node of the session user or null if none was found. */
93 public static Node
getUserHome(Session session
) {
94 String userID
= session
.getUserID();
95 return getUserHome(session
, userID
);
98 private UserJcrUtils() {