1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
package org.kuali.rice.kew.actionlist.service.impl; |
18 | |
|
19 | |
import org.apache.commons.lang.StringUtils; |
20 | |
import org.kuali.rice.core.api.config.property.ConfigContext; |
21 | |
import org.kuali.rice.kew.actionitem.ActionItem; |
22 | |
import org.kuali.rice.kew.actionitem.OutboxItemActionListExtension; |
23 | |
import org.kuali.rice.kew.actionitem.dao.ActionItemDAO; |
24 | |
import org.kuali.rice.kew.actionlist.ActionListFilter; |
25 | |
import org.kuali.rice.kew.actionlist.dao.ActionListDAO; |
26 | |
import org.kuali.rice.kew.actionlist.service.ActionListService; |
27 | |
import org.kuali.rice.kew.actionrequest.ActionRequestValue; |
28 | |
import org.kuali.rice.kew.actionrequest.Recipient; |
29 | |
import org.kuali.rice.kew.actionrequest.service.ActionRequestService; |
30 | |
import org.kuali.rice.kew.actiontaken.ActionTakenValue; |
31 | |
import org.kuali.rice.kew.doctype.bo.DocumentType; |
32 | |
import org.kuali.rice.kew.exception.WorkflowServiceErrorException; |
33 | |
import org.kuali.rice.kew.exception.WorkflowServiceErrorImpl; |
34 | |
import org.kuali.rice.kew.routeheader.DocumentRouteHeaderValue; |
35 | |
import org.kuali.rice.kew.service.KEWServiceLocator; |
36 | |
import org.kuali.rice.kew.useroptions.UserOptions; |
37 | |
import org.kuali.rice.kew.useroptions.UserOptionsService; |
38 | |
import org.kuali.rice.kew.util.KEWConstants; |
39 | |
import org.kuali.rice.kim.api.entity.principal.Principal; |
40 | |
import org.kuali.rice.kim.api.services.KimApiServiceLocator; |
41 | |
|
42 | |
import org.kuali.rice.kim.api.group.GroupService; |
43 | |
|
44 | |
import java.sql.Timestamp; |
45 | |
import java.util.ArrayList; |
46 | |
import java.util.Collection; |
47 | |
import java.util.Date; |
48 | |
import java.util.Iterator; |
49 | |
import java.util.List; |
50 | |
|
51 | |
|
52 | |
|
53 | |
|
54 | |
|
55 | |
|
56 | 0 | public class ActionListServiceImpl implements ActionListService { |
57 | |
|
58 | 0 | protected final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(getClass()); |
59 | |
|
60 | |
private ActionListDAO actionListDAO; |
61 | |
|
62 | |
private ActionItemDAO actionItemDAO; |
63 | |
|
64 | |
public Collection<Recipient> findUserSecondaryDelegators(String principalId) { |
65 | 0 | return getActionItemDAO().findSecondaryDelegators(principalId); |
66 | |
} |
67 | |
|
68 | |
public Collection<Recipient> findUserPrimaryDelegations(String principalId) { |
69 | 0 | return getActionItemDAO().findPrimaryDelegationRecipients(principalId); |
70 | |
} |
71 | |
|
72 | |
public Collection<ActionItem> getActionList(String principalId, ActionListFilter filter) { |
73 | 0 | return getActionListDAO().getActionList(principalId, filter); |
74 | |
} |
75 | |
|
76 | |
public Collection<ActionItem> getActionListForSingleDocument(String documentId) { |
77 | 0 | return getActionListDAO().getActionListForSingleDocument(documentId); |
78 | |
} |
79 | |
|
80 | |
public void setActionListDAO(ActionListDAO actionListDAO) { |
81 | 0 | this.actionListDAO = actionListDAO; |
82 | 0 | } |
83 | |
|
84 | |
public ActionListDAO getActionListDAO() { |
85 | 0 | return actionListDAO; |
86 | |
} |
87 | |
|
88 | |
public boolean refreshActionList(String principalId) { |
89 | 0 | return KEWServiceLocator.getUserOptionsService().refreshActionList(principalId); |
90 | |
} |
91 | |
|
92 | |
public void deleteActionItem(ActionItem actionItem) { |
93 | 0 | deleteActionItem(actionItem, false); |
94 | 0 | } |
95 | |
|
96 | |
public void deleteActionItem(ActionItem actionItem, boolean forceIntoOutbox) { |
97 | |
try { |
98 | 0 | KEWServiceLocator.getUserOptionsService().saveRefreshUserOption(actionItem.getPrincipalId()); |
99 | 0 | } catch (Exception e) { |
100 | 0 | LOG.error("error saving refreshUserOption", e); |
101 | 0 | } |
102 | 0 | getActionItemDAO().deleteActionItem(actionItem); |
103 | |
|
104 | 0 | List<ActionItem> l = new ArrayList<ActionItem>(1); |
105 | 0 | l.add(actionItem); |
106 | 0 | KEWServiceLocator.getNotificationService().removeNotification(l); |
107 | 0 | this.saveOutboxItem(actionItem, forceIntoOutbox); |
108 | 0 | } |
109 | |
|
110 | |
public void deleteByDocumentId(String documentId) { |
111 | 0 | Collection<ActionItem> actionItems = findByDocumentId(documentId); |
112 | 0 | for (Iterator<ActionItem> iter = actionItems.iterator(); iter.hasNext();) { |
113 | 0 | ActionItem actionItem = iter.next(); |
114 | |
try { |
115 | 0 | KEWServiceLocator.getUserOptionsService().saveRefreshUserOption(actionItem.getPrincipalId()); |
116 | 0 | } catch (Exception e) { |
117 | 0 | LOG.error("error saving refreshUserOption", e); |
118 | 0 | } |
119 | 0 | } |
120 | 0 | getActionItemDAO().deleteByDocumentId(documentId); |
121 | 0 | } |
122 | |
|
123 | |
public Collection<ActionItem> findByDocumentId(String documentId) { |
124 | 0 | return getActionItemDAO().findByDocumentId(documentId); |
125 | |
} |
126 | |
|
127 | |
public Collection<ActionItem> findByActionRequestId(Long actionRequestId) { |
128 | 0 | return getActionItemDAO().findByActionRequestId(actionRequestId); |
129 | |
} |
130 | |
|
131 | |
public Collection<ActionItem> findByWorkflowUserDocumentId(String workflowUserId, String documentId) { |
132 | 0 | return getActionItemDAO().findByWorkflowUserDocumentId(workflowUserId, documentId); |
133 | |
} |
134 | |
|
135 | |
public Collection<ActionItem> findByDocumentTypeName(String documentTypeName) { |
136 | 0 | return getActionItemDAO().findByDocumentTypeName(documentTypeName); |
137 | |
} |
138 | |
|
139 | |
public ActionItem createActionItemForActionRequest(ActionRequestValue actionRequest) { |
140 | 0 | ActionItem actionItem = new ActionItem(); |
141 | |
|
142 | 0 | DocumentRouteHeaderValue routeHeader = actionRequest.getRouteHeader(); |
143 | 0 | DocumentType docType = routeHeader.getDocumentType(); |
144 | |
|
145 | 0 | actionItem.setActionRequestCd(actionRequest.getActionRequested()); |
146 | 0 | actionItem.setActionRequestId(actionRequest.getActionRequestId()); |
147 | 0 | actionItem.setDocName(docType.getName()); |
148 | 0 | actionItem.setRoleName(actionRequest.getQualifiedRoleName()); |
149 | 0 | actionItem.setPrincipalId(actionRequest.getPrincipalId()); |
150 | 0 | actionItem.setDocumentId(actionRequest.getDocumentId()); |
151 | 0 | actionItem.setDateAssigned(new Timestamp(new Date().getTime())); |
152 | 0 | actionItem.setDocHandlerURL(docType.getDocHandlerUrl()); |
153 | 0 | actionItem.setDocLabel(docType.getLabel()); |
154 | 0 | actionItem.setDocTitle(routeHeader.getDocTitle()); |
155 | 0 | actionItem.setGroupId(actionRequest.getGroupId()); |
156 | 0 | actionItem.setResponsibilityId(actionRequest.getResponsibilityId()); |
157 | 0 | actionItem.setDelegationType(actionRequest.getDelegationType()); |
158 | 0 | actionItem.setRequestLabel(actionRequest.getRequestLabel()); |
159 | |
|
160 | 0 | ActionRequestValue delegatorActionRequest = getActionRequestService().findDelegatorRequest(actionRequest); |
161 | 0 | if (delegatorActionRequest != null) { |
162 | 0 | actionItem.setDelegatorWorkflowId(delegatorActionRequest.getPrincipalId()); |
163 | 0 | actionItem.setDelegatorGroupId(delegatorActionRequest.getGroupId()); |
164 | |
} |
165 | |
|
166 | 0 | return actionItem; |
167 | |
} |
168 | |
|
169 | |
|
170 | |
public void updateActionItemsForTitleChange(String documentId, String newTitle) { |
171 | 0 | Collection<ActionItem> items = getActionItemDAO().findByDocumentId(documentId); |
172 | 0 | for (Iterator<ActionItem> iterator = items.iterator(); iterator.hasNext();) { |
173 | 0 | ActionItem item = iterator.next(); |
174 | 0 | item.setDocTitle(newTitle); |
175 | 0 | saveActionItem(item); |
176 | 0 | } |
177 | 0 | } |
178 | |
|
179 | |
public void saveActionItem(ActionItem actionItem) { |
180 | 0 | KEWServiceLocator.getUserOptionsService().saveRefreshUserOption(actionItem.getPrincipalId()); |
181 | 0 | getActionItemDAO().saveActionItem(actionItem); |
182 | 0 | } |
183 | |
|
184 | |
public ActionItemDAO getActionItemDAO() { |
185 | 0 | return actionItemDAO; |
186 | |
} |
187 | |
|
188 | |
public ActionRequestService getActionRequestService() { |
189 | 0 | return (ActionRequestService) KEWServiceLocator.getActionRequestService(); |
190 | |
} |
191 | |
|
192 | |
public GroupService getGroupService(){ |
193 | 0 | return KimApiServiceLocator.getGroupService(); |
194 | |
} |
195 | |
|
196 | |
public void setActionItemDAO(ActionItemDAO actionItemDAO) { |
197 | 0 | this.actionItemDAO = actionItemDAO; |
198 | 0 | } |
199 | |
|
200 | |
|
201 | |
public void validateActionItem(ActionItem actionItem) { |
202 | 0 | List<WorkflowServiceErrorImpl> errors = new ArrayList<WorkflowServiceErrorImpl>(); |
203 | 0 | String principalId = actionItem.getPrincipalId(); |
204 | 0 | if (principalId == null || principalId.trim().equals("")) { |
205 | 0 | errors.add(new WorkflowServiceErrorImpl("ActionItem person null.", "actionitem.personid.empty", actionItem |
206 | |
.getActionItemId().toString())); |
207 | |
} else { |
208 | 0 | Principal principal = KimApiServiceLocator.getIdentityManagementService().getPrincipal(principalId); |
209 | 0 | if (principal == null) { |
210 | 0 | errors.add(new WorkflowServiceErrorImpl("ActionItem person invalid.", "actionitem.personid.invalid", |
211 | |
actionItem.getActionItemId().toString())); |
212 | |
} |
213 | |
} |
214 | |
|
215 | 0 | if (actionItem.getDateAssigned() == null) { |
216 | 0 | errors.add(new WorkflowServiceErrorImpl("ActionItem date assigned empty.", "actionitem.dateassigned.empty", |
217 | |
actionItem.getActionItemId().toString())); |
218 | |
} |
219 | |
|
220 | 0 | String actionRequestCd = actionItem.getActionRequestCd(); |
221 | 0 | if (actionRequestCd == null || actionRequestCd.trim().equals("")) { |
222 | 0 | errors.add(new WorkflowServiceErrorImpl("ActionItem action request cd empty.", |
223 | |
"actionitem.actionrequestcd.empty", actionItem.getActionItemId().toString())); |
224 | 0 | } else if (!KEWConstants.ACTION_REQUEST_CD.containsKey(actionRequestCd)) { |
225 | 0 | errors.add(new WorkflowServiceErrorImpl("ActionItem action request cd invalid.", |
226 | |
"actionitem.actionrequestcd.invalid", actionItem.getActionItemId().toString())); |
227 | |
} |
228 | |
|
229 | 0 | if (actionItem.getActionRequestId() == null) { |
230 | 0 | errors.add(new WorkflowServiceErrorImpl("ActionItem action request id empty.", |
231 | |
"actionitem.actionrequestid.empty", actionItem.getActionItemId().toString())); |
232 | |
} |
233 | |
|
234 | 0 | if (actionItem.getDocumentId() == null) { |
235 | 0 | errors.add(new WorkflowServiceErrorImpl("ActionItem Document id empty.", "actionitem.documentid.empty", |
236 | |
actionItem.getActionItemId().toString())); |
237 | 0 | } else if (KEWServiceLocator.getRouteHeaderService().getRouteHeader(actionItem.getDocumentId()) == null) { |
238 | 0 | errors.add(new WorkflowServiceErrorImpl("ActionItem Document id invalid.", "actionitem.documentid.invalid", |
239 | |
actionItem.getActionItemId().toString())); |
240 | |
} |
241 | |
|
242 | 0 | String docTypeName = actionItem.getDocName(); |
243 | 0 | DocumentType docType = null; |
244 | 0 | if (docTypeName == null || docTypeName.trim().equals("")) { |
245 | 0 | errors.add(new WorkflowServiceErrorImpl("ActionItem doctypename empty.", "actionitem.doctypename.empty", |
246 | |
actionItem.getActionItemId().toString())); |
247 | |
} else { |
248 | 0 | docType = KEWServiceLocator.getDocumentTypeService().findByName(actionItem.getDocName()); |
249 | 0 | if (docType == null) { |
250 | 0 | errors.add(new WorkflowServiceErrorImpl("ActionItem doctypename invalid.", "actionitem.doctypename.invalid", |
251 | |
actionItem.getActionItemId().toString())); |
252 | |
} |
253 | |
} |
254 | |
|
255 | 0 | if (actionItem.getDocLabel() == null || actionItem.getDocLabel().trim().equals("")) { |
256 | 0 | errors.add(new WorkflowServiceErrorImpl("ActionItem doctypelabel empty.", "actionitem.doctypelabel.empty", |
257 | |
actionItem.getActionItemId().toString())); |
258 | 0 | } else if (docType != null && !docType.getLabel().equals(actionItem.getDocLabel())) { |
259 | 0 | errors.add(new WorkflowServiceErrorImpl("ActionItem doctypelabel no match.", "actionitem.doctypelabel.nomatch", |
260 | |
actionItem.getActionItemId().toString())); |
261 | |
} |
262 | |
|
263 | |
|
264 | 0 | if (StringUtils.isNotBlank(docType.getDocHandlerUrl())) { |
265 | 0 | if (actionItem.getDocHandlerURL() == null || actionItem.getDocHandlerURL().trim().equals("")) { |
266 | 0 | errors.add(new WorkflowServiceErrorImpl("ActionItem doc handler url empty.", "actionitem.dochdrurl.empty", |
267 | |
actionItem.getActionItemId().toString())); |
268 | 0 | } else if (docType != null && !docType.getDocHandlerUrl().equals(actionItem.getDocHandlerURL())) { |
269 | 0 | errors.add(new WorkflowServiceErrorImpl("ActionItem doc handler url no match.", "actionitem.dochdrurl.nomatch", |
270 | |
actionItem.getActionItemId().toString())); |
271 | |
} |
272 | |
} else { |
273 | |
|
274 | 0 | if (StringUtils.isNotBlank(actionItem.getDocHandlerURL())) { |
275 | 0 | errors.add(new WorkflowServiceErrorImpl("ActionItem doc handler url not empty.", "actionitem.dochdrurl.not.empty", |
276 | |
actionItem.getActionItemId().toString())); |
277 | |
} |
278 | |
} |
279 | |
|
280 | 0 | if (!errors.isEmpty()) { |
281 | 0 | throw new WorkflowServiceErrorException("ActionItem Validation Error", errors); |
282 | |
} |
283 | 0 | } |
284 | |
|
285 | |
public ActionItem findByActionItemId(Long actionItemId) { |
286 | 0 | return getActionItemDAO().findByActionItemId(actionItemId); |
287 | |
} |
288 | |
|
289 | |
public int getCount(String principalId) { |
290 | 0 | return getActionListDAO().getCount(principalId); |
291 | |
} |
292 | |
|
293 | |
public void saveRefreshUserOption(String principalId) { |
294 | 0 | KEWServiceLocator.getUserOptionsService().saveRefreshUserOption(principalId); |
295 | 0 | } |
296 | |
|
297 | |
|
298 | |
|
299 | |
|
300 | |
|
301 | |
|
302 | |
|
303 | |
public Collection<ActionItem> getOutbox(String principalId, ActionListFilter filter) { |
304 | 0 | return this.getActionListDAO().getOutbox(principalId, filter); |
305 | |
} |
306 | |
|
307 | |
public Collection<ActionItem> getOutboxItemsByDocumentType(String documentTypeName) { |
308 | 0 | return this.getActionItemDAO().getOutboxItemsByDocumentType(documentTypeName); |
309 | |
} |
310 | |
|
311 | |
|
312 | |
|
313 | |
|
314 | |
|
315 | |
|
316 | |
public void removeOutboxItems(String principalId, List<String> outboxItems) { |
317 | 0 | this.getActionListDAO().removeOutboxItems(principalId, outboxItems); |
318 | 0 | } |
319 | |
|
320 | |
public void saveOutboxItem(ActionItem actionItem) { |
321 | 0 | saveOutboxItem(actionItem, false); |
322 | 0 | } |
323 | |
|
324 | |
|
325 | |
|
326 | |
|
327 | |
|
328 | |
|
329 | |
|
330 | |
public void saveOutboxItem(ActionItem actionItem, boolean forceIntoOutbox) { |
331 | 0 | UserOptionsService userOptionsService = KEWServiceLocator.getUserOptionsService(); |
332 | 0 | Boolean isUsingOutBox = true; |
333 | 0 | List<UserOptions> options = userOptionsService.findByUserQualified(actionItem.getPrincipalId(), KEWConstants.USE_OUT_BOX); |
334 | 0 | if (options == null || options.isEmpty()){ |
335 | 0 | isUsingOutBox = true; |
336 | |
} else { |
337 | 0 | for (Iterator iter = options.iterator(); iter.hasNext();) { |
338 | 0 | UserOptions u = (UserOptions) iter.next(); |
339 | 0 | if (u.getOptionVal() == null || !(u.getOptionVal().equals("yes"))){ |
340 | 0 | isUsingOutBox = false; |
341 | |
} |
342 | 0 | } |
343 | |
} |
344 | |
|
345 | 0 | if (isUsingOutBox |
346 | |
&& ConfigContext.getCurrentContextConfig().getOutBoxOn() |
347 | |
&& getActionListDAO().getOutboxByDocumentIdUserId(actionItem.getDocumentId(), actionItem.getPrincipalId()) == null |
348 | |
&& !KEWServiceLocator.getRouteHeaderService().getRouteHeader(actionItem.getDocumentId()).getDocRouteStatus().equals( |
349 | |
KEWConstants.ROUTE_HEADER_SAVED_CD)) { |
350 | |
|
351 | |
|
352 | 0 | ActionRequestValue actionRequest = KEWServiceLocator.getActionRequestService().findByActionRequestId( |
353 | |
actionItem.getActionRequestId()); |
354 | 0 | ActionTakenValue actionTaken = actionRequest.getActionTaken(); |
355 | |
|
356 | 0 | if (forceIntoOutbox || (actionTaken != null && actionTaken.getPrincipalId().equals(actionItem.getPrincipalId()))) { |
357 | 0 | this.getActionListDAO().saveOutboxItem(new OutboxItemActionListExtension(actionItem)); |
358 | |
} |
359 | |
|
360 | |
} |
361 | 0 | } |
362 | |
|
363 | |
public Collection<ActionItem> findByPrincipalId(String principalId) { |
364 | 0 | return getActionItemDAO().findByPrincipalId(principalId); |
365 | |
} |
366 | |
|
367 | |
} |