001: /*
002: * Copyright 2007 The Kuali Foundation.
003: *
004: * Licensed under the Educational Community License, Version 1.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/ecl1.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:
017: package org.kuali.module.chart.bo;
018:
019: import java.util.ArrayList;
020: import java.util.HashMap;
021: import java.util.LinkedHashMap;
022: import java.util.List;
023: import java.util.Map;
024:
025: import org.kuali.core.bo.DocumentHeader;
026: import org.kuali.core.bo.GlobalBusinessObject;
027: import org.kuali.core.bo.GlobalBusinessObjectDetail;
028: import org.kuali.core.bo.PersistableBusinessObject;
029: import org.kuali.core.bo.PersistableBusinessObjectBase;
030: import org.kuali.core.service.BusinessObjectService;
031: import org.kuali.core.util.TypedArrayList;
032: import org.kuali.kfs.KFSPropertyConstants;
033: import org.kuali.kfs.bo.Options;
034: import org.kuali.kfs.context.SpringContext;
035:
036: /**
037: *
038: */
039: public class SubObjCdGlobal extends PersistableBusinessObjectBase
040: implements GlobalBusinessObject {
041:
042: private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger
043: .getLogger(SubObjCdGlobal.class);
044:
045: private String documentNumber;
046: private Integer universityFiscalYear;
047: private String chartOfAccountsCode;
048: private String financialSubObjectCode;
049: private String financialSubObjectCodeName;
050: private String financialSubObjectCodeShortName;
051: private boolean financialSubObjectActiveIndicator;
052:
053: private DocumentHeader financialDocument;
054: private Options universityFiscal;
055: private Chart chartOfAccounts;
056:
057: private List<SubObjCdGlobalDetail> subObjCdGlobalDetails;
058: private List<AccountGlobalDetail> accountGlobalDetails;
059:
060: /**
061: * Default constructor.
062: */
063: public SubObjCdGlobal() {
064:
065: subObjCdGlobalDetails = new TypedArrayList(
066: SubObjCdGlobalDetail.class);
067: accountGlobalDetails = new TypedArrayList(
068: AccountGlobalDetail.class);
069:
070: }
071:
072: /**
073: * Gets the documentNumber attribute.
074: *
075: * @return Returns the documentNumber
076: */
077: public String getDocumentNumber() {
078: return documentNumber;
079: }
080:
081: /**
082: * Sets the documentNumber attribute.
083: *
084: * @param documentNumber The documentNumber to set.
085: */
086: public void setDocumentNumber(String documentNumber) {
087: this .documentNumber = documentNumber;
088: }
089:
090: /**
091: * Gets the universityFiscalYear attribute.
092: *
093: * @return Returns the universityFiscalYear
094: */
095: public Integer getUniversityFiscalYear() {
096: return universityFiscalYear;
097: }
098:
099: /**
100: * Sets the universityFiscalYear attribute.
101: *
102: * @param universityFiscalYear The universityFiscalYear to set.
103: */
104: public void setUniversityFiscalYear(Integer universityFiscalYear) {
105: this .universityFiscalYear = universityFiscalYear;
106: }
107:
108: /**
109: * Gets the chartOfAccountsCode attribute.
110: *
111: * @return Returns the chartOfAccountsCode
112: */
113: public String getChartOfAccountsCode() {
114: return chartOfAccountsCode;
115: }
116:
117: /**
118: * Sets the chartOfAccountsCode attribute.
119: *
120: * @param chartOfAccountsCode The chartOfAccountsCode to set.
121: */
122: public void setChartOfAccountsCode(String chartOfAccountsCode) {
123: this .chartOfAccountsCode = chartOfAccountsCode;
124: }
125:
126: /**
127: * Gets the financialSubObjectCode attribute.
128: *
129: * @return Returns the financialSubObjectCode
130: */
131: public String getFinancialSubObjectCode() {
132: return financialSubObjectCode;
133: }
134:
135: /**
136: * Sets the financialSubObjectCode attribute.
137: *
138: * @param financialSubObjectCode The financialSubObjectCode to set.
139: */
140: public void setFinancialSubObjectCode(String financialSubObjectCode) {
141: this .financialSubObjectCode = financialSubObjectCode;
142: }
143:
144: /**
145: * Gets the financialSubObjectCodeName attribute.
146: *
147: * @return Returns the financialSubObjectCodeName
148: */
149: public String getFinancialSubObjectCodeName() {
150: return financialSubObjectCodeName;
151: }
152:
153: /**
154: * Sets the financialSubObjectCodeName attribute.
155: *
156: * @param financialSubObjectCodeName The financialSubObjectCodeName to set.
157: */
158: public void setFinancialSubObjectCodeName(
159: String financialSubObjectCodeName) {
160: this .financialSubObjectCodeName = financialSubObjectCodeName;
161: }
162:
163: /**
164: * Gets the financialSubObjectCodeShortName attribute.
165: *
166: * @return Returns the financialSubObjectCodeShortName
167: */
168: public String getFinancialSubObjectCodeShortName() {
169: return financialSubObjectCodeShortName;
170: }
171:
172: /**
173: * Sets the financialSubObjectCodeShortName attribute.
174: *
175: * @param financialSubObjectCodeShortName The financialSubObjectCodeShortName to set.
176: */
177: public void setFinancialSubObjectCodeShortName(
178: String financialSubObjectCdshortNm) {
179: this .financialSubObjectCodeShortName = financialSubObjectCdshortNm;
180: }
181:
182: /**
183: * Gets the financialSubObjectActiveIndicator attribute.
184: *
185: * @return Returns the financialSubObjectActiveIndicator
186: */
187: public boolean isFinancialSubObjectActiveIndicator() {
188: return financialSubObjectActiveIndicator;
189: }
190:
191: /**
192: * Sets the financialSubObjectActiveIndicator attribute.
193: *
194: * @param financialSubObjectActiveIndicator The financialSubObjectActiveIndicator to set.
195: */
196: public void setFinancialSubObjectActiveIndicator(
197: boolean financialSubObjectActiveIndicator) {
198: this .financialSubObjectActiveIndicator = financialSubObjectActiveIndicator;
199: }
200:
201: /**
202: * Gets the financialDocument attribute.
203: *
204: * @return Returns the financialDocument
205: */
206: public DocumentHeader getFinancialDocument() {
207: return financialDocument;
208: }
209:
210: /**
211: * Sets the financialDocument attribute.
212: *
213: * @param financialDocument The financialDocument to set.
214: * @deprecated
215: */
216: public void setFinancialDocument(DocumentHeader financialDocument) {
217: this .financialDocument = financialDocument;
218: }
219:
220: /**
221: * Gets the universityFiscal attribute.
222: *
223: * @return Returns the universityFiscal
224: */
225: public Options getUniversityFiscal() {
226: return universityFiscal;
227: }
228:
229: /**
230: * Sets the universityFiscal attribute.
231: *
232: * @param universityFiscal The universityFiscal to set.
233: * @deprecated
234: */
235: public void setUniversityFiscal(Options universityFiscal) {
236: this .universityFiscal = universityFiscal;
237: }
238:
239: /**
240: * Gets the chartOfAccounts attribute.
241: *
242: * @return Returns the chartOfAccounts
243: */
244: public Chart getChartOfAccounts() {
245: return chartOfAccounts;
246: }
247:
248: /**
249: * Sets the chartOfAccounts attribute.
250: *
251: * @param chartOfAccounts The chartOfAccounts to set.
252: * @deprecated
253: */
254: public void setChartOfAccounts(Chart chartOfAccounts) {
255: this .chartOfAccounts = chartOfAccounts;
256: }
257:
258: /**
259: * @see org.kuali.core.bo.BusinessObjectBase#toStringMapper()
260: */
261: protected LinkedHashMap toStringMapper() {
262: LinkedHashMap m = new LinkedHashMap();
263: m
264: .put(KFSPropertyConstants.DOCUMENT_NUMBER,
265: this .documentNumber);
266: return m;
267: }
268:
269: public List<SubObjCdGlobalDetail> getSubObjCdGlobalDetails() {
270: return subObjCdGlobalDetails;
271: }
272:
273: public void setSubObjCdGlobalDetails(
274: List<SubObjCdGlobalDetail> subObjCdGlobalDetails) {
275: this .subObjCdGlobalDetails = subObjCdGlobalDetails;
276: }
277:
278: public List<AccountGlobalDetail> getAccountGlobalDetails() {
279: return accountGlobalDetails;
280: }
281:
282: public void setAccountGlobalDetails(
283: List<AccountGlobalDetail> accountGlobalDetails) {
284: this .accountGlobalDetails = accountGlobalDetails;
285: }
286:
287: /**
288: * @see org.kuali.core.document.GlobalBusinessObject#getGlobalChangesToDelete()
289: */
290: public List<PersistableBusinessObject> generateDeactivationsToPersist() {
291: return null;
292: }
293:
294: /**
295: * This returns a list of Sub Object Codes to Update and/or Add
296: *
297: * @see org.kuali.core.document.GlobalBusinessObject#applyGlobalChanges()
298: */
299: public List<PersistableBusinessObject> generateGlobalChangesToPersist() {
300: LOG.debug("applyGlobalChanges");
301: List result = new ArrayList();
302:
303: // Iterate through Account/Object Code combinations; create new or update as necessary
304:
305: for (SubObjCdGlobalDetail subObjCdGlobalDetail : subObjCdGlobalDetails) {
306:
307: String financialObjectCode = subObjCdGlobalDetail
308: .getFinancialObjectCode();
309:
310: if (financialObjectCode != null
311: && financialObjectCode.length() > 0) {
312:
313: for (AccountGlobalDetail accountGlobalDetail : accountGlobalDetails) {
314:
315: Map pk = new HashMap();
316:
317: String accountNumber = accountGlobalDetail
318: .getAccountNumber();
319:
320: if (accountNumber != null
321: && accountNumber.length() > 0) {
322: pk.put("UNIV_FISCAL_YR",
323: this .universityFiscalYear);
324: pk.put("FIN_COA_CD", this .chartOfAccountsCode);
325: pk.put("ACCOUNT_NBR", accountNumber);
326: pk.put("FIN_OBJECT_CD", financialObjectCode);
327: pk.put("FIN_SUB_OBJ_CD",
328: this .financialSubObjectCode);
329:
330: SubObjCd subObjCd = (SubObjCd) SpringContext
331: .getBean(BusinessObjectService.class)
332: .findByPrimaryKey(SubObjCd.class, pk);
333: if (subObjCd == null) {
334: subObjCd = new SubObjCd(
335: this .universityFiscalYear,
336: this .chartOfAccountsCode,
337: accountNumber, financialObjectCode,
338: this .financialSubObjectCode);
339: }
340: populate(subObjCd, accountGlobalDetail,
341: subObjCdGlobalDetail);
342: result.add(subObjCd);
343: }
344: }
345: }
346: }
347:
348: return result;
349: }
350:
351: public void populate(SubObjCd old,
352: AccountGlobalDetail accountGlobalDetail,
353: SubObjCdGlobalDetail subObjCdGlobalDetail) {
354: old.setFinancialSubObjectCodeName(update(old
355: .getFinancialSubObjectCodeName(),
356: financialSubObjectCodeName));
357: old.setFinancialSubObjectCdshortNm(update(old
358: .getFinancialSubObjectCdshortNm(),
359: financialSubObjectCodeShortName));
360: old.setFinancialSubObjectActiveIndicator(update(old
361: .isFinancialSubObjectActiveIndicator(),
362: financialSubObjectActiveIndicator));
363: }
364:
365: /**
366: * This method returns newvalue iff it is not empty
367: *
368: * @param oldValue
369: * @param newValue
370: * @return
371: */
372: private String update(String oldValue, String newValue) {
373: if (newValue == null || newValue.length() == 0) {
374: return oldValue;
375: }
376: return newValue;
377: }
378:
379: private boolean update(boolean oldValue, boolean newValue) {
380: return newValue;
381: }
382:
383: public boolean isPersistable() {
384: return true;
385: }
386:
387: public List<? extends GlobalBusinessObjectDetail> getAllDetailObjects() {
388: ArrayList<GlobalBusinessObjectDetail> details = new ArrayList<GlobalBusinessObjectDetail>(
389: accountGlobalDetails.size()
390: + subObjCdGlobalDetails.size());
391: details.addAll(accountGlobalDetails);
392: details.addAll(subObjCdGlobalDetails);
393: return details;
394: }
395:
396: /**
397: * @see org.kuali.core.bo.PersistableBusinessObjectBase#buildListOfDeletionAwareLists()
398: */
399: @Override
400: public List buildListOfDeletionAwareLists() {
401: List<List> managedLists = super.buildListOfDeletionAwareLists();
402:
403: managedLists.add(getAccountGlobalDetails());
404: managedLists.add(getSubObjCdGlobalDetails());
405:
406: return managedLists;
407: }
408: }
|