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