]> git.aero2k.de Git - tmp/jakarta-migration.git/blob
e406218305930fa6ce075c9342535842d4b35b9a
[tmp/jakarta-migration.git] /
1 /**
2  *  This document is a part of the source code and related artifacts
3  *  for CollectionSpace, an open source collections management system
4  *  for museums and related institutions:
5
6  *  http://www.collectionspace.org
7  *  http://wiki.collectionspace.org
8
9  *  Copyright 2009 University of California at Berkeley
10
11  *  Licensed under the Educational Community License (ECL), Version 2.0.
12  *  You may not use this file except in compliance with this License.
13
14  *  You may obtain a copy of the ECL 2.0 License at
15
16  *  https://source.collectionspace.org/collection-space/LICENSE.txt
17
18  *  Unless required by applicable law or agreed to in writing, software
19  *  distributed under the License is distributed on an "AS IS" BASIS,
20  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21  *  See the License for the specific language governing permissions and
22  *  limitations under the License.
23  */
24 package org.collectionspace.services.authorization.storage;
25
26 import java.util.ArrayList;
27 import java.util.List;
28 import org.collectionspace.services.common.storage.jpa.JpaDocumentFilter;
29 import org.collectionspace.services.common.authorization_mgt.RoleStorageConstants;
30 import org.collectionspace.services.common.context.ServiceContext;
31 import org.collectionspace.services.common.security.SecurityUtils;
32 import org.slf4j.Logger;
33 import org.slf4j.LoggerFactory;
34
35 /**
36  * RoleJpaFilter is to build where clause for role queries
37  * @author 
38  */
39 public class RoleJpaFilter extends JpaDocumentFilter {
40
41     private final Logger logger = LoggerFactory.getLogger(RoleJpaFilter.class);
42
43     public RoleJpaFilter(ServiceContext ctx) {
44         super(ctx);
45     }
46
47     @Override
48     public List<ParamBinding> buildWhereForSearch(StringBuilder queryStrBldr) {
49
50         List<ParamBinding> paramList = new ArrayList<ParamBinding>();
51         String roleName = null;
52         List<String> rn = getQueryParam(RoleStorageConstants.Q_ROLE_NAME);
53         if (null != rn && rn.size() > 0) {
54             roleName = rn.get(0);
55         }
56         boolean csAdmin = SecurityUtils.isCSpaceAdmin();
57         if (!csAdmin) {
58             queryStrBldr.append(addTenant(false, paramList));
59         }
60         if (null != roleName && !roleName.isEmpty()) {
61             if (!csAdmin) {
62                 queryStrBldr.append(" AND");
63             } else {
64                 queryStrBldr.append(" WHERE");
65             }
66             queryStrBldr.append(" UPPER(a." + RoleStorageConstants.ROLE_NAME + ")");
67             queryStrBldr.append(" LIKE");
68             queryStrBldr.append(" :" + RoleStorageConstants.Q_ROLE_NAME);
69             paramList.add(new ParamBinding(RoleStorageConstants.Q_ROLE_NAME, "%"
70                     + roleName.toUpperCase() + "%"));
71             queryStrBldr.append(addTenant(true, paramList));
72         }
73
74
75         if (logger.isDebugEnabled()) {
76             String query = queryStrBldr.toString();
77             logger.debug("query=" + query);
78         }
79
80         return paramList;
81     }
82
83     @Override
84     public List<ParamBinding> buildWhere(StringBuilder queryStrBldr) {
85         return new ArrayList<ParamBinding>();
86     }
87 }