1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.kuali.rice.kew.actiontaken.service.impl; |
17 | |
|
18 | |
import org.apache.commons.lang.StringUtils; |
19 | |
import org.kuali.rice.kew.actionrequest.ActionRequestValue; |
20 | |
import org.kuali.rice.kew.actiontaken.ActionTakenValue; |
21 | |
import org.kuali.rice.kew.actiontaken.dao.ActionTakenDAO; |
22 | |
import org.kuali.rice.kew.actiontaken.service.ActionTakenService; |
23 | |
import org.kuali.rice.kew.exception.WorkflowServiceErrorException; |
24 | |
import org.kuali.rice.kew.exception.WorkflowServiceErrorImpl; |
25 | |
import org.kuali.rice.kew.routeheader.service.RouteHeaderService; |
26 | |
import org.kuali.rice.kew.service.KEWServiceLocator; |
27 | |
import org.kuali.rice.kew.api.KewApiConstants; |
28 | |
import org.kuali.rice.kim.api.group.GroupService; |
29 | |
import org.kuali.rice.kim.api.identity.principal.Principal; |
30 | |
import org.kuali.rice.kim.api.services.KimApiServiceLocator; |
31 | |
|
32 | |
import java.sql.Timestamp; |
33 | |
import java.util.ArrayList; |
34 | |
import java.util.Collection; |
35 | |
import java.util.List; |
36 | |
|
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(String id) { |
49 | 0 | return getActionTakenDAO().load(id); |
50 | |
} |
51 | |
|
52 | |
public ActionTakenValue findByActionTakenId(String 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 | GroupService ims = KimApiServiceLocator.getGroupService(); |
63 | 0 | ActionTakenValue foundActionTaken = null; |
64 | 0 | List<String> principalIds = new ArrayList<String>(); |
65 | 0 | if (actionRequest.isGroupRequest()) { |
66 | 0 | principalIds.addAll( ims.getMemberPrincipalIds(actionRequest.getGroup().getId())); |
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().findByDocumentIdWorkflowId(actionRequest.getDocumentId(), 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(String docId, String action) { |
99 | 0 | return getActionTakenDAO().findByDocIdAndAction(docId, action); |
100 | |
} |
101 | |
|
102 | |
public Collection<ActionTakenValue> findByDocumentId(String documentId) { |
103 | 0 | return getActionTakenDAO().findByDocumentId(documentId); |
104 | |
} |
105 | |
|
106 | |
public List<ActionTakenValue> findByDocumentIdWorkflowId(String documentId, String workflowId) { |
107 | 0 | return getActionTakenDAO().findByDocumentIdWorkflowId(documentId, workflowId); |
108 | |
} |
109 | |
|
110 | |
public Collection getActionsTaken(String documentId) { |
111 | 0 | return getActionTakenDAO().findByDocumentId(documentId); |
112 | |
} |
113 | |
|
114 | |
public List findByDocumentIdIgnoreCurrentInd(String documentId) { |
115 | 0 | return getActionTakenDAO().findByDocumentIdIgnoreCurrentInd(documentId); |
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 deleteByDocumentId(String documentId){ |
135 | 0 | actionTakenDAO.deleteByDocumentId(documentId); |
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 | String documentId = actionTaken.getDocumentId(); |
143 | 0 | if(documentId == null){ |
144 | 0 | errors.add(new WorkflowServiceErrorImpl("ActionTaken documentid null.", "actiontaken.documentid.empty", actionTaken.getActionTakenId().toString())); |
145 | 0 | } else if(getRouteHeaderService().getRouteHeader(documentId) == null){ |
146 | 0 | errors.add(new WorkflowServiceErrorImpl("ActionTaken documentid invalid.", "actiontaken.documentid.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 | Principal principal = KimApiServiceLocator.getIdentityService().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(!KewApiConstants.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, String 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(String documentId) |
186 | |
{ |
187 | 0 | Timestamp dateLastApproved = null; |
188 | 0 | Collection<ActionTakenValue> actionsTaken= getActionTakenDAO().findByDocIdAndAction(documentId, KewApiConstants.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("+documentId+") "+dateLastApproved); |
198 | 0 | return dateLastApproved; |
199 | |
} |
200 | |
|
201 | |
} |