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:
6 * http://www.collectionspace.org
7 * http://wiki.collectionspace.org
9 * Copyright 2009 University of California at Berkeley
11 * Licensed under the Educational Community License (ECL), Version 2.0.
12 * You may not use this file except in compliance with this License.
14 * You may obtain a copy of the ECL 2.0 License at
16 * https://source.collectionspace.org/collection-space/LICENSE.txt
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.
24 package org.collectionspace.services.authorization.storage;
26 import java.util.ArrayList;
27 import java.util.List;
29 import org.collectionspace.services.common.storage.jpa.JpaDocumentFilter;
30 import org.collectionspace.services.common.context.ServiceContext;
31 import org.collectionspace.services.common.security.SecurityUtils;
33 import org.slf4j.Logger;
34 import org.slf4j.LoggerFactory;
37 * RoleJpaFilter is to build where clause for role queries
40 public class RoleJpaFilter extends JpaDocumentFilter {
42 private final Logger logger = LoggerFactory.getLogger(RoleJpaFilter.class);
44 public RoleJpaFilter(ServiceContext ctx) {
49 public List<ParamBinding> buildWhereForSearch(StringBuilder queryStrBldr) {
51 List<ParamBinding> paramList = new ArrayList<ParamBinding>();
52 String roleName = null;
53 List<String> rn = getQueryParam(RoleStorageConstants.Q_ROLE_NAME);
54 if (null != rn && rn.size() > 0) {
57 boolean csAdmin = SecurityUtils.isCSpaceAdmin();
59 queryStrBldr.append(addTenant(false, paramList));
61 if (null != roleName && !roleName.isEmpty()) {
63 queryStrBldr.append(" AND");
65 queryStrBldr.append(" WHERE");
67 queryStrBldr.append(" UPPER(a." + RoleStorageConstants.ROLE_NAME + ")");
68 queryStrBldr.append(" LIKE");
69 queryStrBldr.append(" :" + RoleStorageConstants.Q_ROLE_NAME);
70 paramList.add(new ParamBinding(RoleStorageConstants.Q_ROLE_NAME, "%"
71 + roleName.toUpperCase() + "%"));
72 queryStrBldr.append(addTenant(true, paramList));
76 if (logger.isDebugEnabled()) {
77 String query = queryStrBldr.toString();
78 logger.debug("query=" + query);
85 public List<ParamBinding> buildWhere(StringBuilder queryStrBldr) {
86 return new ArrayList<ParamBinding>();