Clover Coverage Report - Implementation 2.0.0-SNAPSHOT
Coverage timestamp: Wed Dec 31 1969 19:00:00 EST
../../../../../../../img/srcFileCovDistChart0.png 0% of files have more coverage
153   286   34   6.65
18   222   0.22   23
23     1.48  
1    
 
  ActionRequestDAOOjbImpl       Line # 39 153 0% 34 194 0% 0.0
 
No Tests
 
1    /*
2    * Copyright 2005-2007 The Kuali Foundation
3    *
4    *
5    * Licensed under the Educational Community License, Version 2.0 (the "License");
6    * you may not use this file except in compliance with the License.
7    * You may obtain a copy of the License at
8    *
9    * http://www.opensource.org/licenses/ecl2.php
10    *
11    * Unless required by applicable law or agreed to in writing, software
12    * distributed under the License is distributed on an "AS IS" BASIS,
13    * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14    * See the License for the specific language governing permissions and
15    * limitations under the License.
16    */
17    package org.kuali.rice.kew.actionrequest.dao.impl;
18   
19    import org.apache.commons.lang.StringUtils;
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.actionrequest.ActionRequestValue;
25    import org.kuali.rice.kew.actionrequest.dao.ActionRequestDAO;
26    import org.kuali.rice.kew.routeheader.DocumentRouteHeaderValue;
27    import org.kuali.rice.kew.util.KEWConstants;
28    import org.springmodules.orm.ojb.support.PersistenceBrokerDaoSupport;
29   
30    import java.sql.Timestamp;
31    import java.util.*;
32   
33   
34    /**
35    * OJB implementation of the {@link ActionRequestDAO}.
36    *
37    * @author Kuali Rice Team (rice.collab@kuali.org)
38    */
 
