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 java.sql.ResultSet;
20  import java.sql.SQLException;
21  import java.util.Map;
22  
23  import javax.persistence.CascadeType;
24  import javax.persistence.Column;
25  import javax.persistence.Entity;
26  import javax.persistence.FetchType;
27  import javax.persistence.Id;
28  import javax.persistence.JoinColumn;
29  import javax.persistence.ManyToOne;
30  import javax.persistence.NamedQueries;
31  import javax.persistence.NamedQuery;
32  import javax.persistence.PrePersist;
33  import javax.persistence.Table;
34  import javax.persistence.Transient;
35  
36  import org.kuali.rice.core.jpa.annotations.Sequence;
37  import org.kuali.rice.core.util.OrmUtils;
38  import org.kuali.rice.kew.bo.WorkflowPersistable;
39  import org.kuali.rice.kew.routeheader.DocumentRouteHeaderValue;
40  import org.kuali.rice.kew.service.KEWServiceLocator;
41  
42  
43  /**
44   *
45   * @author Kuali Rice Team (rice.collab@kuali.org)
46   */
47  @Entity
48  @Table(name="KREW_DOC_HDR_EXT_T")
49  @Sequence(name="KREW_SRCH_ATTR_S",property="searchableAttributeValueId")
50  @NamedQueries({
51  	@NamedQuery(name="SearchableAttributeStringValue.FindByRouteHeaderId", query="select s from SearchableAttributeStringValue as s where s.routeHeaderId = :routeHeaderId"),
52  	@NamedQuery(name="SearchableAttributeStringtValue.FindByKey", query="select s from SearchableAttributeStringValue as s where s.routeHeaderId = :routeHeaderId and s.searchableAttributeKey = :searchableAttributeKey")
53  })
54  public class SearchableAttributeStringValue implements WorkflowPersistable, SearchableAttributeValue {
55  
56      private static final long serialVersionUID = 8696089933682052078L;
57  
58      private static final String ATTRIBUTE_DATABASE_TABLE_NAME = "KREW_DOC_HDR_EXT_T";
59      private static final boolean DEFAULT_WILDCARD_ALLOWANCE_POLICY = true;
60      private static final boolean ALLOWS_RANGE_SEARCH = true;
61      private static final boolean ALLOWS_CASE_INSENSITIVE_SEARCH = true;
62      private static final String ATTRIBUTE_XML_REPRESENTATION = SearchableAttribute.DATA_TYPE_STRING;
63      private static final int STRING_MAX_LENGTH = 2000; // should match table creation
64  
65      @Id
66  	@Column(name="DOC_HDR_EXT_ID")
67  	private Long searchableAttributeValueId;
68      @Column(name="KEY_CD")
69  	private String searchableAttributeKey;
70      @Column(name="VAL")
71  	private String searchableAttributeValue;
72      @Transient
73      protected String ojbConcreteClass; // attribute needed for OJB polymorphism - do not alter!
74  
75      @Column(name="DOC_HDR_ID")
76  	private Long routeHeaderId;
77      @ManyToOne(fetch=FetchType.EAGER, cascade={CascadeType.PERSIST})
78  	@JoinColumn(name="DOC_HDR_ID", insertable=false, updatable=false)
79  	private DocumentRouteHeaderValue routeHeader;
80  
81      /**
82       * Default constructor.
83       */
84      public SearchableAttributeStringValue() {
85      	super();
86          this.ojbConcreteClass = this.getClass().getName();
87      }
88  
89      /* (non-Javadoc)
90       * @see org.kuali.rice.kew.docsearch.SearchableAttributeValue#setupAttributeValue(java.lang.String)
91       */
92      public void setupAttributeValue(String value) {
93      	this.setSearchableAttributeValue(value);
94      }
95  
96  	/* (non-Javadoc)
97  	 * @see org.kuali.rice.kew.docsearch.SearchableAttributeValue#setupAttributeValue(java.sql.ResultSet, java.lang.String)
98  	 */
99  	public void setupAttributeValue(ResultSet resultSet, String columnName) throws SQLException {
100 		this.setSearchableAttributeValue(resultSet.getString(columnName));
101 	}
102 
103 	/* (non-Javadoc)
104 	 * @see org.kuali.rice.kew.docsearch.SearchableAttributeValue#getSearchableAttributeDisplayValue()
105 	 */
106     public String getSearchableAttributeDisplayValue() {
107         return getSearchableAttributeValue();
108     }
109 
110 	/* (non-Javadoc)
111 	 * @see org.kuali.rice.kew.docsearch.SearchableAttributeValue#getAttributeDataType()
112 	 */
113 	public String getAttributeDataType() {
114 		return ATTRIBUTE_XML_REPRESENTATION;
115 	}
116 
117 	/* (non-Javadoc)
118 	 * @see org.kuali.rice.kew.docsearch.SearchableAttributeValue#getAttributeTableName()
119 	 */
120 	public String getAttributeTableName() {
121 		return ATTRIBUTE_DATABASE_TABLE_NAME;
122 	}
123 
124     /* (non-Javadoc)
125 	 * @see org.kuali.rice.kew.docsearch.SearchableAttributeValue#allowsWildcardsByDefault()
126 	 */
127 	public boolean allowsWildcards() {
128 		return DEFAULT_WILDCARD_ALLOWANCE_POLICY;
129 	}
130 
131     /* (non-Javadoc)
132 	 * @see org.kuali.rice.kew.docsearch.SearchableAttributeValue#allowsCaseInsensitivity()
133 	 */
134 	public boolean allowsCaseInsensitivity() {
135 		return ALLOWS_CASE_INSENSITIVE_SEARCH;
136 	}
137 
138     /* (non-Javadoc)
139 	 * @see org.kuali.rice.kew.docsearch.SearchableAttributeValue#allowsRangeSearches()
140 	 */
141 	public boolean allowsRangeSearches() {
142 		return ALLOWS_RANGE_SEARCH;
143 	}
144 
145 	/**
146 	 * @return true if the {@code valueEntered} parameter is not null and is equal to or
147 	 * less than the specified max length defined by {@link #STRING_MAX_LENGTH}
148 	 *
149 	 * @see org.kuali.rice.kew.docsearch.SearchableAttributeValue#isPassesDefaultValidation()
150 	 */
151 	public boolean isPassesDefaultValidation(String valueEntered) {
152 	    if (valueEntered != null && (valueEntered.length() > STRING_MAX_LENGTH)) {
153 	        return false;
154 	    }
155 		return true;
156 	}
157 
158     /* (non-Javadoc)
159      * @see org.kuali.rice.kew.docsearch.SearchableAttributeValue#isRangeValid(java.lang.String, java.lang.String)
160      */
161     public Boolean isRangeValid(String lowerValue, String upperValue) {
162         if (allowsRangeSearches()) {
163             return true;
164         }
165         return null;
166     }
167 
168 	public String getOjbConcreteClass() {
169 		return ojbConcreteClass;
170 	}
171 
172 	public void setOjbConcreteClass(String ojbConcreteClass) {
173 		this.ojbConcreteClass = ojbConcreteClass;
174 	}
175 
176 	public DocumentRouteHeaderValue getRouteHeader() {
177 		return routeHeader;
178 	}
179 
180 	public void setRouteHeader(DocumentRouteHeaderValue routeHeader) {
181 		this.routeHeader = routeHeader;
182 	}
183 
184 	public Long getRouteHeaderId() {
185 		return routeHeaderId;
186 	}
187 
188 	public void setRouteHeaderId(Long routeHeaderId) {
189 		this.routeHeaderId = routeHeaderId;
190 	}
191 
192 	public String getSearchableAttributeKey() {
193 		return searchableAttributeKey;
194 	}
195 
196 	public void setSearchableAttributeKey(String searchableAttributeKey) {
197 		this.searchableAttributeKey = searchableAttributeKey;
198 	}
199 
200 	public String getSearchableAttributeValue() {
201 		return searchableAttributeValue;
202 	}
203 
204 	public void setSearchableAttributeValue(String searchableAttributeValue) {
205 		this.searchableAttributeValue = searchableAttributeValue;
206 	}
207 
208 	public Long getSearchableAttributeValueId() {
209 		return searchableAttributeValueId;
210 	}
211 
212 	public void setSearchableAttributeValueId(Long searchableAttributeValueId) {
213 		this.searchableAttributeValueId = searchableAttributeValueId;
214 	}
215 
216 	/* (non-Javadoc)
217      * @see org.kuali.rice.kew.WorkflowPersistable#copy(boolean)
218      */
219     public Object copy(boolean preserveKeys) {
220         return null;
221     }
222 
223 	@PrePersist
224 	public void beforeInsert(){
225 		OrmUtils.populateAutoIncValue(this, KEWServiceLocator.getEntityManagerFactory().createEntityManager());
226 	}
227 }
228