Coverage Report - org.kuali.rice.kim.rules.ui.PersonDocumentGroupRule
 
Classes in this File Line Coverage Branch Coverage Complexity
PersonDocumentGroupRule
0%
0/21
0%
0/10
3.5
 
 1  
 /*
 2  
  * Copyright 2007-2008 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.kim.rules.ui;
 17  
 
 18  
 import java.util.HashMap;
 19  
 import java.util.Map;
 20  
 
 21  
 import org.apache.commons.lang.StringUtils;
 22  
 import org.kuali.rice.core.util.RiceKeyConstants;
 23  
 import org.kuali.rice.kim.bo.ui.PersonDocumentGroup;
 24  
 import org.kuali.rice.kim.document.IdentityManagementPersonDocument;
 25  
 import org.kuali.rice.kim.rule.event.ui.AddGroupEvent;
 26  
 import org.kuali.rice.kim.rule.ui.AddGroupRule;
 27  
 import org.kuali.rice.kim.util.KimConstants;
 28  
 import org.kuali.rice.krad.rules.DocumentRuleBase;
 29  
 import org.kuali.rice.krad.util.GlobalVariables;
 30  
 
 31  
 /**
 32  
  * This is a description of what this class does - shyu don't forget to fill this in. 
 33  
  * 
 34  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 35  
  *
 36  
  */
 37  0
 public class PersonDocumentGroupRule extends DocumentRuleBase implements AddGroupRule {
 38  
     protected static final String NEW_GROUP = "newGroup";
 39  
     protected static final String GROUP_ID_ERROR_PATH = NEW_GROUP+".groupId";
 40  
 
 41  
         public boolean processAddGroup(AddGroupEvent addGroupEvent) {
 42  0
                 IdentityManagementPersonDocument document = (IdentityManagementPersonDocument)addGroupEvent.getDocument();
 43  0
                 PersonDocumentGroup newGroup = addGroupEvent.getGroup();
 44  0
             boolean rulePassed = true;
 45  0
             rulePassed = validAssignGroup(document, newGroup);
 46  
 //            List<String> groupIds = KIMServiceLocatorInternal.getUiDocumentService().getPopulatableGroupIds();
 47  
 
 48  0
         if (newGroup == null || StringUtils.isBlank(newGroup.getGroupId())) {
 49  0
             rulePassed = false;
 50  0
             GlobalVariables.getMessageMap().putError(GROUP_ID_ERROR_PATH, RiceKeyConstants.ERROR_EMPTY_ENTRY, new String[] {"Group"});
 51  
                 
 52  
         } else {
 53  0
                     for (PersonDocumentGroup group : document.getGroups()) {
 54  0
                             if (group.getGroupId().equals(newGroup.getGroupId())) {
 55  0
                             rulePassed = false;
 56  0
                             GlobalVariables.getMessageMap().putError(GROUP_ID_ERROR_PATH, RiceKeyConstants.ERROR_DUPLICATE_ENTRY, new String[] {"Group"});
 57  
                                     
 58  
                             }
 59  
                     }
 60  
         }
 61  
         
 62  
 //        if (rulePassed) {
 63  
 //                if (groupIds.isEmpty() || !groupIds.contains(newGroup.getGroupId())) {
 64  
 //                errorMap.putError(errorPath+".groupId", RiceKeyConstants.ERROR_POPULATE_GROUP, new String[] {newGroup.getGroupId()});
 65  
 //                rulePassed = false;
 66  
 //                }   
 67  
 //        }
 68  
         // check it before save ??
 69  
         //rulePassed &= validateActiveDate(newGroup.getActiveFromDate(), newGroup.getActiveToDate());
 70  0
                 return rulePassed;
 71  
         } 
 72  
 
 73  
         protected boolean validAssignGroup(IdentityManagementPersonDocument document, PersonDocumentGroup newGroup){
 74  0
         boolean rulePassed = true;
 75  0
         Map<String,String> additionalPermissionDetails = new HashMap<String,String>();
 76  0
         additionalPermissionDetails.put(KimConstants.AttributeConstants.NAMESPACE_CODE, newGroup.getNamespaceCode());
 77  0
         additionalPermissionDetails.put(KimConstants.AttributeConstants.GROUP_NAME, newGroup.getGroupName());
 78  0
                 if(!getDocumentHelperService().getDocumentAuthorizer(document).isAuthorizedByTemplate(
 79  
                                 document, KimConstants.NAMESPACE_CODE, KimConstants.PermissionTemplateNames.POPULATE_GROUP, 
 80  
                                 GlobalVariables.getUserSession().getPrincipalId(), additionalPermissionDetails, null)){
 81  0
                     GlobalVariables.getMessageMap().putError(GROUP_ID_ERROR_PATH, 
 82  
                                     RiceKeyConstants.ERROR_ASSIGN_GROUP, 
 83  
                                     new String[] {newGroup.getNamespaceCode(), newGroup.getGroupName()});
 84  0
             rulePassed = false;
 85  
                 }
 86  0
                 return rulePassed;
 87  
         }
 88  
         
 89  
 }