View Javadoc

1   /*
2    * Copyright 2005-2007 The Kuali Foundation
3    *
4    *
5    * Licensed under the Educational Community License, Version 2.0 (the "License");
6    * you may not use this file except in compliance with the License.
7    * You may obtain a copy of the License at
8    *
9    * http://www.opensource.org/licenses/ecl2.php
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
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   * @author Kuali Rice Team (rice.collab@kuali.org)
38   */
39  @Entity
40  @Table(name="KREW_DOC_HDR_EXT_T")
41  //@Sequence(name="KREW_SRCH_ATTR_S",property="searchableAttributeValueId")
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; // should match table creation
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; // attribute needed for OJB polymorphism - do not alter!
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       * Default constructor.
80       */
81      public SearchableAttributeStringValue() {
82      	super();
83          this.ojbConcreteClass = this.getClass().getName();
84      }
85  
86      /* (non-Javadoc)
87       * @see org.kuali.rice.kew.docsearch.SearchableAttributeValue#setupAttributeValue(java.lang.String)
88       */
89      public void setupAttributeValue(String value) {
90      	this.setSearchableAttributeValue(value);
91      }
92  
93  	/* (non-Javadoc)
94  	 * @see org.kuali.rice.kew.docsearch.SearchableAttributeValue#setupAttributeValue(java.sql.ResultSet, java.lang.String)
95  	 */
96  	public void setupAttributeValue(ResultSet resultSet, String columnName) throws SQLException {
97  		this.setSearchableAttributeValue(resultSet.getString(columnName));
98  	}
99  
100 	/* (non-Javadoc)
101 	 * @see org.kuali.rice.kew.docsearch.SearchableAttributeValue#getSearchableAttributeDisplayValue()
102 	 */
103     public String getSearchableAttributeDisplayValue() {
104         return getSearchableAttributeValue();
105     }
106 
107 	/* (non-Javadoc)
108 	 * @see org.kuali.rice.kew.docsearch.SearchableAttributeValue#getAttributeDataType()
109 	 */
110 	public String getAttributeDataType() {
111 		return ATTRIBUTE_XML_REPRESENTATION;
112 	}
113 
114 	/* (non-Javadoc)
115 	 * @see org.kuali.rice.kew.docsearch.SearchableAttributeValue#getAttributeTableName()
116 	 */
117 	public String getAttributeTableName() {
118 		return ATTRIBUTE_DATABASE_TABLE_NAME;
119 	}
120 
121     /* (non-Javadoc)
122 	 * @see org.kuali.rice.kew.docsearch.SearchableAttributeValue#allowsWildcardsByDefault()
123 	 */
124 	public boolean allowsWildcards() {
125 		return DEFAULT_WILDCARD_ALLOWANCE_POLICY;
126 	}
127 
128     /* (non-Javadoc)
129 	 * @see org.kuali.rice.kew.docsearch.SearchableAttributeValue#allowsCaseInsensitivity()
130 	 */
131 	public boolean allowsCaseInsensitivity() {
132 		return ALLOWS_CASE_INSENSITIVE_SEARCH;
133 	}
134 
135     /* (non-Javadoc)
136 	 * @see org.kuali.rice.kew.docsearch.SearchableAttributeValue#allowsRangeSearches()
137 	 */
138 	public boolean allowsRangeSearches() {
139 		return ALLOWS_RANGE_SEARCH;
140 	}
141 
142 	/**
143 	 * @return true if the {@code valueEntered} parameter is not null and is equal to or
144 	 * less than the specified max length defined by {@link #STRING_MAX_LENGTH}
145 	 *
146 	 * @see org.kuali.rice.kew.docsearch.SearchableAttributeValue#isPassesDefaultValidation()
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     /* (non-Javadoc)
156      * @see org.kuali.rice.kew.docsearch.SearchableAttributeValue#isRangeValid(java.lang.String, java.lang.String)
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 	//@PrePersist
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