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.apache.commons.lang.StringUtils;
22 import org.kuali.ole.coa.businessobject.Chart;
23 import org.kuali.ole.coa.service.ChartService;
24 import org.kuali.ole.sys.OLEConstants;
25 import org.kuali.ole.sys.context.SpringContext;
26 import org.kuali.ole.sys.document.FinancialSystemMaintainable;
27 import org.kuali.ole.sys.identity.OleKimAttributes;
28 import org.kuali.rice.kim.api.identity.Person;
29 import org.kuali.rice.kim.api.role.RoleService;
30 import org.kuali.rice.kim.api.services.KimApiServiceLocator;
31 import org.kuali.rice.krad.bo.DocumentHeader;
32
33
34
35
36 public class ChartMaintainableImpl extends FinancialSystemMaintainable {
37
38
39
40
41
42
43 @Override
44 public void doRouteStatusChange(DocumentHeader documentHeader) {
45 if (documentHeader.getWorkflowDocument().isProcessed()) {
46 Chart chart = (Chart) getBusinessObject();
47 Person oldChartManager = SpringContext.getBean(ChartService.class).getChartManager(chart.getChartOfAccountsCode());
48
49
50 if ( oldChartManager == null || !StringUtils.equals(chart.getFinCoaManagerPrincipalId(), oldChartManager.getPrincipalId() ) ) {
51 RoleService roleService = KimApiServiceLocator.getRoleService();
52
53 Map<String,String> qualification = new HashMap<String,String>(1);
54 qualification.put(OleKimAttributes.CHART_OF_ACCOUNTS_CODE, chart.getChartOfAccountsCode());
55
56 if (oldChartManager != null) {
57 roleService.removePrincipalFromRole(oldChartManager.getPrincipalId(), OLEConstants.CoreModuleNamespaces.OLE, OLEConstants.SysKimApiConstants.CHART_MANAGER_KIM_ROLE_NAME, qualification);
58 }
59
60 if (StringUtils.isNotBlank(chart.getFinCoaManagerPrincipalId())) {
61 roleService.assignPrincipalToRole(chart.getFinCoaManagerPrincipalId(), OLEConstants.CoreModuleNamespaces.OLE, OLEConstants.SysKimApiConstants.CHART_MANAGER_KIM_ROLE_NAME, qualification);
62 }
63 }
64 }
65
66 super.doRouteStatusChange(documentHeader);
67 }
68
69 }