Coverage Report - org.kuali.rice.kew.impl.peopleflow.PeopleFlowDelegateBo
 
Classes in this File Line Coverage Branch Coverage Complexity
PeopleFlowDelegateBo
0%
0/54
0%
0/60
0
 
 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.impl.peopleflow
 17  
 
 18  
 import org.kuali.rice.core.api.delegation.DelegationType
 19  
 import org.kuali.rice.core.api.membership.MemberType
 20  
 import org.kuali.rice.kew.api.peopleflow.PeopleFlowDelegate
 21  
 
 22  
 import org.kuali.rice.krad.bo.PersistableBusinessObjectBase
 23  
 
 24  
 import org.kuali.rice.kew.api.peopleflow.PeopleFlowDelegateContract
 25  
 import org.kuali.rice.kew.api.action.ActionRequestPolicy
 26  
 import org.kuali.rice.kim.api.identity.Person
 27  
 import org.kuali.rice.kim.framework.group.GroupEbo
 28  
 import org.kuali.rice.kim.framework.role.RoleEbo
 29  
 import org.kuali.rice.kim.api.services.KimApiServiceLocator
 30  
 
 31  
 import org.kuali.rice.krad.service.ModuleService
 32  
 import org.kuali.rice.krad.service.KRADServiceLocatorWeb
 33  
 import org.apache.commons.lang.StringUtils
 34  
 
 35  
 /**
 36  
  * mapped entity for PeopleFlow members
 37  
  */
 38  
 class PeopleFlowDelegateBo extends PersistableBusinessObjectBase implements PeopleFlowDelegateContract {
 39  
 
 40  
     String id
 41  
     String peopleFlowMemberId
 42  
     String memberId
 43  
     String memberTypeCode
 44  
     String actionRequestPolicyCode
 45  
     String delegationTypeCode
 46  
     String responsibilityId
 47  
 
 48  
     // non-persisted
 49  
     String memberName;
 50  
     Person person;
 51  
     GroupEbo group;
 52  
     RoleEbo role;
 53  
 
 54  
     public Person getPerson() {
 55  0
         if (MemberType.PRINCIPAL.getCode().equals(memberTypeCode)) {
 56  0
             if ((this.person == null) || !person.getPrincipalId().equals(memberId) || !person.getPrincipalName().equals(memberName)) {
 57  
                 // use member name first
 58  0
                 if (StringUtils.isNotBlank(memberName)) {
 59  0
                     this.person = KimApiServiceLocator.personService.getPersonByPrincipalName(memberName);
 60  
                 } else {
 61  0
                     this.person = KimApiServiceLocator.personService.getPerson(memberId);
 62  
                 }
 63  
             }
 64  
 
 65  0
             if (this.person != null) {
 66  0
                 memberId = person.getPrincipalId();
 67  0
                 memberName = person.getPrincipalName();
 68  
 
 69  0
                 return this.person;
 70  
             }
 71  
         }
 72  
 
 73  0
         return KimApiServiceLocator.personService.personImplementationClass.newInstance();
 74  
     }
 75  
 
 76  
     public GroupEbo getGroup() {
 77  0
         if (MemberType.GROUP.getCode().equals(memberTypeCode)) {
 78  0
             ModuleService eboModuleService = KRADServiceLocatorWeb.getKualiModuleService().getResponsibleModuleService(GroupEbo.class);
 79  0
             group = eboModuleService.retrieveExternalizableBusinessObjectIfNecessary(this, group, "group");
 80  
 
 81  0
             if (group != null) {
 82  0
                 memberId = group.id;
 83  0
                 memberName = group.namespaceCode + " : " + group.name;
 84  
             }
 85  
         }
 86  
 
 87  0
         return group;
 88  
     }
 89  
 
 90  
     public RoleEbo getRole() {
 91  0
         if (MemberType.ROLE.getCode().equals(memberTypeCode)) {
 92  0
             ModuleService eboModuleService = KRADServiceLocatorWeb.getKualiModuleService().getResponsibleModuleService(RoleEbo.class);
 93  0
             role = eboModuleService.retrieveExternalizableBusinessObjectIfNecessary(this, role, "role");
 94  
 
 95  0
             if (role != null) {
 96  0
                 memberId = role.id;
 97  0
                 memberName = role.namespaceCode + " : " + role.name;
 98  
             }
 99  
         }
 100  
 
 101  0
         return role;
 102  
     }
 103  
 
 104  
     public void setMemberName(String memberName) {
 105  0
         this.memberName = memberName;
 106  
 
 107  
         // trigger update of related object (only person can be updated by name)
 108  0
         if (MemberType.PRINCIPAL.getCode().equals(memberTypeCode)) {
 109  0
             getPerson();
 110  
         }
 111  
     }
 112  
 
 113  
     public void setMemberId(String memberId) {
 114  0
         this.memberId = memberId;
 115  
 
 116  
         // trigger update of related object
 117  0
         if (MemberType.PRINCIPAL.getCode().equals(memberTypeCode)) {
 118  0
             getPerson();
 119  0
         } else if (MemberType.GROUP.getCode().equals(memberTypeCode)) {
 120  0
             getGroup();
 121  0
         } else if (MemberType.ROLE.getCode().equals(memberTypeCode)) {
 122  0
             getRole();
 123  
         }
 124  
     }
 125  
 
 126  
     @Override
 127  
     MemberType getMemberType() {
 128  0
         return MemberType.fromCode(memberTypeCode)
 129  
     }
 130  
 
 131  
     void setMemberType(MemberType type) {
 132  0
         memberTypeCode = type.getCode()
 133  
     }
 134  
 
 135  
     @Override
 136  
     ActionRequestPolicy getActionRequestPolicy() {
 137  0
         return ActionRequestPolicy.fromCode(actionRequestPolicyCode)
 138  
     }
 139  
 
 140  
     @Override
 141  
     DelegationType getDelegationType() {
 142  0
         return DelegationType.fromCode(delegationTypeCode)
 143  
     }
 144  
 
 145  
     void setDelegationType(DelegationType delegationType) {
 146  0
         this.delegationTypeCode = delegationType.getCode()
 147  
     }
 148  
 
 149  
     public static PeopleFlowDelegate to(PeopleFlowDelegateBo delegateBo) {
 150  0
         if (delegateBo == null) {
 151  0
             return null
 152  
         }
 153  0
         PeopleFlowDelegate.Builder builder = PeopleFlowDelegate.Builder.create(delegateBo)
 154  0
         return builder.build()
 155  
     }
 156  
 
 157  
     public static PeopleFlowDelegateBo from(PeopleFlowDelegate delegate) {
 158  0
         if (delegate == null) {
 159  0
             return null
 160  
         }
 161  0
         PeopleFlowDelegateBo delegateBo = new PeopleFlowDelegateBo()
 162  0
         delegateBo.setMemberId(delegate.getMemberId())
 163  0
         delegateBo.setMemberType(delegate.getMemberType())
 164  0
         if (delegate.getActionRequestPolicy() != null) {
 165  0
             delegateBo.setActionRequestPolicyCode(delegate.getActionRequestPolicy().getCode())
 166  
         }
 167  0
         if (delegate.getDelegationType() != null) {
 168  0
             delegateBo.setDelegationTypeCode(delegate.getDelegationType().getCode())
 169  
         }
 170  0
         delegateBo.setResponsibilityId(delegate.getResponsibilityId())
 171  0
         return delegateBo
 172  
     }
 173  
 
 174  
 }