View Javadoc
1   /**
2    * Copyright 2005-2015 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.krad.datadictionary.validation;
17  
18  import org.kuali.rice.core.framework.persistence.jdbc.sql.SQLUtils;
19  import org.kuali.rice.krad.datadictionary.exception.AttributeValidationException;
20  import org.kuali.rice.krad.util.DataTypeUtil;
21  
22  import java.sql.Timestamp;
23  import java.text.SimpleDateFormat;
24  import java.util.Date;
25  import java.util.List;
26  
27  /**
28   * A class that implements the required accessors and legacy processing for an attribute value reader. This provides a
29   * convenient base class
30   * from which other attribute value readers can be derived.
31   *
32   * @author Kuali Rice Team (rice.collab@kuali.org)
33   */
34  public abstract class BaseAttributeValueReader implements AttributeValueReader {
35  
36      protected String entryName;
37      protected String attributeName;
38  
39      @Override
40      public List<String> getCleanSearchableValues(String attributeKey) throws AttributeValidationException {
41          Class<?> attributeType = getType(attributeKey);
42          Object rawValue = getValue(attributeKey);
43          String attributeInValue = "";
44  
45          if (rawValue != null) {
46              //if a date force the format
47              if (rawValue instanceof Date && !(rawValue instanceof Timestamp)) {
48                  attributeInValue = new SimpleDateFormat("MM-dd-yyyy").format(rawValue);
49              } else {
50                  attributeInValue = rawValue.toString();
51              }
52          }
53  
54          String attributeDataType = DataTypeUtil.determineDataType(attributeType);
55          return SQLUtils.getCleanedSearchableValues(attributeInValue, attributeDataType);
56      }
57  
58      /**
59       * @return the currentName
60       */
61      @Override
62      public String getAttributeName() {
63          return this.attributeName;
64      }
65  
66      /**
67       * @param currentName the currentName to set
68       */
69      @Override
70      public void setAttributeName(String currentName) {
71          this.attributeName = currentName;
72      }
73  
74      /**
75       * @return the entryName
76       */
77      @Override
78      public String getEntryName() {
79          return this.entryName;
80      }
81  
82      @Override
83      public abstract AttributeValueReader clone();
84  
85  }