1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34 package fr.paris.lutece.portal.business.mailinglist;
35
36 import fr.paris.lutece.util.sql.DAOUtil;
37
38 import org.apache.commons.lang3.StringUtils;
39
40 import java.io.Serializable;
41
42
43
44
45
46
47 public class MailingListFilter implements Serializable
48 {
49 private static final long serialVersionUID = -2176789297248798592L;
50 private static final String SQL_FILTER_NAME = " name LIKE ? ";
51 private static final String SQL_FILTER_DESCRIPTION = " description LIKE ? ";
52 private static final String SQL_FILTER_WORKGROUP = " workgroup = ? ";
53 private static final String SQL_WHERE = " WHERE ";
54 private static final String SQL_AND = " AND ";
55 private static final String SQL_OR = " OR ";
56 private static final String PERCENT = "%";
57 private String _strName;
58 private String _strDescription;
59 private String _strWorkgroup;
60 private boolean _bIsWideSearch;
61
62
63
64
65 public MailingListFilter( )
66 {
67 }
68
69
70
71
72
73
74
75 public MailingListFilter/../../../../../fr/paris/lutece/portal/business/mailinglist/MailingListFilter.html#MailingListFilter">MailingListFilter( MailingListFilter filter )
76 {
77 _strName = filter.getName( );
78 _strDescription = filter.getDescription( );
79 _strWorkgroup = filter.getWorkgroup( );
80 _bIsWideSearch = filter.isWideSearch( );
81 }
82
83
84
85
86
87
88 public String getName( )
89 {
90 return _strName;
91 }
92
93
94
95
96
97
98
99 public void setName( String strName )
100 {
101 _strName = strName;
102 }
103
104
105
106
107
108
109 public boolean containsName( )
110 {
111 return StringUtils.isNotBlank( _strName );
112 }
113
114
115
116
117
118
119 public String getDescription( )
120 {
121 return _strDescription;
122 }
123
124
125
126
127
128
129
130 public void setDescription( String strDescription )
131 {
132 _strDescription = strDescription;
133 }
134
135
136
137
138
139
140 public boolean containsDescription( )
141 {
142 return StringUtils.isNotBlank( _strDescription );
143 }
144
145
146
147
148
149
150 public String getWorkgroup( )
151 {
152 return _strWorkgroup;
153 }
154
155
156
157
158
159
160
161 public void setWorkgroup( String strWorkgroup )
162 {
163 _strWorkgroup = strWorkgroup;
164 }
165
166
167
168
169
170
171 public boolean containsWorkgroup( )
172 {
173 return StringUtils.isNotBlank( _strWorkgroup );
174 }
175
176
177
178
179
180
181
182 public void setWideSearch( boolean isWideSearch )
183 {
184 _bIsWideSearch = isWideSearch;
185 }
186
187
188
189
190
191
192 public boolean isWideSearch( )
193 {
194 return _bIsWideSearch;
195 }
196
197
198
199
200
201
202
203
204 public String buildSQLQuery( String strSQL )
205 {
206 StringBuilder sbSQL = new StringBuilder( strSQL );
207 int nIndex = 1;
208
209 nIndex = buildFilter( sbSQL, containsName( ), SQL_FILTER_NAME, nIndex );
210 nIndex = buildFilter( sbSQL, containsDescription( ), SQL_FILTER_DESCRIPTION, nIndex );
211 buildFilter( sbSQL, containsWorkgroup( ), SQL_FILTER_WORKGROUP, nIndex );
212
213 return sbSQL.toString( );
214 }
215
216
217
218
219
220
221
222 public void setFilterValues( DAOUtil daoUtil )
223 {
224 int nIndex = 1;
225
226 if ( containsName( ) )
227 {
228 daoUtil.setString( nIndex++, PERCENT + getName( ) + PERCENT );
229 }
230
231 if ( containsDescription( ) )
232 {
233 daoUtil.setString( nIndex++, PERCENT + getDescription( ) + PERCENT );
234 }
235
236 if ( containsWorkgroup( ) )
237 {
238 daoUtil.setString( nIndex, getWorkgroup( ) );
239 }
240 }
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255 private int buildFilter( StringBuilder sbSQL, boolean bAddFilter, String strSQL, int nIndex )
256 {
257 int nIndexTmp = nIndex;
258
259 if ( bAddFilter )
260 {
261 nIndexTmp = addSQLWhereOr( isWideSearch( ), sbSQL, nIndex );
262 sbSQL.append( strSQL );
263 }
264
265 return nIndexTmp;
266 }
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283 private int addSQLWhereOr( boolean bIsWideSearch, StringBuilder sbSQL, int nIndex )
284 {
285 if ( nIndex == 1 )
286 {
287 sbSQL.append( SQL_WHERE );
288 }
289 else
290 {
291 sbSQL.append( bIsWideSearch ? SQL_OR : SQL_AND );
292 }
293
294 return nIndex + 1;
295 }
296 }