Clover Coverage Report - kew-test 2.0.0-SNAPSHOT
Coverage timestamp: Wed Dec 31 1969 19:00:00 EST
../../../../../img/srcFileCovDistChart0.png 0% of files have more coverage
41   108   13   10.25
18   78   0.32   4
4     3.25  
1    
 
  TestRouteModule       Line # 43 41 0% 13 63 0% 0.0
 
No Tests
 
1   
2    /*
3    * Copyright 2005-2007 The Kuali Foundation
4    *
5    *
6    * Licensed under the Educational Community License, Version 2.0 (the "License");
7    * you may not use this file except in compliance with the License.
8    * You may obtain a copy of the License at
9    *
10    * http://www.opensource.org/licenses/ecl2.php
11    *
12    * Unless required by applicable law or agreed to in writing, software
13    * distributed under the License is distributed on an "AS IS" BASIS,
14    * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15    * See the License for the specific language governing permissions and
16    * limitations under the License.
17    */
18    package org.kuali.rice.kew.routemodule;
19   
20    import java.util.ArrayList;
21    import java.util.HashMap;
22    import java.util.Iterator;
23    import java.util.List;
24    import java.util.Map;
25   
26    import org.kuali.rice.kew.actionrequest.ActionRequestFactory;
27    import org.kuali.rice.kew.actionrequest.ActionRequestValue;
28    import org.kuali.rice.kew.actionrequest.KimGroupRecipient;
29    import org.kuali.rice.kew.actionrequest.KimPrincipalRecipient;
30    import org.kuali.rice.kew.actionrequest.Recipient;
31    import org.kuali.rice.kew.engine.RouteContext;
32    import org.kuali.rice.kew.exception.ResourceUnavailableException;
33    import org.kuali.rice.kew.exception.WorkflowException;
34    import org.kuali.rice.kew.routeheader.DocumentRouteHeaderValue;
35    import org.kuali.rice.kew.service.KEWServiceLocator;
36    import org.kuali.rice.kew.util.KEWConstants;
37    import org.kuali.rice.kew.util.ResponsibleParty;
38   
39   
40    /**
41    * @author Kuali Rice Team (rice.collab@kuali.org)
42    */
 
43    public class TestRouteModule implements RouteModule {
44   
45    private static Map responsibilityMap = new HashMap();
46   
 
47  0 toggle public List findActionRequests(RouteContext context) throws ResourceUnavailableException, WorkflowException {
48  0 return findActionRequests(context.getDocument());
49    }
50   
 
51  0 toggle public List findActionRequests(DocumentRouteHeaderValue routeHeader) throws ResourceUnavailableException, WorkflowException {
52  0 TestRouteLevel routeLevel = TestRouteModuleXMLHelper.parseCurrentRouteLevel(routeHeader);
53  0 List actionRequests = new ArrayList();
54  0 if (routeLevel == null) {
55  0 return actionRequests;
56    }
57  0 for (Iterator iterator = routeLevel.getResponsibilities().iterator(); iterator.hasNext();) {
58  0 TestResponsibility responsibility = (TestResponsibility) iterator.next();
59  0 TestRecipient recipient = responsibility.getRecipient();
60  0 Recipient realRecipient = getRealRecipient(recipient);
61  0 ActionRequestFactory arFactory = new ActionRequestFactory(routeHeader);
62  0 Long responsibilityId = KEWServiceLocator.getResponsibilityIdService().getNewResponsibilityId();
63  0 ActionRequestValue request = arFactory.addRootActionRequest(responsibility.getActionRequested(), new Integer(responsibility.getPriority()), realRecipient, "", responsibilityId, Boolean.FALSE, null, null);
64  0 responsibilityMap.put(request.getResponsibilityId(), recipient);
65  0 for (Iterator delIt = responsibility.getDelegations().iterator(); delIt.hasNext();) {
66  0 TestDelegation delegation = (TestDelegation) delIt.next();
67  0 TestRecipient delegationRecipient = delegation.getResponsibility().getRecipient();
68  0 Recipient realDelegationRecipient = getRealRecipient(delegationRecipient);
69  0 responsibilityId = KEWServiceLocator.getResponsibilityIdService().getNewResponsibilityId();
70  0 ActionRequestValue delegationRequest = arFactory.addDelegationRequest(request, realDelegationRecipient, responsibilityId, Boolean.FALSE, delegation.getType(), "", null);
71  0 responsibilityMap.put(delegationRequest.getResponsibilityId(), delegationRecipient);
72    }
73  0 actionRequests.add(request);
74    }
75  0 return actionRequests;
76    }
77   
 
78  0 toggle public Recipient getRealRecipient(TestRecipient recipient) throws WorkflowException {
79  0 Recipient realRecipient = null;
80  0 if (recipient.getType().equals(KEWConstants.ACTION_REQUEST_USER_RECIPIENT_CD)) {
81  0 realRecipient = new KimPrincipalRecipient(recipient.getId());
82  0 } else if (recipient.getType().equals(KEWConstants.ACTION_REQUEST_GROUP_RECIPIENT_CD)) {
83  0 realRecipient = new KimGroupRecipient(recipient.getId());
84    } else {
85  0 throw new WorkflowException("Could not resolve recipient with type " + recipient.getType());
86    }
87  0 return realRecipient;
88    }
89   
 
90  0 toggle public ResponsibleParty resolveResponsibilityId(Long responsibilityId) throws ResourceUnavailableException, WorkflowException {
91  0 TestRecipient recipient = (TestRecipient)responsibilityMap.get(responsibilityId);
92  0 if (recipient == null) {
93  0 return null;
94    }
95  0 ResponsibleParty responsibleParty = new ResponsibleParty();
96  0 if (recipient.getType().equals(KEWConstants.ACTION_REQUEST_USER_RECIPIENT_CD)) {
97  0 responsibleParty.setPrincipalId(recipient.getId());
98  0 } else if (recipient.getType().equals(KEWConstants.ACTION_REQUEST_GROUP_RECIPIENT_CD)) {
99  0 responsibleParty.setGroupId(recipient.getId());
100  0 } else if (recipient.getType().equals(KEWConstants.ACTION_REQUEST_ROLE_RECIPIENT_CD)) {
101  0 responsibleParty.setRoleName(recipient.getId());
102    } else {
103  0 throw new WorkflowException("Invalid recipient type code of '"+recipient.getType()+"' for responsibility id "+responsibilityId);
104    }
105  0 return responsibleParty;
106    }
107   
108    }