]> git.aero2k.de Git - tmp/jakarta-migration.git/blob
ad6c95353c702684e6598d34c93f234444c25642
[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  *  This document is a part of the source code and related artifacts
25  *  for CollectionSpace, an open source collections management system
26  *  for museums and related institutions:
27
28  *  http://www.collectionspace.org
29  *  http://wiki.collectionspace.org
30
31  *  Copyright 2009 University of California at Berkeley
32
33  *  Licensed under the Educational Community License (ECL), Version 2.0.
34  *  You may not use this file except in compliance with this License.
35
36  *  You may obtain a copy of the ECL 2.0 License at
37
38  *  https://source.collectionspace.org/collection-space/LICENSE.txt
39
40  *  Unless required by applicable law or agreed to in writing, software
41  *  distributed under the License is distributed on an "AS IS" BASIS,
42  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
43  *  See the License for the specific language governing permissions and
44  *  limitations under the License.
45  */
46 /*
47  * To change this template, choose Tools | Templates
48  * and open the template in the editor.
49  */
50 package org.collectionspace.services.account.storage;
51
52 import java.util.ArrayList;
53 import java.util.List;
54 import org.collectionspace.services.common.storage.jpa.JpaDocumentFilter;
55 import org.slf4j.Logger;
56 import org.slf4j.LoggerFactory;
57
58 /**
59  *
60  * @author 
61  */
62 public class AccountJpaFilter extends JpaDocumentFilter {
63
64     private final Logger logger = LoggerFactory.getLogger(AccountJpaFilter.class);
65
66     @Override
67     public List<ParamBinding> buildWhereForSearch(StringBuilder queryStrBldr) {
68
69         List<ParamBinding> paramList = new ArrayList<ParamBinding>();
70         boolean hasWhere = false;
71         //TODO: add tenant id
72
73         String screenName = null;
74         List<String> snvals = getQueryParam(AccountStorageConstants.Q_SCREEN_NAME);
75         if (snvals != null) {
76             screenName = snvals.get(0);
77         }
78         if (null != screenName && !screenName.isEmpty()) {
79             hasWhere = true;
80             queryStrBldr.append(" WHERE");
81             queryStrBldr.append(" UPPER(a." + AccountStorageConstants.SCREEN_NAME + ")");
82             queryStrBldr.append(" LIKE");
83             queryStrBldr.append(" :" + AccountStorageConstants.Q_SCREEN_NAME);
84             paramList.add(new ParamBinding(AccountStorageConstants.Q_SCREEN_NAME, "%"
85                     + screenName.toUpperCase() + "%"));
86         }
87
88         String uid = null;
89         List<String> uidvals = getQueryParam(AccountStorageConstants.Q_USER_ID);
90         if (uidvals != null) {
91             uid = uidvals.get(0);
92         }
93         if (null != uid && !uid.isEmpty()) {
94             if (hasWhere) {
95                 queryStrBldr.append(" AND");
96             } else {
97                 queryStrBldr.append(" WHERE");
98             }
99             queryStrBldr.append(" UPPER(a." + AccountStorageConstants.USER_ID + ")");
100             queryStrBldr.append(" LIKE");
101             queryStrBldr.append(" :" + AccountStorageConstants.Q_USER_ID);
102             paramList.add(new ParamBinding(AccountStorageConstants.Q_USER_ID, "%"
103                     + uid.toUpperCase() + "%"));
104             hasWhere = true;
105         }
106
107         String email = null;
108         List<String> emailvals = getQueryParam(AccountStorageConstants.Q_EMAIL);
109         if (emailvals != null) {
110             email = emailvals.get(0);
111         }
112         if (null != email && !email.isEmpty()) {
113             if (hasWhere) {
114                 queryStrBldr.append(" AND");
115             } else {
116                 queryStrBldr.append(" WHERE");
117             }
118             queryStrBldr.append(" UPPER(a." + AccountStorageConstants.EMAIL + ")");
119             queryStrBldr.append(" LIKE");
120             queryStrBldr.append(" :" + AccountStorageConstants.Q_EMAIL);
121             paramList.add(new ParamBinding(AccountStorageConstants.Q_EMAIL, "%"
122                     + email.toUpperCase() + "%"));
123             hasWhere = true;
124         }
125
126         if (logger.isDebugEnabled()) {
127             logger.debug("query=" + queryStrBldr.toString());
128         }
129
130         return paramList;
131     }
132
133     @Override
134     public List<ParamBinding> buildWhere(StringBuilder queryStrBldr) {
135         return new ArrayList<ParamBinding>();
136     }
137 }