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