Coverage Report - org.kuali.rice.core.web.parameter.ParameterRule
 
Classes in this File Line Coverage Branch Coverage Complexity
ParameterRule
0%
0/33
0%
0/12
4
 
 1  
 /*
 2  
  * Copyright 2007-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.rice.core.web.parameter;
 17  
 
 18  
 import org.kuali.rice.core.api.component.Component;
 19  
 import org.kuali.rice.core.impl.component.ComponentBo;
 20  
 import org.kuali.rice.core.impl.parameter.ParameterBo;
 21  
 import org.kuali.rice.core.util.RiceKeyConstants;
 22  
 import org.kuali.rice.core.xml.dto.AttributeSet;
 23  
 import org.kuali.rice.kim.service.KIMServiceLocator;
 24  
 import org.kuali.rice.kim.util.KimConstants;
 25  
 import org.kuali.rice.kns.datadictionary.DataDictionaryException;
 26  
 import org.kuali.rice.kns.document.MaintenanceDocument;
 27  
 import org.kuali.rice.kns.maintenance.rules.MaintenanceDocumentRuleBase;
 28  
 import org.kuali.rice.kns.service.KNSServiceLocatorWeb;
 29  
 import org.kuali.rice.kns.util.GlobalVariables;
 30  
 import org.kuali.rice.kns.util.KNSConstants;
 31  
 import org.kuali.rice.kns.util.ObjectUtils;
 32  
 
 33  
 import java.util.HashMap;
 34  
 import java.util.List;
 35  
 import java.util.Map;
 36  
 
 37  
 /**
 38  
  * This is a description of what this class does - kellerj don't forget to fill
 39  
  * this in.
 40  
  *
 41  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 42  
  */
 43  0
 public class ParameterRule extends MaintenanceDocumentRuleBase {
 44  
 
 45  
         /**
 46  
          * This overridden method ...
 47  
          *
 48  
          * @see org.kuali.rice.kns.maintenance.rules.MaintenanceDocumentRuleBase#processCustomRouteDocumentBusinessRules(org.kuali.rice.kns.document.MaintenanceDocument)
 49  
          */
 50  
         @Override
 51  
         protected boolean processCustomRouteDocumentBusinessRules(MaintenanceDocument document) {
 52  0
                 boolean result = super.processCustomRouteDocumentBusinessRules( document );
 53  
 
 54  0
                 result &= checkAllowsMaintenanceEdit( document.getDocumentHeader().getWorkflowDocument()
 55  
                                 .getRouteHeader().getInitiatorPrincipalId(), (ParameterBo)getNewBo() );
 56  
 
 57  0
                 result &= checkComponent((ParameterBo) getNewBo());
 58  
                 
 59  0
                 return result;
 60  
         }
 61  
 
 62  
         protected boolean checkAllowsMaintenanceEdit(String initiatorPrincipalId, ParameterBo newBO) {
 63  
 
 64  0
                  boolean allowsEdit = false;
 65  0
                 ParameterBo parm = (ParameterBo)newBO;
 66  
                 
 67  0
                 AttributeSet permissionDetails = new AttributeSet();
 68  0
                 permissionDetails.put(KimConstants.AttributeConstants.NAMESPACE_CODE, parm.getNamespaceCode());
 69  0
                 permissionDetails.put(KimConstants.AttributeConstants.COMPONENT_NAME, parm.getComponentCode());
 70  0
                 permissionDetails.put(KimConstants.AttributeConstants.PARAMETER_NAME, parm.getName());
 71  0
                 allowsEdit = KIMServiceLocator.getIdentityManagementService().isAuthorizedByTemplateName(
 72  
                                                 GlobalVariables.getUserSession().getPerson().getPrincipalId(),
 73  
                                                 KNSConstants.KNS_NAMESPACE,
 74  
                                                 KimConstants.PermissionTemplateNames.MAINTAIN_SYSTEM_PARAMETER,
 75  
                                                 permissionDetails, null);
 76  0
                 if(!allowsEdit){
 77  0
                         putGlobalError(RiceKeyConstants.AUTHORIZATION_ERROR_PARAMETER);
 78  
                 }
 79  0
                 return allowsEdit;
 80  
         }
 81  
 
 82  
     public boolean checkComponent(ParameterBo param) {
 83  0
         String component = param.getComponentCode();
 84  0
         String namespace = param.getNamespaceCode();
 85  0
         boolean result = false;
 86  
 
 87  
         try {
 88  0
             List<Component> dataDictionaryAndSpringComponents = KNSServiceLocatorWeb.getRiceApplicationConfigurationMediationService().getNonDatabaseComponents();
 89  0
             for (Component pdt : dataDictionaryAndSpringComponents) {
 90  0
                 if (namespace.equals(pdt.getNamespaceCode()) && component.equals(pdt.getCode())) {
 91  0
                     result = true;
 92  0
                     break;
 93  
                 }
 94  
             }
 95  
 
 96  0
             if (!result) {
 97  0
                 Map<String, String> primaryKeys = new HashMap<String, String>(2);
 98  0
                 primaryKeys.put("namespaceCode", namespace);
 99  0
                 primaryKeys.put("code", component);
 100  0
                 result = ObjectUtils.isNotNull(getBoService().findByPrimaryKey(ComponentBo.class, primaryKeys));
 101  
             }
 102  
 
 103  0
             if (!result) {
 104  0
                 putFieldError("code", "error.document.parameter.detailType.invalid", component);
 105  
             }
 106  
 
 107  0
             return result;
 108  
         }
 109  0
         catch (DataDictionaryException ex) {
 110  0
             throw new RuntimeException("Problem parsing data dictionary during full load required for rule validation: " + ex.getMessage(), ex);
 111  
         }
 112  
     }
 113  
 }
 114