001 /*
002 * Copyright 2011 The Kuali Foundation.
003 *
004 * Licensed under the Educational Community License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.opensource.org/licenses/ecl2.php
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016 package org.kuali.kfs.coa.document;
017
018 import org.apache.commons.lang.StringUtils;
019 import org.kuali.kfs.coa.businessobject.Chart;
020 import org.kuali.kfs.coa.service.ChartService;
021 import org.kuali.kfs.sys.KFSConstants;
022 import org.kuali.kfs.sys.context.SpringContext;
023 import org.kuali.kfs.sys.document.FinancialSystemMaintainable;
024 import org.kuali.kfs.sys.identity.KfsKimAttributes;
025 import org.kuali.rice.kim.bo.Person;
026 import org.kuali.rice.kim.bo.types.dto.AttributeSet;
027 import org.kuali.rice.kim.service.RoleManagementService;
028 import org.kuali.rice.kns.bo.DocumentHeader;
029 import org.kuali.rice.kns.workflow.service.KualiWorkflowDocument;
030
031 /**
032 * Maintainable implementation for the chart maintenance document
033 */
034 public class ChartMaintainableImpl extends FinancialSystemMaintainable {
035
036 /**
037 * Override to push chart manager id into KIM
038 *
039 * @see org.kuali.rice.kns.maintenance.KualiMaintainableImpl#doRouteStatusChange(org.kuali.rice.kns.bo.DocumentHeader)
040 */
041 @Override
042 public void doRouteStatusChange(DocumentHeader documentHeader) {
043 KualiWorkflowDocument workflowDocument = documentHeader.getWorkflowDocument();
044
045 if (workflowDocument.stateIsProcessed()) {
046 Chart chart = (Chart) getBusinessObject();
047
048 RoleManagementService roleManagementService = SpringContext.getBean(RoleManagementService.class);
049
050 AttributeSet qualification = new AttributeSet();
051 qualification.put(KfsKimAttributes.CHART_OF_ACCOUNTS_CODE, chart.getChartOfAccountsCode());
052
053 Person oldChartManager = SpringContext.getBean(ChartService.class).getChartManager(chart.getChartOfAccountsCode());
054 if (oldChartManager != null) {
055 roleManagementService.removePrincipalFromRole(oldChartManager.getPrincipalId(), KFSConstants.ParameterNamespaces.KFS, KFSConstants.SysKimConstants.CHART_MANAGER_KIM_ROLE_NAME, qualification);
056 }
057
058 if (StringUtils.isNotBlank(chart.getFinCoaManagerPrincipalId())) {
059 roleManagementService.assignPrincipalToRole(chart.getFinCoaManagerPrincipalId(), KFSConstants.ParameterNamespaces.KFS, KFSConstants.SysKimConstants.CHART_MANAGER_KIM_ROLE_NAME, qualification);
060 }
061
062 roleManagementService.flushRoleCaches();
063 }
064
065 super.doRouteStatusChange(documentHeader);
066 }
067
068 }