Coverage Report - org.kuali.rice.kew.rule.web.DelegateRuleForm
 
Classes in this File Line Coverage Branch Coverage Complexity
DelegateRuleForm
0%
0/61
0%
0/34
2.188
 
 1  
 /*
 2  
  * Copyright 2005-2009 The Kuali Foundation
 3  
  *
 4  
  *
 5  
  * Licensed under the Educational Community License, Version 2.0 (the "License");
 6  
  * you may not use this file except in compliance with the License.
 7  
  * You may obtain a copy of the License at
 8  
  *
 9  
  * http://www.opensource.org/licenses/ecl2.php
 10  
  *
 11  
  * Unless required by applicable law or agreed to in writing, software
 12  
  * distributed under the License is distributed on an "AS IS" BASIS,
 13  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 14  
  * See the License for the specific language governing permissions and
 15  
  * limitations under the License.
 16  
  */
 17  
 package org.kuali.rice.kew.rule.web;
 18  
 
 19  
 import java.util.ArrayList;
 20  
 import java.util.List;
 21  
 
 22  
 import javax.servlet.http.HttpServletRequest;
 23  
 
 24  
 import org.kuali.rice.core.exception.RiceRuntimeException;
 25  
 import org.kuali.rice.kew.rule.RuleBaseValues;
 26  
 import org.kuali.rice.kew.rule.RuleResponsibility;
 27  
 import org.kuali.rice.kew.service.KEWServiceLocator;
 28  
 import org.kuali.rice.kew.util.KEWConstants;
 29  
 import org.kuali.rice.kim.bo.Group;
 30  
 import org.kuali.rice.kim.bo.entity.KimPrincipal;
 31  
 import org.kuali.rice.kim.service.KIMServiceLocator;
 32  
 import org.kuali.rice.kns.web.struts.form.KualiForm;
 33  
 
 34  
 
 35  
 /**
 36  
  * Struts ActionForm for {@link DelegateRuleAction}.
 37  
  *
 38  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 39  
  */
 40  0
 public class DelegateRuleForm extends KualiForm {
 41  
 
 42  
         private static final long serialVersionUID = 5412969516727713859L;
 43  
 
 44  
         private Long parentRuleId;
 45  
         private Long parentResponsibilityId;
 46  
 
 47  
         private RuleBaseValues parentRule;
 48  
         private RuleResponsibility parentResponsibility;
 49  
                 
 50  0
         private List<String> reviewers = new ArrayList<String>();
 51  0
         private List<String> responsibilityTypes = new ArrayList<String>();
 52  0
         private List<String> actionRequestCodes = new ArrayList<String>();
 53  
         
 54  
         public Long getParentRuleId() {
 55  0
                 return this.parentRuleId;
 56  
         }
 57  
 
 58  
         public void setParentRuleId(Long parentRuleId) {
 59  0
                 this.parentRuleId = parentRuleId;
 60  0
         }
 61  
 
 62  
         public Long getParentResponsibilityId() {
 63  0
                 return this.parentResponsibilityId;
 64  
         }
 65  
 
 66  
         public void setParentResponsibilityId(Long parentResponsibilityId) {
 67  0
                 this.parentResponsibilityId = parentResponsibilityId;
 68  0
         }
 69  
 
 70  
         public RuleBaseValues getParentRule() {
 71  0
                 return this.parentRule;
 72  
         }
 73  
 
 74  
         public void setParentRule(RuleBaseValues parentRule) {
 75  0
             if (this.parentRule != null 
 76  
                     && parentRule != null
 77  
                     && this.parentResponsibility != null) {
 78  0
                 if (this.parentRule.getRuleBaseValuesId().longValue() != parentRule.getRuleBaseValuesId().longValue()) {
 79  0
                     this.parentResponsibility = null;
 80  0
                     this.parentResponsibilityId = null;
 81  
                 }
 82  
             }
 83  0
                 this.parentRule = parentRule;
 84  0
         }
 85  
 
 86  
         public RuleResponsibility getParentResponsibility() {
 87  0
                 return this.parentResponsibility;
 88  
         }
 89  
 
 90  
         public void setParentResponsibility(RuleResponsibility parentResponsibility) {
 91  0
                 this.parentResponsibility = parentResponsibility;
 92  0
         }
 93  
 
 94  
         public List<String> getReviewers() {
 95  0
                 return this.reviewers;
 96  
         }
 97  
 
 98  
         public void setReviewers(List<String> reviewers) {
 99  0
                 this.reviewers = reviewers;
 100  0
         }
 101  
 
 102  
         public List<String> getResponsibilityTypes() {
 103  0
                 return this.responsibilityTypes;
 104  
         }
 105  
 
 106  
         public void setResponsibilityTypes(List<String> responsibilityTypes) {
 107  0
                 this.responsibilityTypes = responsibilityTypes;
 108  0
         }
 109  
 
 110  
         public List<String> getActionRequestCodes() {
 111  0
                 return this.actionRequestCodes;
 112  
         }
 113  
 
 114  
         public void setActionRequestCodes(List<String> actionRequestCodes) {
 115  0
                 this.actionRequestCodes = actionRequestCodes;
 116  0
         }
 117  
 
 118  
         public String getRuleDescription() {
 119  0
                 if (getParentRule() == null) {
 120  0
                         return "";
 121  
                 }
 122  0
                 return getParentRule().getDescription();
 123  
         }
 124  
 
 125  
         @Override
 126  
         public void populate(HttpServletRequest request) {
 127  
                                 
 128  0
                 super.populate(request);
 129  
 
 130  0
                 reviewers.clear();
 131  0
                 responsibilityTypes.clear();
 132  0
                 actionRequestCodes.clear();
 133  
                 
 134  0
                 if (getParentRuleId() != null) {
 135  0
                         setParentRule(KEWServiceLocator.getRuleService().findRuleBaseValuesById(getParentRuleId()));
 136  
                 }
 137  0
                 if (getParentResponsibilityId() != null && getParentRule() != null) {
 138  0
                         for (RuleResponsibility responsibility : getParentRule().getResponsibilities()) {
 139  0
                                 if (responsibility.getResponsibilityId().equals(getParentResponsibilityId())) {
 140  0
                                         setParentResponsibility(responsibility);
 141  0
                                         break;
 142  
                                 }
 143  
                         }
 144  
                 }
 145  
                 
 146  0
                 if (getParentRule() != null) {
 147  0
                         for (RuleResponsibility responsibility : getParentRule().getResponsibilities()) {
 148  0
                                 if (KEWConstants.RULE_RESPONSIBILITY_WORKFLOW_ID.equals(responsibility.getRuleResponsibilityType())) {
 149  0
                                         KimPrincipal principal = KEWServiceLocator.getIdentityHelperService().getPrincipal(responsibility.getRuleResponsibilityName());
 150  0
                                         if (principal != null) {
 151  0
                                             reviewers.add(principal.getPrincipalName());
 152  
                                         }
 153  0
                                         responsibilityTypes.add(KEWConstants.RULE_RESPONSIBILITY_WORKFLOW_ID_LABEL);
 154  0
                                 } else if (KEWConstants.RULE_RESPONSIBILITY_GROUP_ID.equals(responsibility.getRuleResponsibilityType())) {
 155  0
                                         Group group = KIMServiceLocator.getIdentityManagementService().getGroup(responsibility.getRuleResponsibilityName());
 156  0
                                         if (group != null) {
 157  0
                                             reviewers.add(group.getNamespaceCode() + " " + group.getGroupName());
 158  
                                         }
 159  0
                                         responsibilityTypes.add(KEWConstants.RULE_RESPONSIBILITY_GROUP_ID_LABEL);
 160  0
                                 } else if (KEWConstants.RULE_RESPONSIBILITY_ROLE_ID.equals(responsibility.getRuleResponsibilityType())) {
 161  0
                                         reviewers.add(responsibility.getResolvedRoleName());
 162  0
                                         responsibilityTypes.add(KEWConstants.RULE_RESPONSIBILITY_ROLE_ID_LABEL);
 163  
                                 } else {
 164  0
                                         throw new RiceRuntimeException("Encountered a responsibility with an invalid type, type value was " + responsibility.getRuleResponsibilityType());
 165  
                                 }
 166  0
                                 actionRequestCodes.add(KEWConstants.ACTION_REQUEST_CODES.get(responsibility.getActionRequestedCd()));
 167  
                         }
 168  
                 }
 169  
                 
 170  0
         }
 171  
 
 172  
         
 173  
 
 174  
 }