1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.kew.docsearch;
17
18 import org.apache.commons.lang.ObjectUtils;
19 import org.apache.commons.lang.StringUtils;
20 import org.kuali.rice.kew.api.KewApiConstants;
21 import org.kuali.rice.kew.api.document.attribute.DocumentAttributeFactory;
22 import org.kuali.rice.kew.api.document.attribute.DocumentAttributeString;
23
24 import javax.persistence.Column;
25 import javax.persistence.Entity;
26 import javax.persistence.Inheritance;
27 import javax.persistence.InheritanceType;
28 import javax.persistence.NamedQueries;
29 import javax.persistence.NamedQuery;
30 import javax.persistence.Table;
31 import java.io.Serializable;
32 import java.sql.ResultSet;
33 import java.sql.SQLException;
34
35
36
37
38
39 @Entity
40 @Inheritance(strategy= InheritanceType.TABLE_PER_CLASS)
41 @Table(name="KREW_DOC_HDR_EXT_T")
42 @NamedQueries({
43 @NamedQuery(name="SearchableAttributeStringValue.FindByDocumentId", query="select s from "
44 + "SearchableAttributeStringValue as s where s.documentId = :documentId"),
45 @NamedQuery(name="SearchableAttributeStringValue.FindByKey", query="select s from SearchableAttributeStringValue as "
46 + "s where s.documentId = :documentId and s.searchableAttributeKey = :searchableAttributeKey")
47 })
48 public class SearchableAttributeStringValue extends SearchableAttributeBase implements CaseAwareSearchableAttributeValue, Serializable {
49
50 private static final long serialVersionUID = 8696089933682052078L;
51
52 private static final String ATTRIBUTE_DATABASE_TABLE_NAME = "KREW_DOC_HDR_EXT_T";
53 private static final boolean DEFAULT_WILDCARD_ALLOWANCE_POLICY = true;
54 private static final boolean ALLOWS_RANGE_SEARCH = true;
55 private static final boolean ALLOWS_CASE_INSENSITIVE_SEARCH = true;
56 private static final String ATTRIBUTE_XML_REPRESENTATION = KewApiConstants.SearchableAttributeConstants.DATA_TYPE_STRING;
57 private static final int STRING_MAX_LENGTH = 2000;
58
59 @Column(name="VAL")
60 private String searchableAttributeValue;
61
62
63
64
65 public SearchableAttributeStringValue() {
66 super();
67 this.ojbConcreteClass = this.getClass().getName();
68 }
69
70 @Override
71 public void setupAttributeValue(String value) {
72 this.setSearchableAttributeValue(value);
73 }
74
75 @Override
76 public void setupAttributeValue(ResultSet resultSet, String columnName) throws SQLException {
77 this.setSearchableAttributeValue(resultSet.getString(columnName));
78 }
79
80 @Override
81 public String getSearchableAttributeDisplayValue() {
82 return getSearchableAttributeValue();
83 }
84
85 @Override
86 public String getAttributeDataType() {
87 return ATTRIBUTE_XML_REPRESENTATION;
88 }
89
90 @Override
91 public String getAttributeTableName() {
92 return ATTRIBUTE_DATABASE_TABLE_NAME;
93 }
94
95 @Override
96 public boolean allowsWildcards() {
97 return DEFAULT_WILDCARD_ALLOWANCE_POLICY;
98 }
99
100 @Override
101 public boolean allowsCaseInsensitivity() {
102 return ALLOWS_CASE_INSENSITIVE_SEARCH;
103 }
104
105 @Override
106 public boolean allowsRangeSearches() {
107 return ALLOWS_RANGE_SEARCH;
108 }
109
110
111
112
113
114 @Override
115 public boolean isPassesDefaultValidation(String valueEntered) {
116 if (valueEntered != null && (valueEntered.length() > STRING_MAX_LENGTH)) {
117 return false;
118 }
119 return true;
120 }
121
122 @Override
123 public Boolean isRangeValid(String lowerValue, String upperValue) {
124 return isRangeValid(lowerValue, upperValue, true);
125 }
126
127 @Override
128 public Boolean isRangeValid(String lowerValue, String upperValue, boolean caseSensitive) {
129 if (allowsRangeSearches()) {
130 return StringUtils.isBlank(lowerValue) ||
131 StringUtils.isBlank(upperValue) ||
132 (caseSensitive ?
133 ObjectUtils.compare(lowerValue, upperValue) <= 0 :
134 String.CASE_INSENSITIVE_ORDER.compare(lowerValue, upperValue) <= 0);
135 }
136 return null;
137 }
138
139 @Override
140 public String getSearchableAttributeValue() {
141 return searchableAttributeValue;
142 }
143
144 public void setSearchableAttributeValue(String searchableAttributeValue) {
145 this.searchableAttributeValue = searchableAttributeValue;
146 }
147
148 @Override
149 public DocumentAttributeString toDocumentAttribute() {
150 return DocumentAttributeFactory.createStringAttribute(getSearchableAttributeKey(), getSearchableAttributeValue());
151 }
152
153 }
154