]> git.aero2k.de Git - tmp/jakarta-migration.git/blob
cfe69cf12f2e7d30e14f6337e6660dbc3bdcd62f
[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  */
25 package org.collectionspace.services.authorization.storage;
26
27 import java.util.ArrayList;
28 import java.util.List;
29 import org.collectionspace.services.common.context.ServiceContext;
30 import org.collectionspace.services.common.storage.jpa.JpaDocumentFilter;
31 import org.slf4j.Logger;
32 import org.slf4j.LoggerFactory;
33
34 /**
35  * PermissionJpaFilter is to build where clause for role queries
36  * @author 
37  */
38 public class PermissionJpaFilter extends JpaDocumentFilter {
39
40     private final Logger logger = LoggerFactory.getLogger(PermissionJpaFilter.class);
41
42     /**
43      * Instantiates a new permission jpa filter.
44      * 
45      * @param ctx the ctx
46      */
47     public PermissionJpaFilter(ServiceContext ctx) {
48         super(ctx);
49     }
50
51     @Override
52     public List<ParamBinding> buildWhereForSearch(StringBuilder queryStrBldr) {
53
54         List<ParamBinding> paramList = new ArrayList<ParamBinding>();
55
56         String resName = null;
57         List<String> rn = getQueryParam(PermissionStorageConstants.Q_RESOURCE_NAME);
58         if (null != rn && rn.size() > 0) {
59             resName = rn.get(0);
60         }
61         queryStrBldr.append(addTenant(false, paramList));
62         if (null != resName && !resName.isEmpty()) {
63             queryStrBldr.append(" AND");
64             queryStrBldr.append(" UPPER(a." + PermissionStorageConstants.RESOURCE_NAME + ")");
65             queryStrBldr.append(" LIKE");
66             queryStrBldr.append(" :" + PermissionStorageConstants.Q_RESOURCE_NAME);
67             paramList.add(new ParamBinding(PermissionStorageConstants.Q_RESOURCE_NAME, "%"
68                     + resName.toUpperCase() + "%"));
69         }
70
71         if (logger.isDebugEnabled()) {
72             String query = queryStrBldr.toString();
73             logger.debug("query=" + query);
74         }
75
76         return paramList;
77     }
78
79     @Override
80     public List<ParamBinding> buildWhere(StringBuilder queryStrBldr) {
81         return new ArrayList<ParamBinding>();
82     }
83 }