1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
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 |
|
@link |
44 |
|
|
45 |
|
@author |
46 |
|
|
|
|
| 0% |
Uncovered Elements: 147 (147) |
Complexity: 34 |
Complexity Density: 0.34 |
|
47 |
|
public class ActionItemDAOJpaImpl implements ActionItemDAO { |
48 |
|
@PersistenceContext(unitName="kew-unit") |
49 |
|
private EntityManager entityManager; |
50 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
51 |
0
|
public ActionItem findByActionItemId(Long actionItemId) {... |
52 |
0
|
return entityManager.find(ActionItem.class, actionItemId); |
53 |
|
} |
54 |
|
|
|
|
| 0% |
Uncovered Elements: 7 (7) |
Complexity: 2 |
Complexity Density: 0.4 |
|
55 |
0
|
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 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
66 |
0
|
public void deleteActionItem(ActionItem actionItem) {... |
67 |
0
|
entityManager.remove(findByActionItemId(actionItem.getActionItemId())); |
68 |
|
} |
69 |
|
|
|
|
| 0% |
Uncovered Elements: 8 (8) |
Complexity: 2 |
Complexity Density: 0.33 |
|
70 |
0
|
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 |
|
|
|
|
| 0% |
Uncovered Elements: 7 (7) |
Complexity: 2 |
Complexity Density: 0.4 |
|
81 |
0
|
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 |
|
|
93 |
|
|
94 |
|
@see |
95 |
|
|
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
|
96 |
0
|
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 |
|
|
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
|
105 |
0
|
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 |
|
|
|
|
| 0% |
Uncovered Elements: 4 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
|
114 |
0
|
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 |
|
|
|
|
| 0% |
Uncovered Elements: 12 (12) |
Complexity: 3 |
Complexity Density: 0.38 |
|
122 |
0
|
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 |
|
|
|
|
| 0% |
Uncovered Elements: 4 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
|
135 |
0
|
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 |
|
|
|
|
| 0% |
Uncovered Elements: 4 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
|
143 |
0
|
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 |
|
|
|
|
| 0% |
Uncovered Elements: 9 (9) |
Complexity: 3 |
Complexity Density: 0.6 |
|
151 |
0
|
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 |
|
|
|
|
| 0% |
Uncovered Elements: 27 (27) |
Complexity: 5 |
Complexity Density: 0.24 |
|
163 |
0
|
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 |
|
|
|
|
| 0% |
Uncovered Elements: 23 (23) |
Complexity: 4 |
Complexity Density: 0.21 |
|
193 |
0
|
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 |
|
|
|
|
| 0% |
Uncovered Elements: 9 (9) |
Complexity: 3 |
Complexity Density: 0.6 |
|
222 |
0
|
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 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
233 |
0
|
private IdentityManagementService getIdentityManagementService() {... |
234 |
0
|
return KIMServiceLocator.getIdentityManagementService(); |
235 |
|
} |
236 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
237 |
0
|
public EntityManager getEntityManager() {... |
238 |
0
|
return this.entityManager; |
239 |
|
} |
240 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
241 |
0
|
public void setEntityManager(EntityManager entityManager) {... |
242 |
0
|
this.entityManager = entityManager; |
243 |
|
} |
244 |
|
|
245 |
|
|
246 |
|
} |