1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
package org.kuali.rice.kew.actiontaken.service.impl; |
18 | |
|
19 | |
import org.apache.commons.lang.StringUtils; |
20 | |
import org.kuali.rice.kew.actionrequest.ActionRequestValue; |
21 | |
import org.kuali.rice.kew.actiontaken.ActionTakenValue; |
22 | |
import org.kuali.rice.kew.actiontaken.dao.ActionTakenDAO; |
23 | |
import org.kuali.rice.kew.actiontaken.service.ActionTakenService; |
24 | |
import org.kuali.rice.kew.exception.WorkflowServiceErrorException; |
25 | |
import org.kuali.rice.kew.exception.WorkflowServiceErrorImpl; |
26 | |
import org.kuali.rice.kew.routeheader.service.RouteHeaderService; |
27 | |
import org.kuali.rice.kew.service.KEWServiceLocator; |
28 | |
import org.kuali.rice.kew.util.KEWConstants; |
29 | |
import org.kuali.rice.kim.bo.entity.KimPrincipal; |
30 | |
import org.kuali.rice.kim.service.IdentityManagementService; |
31 | |
import org.kuali.rice.kim.service.KIMServiceLocator; |
32 | |
|
33 | |
import java.sql.Timestamp; |
34 | |
import java.util.ArrayList; |
35 | |
import java.util.Collection; |
36 | |
import java.util.List; |
37 | |
|
38 | |
|
39 | |
|
40 | |
|
41 | |
|
42 | |
|
43 | |
|
44 | 0 | public class ActionTakenServiceImpl implements ActionTakenService { |
45 | 0 | private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(ActionTakenServiceImpl.class); |
46 | |
private ActionTakenDAO actionTakenDAO; |
47 | |
|
48 | |
public ActionTakenValue load(Long id) { |
49 | 0 | return getActionTakenDAO().load(id); |
50 | |
} |
51 | |
|
52 | |
public ActionTakenValue findByActionTakenId(Long actionTakenId) { |
53 | 0 | return getActionTakenDAO().findByActionTakenId(actionTakenId); |
54 | |
} |
55 | |
|
56 | |
public ActionTakenValue getPreviousAction(ActionRequestValue actionRequest) { |
57 | 0 | return getPreviousAction(actionRequest, null); |
58 | |
} |
59 | |
|
60 | |
public ActionTakenValue getPreviousAction(ActionRequestValue actionRequest, List<ActionTakenValue> simulatedActionsTaken) |
61 | |
{ |
62 | 0 | IdentityManagementService ims = KIMServiceLocator.getIdentityManagementService(); |
63 | 0 | ActionTakenValue foundActionTaken = null; |
64 | 0 | List<String> principalIds = new ArrayList<String>(); |
65 | 0 | if (actionRequest.isGroupRequest()) { |
66 | 0 | principalIds.addAll( ims.getGroupMemberPrincipalIds(actionRequest.getGroup().getGroupId())); |
67 | 0 | } else if (actionRequest.isUserRequest()) { |
68 | 0 | principalIds.add(actionRequest.getPrincipalId()); |
69 | |
} |
70 | |
|
71 | 0 | for (String id : principalIds) |
72 | |
{ |
73 | 0 | List<ActionTakenValue> actionsTakenByUser = |
74 | |
getActionTakenDAO().findByRouteHeaderIdWorkflowId(actionRequest.getRouteHeaderId(), id ); |
75 | 0 | if (simulatedActionsTaken != null) { |
76 | 0 | for (ActionTakenValue simulatedAction : simulatedActionsTaken) |
77 | |
{ |
78 | 0 | if (id.equals(simulatedAction.getPrincipalId())) |
79 | |
{ |
80 | 0 | actionsTakenByUser.add(simulatedAction); |
81 | |
} |
82 | |
} |
83 | |
} |
84 | |
|
85 | 0 | for (ActionTakenValue actionTaken : actionsTakenByUser) |
86 | |
{ |
87 | 0 | if (ActionRequestValue.compareActionCode(actionTaken.getActionTaken(), |
88 | |
actionRequest.getActionRequested(), true) >= 0) |
89 | |
{ |
90 | 0 | foundActionTaken = actionTaken; |
91 | |
} |
92 | |
} |
93 | 0 | } |
94 | |
|
95 | 0 | return foundActionTaken; |
96 | |
} |
97 | |
|
98 | |
public Collection findByDocIdAndAction(Long docId, String action) { |
99 | 0 | return getActionTakenDAO().findByDocIdAndAction(docId, action); |
100 | |
} |
101 | |
|
102 | |
public Collection<ActionTakenValue> findByRouteHeaderId(Long routeHeaderId) { |
103 | 0 | return getActionTakenDAO().findByRouteHeaderId(routeHeaderId); |
104 | |
} |
105 | |
|
106 | |
public List findByRouteHeaderIdWorkflowId(Long routeHeaderId, String workflowId) { |
107 | 0 | return getActionTakenDAO().findByRouteHeaderIdWorkflowId(routeHeaderId, workflowId); |
108 | |
} |
109 | |
|
110 | |
public Collection getActionsTaken(Long routeHeaderId) { |
111 | 0 | return getActionTakenDAO().findByRouteHeaderId(routeHeaderId); |
112 | |
} |
113 | |
|
114 | |
public List findByRouteHeaderIdIgnoreCurrentInd(Long routeHeaderId) { |
115 | 0 | return getActionTakenDAO().findByRouteHeaderIdIgnoreCurrentInd(routeHeaderId); |
116 | |
} |
117 | |
|
118 | |
public void saveActionTaken(ActionTakenValue actionTaken) { |
119 | 0 | this.getActionTakenDAO().saveActionTaken(actionTaken); |
120 | 0 | } |
121 | |
|
122 | |
public void delete(ActionTakenValue actionTaken) { |
123 | 0 | getActionTakenDAO().deleteActionTaken(actionTaken); |
124 | 0 | } |
125 | |
|
126 | |
public ActionTakenDAO getActionTakenDAO() { |
127 | 0 | return actionTakenDAO; |
128 | |
} |
129 | |
|
130 | |
public void setActionTakenDAO(ActionTakenDAO actionTakenDAO) { |
131 | 0 | this.actionTakenDAO = actionTakenDAO; |
132 | 0 | } |
133 | |
|
134 | |
public void deleteByRouteHeaderId(Long routeHeaderId){ |
135 | 0 | actionTakenDAO.deleteByRouteHeaderId(routeHeaderId); |
136 | 0 | } |
137 | |
|
138 | |
public void validateActionTaken(ActionTakenValue actionTaken){ |
139 | 0 | LOG.debug("Enter validateActionTaken(..)"); |
140 | 0 | List<WorkflowServiceErrorImpl> errors = new ArrayList<WorkflowServiceErrorImpl>(); |
141 | |
|
142 | 0 | Long routeHeaderId = actionTaken.getRouteHeaderId(); |
143 | 0 | if(routeHeaderId == null){ |
144 | 0 | errors.add(new WorkflowServiceErrorImpl("ActionTaken routeheaderid null.", "actiontaken.routeheaderid.empty", actionTaken.getActionTakenId().toString())); |
145 | 0 | } else if(getRouteHeaderService().getRouteHeader(routeHeaderId) == null){ |
146 | 0 | errors.add(new WorkflowServiceErrorImpl("ActionTaken routeheaderid invalid.", "actiontaken.routeheaderid.invalid", actionTaken.getActionTakenId().toString())); |
147 | |
} |
148 | |
|
149 | 0 | String principalId = actionTaken.getPrincipalId(); |
150 | 0 | if(StringUtils.isBlank(principalId)){ |
151 | 0 | errors.add(new WorkflowServiceErrorImpl("ActionTaken personid null.", "actiontaken.personid.empty", actionTaken.getActionTakenId().toString())); |
152 | |
} else { |
153 | 0 | KimPrincipal principal = KIMServiceLocator.getIdentityManagementService().getPrincipal(principalId); |
154 | 0 | if (principal == null) { |
155 | 0 | errors.add(new WorkflowServiceErrorImpl("ActionTaken personid invalid.", "actiontaken.personid.invalid", actionTaken.getActionTakenId().toString())); |
156 | |
} |
157 | |
} |
158 | 0 | String actionTakenCd = actionTaken.getActionTaken(); |
159 | 0 | if(actionTakenCd == null || actionTakenCd.trim().equals("")){ |
160 | 0 | errors.add(new WorkflowServiceErrorImpl("ActionTaken cd null.", "actiontaken.actiontaken.empty", actionTaken.getActionTakenId().toString())); |
161 | 0 | } else if(!KEWConstants.ACTION_TAKEN_CD.containsKey(actionTakenCd)){ |
162 | 0 | errors.add(new WorkflowServiceErrorImpl("ActionTaken invalid.", "actiontaken.actiontaken.invalid", actionTaken.getActionTakenId().toString())); |
163 | |
} |
164 | 0 | if(actionTaken.getActionDate() == null){ |
165 | 0 | errors.add(new WorkflowServiceErrorImpl("ActionTaken actiondate null.", "actiontaken.actiondate.empty", actionTaken.getActionTakenId().toString())); |
166 | |
} |
167 | |
|
168 | 0 | if(actionTaken.getDocVersion() == null){ |
169 | 0 | errors.add(new WorkflowServiceErrorImpl("ActionTaken docversion null.", "actiontaken.docverion.empty", actionTaken.getActionTakenId().toString())); |
170 | |
} |
171 | 0 | LOG.debug("Exit validateActionRequest(..) "); |
172 | 0 | if (!errors.isEmpty()) { |
173 | 0 | throw new WorkflowServiceErrorException("ActionRequest Validation Error", errors); |
174 | |
} |
175 | 0 | } |
176 | |
|
177 | |
public boolean hasUserTakenAction(String principalId, Long documentId) { |
178 | 0 | return getActionTakenDAO().hasUserTakenAction(principalId, documentId); |
179 | |
} |
180 | |
|
181 | |
private RouteHeaderService getRouteHeaderService() { |
182 | 0 | return (RouteHeaderService) KEWServiceLocator.getService(KEWServiceLocator.DOC_ROUTE_HEADER_SRV); |
183 | |
} |
184 | |
|
185 | |
public Timestamp getLastApprovedDate(Long routeHeaderId) |
186 | |
{ |
187 | 0 | Timestamp dateLastApproved = null; |
188 | 0 | Collection<ActionTakenValue> actionsTaken= getActionTakenDAO().findByDocIdAndAction(routeHeaderId, KEWConstants.ACTION_TAKEN_APPROVED_CD); |
189 | 0 | for (ActionTakenValue actionTaken : actionsTaken) |
190 | |
{ |
191 | |
|
192 | 0 | if (dateLastApproved == null || dateLastApproved.compareTo(actionTaken.getActionDate()) <= -1) |
193 | |
{ |
194 | 0 | dateLastApproved = actionTaken.getActionDate(); |
195 | |
} |
196 | |
} |
197 | 0 | LOG.info("Exit getLastApprovedDate("+routeHeaderId+") "+dateLastApproved); |
198 | 0 | return dateLastApproved; |
199 | |
} |
200 | |
|
201 | |
} |