| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 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.api.search.SearchOperator; |
| 23 | |
import org.kuali.rice.core.framework.persistence.jdbc.sql.SQLUtils; |
| 24 | |
import org.kuali.rice.core.framework.persistence.jpa.OrmUtils; |
| 25 | |
import org.kuali.rice.kew.routeheader.DocumentRouteHeaderValue; |
| 26 | |
import org.kuali.rice.kew.service.KEWServiceLocator; |
| 27 | |
import org.kuali.rice.kew.util.KEWConstants; |
| 28 | |
|
| 29 | |
import javax.persistence.CascadeType; |
| 30 | |
import javax.persistence.Column; |
| 31 | |
import javax.persistence.Entity; |
| 32 | |
import javax.persistence.FetchType; |
| 33 | |
import javax.persistence.GeneratedValue; |
| 34 | |
import javax.persistence.Id; |
| 35 | |
import javax.persistence.JoinColumn; |
| 36 | |
import javax.persistence.ManyToOne; |
| 37 | |
import javax.persistence.NamedQueries; |
| 38 | |
import javax.persistence.NamedQuery; |
| 39 | |
import javax.persistence.Table; |
| 40 | |
import javax.persistence.Transient; |
| 41 | |
import java.io.Serializable; |
| 42 | |
import java.math.BigDecimal; |
| 43 | |
import java.sql.ResultSet; |
| 44 | |
import java.sql.SQLException; |
| 45 | |
import java.text.DecimalFormat; |
| 46 | |
import java.text.NumberFormat; |
| 47 | |
import java.util.Arrays; |
| 48 | |
import java.util.List; |
| 49 | |
import java.util.regex.Matcher; |
| 50 | |
import java.util.regex.Pattern; |
| 51 | |
|
| 52 | |
|
| 53 | |
|
| 54 | |
|
| 55 | |
|
| 56 | 0 | @Entity |
| 57 | |
@Table(name="KREW_DOC_HDR_EXT_FLT_T") |
| 58 | |
|
| 59 | |
@NamedQueries({ |
| 60 | |
@NamedQuery(name="SearchableAttributeFloatValue.FindByDocumentId", query="select s from SearchableAttributeFloatValue as s where s.documentId = :documentId"), |
| 61 | |
@NamedQuery(name="SearchableAttributeFloatValue.FindByKey", query="select s from SearchableAttributeFloatValue as s where s.documentId = :documentId and s.searchableAttributeKey = :searchableAttributeKey") |
| 62 | |
}) |
| 63 | |
public class SearchableAttributeFloatValue implements SearchableAttributeValue, Serializable { |
| 64 | |
|
| 65 | |
private static final long serialVersionUID = -6682101853805320760L; |
| 66 | |
|
| 67 | |
private static final String ATTRIBUTE_DATABASE_TABLE_NAME = "KREW_DOC_HDR_EXT_FLT_T"; |
| 68 | |
private static final boolean DEFAULT_WILDCARD_ALLOWANCE_POLICY = false; |
| 69 | |
private static final boolean ALLOWS_RANGE_SEARCH = true; |
| 70 | |
private static final boolean ALLOWS_CASE_INSENSITIVE_SEARCH = false; |
| 71 | |
private static final String DEFAULT_VALIDATION_REGEX_EXPRESSION = "[-+]?[0-9]*\\.?[0-9]+"; |
| 72 | |
private static final String ATTRIBUTE_XML_REPRESENTATION = KEWConstants.SearchableAttributeConstants.DATA_TYPE_FLOAT; |
| 73 | |
private static final String DEFAULT_FORMAT_PATTERN = ""; |
| 74 | |
|
| 75 | |
@Id |
| 76 | |
@GeneratedValue(generator="KREW_SRCH_ATTR_S") |
| 77 | |
@GenericGenerator(name="KREW_SRCH_ATTR_S",strategy="org.hibernate.id.enhanced.SequenceStyleGenerator",parameters={ |
| 78 | |
@Parameter(name="sequence_name",value="KREW_SRCH_ATTR_S"), |
| 79 | |
@Parameter(name="value_column",value="id") |
| 80 | |
}) |
| 81 | |
@Column(name="DOC_HDR_EXT_FLT_ID") |
| 82 | |
private String searchableAttributeValueId; |
| 83 | |
@Column(name="KEY_CD") |
| 84 | |
private String searchableAttributeKey; |
| 85 | |
@Column(name="VAL") |
| 86 | |
private BigDecimal searchableAttributeValue; |
| 87 | |
@Transient |
| 88 | |
protected String ojbConcreteClass; |
| 89 | |
|
| 90 | |
@Column(name="DOC_HDR_ID") |
| 91 | |
private String documentId; |
| 92 | |
@ManyToOne(fetch=FetchType.EAGER, cascade={CascadeType.PERSIST}) |
| 93 | |
@JoinColumn(name="DOC_HDR_ID", insertable=false, updatable=false) |
| 94 | |
private DocumentRouteHeaderValue routeHeader; |
| 95 | |
|
| 96 | |
|
| 97 | |
|
| 98 | |
|
| 99 | |
public SearchableAttributeFloatValue() { |
| 100 | 0 | super(); |
| 101 | 0 | this.ojbConcreteClass = this.getClass().getName(); |
| 102 | 0 | } |
| 103 | |
|
| 104 | |
|
| 105 | |
|
| 106 | |
|
| 107 | |
public void setupAttributeValue(String value) { |
| 108 | 0 | this.setSearchableAttributeValue(convertStringToBigDecimal(value)); |
| 109 | 0 | } |
| 110 | |
|
| 111 | |
private BigDecimal convertStringToBigDecimal(String value) { |
| 112 | 0 | if (org.apache.commons.lang.StringUtils.isEmpty(value)) { |
| 113 | 0 | return null; |
| 114 | |
} else { |
| 115 | 0 | return new BigDecimal(value); |
| 116 | |
} |
| 117 | |
} |
| 118 | |
|
| 119 | |
|
| 120 | |
|
| 121 | |
|
| 122 | |
public void setupAttributeValue(ResultSet resultSet, String columnName) throws SQLException { |
| 123 | 0 | this.setSearchableAttributeValue(resultSet.getBigDecimal(columnName)); |
| 124 | 0 | } |
| 125 | |
|
| 126 | |
|
| 127 | |
|
| 128 | |
|
| 129 | |
public String getSearchableAttributeDisplayValue() { |
| 130 | 0 | NumberFormat format = DecimalFormat.getInstance(); |
| 131 | 0 | ((DecimalFormat)format).toPattern(); |
| 132 | 0 | ((DecimalFormat)format).applyPattern(DEFAULT_FORMAT_PATTERN); |
| 133 | 0 | return format.format(getSearchableAttributeValue().doubleValue()); |
| 134 | |
} |
| 135 | |
|
| 136 | |
|
| 137 | |
|
| 138 | |
|
| 139 | |
public String getAttributeDataType() { |
| 140 | 0 | return ATTRIBUTE_XML_REPRESENTATION; |
| 141 | |
} |
| 142 | |
|
| 143 | |
|
| 144 | |
|
| 145 | |
|
| 146 | |
public String getAttributeTableName() { |
| 147 | 0 | return ATTRIBUTE_DATABASE_TABLE_NAME; |
| 148 | |
} |
| 149 | |
|
| 150 | |
|
| 151 | |
|
| 152 | |
|
| 153 | |
public boolean allowsWildcards() { |
| 154 | 0 | return DEFAULT_WILDCARD_ALLOWANCE_POLICY; |
| 155 | |
} |
| 156 | |
|
| 157 | |
|
| 158 | |
|
| 159 | |
|
| 160 | |
public boolean allowsCaseInsensitivity() { |
| 161 | 0 | return ALLOWS_CASE_INSENSITIVE_SEARCH; |
| 162 | |
} |
| 163 | |
|
| 164 | |
|
| 165 | |
|
| 166 | |
|
| 167 | |
public boolean allowsRangeSearches() { |
| 168 | 0 | return ALLOWS_RANGE_SEARCH; |
| 169 | |
} |
| 170 | |
|
| 171 | |
|
| 172 | |
|
| 173 | |
|
| 174 | |
public boolean isPassesDefaultValidation(String valueEntered) { |
| 175 | |
|
| 176 | 0 | boolean bRet = true; |
| 177 | 0 | boolean bSplit = false; |
| 178 | |
|
| 179 | 0 | if (StringUtils.contains(valueEntered, SearchOperator.BETWEEN.op())) { |
| 180 | 0 | List<String> l = Arrays.asList(valueEntered.split("\\.\\.")); |
| 181 | 0 | for(String value : l){ |
| 182 | 0 | bSplit = true; |
| 183 | 0 | if(!isPassesDefaultValidation(value)){ |
| 184 | 0 | bRet = false; |
| 185 | |
} |
| 186 | |
} |
| 187 | |
} |
| 188 | 0 | if (StringUtils.contains(valueEntered, SearchOperator.OR.op())) { |
| 189 | |
|
| 190 | 0 | List<String> l = Arrays.asList(StringUtils.split(valueEntered, SearchOperator.OR.op())); |
| 191 | 0 | for(String value : l){ |
| 192 | 0 | bSplit = true; |
| 193 | 0 | if(!isPassesDefaultValidation(value)){ |
| 194 | 0 | bRet = false; |
| 195 | |
} |
| 196 | |
} |
| 197 | |
} |
| 198 | 0 | if (StringUtils.contains(valueEntered, SearchOperator.AND.op())) { |
| 199 | |
|
| 200 | 0 | List<String> l = Arrays.asList(StringUtils.split(valueEntered, SearchOperator.AND.op())); |
| 201 | 0 | for(String value : l){ |
| 202 | 0 | bSplit = true; |
| 203 | 0 | if(!isPassesDefaultValidation(value)){ |
| 204 | 0 | bRet = false; |
| 205 | |
} |
| 206 | |
} |
| 207 | |
} |
| 208 | |
|
| 209 | 0 | if(bSplit){ |
| 210 | 0 | return bRet; |
| 211 | |
} |
| 212 | |
|
| 213 | 0 | Pattern pattern = Pattern.compile(DEFAULT_VALIDATION_REGEX_EXPRESSION); |
| 214 | 0 | Matcher matcher = pattern.matcher(SQLUtils.cleanNumericOfValidOperators(valueEntered).trim()); |
| 215 | 0 | if(!matcher.matches()){ |
| 216 | 0 | bRet = false; |
| 217 | |
} |
| 218 | |
|
| 219 | 0 | return bRet; |
| 220 | |
|
| 221 | |
} |
| 222 | |
|
| 223 | |
|
| 224 | |
|
| 225 | |
|
| 226 | |
public Boolean isRangeValid(String lowerValue, String upperValue) { |
| 227 | 0 | if (allowsRangeSearches()) { |
| 228 | 0 | BigDecimal lower = null; |
| 229 | 0 | BigDecimal upper = null; |
| 230 | |
try{ |
| 231 | 0 | lower = convertStringToBigDecimal(lowerValue); |
| 232 | 0 | upper = convertStringToBigDecimal(upperValue); |
| 233 | 0 | }catch(NumberFormatException ex){ |
| 234 | 0 | return false; |
| 235 | 0 | } |
| 236 | 0 | if ( (lower != null) && (upper != null) ) { |
| 237 | 0 | return (lower.compareTo(upper) <= 0); |
| 238 | |
} |
| 239 | 0 | return true; |
| 240 | |
} |
| 241 | 0 | return null; |
| 242 | |
} |
| 243 | |
|
| 244 | |
public String getOjbConcreteClass() { |
| 245 | 0 | return ojbConcreteClass; |
| 246 | |
} |
| 247 | |
|
| 248 | |
public void setOjbConcreteClass(String ojbConcreteClass) { |
| 249 | 0 | this.ojbConcreteClass = ojbConcreteClass; |
| 250 | 0 | } |
| 251 | |
|
| 252 | |
public DocumentRouteHeaderValue getRouteHeader() { |
| 253 | 0 | return routeHeader; |
| 254 | |
} |
| 255 | |
|
| 256 | |
public void setRouteHeader(DocumentRouteHeaderValue routeHeader) { |
| 257 | 0 | this.routeHeader = routeHeader; |
| 258 | 0 | } |
| 259 | |
|
| 260 | |
public String getDocumentId() { |
| 261 | 0 | return documentId; |
| 262 | |
} |
| 263 | |
|
| 264 | |
public void setDocumentId(String documentId) { |
| 265 | 0 | this.documentId = documentId; |
| 266 | 0 | } |
| 267 | |
|
| 268 | |
public String getSearchableAttributeKey() { |
| 269 | 0 | return searchableAttributeKey; |
| 270 | |
} |
| 271 | |
|
| 272 | |
public void setSearchableAttributeKey(String searchableAttributeKey) { |
| 273 | 0 | this.searchableAttributeKey = searchableAttributeKey; |
| 274 | 0 | } |
| 275 | |
|
| 276 | |
public BigDecimal getSearchableAttributeValue() { |
| 277 | 0 | return searchableAttributeValue; |
| 278 | |
} |
| 279 | |
|
| 280 | |
public void setSearchableAttributeValue(BigDecimal searchableAttributeValue) { |
| 281 | 0 | this.searchableAttributeValue = searchableAttributeValue; |
| 282 | 0 | } |
| 283 | |
|
| 284 | |
|
| 285 | |
|
| 286 | |
|
| 287 | |
public void setSearchableAttributeValue(Float floatValueToTranslate) { |
| 288 | 0 | this.searchableAttributeValue = null; |
| 289 | 0 | if (floatValueToTranslate != null) { |
| 290 | 0 | this.searchableAttributeValue = new BigDecimal(floatValueToTranslate.toString()); |
| 291 | |
} |
| 292 | 0 | } |
| 293 | |
|
| 294 | |
public String getSearchableAttributeValueId() { |
| 295 | 0 | return searchableAttributeValueId; |
| 296 | |
} |
| 297 | |
|
| 298 | |
public void setSearchableAttributeValueId(String searchableAttributeValueId) { |
| 299 | 0 | this.searchableAttributeValueId = searchableAttributeValueId; |
| 300 | 0 | } |
| 301 | |
|
| 302 | |
|
| 303 | |
public void beforeInsert(){ |
| 304 | 0 | OrmUtils.populateAutoIncValue(this, KEWServiceLocator.getEntityManagerFactory().createEntityManager()); |
| 305 | 0 | } |
| 306 | |
|
| 307 | |
} |
| 308 | |
|