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.kfs.sys.KFSConstants.BudgetConstructionPositionConstants;
019    import org.kuali.rice.kns.util.OjbCharBooleanConversion;
020    
021    /**
022     * Handles conversion of active indicator so as to piggy back onto the existing position effective status. Converts database values
023     * of A and I to java Y and N and back.
024     */
025    public class OjbBCPositionActiveIndicatorConversion extends OjbCharBooleanConversion {
026        private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(OjbBCPositionActiveIndicatorConversion.class);
027    
028        public final static String INDICATOR_NO = "N";
029        public final static String INDICATOR_YES = "Y";
030    
031        /**
032         * @see org.kuali.rice.kns.util.OjbCharBooleanConversion#javaToSql(java.lang.Object)
033         */
034        @Override
035        public Object javaToSql(Object source) {
036            Object sqlValue = super.javaToSql(source);
037    
038            if (INDICATOR_NO.equals(sqlValue)) {
039                return BudgetConstructionPositionConstants.POSITION_EFFECTIVE_STATUS_INACTIVE;
040            }
041            else if (INDICATOR_YES.equals(sqlValue)) {
042                return BudgetConstructionPositionConstants.POSITION_EFFECTIVE_STATUS_ACTIVE;
043            }
044    
045            return sqlValue;
046        }
047    
048        /**
049         * @see org.kuali.rice.kns.util.OjbCharBooleanConversion#sqlToJava(java.lang.Object)
050         */
051        @Override
052        public Object sqlToJava(Object source) {
053            try {
054                if (source instanceof String) {
055                    if (source != null) {
056                        String s = (String) source;
057                        return Boolean.valueOf(BudgetConstructionPositionConstants.POSITION_EFFECTIVE_STATUS_ACTIVE.indexOf(s) >= 0);
058                    }
059                    else {
060                        return null;
061                    }
062                }
063                return source;
064            }
065            catch (Throwable t) {
066                t.printStackTrace();
067                throw new RuntimeException("I have exploded converting types", t);
068            }
069        }
070    
071    }