View Javadoc

1   /*
2    * Copyright 2005-2008 The Kuali Foundation
3    * 
4    * 
5    * Licensed under the Educational Community License, Version 2.0 (the "License");
6    * you may not use this file except in compliance with the License.
7    * You may obtain a copy of the License at
8    * 
9    * http://www.opensource.org/licenses/ecl2.php
10   * 
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  package org.kuali.rice.kew.docsearch;
18  
19  import org.apache.commons.collections.CollectionUtils;
20  import org.apache.commons.lang.StringUtils;
21  import org.kuali.rice.kew.util.KEWConstants;
22  
23  import java.io.Serializable;
24  import java.util.List;
25  
26  
27  /**
28   *
29   * @author Kuali Rice Team (rice.collab@kuali.org)
30   */
31  public class SearchAttributeCriteriaComponent implements Serializable {
32      private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(SearchAttributeCriteriaComponent.class);
33  	
34  	private static final long serialVersionUID = -5927435567057306529L;
35  
36  	private String formKey;  // this if the field that is used in the UI for the form
37      private String value;
38      private List<String> values;
39      private String lookupableFieldType;
40      private boolean caseSensitive = false;
41      private boolean searchInclusive = true;  // not just for ranges... used by single date searches
42      private SearchableAttributeValue searchableAttributeValue;
43      private boolean searchable = true;
44      private boolean canHoldMultipleValues = false;
45      
46      // range properties
47      private boolean rangeSearch = false;
48      private boolean allowInlineRange = false;
49      // this is the field that is saved to the database
50      private String savedKey;
51  
52  	/**
53  	 * @param formKey key value associated with the search form
54  	 * @param value value the user is searching on
55  	 * @param savedKey key value associated with the value saved in the database
56  	 */
57  	public SearchAttributeCriteriaComponent(String formKey, String value, boolean rangeSearch) {
58  		super();
59  		this.formKey = formKey;
60  		this.value = value;
61  		this.rangeSearch = rangeSearch;
62  		if (!rangeSearch) {
63  			this.savedKey = formKey;
64  		}
65  	}
66  	
67  	/**
68  	 * @param formKey key value associated with the search form
69  	 * @param value value the user is searching on
70  	 * @param savedKey key value associated with the value saved in the database
71  	 */
72  	public SearchAttributeCriteriaComponent(String formKey, String value, String savedKey) {
73  		super();
74  		this.formKey = formKey;
75  		this.value = value;
76  		this.savedKey = savedKey;
77  	}
78  	
79  	/**
80  	 * @param formKey key value associated with the search form
81  	 * @param value value the user is searching on
82  	 * @param savedKey key value associated with the value saved in the database
83  	 * @param searchableAttributeValue
84  	 */
85  	public SearchAttributeCriteriaComponent(String formKey, String value, String savedKey, SearchableAttributeValue searchableAttributeValue) {
86  		super();
87  		this.formKey = formKey;
88  		this.value = value;
89  		this.savedKey = savedKey;
90  		this.searchableAttributeValue = searchableAttributeValue;
91  	}
92  	
93  	public boolean isComponentLowerBoundValue() {
94  		return isComponentGivenBoundValue(KEWConstants.SearchableAttributeConstants.RANGE_LOWER_BOUND_PROPERTY_PREFIX);
95  	}
96  	
97  	public boolean isComponentUpperBoundValue() {
98  		return isComponentGivenBoundValue(KEWConstants.SearchableAttributeConstants.RANGE_UPPER_BOUND_PROPERTY_PREFIX);
99  	}
100 	
101 	private boolean isComponentGivenBoundValue(String boundKeyPrefix) {
102 		if (!isRangeSearch()) {
103 			String errorMsg = "Criteria Component with formKey value '" + formKey + "' is not part of a range search";
104 			LOG.error("isComponentGivenBoundValue() " + errorMsg);
105 			throw new RuntimeException(errorMsg);
106 		}
107 		return formKey.indexOf(boundKeyPrefix) == 0;
108 	}
109     
110     public boolean isNonBlankValueGiven() {
111         return ( (StringUtils.isNotBlank(getValue())) || (!CollectionUtils.isEmpty(getValues())) );
112     }
113 
114 	/**
115      * @return the canHoldMultipleValues
116      */
117     public boolean isCanHoldMultipleValues() {
118         return canHoldMultipleValues;
119     }
120 
121     /**
122      * @param canHoldMultipleValues the canHoldMultipleValues to set
123      */
124     public void setCanHoldMultipleValues(boolean canHoldMultipleValues) {
125         this.canHoldMultipleValues = canHoldMultipleValues;
126     }
127 
128     /**
129      * @return the searchable
130      */
131     public boolean isSearchable() {
132         return searchable;
133     }
134 
135     /**
136      * @param searchable the searchable to set
137      */
138     public void setSearchable(boolean searchable) {
139         this.searchable = searchable;
140     }
141 
142 	/**
143 	 * @return the caseSensitive
144 	 */
145 	public boolean isCaseSensitive() {
146 		return caseSensitive;
147 	}
148 
149 	/**
150 	 * @param caseSensitive the caseSensitive to set
151 	 */
152 	public void setCaseSensitive(boolean caseSensitive) {
153 		this.caseSensitive = caseSensitive;
154 	}
155 
156 	/**
157 	 * @return the formKey
158 	 */
159 	public String getFormKey() {
160 		return formKey;
161 	}
162 
163 	/**
164 	 * @param formKey the formKey to set
165 	 */
166 	public void setFormKey(String formKey) {
167 		this.formKey = formKey;
168 	}
169 
170 	/**
171 	 * @return the rangeSearch
172 	 */
173 	public boolean isRangeSearch() {
174 		return rangeSearch;
175 	}
176 
177 	/**
178 	 * @param rangeSearch the rangeSearch to set
179 	 */
180 	public void setRangeSearch(boolean rangeSearch) {
181 		this.rangeSearch = rangeSearch;
182 	}
183 
184 	/**
185 	 * @return the savedKey
186 	 */
187 	public String getSavedKey() {
188 		return savedKey;
189 	}
190 
191 	/**
192 	 * @param savedKey the savedKey to set
193 	 */
194 	public void setSavedKey(String savedKey) {
195 		this.savedKey = savedKey;
196 	}
197 
198 	/**
199 	 * @return the searchableAttributeValue
200 	 */
201 	public SearchableAttributeValue getSearchableAttributeValue() {
202 		return searchableAttributeValue;
203 	}
204 
205 	/**
206 	 * @param searchableAttributeValue the searchableAttributeValue to set
207 	 */
208 	public void setSearchableAttributeValue(
209 			SearchableAttributeValue searchableAttributeValue) {
210 		this.searchableAttributeValue = searchableAttributeValue;
211 	}
212 
213 	/**
214 	 * @return the searchInclusive
215 	 */
216 	public boolean isSearchInclusive() {
217 		return searchInclusive;
218 	}
219 
220 	/**
221 	 * @param searchInclusive the searchInclusive to set
222 	 */
223 	public void setSearchInclusive(boolean searchInclusive) {
224 		this.searchInclusive = searchInclusive;
225 	}
226 
227 	/**
228 	 * @return the value
229 	 */
230 	public String getValue() {
231 		return value;
232 	}
233 
234 	/**
235 	 * @param value the value to set
236 	 */
237 	public void setValue(String value) {
238 		this.value = value;
239 	}
240 
241     /**
242      * @return the values
243      */
244     public List<String> getValues() {
245         return values;
246     }
247 
248     /**
249      * @param values the values to set
250      */
251     public void setValues(List<String> values) {
252         this.values = values;
253     }
254 
255     /**
256      * @return the lookupableFieldType
257      */
258     public String getLookupableFieldType() {
259         return lookupableFieldType;
260     }
261 
262     /**
263      * @param lookupableFieldType the lookupableFieldType to set
264      */
265     public void setLookupableFieldType(String lookupableFieldType) {
266         this.lookupableFieldType = lookupableFieldType;
267     }
268 
269 	/**
270 	 * @return the allowInlineRange
271 	 */
272 	public boolean isAllowInlineRange() {
273 		return this.allowInlineRange;
274 	}
275 
276 	/**
277 	 * @param allowInlineRange the allowInlineRange to set
278 	 */
279 	public void setAllowInlineRange(boolean allowInlineRange) {
280 		this.allowInlineRange = allowInlineRange;
281 	}
282 
283 }