| 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.apache.commons.lang.StringUtils; |
| 20 | |
import org.hibernate.annotations.GenericGenerator; |
| 21 | |
import org.hibernate.annotations.Parameter; |
| 22 | |
import org.kuali.rice.core.api.CoreApiServiceLocator; |
| 23 | |
import org.kuali.rice.core.framework.persistence.jpa.OrmUtils; |
| 24 | |
import org.kuali.rice.core.framework.persistence.jdbc.sql.SqlBuilder; |
| 25 | |
import org.kuali.rice.core.util.RiceConstants; |
| 26 | |
import org.kuali.rice.kew.routeheader.DocumentRouteHeaderValue; |
| 27 | |
import org.kuali.rice.kew.service.KEWServiceLocator; |
| 28 | |
import org.kuali.rice.kew.util.KEWConstants; |
| 29 | |
|
| 30 | |
import javax.persistence.*; |
| 31 | |
import java.io.Serializable; |
| 32 | |
import java.sql.Date; |
| 33 | |
import java.sql.ResultSet; |
| 34 | |
import java.sql.SQLException; |
| 35 | |
import java.sql.Timestamp; |
| 36 | |
import java.text.DateFormat; |
| 37 | |
import java.text.ParseException; |
| 38 | |
import java.text.SimpleDateFormat; |
| 39 | |
import java.util.Calendar; |
| 40 | |
|
| 41 | |
|
| 42 | |
|
| 43 | |
|
| 44 | |
|
| 45 | |
|
| 46 | 0 | @Entity |
| 47 | |
@Table(name="KREW_DOC_HDR_EXT_DT_T") |
| 48 | |
|
| 49 | |
@NamedQueries({ |
| 50 | |
@NamedQuery(name="SearchableAttributeDateTimeValue.FindByDocumentId", query="select s from SearchableAttributeDateTimeValue as s where s.documentId = :documentId"), |
| 51 | |
@NamedQuery(name="SearchableAttributeDateTimeValue.FindByKey", query="select s from SearchableAttributeDateTimeValue as s where s.documentId = :documentId and s.searchableAttributeKey = :searchableAttributeKey") |
| 52 | |
}) |
| 53 | |
public class SearchableAttributeDateTimeValue implements SearchableAttributeValue, Serializable { |
| 54 | 0 | private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(SearchableAttributeDateTimeValue.class); |
| 55 | |
|
| 56 | |
private static final long serialVersionUID = 3045621112943214772L; |
| 57 | |
|
| 58 | |
private static final String ATTRIBUTE_DATABASE_TABLE_NAME = "KREW_DOC_HDR_EXT_DT_T"; |
| 59 | |
private static final boolean DEFAULT_WILDCARD_ALLOWANCE_POLICY = false; |
| 60 | |
private static final boolean ALLOWS_RANGE_SEARCH = true; |
| 61 | |
private static final boolean ALLOWS_CASE_INSENSITIVE_SEARCH = false; |
| 62 | |
private static final String ATTRIBUTE_XML_REPRESENTATION = KEWConstants.SearchableAttributeConstants.DATA_TYPE_DATE; |
| 63 | |
|
| 64 | |
@Id |
| 65 | |
@GeneratedValue(generator="KREW_SRCH_ATTR_S") |
| 66 | |
@GenericGenerator(name="KREW_SRCH_ATTR_S",strategy="org.hibernate.id.enhanced.SequenceStyleGenerator",parameters={ |
| 67 | |
@Parameter(name="sequence_name",value="KREW_SRCH_ATTR_S"), |
| 68 | |
@Parameter(name="value_column",value="id") |
| 69 | |
}) |
| 70 | |
@Column(name="DOC_HDR_EXT_DT_ID") |
| 71 | |
private String searchableAttributeValueId; |
| 72 | |
@Column(name="KEY_CD") |
| 73 | |
private String searchableAttributeKey; |
| 74 | |
@Column(name="VAL") |
| 75 | |
private Timestamp searchableAttributeValue; |
| 76 | |
@Transient |
| 77 | |
protected String ojbConcreteClass; |
| 78 | |
|
| 79 | |
@Column(name="DOC_HDR_ID") |
| 80 | |
private String documentId; |
| 81 | |
@ManyToOne(fetch=FetchType.EAGER, cascade={CascadeType.PERSIST}) |
| 82 | |
@JoinColumn(name="DOC_HDR_ID", insertable=false, updatable=false) |
| 83 | |
private DocumentRouteHeaderValue routeHeader; |
| 84 | |
|
| 85 | |
|
| 86 | |
|
| 87 | |
|
| 88 | |
public SearchableAttributeDateTimeValue() { |
| 89 | 0 | super(); |
| 90 | 0 | this.ojbConcreteClass = this.getClass().getName(); |
| 91 | 0 | } |
| 92 | |
|
| 93 | |
|
| 94 | |
|
| 95 | |
|
| 96 | |
public void setupAttributeValue(String value) { |
| 97 | 0 | this.setSearchableAttributeValue(convertStringToTimestamp(value)); |
| 98 | 0 | } |
| 99 | |
|
| 100 | |
private Timestamp convertStringToTimestamp(String value) { |
| 101 | 0 | if (org.apache.commons.lang.StringUtils.isEmpty(value)) { |
| 102 | 0 | return null; |
| 103 | |
} else { |
| 104 | |
Timestamp t; |
| 105 | |
try { |
| 106 | 0 | t = CoreApiServiceLocator.getDateTimeService().convertToSqlTimestamp(value); |
| 107 | 0 | } catch (ParseException e) { |
| 108 | 0 | t = null; |
| 109 | 0 | } |
| 110 | 0 | if (t == null) { |
| 111 | 0 | String errorMsg = "Error converting timestamp value '" + value + "' to valid timestamp object."; |
| 112 | 0 | LOG.error("setupAttributeValue() " + errorMsg); |
| 113 | 0 | throw new RuntimeException(errorMsg); |
| 114 | |
} |
| 115 | 0 | return t; |
| 116 | |
} |
| 117 | |
} |
| 118 | |
|
| 119 | |
|
| 120 | |
|
| 121 | |
|
| 122 | |
public void setupAttributeValue(ResultSet resultSet, String columnName) throws SQLException { |
| 123 | 0 | Calendar c = Calendar.getInstance(); |
| 124 | 0 | c.clear(Calendar.HOUR); |
| 125 | 0 | c.clear(Calendar.MINUTE); |
| 126 | 0 | c.clear(Calendar.SECOND); |
| 127 | 0 | c.clear(Calendar.MILLISECOND); |
| 128 | 0 | this.setSearchableAttributeValue(resultSet.getTimestamp(columnName, c)); |
| 129 | 0 | } |
| 130 | |
|
| 131 | |
|
| 132 | |
|
| 133 | |
|
| 134 | |
public String getSearchableAttributeDisplayValue() { |
| 135 | 0 | return formatAttributeValue(null); |
| 136 | |
} |
| 137 | |
|
| 138 | |
private String formatAttributeValue(String formatPattern) { |
| 139 | 0 | DateFormat df = getDateFormatToUse(formatPattern); |
| 140 | 0 | return df.format(new Date(getSearchableAttributeValue().getTime())); |
| 141 | |
} |
| 142 | |
|
| 143 | |
private DateFormat getDateFormatToUse(String parameterFormatPattern) { |
| 144 | 0 | if (StringUtils.isNotBlank(parameterFormatPattern)) { |
| 145 | 0 | return new SimpleDateFormat(parameterFormatPattern); |
| 146 | |
} |
| 147 | 0 | return RiceConstants.getDefaultDateFormat(); |
| 148 | |
} |
| 149 | |
|
| 150 | |
|
| 151 | |
|
| 152 | |
|
| 153 | |
public String getAttributeDataType() { |
| 154 | 0 | return ATTRIBUTE_XML_REPRESENTATION; |
| 155 | |
} |
| 156 | |
|
| 157 | |
|
| 158 | |
|
| 159 | |
|
| 160 | |
public String getAttributeTableName() { |
| 161 | 0 | return ATTRIBUTE_DATABASE_TABLE_NAME; |
| 162 | |
} |
| 163 | |
|
| 164 | |
|
| 165 | |
|
| 166 | |
|
| 167 | |
public boolean allowsWildcards() { |
| 168 | 0 | return DEFAULT_WILDCARD_ALLOWANCE_POLICY; |
| 169 | |
} |
| 170 | |
|
| 171 | |
|
| 172 | |
|
| 173 | |
|
| 174 | |
public boolean allowsCaseInsensitivity() { |
| 175 | 0 | return ALLOWS_CASE_INSENSITIVE_SEARCH; |
| 176 | |
} |
| 177 | |
|
| 178 | |
|
| 179 | |
|
| 180 | |
|
| 181 | |
public boolean allowsRangeSearches() { |
| 182 | 0 | return ALLOWS_RANGE_SEARCH; |
| 183 | |
} |
| 184 | |
|
| 185 | |
|
| 186 | |
|
| 187 | |
|
| 188 | |
public boolean isPassesDefaultValidation(String valueEntered) { |
| 189 | 0 | return new SqlBuilder().isValidDate(valueEntered); |
| 190 | |
|
| 191 | |
} |
| 192 | |
|
| 193 | |
|
| 194 | |
|
| 195 | |
|
| 196 | |
public Boolean isRangeValid(String lowerValue, String upperValue) { |
| 197 | 0 | if (allowsRangeSearches()) { |
| 198 | 0 | Timestamp lowerTime = convertStringToTimestamp(lowerValue); |
| 199 | 0 | Timestamp upperTime = convertStringToTimestamp(upperValue); |
| 200 | 0 | if ( (lowerTime != null) && (upperTime != null) ) { |
| 201 | 0 | return (lowerTime.compareTo(upperTime) <= 0); |
| 202 | |
} |
| 203 | 0 | return true; |
| 204 | |
} |
| 205 | 0 | return null; |
| 206 | |
} |
| 207 | |
|
| 208 | |
public String getOjbConcreteClass() { |
| 209 | 0 | return ojbConcreteClass; |
| 210 | |
} |
| 211 | |
|
| 212 | |
public void setOjbConcreteClass(String ojbConcreteClass) { |
| 213 | 0 | this.ojbConcreteClass = ojbConcreteClass; |
| 214 | 0 | } |
| 215 | |
|
| 216 | |
public DocumentRouteHeaderValue getRouteHeader() { |
| 217 | 0 | return routeHeader; |
| 218 | |
} |
| 219 | |
|
| 220 | |
public void setRouteHeader(DocumentRouteHeaderValue routeHeader) { |
| 221 | 0 | this.routeHeader = routeHeader; |
| 222 | 0 | } |
| 223 | |
|
| 224 | |
public String getDocumentId() { |
| 225 | 0 | return documentId; |
| 226 | |
} |
| 227 | |
|
| 228 | |
public void setDocumentId(String documentId) { |
| 229 | 0 | this.documentId = documentId; |
| 230 | 0 | } |
| 231 | |
|
| 232 | |
public String getSearchableAttributeKey() { |
| 233 | 0 | return searchableAttributeKey; |
| 234 | |
} |
| 235 | |
|
| 236 | |
public void setSearchableAttributeKey(String searchableAttributeKey) { |
| 237 | 0 | this.searchableAttributeKey = searchableAttributeKey; |
| 238 | 0 | } |
| 239 | |
|
| 240 | |
public Timestamp getSearchableAttributeValue() { |
| 241 | 0 | return searchableAttributeValue; |
| 242 | |
} |
| 243 | |
|
| 244 | |
public void setSearchableAttributeValue(Timestamp searchableAttributeValue) { |
| 245 | 0 | this.searchableAttributeValue = searchableAttributeValue; |
| 246 | 0 | } |
| 247 | |
|
| 248 | |
public String getSearchableAttributeValueId() { |
| 249 | 0 | return searchableAttributeValueId; |
| 250 | |
} |
| 251 | |
|
| 252 | |
public void setSearchableAttributeValueId(String searchableAttributeValueId) { |
| 253 | 0 | this.searchableAttributeValueId = searchableAttributeValueId; |
| 254 | 0 | } |
| 255 | |
|
| 256 | |
|
| 257 | |
public void beforeInsert(){ |
| 258 | 0 | OrmUtils.populateAutoIncValue(this, KEWServiceLocator.getEntityManagerFactory().createEntityManager()); |
| 259 | 0 | } |
| 260 | |
} |
| 261 | |
|