001 /*
002 * Copyright 2011 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 */
016 package org.kuali.kfs.module.bc.util;
017
018 import org.kuali.rice.kns.util.OjbCharBooleanConversion;
019
020 /**
021 * Handles conversion of active indicator so as to piggy back onto appointmentFundingDeleteIndicator by reversing the values.
022 * Converts database delete values of Y and N to java active N and Y and back.
023 */
024 public class OjbPendingBCAppointmentFundingActiveIndicatorConversion extends OjbCharBooleanConversion {
025 private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(OjbPendingBCAppointmentFundingActiveIndicatorConversion.class);
026
027 public final static String INDICATOR_NO = "N";
028 public final static String INDICATOR_YES = "Y";
029
030 /**
031 * This handles checking the boolean value coming in and converts it to
032 * the appropriate Y or N value.
033 * @see FieldConversion#javaToSql(Object)
034 */
035 @Override
036 public Object javaToSql(Object source) {
037 Object sqlValue = super.javaToSql(source);
038
039 if(INDICATOR_NO.equals(sqlValue)) {
040 return INDICATOR_YES;
041 }
042 else if(INDICATOR_YES.equals(sqlValue)) {
043 return INDICATOR_NO;
044 }
045
046 return sqlValue;
047 }
048
049 /**
050 * This handles checking the sql coming back from the database and converting
051 * it to the appropriate boolean true or false value.
052 * @see FieldConversion#sqlToJava(Object)
053 */
054 @Override
055 public Object sqlToJava(Object source) {
056 Object javaValue = super.sqlToJava(source);
057
058 if(javaValue == null) {
059 return null;
060 }
061 else if(Boolean.TRUE.equals(javaValue)) {
062 return Boolean.FALSE;
063 }
064 else if(Boolean.FALSE.equals(javaValue)) {
065 return Boolean.TRUE;
066 }
067
068 return javaValue;
069 }
070 }