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.api.group.GroupService; |
30 | |
import org.kuali.rice.kim.api.identity.principal.Principal; |
31 | |
import org.kuali.rice.kim.api.services.KimApiServiceLocator; |
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 | |
|
45 | 0 | public class ActionTakenServiceImpl implements ActionTakenService { |
46 | 0 | private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(ActionTakenServiceImpl.class); |
47 | |
private ActionTakenDAO actionTakenDAO; |
48 | |
|
49 | |
public ActionTakenValue load(String id) { |
50 | 0 | return getActionTakenDAO().load(id); |
51 | |
} |
52 | |
|
53 | |
public ActionTakenValue findByActionTakenId(String actionTakenId) { |
54 | 0 | return getActionTakenDAO().findByActionTakenId(actionTakenId); |
55 | |
} |
56 | |
|
57 | |
public ActionTakenValue getPreviousAction(ActionRequestValue actionRequest) { |
58 | 0 | return getPreviousAction(actionRequest, null); |
59 | |
} |
60 | |
|
61 | |
public ActionTakenValue getPreviousAction(ActionRequestValue actionRequest, List<ActionTakenValue> simulatedActionsTaken) |
62 | |
{ |
63 | 0 | GroupService ims = KimApiServiceLocator.getGroupService(); |
64 | 0 | ActionTakenValue foundActionTaken = null; |
65 | 0 | List<String> principalIds = new ArrayList<String>(); |
66 | 0 | if (actionRequest.isGroupRequest()) { |
67 | 0 | principalIds.addAll( ims.getMemberPrincipalIds(actionRequest.getGroup().getId())); |
68 | 0 | } else if (actionRequest.isUserRequest()) { |
69 | 0 | principalIds.add(actionRequest.getPrincipalId()); |
70 | |
} |
71 | |
|
72 | 0 | for (String id : principalIds) |
73 | |
{ |
74 | 0 | List<ActionTakenValue> actionsTakenByUser = |
75 | |
getActionTakenDAO().findByDocumentIdWorkflowId(actionRequest.getDocumentId(), id ); |
76 | 0 | if (simulatedActionsTaken != null) { |
77 | 0 | for (ActionTakenValue simulatedAction : simulatedActionsTaken) |
78 | |
{ |
79 | 0 | if (id.equals(simulatedAction.getPrincipalId())) |
80 | |
{ |
81 | 0 | actionsTakenByUser.add(simulatedAction); |
82 | |
} |
83 | |
} |
84 | |
} |
85 | |
|
86 | 0 | for (ActionTakenValue actionTaken : actionsTakenByUser) |
87 | |
{ |
88 | 0 | if (ActionRequestValue.compareActionCode(actionTaken.getActionTaken(), |
89 | |
actionRequest.getActionRequested(), true) >= 0) |
90 | |
{ |
91 | 0 | foundActionTaken = actionTaken; |
92 | |
} |
93 | |
} |
94 | 0 | } |
95 | |
|
96 | 0 | return foundActionTaken; |
97 | |
} |
98 | |
|
99 | |
public Collection findByDocIdAndAction(String docId, String action) { |
100 | 0 | return getActionTakenDAO().findByDocIdAndAction(docId, action); |
101 | |
} |
102 | |
|
103 | |
public Collection<ActionTakenValue> findByDocumentId(String documentId) { |
104 | 0 | return getActionTakenDAO().findByDocumentId(documentId); |
105 | |
} |
106 | |
|
107 | |
public List findByDocumentIdWorkflowId(String documentId, String workflowId) { |
108 | 0 | return getActionTakenDAO().findByDocumentIdWorkflowId(documentId, workflowId); |
109 | |
} |
110 | |
|
111 | |
public Collection getActionsTaken(String documentId) { |
112 | 0 | return getActionTakenDAO().findByDocumentId(documentId); |
113 | |
} |
114 | |
|
115 | |
public List findByDocumentIdIgnoreCurrentInd(String documentId) { |
116 | 0 | return getActionTakenDAO().findByDocumentIdIgnoreCurrentInd(documentId); |
117 | |
} |
118 | |
|
119 | |
public void saveActionTaken(ActionTakenValue actionTaken) { |
120 | 0 | this.getActionTakenDAO().saveActionTaken(actionTaken); |
121 | 0 | } |
122 | |
|
123 | |
public void delete(ActionTakenValue actionTaken) { |
124 | 0 | getActionTakenDAO().deleteActionTaken(actionTaken); |
125 | 0 | } |
126 | |
|
127 | |
public ActionTakenDAO getActionTakenDAO() { |
128 | 0 | return actionTakenDAO; |
129 | |
} |
130 | |
|
131 | |
public void setActionTakenDAO(ActionTakenDAO actionTakenDAO) { |
132 | 0 | this.actionTakenDAO = actionTakenDAO; |
133 | 0 | } |
134 | |
|
135 | |
public void deleteByDocumentId(String documentId){ |
136 | 0 | actionTakenDAO.deleteByDocumentId(documentId); |
137 | 0 | } |
138 | |
|
139 | |
public void validateActionTaken(ActionTakenValue actionTaken){ |
140 | 0 | LOG.debug("Enter validateActionTaken(..)"); |
141 | 0 | List<WorkflowServiceErrorImpl> errors = new ArrayList<WorkflowServiceErrorImpl>(); |
142 | |
|
143 | 0 | String documentId = actionTaken.getDocumentId(); |
144 | 0 | if(documentId == null){ |
145 | 0 | errors.add(new WorkflowServiceErrorImpl("ActionTaken documentid null.", "actiontaken.documentid.empty", actionTaken.getActionTakenId().toString())); |
146 | 0 | } else if(getRouteHeaderService().getRouteHeader(documentId) == null){ |
147 | 0 | errors.add(new WorkflowServiceErrorImpl("ActionTaken documentid invalid.", "actiontaken.documentid.invalid", actionTaken.getActionTakenId().toString())); |
148 | |
} |
149 | |
|
150 | 0 | String principalId = actionTaken.getPrincipalId(); |
151 | 0 | if(StringUtils.isBlank(principalId)){ |
152 | 0 | errors.add(new WorkflowServiceErrorImpl("ActionTaken personid null.", "actiontaken.personid.empty", actionTaken.getActionTakenId().toString())); |
153 | |
} else { |
154 | 0 | Principal principal = KimApiServiceLocator.getIdentityService().getPrincipal(principalId); |
155 | 0 | if (principal == null) { |
156 | 0 | errors.add(new WorkflowServiceErrorImpl("ActionTaken personid invalid.", "actiontaken.personid.invalid", actionTaken.getActionTakenId().toString())); |
157 | |
} |
158 | |
} |
159 | 0 | String actionTakenCd = actionTaken.getActionTaken(); |
160 | 0 | if(actionTakenCd == null || actionTakenCd.trim().equals("")){ |
161 | 0 | errors.add(new WorkflowServiceErrorImpl("ActionTaken cd null.", "actiontaken.actiontaken.empty", actionTaken.getActionTakenId().toString())); |
162 | 0 | } else if(!KEWConstants.ACTION_TAKEN_CD.containsKey(actionTakenCd)){ |
163 | 0 | errors.add(new WorkflowServiceErrorImpl("ActionTaken invalid.", "actiontaken.actiontaken.invalid", actionTaken.getActionTakenId().toString())); |
164 | |
} |
165 | 0 | if(actionTaken.getActionDate() == null){ |
166 | 0 | errors.add(new WorkflowServiceErrorImpl("ActionTaken actiondate null.", "actiontaken.actiondate.empty", actionTaken.getActionTakenId().toString())); |
167 | |
} |
168 | |
|
169 | 0 | if(actionTaken.getDocVersion() == null){ |
170 | 0 | errors.add(new WorkflowServiceErrorImpl("ActionTaken docversion null.", "actiontaken.docverion.empty", actionTaken.getActionTakenId().toString())); |
171 | |
} |
172 | 0 | LOG.debug("Exit validateActionRequest(..) "); |
173 | 0 | if (!errors.isEmpty()) { |
174 | 0 | throw new WorkflowServiceErrorException("ActionRequest Validation Error", errors); |
175 | |
} |
176 | 0 | } |
177 | |
|
178 | |
public boolean hasUserTakenAction(String principalId, String documentId) { |
179 | 0 | return getActionTakenDAO().hasUserTakenAction(principalId, documentId); |
180 | |
} |
181 | |
|
182 | |
private RouteHeaderService getRouteHeaderService() { |
183 | 0 | return (RouteHeaderService) KEWServiceLocator.getService(KEWServiceLocator.DOC_ROUTE_HEADER_SRV); |
184 | |
} |
185 | |
|
186 | |
public Timestamp getLastApprovedDate(String documentId) |
187 | |
{ |
188 | 0 | Timestamp dateLastApproved = null; |
189 | 0 | Collection<ActionTakenValue> actionsTaken= getActionTakenDAO().findByDocIdAndAction(documentId, KEWConstants.ACTION_TAKEN_APPROVED_CD); |
190 | 0 | for (ActionTakenValue actionTaken : actionsTaken) |
191 | |
{ |
192 | |
|
193 | 0 | if (dateLastApproved == null || dateLastApproved.compareTo(actionTaken.getActionDate()) <= -1) |
194 | |
{ |
195 | 0 | dateLastApproved = actionTaken.getActionDate(); |
196 | |
} |
197 | |
} |
198 | 0 | LOG.info("Exit getLastApprovedDate("+documentId+") "+dateLastApproved); |
199 | 0 | return dateLastApproved; |
200 | |
} |
201 | |
|
202 | |
} |