001/** 002 * Copyright 2005-2014 The Kuali Foundation 003 * 004 * Licensed under the Educational Community License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.opensource.org/licenses/ecl2.php 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package org.kuali.rice.krad.datadictionary.validation; 017 018import org.kuali.rice.core.framework.persistence.jdbc.sql.SQLUtils; 019import org.kuali.rice.krad.datadictionary.exception.AttributeValidationException; 020import org.kuali.rice.krad.util.DataTypeUtil; 021 022import java.sql.Timestamp; 023import java.text.SimpleDateFormat; 024import java.util.Date; 025import java.util.List; 026 027/** 028 * A class that implements the required accessors and legacy processing for an attribute value reader. This provides a 029 * convenient base class 030 * from which other attribute value readers can be derived. 031 * 032 * @author Kuali Rice Team (rice.collab@kuali.org) 033 */ 034public abstract class BaseAttributeValueReader implements AttributeValueReader { 035 036 protected String entryName; 037 protected String attributeName; 038 039 @Override 040 public List<String> getCleanSearchableValues(String attributeKey) throws AttributeValidationException { 041 Class<?> attributeType = getType(attributeKey); 042 Object rawValue = getValue(attributeKey); 043 String attributeInValue = ""; 044 045 if (rawValue != null) { 046 //if a date force the format 047 if (rawValue instanceof Date && !(rawValue instanceof Timestamp)) { 048 attributeInValue = new SimpleDateFormat("MM-dd-yyyy").format(rawValue); 049 } else { 050 attributeInValue = rawValue.toString(); 051 } 052 } 053 054 String attributeDataType = DataTypeUtil.determineDataType(attributeType); 055 return SQLUtils.getCleanedSearchableValues(attributeInValue, attributeDataType); 056 } 057 058 /** 059 * @return the currentName 060 */ 061 @Override 062 public String getAttributeName() { 063 return this.attributeName; 064 } 065 066 /** 067 * @param currentName the currentName to set 068 */ 069 @Override 070 public void setAttributeName(String currentName) { 071 this.attributeName = currentName; 072 } 073 074 /** 075 * @return the entryName 076 */ 077 @Override 078 public String getEntryName() { 079 return this.entryName; 080 } 081 082 @Override 083 public abstract AttributeValueReader clone(); 084 085}