001: /*
002: * Copyright 2005-2007 The Kuali Foundation.
003: *
004: *
005: * Licensed under the Educational Community License, Version 1.0 (the "License");
006: * you may not use this file except in compliance with the License.
007: * You may obtain a copy of the License at
008: *
009: * http://www.opensource.org/licenses/ecl1.php
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: package edu.iu.uis.eden.routemodule;
018:
019: import java.util.ArrayList;
020: import java.util.HashMap;
021: import java.util.Iterator;
022: import java.util.List;
023: import java.util.Map;
024:
025: import edu.iu.uis.eden.EdenConstants;
026: import edu.iu.uis.eden.KEWServiceLocator;
027: import edu.iu.uis.eden.actionrequests.ActionRequestFactory;
028: import edu.iu.uis.eden.actionrequests.ActionRequestValue;
029: import edu.iu.uis.eden.engine.RouteContext;
030: import edu.iu.uis.eden.exception.ResourceUnavailableException;
031: import edu.iu.uis.eden.exception.WorkflowException;
032: import edu.iu.uis.eden.routeheader.DocumentRouteHeaderValue;
033: import edu.iu.uis.eden.user.AuthenticationUserId;
034: import edu.iu.uis.eden.user.Recipient;
035: import edu.iu.uis.eden.util.ResponsibleParty;
036: import edu.iu.uis.eden.workgroup.GroupNameId;
037:
038: /**
039: * @author ewestfal
040: */
041: public class TestRouteModule implements RouteModule {
042:
043: private static Map responsibilityMap = new HashMap();
044:
045: public List findActionRequests(RouteContext context)
046: throws ResourceUnavailableException, WorkflowException {
047: return findActionRequests(context.getDocument());
048: }
049:
050: public List findActionRequests(DocumentRouteHeaderValue routeHeader)
051: throws ResourceUnavailableException, WorkflowException {
052: TestRouteLevel routeLevel = TestRouteModuleXMLHelper
053: .parseCurrentRouteLevel(routeHeader);
054: List actionRequests = new ArrayList();
055: if (routeLevel == null) {
056: return actionRequests;
057: }
058: for (Iterator iterator = routeLevel.getResponsibilities()
059: .iterator(); iterator.hasNext();) {
060: TestResponsibility responsibility = (TestResponsibility) iterator
061: .next();
062: TestRecipient recipient = responsibility.getRecipient();
063: Recipient realRecipient = getRealRecipient(recipient);
064: ActionRequestFactory arFactory = new ActionRequestFactory(
065: routeHeader);
066: Long responsibilityId = KEWServiceLocator
067: .getResponsibilityIdService()
068: .getNewResponsibilityId();
069: ActionRequestValue request = arFactory
070: .addRootActionRequest(responsibility
071: .getActionRequested(), new Integer(
072: responsibility.getPriority()),
073: realRecipient, "", responsibilityId,
074: Boolean.FALSE, null, null);
075: responsibilityMap.put(request.getResponsibilityId(),
076: recipient);
077: for (Iterator delIt = responsibility.getDelegations()
078: .iterator(); delIt.hasNext();) {
079: TestDelegation delegation = (TestDelegation) delIt
080: .next();
081: TestRecipient delegationRecipient = delegation
082: .getResponsibility().getRecipient();
083: Recipient realDelegationRecipient = getRealRecipient(delegationRecipient);
084: responsibilityId = KEWServiceLocator
085: .getResponsibilityIdService()
086: .getNewResponsibilityId();
087: ActionRequestValue delegationRequest = arFactory
088: .addDelegationRequest(request,
089: realDelegationRecipient,
090: responsibilityId, Boolean.FALSE,
091: delegation.getType(), "", null);
092: responsibilityMap.put(delegationRequest
093: .getResponsibilityId(), delegationRecipient);
094: }
095: actionRequests.add(request);
096: }
097: return actionRequests;
098: }
099:
100: public Recipient getRealRecipient(TestRecipient recipient)
101: throws WorkflowException {
102: Recipient realRecipient = null;
103: if (recipient.getType().equals(
104: EdenConstants.ACTION_REQUEST_USER_RECIPIENT_CD)) {
105: realRecipient = KEWServiceLocator
106: .getUserService()
107: .getWorkflowUser(
108: new AuthenticationUserId(recipient.getId()));
109: } else if (recipient.getType().equals(
110: EdenConstants.ACTION_REQUEST_USER_RECIPIENT_CD)) {
111: realRecipient = KEWServiceLocator.getWorkgroupService()
112: .getWorkgroup(new GroupNameId(recipient.getId()));
113: } else {
114: throw new WorkflowException(
115: "Could not resolve recipient with type "
116: + recipient.getType());
117: }
118: return realRecipient;
119: }
120:
121: public ResponsibleParty resolveResponsibilityId(
122: Long responsibilityId) throws ResourceUnavailableException,
123: WorkflowException {
124: TestRecipient recipient = (TestRecipient) responsibilityMap
125: .get(responsibilityId);
126: if (recipient == null) {
127: return null;
128: }
129: ResponsibleParty responsibleParty = new ResponsibleParty();
130: if (recipient.getType().equals(
131: EdenConstants.ACTION_REQUEST_USER_RECIPIENT_CD)) {
132: responsibleParty.setUserId(new AuthenticationUserId(
133: recipient.getId()));
134: } else if (recipient.getType().equals(
135: EdenConstants.ACTION_REQUEST_WORKGROUP_RECIPIENT_CD)) {
136: responsibleParty.setGroupId(new GroupNameId(recipient
137: .getId()));
138: } else if (recipient.getType().equals(
139: EdenConstants.ACTION_REQUEST_ROLE_RECIPIENT_CD)) {
140: responsibleParty.setRoleName(recipient.getId());
141: } else {
142: throw new WorkflowException(
143: "Invalid recipient type code of '"
144: + recipient.getType()
145: + "' for responsibility id "
146: + responsibilityId);
147: }
148: return responsibleParty;
149: }
150:
151: }
|