Coverage Report - org.kuali.rice.kew.rule.RuleResponsibilityBo
 
Classes in this File Line Coverage Branch Coverage Complexity
RuleResponsibilityBo
0%
0/82
0%
0/64
2
 
 1  
 /**
 2  
  * Copyright 2005-2011 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.kew.rule;
 17  
 
 18  
 import org.apache.commons.lang.ObjectUtils;
 19  
 import org.apache.commons.lang.builder.HashCodeBuilder;
 20  
 import org.hibernate.annotations.GenericGenerator;
 21  
 import org.hibernate.annotations.Parameter;
 22  
 import org.kuali.rice.core.api.reflect.ObjectDefinition;
 23  
 import org.kuali.rice.core.api.resourceloader.GlobalResourceLoader;
 24  
 import org.kuali.rice.kew.actionrequest.ActionRequestValue;
 25  
 import org.kuali.rice.kew.api.rule.RuleResponsibilityContract;
 26  
 import org.kuali.rice.kew.service.KEWServiceLocator;
 27  
 import org.kuali.rice.kew.api.KewApiConstants;
 28  
 import org.kuali.rice.kim.api.group.Group;
 29  
 import org.kuali.rice.kim.api.identity.principal.Principal;
 30  
 import org.kuali.rice.kim.api.services.KimApiServiceLocator;
 31  
 import org.kuali.rice.krad.bo.PersistableBusinessObjectBase;
 32  
 
 33  
 import javax.persistence.Column;
 34  
 import javax.persistence.Entity;
 35  
 import javax.persistence.FetchType;
 36  
 import javax.persistence.GeneratedValue;
 37  
 import javax.persistence.Id;
 38  
 import javax.persistence.JoinColumn;
 39  
 import javax.persistence.ManyToOne;
 40  
 import javax.persistence.Table;
 41  
 import java.util.List;
 42  
 
 43  
 
 44  
 /**
 45  
  * A model bean representing the responsibility of a user, workgroup, or role
 46  
  * to perform some action on a document.  Used by the rule system to
 47  
  * identify the appropriate responsibile parties to generate
 48  
  * {@link ActionRequestValue}s to.
 49  
  *
 50  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 51  
  */
 52  
 @Entity
 53  
 @Table(name="KREW_RULE_RSP_T")
 54  
 //@Sequence(name="KREW_RSP_S", property="id")
 55  0
 public class RuleResponsibilityBo extends PersistableBusinessObjectBase implements RuleResponsibilityContract {
 56  
 
 57  
         private static final long serialVersionUID = -1565688857123316797L;
 58  
         @Id
 59  
         @GeneratedValue(generator="KREW_RSP_S")
 60  
         @GenericGenerator(name="KREW_RSP_S",strategy="org.hibernate.id.enhanced.SequenceStyleGenerator",parameters={
 61  
                         @Parameter(name="sequence_name",value="KREW_RSP_S"),
 62  
                         @Parameter(name="value_column",value="id")
 63  
         })
 64  
         @Column(name="RULE_RSP_ID")
 65  
         private String id;
 66  
     @Column(name="RSP_ID")
 67  
         private String responsibilityId;
 68  
     @Column(name="RULE_ID", insertable=false, updatable=false)
 69  
     private String ruleBaseValuesId;
 70  
     @Column(name="ACTN_RQST_CD")
 71  
         private String actionRequestedCd;
 72  
     @Column(name="NM")
 73  
         private String ruleResponsibilityName;
 74  
     @Column(name="TYP")
 75  
         private String ruleResponsibilityType;
 76  
     @Column(name="PRIO")
 77  
         private Integer priority;
 78  
     @Column(name="APPR_PLCY")
 79  
         private String approvePolicy;
 80  
 
 81  
     @ManyToOne(fetch=FetchType.EAGER)
 82  
         @JoinColumn(name="RULE_ID")
 83  
         private RuleBaseValues ruleBaseValues;
 84  
     //@OneToMany(fetch=FetchType.EAGER,cascade={CascadeType.PERSIST, CascadeType.REMOVE, CascadeType.MERGE},
 85  
     //        mappedBy="ruleResponsibility")
 86  
     //private List<RuleDelegation> delegationRules = new ArrayList<RuleDelegation>();
 87  
 
 88  
     public Principal getPrincipal()
 89  
     {
 90  0
             if (isUsingPrincipal()) {
 91  0
                     return KEWServiceLocator.getIdentityHelperService().getPrincipal(ruleResponsibilityName);
 92  
             }
 93  0
             return null;
 94  
     }
 95  
 
 96  
     public Group getGroup() {
 97  0
         if (isUsingGroup()) {
 98  0
                 return KimApiServiceLocator.getGroupService().getGroup(ruleResponsibilityName);
 99  
         }
 100  0
         return null;
 101  
     }
 102  
 
 103  
     public String getRole() {
 104  0
         if (isUsingRole()) {
 105  0
             return ruleResponsibilityName;
 106  
         }
 107  0
         return null;
 108  
     }
 109  
 
 110  
     public String getResolvedRoleName() {
 111  0
         if (isUsingRole()) {
 112  0
             return getRole().substring(getRole().indexOf("!") + 1, getRole().length());
 113  
         }
 114  0
         return null;
 115  
     }
 116  
 
 117  
     public String getRoleAttributeName() {
 118  0
             return getRole().substring(0, getRole().indexOf("!"));
 119  
     }
 120  
     
 121  
     public RoleAttribute resolveRoleAttribute() {
 122  0
         if (isUsingRole()) {
 123  0
             String attributeName = getRoleAttributeName();
 124  0
             return (RoleAttribute) GlobalResourceLoader.getResourceLoader().getObject(new ObjectDefinition(attributeName));
 125  
         }
 126  0
         return null;
 127  
     }
 128  
 
 129  
     @Override
 130  
     public boolean isUsingRole() {
 131  0
             return (ruleResponsibilityName != null && ruleResponsibilityType != null && ruleResponsibilityType.equals(KewApiConstants.RULE_RESPONSIBILITY_ROLE_ID));
 132  
     }
 133  
 
 134  
     @Override
 135  
     public boolean isUsingPrincipal() {
 136  0
             return (ruleResponsibilityName != null && !ruleResponsibilityName.trim().equals("") && ruleResponsibilityType != null && ruleResponsibilityType.equals(KewApiConstants.RULE_RESPONSIBILITY_WORKFLOW_ID));
 137  
     }
 138  
 
 139  
     @Override
 140  
     public boolean isUsingGroup() {
 141  0
             return (ruleResponsibilityName != null && !ruleResponsibilityName.trim().equals("") && ruleResponsibilityType != null && ruleResponsibilityType.equals(KewApiConstants.RULE_RESPONSIBILITY_GROUP_ID));
 142  
     }
 143  
 
 144  
     public String getRuleBaseValuesId() {
 145  0
         return ruleBaseValuesId;
 146  
     }
 147  
 
 148  
     public void setRuleBaseValuesId(String ruleBaseValuesId) {
 149  0
         this.ruleBaseValuesId = ruleBaseValuesId;
 150  0
     }
 151  
 
 152  
     public RuleBaseValues getRuleBaseValues() {
 153  0
         return ruleBaseValues;
 154  
     }
 155  
 
 156  
     public void setRuleBaseValues(RuleBaseValues ruleBaseValues) {
 157  0
         this.ruleBaseValues = ruleBaseValues;
 158  0
     }
 159  
 
 160  
     public String getActionRequestedCd() {
 161  0
         return actionRequestedCd;
 162  
     }
 163  
 
 164  
     public void setActionRequestedCd(String actionRequestedCd) {
 165  0
         this.actionRequestedCd = actionRequestedCd;
 166  0
     }
 167  
 
 168  
     public String getId() {
 169  0
         return id;
 170  
     }
 171  
 
 172  
     public void setId(String ruleResponsibilityId) {
 173  0
         this.id = ruleResponsibilityId;
 174  0
     }
 175  
     public Integer getPriority() {
 176  0
         return priority;
 177  
     }
 178  
 
 179  
     public void setPriority(Integer priority) {
 180  0
         this.priority = priority;
 181  0
     }
 182  
 
 183  
     public String getApprovePolicy() {
 184  0
         return approvePolicy;
 185  
     }
 186  
 
 187  
     public void setApprovePolicy(String approvePolicy) {
 188  0
         this.approvePolicy = approvePolicy;
 189  0
     }
 190  
 
 191  
     public Object copy(boolean preserveKeys) {
 192  0
         RuleResponsibilityBo ruleResponsibilityClone = new RuleResponsibilityBo();
 193  0
         ruleResponsibilityClone.setApprovePolicy(getApprovePolicy());
 194  0
         if (actionRequestedCd != null) {
 195  0
             ruleResponsibilityClone.setActionRequestedCd(actionRequestedCd);
 196  
         }
 197  0
         if (id != null && preserveKeys) {
 198  0
             ruleResponsibilityClone.setId(id);
 199  
         }
 200  
 
 201  0
         if (responsibilityId != null) {
 202  0
             ruleResponsibilityClone.setResponsibilityId(responsibilityId);
 203  
         }
 204  
 
 205  0
         if (ruleResponsibilityName != null) {
 206  0
             ruleResponsibilityClone.setRuleResponsibilityName(ruleResponsibilityName);
 207  
         }
 208  0
         if (ruleResponsibilityType != null) {
 209  0
             ruleResponsibilityClone.setRuleResponsibilityType(ruleResponsibilityType);
 210  
         }
 211  0
         if (priority != null) {
 212  0
             ruleResponsibilityClone.setPriority(priority);
 213  
         }
 214  
 //        if (delegationRules != null) {
 215  
 //            for (Iterator iter = delegationRules.iterator(); iter.hasNext();) {
 216  
 //                RuleDelegation delegation = (RuleDelegation) iter.next();
 217  
 //                RuleDelegation delegationClone = (RuleDelegation)delegation.copy(preserveKeys);
 218  
 //                delegationClone.setRuleResponsibility(ruleResponsibilityClone);
 219  
 //                ruleResponsibilityClone.getDelegationRules().add(delegationClone);
 220  
 //
 221  
 //            }
 222  
 //        }
 223  0
         return ruleResponsibilityClone;
 224  
     }
 225  
 
 226  
     public String getRuleResponsibilityName() {
 227  0
         return ruleResponsibilityName;
 228  
     }
 229  
 
 230  
     public void setRuleResponsibilityName(String ruleResponsibilityName) {
 231  0
         this.ruleResponsibilityName = ruleResponsibilityName;
 232  0
     }
 233  
 
 234  
     public String getRuleResponsibilityType() {
 235  0
         return ruleResponsibilityType;
 236  
     }
 237  
 
 238  
     public void setRuleResponsibilityType(String ruleResponsibilityType) {
 239  0
         this.ruleResponsibilityType = ruleResponsibilityType;
 240  0
     }
 241  
 
 242  
     public String getResponsibilityId() {
 243  0
         return responsibilityId;
 244  
     }
 245  
     public void setResponsibilityId(String responsibilityId) {
 246  0
         this.responsibilityId = responsibilityId;
 247  0
     }
 248  
     
 249  
     public List<RuleDelegationBo> getDelegationRules() {
 250  0
             return KEWServiceLocator.getRuleDelegationService().findByResponsibilityId(getResponsibilityId());
 251  
     }
 252  
     
 253  
     public RuleDelegationBo getDelegationRule(int index) {
 254  0
             return getDelegationRules().get(index);
 255  
     }
 256  
     
 257  
 //    public boolean isDelegating() {
 258  
 //        return !getDelegationRules().isEmpty();
 259  
 //    }
 260  
 //
 261  
 //    public List getDelegationRules() {
 262  
 //        return delegationRules;
 263  
 //    }
 264  
 //    public void setDelegationRules(List delegationRules) {
 265  
 //        this.delegationRules = delegationRules;
 266  
 //    }
 267  
 //
 268  
 //    public RuleDelegation getDelegationRule(int index) {
 269  
 //        while (getDelegationRules().size() <= index) {
 270  
 //            RuleDelegation ruleDelegation = new RuleDelegation();
 271  
 //            ruleDelegation.setRuleResponsibility(this);
 272  
 //            ruleDelegation.setDelegationRuleBaseValues(new RuleBaseValues());
 273  
 //            getDelegationRules().add(ruleDelegation);
 274  
 //        }
 275  
 //        return (RuleDelegation) getDelegationRules().get(index);
 276  
 //    }
 277  
     
 278  
     // convenience methods for the web-tier
 279  
     
 280  
     public String getActionRequestedDisplayValue() {
 281  0
             return KewApiConstants.ACTION_REQUEST_CODES.get(getActionRequestedCd());
 282  
     }
 283  
     
 284  
     public String getRuleResponsibilityTypeDisplayValue() {
 285  0
             return KewApiConstants.RULE_RESPONSIBILITY_TYPES.get(getRuleResponsibilityType());
 286  
     }
 287  
     
 288  
     public boolean equals(Object o) {
 289  0
         if (o == null) return false;
 290  0
         if (!(o instanceof RuleResponsibilityBo)) return false;
 291  0
         RuleResponsibilityBo pred = (RuleResponsibilityBo) o;
 292  0
         return ObjectUtils.equals(ruleResponsibilityName, pred.getRuleResponsibilityName()) &&
 293  
                ObjectUtils.equals(actionRequestedCd, pred.getActionRequestedCd()) &&
 294  
                ObjectUtils.equals(priority, pred.getPriority()) &&
 295  
                ObjectUtils.equals(approvePolicy, pred.getApprovePolicy());
 296  
     }
 297  
     
 298  
     /**
 299  
          * @see java.lang.Object#hashCode()
 300  
          */
 301  
         @Override
 302  
         public int hashCode() {
 303  0
                 return new HashCodeBuilder()
 304  
                 .append(this.actionRequestedCd)
 305  
                 .append(this.approvePolicy)
 306  
                 .append(this.priority)
 307  
                 .append(this.ruleResponsibilityName).toHashCode();
 308  
         }
 309  
 
 310  
     @Override
 311  
     public String getGroupId() {
 312  0
         if (!isUsingGroup()) {
 313  0
             return null;
 314  
         }
 315  0
         return getGroup().getId();
 316  
     }
 317  
 
 318  
     @Override
 319  
     public String getPrincipalId() {
 320  0
         if (getPrincipal() == null) {
 321  0
             return null;
 322  
         }
 323  0
         return getPrincipal().getPrincipalId();
 324  
     }
 325  
 
 326  
     @Override
 327  
     public String getRoleName() {
 328  0
         return getRole();
 329  
     }
 330  
 
 331  
     public static org.kuali.rice.kew.api.rule.RuleResponsibility to(RuleResponsibilityBo bo) {
 332  0
         if (bo == null) {
 333  0
             return null;
 334  
         }
 335  0
         return org.kuali.rice.kew.api.rule.RuleResponsibility.Builder.create(bo).build();
 336  
         /*org.kuali.rice.kew.api.rule.RuleResponsibility.Builder builder = org.kuali.rice.kew.api.rule.RuleResponsibility.Builder.create();
 337  
         builder.setPriority(bo.getPriority());
 338  
         builder.setResponsibilityId(bo.getResponsibilityId());
 339  
         builder.setActionRequestedCd(bo.getActionRequestedCd());
 340  
         builder.setApprovePolicy(bo.getApprovePolicy());
 341  
         builder.setPrincipalId(bo.getPrincipal() == null ? null : bo.getPrincipal().getPrincipalId());
 342  
         builder.setGroupId(bo.getGroup() == null ? null : bo.getGroup().getId());
 343  
         builder.setRoleName(bo.getResolvedRoleName());
 344  
         if (CollectionUtils.isNotEmpty(bo.getDelegationRules())) {
 345  
             List<org.kuali.rice.kew.api.rule.RuleDelegation.Builder> delegationRuleBuilders =
 346  
                     new ArrayList<org.kuali.rice.kew.api.rule.RuleDelegation.Builder>();
 347  
             for (RuleDelegation delegationRule : bo.getDelegationRules()) {
 348  
                 delegationRuleBuilders.add(
 349  
                         org.kuali.rice.kew.api.rule.RuleDelegation.Builder.create(RuleDelegation.to(delegationRule)));
 350  
             }
 351  
             builder.setDelegationRules(delegationRuleBuilders);
 352  
         } else {
 353  
             builder.setDelegationRules(Collections.<org.kuali.rice.kew.api.rule.RuleDelegation.Builder>emptyList());
 354  
         }
 355  
         return builder.build();*/
 356  
     }
 357  
 }