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 */
016package org.kuali.ole.gl.service.impl;
017
018import java.util.Arrays;
019
020import org.kuali.ole.coa.service.BalanceTypeService;
021import org.kuali.ole.gl.ObjectHelper;
022import org.kuali.ole.gl.businessobject.OriginEntryFull;
023import org.kuali.ole.sys.context.SpringContext;
024
025/**
026 * This class represents an origin entry key
027 */
028public class OriginEntryKey {
029    static BalanceTypeService balanceTypService = SpringContext.getBean(BalanceTypeService.class);
030
031    /*
032     * (non-Javadoc)
033     * 
034     * @see java.lang.Object#equals(java.lang.Object)
035     */
036    public boolean equals(Object obj) {
037        if (!(obj instanceof OriginEntryKey) || null == obj) {
038            return false;
039        }
040
041        OriginEntryKey key = (OriginEntryKey) obj;
042        return ObjectHelper.isEqual(getAccountNumber(), key.getAccountNumber()) && ObjectHelper.isEqual(getBalanceTypeCode(), key.getBalanceTypeCode()) && ObjectHelper.isEqual(getChartCode(), key.getChartCode()) && ObjectHelper.isEqual(getFinancialSystemDocumentTypeCodeCode(), key.getFinancialSystemDocumentTypeCodeCode()) && ObjectHelper.isEqual(getEntrySequenceNumber(), key.getEntrySequenceNumber()) && ObjectHelper.isEqual(getDocumentNumber(), key.getDocumentNumber()) && ObjectHelper.isEqual(getFinancialObjectCode(), key.getFinancialObjectCode()) && ObjectHelper.isEqual(getFiscalPeriodCode(), key.getFiscalPeriodCode()) && ObjectHelper.isEqual(getFiscalYear(), key.getFiscalYear()) && ObjectHelper.isEqual(getObjectTypeCode(), key.getObjectTypeCode()) && ObjectHelper.isEqual(getSubAccountNumber(), key.getSubAccountNumber()) && ObjectHelper.isEqual(getSubObjectCode(), key.getSubObjectCode()) && ObjectHelper.isEqual(getSystemOriginationCode(), key.getSystemOriginationCode());
043    }
044
045    /**
046     * @param entry
047     * @return
048     */
049    static public OriginEntryKey buildFromOriginEntry(OriginEntryFull entry) {
050        if (null == entry) {
051            return null;
052        }
053
054        OriginEntryKey key = new OriginEntryKey();
055        key.setAccountNumber(entry.getAccountNumber());
056        key.setBalanceTypeCode(entry.getFinancialBalanceTypeCode());
057        key.setChartCode(entry.getChartOfAccountsCode());
058        key.setFinancialSystemDocumentTypeCodeCode(entry.getFinancialDocumentTypeCode());
059        key.setEntrySequenceNumber(entry.getTransactionLedgerEntrySequenceNumber().toString());
060        key.setDocumentNumber(entry.getDocumentNumber());
061        key.setFinancialObjectCode(entry.getFinancialObjectCode());
062        key.setFiscalPeriodCode(entry.getUniversityFiscalPeriodCode());
063        key.setFiscalYear(entry.getUniversityFiscalYear().toString());
064        key.setObjectTypeCode(entry.getFinancialObjectTypeCode());
065        key.setSubAccountNumber(entry.getSubAccountNumber());
066        key.setSubObjectCode(entry.getFinancialSubObjectCode());
067        key.setSystemOriginationCode(entry.getFinancialSystemOriginationCode());
068        return key;
069    }
070
071    /**
072     * @param entry
073     */
074    public void setIntoOriginEntry(OriginEntryFull entry) {
075        entry.setAccountNumber(getAccountNumber());
076        entry.setBalanceType(balanceTypService.getBalanceTypeByCode(getBalanceTypeCode()));
077        entry.setChartOfAccountsCode(getChartCode());
078        entry.setTransactionLedgerEntrySequenceNumber(new Integer(getEntrySequenceNumber()));
079        entry.setDocumentNumber(getDocumentNumber());
080        entry.setFinancialObjectCode(getFinancialObjectCode());
081        entry.setUniversityFiscalPeriodCode(getFiscalPeriodCode());
082        entry.setUniversityFiscalYear(new Integer(getFiscalYear()));
083        entry.setFinancialObjectTypeCode(getObjectTypeCode());
084        entry.setSubAccountNumber(getSubAccountNumber());
085        entry.setFinancialSubObjectCode(getSubObjectCode());
086        entry.setFinancialSystemOriginationCode(getSystemOriginationCode());
087        entry.setFinancialDocumentTypeCode(getFinancialSystemDocumentTypeCodeCode());
088    }
089
090    /**
091     * @return Returns the accountNumber.
092     */
093    public String getAccountNumber() {
094        return new String(accountNumber);
095    }
096
097    /**
098     * @param accountNumber The accountNumber to set.
099     */
100    public void setAccountNumber(String accountNumber) {
101        if (null != accountNumber) {
102            System.arraycopy(accountNumber.toCharArray(), 0, this.accountNumber, 0, this.accountNumber.length);
103        }
104        else {
105            Arrays.fill(this.accountNumber, (char) 0);
106        }
107    }
108
109    /**
110     * @return Returns the balanceTypeCode.
111     */
112    public String getBalanceTypeCode() {
113        return new String(balanceTypeCode);
114    }
115
116    /**
117     * @param balanceTypeCode The balanceTypeCode to set.
118     */
119    public void setBalanceTypeCode(String balanceTypeCode) {
120        if (null != balanceTypeCode) {
121            System.arraycopy(balanceTypeCode.toCharArray(), 0, this.balanceTypeCode, 0, this.balanceTypeCode.length);
122        }
123        else {
124            Arrays.fill(this.balanceTypeCode, (char) 0);
125        }
126    }
127
128    /**
129     * @return Returns the chartCode.
130     */
131    public String getChartCode() {
132        return new String(chartCode);
133    }
134
135    /**
136     * @param chartCode The chartCode to set.
137     */
138    public void setChartCode(String chartCode) {
139        if (null != chartCode) {
140            System.arraycopy(chartCode, 0, this.chartCode, 0, this.chartCode.length);
141        }
142        else {
143            Arrays.fill(this.chartCode, (char) 0);
144        }
145    }
146
147    /**
148     * @return Returns the financialSystemDocumentTypeCodeCode.
149     */
150    public String getFinancialSystemDocumentTypeCodeCode() {
151        return new String(financialSystemDocumentTypeCodeCode);
152    }
153
154    /**
155     * @param financialSystemDocumentTypeCodeCode The financialSystemDocumentTypeCodeCode to set.
156     */
157    public void setFinancialSystemDocumentTypeCodeCode(String financialSystemDocumentTypeCodeCode) {
158        if (null != financialSystemDocumentTypeCodeCode) {
159            System.arraycopy(financialSystemDocumentTypeCodeCode.toCharArray(), 0, this.financialSystemDocumentTypeCodeCode, 0, this.financialSystemDocumentTypeCodeCode.length);
160        }
161        else {
162            Arrays.fill(this.financialSystemDocumentTypeCodeCode, (char) 0);
163        }
164    }
165
166    /**
167     * @return Returns the entrySequenceNumber.
168     */
169    public String getEntrySequenceNumber() {
170        return new String(entrySequenceNumber);
171    }
172
173    /**
174     * @param entrySequenceNumber The entrySequenceNumber to set.
175     */
176    public void setEntrySequenceNumber(String entrySequenceNumber) {
177        if (null != entrySequenceNumber) {
178            System.arraycopy(entrySequenceNumber, 0, this.entrySequenceNumber, 0, this.entrySequenceNumber.length);
179        }
180        else {
181            Arrays.fill(this.entrySequenceNumber, (char) 0);
182        }
183    }
184
185    /**
186     * @return Returns the documentNumber.
187     */
188    public String getDocumentNumber() {
189        return new String(documentNumber);
190    }
191
192    /**
193     * @param documentNumber The documentNumber to set.
194     */
195    public void setDocumentNumber(String documentNumber) {
196        if (null != documentNumber) {
197            System.arraycopy(documentNumber, 0, this.documentNumber, 0, this.documentNumber.length);
198        }
199        else {
200            Arrays.fill(this.documentNumber, (char) 0);
201        }
202    }
203
204    /**
205     * @return Returns the financialObjectCode.
206     */
207    public String getFinancialObjectCode() {
208        return new String(financialObjectCode);
209    }
210
211    /**
212     * @param financialObjectCode The financialObjectCode to set.
213     */
214    public void setFinancialObjectCode(String financialObjectCode) {
215        if (null != financialObjectCode) {
216            System.arraycopy(financialObjectCode, 0, this.financialObjectCode, 0, this.financialObjectCode.length);
217        }
218        else {
219            Arrays.fill(this.financialObjectCode, (char) 0);
220        }
221    }
222
223    /**
224     * @return Returns the fiscalPeriodCode.
225     */
226    public String getFiscalPeriodCode() {
227        return new String(fiscalPeriodCode);
228    }
229
230    /**
231     * @param fiscalPeriodCode The fiscalPeriodCode to set.
232     */
233    public void setFiscalPeriodCode(String fiscalPeriodCode) {
234        if (null != fiscalPeriodCode) {
235            System.arraycopy(fiscalPeriodCode, 0, this.fiscalPeriodCode, 0, this.fiscalPeriodCode.length);
236        }
237        else {
238            Arrays.fill(this.fiscalPeriodCode, (char) 0);
239        }
240    }
241
242    /**
243     * @return Returns the fiscalYear.
244     */
245    public String getFiscalYear() {
246        return new String(fiscalYear);
247    }
248
249    /**
250     * @param fiscalYear The fiscalYear to set.
251     */
252    public void setFiscalYear(String fiscalYear) {
253        if (null != fiscalYear) {
254            System.arraycopy(fiscalYear, 0, this.fiscalYear, 0, this.fiscalYear.length);
255        }
256        else {
257            Arrays.fill(this.fiscalYear, (char) 0);
258        }
259    }
260
261    /**
262     * @return Returns the objectTypeCode.
263     */
264    public String getObjectTypeCode() {
265        return new String(objectTypeCode);
266    }
267
268    /**
269     * @param objectTypeCode The objectTypeCode to set.
270     */
271    public void setObjectTypeCode(String objectTypeCode) {
272        if (null != objectTypeCode) {
273            System.arraycopy(objectTypeCode, 0, this.objectTypeCode, 0, this.objectTypeCode.length);
274        }
275        else {
276            Arrays.fill(this.objectTypeCode, (char) 0);
277        }
278    }
279
280    /**
281     * @return Returns the subAccountNumber.
282     */
283    public String getSubAccountNumber() {
284        return new String(subAccountNumber);
285    }
286
287    /**
288     * @param subAccountNumber The subAccountNumber to set.
289     */
290    public void setSubAccountNumber(String subAccountNumber) {
291        if (null != subAccountNumber) {
292            System.arraycopy(subAccountNumber, 0, this.subAccountNumber, 0, this.subAccountNumber.length);
293        }
294        else {
295            Arrays.fill(this.subAccountNumber, (char) 0);
296        }
297    }
298
299    /**
300     * @return Returns the subObjectCode.
301     */
302    public String getSubObjectCode() {
303        return new String(subObjectCode);
304    }
305
306    /**
307     * @param subObjectCode The subObjectCode to set.
308     */
309    public void setSubObjectCode(String subObjectCode) {
310        if (null != subObjectCode) {
311            System.arraycopy(subObjectCode, 0, this.subObjectCode, 0, this.subObjectCode.length);
312        }
313        else {
314            Arrays.fill(this.subObjectCode, (char) 0);
315        }
316    }
317
318    /**
319     * @return Returns the systemOriginationCode.
320     */
321    public String getSystemOriginationCode() {
322        return new String(systemOriginationCode);
323    }
324
325    /**
326     * @param systemOriginationCode The systemOriginationCode to set.
327     */
328    public void setSystemOriginationCode(String systemOriginationCode) {
329        if (null != systemOriginationCode) {
330            System.arraycopy(systemOriginationCode.toCharArray(), 0, this.systemOriginationCode, 0, this.systemOriginationCode.length);
331        }
332        else {
333            Arrays.fill(this.systemOriginationCode, (char) 0);
334        }
335    }
336
337    public OriginEntryKey() {
338        super();
339    }
340
341    final private char[] fiscalYear = new char[4];
342
343    final private char[] chartCode = new char[2];
344
345    final private char[] accountNumber = new char[7];
346
347    final private char[] subAccountNumber = new char[5];
348
349    final private char[] financialObjectCode = new char[4];
350
351    final private char[] subObjectCode = new char[3];
352
353    final private char[] balanceTypeCode = new char[2];
354
355    final private char[] objectTypeCode = new char[2];
356
357    final private char[] fiscalPeriodCode = new char[2];
358
359    final private char[] financialSystemDocumentTypeCodeCode = new char[4];
360
361    final private char[] systemOriginationCode = new char[2];
362
363    final private char[] documentNumber = new char[9];
364
365    final private char[] entrySequenceNumber = new char[5];
366}