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
101   246   34   5.61
28   186   0.34   18
18     1.89  
1    
 
  ActionItemDAOJpaImpl       Line # 47 101 0% 34 147 0% 0.0
 
No Tests
 
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.actionitem.dao.impl;
15   
16    import java.sql.Timestamp;
17    import java.util.ArrayList;
18    import java.util.Collection;
19    import java.util.Date;
20    import java.util.HashMap;
21    import java.util.Iterator;
22    import java.util.List;
23    import java.util.Map;
24   
25    import javax.persistence.EntityManager;
26    import javax.persistence.PersistenceContext;
27   
28    import org.apache.commons.collections.CollectionUtils;
29    import org.kuali.rice.core.framework.persistence.jpa.criteria.Criteria;
30    import org.kuali.rice.core.framework.persistence.jpa.criteria.QueryByCriteria;
31    import org.kuali.rice.core.framework.persistence.jpa.OrmUtils;
32    import org.kuali.rice.kew.actionitem.ActionItem;
33    import org.kuali.rice.kew.actionitem.OutboxItemActionListExtension;
34    import org.kuali.rice.kew.actionitem.dao.ActionItemDAO;
35    import org.kuali.rice.kew.actionrequest.KimGroupRecipient;
36    import org.kuali.rice.kew.actionrequest.Recipient;
37    import org.kuali.rice.kew.util.KEWConstants;
38    import org.kuali.rice.kew.util.WebFriendlyRecipient;
39    import org.kuali.rice.kim.service.IdentityManagementService;
40    import org.kuali.rice.kim.service.KIMServiceLocator;
41   
42    /**
43    * OJB implementation of {@link ActionItemDAO}.
44    *
45    * @author Kuali Rice Team (rice.collab@kuali.org)
46    */
 
