]> git.aero2k.de Git - tmp/jakarta-migration.git/blob
483baa9a3e633412bd2fd53f277ad1818899da3d
[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.context.ServiceContext;
30 import org.collectionspace.services.common.security.SecurityUtils;
31 import org.slf4j.Logger;
32 import org.slf4j.LoggerFactory;
33
34 /**
35  * RoleJpaFilter is to build where clause for role queries
36  * @author 
37  */
38 public class RoleJpaFilter extends JpaDocumentFilter {
39
40     private final Logger logger = LoggerFactory.getLogger(RoleJpaFilter.class);
41
42     public RoleJpaFilter(ServiceContext ctx) {
43         super(ctx);
44     }
45
46     @Override
47     public List<ParamBinding> buildWhereForSearch(StringBuilder queryStrBldr) {
48
49         List<ParamBinding> paramList = new ArrayList<ParamBinding>();
50         String roleName = null;
51         List<String> rn = getQueryParam(RoleStorageConstants.Q_ROLE_NAME);
52         if (null != rn && rn.size() > 0) {
53             roleName = rn.get(0);
54         }
55         boolean csAdmin = SecurityUtils.isCSpaceAdmin();
56         if (!csAdmin) {
57             queryStrBldr.append(addTenant(false, paramList));
58         }
59         if (null != roleName && !roleName.isEmpty()) {
60             if (!csAdmin) {
61                 queryStrBldr.append(" AND");
62             } else {
63                 queryStrBldr.append(" WHERE");
64             }
65             queryStrBldr.append(" UPPER(a." + RoleStorageConstants.ROLE_NAME + ")");
66             queryStrBldr.append(" LIKE");
67             queryStrBldr.append(" :" + RoleStorageConstants.Q_ROLE_NAME);
68             paramList.add(new ParamBinding(RoleStorageConstants.Q_ROLE_NAME, "%"
69                     + roleName.toUpperCase() + "%"));
70             queryStrBldr.append(addTenant(true, paramList));
71         }
72
73
74         if (logger.isDebugEnabled()) {
75             String query = queryStrBldr.toString();
76             logger.debug("query=" + query);
77         }
78
79         return paramList;
80     }
81
82     @Override
83     public List<ParamBinding> buildWhere(StringBuilder queryStrBldr) {
84         return new ArrayList<ParamBinding>();
85     }
86 }