View Javadoc
1   /*
2    * The Kuali Financial System, a comprehensive financial management system for higher education.
3    * 
4    * Copyright 2005-2014 The Kuali Foundation
5    * 
6    * This program is free software: you can redistribute it and/or modify
7    * it under the terms of the GNU Affero General Public License as
8    * published by the Free Software Foundation, either version 3 of the
9    * License, or (at your option) any later version.
10   * 
11   * This program is distributed in the hope that it will be useful,
12   * but WITHOUT ANY WARRANTY; without even the implied warranty of
13   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14   * GNU Affero General Public License for more details.
15   * 
16   * You should have received a copy of the GNU Affero General Public License
17   * along with this program.  If not, see <http://www.gnu.org/licenses/>.
18   */
19  package org.kuali.kfs.coa.document;
20  
21  import java.util.HashMap;
22  import java.util.Map;
23  
24  import org.apache.commons.lang.StringUtils;
25  import org.kuali.kfs.coa.businessobject.Chart;
26  import org.kuali.kfs.coa.service.ChartService;
27  import org.kuali.kfs.sys.KFSConstants;
28  import org.kuali.kfs.sys.context.SpringContext;
29  import org.kuali.kfs.sys.document.FinancialSystemMaintainable;
30  import org.kuali.kfs.sys.identity.KfsKimAttributes;
31  import org.kuali.rice.kim.api.identity.Person;
32  import org.kuali.rice.kim.api.role.RoleService;
33  import org.kuali.rice.kim.api.services.KimApiServiceLocator;
34  import org.kuali.rice.krad.bo.DocumentHeader;
35  
36  /**
37   * Maintainable implementation for the chart maintenance document
38   */
39  public class ChartMaintainableImpl extends FinancialSystemMaintainable {
40  
41      /**
42       * Override to push chart manager id into KIM
43       *
44       * @see org.kuali.rice.kns.maintenance.KualiMaintainableImpl#doRouteStatusChange(org.kuali.rice.krad.bo.DocumentHeader)
45       */
46      @Override
47      public void doRouteStatusChange(DocumentHeader documentHeader) {
48          if (documentHeader.getWorkflowDocument().isProcessed()) {
49              Chart chart = (Chart) getBusinessObject();
50              Person oldChartManager = SpringContext.getBean(ChartService.class).getChartManager(chart.getChartOfAccountsCode());
51  
52              // Only make the KIM calls if the chart manager was changed
53              if ( oldChartManager == null || !StringUtils.equals(chart.getFinCoaManagerPrincipalId(), oldChartManager.getPrincipalId() ) ) {
54                  RoleService roleService = KimApiServiceLocator.getRoleService();
55  
56                  Map<String,String> qualification = new HashMap<String,String>(1);
57                  qualification.put(KfsKimAttributes.CHART_OF_ACCOUNTS_CODE, chart.getChartOfAccountsCode());
58  
59                  if (oldChartManager != null) {
60                      roleService.removePrincipalFromRole(oldChartManager.getPrincipalId(), KFSConstants.ParameterNamespaces.KFS, KFSConstants.SysKimApiConstants.CHART_MANAGER_KIM_ROLE_NAME, qualification);
61                  }
62  
63                  if (StringUtils.isNotBlank(chart.getFinCoaManagerPrincipalId())) {
64                      roleService.assignPrincipalToRole(chart.getFinCoaManagerPrincipalId(), KFSConstants.ParameterNamespaces.KFS, KFSConstants.SysKimApiConstants.CHART_MANAGER_KIM_ROLE_NAME, qualification);
65                  }
66              }
67          }
68  
69          super.doRouteStatusChange(documentHeader);
70      }
71  
72  }