Clover Coverage Report - Implementation 2.0.0-SNAPSHOT
Coverage timestamp: Wed Dec 31 1969 19:00:00 EST
../../../../../img/srcFileCovDistChart0.png 0% of files have more coverage
62   279   37   2.48
22   182   0.6   25
25     1.48  
1    
 
  SearchableAttributeLongValue       Line # 51 62 0% 37 109 0% 0.0
 
No Tests
 
1    /*
2    * Copyright 2005-2007 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.lang.StringUtils;
20    import org.hibernate.annotations.GenericGenerator;
21    import org.hibernate.annotations.Parameter;
22    import org.kuali.rice.core.framework.persistence.jpa.OrmUtils;
23    import org.kuali.rice.core.framework.persistence.jdbc.sql.SQLUtils;
24    import org.kuali.rice.kew.routeheader.DocumentRouteHeaderValue;
25    import org.kuali.rice.kew.service.KEWServiceLocator;
26    import org.kuali.rice.kew.util.KEWConstants;
27    import org.kuali.rice.kns.util.KNSConstants;
28   
29    import javax.persistence.*;
30    import java.io.Serializable;
31    import java.sql.ResultSet;
32    import java.sql.SQLException;
33    import java.text.DecimalFormat;
34    import java.text.NumberFormat;
35    import java.util.Arrays;
36    import java.util.List;
37    import java.util.regex.Matcher;
38    import java.util.regex.Pattern;
39   
40    /**
41    *
42    * @author Kuali Rice Team (rice.collab@kuali.org)
43    */
44    @Entity
45    @Table(name="KREW_DOC_HDR_EXT_LONG_T")
46    //@Sequence(name="KREW_SRCH_ATTR_S",property="searchableAttributeValueId")
47    @NamedQueries({
48    @NamedQuery(name="SearchableAttributeLongValue.FindByRouteHeaderId", query="select s from SearchableAttributeLongValue as s where s.routeHeaderId = :routeHeaderId"),
49    @NamedQuery(name="SearchableAttributeLongValue.FindByKey", query="select s from SearchableAttributeLongValue as s where s.routeHeaderId = :routeHeaderId and s.searchableAttributeKey = :searchableAttributeKey")
50    })
 
