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.hibernate.annotations.GenericGenerator;
21 import org.hibernate.annotations.Parameter;
22 import org.kuali.rice.core.framework.persistence.jpa.OrmUtils;
23 import org.kuali.rice.kew.api.document.attribute.DocumentAttribute;
24 import org.kuali.rice.kew.api.document.attribute.DocumentAttributeFactory;
25 import org.kuali.rice.kew.api.document.attribute.DocumentAttributeString;
26 import org.kuali.rice.kew.routeheader.DocumentRouteHeaderValue;
27 import org.kuali.rice.kew.service.KEWServiceLocator;
28 import org.kuali.rice.kew.api.KewApiConstants;
29
30 import javax.persistence.*;
31 import java.io.Serializable;
32 import java.sql.ResultSet;
33 import java.sql.SQLException;
34
35
36
37
38
39
40 @Entity
41 @Table(name="KREW_DOC_HDR_EXT_T")
42
43 @NamedQueries({
44 @NamedQuery(name="SearchableAttributeStringValue.FindByDocumentId", query="select s from SearchableAttributeStringValue as s where s.documentId = :documentId"),
45 @NamedQuery(name="SearchableAttributeStringValue.FindByKey", query="select s from SearchableAttributeStringValue as s where s.documentId = :documentId and s.searchableAttributeKey = :searchableAttributeKey")
46 })
47 public class SearchableAttributeStringValue implements CaseAwareSearchableAttributeValue, Serializable {
48
49 private static final long serialVersionUID = 8696089933682052078L;
50
51 private static final String ATTRIBUTE_DATABASE_TABLE_NAME = "KREW_DOC_HDR_EXT_T";
52 private static final boolean DEFAULT_WILDCARD_ALLOWANCE_POLICY = true;
53 private static final boolean ALLOWS_RANGE_SEARCH = true;
54 private static final boolean ALLOWS_CASE_INSENSITIVE_SEARCH = true;
55 private static final String ATTRIBUTE_XML_REPRESENTATION = KewApiConstants.SearchableAttributeConstants.DATA_TYPE_STRING;
56 private static final int STRING_MAX_LENGTH = 2000;
57
58 @Id
59 @GeneratedValue(generator="KREW_SRCH_ATTR_S")
60 @GenericGenerator(name="KREW_SRCH_ATTR_S",strategy="org.hibernate.id.enhanced.SequenceStyleGenerator",parameters={
61 @Parameter(name="sequence_name",value="KREW_SRCH_ATTR_S"),
62 @Parameter(name="value_column",value="id")
63 })
64 @Column(name="DOC_HDR_EXT_ID")
65 private String searchableAttributeValueId;
66 @Column(name="KEY_CD")
67 private String searchableAttributeKey;
68 @Column(name="VAL")
69 private String searchableAttributeValue;
70 @Transient
71 protected String ojbConcreteClass;
72
73 @Column(name="DOC_HDR_ID")
74 private String documentId;
75 @ManyToOne(fetch=FetchType.EAGER, cascade={CascadeType.PERSIST})
76 @JoinColumn(name="DOC_HDR_ID", insertable=false, updatable=false)
77 private DocumentRouteHeaderValue routeHeader;
78
79
80
81
82 public SearchableAttributeStringValue() {
83 super();
84 this.ojbConcreteClass = this.getClass().getName();
85 }
86
87
88
89
90 public void setupAttributeValue(String value) {
91 this.setSearchableAttributeValue(value);
92 }
93
94
95
96
97 public void setupAttributeValue(ResultSet resultSet, String columnName) throws SQLException {
98 this.setSearchableAttributeValue(resultSet.getString(columnName));
99 }
100
101
102
103
104 public String getSearchableAttributeDisplayValue() {
105 return getSearchableAttributeValue();
106 }
107
108
109
110
111 public String getAttributeDataType() {
112 return ATTRIBUTE_XML_REPRESENTATION;
113 }
114
115
116
117
118 public String getAttributeTableName() {
119 return ATTRIBUTE_DATABASE_TABLE_NAME;
120 }
121
122
123
124
125 public boolean allowsWildcards() {
126 return DEFAULT_WILDCARD_ALLOWANCE_POLICY;
127 }
128
129
130
131
132 public boolean allowsCaseInsensitivity() {
133 return ALLOWS_CASE_INSENSITIVE_SEARCH;
134 }
135
136
137
138
139 public boolean allowsRangeSearches() {
140 return ALLOWS_RANGE_SEARCH;
141 }
142
143
144
145
146
147
148
149 public boolean isPassesDefaultValidation(String valueEntered) {
150 if (valueEntered != null && (valueEntered.length() > STRING_MAX_LENGTH)) {
151 return false;
152 }
153 return true;
154 }
155
156
157
158
159 public Boolean isRangeValid(String lowerValue, String upperValue) {
160 return isRangeValid(lowerValue, upperValue, true);
161 }
162
163
164
165
166 public Boolean isRangeValid(String lowerValue, String upperValue, boolean caseSensitive) {
167 if (allowsRangeSearches()) {
168 return StringUtils.isBlank(lowerValue) ||
169 StringUtils.isBlank(upperValue) ||
170 (caseSensitive ?
171 ObjectUtils.compare(lowerValue, upperValue) <= 0 :
172 String.CASE_INSENSITIVE_ORDER.compare(lowerValue, upperValue) <= 0);
173 }
174 return null;
175 }
176
177 public String getOjbConcreteClass() {
178 return ojbConcreteClass;
179 }
180
181 public void setOjbConcreteClass(String ojbConcreteClass) {
182 this.ojbConcreteClass = ojbConcreteClass;
183 }
184
185 public DocumentRouteHeaderValue getRouteHeader() {
186 return routeHeader;
187 }
188
189 public void setRouteHeader(DocumentRouteHeaderValue routeHeader) {
190 this.routeHeader = routeHeader;
191 }
192
193 public String getDocumentId() {
194 return documentId;
195 }
196
197 public void setDocumentId(String documentId) {
198 this.documentId = documentId;
199 }
200
201 public String getSearchableAttributeKey() {
202 return searchableAttributeKey;
203 }
204
205 public void setSearchableAttributeKey(String searchableAttributeKey) {
206 this.searchableAttributeKey = searchableAttributeKey;
207 }
208
209 public String getSearchableAttributeValue() {
210 return searchableAttributeValue;
211 }
212
213 public void setSearchableAttributeValue(String searchableAttributeValue) {
214 this.searchableAttributeValue = searchableAttributeValue;
215 }
216
217 public String getSearchableAttributeValueId() {
218 return searchableAttributeValueId;
219 }
220
221 public void setSearchableAttributeValueId(String searchableAttributeValueId) {
222 this.searchableAttributeValueId = searchableAttributeValueId;
223 }
224
225
226 public void beforeInsert(){
227 OrmUtils.populateAutoIncValue(this, KEWServiceLocator.getEntityManagerFactory().createEntityManager());
228 }
229
230 @Override
231 public DocumentAttributeString toDocumentAttribute() {
232 return DocumentAttributeFactory.createStringAttribute(getSearchableAttributeKey(), getSearchableAttributeValue());
233 }
234 }
235