Coverage Report - org.kuali.rice.kew.routemodule.RouteModuleRemoteAdapter
 
Classes in this File Line Coverage Branch Coverage Complexity
RouteModuleRemoteAdapter
0%
0/31
0%
0/20
5.2
 
 1  
 /*
 2  
  * Copyright 2005-2007 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.routemodule;
 18  
 
 19  
 import java.rmi.RemoteException;
 20  
 import java.util.ArrayList;
 21  
 import java.util.List;
 22  
 
 23  
 import org.kuali.rice.core.exception.RiceRuntimeException;
 24  
 import org.kuali.rice.kew.dto.ActionRequestDTO;
 25  
 import org.kuali.rice.kew.dto.DTOConverter;
 26  
 import org.kuali.rice.kew.dto.DocumentContentDTO;
 27  
 import org.kuali.rice.kew.dto.RouteHeaderDTO;
 28  
 import org.kuali.rice.kew.engine.RouteContext;
 29  
 import org.kuali.rice.kew.exception.WorkflowException;
 30  
 import org.kuali.rice.kew.routeheader.DocumentRouteHeaderValue;
 31  
 import org.kuali.rice.kew.util.ResponsibleParty;
 32  
 
 33  
 
 34  
 /**
 35  
  * Adapts a {@link RouteModuleRemote} to the {@link RouteModule} interface.
 36  
  *
 37  
  * @see RouteModuleRemote
 38  
  * @see RouteModule
 39  
  *
 40  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 41  
  */
 42  
 public class RouteModuleRemoteAdapter implements RouteModule {
 43  
 
 44  
     private RouteModuleRemote routeModule;
 45  
 
 46  0
     public RouteModuleRemoteAdapter(RouteModuleRemote routeModule) {
 47  0
         if (routeModule == null) {
 48  0
             throw new IllegalArgumentException("RouteModuleRemoteAdapter cannot adapt a null RouteModuleRemote");
 49  
         }
 50  0
         this.routeModule = routeModule;
 51  0
     }
 52  
 
 53  
     public List findActionRequests(RouteContext context) throws Exception {
 54  
             // TODO add new findActionRequests to RouteModuleRemote
 55  0
             return findActionRequests(context.getDocument());
 56  
     }
 57  
 
 58  
     public List findActionRequests(DocumentRouteHeaderValue routeHeader) throws WorkflowException {
 59  
         try {
 60  0
             List actionRequests = new ArrayList();
 61  0
             RouteHeaderDTO routeHeaderVO = DTOConverter.convertRouteHeader(routeHeader, null);
 62  0
             DocumentContentDTO documentContentVO = DTOConverter.convertDocumentContent(routeHeader.getDocContent(), routeHeaderVO.getRouteHeaderId());
 63  0
             ActionRequestDTO[] actionRequestVOs = routeModule.findActionRequests(routeHeaderVO, documentContentVO);
 64  0
             if (actionRequestVOs != null && actionRequestVOs.length > 0) {
 65  0
                     assertRootRequests(actionRequestVOs);
 66  
 
 67  0
                 for (ActionRequestDTO actionRequestVO : actionRequestVOs) {
 68  0
                     actionRequestVO.setRouteHeaderId(routeHeader.getRouteHeaderId());
 69  
                     
 70  
                     // TODO this should be moved to a validate somewhere's...
 71  0
                     if (actionRequestVO.getPrincipalId() == null && actionRequestVO.getGroupId() == null) {
 72  0
                             throw new RiceRuntimeException("Post processor didn't set a user or workgroup on the request");
 73  
                     }
 74  
                     
 75  0
                     actionRequests.add(DTOConverter.convertActionRequestDTO(actionRequestVO));
 76  
                 }
 77  
             }
 78  0
             return actionRequests;
 79  0
         } catch (RemoteException e) {
 80  0
             if (e.getCause() instanceof WorkflowException) {
 81  0
                 throw (WorkflowException)e.getCause();
 82  
             }
 83  0
             throw new WorkflowException("Remote exception when finding action requests from route module "+routeModule.toString(), e);
 84  
         }
 85  
     }
 86  
 
 87  
     public ResponsibleParty resolveResponsibilityId(Long responsibilityId) throws WorkflowException {
 88  
         try {
 89  0
             return DTOConverter.convertResponsiblePartyVO(routeModule.resolveResponsibilityId(responsibilityId));
 90  0
         } catch (RemoteException e) {
 91  0
             if (e.getCause() instanceof WorkflowException) {
 92  0
                 throw (WorkflowException)e.getCause();
 93  
             }
 94  0
             throw new WorkflowException("Remote exception when resolving responsibility ids from route module "+routeModule.toString(), e);
 95  
         }
 96  
     }
 97  
     
 98  
     /**
 99  
      * Asserts that the given array of ActionRequestDTOs are only root requests (as required by the RouteModuleRemote API)
 100  
      */
 101  
     private void assertRootRequests(ActionRequestDTO[] actionRequestVOs) throws WorkflowException {
 102  0
             for (ActionRequestDTO actionRequest : actionRequestVOs) {
 103  0
                     if (actionRequest.getParentActionRequestId() != null) {
 104  0
                             throw new WorkflowException("Encountered an action request in the graph which was NOT a root request.  RouteModuleRemote.findActionRequests should only produce root ActionRequestDTO objects.");
 105  
                     }
 106  
             }
 107  0
     }
 108  
 
 109  
 }