1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.ole.coa.document;
17
18 import java.util.List;
19 import java.util.Map;
20
21 import org.apache.commons.lang.StringUtils;
22 import org.kuali.ole.coa.businessobject.Chart;
23 import org.kuali.ole.coa.businessobject.ObjectCode;
24 import org.kuali.ole.coa.service.ObjectCodeService;
25 import org.kuali.ole.coa.service.SubObjectTrickleDownInactivationService;
26 import org.kuali.ole.sys.context.SpringContext;
27 import org.kuali.ole.sys.document.FinancialSystemMaintainable;
28 import org.kuali.rice.kns.document.MaintenanceDocument;
29 import org.kuali.rice.krad.maintenance.MaintenanceLock;
30 import org.kuali.rice.krad.util.KRADConstants;
31 import org.kuali.rice.krad.util.ObjectUtils;
32
33 public class ObjectCodeMaintainableImpl extends FinancialSystemMaintainable {
34
35 @Override
36 public List<MaintenanceLock> generateMaintenanceLocks() {
37 List<MaintenanceLock> maintenanceLocks = super.generateMaintenanceLocks();
38 ObjectCode maintainedObjectCode = (ObjectCode) getBusinessObject();
39 if (isInactivatingObjectCode()) {
40 maintenanceLocks.addAll(SpringContext.getBean(SubObjectTrickleDownInactivationService.class).generateTrickleDownMaintenanceLocks((ObjectCode) getBusinessObject(), getDocumentNumber()));
41 }
42 return maintenanceLocks;
43 }
44
45
46 @Override
47 public void saveBusinessObject() {
48 boolean isInactivatingObjectCode = isInactivatingObjectCode();
49
50 super.saveBusinessObject();
51
52 if (isInactivatingObjectCode) {
53 SpringContext.getBean(SubObjectTrickleDownInactivationService.class).trickleDownInactivateSubObjects((ObjectCode) getBusinessObject(), getDocumentNumber());
54 }
55 }
56
57 protected boolean isInactivatingObjectCode() {
58
59 if (KRADConstants.MAINTENANCE_EDIT_ACTION.equals(getMaintenanceAction()) && !((ObjectCode) getBusinessObject()).isActive()) {
60
61 ObjectCode objectCodeFromDB = retrieveObjectCodeFromDB();
62 if (ObjectUtils.isNotNull(objectCodeFromDB)) {
63 if (objectCodeFromDB.isActive()) {
64 return true;
65 }
66 }
67 }
68 return false;
69 }
70
71 protected ObjectCode retrieveObjectCodeFromDB() {
72 ObjectCode maintainedObjectCode = (ObjectCode) getBusinessObject();
73 ObjectCode oldObjectCode = SpringContext.getBean(ObjectCodeService.class).getByPrimaryId(maintainedObjectCode.getUniversityFiscalYear(), maintainedObjectCode.getChartOfAccountsCode(), maintainedObjectCode.getFinancialObjectCode());
74 return oldObjectCode;
75 }
76
77
78
79
80
81 @Override
82 public void refresh(String refreshCaller, Map fieldValues, MaintenanceDocument document) {
83 super.refresh(refreshCaller, fieldValues, document);
84 refreshReportsToChartOfAccountsCodeIfNecessary(document);
85 }
86
87
88
89
90
91 protected void refreshReportsToChartOfAccountsCodeIfNecessary(MaintenanceDocument document) {
92 final ObjectCode newObjectCode = (ObjectCode)document.getNewMaintainableObject().getBusinessObject();
93 if (!StringUtils.isBlank(newObjectCode.getChartOfAccountsCode())) {
94 newObjectCode.refreshReferenceObject("chartOfAccounts");
95 final Chart newChart = newObjectCode.getChartOfAccounts();
96
97 if (!ObjectUtils.isNull(newChart) && (StringUtils.isBlank(newObjectCode.getReportsToChartOfAccountsCode()) || !newObjectCode.getReportsToChartOfAccountsCode().equalsIgnoreCase(newChart.getReportsToChartOfAccountsCode()))) {
98 newObjectCode.setReportsToChartOfAccountsCode(newChart.getReportsToChartOfAccountsCode());
99 }
100 }
101 }
102 }