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