View Javadoc

1   /*
2    * Copyright 2009 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
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   * Maintainable implementation for the chart maintenance document
35   */
36  public class ChartMaintainableImpl extends FinancialSystemMaintainable {
37  
38      /**
39       * Override to push chart manager id into KIM
40       *
41       * @see org.kuali.rice.kns.maintenance.KualiMaintainableImpl#doRouteStatusChange(org.kuali.rice.kns.bo.DocumentHeader)
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              // Only make the KIM calls if the chart manager was changed
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  }