Coverage Report - org.kuali.rice.kim.impl.responsibility.KimDocumentResponsibilityRule
 
Classes in this File Line Coverage Branch Coverage Complexity
KimDocumentResponsibilityRule
0%
0/30
0%
0/16
7
 
 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 responsibilitys and
 14  
  * limitations under the License.
 15  
  */
 16  
 package org.kuali.rice.kim.impl.responsibility;
 17  
 
 18  
 import org.apache.commons.lang.StringUtils;
 19  
 import org.kuali.rice.core.api.util.RiceKeyConstants;
 20  
 import org.kuali.rice.kim.api.responsibility.Responsibility;
 21  
 import org.kuali.rice.kim.bo.ui.KimDocumentRoleResponsibility;
 22  
 import org.kuali.rice.kim.document.IdentityManagementRoleDocument;
 23  
 import org.kuali.rice.kim.util.KimConstants;
 24  
 import org.kuali.rice.krad.rules.DocumentRuleBase;
 25  
 import org.kuali.rice.krad.util.GlobalVariables;
 26  
 
 27  
 import java.util.HashMap;
 28  
 import java.util.Map;
 29  
 
 30  
 /**
 31  
  * This is a description of what this class does - shyu don't forget to fill this in. 
 32  
  * 
 33  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 34  
  *
 35  
  */
 36  0
 public class KimDocumentResponsibilityRule extends DocumentRuleBase implements AddResponsibilityRule {
 37  
 
 38  
         public static final String ERROR_PATH = "document.responsibility.responsibilityId";
 39  
 
 40  
         public boolean processAddResponsibility(AddResponsibilityEvent addResponsibilityEvent) {
 41  0
                 KimDocumentRoleResponsibility newResponsibility = addResponsibilityEvent.getResponsibility();
 42  0
                 if(newResponsibility==null){
 43  0
                         GlobalVariables.getMessageMap().putError(ERROR_PATH, RiceKeyConstants.ERROR_EMPTY_ENTRY, new String[] {"Responsibility"});
 44  0
                         return false;
 45  
                 }
 46  
 
 47  0
                 ResponsibilityBo kimResponsibilityImpl = newResponsibility.getKimResponsibility();
 48  0
                 if(kimResponsibilityImpl==null){
 49  0
                         GlobalVariables.getMessageMap().putError(ERROR_PATH, RiceKeyConstants.ERROR_EMPTY_ENTRY, new String[] {"Responsibility"});
 50  0
                         return false;
 51  
                 }
 52  
 
 53  0
                 IdentityManagementRoleDocument document = (IdentityManagementRoleDocument)addResponsibilityEvent.getDocument();                
 54  0
             boolean rulePassed = true;
 55  0
                 if (!hasPermissionToGrantResponsibility(ResponsibilityBo.to(kimResponsibilityImpl), document)) {
 56  0
             GlobalVariables.getMessageMap().putError(ERROR_PATH, RiceKeyConstants.ERROR_ASSIGN_RESPONSIBILITY, 
 57  
                             new String[] {kimResponsibilityImpl.getNamespaceCode(), kimResponsibilityImpl.getTemplate().getName()});
 58  0
             return false;
 59  
                 }
 60  
                 
 61  0
                 if (newResponsibility == null || StringUtils.isBlank(newResponsibility.getResponsibilityId())) {
 62  0
             rulePassed = false;
 63  0
             GlobalVariables.getMessageMap().putError(ERROR_PATH, RiceKeyConstants.ERROR_EMPTY_ENTRY, new String[] {"Responsibility"});
 64  
         } else {
 65  0
                 int i = 0;
 66  0
                     for (KimDocumentRoleResponsibility responsibility: document.getResponsibilities()) {
 67  0
                             if (responsibility.getResponsibilityId().equals(newResponsibility.getResponsibilityId())) {
 68  0
                             rulePassed = false;
 69  0
                             GlobalVariables.getMessageMap().putError("document.responsibilities["+i+"].responsibilityId", RiceKeyConstants.ERROR_DUPLICATE_ENTRY, new String[] {"Responsibility"});
 70  
                             }
 71  0
                             i++;
 72  
                     }
 73  
         }
 74  0
                 return rulePassed;
 75  
         } 
 76  
 
 77  
         public boolean hasPermissionToGrantResponsibility(Responsibility kimResponsibilityInfo, IdentityManagementRoleDocument document){
 78  0
                 Map<String,String> responsibilityDetails = new HashMap<String,String>();
 79  0
                 responsibilityDetails.put(KimConstants.AttributeConstants.NAMESPACE_CODE, kimResponsibilityInfo.getNamespaceCode());
 80  0
                 responsibilityDetails.put(KimConstants.AttributeConstants.RESPONSIBILITY_NAME, kimResponsibilityInfo.getName());
 81  0
                 if (!getDocumentHelperService().getDocumentAuthorizer(document).isAuthorizedByTemplate(
 82  
                                 document, 
 83  
                                 KimConstants.NAMESPACE_CODE, 
 84  
                                 KimConstants.PermissionTemplateNames.GRANT_RESPONSIBILITY, 
 85  
                                 GlobalVariables.getUserSession().getPerson().getPrincipalId(), 
 86  
                                 responsibilityDetails, null)) {
 87  0
             return false;
 88  
                 }
 89  0
                 return true;
 90  
         }
 91  
 }