View Javadoc
1   /*
2    * Copyright 2008-2009 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.ole.sys.document.workflow;
17  
18  import java.util.ArrayList;
19  import java.util.List;
20  
21  import org.kuali.ole.sys.context.SpringContext;
22  import org.kuali.ole.sys.document.FinancialSystemDocument;
23  import org.kuali.ole.sys.document.FinancialSystemMaintenanceDocument;
24  import org.kuali.ole.sys.document.FinancialSystemTransactionalDocument;
25  import org.kuali.rice.kew.engine.RouteContext;
26  import org.kuali.rice.kew.engine.RouteHelper;
27  import org.kuali.rice.kew.engine.node.SplitNode;
28  import org.kuali.rice.kew.engine.node.SplitResult;
29  import org.kuali.rice.krad.document.Document;
30  import org.kuali.rice.krad.service.DocumentService;
31  
32  public class SimpleBooleanSplitNode implements SplitNode {
33  
34      /**
35       * @see org.kuali.rice.kew.engine.node.SimpleNode#process(org.kuali.rice.kew.engine.RouteContext, org.kuali.rice.kew.engine.RouteHelper)
36       */
37      @Override
38      public SplitResult process(RouteContext context, RouteHelper helper) throws Exception {
39          SplitResult result = null;
40          String documentID = context.getDocument().getDocumentId();
41          Document document = SpringContext.getBean(DocumentService.class).getByDocumentHeaderId(documentID);
42          if (document instanceof FinancialSystemDocument) {
43          String nodeName = context.getNodeInstance().getRouteNode().getRouteNodeName();
44              boolean ret = ((FinancialSystemDocument)document).answerSplitNodeQuestion(nodeName);
45              result = booleanToSplitResult(ret);
46          } else {
47              throw new IllegalArgumentException("Document "+document.getDocumentTitle() +" with id " + documentID + " is not an instance of " + FinancialSystemMaintenanceDocument.class + " or " + FinancialSystemTransactionalDocument.class);
48          }
49          
50          return result;
51      }
52      
53      /**
54       * Converts a boolean value to SplitResult where the branch name is "True" or "False" based on the value of the given boolean
55       * @param b a boolean to convert to a SplitResult
56       * @return the converted SplitResult
57       */
58      protected SplitResult booleanToSplitResult(boolean b) {
59          List<String> branches = new ArrayList<String>();
60          final String branchName = b ? "True" : "False";
61          branches.add(branchName);
62          return new SplitResult(branches);
63      }
64  
65  }