View Javadoc

1   /**
2    * Copyright 2005-2011 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.rice.core.web.parameter;
17  
18  import org.kuali.rice.core.api.CoreApiServiceLocator;
19  import org.kuali.rice.core.api.component.Component;
20  import org.kuali.rice.core.api.util.RiceKeyConstants;
21  import org.kuali.rice.core.impl.component.ComponentBo;
22  import org.kuali.rice.core.impl.parameter.ParameterBo;
23  import org.kuali.rice.kim.api.KimConstants;
24  import org.kuali.rice.kim.api.services.KimApiServiceLocator;
25  import org.kuali.rice.kns.document.MaintenanceDocument;
26  import org.kuali.rice.kns.maintenance.rules.MaintenanceDocumentRuleBase;
27  import org.kuali.rice.krad.datadictionary.DataDictionaryException;
28  import org.kuali.rice.krad.service.KRADServiceLocatorWeb;
29  import org.kuali.rice.krad.util.GlobalVariables;
30  import org.kuali.rice.krad.util.KRADConstants;
31  import org.kuali.rice.krad.util.ObjectUtils;
32  
33  import java.util.Collections;
34  import java.util.HashMap;
35  import java.util.List;
36  import java.util.Map;
37  
38  /**
39   * This is a description of what this class does - kellerj don't forget to fill
40   * this in.
41   *
42   * @author Kuali Rice Team (rice.collab@kuali.org)
43   */
44  public class ParameterRule extends MaintenanceDocumentRuleBase {
45  
46  	/**
47  	 * This overridden method ...
48  	 *
49  	 * @see org.kuali.rice.krad.rules.MaintenanceDocumentRuleBase#processCustomRouteDocumentBusinessRules(org.kuali.rice.krad.document.MaintenanceDocument)
50  	 */
51  	@Override
52  	protected boolean processCustomRouteDocumentBusinessRules(MaintenanceDocument document) {
53  		boolean result = super.processCustomRouteDocumentBusinessRules( document );
54  
55  		result &= checkAllowsMaintenanceEdit( document.getDocumentHeader().getWorkflowDocument()
56  				.getInitiatorPrincipalId(), (ParameterBo)getNewBo() );
57  
58  		result &= checkComponent((ParameterBo) getNewBo());
59  		
60  		return result;
61  	}
62  
63  	protected boolean checkAllowsMaintenanceEdit(String initiatorPrincipalId, ParameterBo newBO) {
64  
65  		 boolean allowsEdit = false;
66  	        ParameterBo parm = newBO;
67  	        
68  	        Map<String, String> permissionDetails = new HashMap<String, String>();
69  	        permissionDetails.put(KimConstants.AttributeConstants.NAMESPACE_CODE, parm.getNamespaceCode());
70  	        permissionDetails.put(KimConstants.AttributeConstants.COMPONENT_NAME, parm.getComponentCode());
71  	        permissionDetails.put(KimConstants.AttributeConstants.PARAMETER_NAME, parm.getName());
72  	        allowsEdit = KimApiServiceLocator.getPermissionService().isAuthorizedByTemplateName(
73  	        				GlobalVariables.getUserSession().getPerson().getPrincipalId(),
74  	        				KRADConstants.KRAD_NAMESPACE,
75  	        				KimConstants.PermissionTemplateNames.MAINTAIN_SYSTEM_PARAMETER,
76  	        				permissionDetails, Collections.<String, String>emptyMap());
77  	        if(!allowsEdit){
78  	        	putGlobalError(RiceKeyConstants.AUTHORIZATION_ERROR_PARAMETER);
79  	        }
80  	        return allowsEdit;
81  	}
82  
83      public boolean checkComponent(ParameterBo param) {
84          String componentCode = param.getComponentCode();
85          String namespace = param.getNamespaceCode();
86          boolean result = false;
87          Component component = CoreApiServiceLocator.getComponentService().getComponentByCode(namespace, componentCode);
88          if (component != null) {
89              result = true;
90          }
91          if (!result) {
92              putFieldError("code", "error.document.parameter.detailType.invalid", componentCode);
93          }
94          return result;
95      }
96  }
97