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.coa.businessobject; 017 018 import java.util.LinkedHashMap; 019 020 import org.apache.ojb.broker.PersistenceBroker; 021 import org.apache.ojb.broker.PersistenceBrokerException; 022 import org.kuali.kfs.gl.businessobject.SufficientFundRebuild; 023 import org.kuali.kfs.sys.context.SpringContext; 024 import org.kuali.rice.kns.bo.Inactivateable; 025 import org.kuali.rice.kns.bo.PersistableBusinessObjectBase; 026 import org.kuali.rice.kns.service.BusinessObjectService; 027 028 /** 029 * 030 */ 031 public class ObjectLevel extends PersistableBusinessObjectBase implements Inactivateable { 032 private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(ObjectLevel.class); 033 034 private String chartOfAccountsCode; 035 private String financialObjectLevelCode; 036 private String financialObjectLevelName; 037 private String financialObjectLevelShortNm; 038 private boolean active; 039 private String financialReportingSortCode; 040 private String financialConsolidationObjectCode; 041 042 private ObjectConsolidation financialConsolidationObject; 043 private Chart chartOfAccounts; 044 045 046 /** 047 * Constructs a ObjLevel.java. 048 */ 049 public ObjectLevel() { 050 super(); 051 this.financialConsolidationObject = new ObjectConsolidation(); 052 } 053 054 /** 055 * Gets the financialObjectLevelCode attribute. 056 * 057 * @return Returns the financialObjectLevelCode 058 */ 059 public String getFinancialObjectLevelCode() { 060 return financialObjectLevelCode; 061 } 062 063 /** 064 * Sets the financialObjectLevelCode attribute. 065 * 066 * @param financialObjectLevelCode The financialObjectLevelCode to set. 067 */ 068 public void setFinancialObjectLevelCode(String financialObjectLevelCode) { 069 this.financialObjectLevelCode = financialObjectLevelCode; 070 } 071 072 /** 073 * Gets the financialObjectLevelName attribute. 074 * 075 * @return Returns the financialObjectLevelName 076 */ 077 public String getFinancialObjectLevelName() { 078 return financialObjectLevelName; 079 } 080 081 /** 082 * Sets the financialObjectLevelName attribute. 083 * 084 * @param financialObjectLevelName The financialObjectLevelName to set. 085 */ 086 public void setFinancialObjectLevelName(String financialObjectLevelName) { 087 this.financialObjectLevelName = financialObjectLevelName; 088 } 089 090 /** 091 * Gets the financialObjectLevelShortNm attribute. 092 * 093 * @return Returns the financialObjectLevelShortNm 094 */ 095 public String getFinancialObjectLevelShortNm() { 096 return financialObjectLevelShortNm; 097 } 098 099 /** 100 * Sets the financialObjectLevelShortNm attribute. 101 * 102 * @param financialObjectLevelShortNm The financialObjectLevelShortNm to set. 103 */ 104 public void setFinancialObjectLevelShortNm(String financialObjectLevelShortNm) { 105 this.financialObjectLevelShortNm = financialObjectLevelShortNm; 106 } 107 108 /** 109 * Gets the financialObjectLevelActiveIndicator attribute. 110 * 111 * @return Returns the financialObjectLevelActiveIndicator 112 */ 113 public boolean isActive() { 114 return active; 115 } 116 117 /** 118 * Sets the financialObjectLevelActiveIndicator attribute. 119 * 120 * @param financialObjectLevelActiveIndicator The financialObjectLevelActiveIndicator to set. 121 */ 122 public void setActive(boolean financialObjectLevelActiveIndicator) { 123 this.active = financialObjectLevelActiveIndicator; 124 } 125 126 /** 127 * Gets the financialReportingSortCode attribute. 128 * 129 * @return Returns the financialReportingSortCode 130 */ 131 public String getFinancialReportingSortCode() { 132 return financialReportingSortCode; 133 } 134 135 /** 136 * Sets the financialReportingSortCode attribute. 137 * 138 * @param financialReportingSortCode The financialReportingSortCode to set. 139 */ 140 public void setFinancialReportingSortCode(String financialReportingSortCode) { 141 this.financialReportingSortCode = financialReportingSortCode; 142 } 143 144 145 public String getConsolidatedObjectCode() { 146 return financialConsolidationObject.getFinancialReportingSortCode(); 147 } 148 149 /** 150 * Gets the financialConsolidationObject attribute. 151 * 152 * @return Returns the financialConsolidationObject 153 */ 154 public ObjectConsolidation getFinancialConsolidationObject() { 155 return financialConsolidationObject; 156 } 157 158 /** 159 * Sets the financialConsolidationObject attribute. 160 * 161 * @param financialConsolidationObject The financialConsolidationObject to set. 162 */ 163 public void setFinancialConsolidationObject(ObjectConsolidation financialConsolidationObject) { 164 this.financialConsolidationObject = financialConsolidationObject; 165 } 166 167 public String getChartOfAccountsCode() { 168 return chartOfAccountsCode; 169 } 170 171 /** 172 * Gets the chartOfAccounts attribute. 173 * 174 * @return Returns the chartOfAccounts 175 */ 176 public Chart getChartOfAccounts() { 177 return chartOfAccounts; 178 } 179 180 /** 181 * Sets the chartOfAccounts attribute. 182 * 183 * @param chartOfAccounts The chartOfAccounts to set. 184 * @deprecated 185 */ 186 public void setChartOfAccounts(Chart chartOfAccounts) { 187 this.chartOfAccounts = chartOfAccounts; 188 } 189 190 191 /** 192 * @return Returns the financialConsolidationObjectCode. 193 */ 194 public String getFinancialConsolidationObjectCode() { 195 return financialConsolidationObjectCode; 196 } 197 198 /** 199 * @param financialConsolidationObjectCode The financialConsolidationObjectCode to set. 200 */ 201 public void setFinancialConsolidationObjectCode(String financialConsolidationObjectCode) { 202 this.financialConsolidationObjectCode = financialConsolidationObjectCode; 203 } 204 205 /** 206 * @see org.kuali.rice.kns.bo.BusinessObjectBase#toStringMapper() 207 */ 208 protected LinkedHashMap toStringMapper() { 209 LinkedHashMap m = new LinkedHashMap(); 210 211 m.put("chartOfAccountsCode", this.chartOfAccountsCode); 212 m.put("financialObjectLevelCode", this.financialObjectLevelCode); 213 214 return m; 215 } 216 217 public void setChartOfAccountsCode(String chart) { 218 this.chartOfAccountsCode = chart; 219 } 220 221 @Override 222 public void beforeUpdate(PersistenceBroker persistenceBroker) throws PersistenceBrokerException { 223 super.beforeUpdate(persistenceBroker); 224 try { 225 // KULCOA-549: update the sufficient funds table 226 // get the current data from the database 227 BusinessObjectService boService = SpringContext.getBean(BusinessObjectService.class); 228 ObjectLevel originalObjLevel = (ObjectLevel) boService.retrieve(this); 229 230 if (originalObjLevel != null) { 231 if (!originalObjLevel.getFinancialConsolidationObjectCode().equals(getFinancialConsolidationObjectCode())) { 232 SufficientFundRebuild sfr = new SufficientFundRebuild(); 233 sfr.setAccountFinancialObjectTypeCode(SufficientFundRebuild.REBUILD_OBJECT); 234 sfr.setChartOfAccountsCode(originalObjLevel.getChartOfAccountsCode()); 235 sfr.setAccountNumberFinancialObjectCode(originalObjLevel.getFinancialConsolidationObjectCode()); 236 if (boService.retrieve(sfr) == null) { 237 persistenceBroker.store(sfr); 238 } 239 sfr = new SufficientFundRebuild(); 240 sfr.setAccountFinancialObjectTypeCode(SufficientFundRebuild.REBUILD_OBJECT); 241 sfr.setChartOfAccountsCode(getChartOfAccountsCode()); 242 sfr.setAccountNumberFinancialObjectCode(getFinancialConsolidationObjectCode()); 243 if (boService.retrieve(sfr) == null) { 244 persistenceBroker.store(sfr); 245 } 246 } 247 } 248 } 249 catch (Exception ex) { 250 LOG.error("Problem updating sufficient funds rebuild table: ", ex); 251 } 252 } 253 254 }