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.HashMap;
19 import java.util.Map;
20
21 import org.kuali.ole.coa.businessobject.OrganizationReversionCategory;
22 import org.kuali.ole.coa.service.OrganizationReversionDetailTrickleDownInactivationService;
23 import org.kuali.ole.sys.context.SpringContext;
24 import org.kuali.ole.sys.document.FinancialSystemMaintainable;
25 import org.kuali.rice.krad.service.BusinessObjectService;
26 import org.kuali.rice.krad.util.KRADConstants;
27 import org.kuali.rice.krad.util.ObjectUtils;
28
29
30
31
32 public class OrganizationReversionCategoryMaintainableImpl extends FinancialSystemMaintainable {
33
34
35
36
37
38 protected boolean isInactivatingOrganizationReversionCategory() {
39
40 if (KRADConstants.MAINTENANCE_EDIT_ACTION.equals(getMaintenanceAction()) && !((OrganizationReversionCategory) getBusinessObject()).isActive()) {
41 OrganizationReversionCategory existingOrganizationReversionCategoryFromDB = retrieveExistingOrganizationReversionCategory();
42 if (ObjectUtils.isNotNull(existingOrganizationReversionCategoryFromDB)) {
43
44 if (existingOrganizationReversionCategoryFromDB.isActive()) {
45 return true;
46 }
47 }
48 }
49 return false;
50 }
51
52
53
54
55
56 protected boolean isActivatingOrganizationReversionCategory() {
57
58 if (KRADConstants.MAINTENANCE_EDIT_ACTION.equals(getMaintenanceAction()) && ((OrganizationReversionCategory) getBusinessObject()).isActive()) {
59 OrganizationReversionCategory existingOrganizationReversionCategoryFromDB = retrieveExistingOrganizationReversionCategory();
60 if (ObjectUtils.isNotNull(existingOrganizationReversionCategoryFromDB)) {
61
62 if (!existingOrganizationReversionCategoryFromDB.isActive()) {
63 return true;
64 }
65 }
66 }
67 return false;
68 }
69
70
71
72
73
74 protected OrganizationReversionCategory retrieveExistingOrganizationReversionCategory() {
75 final OrganizationReversionCategory orgRevCategory = (OrganizationReversionCategory)getBusinessObject();
76 Map<String, Object> pkMap = new HashMap<String, Object>();
77 pkMap.put("organizationReversionCategoryCode", ((OrganizationReversionCategory)getBusinessObject()).getOrganizationReversionCategoryCode());
78 final OrganizationReversionCategory oldOrgRevCategory = (OrganizationReversionCategory)SpringContext.getBean(BusinessObjectService.class).findByPrimaryKey(OrganizationReversionCategory.class, pkMap);
79 return oldOrgRevCategory;
80 }
81
82
83
84
85
86 @Override
87 public void saveBusinessObject() {
88 final boolean isActivatingOrgReversionCategory = isActivatingOrganizationReversionCategory();
89 final boolean isInactivatingOrgReversionCategory = isInactivatingOrganizationReversionCategory();
90
91 super.saveBusinessObject();
92
93 if (isActivatingOrgReversionCategory) {
94 SpringContext.getBean(OrganizationReversionDetailTrickleDownInactivationService.class).trickleDownActiveOrganizationReversionDetails((OrganizationReversionCategory)getBusinessObject(), getDocumentNumber());
95 } else if (isInactivatingOrgReversionCategory) {
96 SpringContext.getBean(OrganizationReversionDetailTrickleDownInactivationService.class).trickleDownInactiveOrganizationReversionDetails((OrganizationReversionCategory)getBusinessObject(), getDocumentNumber());
97 }
98 }
99
100 }