1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.kuali.rice.kew.engine.node.dao.impl; |
17 | |
|
18 | |
import java.util.ArrayList; |
19 | |
import java.util.Iterator; |
20 | |
import java.util.List; |
21 | |
|
22 | |
import org.apache.ojb.broker.query.Criteria; |
23 | |
import org.apache.ojb.broker.query.QueryByCriteria; |
24 | |
import org.apache.ojb.broker.query.QueryFactory; |
25 | |
import org.apache.ojb.broker.query.ReportQueryByCriteria; |
26 | |
import org.kuali.rice.kew.engine.node.Branch; |
27 | |
import org.kuali.rice.kew.engine.node.NodeState; |
28 | |
import org.kuali.rice.kew.engine.node.RouteNode; |
29 | |
import org.kuali.rice.kew.engine.node.RouteNodeInstance; |
30 | |
import org.kuali.rice.kew.engine.node.dao.RouteNodeDAO; |
31 | |
import org.kuali.rice.kew.routeheader.DocumentRouteHeaderValue; |
32 | |
import org.springmodules.orm.ojb.support.PersistenceBrokerDaoSupport; |
33 | |
|
34 | |
|
35 | 0 | public class RouteNodeDAOOjbImpl extends PersistenceBrokerDaoSupport implements RouteNodeDAO { |
36 | |
|
37 | |
private static final String ROUTE_NODE_ID = "routeNodeId"; |
38 | |
private static final String ROUTE_NODE_INSTANCE_ID = "routeNodeInstanceId"; |
39 | |
private static final String NODE_INSTANCE_ID = "nodeInstanceId"; |
40 | |
private static final String DOCUMENT_ID = "documentId"; |
41 | |
private static final String ROUTE_NODE_NAME = "routeNodeName"; |
42 | |
private static final String DOCUMENT_TYPE_ID = "documentTypeId"; |
43 | |
private static final String PROCESS_ID = "processId"; |
44 | |
private static final String ACTIVE = "active"; |
45 | |
private static final String COMPLETE = "complete"; |
46 | |
private static final String FINAL_APPROVAL = "finalApprovalInd"; |
47 | |
private static final String KEY = "key"; |
48 | |
private static final String Route_Node_State_ID = "nodeStateId"; |
49 | |
|
50 | |
public void save(RouteNode node) { |
51 | 0 | getPersistenceBrokerTemplate().store(node); |
52 | 0 | } |
53 | |
|
54 | |
public void save(RouteNodeInstance nodeInstance) { |
55 | |
|
56 | |
|
57 | 0 | getPersistenceBrokerTemplate().store(nodeInstance.getBranch()); |
58 | 0 | getPersistenceBrokerTemplate().store(nodeInstance); |
59 | 0 | } |
60 | |
|
61 | |
public void save(NodeState nodeState) { |
62 | 0 | getPersistenceBrokerTemplate().store(nodeState); |
63 | 0 | } |
64 | |
|
65 | |
public void save(Branch branch) { |
66 | 0 | getPersistenceBrokerTemplate().store(branch); |
67 | 0 | } |
68 | |
|
69 | |
public RouteNode findRouteNodeById(String nodeId) { |
70 | 0 | Criteria criteria = new Criteria(); |
71 | 0 | criteria.addEqualTo(ROUTE_NODE_ID, nodeId); |
72 | 0 | return (RouteNode) getPersistenceBrokerTemplate().getObjectByQuery(new QueryByCriteria(RouteNode.class, criteria)); |
73 | |
} |
74 | |
|
75 | |
public RouteNodeInstance findRouteNodeInstanceById(String nodeInstanceId) { |
76 | 0 | Criteria criteria = new Criteria(); |
77 | 0 | criteria.addEqualTo(ROUTE_NODE_INSTANCE_ID, nodeInstanceId); |
78 | 0 | return (RouteNodeInstance) getPersistenceBrokerTemplate().getObjectByQuery( |
79 | |
new QueryByCriteria(RouteNodeInstance.class, criteria)); |
80 | |
} |
81 | |
|
82 | |
@SuppressWarnings(value = "unchecked") |
83 | |
public List<RouteNodeInstance> getActiveNodeInstances(String documentId) { |
84 | 0 | Criteria criteria = new Criteria(); |
85 | 0 | criteria.addEqualTo(DOCUMENT_ID, documentId); |
86 | 0 | criteria.addEqualTo(ACTIVE, Boolean.TRUE); |
87 | 0 | return (List<RouteNodeInstance>) getPersistenceBrokerTemplate().getCollectionByQuery( |
88 | |
new QueryByCriteria(RouteNodeInstance.class, criteria)); |
89 | |
} |
90 | |
|
91 | |
@SuppressWarnings("unchecked") |
92 | |
public List<RouteNodeInstance> getTerminalNodeInstances(String documentId) { |
93 | 0 | Criteria criteria = new Criteria(); |
94 | 0 | criteria.addEqualTo(DOCUMENT_ID, documentId); |
95 | 0 | criteria.addEqualTo(ACTIVE, Boolean.FALSE); |
96 | 0 | criteria.addEqualTo(COMPLETE, Boolean.TRUE); |
97 | |
|
98 | |
|
99 | |
|
100 | |
|
101 | |
|
102 | |
|
103 | |
|
104 | 0 | List<RouteNodeInstance> terminalNodes = new ArrayList<RouteNodeInstance>(); |
105 | 0 | List<RouteNodeInstance> routeNodeInstances = (List<RouteNodeInstance>) getPersistenceBrokerTemplate().getCollectionByQuery(new QueryByCriteria(RouteNodeInstance.class, criteria)); |
106 | 0 | for (RouteNodeInstance routeNodeInstance : routeNodeInstances) { |
107 | 0 | if (routeNodeInstance.getNextNodeInstances().isEmpty()) { |
108 | 0 | terminalNodes.add(routeNodeInstance); |
109 | |
} |
110 | |
} |
111 | 0 | return terminalNodes; |
112 | |
} |
113 | |
|
114 | |
public List getInitialNodeInstances(String documentId) { |
115 | 0 | Criteria subCriteria = new Criteria(); |
116 | 0 | subCriteria.addEqualTo(DOCUMENT_ID, documentId); |
117 | 0 | ReportQueryByCriteria subQuery = QueryFactory.newReportQuery(DocumentRouteHeaderValue.class, subCriteria); |
118 | 0 | subQuery.setAttributes(new String[]{"initialRouteNodeInstances.routeNodeInstanceId"}); |
119 | 0 | Criteria criteria = new Criteria(); |
120 | 0 | criteria.addIn(ROUTE_NODE_INSTANCE_ID, subQuery); |
121 | 0 | return (List) getPersistenceBrokerTemplate().getCollectionByQuery( |
122 | |
new QueryByCriteria(RouteNodeInstance.class, criteria)); |
123 | |
} |
124 | |
|
125 | |
public NodeState findNodeState(Long nodeInstanceId, String key) { |
126 | 0 | Criteria criteria = new Criteria(); |
127 | 0 | criteria.addEqualTo(NODE_INSTANCE_ID, nodeInstanceId); |
128 | 0 | criteria.addEqualTo(KEY, key); |
129 | 0 | return (NodeState) getPersistenceBrokerTemplate().getObjectByQuery(new QueryByCriteria(NodeState.class, criteria)); |
130 | |
} |
131 | |
|
132 | |
public RouteNode findRouteNodeByName(String documentTypeId, String name) { |
133 | 0 | Criteria criteria = new Criteria(); |
134 | 0 | criteria.addEqualTo(ROUTE_NODE_NAME, name); |
135 | 0 | criteria.addEqualTo(DOCUMENT_TYPE_ID, documentTypeId); |
136 | 0 | return (RouteNode) getPersistenceBrokerTemplate().getObjectByQuery(new QueryByCriteria(RouteNode.class, criteria)); |
137 | |
} |
138 | |
|
139 | |
public List<RouteNode> findFinalApprovalRouteNodes(String documentTypeId) { |
140 | 0 | Criteria criteria = new Criteria(); |
141 | 0 | criteria.addEqualTo(DOCUMENT_TYPE_ID, documentTypeId); |
142 | 0 | criteria.addEqualTo(FINAL_APPROVAL, Boolean.TRUE); |
143 | 0 | return new ArrayList<RouteNode>(getPersistenceBrokerTemplate().getCollectionByQuery(new QueryByCriteria(RouteNode.class, criteria))); |
144 | |
} |
145 | |
|
146 | |
public List findProcessNodeInstances(RouteNodeInstance process) { |
147 | 0 | Criteria crit = new Criteria(); |
148 | 0 | crit.addEqualTo(PROCESS_ID, process.getRouteNodeInstanceId()); |
149 | 0 | return (List) getPersistenceBrokerTemplate() |
150 | |
.getCollectionByQuery(new QueryByCriteria(RouteNodeInstance.class, crit)); |
151 | |
} |
152 | |
|
153 | |
public List findRouteNodeInstances(String documentId) { |
154 | 0 | Criteria criteria = new Criteria(); |
155 | 0 | criteria.addEqualTo(DOCUMENT_ID, documentId); |
156 | 0 | return (List) getPersistenceBrokerTemplate().getCollectionByQuery( |
157 | |
new QueryByCriteria(RouteNodeInstance.class, criteria)); |
158 | |
} |
159 | |
|
160 | |
public void deleteLinksToPreNodeInstances(RouteNodeInstance routeNodeInstance) { |
161 | 0 | List<RouteNodeInstance> preNodeInstances = routeNodeInstance.getPreviousNodeInstances(); |
162 | 0 | for (Iterator<RouteNodeInstance> preNodeInstanceIter = preNodeInstances.iterator(); preNodeInstanceIter.hasNext();) { |
163 | 0 | RouteNodeInstance preNodeInstance = (RouteNodeInstance) preNodeInstanceIter.next(); |
164 | 0 | List<RouteNodeInstance> nextInstances = preNodeInstance.getNextNodeInstances(); |
165 | 0 | nextInstances.remove(routeNodeInstance); |
166 | 0 | save(preNodeInstance); |
167 | 0 | } |
168 | 0 | } |
169 | |
|
170 | |
public void deleteRouteNodeInstancesHereAfter(RouteNodeInstance routeNodeInstance) { |
171 | 0 | this.getPersistenceBrokerTemplate().delete(routeNodeInstance); |
172 | 0 | } |
173 | |
|
174 | |
public void deleteNodeStateById(Long nodeStateId) { |
175 | 0 | Criteria criteria = new Criteria(); |
176 | 0 | criteria.addEqualTo(Route_Node_State_ID, nodeStateId); |
177 | 0 | NodeState nodeState = (NodeState) getPersistenceBrokerTemplate().getObjectByQuery( |
178 | |
new QueryByCriteria(NodeState.class, criteria)); |
179 | 0 | getPersistenceBrokerTemplate().delete(nodeState); |
180 | 0 | } |
181 | |
|
182 | |
public void deleteNodeStates(List statesToBeDeleted) { |
183 | 0 | for (Iterator stateToBeDeletedIter = statesToBeDeleted.iterator(); stateToBeDeletedIter.hasNext();) { |
184 | 0 | Long stateId = (Long) stateToBeDeletedIter.next(); |
185 | 0 | deleteNodeStateById(stateId); |
186 | 0 | } |
187 | 0 | } |
188 | |
|
189 | |
} |