| 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.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 |
| 43 |
|
|
| 44 |
|
@Entity |
| 45 |
|
@Table(name="KREW_DOC_HDR_EXT_LONG_T") |
| 46 |
|
|
| 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 |
|
}) |
|
|
|
| 0% |
Uncovered Elements: 109 (109) |
Complexity: 37 |
Complexity Density: 0.6 |
|
| 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; |
| 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 |
|
|
| 86 |
|
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
| 87 |
0
|
public SearchableAttributeLongValue() {... |
| 88 |
0
|
super(); |
| 89 |
0
|
this.ojbConcreteClass = this.getClass().getName(); |
| 90 |
|
} |
| 91 |
|
|
| 92 |
|
|
| 93 |
|
@see |
| 94 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 95 |
0
|
public void setupAttributeValue(String value) {... |
| 96 |
0
|
this.setSearchableAttributeValue(convertStringToLong(value)); |
| 97 |
|
} |
| 98 |
|
|
|
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
| 99 |
0
|
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 |
|
|
| 108 |
|
@see |
| 109 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 110 |
0
|
public void setupAttributeValue(ResultSet resultSet, String columnName) throws SQLException {... |
| 111 |
0
|
this.setSearchableAttributeValue(resultSet.getLong(columnName)); |
| 112 |
|
} |
| 113 |
|
|
| 114 |
|
|
| 115 |
|
@see |
| 116 |
|
|
|
|
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
| 117 |
0
|
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 |
|
|
| 124 |
|
@see |
| 125 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 126 |
0
|
public String getAttributeDataType() {... |
| 127 |
0
|
return ATTRIBUTE_XML_REPRESENTATION; |
| 128 |
|
} |
| 129 |
|
|
| 130 |
|
|
| 131 |
|
@see |
| 132 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 133 |
0
|
public String getAttributeTableName() {... |
| 134 |
0
|
return ATTRIBUTE_DATABASE_TABLE_NAME; |
| 135 |
|
} |
| 136 |
|
|
| 137 |
|
|
| 138 |
|
@see |
| 139 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 140 |
0
|
public boolean allowsWildcards() {... |
| 141 |
0
|
return DEFAULT_WILDCARD_ALLOWANCE_POLICY; |
| 142 |
|
} |
| 143 |
|
|
| 144 |
|
|
| 145 |
|
@see |
| 146 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 147 |
0
|
public boolean allowsCaseInsensitivity() {... |
| 148 |
0
|
return ALLOWS_CASE_INSENSITIVE_SEARCH; |
| 149 |
|
} |
| 150 |
|
|
| 151 |
|
|
| 152 |
|
@see |
| 153 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 154 |
0
|
public boolean allowsRangeSearches() {... |
| 155 |
0
|
return ALLOWS_RANGE_SEARCH; |
| 156 |
|
} |
| 157 |
|
|
| 158 |
|
|
| 159 |
|
@see |
| 160 |
|
|
|
|
|
| 0% |
Uncovered Elements: 43 (43) |
Complexity: 9 |
Complexity Density: 0.33 |
|
| 161 |
0
|
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 |
|
|
| 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 |
|
|
| 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 |
|
|
| 212 |
|
@see |
| 213 |
|
|
|
|
|
| 0% |
Uncovered Elements: 11 (11) |
Complexity: 4 |
Complexity Density: 0.57 |
|
| 214 |
0
|
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 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 226 |
0
|
public String getOjbConcreteClass() {... |
| 227 |
0
|
return ojbConcreteClass; |
| 228 |
|
} |
| 229 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 230 |
0
|
public void setOjbConcreteClass(String ojbConcreteClass) {... |
| 231 |
0
|
this.ojbConcreteClass = ojbConcreteClass; |
| 232 |
|
} |
| 233 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 234 |
0
|
public DocumentRouteHeaderValue getRouteHeader() {... |
| 235 |
0
|
return routeHeader; |
| 236 |
|
} |
| 237 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 238 |
0
|
public void setRouteHeader(DocumentRouteHeaderValue routeHeader) {... |
| 239 |
0
|
this.routeHeader = routeHeader; |
| 240 |
|
} |
| 241 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 242 |
0
|
public Long getRouteHeaderId() {... |
| 243 |
0
|
return routeHeaderId; |
| 244 |
|
} |
| 245 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 246 |
0
|
public void setRouteHeaderId(Long routeHeaderId) {... |
| 247 |
0
|
this.routeHeaderId = routeHeaderId; |
| 248 |
|
} |
| 249 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 250 |
0
|
public String getSearchableAttributeKey() {... |
| 251 |
0
|
return searchableAttributeKey; |
| 252 |
|
} |
| 253 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 254 |
0
|
public void setSearchableAttributeKey(String searchableAttributeKey) {... |
| 255 |
0
|
this.searchableAttributeKey = searchableAttributeKey; |
| 256 |
|
} |
| 257 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 258 |
0
|
public Long getSearchableAttributeValue() {... |
| 259 |
0
|
return searchableAttributeValue; |
| 260 |
|
} |
| 261 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 262 |
0
|
public void setSearchableAttributeValue(Long searchableAttributeValue) {... |
| 263 |
0
|
this.searchableAttributeValue = searchableAttributeValue; |
| 264 |
|
} |
| 265 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 266 |
0
|
public Long getSearchableAttributeValueId() {... |
| 267 |
0
|
return searchableAttributeValueId; |
| 268 |
|
} |
| 269 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 270 |
0
|
public void setSearchableAttributeValueId(Long searchableAttributeValueId) {... |
| 271 |
0
|
this.searchableAttributeValueId = searchableAttributeValueId; |
| 272 |
|
} |
| 273 |
|
|
| 274 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 275 |
0
|
public void beforeInsert(){... |
| 276 |
0
|
OrmUtils.populateAutoIncValue(this, KEWServiceLocator.getEntityManagerFactory().createEntityManager()); |
| 277 |
|
} |
| 278 |
|
} |
| 279 |
|
|