]> git.aero2k.de Git - tmp/jakarta-migration.git/blob
6bbc8b24beb11deb47ffbd651275fa9b2aac2455
[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.account.storage;
26
27 import java.util.ArrayList;
28 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;
32 import org.slf4j.Logger;
33 import org.slf4j.LoggerFactory;
34
35 /**
36  *
37  * @author 
38  */
39 public class TenantJpaFilter extends JpaDocumentFilter {
40
41     private final Logger logger = LoggerFactory.getLogger(TenantJpaFilter.class);
42
43     public TenantJpaFilter(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 name = null;
52         List<String> nvals = getQueryParam(TenantStorageConstants.Q_NAME);
53         if (null != nvals && nvals.size() > 0) {
54             name = nvals.get(0);
55         }
56         boolean csAdmin = SecurityUtils.isCSpaceAdmin();
57         if (null != name && !name.isEmpty()) {
58             queryStrBldr.append(" WHERE UPPER(a.");
59             queryStrBldr.append(TenantStorageConstants.NAME_FIELD);
60             queryStrBldr.append(") LIKE :");
61             queryStrBldr.append(" :" + TenantStorageConstants.Q_NAME);
62             paramList.add(new ParamBinding(
63                         TenantStorageConstants.Q_NAME, "%" + name.toUpperCase() + "%"));
64         }
65
66         String includeDisabledStr = null;
67         List<String> inclDisVals = getQueryParam(TenantStorageConstants.Q_INCLUDE_DISABLED);
68         if (null != inclDisVals && inclDisVals.size() > 0) {
69             includeDisabledStr = inclDisVals.get(0);
70         }
71         // Default is to exclude disabled tenants, unless they specify to include them
72         boolean includeDisabled = (null != includeDisabledStr && !includeDisabledStr.isEmpty() 
73                         && Boolean.parseBoolean(includeDisabledStr));
74         // If excluding, then add a clause
75         if(!includeDisabled) {
76                 queryStrBldr.append(" WHERE NOT a.");
77             queryStrBldr.append(TenantStorageConstants.DISABLED_FIELD);
78         }
79
80         if (logger.isDebugEnabled()) {
81             String query = queryStrBldr.toString();
82             logger.debug("query=" + query);
83         }
84
85         return paramList;
86     }
87
88     @Override
89     public List<ParamBinding> buildWhere(StringBuilder queryStrBldr) {
90         return new ArrayList<ParamBinding>();
91     }
92
93     @Override
94     protected String addTenant(boolean append, List<ParamBinding> paramList) {
95         // unused for tenants - special case
96         return "";
97     }
98 }