001/*
002 * Copyright 2006 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
017package org.kuali.ole.gl.businessobject;
018
019import java.util.LinkedHashMap;
020
021import org.kuali.ole.coa.businessobject.Chart;
022import org.kuali.rice.krad.bo.PersistableBusinessObjectBase;
023
024
025/**
026 * This class represents a sufficient fund rebuild
027 */
028public class SufficientFundRebuild extends PersistableBusinessObjectBase {
029
030    public static final String REBUILD_ACCOUNT = "A";
031    public static final String REBUILD_OBJECT = "O";
032
033    private String chartOfAccountsCode;
034    private String accountFinancialObjectTypeCode;
035    private String accountNumberFinancialObjectCode;
036    private Chart chart;
037
038    /**
039     * Default constructor.
040     */
041    public SufficientFundRebuild() {
042
043    }
044
045    public SufficientFundRebuild(String line) {
046        setFromTextFile(line);
047    }
048
049    /**
050     * This method sets this object's attributes from a line
051     * 
052     * @param line with object's attributes
053     */
054    public void setFromTextFile(String line) {
055
056        // Just in case
057        line = line + "                   ";
058
059        setChartOfAccountsCode(line.substring(0, 2).trim());
060        setAccountFinancialObjectTypeCode(line.substring(2, 3));
061        setAccountNumberFinancialObjectCode(line.substring(3, 10).trim());
062    }
063
064    /**
065     * This method returns a String representation of this object
066     * @return String representation of this object
067     */
068    public String getLine() {
069        StringBuffer sb = new StringBuffer();
070        sb.append(getField(2, chartOfAccountsCode));
071        sb.append(getField(1, accountFinancialObjectTypeCode));
072        sb.append(getField(7, accountNumberFinancialObjectCode));
073        return sb.toString();
074    }
075
076    private static String SPACES = "          ";
077
078    /**
079     * This method returns the value passed in with additional spaces if need be.
080     * 
081     * @param size
082     * @param value
083     * @return
084     */
085    private String getField(int size, String value) {
086        if (value == null) {
087            return SPACES.substring(0, size);
088        }
089        else {
090            if (value.length() < size) {
091                return value + SPACES.substring(0, size - value.length());
092            }
093            else {
094                return value;
095            }
096        }
097    }
098
099    /**
100     * Gets the chartOfAccountsCode attribute.
101     * 
102     * @return Returns the chartOfAccountsCode
103     */
104    public String getChartOfAccountsCode() {
105        return chartOfAccountsCode;
106    }
107
108    /**
109     * Sets the chartOfAccountsCode attribute.
110     * 
111     * @param chartOfAccountsCode The chartOfAccountsCode to set.
112     */
113    public void setChartOfAccountsCode(String chartOfAccountsCode) {
114        this.chartOfAccountsCode = chartOfAccountsCode;
115    }
116
117
118    /**
119     * Gets the accountFinancialObjectTypeCode attribute.
120     * 
121     * @return Returns the accountFinancialObjectTypeCode
122     */
123    public String getAccountFinancialObjectTypeCode() {
124        return accountFinancialObjectTypeCode;
125    }
126
127    /**
128     * Sets the accountFinancialObjectTypeCode attribute.
129     * 
130     * @param accountFinancialObjectTypeCode The accountFinancialObjectTypeCode to set.
131     */
132    public void setAccountFinancialObjectTypeCode(String accountFinancialObjectTypeCode) {
133        this.accountFinancialObjectTypeCode = accountFinancialObjectTypeCode;
134    }
135
136
137    /**
138     * Gets the accountNumberFinancialObjectCode attribute.
139     * 
140     * @return Returns the accountNumberFinancialObjectCode
141     */
142    public String getAccountNumberFinancialObjectCode() {
143        return accountNumberFinancialObjectCode;
144    }
145
146    /**
147     * Sets the accountNumberFinancialObjectCode attribute.
148     * 
149     * @param accountNumberFinancialObjectCode The accountNumberFinancialObjectCode to set.
150     */
151    public void setAccountNumberFinancialObjectCode(String accountNumberFinancialObjectCode) {
152        this.accountNumberFinancialObjectCode = accountNumberFinancialObjectCode;
153    }
154
155
156    /**
157     * Gets the chart attribute.
158     * 
159     * @return Returns the chart
160     */
161    public Chart getChart() {
162        return chart;
163    }
164
165    /**
166     * Sets the chart attribute.
167     * 
168     * @param chart The chart to set.
169     * @deprecated
170     */
171    public void setChart(Chart chart) {
172        this.chart = chart;
173    }
174
175    /**
176     * @see org.kuali.rice.krad.bo.BusinessObjectBase#toStringMapper()
177     */
178    protected LinkedHashMap toStringMapper_RICE20_REFACTORME() {
179        LinkedHashMap m = new LinkedHashMap();
180        m.put("chartOfAccountsCode", this.chartOfAccountsCode);
181        m.put("accountFinancialObjectTypeCode", this.accountFinancialObjectTypeCode);
182        m.put("accountNumberFinancialObjectCode", this.accountNumberFinancialObjectCode);
183        return m;
184    }
185}