Coverage Report - org.kuali.rice.kew.engine.node.service.impl.BranchServiceImpl
 
Classes in this File Line Coverage Branch Coverage Complexity
BranchServiceImpl
0%
0/38
0%
0/10
2
 
 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.engine.node.service.impl;
 17  
 
 18  
 import java.util.List;
 19  
 
 20  
 import org.apache.log4j.Logger;
 21  
 import org.kuali.rice.kew.engine.node.Branch;
 22  
 import org.kuali.rice.kew.engine.node.BranchState;
 23  
 import org.kuali.rice.kew.engine.node.dao.BranchDAO;
 24  
 import org.kuali.rice.kew.engine.node.service.BranchService;
 25  
 
 26  
 
 27  
 
 28  0
 public class BranchServiceImpl implements BranchService {
 29  0
     private static final Logger LOG = Logger.getLogger(BranchServiceImpl.class);
 30  
 
 31  
     private BranchDAO branchDAO;
 32  
     
 33  
     public void save(Branch branch){
 34  0
         getBranchDAO().save(branch);
 35  0
     }
 36  
     
 37  
      public BranchDAO getBranchDAO() {
 38  0
         return branchDAO;
 39  
     }
 40  
     public void setBranchDAO(BranchDAO branchDAO) {
 41  0
         this.branchDAO = branchDAO;
 42  0
     }
 43  
     
 44  
     public void deleteBranchStates(List statesToBeDeleted){
 45  0
         getBranchDAO().deleteBranchStates(statesToBeDeleted);
 46  0
     }
 47  
 
 48  
     /**
 49  
      * Walks up the Branch/scope hierarchy trying to find a variable with the specified name
 50  
      * @param branch the lowermost branch at which to start the search
 51  
      * @param name name of the variable to search for
 52  
      * @return a BranchState object in the first Branch/scope in which the variable was found
 53  
      */
 54  
     private BranchState resolveScopedVariable(Branch branch, String name) {
 55  0
         Branch b = branch;
 56  0
         while (b != null) {
 57  0
             for (BranchState bs: b.getBranchState()) {
 58  0
                 LOG.debug(bs);
 59  
             }
 60  0
             LOG.debug("Resolving variable: '" + name + "' in scope (branch): '" + branch.getName() + "' (" + branch.getBranchId() + ")");
 61  0
             BranchState bs = b.getBranchState(name);
 62  0
             if (bs != null) {
 63  0
                 return bs;    
 64  
             }
 65  0
             b = b.getParentBranch();
 66  0
         }
 67  0
         return null;
 68  
     }
 69  
 
 70  
     public String getScopedVariableValue(Branch branch, String name) {
 71  0
         BranchState bs = resolveScopedVariable(branch, name);
 72  0
         if (bs != null) return bs.getValue();
 73  0
         return null;
 74  
     }
 75  
 
 76  
     public String setScopedVariableValue(Branch branch, String name, String value) {
 77  0
         LOG.debug("Setting scoped variable value: " + name + " " + value);
 78  0
         BranchState bs = resolveScopedVariable(branch, name);
 79  0
         String oldValue = null;
 80  0
         if (bs == null) {
 81  0
             LOG.debug("Defining new variable named '" + name + "' at scope '" + branch + "'");
 82  
             // create new variable at initial search scope
 83  0
             bs = new BranchState();
 84  0
             bs.setKey(name);
 85  0
             bs.setValue(value);
 86  0
             bs.setBranch(branch);
 87  0
             branch.addBranchState(bs);
 88  
         } else {
 89  0
             oldValue = bs.getValue();
 90  0
             LOG.debug("Replacing old value of variable '" + name + "' (" + oldValue + ") at scope '" + branch + "' with new value: " + value);
 91  0
             bs.setValue(value);
 92  
         }
 93  
         // now save the Branch whose state we just modified
 94  0
         save(bs.getBranch());
 95  0
         return oldValue;
 96  
     }
 97  
     
 98  
 }