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