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: package org.kuali.module.chart.bo;
017:
018: import java.util.ArrayList;
019: import java.util.HashMap;
020: import java.util.LinkedHashMap;
021: import java.util.List;
022: import java.util.Map;
023:
024: import org.apache.commons.lang.StringUtils;
025: import org.kuali.core.bo.GlobalBusinessObject;
026: import org.kuali.core.bo.GlobalBusinessObjectDetail;
027: import org.kuali.core.bo.PersistableBusinessObject;
028: import org.kuali.core.bo.PersistableBusinessObjectBase;
029: import org.kuali.core.service.BusinessObjectService;
030: import org.kuali.core.service.PersistenceStructureService;
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: import org.kuali.module.chart.service.OrganizationReversionService;
036:
037: /**
038: * The representation of a Global Organization Reversion. A Global Organization Reversion is made up of three sections: 1. The
039: * University Fiscal Year and Chart of Accounts code for the Organizations going through reversion, with some account information.
040: * 2. A list of the appropriate Object Reversion Details 3. A list of Organizations to apply the Organization Reversion to
041: */
042: public class OrganizationReversionGlobal extends
043: PersistableBusinessObjectBase implements GlobalBusinessObject {
044: protected static org.apache.log4j.Logger LOG = org.apache.log4j.Logger
045: .getLogger(OrganizationReversionGlobal.class);
046: private String documentNumber;
047:
048: private Integer universityFiscalYear;
049: private String budgetReversionChartOfAccountsCode;
050: private String budgetReversionAccountNumber;
051: private Boolean carryForwardByObjectCodeIndicator;
052: private String cashReversionFinancialChartOfAccountsCode;
053: private String cashReversionAccountNumber;
054:
055: private Account cashReversionAccount;
056: private Account budgetReversionAccount;
057: private Chart budgetReversionChartOfAccounts;
058: private Chart cashReversionFinancialChartOfAccounts;
059: private Options universityFiscal;
060:
061: private List<OrganizationReversionGlobalDetail> organizationReversionGlobalDetails;
062: private List<OrganizationReversionGlobalOrganization> organizationReversionGlobalOrganizations;
063:
064: public OrganizationReversionGlobal() {
065: super ();
066: organizationReversionGlobalDetails = new TypedArrayList(
067: OrganizationReversionGlobalDetail.class);
068: organizationReversionGlobalOrganizations = new TypedArrayList(
069: OrganizationReversionGlobalOrganization.class);
070: }
071:
072: /**
073: * @see org.kuali.core.bo.BusinessObjectBase#toStringMapper()
074: */
075: @Override
076: protected LinkedHashMap toStringMapper() {
077: LinkedHashMap stringMapper = new LinkedHashMap();
078: stringMapper.put(KFSPropertyConstants.DOCUMENT_NUMBER,
079: this .documentNumber);
080: stringMapper.put(KFSPropertyConstants.UNIVERSITY_FISCAL_YEAR,
081: this .universityFiscalYear);
082: return stringMapper;
083: }
084:
085: /**
086: * Gets the budgetReversionAccount attribute.
087: *
088: * @return Returns the budgetReversionAccount.
089: */
090: public Account getBudgetReversionAccount() {
091: return budgetReversionAccount;
092: }
093:
094: /**
095: * Gets the documentNumber attribute.
096: *
097: * @return Returns the documentNumber.
098: */
099: public String getDocumentNumber() {
100: return documentNumber;
101: }
102:
103: /**
104: * Sets the documentNumber attribute value.
105: *
106: * @param documentNumber The documentNumber to set.
107: */
108: public void setDocumentNumber(String documentNumber) {
109: this .documentNumber = documentNumber;
110: }
111:
112: /**
113: * Sets the budgetReversionAccount attribute value.
114: *
115: * @param budgetReversionAccount The budgetReversionAccount to set.
116: * @deprecated
117: */
118: public void setBudgetReversionAccount(Account budgetReversionAccount) {
119: this .budgetReversionAccount = budgetReversionAccount;
120: }
121:
122: /**
123: * Gets the budgetReversionAccountNumber attribute.
124: *
125: * @return Returns the budgetReversionAccountNumber.
126: */
127: public String getBudgetReversionAccountNumber() {
128: return budgetReversionAccountNumber;
129: }
130:
131: /**
132: * Sets the budgetReversionAccountNumber attribute value.
133: *
134: * @param budgetReversionAccountNumber The budgetReversionAccountNumber to set.
135: */
136: public void setBudgetReversionAccountNumber(
137: String budgetReversionAccountNumber) {
138: this .budgetReversionAccountNumber = budgetReversionAccountNumber;
139: }
140:
141: /**
142: * Gets the budgetReversionChartOfAccounts attribute.
143: *
144: * @return Returns the budgetReversionChartOfAccounts.
145: */
146: public Chart getBudgetReversionChartOfAccounts() {
147: return budgetReversionChartOfAccounts;
148: }
149:
150: /**
151: * Sets the budgetReversionChartOfAccounts attribute value.
152: *
153: * @param budgetReversionChartOfAccounts The budgetReversionChartOfAccounts to set.
154: * @deprecated
155: */
156: public void setBudgetReversionChartOfAccounts(
157: Chart budgetReversionChartOfAccounts) {
158: this .budgetReversionChartOfAccounts = budgetReversionChartOfAccounts;
159: }
160:
161: /**
162: * Gets the budgetReversionChartOfAccountsCode attribute.
163: *
164: * @return Returns the budgetReversionChartOfAccountsCode.
165: */
166: public String getBudgetReversionChartOfAccountsCode() {
167: return budgetReversionChartOfAccountsCode;
168: }
169:
170: /**
171: * Sets the budgetReversionChartOfAccountsCode attribute value.
172: *
173: * @param budgetReversionChartOfAccountsCode The budgetReversionChartOfAccountsCode to set.
174: */
175: public void setBudgetReversionChartOfAccountsCode(
176: String budgetReversionChartOfAccountsCode) {
177: this .budgetReversionChartOfAccountsCode = budgetReversionChartOfAccountsCode;
178: }
179:
180: /**
181: * Gets the carryForwardByObjectCodeIndicator attribute.
182: *
183: * @return Returns the carryForwardByObjectCodeIndicator.
184: */
185: public Boolean isCarryForwardByObjectCodeIndicator() {
186: return carryForwardByObjectCodeIndicator;
187: }
188:
189: /**
190: * Gets the carryForwardByObjectCodeIndicator attribute: but for other methods that don't like to call "is" and would rather
191: * call "get"
192: *
193: * @return Returns the carryForwardByObjectCodeIndicator.
194: */
195: public Boolean getCarryForwardByObjectCodeIndicator() {
196: return this .isCarryForwardByObjectCodeIndicator();
197: }
198:
199: /**
200: * Sets the carryForwardByObjectCodeIndicator attribute value.
201: *
202: * @param carryForwardByObjectCodeIndicator The carryForwardByObjectCodeIndicator to set.
203: */
204: public void setCarryForwardByObjectCodeIndicator(
205: Boolean carryForwardByObjectCodeIndicator) {
206: this .carryForwardByObjectCodeIndicator = carryForwardByObjectCodeIndicator;
207: }
208:
209: /**
210: * Gets the cashReversionAccount attribute.
211: *
212: * @return Returns the cashReversionAccount.
213: */
214: public Account getCashReversionAccount() {
215: return cashReversionAccount;
216: }
217:
218: /**
219: * Sets the cashReversionAccount attribute value.
220: *
221: * @param cashReversionAccount The cashReversionAccount to set.
222: * @deprecated
223: */
224: public void setCashReversionAccount(Account cashReversionAccount) {
225: this .cashReversionAccount = cashReversionAccount;
226: }
227:
228: /**
229: * Gets the cashReversionAccountNumber attribute.
230: *
231: * @return Returns the cashReversionAccountNumber.
232: */
233: public String getCashReversionAccountNumber() {
234: return cashReversionAccountNumber;
235: }
236:
237: /**
238: * Sets the cashReversionAccountNumber attribute value.
239: *
240: * @param cashReversionAccountNumber The cashReversionAccountNumber to set.
241: */
242: public void setCashReversionAccountNumber(
243: String cashReversionAccountNumber) {
244: this .cashReversionAccountNumber = cashReversionAccountNumber;
245: }
246:
247: /**
248: * Gets the cashReversionFinancialChartOfAccounts attribute.
249: *
250: * @return Returns the cashReversionFinancialChartOfAccounts.
251: */
252: public Chart getCashReversionFinancialChartOfAccounts() {
253: return cashReversionFinancialChartOfAccounts;
254: }
255:
256: /**
257: * Sets the cashReversionFinancialChartOfAccounts attribute value.
258: *
259: * @param cashReversionFinancialChartOfAccounts The cashReversionFinancialChartOfAccounts to set.
260: * @deprecated
261: */
262: public void setCashReversionFinancialChartOfAccounts(
263: Chart cashReversionFinancialChartOfAccounts) {
264: this .cashReversionFinancialChartOfAccounts = cashReversionFinancialChartOfAccounts;
265: }
266:
267: /**
268: * Gets the cashReversionFinancialChartOfAccountsCode attribute.
269: *
270: * @return Returns the cashReversionFinancialChartOfAccountsCode.
271: */
272: public String getCashReversionFinancialChartOfAccountsCode() {
273: return cashReversionFinancialChartOfAccountsCode;
274: }
275:
276: /**
277: * Sets the cashReversionFinancialChartOfAccountsCode attribute value.
278: *
279: * @param cashReversionFinancialChartOfAccountsCode The cashReversionFinancialChartOfAccountsCode to set.
280: */
281: public void setCashReversionFinancialChartOfAccountsCode(
282: String cashReversionFinancialChartOfAccountsCode) {
283: this .cashReversionFinancialChartOfAccountsCode = cashReversionFinancialChartOfAccountsCode;
284: }
285:
286: /**
287: * Gets the organizationReversionGlobalOrganizations attribute.
288: *
289: * @return Returns the organizationReversionGlobalOrganizations.
290: */
291: public List<OrganizationReversionGlobalOrganization> getOrganizationReversionGlobalOrganizations() {
292: return organizationReversionGlobalOrganizations;
293: }
294:
295: /**
296: * Sets the organizationReversionGlobalOrganizations attribute value.
297: *
298: * @param organizationReversionGlobalOrganizations The organizationReversionGlobalOrganizations to set.
299: * @deprecated
300: */
301: public void setOrganizationReversionGlobalOrganizations(
302: List<OrganizationReversionGlobalOrganization> organizationReversionGlobalOrganizations) {
303: this .organizationReversionGlobalOrganizations = organizationReversionGlobalOrganizations;
304: }
305:
306: /**
307: * Gets the organizationReversionGlobalDocumentDetails attribute.
308: *
309: * @return Returns the organizationReversionGlobalDocumentDetails.
310: */
311: public List<OrganizationReversionGlobalDetail> getOrganizationReversionGlobalDetails() {
312: return organizationReversionGlobalDetails;
313: }
314:
315: /**
316: * Sets the organizationReversionGlobalDocumentDetails attribute value.
317: *
318: * @param organizationReversionGlobalDocumentDetails The organizationReversionGlobalDocumentDetails to set.
319: */
320: public void setOrganizationReversionGlobalDetails(
321: List<OrganizationReversionGlobalDetail> organizationReversionGlobalDetails) {
322: this .organizationReversionGlobalDetails = organizationReversionGlobalDetails;
323: }
324:
325: /**
326: * Gets the universityFiscalYear attribute.
327: *
328: * @return Returns the universityFiscalYear.
329: */
330: public Integer getUniversityFiscalYear() {
331: return universityFiscalYear;
332: }
333:
334: /**
335: * Sets the universityFiscalYear attribute value.
336: *
337: * @param universityFiscalYear The universityFiscalYear to set.
338: */
339: public void setUniversityFiscalYear(Integer universityFiscalYear) {
340: this .universityFiscalYear = universityFiscalYear;
341: }
342:
343: /**
344: * Gets the universityFiscal attribute.
345: *
346: * @return Returns the universityFiscal.
347: */
348: public Options getUniversityFiscal() {
349: return universityFiscal;
350: }
351:
352: /**
353: * Sets the universityFiscal attribute value.
354: *
355: * @param universityFiscal The universityFiscal to set.
356: */
357: public void setUniversityFiscal(Options universityFiscal) {
358: this .universityFiscal = universityFiscal;
359: }
360:
361: /**
362: * @see org.kuali.core.bo.GlobalBusinessObject#generateDeactivationsToPersist() As global organization reversions only update
363: * existing records, deactivations will never be produced by creating one; thus, this method always returns an empty list.
364: */
365: public List<PersistableBusinessObject> generateDeactivationsToPersist() {
366: return null;
367: }
368:
369: /**
370: * @see org.kuali.core.bo.GlobalBusinessObject#generateGlobalChangesToPersist() This creates a list of changes to be made to the
371: * existing Organization Reversion records impacted by this global reversion.
372: */
373: public List<PersistableBusinessObject> generateGlobalChangesToPersist() {
374: List<PersistableBusinessObject> persistingChanges = new ArrayList<PersistableBusinessObject>();
375:
376: BusinessObjectService boService = SpringContext
377: .getBean(BusinessObjectService.class);
378: Map<OrganizationReversionCategory, OrganizationReversionGlobalDetail> detailsMap = this
379: .rearrangeOrganizationReversionDetailsAsMap();
380:
381: for (OrganizationReversionGlobalOrganization orgRevOrg : this
382: .getOrganizationReversionGlobalOrganizations()) {
383: // 1. find that organization reversion
384: OrganizationReversion currOrgRev = SpringContext.getBean(
385: OrganizationReversionService.class).getByPrimaryId(
386: this .getUniversityFiscalYear(),
387: orgRevOrg.getChartOfAccountsCode(),
388: orgRevOrg.getOrganizationCode());
389:
390: if (currOrgRev != null) { // only proceed if there's a pre-existing org reversion; we don't want to insert any new
391: // records
392: if (!StringUtils.isBlank(this
393: .getBudgetReversionChartOfAccountsCode())) {
394: currOrgRev
395: .setBudgetReversionChartOfAccountsCode(this
396: .getBudgetReversionChartOfAccountsCode());
397: }
398: if (!StringUtils.isBlank(this
399: .getBudgetReversionAccountNumber())) {
400: currOrgRev.setBudgetReversionAccountNumber(this
401: .getBudgetReversionAccountNumber());
402: }
403: if (!StringUtils
404: .isBlank(this
405: .getCashReversionFinancialChartOfAccountsCode())) {
406: currOrgRev
407: .setCashReversionFinancialChartOfAccountsCode(this
408: .getCashReversionFinancialChartOfAccountsCode());
409: }
410: if (!StringUtils.isBlank(this
411: .getCashReversionAccountNumber())) {
412: currOrgRev.setCashReversionAccountNumber(this
413: .getCashReversionAccountNumber());
414: }
415:
416: if (this .isCarryForwardByObjectCodeIndicator() != null) {
417: currOrgRev
418: .setCarryForwardByObjectCodeIndicator(this
419: .isCarryForwardByObjectCodeIndicator()
420: .booleanValue());
421: }
422:
423: // 3. now, go through each org reversion detail and update each of those
424: for (OrganizationReversionDetail orgRevDetail : currOrgRev
425: .getOrganizationReversionDetail()) {
426: OrganizationReversionGlobalDetail changeDetail = detailsMap
427: .get(orgRevDetail
428: .getOrganizationReversionCategory());
429: if (changeDetail != null) {
430: if (!StringUtils.isBlank(changeDetail
431: .getOrganizationReversionCode())) {
432: orgRevDetail
433: .setOrganizationReversionCode(changeDetail
434: .getOrganizationReversionCode());
435: }
436: if (!StringUtils.isBlank(changeDetail
437: .getOrganizationReversionObjectCode())) {
438: orgRevDetail
439: .setOrganizationReversionObjectCode(changeDetail
440: .getOrganizationReversionObjectCode());
441: }
442: }
443: }
444:
445: currOrgRev.refreshNonUpdateableReferences();
446: persistingChanges.add(currOrgRev);
447: }
448:
449: }
450: return persistingChanges;
451: }
452:
453: /**
454: * This sticks all of the Organization Reversion Change Details into a map, for quicker access in
455: * generateGlobalChangesToPersist.
456: *
457: * @return a map of all organization reversion change details, keyed by OrganizationReversionCategory
458: */
459: private Map<OrganizationReversionCategory, OrganizationReversionGlobalDetail> rearrangeOrganizationReversionDetailsAsMap() {
460: Map<OrganizationReversionCategory, OrganizationReversionGlobalDetail> orgRevMap = new HashMap<OrganizationReversionCategory, OrganizationReversionGlobalDetail>();
461: for (OrganizationReversionGlobalDetail orgRevDetail : this
462: .getOrganizationReversionGlobalDetails()) {
463: if (!StringUtils.isBlank(orgRevDetail
464: .getOrganizationReversionObjectCode())
465: && !StringUtils.isBlank(orgRevDetail
466: .getOrganizationReversionCode())) {
467: orgRevMap.put(orgRevDetail
468: .getOrganizationReversionCategory(),
469: orgRevDetail);
470: }
471: }
472: return orgRevMap;
473: }
474:
475: /**
476: * @see org.kuali.core.bo.GlobalBusinessObject#getAllDetailObjects() This returns a list of all the detail objects held within
477: * this main global organization reversion container.
478: */
479: public List<? extends GlobalBusinessObjectDetail> getAllDetailObjects() {
480: List<GlobalBusinessObjectDetail> detailObjects = new ArrayList<GlobalBusinessObjectDetail>();
481: detailObjects.addAll(this
482: .getOrganizationReversionGlobalDetails());
483: detailObjects.addAll(this
484: .getOrganizationReversionGlobalOrganizations());
485: return detailObjects;
486: }
487:
488: /**
489: * @see org.kuali.core.bo.GlobalBusinessObject#isPersistable() returns whether this global object reversion can be stored in the
490: * database, which is really a question of whether it and all of its details have all of their appropriate primary keys
491: * set.
492: */
493: public boolean isPersistable() {
494: PersistenceStructureService persistenceStructureService = SpringContext
495: .getBean(PersistenceStructureService.class);
496:
497: if (!persistenceStructureService.hasPrimaryKeyFieldValues(this )) {
498: return false;
499: }
500:
501: for (OrganizationReversionGlobalDetail orgRevDetail : this
502: .getOrganizationReversionGlobalDetails()) {
503: if (!persistenceStructureService
504: .hasPrimaryKeyFieldValues(orgRevDetail)) {
505: return false;
506: }
507: }
508:
509: for (OrganizationReversionGlobalOrganization orgRevOrg : this
510: .getOrganizationReversionGlobalOrganizations()) {
511: if (!persistenceStructureService
512: .hasPrimaryKeyFieldValues(orgRevOrg)) {
513: return false;
514: }
515: }
516:
517: // are we still here? really? Then, hey, let's persist!
518: return true;
519: }
520:
521: /**
522: * @see org.kuali.core.bo.PersistableBusinessObjectBase#buildListOfDeletionAwareLists()
523: */
524: @Override
525: public List buildListOfDeletionAwareLists() {
526: List<List> managedLists = super.buildListOfDeletionAwareLists();
527:
528: managedLists.add(getOrganizationReversionGlobalDetails());
529: managedLists.add(getOrganizationReversionGlobalOrganizations());
530:
531: return managedLists;
532: }
533: }
|