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.
25 package org.collectionspace.services.account.storage;
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;
39 public class TenantJpaFilter extends JpaDocumentFilter {
41 private final Logger logger = LoggerFactory.getLogger(TenantJpaFilter.class);
43 public TenantJpaFilter(ServiceContext ctx) {
48 public List<ParamBinding> buildWhereForSearch(StringBuilder queryStrBldr) {
50 List<ParamBinding> paramList = new ArrayList<ParamBinding>();
52 List<String> nvals = getQueryParam(TenantStorageConstants.Q_NAME);
53 if (null != nvals && nvals.size() > 0) {
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() + "%"));
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);
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);
80 if (logger.isDebugEnabled()) {
81 String query = queryStrBldr.toString();
82 logger.debug("query=" + query);
89 public List<ParamBinding> buildWhere(StringBuilder queryStrBldr) {
90 return new ArrayList<ParamBinding>();
94 protected String addTenant(boolean append, List<ParamBinding> paramList) {
95 // unused for tenants - special case