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