51    public class SearchableAttributeLongValue implements SearchableAttributeValue, Serializable {
52   
53    private static final long serialVersionUID = 5786144436732198346L;
54   
55    private static final String ATTRIBUTE_DATABASE_TABLE_NAME = "KREW_DOC_HDR_EXT_LONG_T";
56    private static final boolean DEFAULT_WILDCARD_ALLOWANCE_POLICY = false;
57    private static final boolean ALLOWS_RANGE_SEARCH = true;
58    private static final boolean ALLOWS_CASE_INSENSITIVE_SEARCH = false;
59    private static final String DEFAULT_VALIDATION_REGEX_EXPRESSION = "^-?[0-9]+$";
60    private static final String ATTRIBUTE_XML_REPRESENTATION = KEWConstants.SearchableAttributeConstants.DATA_TYPE_LONG;
61    private static final String DEFAULT_FORMAT_PATTERN = "#";
62   
63    @Id
64    @GeneratedValue(generator="KREW_SRCH_ATTR_S")
65    @GenericGenerator(name="KREW_SRCH_ATTR_S",strategy="org.hibernate.id.enhanced.SequenceStyleGenerator",parameters={
66    @Parameter(name="sequence_name",value="KREW_SRCH_ATTR_S"),
67    @Parameter(name="value_column",value="id")
68    })
69    @Column(name="DOC_HDR_EXT_LONG_ID")
70    private Long searchableAttributeValueId;
71    @Column(name="KEY_CD")
72    private String searchableAttributeKey;
73    @Column(name="VAL")
74    private Long searchableAttributeValue;
75    @Transient
76    protected String ojbConcreteClass; // attribute needed for OJB polymorphism - do not alter!
77   
78    @Column(name="DOC_HDR_ID")
79    private Long routeHeaderId;
80    @ManyToOne(fetch=FetchType.EAGER, cascade={CascadeType.PERSIST})
81    @JoinColumn(name="DOC_HDR_ID", insertable=false, updatable=false)
82    private DocumentRouteHeaderValue routeHeader;
83   
84    /**
85    * Default constructor.
86    */
 
87  0 toggle public SearchableAttributeLongValue() {
88  0 super();
89  0 this.ojbConcreteClass = this.getClass().getName();
90    }
91   
92    /* (non-Javadoc)
93    * @see org.kuali.rice.kew.docsearch.SearchableAttributeValue#setupAttributeValue(java.lang.String)
94    */
 
95  0 toggle public void setupAttributeValue(String value) {
96  0 this.setSearchableAttributeValue(convertStringToLong(value));
97    }
98   
 
99  0 toggle private Long convertStringToLong(String value) {
100  0 if (org.apache.commons.lang.StringUtils.isEmpty(value)) {
101  0 return null;
102    } else {
103  0 return Long.valueOf(value);
104    }
105    }
106   
107    /* (non-Javadoc)
108    * @see org.kuali.rice.kew.docsearch.SearchableAttributeValue#setupAttributeValue(java.sql.ResultSet, java.lang.String)
109    */
 
110  0 toggle public void setupAttributeValue(ResultSet resultSet, String columnName) throws SQLException {
111  0 this.setSearchableAttributeValue(resultSet.getLong(columnName));
112    }
113   
114    /* (non-Javadoc)
115    * @see org.kuali.rice.kew.docsearch.SearchableAttributeValue#getSearchableAttributeDisplayValue(java.util.Map)
116    */
 
117  0 toggle public String getSearchableAttributeDisplayValue() {
118  0 NumberFormat format = DecimalFormat.getInstance();
119  0 ((DecimalFormat)format).applyPattern(DEFAULT_FORMAT_PATTERN);
120  0 return format.format(getSearchableAttributeValue().longValue());
121    }
122   
123    /* (non-Javadoc)
124    * @see org.kuali.rice.kew.docsearch.SearchableAttributeValue#getAttributeDataType()
125    */
 
126  0 toggle public String getAttributeDataType() {
127  0 return ATTRIBUTE_XML_REPRESENTATION;
128    }
129   
130    /* (non-Javadoc)
131    * @see org.kuali.rice.kew.docsearch.SearchableAttributeValue#getAttributeTableName()
132    */
 
133  0 toggle public String getAttributeTableName() {
134  0 return ATTRIBUTE_DATABASE_TABLE_NAME;
135    }
136   
137    /* (non-Javadoc)
138    * @see org.kuali.rice.kew.docsearch.SearchableAttributeValue#allowsWildcardsByDefault()
139    */
 
140  0 toggle public boolean allowsWildcards() {
141  0 return DEFAULT_WILDCARD_ALLOWANCE_POLICY;
142    }
143   
144    /* (non-Javadoc)
145    * @see org.kuali.rice.kew.docsearch.SearchableAttributeValue#allowsCaseInsensitivity()
146    */
 
147  0 toggle public boolean allowsCaseInsensitivity() {
148  0 return ALLOWS_CASE_INSENSITIVE_SEARCH;
149    }
150   
151    /* (non-Javadoc)
152    * @see org.kuali.rice.kew.docsearch.SearchableAttributeValue#allowsRangeSearches()
153    */
 
154  0 toggle public boolean allowsRangeSearches() {
155  0 return ALLOWS_RANGE_SEARCH;
156    }
157   
158    /* (non-Javadoc)
159    * @see org.kuali.rice.kew.docsearch.SearchableAttributeValue#isPassesDefaultValidation()
160    */
 
161  0 toggle public boolean isPassesDefaultValidation(String valueEntered) {
162   
163  0 boolean bRet = true;
164  0 boolean bSplit = false;
165   
166  0 if (StringUtils.contains(valueEntered, KNSConstants.BETWEEN_OPERATOR)) {
167  0 List<String> l = Arrays.asList(valueEntered.split("\\.\\."));
168  0 for(String value : l){
169  0 bSplit = true;
170  0 if(!isPassesDefaultValidation(value)){
171  0 bRet = false;
172    }
173    }
174    }
175  0 if (StringUtils.contains(valueEntered, KNSConstants.OR_LOGICAL_OPERATOR)) {
176    //splitValueList.addAll(Arrays.asList(StringUtils.split(valueEntered, KNSConstants.OR_LOGICAL_OPERATOR)));
177  0 List<String> l = Arrays.asList(StringUtils.split(valueEntered, KNSConstants.OR_LOGICAL_OPERATOR));
178  0 for(String value : l){
179  0 bSplit = true;
180  0 if(!isPassesDefaultValidation(value)){
181  0 bRet = false;
182    }
183    }
184    }
185  0 if (StringUtils.contains(valueEntered, KNSConstants.AND_LOGICAL_OPERATOR)) {
186    //splitValueList.addAll(Arrays.asList(StringUtils.split(valueEntered, KNSConstants.AND_LOGICAL_OPERATOR)));
187  0 List<String> l = Arrays.asList(StringUtils.split(valueEntered, KNSConstants.AND_LOGICAL_OPERATOR));
188  0 for(String value : l){
189  0 bSplit = true;
190  0 if(!isPassesDefaultValidation(value)){
191  0 bRet = false;
192    }
193    }
194    }
195   
196  0 if(bSplit){
197  0 return bRet;
198    }
199   
200  0 Pattern pattern = Pattern.compile(DEFAULT_VALIDATION_REGEX_EXPRESSION);
201  0 Matcher matcher = pattern.matcher(SQLUtils.cleanNumericOfValidOperators(valueEntered).trim());
202  0 if(!matcher.matches()){
203  0 bRet = false;
204    }
205   
206  0 return bRet;
207   
208    }
209   
210   
211    /* (non-Javadoc)
212    * @see org.kuali.rice.kew.docsearch.SearchableAttributeValue#isRangeValid(java.lang.String, java.lang.String)
213    */
 
214  0 toggle public Boolean isRangeValid(String lowerValue, String upperValue) {
215  0 if (allowsRangeSearches()) {
216  0 Long lower = convertStringToLong(lowerValue);
217  0 Long upper = convertStringToLong(upperValue);
218  0 if ( (lower != null) && (upper != null) ) {
219  0 return (lower.compareTo(upper) <= 0);
220    }
221  0 return true;
222    }
223  0 return null;
224    }
225   
 
226  0 toggle public String getOjbConcreteClass() {
227  0 return ojbConcreteClass;
228    }
229   
 
230  0 toggle public void setOjbConcreteClass(String ojbConcreteClass) {
231  0 this.ojbConcreteClass = ojbConcreteClass;
232    }
233   
 
234  0 toggle public DocumentRouteHeaderValue getRouteHeader() {
235  0 return routeHeader;
236    }
237   
 
238  0 toggle public void setRouteHeader(DocumentRouteHeaderValue routeHeader) {
239  0 this.routeHeader = routeHeader;
240    }
241   
 
242  0 toggle public Long getRouteHeaderId() {
243  0 return routeHeaderId;
244    }
245   
 
246  0 toggle public void setRouteHeaderId(Long routeHeaderId) {
247  0 this.routeHeaderId = routeHeaderId;
248    }
249   
 
250  0 toggle public String getSearchableAttributeKey() {
251  0 return searchableAttributeKey;
252    }
253   
 
254  0 toggle public void setSearchableAttributeKey(String searchableAttributeKey) {
255  0 this.searchableAttributeKey = searchableAttributeKey;
256    }
257   
 
258  0 toggle public Long getSearchableAttributeValue() {
259  0 return searchableAttributeValue;
260    }
261   
 
262  0 toggle public void setSearchableAttributeValue(Long searchableAttributeValue) {
263  0 this.searchableAttributeValue = searchableAttributeValue;
264    }
265   
 
266  0 toggle public Long getSearchableAttributeValueId() {
267  0 return searchableAttributeValueId;
268    }
269   
 
270  0 toggle public void setSearchableAttributeValueId(Long searchableAttributeValueId) {
271  0 this.searchableAttributeValueId = searchableAttributeValueId;
272    }
273   
274    //@PrePersist
 
275  0 toggle public void beforeInsert(){
276  0 OrmUtils.populateAutoIncValue(this, KEWServiceLocator.getEntityManagerFactory().createEntityManager());
277    }
278    }
279