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.fp.businessobject;
017
018 import java.util.LinkedHashMap;
019
020 import org.apache.commons.lang.StringUtils;
021 import org.kuali.kfs.coa.businessobject.ObjectType;
022 import org.kuali.kfs.sys.KFSConstants;
023 import org.kuali.kfs.sys.KFSPropertyConstants;
024 import org.kuali.kfs.sys.businessobject.SourceAccountingLine;
025 import org.kuali.rice.kns.util.ObjectUtils;
026
027
028 /**
029 * Special case <code>{@link SourceAccountingLine}</code> type for <code>{@link org.kuali.kfs.fp.document.VoucherDocument}</code>
030 */
031 public class VoucherSourceAccountingLine extends SourceAccountingLine {
032 private String objectTypeCode;
033 private ObjectType objectType;
034
035 /**
036 * Constructs a VoucherSourceAccountingLine.java.
037 */
038 public VoucherSourceAccountingLine() {
039 super();
040
041 // default is debit. This is important for single sided accounting lines (example: JV w/BB) so that
042 // totals get calculated correctly
043 this.setDebitCreditCode(KFSConstants.GL_DEBIT_CODE);
044 }
045
046 /**
047 * Gets the objectType attribute.
048 *
049 * @return Returns the objectType.
050 */
051 @Override
052 public ObjectType getObjectType() {
053 return objectType;
054 }
055
056 /**
057 * Sets the objectType attribute value.
058 *
059 * @param objectType The objectType to set.
060 */
061 public void setObjectType(ObjectType objectType) {
062 this.objectType = objectType;
063 }
064
065 /**
066 * Gets the objectTypeCode attribute.
067 *
068 * @return Returns the objectTypeCode.
069 */
070 @Override
071 public String getObjectTypeCode() {
072 return objectTypeCode;
073 }
074
075 /**
076 * Sets the objectTypeCode attribute value.
077 *
078 * @param objectTypeCode The objectTypeCode to set.
079 */
080 public void setObjectTypeCode(String objectTypeCode) {
081 this.objectTypeCode = objectTypeCode;
082 }
083
084 /**
085 * Overridden to automatically set the object type code on the setting of the object code - if the object type code is blank
086 *
087 * @see org.kuali.kfs.sys.businessobject.AccountingLineBase#setFinancialObjectCode(java.lang.String)
088 */
089 @Override
090 public void setFinancialObjectCode(String financialObjectCode) {
091 super.setFinancialObjectCode(financialObjectCode);
092 if (StringUtils.isBlank(getObjectTypeCode()) && !StringUtils.isBlank(getFinancialObjectCode())) {
093 refreshReferenceObject("objectCode");
094 if (!ObjectUtils.isNull(getObjectCode())) {
095 setObjectTypeCode(getObjectCode().getFinancialObjectTypeCode());
096 }
097 }
098 }
099
100 /**
101 * @see org.kuali.kfs.sys.businessobject.AccountingLineBase#toStringMapper()
102 */
103 @Override
104 protected LinkedHashMap toStringMapper() {
105 LinkedHashMap<String, Object> map = super.toStringMapper();
106 map.put(KFSPropertyConstants.OBJECT_TYPE_CODE, this.getObjectTypeCode());
107
108 return map;
109 }
110 }