View Javadoc

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