39    public class ActionRequestDAOOjbImpl extends PersistenceBrokerDaoSupport implements ActionRequestDAO {
40   
 
41  0 toggle public ActionRequestValue getActionRequestByActionRequestId(Long actionRequestId) {
42  0 Criteria crit = new Criteria();
43  0 crit.addEqualTo("actionRequestId", actionRequestId);
44  0 return (ActionRequestValue) this.getPersistenceBrokerTemplate().getObjectByQuery(new QueryByCriteria(ActionRequestValue.class, crit));
45    }
46   
 
47  0 toggle public void saveActionRequest(ActionRequestValue actionRequest) {
48  0 if (actionRequest.getActionRequestId() == null) {
49  0 loadDefaultValues(actionRequest);
50    }
51  0 if ( actionRequest.getAnnotation() != null && actionRequest.getAnnotation().length() > 2000 ) {
52  0 actionRequest.setAnnotation( StringUtils.abbreviate(actionRequest.getAnnotation(), 2000) );
53    }
54  0 this.getPersistenceBrokerTemplate().store(actionRequest);
55    }
56   
 
57  0 toggle public List findPendingByResponsibilityIds(Collection responsibilityIds) {
58  0 if (responsibilityIds == null || responsibilityIds.size() == 0) return Collections.emptyList();
59  0 Criteria crit = new Criteria();
60  0 Criteria statusCriteria = new Criteria();
61  0 Criteria activatedCriteria = new Criteria();
62  0 activatedCriteria.addEqualTo("status", KEWConstants.ACTION_REQUEST_ACTIVATED);
63   
64  0 Criteria initializedCriteria = new Criteria();
65  0 initializedCriteria.addEqualTo("status", KEWConstants.ACTION_REQUEST_INITIALIZED);
66   
67  0 statusCriteria.addOrCriteria(activatedCriteria);
68  0 statusCriteria.addOrCriteria(initializedCriteria);
69  0 crit.addAndCriteria(statusCriteria);
70  0 crit.addIn("responsibilityId", responsibilityIds);
71  0 return (List) this.getPersistenceBrokerTemplate().getCollectionByQuery(new QueryByCriteria(ActionRequestValue.class, crit));
72    }
73   
 
74  0 toggle public List findPendingByActionRequestedAndDocId(String actionRequestedCd, Long routeHeaderId) {
75  0 Criteria crit = new Criteria();
76  0 crit.addEqualTo("actionRequested", actionRequestedCd);
77  0 crit.addEqualTo("routeHeaderId", routeHeaderId);
78  0 crit.addEqualTo("currentIndicator", Boolean.TRUE);
79  0 crit.addAndCriteria(getPendingCriteria());
80  0 return (List) this.getPersistenceBrokerTemplate().getCollectionByQuery(new QueryByCriteria(ActionRequestValue.class, crit));
81    }
82   
 
83  0 toggle @SuppressWarnings("unchecked")
84    public List<ActionRequestValue> findByStatusAndDocId(String statusCd, Long routeHeaderId) {
85  0 Criteria crit = new Criteria();
86  0 crit.addEqualTo("status", statusCd);
87  0 crit.addEqualTo("routeHeaderId", routeHeaderId);
88  0 crit.addEqualTo("currentIndicator", true);
89   
90  0 return (List<ActionRequestValue>) this.getPersistenceBrokerTemplate().getCollectionByQuery(new QueryByCriteria(ActionRequestValue.class, crit));
91    }
92   
 
93  0 toggle private void loadDefaultValues(ActionRequestValue actionRequest) {
94  0 checkNull(actionRequest.getActionRequested(), "action requested");
95  0 checkNull(actionRequest.getResponsibilityId(), "responsibility ID");
96  0 checkNull(actionRequest.getRouteLevel(), "route level");
97  0 checkNull(actionRequest.getDocVersion(), "doc version");
98  0 if (actionRequest.getForceAction() == null) {
99  0 actionRequest.setForceAction(Boolean.FALSE);
100    }
101  0 if (actionRequest.getStatus() == null) {
102  0 actionRequest.setStatus(KEWConstants.ACTION_REQUEST_INITIALIZED);
103    }
104  0 if (actionRequest.getPriority() == null) {
105  0 actionRequest.setPriority(KEWConstants.ACTION_REQUEST_DEFAULT_PRIORITY);
106    }
107  0 if (actionRequest.getCurrentIndicator() == null) {
108  0 actionRequest.setCurrentIndicator(true);
109    }
110  0 actionRequest.setCreateDate(new Timestamp(System.currentTimeMillis()));
111    }
112   
113    //TODO Runtime might not be the right thing to do here...
 
114  0 toggle private void checkNull(Object value, String valueName) throws RuntimeException {
115  0 if (value == null) {
116  0 throw new RuntimeException("Null value for " + valueName);
117    }
118    }
119   
 
120  0 toggle public List findPendingRootRequestsByDocIdAtRouteLevel(Long routeHeaderId, Integer routeLevel) {
121  0 Criteria crit = new Criteria();
122  0 crit.addEqualTo("routeLevel", routeLevel);
123  0 crit.addNotEqualTo("status", KEWConstants.ACTION_REQUEST_DONE_STATE);
124  0 crit.addEqualTo("routeHeaderId", routeHeaderId);
125  0 crit.addEqualTo("currentIndicator", Boolean.TRUE);
126  0 crit.addIsNull("parentActionRequest");
127  0 return (List) this.getPersistenceBrokerTemplate().getCollectionByQuery(new QueryByCriteria(ActionRequestValue.class, crit));
128    }
129   
 
130  0 toggle public List findPendingByDocIdAtOrBelowRouteLevel(Long routeHeaderId, Integer routeLevel) {
131  0 Criteria crit = new Criteria();
132  0 crit.addLessOrEqualThan("routeLevel", routeLevel);
133  0 crit.addNotEqualTo("status", KEWConstants.ACTION_REQUEST_DONE_STATE);
134  0 crit.addEqualTo("routeHeaderId", routeHeaderId);
135  0 crit.addEqualTo("currentIndicator", true);
136  0 return (List) this.getPersistenceBrokerTemplate().getCollectionByQuery(new QueryByCriteria(ActionRequestValue.class, crit));
137    }
138   
 
139  0 toggle public List findPendingRootRequestsByDocIdAtOrBelowRouteLevel(Long routeHeaderId, Integer routeLevel) {
140  0 Criteria crit = new Criteria();
141  0 crit.addLessOrEqualThan("routeLevel", routeLevel);
142  0 crit.addNotEqualTo("status", KEWConstants.ACTION_REQUEST_DONE_STATE);
143  0 crit.addEqualTo("routeHeaderId", routeHeaderId);
144  0 crit.addEqualTo("currentIndicator", true);
145  0 crit.addIsNull("parentActionRequest");
146  0 return (List) this.getPersistenceBrokerTemplate().getCollectionByQuery(new QueryByCriteria(ActionRequestValue.class, crit));
147    }
148   
 
149  0 toggle public void delete(Long actionRequestId) {
150  0 Criteria crit = new Criteria();
151  0 crit.addEqualTo("actionRequestId", actionRequestId);
152  0 this.getPersistenceBrokerTemplate().deleteByQuery(new QueryByCriteria(ActionRequestValue.class, crit));
153    }
154   
 
155  0 toggle public List findAllPendingByDocId(Long routeHeaderId) {
156  0 Criteria initializedStatCriteria = new Criteria();
157  0 initializedStatCriteria.addEqualTo("status", KEWConstants.ACTION_REQUEST_INITIALIZED);
158   
159  0 Criteria activatedStatCriteria = new Criteria();
160  0 activatedStatCriteria.addEqualTo("status", KEWConstants.ACTION_REQUEST_ACTIVATED);
161   
162  0 Criteria statusCriteria = new Criteria();
163  0 statusCriteria.addOrCriteria(initializedStatCriteria);
164  0 statusCriteria.addOrCriteria(activatedStatCriteria);
165   
166  0 Criteria crit = new Criteria();
167  0 crit.addEqualTo("routeHeaderId", routeHeaderId);
168  0 crit.addEqualTo("currentIndicator", true);
169  0 crit.addAndCriteria(statusCriteria);
170   
171  0 return (List) this.getPersistenceBrokerTemplate().getCollectionByQuery(new QueryByCriteria(ActionRequestValue.class, crit));
172    }
173   
 
174  0 toggle public List findAllByDocId(Long routeHeaderId) {
175  0 Criteria crit = new Criteria();
176  0 crit.addEqualTo("routeHeaderId", routeHeaderId);
177  0 crit.addEqualTo("currentIndicator", true);
178  0 return (List) this.getPersistenceBrokerTemplate().getCollectionByQuery(new QueryByCriteria(ActionRequestValue.class, crit));
179    }
180   
 
181  0 toggle public List findAllRootByDocId(Long routeHeaderId) {
182  0 Criteria crit = new Criteria();
183  0 crit.addEqualTo("routeHeaderId", routeHeaderId);
184  0 crit.addEqualTo("currentIndicator", true);
185  0 crit.addIsNull("parentActionRequest");
186  0 return (List) this.getPersistenceBrokerTemplate().getCollectionByQuery(new QueryByCriteria(ActionRequestValue.class, crit));
187    }
188   
 
189  0 toggle public List findByRouteHeaderIdIgnoreCurrentInd(Long routeHeaderId) {
190  0 Criteria crit = new Criteria();
191  0 crit.addEqualTo("routeHeaderId", routeHeaderId);
192  0 return (List) this.getPersistenceBrokerTemplate().getCollectionByQuery(new QueryByCriteria(ActionRequestValue.class, crit));
193    }
194   
195   
 
196  0 toggle private Criteria getPendingCriteria() {
197  0 Criteria pendingCriteria = new Criteria();
198  0 Criteria activatedCriteria = new Criteria();
199  0 activatedCriteria.addEqualTo("status", KEWConstants.ACTION_REQUEST_ACTIVATED);
200  0 Criteria initializedCriteria = new Criteria();
201  0 initializedCriteria.addEqualTo("status", KEWConstants.ACTION_REQUEST_INITIALIZED);
202  0 pendingCriteria.addOrCriteria(activatedCriteria);
203  0 pendingCriteria.addOrCriteria(initializedCriteria);
204  0 return pendingCriteria;
205    }
206   
 
207  0 toggle public void deleteByRouteHeaderId(Long routeHeaderId){
208  0 Criteria crit = new Criteria();
209  0 crit.addEqualTo("routeHeaderId", routeHeaderId);
210  0 this.getPersistenceBrokerTemplate().deleteByQuery(new QueryByCriteria(ActionRequestValue.class, crit));
211    }
212   
 
213  0 toggle public List findPendingRootRequestsByDocumentType(Long documentTypeId) {
214  0 Criteria routeHeaderCrit = new Criteria();
215  0 routeHeaderCrit.addEqualTo("documentTypeId", documentTypeId);
216  0 Criteria crit = new Criteria();
217    //crit.addEqualTo("routeHeader.documentTypeId", documentTypeId);
218  0 crit.addIn("routeHeaderId", new ReportQueryByCriteria(DocumentRouteHeaderValue.class, new String[] {"routeHeaderId"}, routeHeaderCrit));
219  0 crit.addAndCriteria(getPendingCriteria());
220  0 crit.addEqualTo("currentIndicator", Boolean.TRUE);
221  0 crit.addIsNull("parentActionRequest");
222  0 return (List) this.getPersistenceBrokerTemplate().getCollectionByQuery(new QueryByCriteria(ActionRequestValue.class, crit));
223    }
224   
 
225  0 toggle public List findPendingRootRequestsByDocIdAtRouteNode(Long routeHeaderId, Long nodeInstanceId) {
226  0 Criteria crit = new Criteria();
227  0 crit.addEqualTo("routeHeaderId", routeHeaderId);
228  0 crit.addAndCriteria(getPendingCriteria());
229  0 crit.addEqualTo("currentIndicator", Boolean.TRUE);
230  0 crit.addIsNull("parentActionRequest");
231  0 crit.addEqualTo("nodeInstance.routeNodeInstanceId", nodeInstanceId);
232  0 return (List) this.getPersistenceBrokerTemplate().getCollectionByQuery(new QueryByCriteria(ActionRequestValue.class, crit));
233    }
234   
 
235  0 toggle public List findRootRequestsByDocIdAtRouteNode(Long documentId, Long nodeInstanceId) {
236  0 Criteria crit = new Criteria();
237  0 crit.addEqualTo("routeHeaderId", documentId);
238  0 crit.addEqualTo("currentIndicator", Boolean.TRUE);
239  0 crit.addIsNull("parentActionRequest");
240  0 crit.addEqualTo("nodeInstance.routeNodeInstanceId", nodeInstanceId);
241  0 return (List) this.getPersistenceBrokerTemplate().getCollectionByQuery(new QueryByCriteria(ActionRequestValue.class, crit));
242    }
243   
 
244  0 toggle public boolean doesDocumentHaveUserRequest(String principalId, Long documentId) {
245  0 Criteria crit = new Criteria();
246  0 crit.addEqualTo("routeHeaderId", documentId);
247  0 crit.addEqualTo("recipientTypeCd", KEWConstants.ACTION_REQUEST_USER_RECIPIENT_CD);
248  0 crit.addEqualTo("principalId", principalId);
249  0 crit.addEqualTo("currentIndicator", Boolean.TRUE);
250  0 int count = getPersistenceBrokerTemplate().getCount(new QueryByCriteria(ActionRequestValue.class, crit));
251  0 return count > 0;
252    }
253   
 
254  0 toggle public List<String> getRequestGroupIds(Long documentId) {
255  0 Criteria crit = new Criteria();
256  0 crit.addEqualTo("routeHeaderId", documentId);
257  0 crit.addEqualTo("recipientTypeCd", KEWConstants.ACTION_REQUEST_GROUP_RECIPIENT_CD);
258  0 crit.addEqualTo("currentIndicator", Boolean.TRUE);
259   
260  0 ReportQueryByCriteria query = QueryFactory.newReportQuery(ActionRequestValue.class, crit);
261  0 query.setAttributes(new String[] { "groupId" });
262   
263  0 List<String> groupIds = new ArrayList<String>();
264  0 Iterator iter = getPersistenceBrokerTemplate().getReportQueryIteratorByQuery(query);
265  0 while (iter.hasNext()) {
266  0 Object[] row = (Object[]) iter.next();
267  0 String id = (String)row[0];
268  0 groupIds.add(id);
269    }
270  0 return groupIds;
271    }
272   
273    /**
274    * @see org.kuali.rice.kew.actionrequest.dao.ActionRequestDAO#findActivatedByGroup(String)
275    */
 
276  0 toggle public List findActivatedByGroup(String groupId) {
277  0 Criteria statusCriteria = new Criteria();
278  0 statusCriteria.addEqualTo("status", KEWConstants.ACTION_REQUEST_ACTIVATED);
279  0 Criteria crit = new Criteria();
280  0 crit.addEqualTo("groupId", groupId);
281  0 crit.addEqualTo("currentIndicator", true);
282  0 crit.addAndCriteria(statusCriteria);
283   
284  0 return (List) this.getPersistenceBrokerTemplate().getCollectionByQuery(new QueryByCriteria(ActionRequestValue.class, crit));
285    }
286    }