47    public class ActionItemDAOJpaImpl implements ActionItemDAO {
48    @PersistenceContext(unitName="kew-unit")
49    private EntityManager entityManager;
50   
 
51  0 toggle public ActionItem findByActionItemId(Long actionItemId) {
52  0 return entityManager.find(ActionItem.class, actionItemId);
53    }
54   
 
55  0 toggle public void deleteActionItems(Long actionRequestId) {
56  0 Criteria crit = new Criteria(ActionItem.class.getName());
57  0 crit.eq("actionRequestId", actionRequestId);
58  0 for(Object actionItem:new QueryByCriteria(entityManager,crit).toQuery().getResultList()){
59  0 if( ! (actionItem instanceof OutboxItemActionListExtension)) {
60  0 entityManager.remove(actionItem);
61    }
62    }
63   
64    }
65   
 
66  0 toggle public void deleteActionItem(ActionItem actionItem) {
67  0 entityManager.remove(findByActionItemId(actionItem.getActionItemId()));
68    }
69   
 
70  0 toggle public void deleteByRouteHeaderIdWorkflowUserId(Long routeHeaderId, String workflowUserId) {
71  0 Criteria crit = new Criteria(ActionItem.class.getName());
72  0 crit.eq("routeHeaderId", routeHeaderId);
73  0 crit.eq("principalId", workflowUserId);
74  0 for(Object actionItem: new QueryByCriteria(entityManager,crit).toQuery().getResultList()){
75  0 if( ! (actionItem instanceof OutboxItemActionListExtension)) {
76  0 entityManager.remove(actionItem);
77    }
78    }
79    }
80   
 
81  0 toggle public void deleteByRouteHeaderId(Long routeHeaderId) {
82  0 Criteria crit = new Criteria(ActionItem.class.getName());
83  0 crit.eq("routeHeaderId", routeHeaderId);
84  0 for(Object actionItem: new QueryByCriteria(entityManager,crit).toQuery().getResultList()){
85  0 if( ! (actionItem instanceof OutboxItemActionListExtension)) {
86  0 entityManager.remove(actionItem);
87    }
88    }
89    }
90   
91    /**
92    * This method replaces findByWorkflowUser
93    *
94    * @see org.kuali.rice.kew.actionitem.dao.ActionItemDAO#findByPrincipalId(java.lang.String)
95    */
 
96  0 toggle public Collection<ActionItem> findByPrincipalId(String principalId) {
97  0 Criteria crit = new Criteria(ActionItem.class.getName());
98  0 crit.eq("principalId", principalId);
99  0 crit.orderBy("routeHeaderId", true);
100  0 List<ActionItem> results = new QueryByCriteria(entityManager, crit).toQuery().getResultList();
101   
102  0 return removeOutBoxItems(results);
103    }
104   
 
105  0 toggle public Collection<ActionItem> findByWorkflowUserRouteHeaderId(String workflowId, Long routeHeaderId) {
106  0 Criteria crit = new Criteria(ActionItem.class.getName());
107  0 crit.eq("principalId", workflowId);
108  0 crit.eq("routeHeaderId", routeHeaderId);
109  0 List<ActionItem> results = new QueryByCriteria(entityManager, crit).toQuery().getResultList();
110   
111  0 return removeOutBoxItems(results);
112    }
113   
 
114  0 toggle public Collection<ActionItem> findByDocumentTypeName(String documentTypeName) {
115  0 Criteria crit = new Criteria(ActionItem.class.getName());
116  0 crit.eq("docName", documentTypeName);
117  0 List<ActionItem> results = new QueryByCriteria(entityManager, crit).toQuery().getResultList();
118   
119  0 return removeOutBoxItems(results);
120    }
121   
 
122  0 toggle public Collection<ActionItem> getOutboxItemsByDocumentType(String documentTypeName) {
123  0 Criteria crit = new Criteria(ActionItem.class.getName());
124  0 crit.eq("docName", documentTypeName);
125  0 List<ActionItem> results = new QueryByCriteria(entityManager, crit).toQuery().getResultList();
126  0 Iterator<ActionItem> iterator = results.iterator();
127  0 while (iterator.hasNext()) {
128  0 if (!(iterator.next() instanceof OutboxItemActionListExtension)) {
129  0 iterator.remove();
130    }
131    }
132  0 return results;
133    }
134   
 
135  0 toggle public Collection<ActionItem> findByRouteHeaderId(Long routeHeaderId) {
136  0 Criteria crit = new Criteria(ActionItem.class.getName());
137  0 crit.eq("routeHeaderId", routeHeaderId);
138  0 List<ActionItem> results = new QueryByCriteria(entityManager, crit).toQuery().getResultList();
139   
140  0 return removeOutBoxItems(results);
141    }
142   
 
143  0 toggle public Collection<ActionItem> findByActionRequestId(Long actionRequestId) {
144  0 Criteria crit = new Criteria(ActionItem.class.getName());
145  0 crit.eq("actionRequestId", actionRequestId);
146  0 List<ActionItem> results = new QueryByCriteria(entityManager, crit).toQuery().getResultList();
147   
148  0 return removeOutBoxItems(results);
149    }
150   
 
151  0 toggle public void saveActionItem(ActionItem actionItem) {
152  0 if (actionItem.getDateAssigned() == null) {
153  0 actionItem.setDateAssigned(new Timestamp(new Date().getTime()));
154    }
155   
156  0 if(actionItem.getActionItemId()==null){
157  0 entityManager.persist(actionItem);
158    }else{
159  0 OrmUtils.merge(entityManager, actionItem);
160    }
161    }
162   
 
163  0 toggle public Collection<Recipient> findSecondaryDelegators(String principalId) {
164  0 Criteria notNullWorkflowCriteria = new Criteria(ActionItem.class.getName());
165  0 notNullWorkflowCriteria.notNull("delegatorWorkflowId");
166  0 Criteria notNullWorkgroupCriteria = new Criteria(ActionItem.class.getName());
167  0 notNullWorkgroupCriteria.notNull("delegatorGroupId");
168  0 Criteria orCriteria = new Criteria(ActionItem.class.getName());
169  0 orCriteria.or(notNullWorkflowCriteria);
170  0 orCriteria.or(notNullWorkgroupCriteria);
171  0 Criteria criteria = new Criteria(ActionItem.class.getName());
172  0 criteria.eq("principalId", principalId);
173  0 criteria.eq("delegationType", KEWConstants.DELEGATION_SECONDARY);
174  0 criteria.and(orCriteria);
175   
176  0 Map<Object, Recipient> delegators = new HashMap<Object, Recipient>();
177   
178  0 for(Object actionItem:new QueryByCriteria(entityManager, criteria).toQuery().getResultList()){
179  0 final String delegatorWorkflowId = ((ActionItem)actionItem).getDelegatorWorkflowId();
180  0 String delegatorGroupId = ((ActionItem)actionItem).getDelegatorGroupId();
181   
182  0 if (delegatorWorkflowId != null && !delegators.containsKey(delegatorWorkflowId)) {
183  0 delegators.put(delegatorWorkflowId,new WebFriendlyRecipient(KIMServiceLocator.getPersonService().getPerson(delegatorWorkflowId)));
184  0 }else if (delegatorGroupId != null) {
185  0 if (!delegators.containsKey(delegatorGroupId)) {
186  0 delegators.put(delegatorGroupId, new KimGroupRecipient(getIdentityManagementService().getGroup(delegatorGroupId)));
187    }
188    }
189    }
190  0 return delegators.values();
191    }
192   
 
193  0 toggle public Collection<Recipient> findPrimaryDelegationRecipients(String principalId) {
194  0 List<String> workgroupIds = KIMServiceLocator.getIdentityManagementService().getGroupIdsForPrincipal(principalId);
195  0 Criteria orCriteria = new Criteria(ActionItem.class.getName());
196  0 Criteria delegatorWorkflowIdCriteria = new Criteria(ActionItem.class.getName());
197  0 delegatorWorkflowIdCriteria.eq("delegatorWorkflowId", principalId);
198  0 if (CollectionUtils.isNotEmpty(workgroupIds)) {
199  0 Criteria delegatorWorkgroupCriteria = new Criteria(ActionItem.class.getName());
200  0 delegatorWorkgroupCriteria.in("delegatorGroupId", new ArrayList<String>(workgroupIds));
201  0 orCriteria.or(delegatorWorkgroupCriteria);
202  0 orCriteria.or(delegatorWorkflowIdCriteria);
203    }
204    else {
205  0 orCriteria.and(delegatorWorkflowIdCriteria);
206    }
207  0 Criteria criteria = new Criteria(ActionItem.class.getName());
208  0 criteria.eq("delegationType", KEWConstants.DELEGATION_PRIMARY);
209  0 criteria.and(orCriteria);
210   
211  0 Map<Object, Recipient> delegators = new HashMap<Object, Recipient>();
212  0 for(Object actionItem:new QueryByCriteria(entityManager, criteria).toQuery().getResultList()){
213  0 String princlId = ((ActionItem)actionItem).getPrincipalId();
214  0 if (princlId != null && !delegators.containsKey(princlId)) {
215  0 delegators.put(princlId, new WebFriendlyRecipient(KIMServiceLocator.getPersonService().getPerson(princlId)));
216    }
217    }
218   
219  0 return delegators.values();
220    }
221   
 
222  0 toggle private List<ActionItem> removeOutBoxItems(List<ActionItem> results) {
223  0 Iterator<ActionItem> iterator = results.iterator();
224  0 while(iterator.hasNext()) {
225  0 if(iterator.next() instanceof OutboxItemActionListExtension) {
226  0 iterator.remove();
227    }
228    }
229   
230  0 return results;
231    }
232   
 
233  0 toggle private IdentityManagementService getIdentityManagementService() {
234  0 return KIMServiceLocator.getIdentityManagementService();
235    }
236   
 
237  0 toggle public EntityManager getEntityManager() {
238  0 return this.entityManager;
239    }
240   
 
241  0 toggle public void setEntityManager(EntityManager entityManager) {
242  0 this.entityManager = entityManager;
243    }
244   
245   
246    }