Coverage Report - org.kuali.rice.kew.engine.node.dao.impl.RouteNodeDAOOjbImpl
 
Classes in this File Line Coverage Branch Coverage Complexity
RouteNodeDAOOjbImpl
0%
0/75
0%
0/8
1.222
 
 1  
 /*
 2  
  * Copyright 2005-2008 The Kuali Foundation
 3  
  * 
 4  
  * 
 5  
  * Licensed under the Educational Community License, Version 2.0 (the "License"); you may not use this file except in
 6  
  * compliance with the License. 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 distributed under the License is distributed on an "AS
 11  
  * IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific
 12  
  * language governing permissions and limitations under the License.
 13  
  */
 14  
 package org.kuali.rice.kew.engine.node.dao.impl;
 15  
 
 16  
 import java.util.ArrayList;
 17  
 import java.util.Iterator;
 18  
 import java.util.List;
 19  
 
 20  
 import org.apache.ojb.broker.query.Criteria;
 21  
 import org.apache.ojb.broker.query.QueryByCriteria;
 22  
 import org.apache.ojb.broker.query.QueryFactory;
 23  
 import org.apache.ojb.broker.query.ReportQueryByCriteria;
 24  
 import org.kuali.rice.kew.engine.node.Branch;
 25  
 import org.kuali.rice.kew.engine.node.NodeState;
 26  
 import org.kuali.rice.kew.engine.node.RouteNode;
 27  
 import org.kuali.rice.kew.engine.node.RouteNodeInstance;
 28  
 import org.kuali.rice.kew.engine.node.dao.RouteNodeDAO;
 29  
 import org.kuali.rice.kew.routeheader.DocumentRouteHeaderValue;
 30  
 import org.springmodules.orm.ojb.support.PersistenceBrokerDaoSupport;
 31  
 
 32  
 
 33  0
 public class RouteNodeDAOOjbImpl extends PersistenceBrokerDaoSupport implements RouteNodeDAO {
 34  
 
 35  
     private static final String ROUTE_NODE_ID = "routeNodeId";
 36  
     private static final String ROUTE_NODE_INSTANCE_ID = "routeNodeInstanceId";
 37  
     private static final String NODE_INSTANCE_ID = "nodeInstanceId";
 38  
     private static final String DOCUMENT_ID = "documentId";
 39  
     private static final String ROUTE_NODE_NAME = "routeNodeName";
 40  
     private static final String DOCUMENT_TYPE_ID = "documentTypeId";
 41  
     private static final String PROCESS_ID = "processId";
 42  
     private static final String ACTIVE = "active";
 43  
     private static final String COMPLETE = "complete";
 44  
     private static final String FINAL_APPROVAL = "finalApprovalInd";
 45  
     private static final String KEY = "key";
 46  
     private static final String Route_Node_State_ID = "nodeStateId";
 47  
 
 48  
     public void save(RouteNode node) {
 49  0
         getPersistenceBrokerTemplate().store(node);
 50  0
     }
 51  
 
 52  
     public void save(RouteNodeInstance nodeInstance) {
 53  
             // this is because the branch table relates to the node instance table - both through their keys - and
 54  
             // ojb can't automatically do this bi-directional relationship
 55  0
             getPersistenceBrokerTemplate().store(nodeInstance.getBranch());
 56  0
             getPersistenceBrokerTemplate().store(nodeInstance);
 57  0
     }
 58  
 
 59  
     public void save(NodeState nodeState) {
 60  0
         getPersistenceBrokerTemplate().store(nodeState);
 61  0
     }
 62  
 
 63  
     public void save(Branch branch) {
 64  0
         getPersistenceBrokerTemplate().store(branch);
 65  0
     }
 66  
 
 67  
     public RouteNode findRouteNodeById(String nodeId) {
 68  0
         Criteria criteria = new Criteria();
 69  0
         criteria.addEqualTo(ROUTE_NODE_ID, nodeId);
 70  0
         return (RouteNode) getPersistenceBrokerTemplate().getObjectByQuery(new QueryByCriteria(RouteNode.class, criteria));
 71  
     }
 72  
 
 73  
     public RouteNodeInstance findRouteNodeInstanceById(String nodeInstanceId) {
 74  0
         Criteria criteria = new Criteria();
 75  0
         criteria.addEqualTo(ROUTE_NODE_INSTANCE_ID, nodeInstanceId);
 76  0
         return (RouteNodeInstance) getPersistenceBrokerTemplate().getObjectByQuery(
 77  
                 new QueryByCriteria(RouteNodeInstance.class, criteria));
 78  
     }
 79  
 
 80  
     @SuppressWarnings(value = "unchecked")
 81  
     public List<RouteNodeInstance> getActiveNodeInstances(String documentId) {
 82  0
         Criteria criteria = new Criteria();
 83  0
         criteria.addEqualTo(DOCUMENT_ID, documentId);
 84  0
         criteria.addEqualTo(ACTIVE, Boolean.TRUE);
 85  0
         return (List<RouteNodeInstance>) getPersistenceBrokerTemplate().getCollectionByQuery(
 86  
                 new QueryByCriteria(RouteNodeInstance.class, criteria));
 87  
     }
 88  
 
 89  
     @SuppressWarnings("unchecked")
 90  
     public List<RouteNodeInstance> getTerminalNodeInstances(String documentId) {
 91  0
         Criteria criteria = new Criteria();
 92  0
         criteria.addEqualTo(DOCUMENT_ID, documentId);
 93  0
         criteria.addEqualTo(ACTIVE, Boolean.FALSE);
 94  0
         criteria.addEqualTo(COMPLETE, Boolean.TRUE);
 95  
 //        criteria.addIsNull("nextNodeInstances.routeNodeInstanceId");
 96  
 //        QueryByCriteria query = new QueryByCriteria(RouteNodeInstance.class, criteria);
 97  
 //        // we need to outer join here because we are looking for nodes with no nextNodeInstances
 98  
 //        query.setPathOuterJoin("nextNodeInstances");
 99  
 //        return (List) getPersistenceBrokerTemplate().getCollectionByQuery(query);
 100  
         
 101  
         //forced to do this programmatically, for some reason the above code stopped working 
 102  0
         List<RouteNodeInstance> terminalNodes = new ArrayList<RouteNodeInstance>();
 103  0
         List<RouteNodeInstance> routeNodeInstances = (List<RouteNodeInstance>) getPersistenceBrokerTemplate().getCollectionByQuery(new QueryByCriteria(RouteNodeInstance.class, criteria));
 104  0
         for (RouteNodeInstance routeNodeInstance : routeNodeInstances) {
 105  0
             if (routeNodeInstance.getNextNodeInstances().isEmpty()) {
 106  0
                 terminalNodes.add(routeNodeInstance);
 107  
             }
 108  
         }
 109  0
         return terminalNodes;
 110  
     }
 111  
 
 112  
     public List getInitialNodeInstances(String documentId) {
 113  0
         Criteria subCriteria = new Criteria();
 114  0
         subCriteria.addEqualTo(DOCUMENT_ID, documentId);
 115  0
         ReportQueryByCriteria subQuery = QueryFactory.newReportQuery(DocumentRouteHeaderValue.class, subCriteria);
 116  0
         subQuery.setAttributes(new String[]{"initialRouteNodeInstances.routeNodeInstanceId"});
 117  0
         Criteria criteria = new Criteria();
 118  0
         criteria.addIn(ROUTE_NODE_INSTANCE_ID, subQuery);
 119  0
         return (List) getPersistenceBrokerTemplate().getCollectionByQuery(
 120  
                 new QueryByCriteria(RouteNodeInstance.class, criteria));
 121  
     }
 122  
 
 123  
     public NodeState findNodeState(Long nodeInstanceId, String key) {
 124  0
         Criteria criteria = new Criteria();
 125  0
         criteria.addEqualTo(NODE_INSTANCE_ID, nodeInstanceId);
 126  0
         criteria.addEqualTo(KEY, key);
 127  0
         return (NodeState) getPersistenceBrokerTemplate().getObjectByQuery(new QueryByCriteria(NodeState.class, criteria));
 128  
     }
 129  
 
 130  
     public RouteNode findRouteNodeByName(String documentTypeId, String name) {
 131  0
         Criteria criteria = new Criteria();
 132  0
         criteria.addEqualTo(ROUTE_NODE_NAME, name);
 133  0
         criteria.addEqualTo(DOCUMENT_TYPE_ID, documentTypeId);
 134  0
         return (RouteNode) getPersistenceBrokerTemplate().getObjectByQuery(new QueryByCriteria(RouteNode.class, criteria));
 135  
     }
 136  
 
 137  
     public List findFinalApprovalRouteNodes(String documentTypeId) {
 138  0
         Criteria criteria = new Criteria();
 139  0
         criteria.addEqualTo(DOCUMENT_TYPE_ID, documentTypeId);
 140  0
         criteria.addEqualTo(FINAL_APPROVAL, Boolean.TRUE);
 141  0
         return (List) getPersistenceBrokerTemplate().getCollectionByQuery(new QueryByCriteria(RouteNode.class, criteria));
 142  
     }
 143  
 
 144  
     public List findProcessNodeInstances(RouteNodeInstance process) {
 145  0
         Criteria crit = new Criteria();
 146  0
         crit.addEqualTo(PROCESS_ID, process.getRouteNodeInstanceId());
 147  0
         return (List) getPersistenceBrokerTemplate()
 148  
                 .getCollectionByQuery(new QueryByCriteria(RouteNodeInstance.class, crit));
 149  
     }
 150  
 
 151  
     public List findRouteNodeInstances(String documentId) {
 152  0
         Criteria criteria = new Criteria();
 153  0
         criteria.addEqualTo(DOCUMENT_ID, documentId);
 154  0
         return (List) getPersistenceBrokerTemplate().getCollectionByQuery(
 155  
                 new QueryByCriteria(RouteNodeInstance.class, criteria));
 156  
     }
 157  
 
 158  
     public void deleteLinksToPreNodeInstances(RouteNodeInstance routeNodeInstance) {
 159  0
         List<RouteNodeInstance> preNodeInstances = routeNodeInstance.getPreviousNodeInstances();
 160  0
         for (Iterator<RouteNodeInstance> preNodeInstanceIter = preNodeInstances.iterator(); preNodeInstanceIter.hasNext();) {
 161  0
             RouteNodeInstance preNodeInstance = (RouteNodeInstance) preNodeInstanceIter.next();
 162  0
             List<RouteNodeInstance> nextInstances = preNodeInstance.getNextNodeInstances();
 163  0
             nextInstances.remove(routeNodeInstance);
 164  0
             save(preNodeInstance);
 165  0
         }
 166  0
     }
 167  
 
 168  
     public void deleteRouteNodeInstancesHereAfter(RouteNodeInstance routeNodeInstance) {
 169  0
         this.getPersistenceBrokerTemplate().delete(routeNodeInstance);
 170  0
     }
 171  
 
 172  
     public void deleteNodeStateById(Long nodeStateId) {
 173  0
         Criteria criteria = new Criteria();
 174  0
         criteria.addEqualTo(Route_Node_State_ID, nodeStateId);
 175  0
         NodeState nodeState = (NodeState) getPersistenceBrokerTemplate().getObjectByQuery(
 176  
                 new QueryByCriteria(NodeState.class, criteria));
 177  0
         getPersistenceBrokerTemplate().delete(nodeState);
 178  0
     }
 179  
 
 180  
     public void deleteNodeStates(List statesToBeDeleted) {
 181  0
         for (Iterator stateToBeDeletedIter = statesToBeDeleted.iterator(); stateToBeDeletedIter.hasNext();) {
 182  0
             Long stateId = (Long) stateToBeDeletedIter.next();
 183  0
             deleteNodeStateById(stateId);
 184  0
         }
 185  0
     }
 186  
 
 187  
 }