1 | |
package org.kuali.student.r2.core.class1.process.service.impl; |
2 | |
|
3 | |
import org.apache.commons.lang.StringUtils; |
4 | |
import org.kuali.rice.core.api.criteria.QueryByCriteria; |
5 | |
import org.kuali.student.r2.common.dto.ContextInfo; |
6 | |
import org.kuali.student.r2.common.dto.StatusInfo; |
7 | |
import org.kuali.student.r2.common.dto.ValidationResultInfo; |
8 | |
import org.kuali.student.r2.common.exceptions.*; |
9 | |
import org.kuali.student.r2.common.util.constants.ProcessServiceConstants; |
10 | |
import org.kuali.student.r2.core.class1.process.dao.CheckDao; |
11 | |
import org.kuali.student.r2.core.class1.process.dao.InstructionDao; |
12 | |
import org.kuali.student.r2.core.class1.process.dao.ProcessDao; |
13 | |
import org.kuali.student.r2.core.class1.process.model.CheckEntity; |
14 | |
import org.kuali.student.r2.core.class1.process.model.InstructionEntity; |
15 | |
import org.kuali.student.r2.core.class1.process.model.ProcessEntity; |
16 | |
import org.kuali.student.r2.core.process.dto.CheckInfo; |
17 | |
import org.kuali.student.r2.core.process.dto.InstructionInfo; |
18 | |
import org.kuali.student.r2.core.process.dto.ProcessCategoryInfo; |
19 | |
import org.kuali.student.r2.core.process.dto.ProcessInfo; |
20 | |
import org.kuali.student.r2.core.process.service.ProcessService; |
21 | |
import org.kuali.student.r2.core.state.service.StateService; |
22 | |
import org.springframework.transaction.annotation.Transactional; |
23 | |
|
24 | |
import javax.jws.WebParam; |
25 | |
import java.util.ArrayList; |
26 | |
import java.util.Calendar; |
27 | |
import java.util.Collections; |
28 | |
import java.util.Comparator; |
29 | |
import java.util.Date; |
30 | |
import java.util.List; |
31 | |
|
32 | 0 | public class ProcessServiceImpl implements ProcessService { |
33 | |
|
34 | |
private CheckDao checkDao; |
35 | |
private InstructionDao instructionDao; |
36 | |
private ProcessDao processDao; |
37 | |
private StateService stateService; |
38 | |
|
39 | |
public CheckDao getCheckDao() { |
40 | 0 | return checkDao; |
41 | |
} |
42 | |
|
43 | |
public void setCheckDao(CheckDao checkDao) { |
44 | 0 | this.checkDao = checkDao; |
45 | 0 | } |
46 | |
|
47 | |
public InstructionDao getInstructionDao() { |
48 | 0 | return instructionDao; |
49 | |
} |
50 | |
|
51 | |
public void setInstructionDao(InstructionDao instructionDao) { |
52 | 0 | this.instructionDao = instructionDao; |
53 | 0 | } |
54 | |
|
55 | |
public ProcessDao getProcessDao() { |
56 | 0 | return processDao; |
57 | |
} |
58 | |
|
59 | |
public void setProcessDao(ProcessDao processDao) { |
60 | 0 | this.processDao = processDao; |
61 | 0 | } |
62 | |
|
63 | |
public StateService getStateService() { |
64 | 0 | return stateService; |
65 | |
} |
66 | |
|
67 | |
public void setStateService(StateService stateService) { |
68 | 0 | this.stateService = stateService; |
69 | 0 | } |
70 | |
|
71 | |
@Override |
72 | |
public ProcessCategoryInfo getProcessCategory(@WebParam(name = "processCategoryId") String processCategoryId, |
73 | |
@WebParam(name = "contextInfo") ContextInfo contextInfo) |
74 | |
throws DoesNotExistException, InvalidParameterException, MissingParameterException, |
75 | |
OperationFailedException, PermissionDeniedException { |
76 | 0 | throw new OperationFailedException("Method not implemented."); |
77 | |
|
78 | |
} |
79 | |
|
80 | |
@Override |
81 | |
public List<ProcessCategoryInfo> getProcessCategoriesByIds( |
82 | |
@WebParam(name = "processCategoryIds") List<String> processCategoryIds, |
83 | |
@WebParam(name = "contextInfo") ContextInfo contextInfo) |
84 | |
throws DoesNotExistException, InvalidParameterException, MissingParameterException, |
85 | |
OperationFailedException, PermissionDeniedException { |
86 | 0 | throw new OperationFailedException("Method not implemented."); |
87 | |
|
88 | |
} |
89 | |
|
90 | |
@Override |
91 | |
public List<String> getProcessCategoryIdsByType(@WebParam(name = "processTypeKey") String processTypeKey, |
92 | |
@WebParam(name = "contextInfo") ContextInfo contextInfo) |
93 | |
throws InvalidParameterException, MissingParameterException, OperationFailedException, |
94 | |
PermissionDeniedException { |
95 | 0 | throw new OperationFailedException("Method not implemented."); |
96 | |
|
97 | |
} |
98 | |
|
99 | |
@Override |
100 | |
public List<ProcessCategoryInfo> getProcessCategoriesForProcess(@WebParam(name = "processKey") String processKey, |
101 | |
@WebParam(name = "contextInfo") ContextInfo contextInfo) |
102 | |
throws InvalidParameterException, MissingParameterException, OperationFailedException, |
103 | |
PermissionDeniedException { |
104 | 0 | throw new OperationFailedException("Method not implemented."); |
105 | |
|
106 | |
} |
107 | |
|
108 | |
@Override |
109 | |
public List<String> searchForProcessCategoryIds(@WebParam(name = "criteria") QueryByCriteria criteria, |
110 | |
@WebParam(name = "contextInfo") ContextInfo contextInfo) throws InvalidParameterException, |
111 | |
MissingParameterException, OperationFailedException, PermissionDeniedException { |
112 | 0 | throw new OperationFailedException("Method not implemented."); |
113 | |
|
114 | |
} |
115 | |
|
116 | |
@Override |
117 | |
public List<ProcessCategoryInfo> searchForProcessCategories(@WebParam(name = "criteria") QueryByCriteria criteria, |
118 | |
@WebParam(name = "contextInfo") ContextInfo contextInfo) |
119 | |
throws InvalidParameterException, MissingParameterException, OperationFailedException, |
120 | |
PermissionDeniedException { |
121 | 0 | throw new OperationFailedException("Method not implemented."); |
122 | |
|
123 | |
} |
124 | |
|
125 | |
@Override |
126 | |
public List<ValidationResultInfo> validateProcessCategory( |
127 | |
@WebParam(name = "validationTypeKey") String validationTypeKey, |
128 | |
String processCategoryTypeKey, |
129 | |
@WebParam(name = "processCategoryInfo") ProcessCategoryInfo processCategoryInfo, |
130 | |
@WebParam(name = "contextInfo") ContextInfo contextInfo) throws DoesNotExistException, |
131 | |
InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException { |
132 | 0 | throw new OperationFailedException("Method not implemented."); |
133 | |
|
134 | |
} |
135 | |
|
136 | |
@Override |
137 | |
public ProcessCategoryInfo createProcessCategory(String processCategoryTypeKey, @WebParam(name = "processInfo") ProcessCategoryInfo processInfo, |
138 | |
@WebParam(name = "contextInfo") ContextInfo contextInfo) |
139 | |
throws DataValidationErrorException, InvalidParameterException, |
140 | |
MissingParameterException, OperationFailedException, PermissionDeniedException, ReadOnlyException { |
141 | 0 | throw new OperationFailedException("Method not implemented."); |
142 | |
|
143 | |
} |
144 | |
|
145 | |
@Override |
146 | |
public ProcessCategoryInfo updateProcessCategory(@WebParam(name = "processCategoryId") String processCategoryId, |
147 | |
@WebParam(name = "processInfo") ProcessCategoryInfo processInfo, |
148 | |
@WebParam(name = "contextInfo") ContextInfo contextInfo) throws DataValidationErrorException, |
149 | |
DoesNotExistException, InvalidParameterException, MissingParameterException, |
150 | |
OperationFailedException, PermissionDeniedException, ReadOnlyException, VersionMismatchException { |
151 | 0 | throw new OperationFailedException("Method not implemented."); |
152 | |
|
153 | |
} |
154 | |
|
155 | |
@Override |
156 | |
public StatusInfo deleteProcessCategory(@WebParam(name = "processCategoryId") String processCategoryId, |
157 | |
@WebParam(name = "contextInfo") ContextInfo contextInfo) throws DoesNotExistException, |
158 | |
InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException { |
159 | 0 | throw new OperationFailedException("Method not implemented."); |
160 | |
|
161 | |
} |
162 | |
|
163 | |
@Override |
164 | |
public StatusInfo addProcessToProcessCategory(@WebParam(name = "processKey") String processKey, |
165 | |
@WebParam(name = "processCategoryId") String processCategoryId, |
166 | |
@WebParam(name = "contextInfo") ContextInfo contextInfo) throws AlreadyExistsException, |
167 | |
DoesNotExistException, InvalidParameterException, MissingParameterException, |
168 | |
OperationFailedException, PermissionDeniedException { |
169 | 0 | throw new OperationFailedException("Method not implemented."); |
170 | |
|
171 | |
} |
172 | |
|
173 | |
@Override |
174 | |
public StatusInfo removeProcessFromProcessCategory(@WebParam(name = "processKey") String processKey, |
175 | |
@WebParam(name = "processCategoryId") String processCategoryId, |
176 | |
@WebParam(name = "contextInfo") ContextInfo contextInfo) throws |
177 | |
DoesNotExistException, InvalidParameterException, MissingParameterException, |
178 | |
OperationFailedException, PermissionDeniedException { |
179 | 0 | throw new OperationFailedException("Method not implemented."); |
180 | |
|
181 | |
} |
182 | |
|
183 | |
@Override |
184 | |
public ProcessInfo getProcess(@WebParam(name = "processKey") String processKey, |
185 | |
@WebParam(name = "contextInfo") ContextInfo contextInfo) throws DoesNotExistException, |
186 | |
InvalidParameterException, |
187 | |
MissingParameterException, OperationFailedException, PermissionDeniedException { |
188 | 0 | ProcessEntity processEntity = processDao.find(processKey); |
189 | 0 | if (processEntity == null) { |
190 | 0 | throw new DoesNotExistException(processKey); |
191 | |
} |
192 | |
|
193 | 0 | return processEntity.toDto(); |
194 | |
} |
195 | |
|
196 | |
@Override |
197 | |
public List<ProcessInfo> getProcessesByKeys(@WebParam(name = "processKeys") List<String> processKeys, |
198 | |
@WebParam(name = "contextInfo") ContextInfo contextInfo) throws DoesNotExistException, |
199 | |
InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException { |
200 | 0 | List<ProcessEntity> processEntities = processDao.findByIds(processKeys); |
201 | 0 | if (processEntities == null || processEntities.isEmpty()) { |
202 | 0 | throw new DoesNotExistException("No records found"); |
203 | |
} |
204 | 0 | List<ProcessInfo> processInfoList = new ArrayList<ProcessInfo>(); |
205 | 0 | for (ProcessEntity processEntity : processEntities) { |
206 | 0 | if (processEntity == null) { |
207 | 0 | throw new DoesNotExistException(); |
208 | |
} |
209 | 0 | processInfoList.add(processEntity.toDto()); |
210 | |
} |
211 | 0 | return processInfoList; |
212 | |
} |
213 | |
|
214 | |
@Override |
215 | |
public List<String> getProcessKeysByType(@WebParam(name = "processTypeKey") String processTypeKey, |
216 | |
@WebParam(name = "contextInfo") ContextInfo contextInfo) throws InvalidParameterException, |
217 | |
MissingParameterException, OperationFailedException, PermissionDeniedException { |
218 | 0 | List<ProcessEntity> processEntities = processDao.getByProcessTypeId(processTypeKey); |
219 | |
|
220 | 0 | List<String> processIds = new ArrayList<String>(); |
221 | 0 | for (ProcessEntity processEntity : processEntities) { |
222 | 0 | processIds.add(processEntity.getId()); |
223 | |
} |
224 | |
|
225 | 0 | return processIds; |
226 | |
} |
227 | |
|
228 | |
@Override |
229 | |
public List<ProcessInfo> getProcessesForProcessCategory( |
230 | |
@WebParam(name = "processCategoryId") String processCategoryId, |
231 | |
@WebParam(name = "contextInfo") ContextInfo contextInfo) |
232 | |
throws InvalidParameterException, MissingParameterException, OperationFailedException, |
233 | |
PermissionDeniedException { |
234 | 0 | throw new OperationFailedException("Method not implemented."); |
235 | |
|
236 | |
} |
237 | |
|
238 | |
@Override |
239 | |
public List<String> searchForProcessKeys(@WebParam(name = "criteria") QueryByCriteria criteria, |
240 | |
@WebParam(name = "contextInfo") ContextInfo contextInfo) throws InvalidParameterException, |
241 | |
MissingParameterException, OperationFailedException, PermissionDeniedException { |
242 | 0 | throw new OperationFailedException("Method not implemented."); |
243 | |
|
244 | |
} |
245 | |
|
246 | |
@Override |
247 | |
public List<ProcessInfo> searchForProcesss(@WebParam(name = "criteria") QueryByCriteria criteria, |
248 | |
@WebParam(name = "contextInfo") ContextInfo contextInfo) throws InvalidParameterException, |
249 | |
MissingParameterException, OperationFailedException, PermissionDeniedException { |
250 | 0 | throw new OperationFailedException("Method not implemented."); |
251 | |
|
252 | |
} |
253 | |
|
254 | |
@Override |
255 | |
public List<ValidationResultInfo> validateProcess(@WebParam(name = "validationTypeKey") String validationTypeKey, |
256 | |
String processTypeKey, |
257 | |
@WebParam(name = "processInfo") ProcessInfo processInfo, |
258 | |
@WebParam(name = "contextInfo") ContextInfo contextInfo) throws DoesNotExistException, |
259 | |
InvalidParameterException, MissingParameterException, OperationFailedException, |
260 | |
PermissionDeniedException { |
261 | 0 | throw new OperationFailedException("Method not implemented."); |
262 | |
|
263 | |
} |
264 | |
|
265 | |
@Override |
266 | |
@Transactional(readOnly = false) |
267 | |
public ProcessInfo createProcess(@WebParam(name = "processKey") String processKey, |
268 | |
String processTypeKey, |
269 | |
@WebParam(name = "processInfo") ProcessInfo processInfo, |
270 | |
@WebParam(name = "contextInfo") ContextInfo contextInfo) |
271 | |
throws AlreadyExistsException, DataValidationErrorException, InvalidParameterException, |
272 | |
MissingParameterException, OperationFailedException, PermissionDeniedException, ReadOnlyException { |
273 | |
|
274 | 0 | ProcessEntity existing = processDao.find(processKey); |
275 | 0 | if (existing != null) { |
276 | 0 | throw new AlreadyExistsException(processKey); |
277 | |
} |
278 | |
|
279 | 0 | ProcessEntity process = new ProcessEntity(processInfo); |
280 | |
|
281 | 0 | process.setId(processKey); |
282 | 0 | process.setProcessType(processTypeKey); |
283 | 0 | processDao.persist(process); |
284 | |
|
285 | 0 | ProcessEntity retrieved = processDao.find(processKey); |
286 | |
|
287 | 0 | return retrieved.toDto(); |
288 | |
} |
289 | |
|
290 | |
@Override |
291 | |
@Transactional(readOnly = false) |
292 | |
public ProcessInfo updateProcess(@WebParam(name = "processKey") String processKey, |
293 | |
@WebParam(name = "processInfo") ProcessInfo processInfo, |
294 | |
@WebParam(name = "contextInfo") ContextInfo contextInfo) |
295 | |
throws DataValidationErrorException, DoesNotExistException, InvalidParameterException, |
296 | |
MissingParameterException, OperationFailedException, PermissionDeniedException, ReadOnlyException, |
297 | |
VersionMismatchException { |
298 | |
|
299 | 0 | ProcessEntity processEntity = processDao.find(processKey); |
300 | |
|
301 | 0 | if (processEntity == null) { |
302 | 0 | throw new DoesNotExistException(processKey); |
303 | |
} |
304 | |
|
305 | 0 | ProcessEntity toUpdate = new ProcessEntity(processInfo); |
306 | |
|
307 | 0 | toUpdate.setProcessState(ProcessServiceConstants.PROCESS_LIFECYCLE_KEY); |
308 | |
|
309 | 0 | toUpdate.setProcessType(processInfo.getTypeKey()); |
310 | |
|
311 | 0 | processDao.merge(toUpdate); |
312 | 0 | return processDao.find(toUpdate.getId()).toDto(); |
313 | |
|
314 | |
} |
315 | |
|
316 | |
@Override |
317 | |
@Transactional(readOnly = false) |
318 | |
public StatusInfo deleteProcess(@WebParam(name = "processKey") String processKey, |
319 | |
@WebParam(name = "contextInfo") ContextInfo contextInfo) throws DependentObjectsExistException, |
320 | |
DoesNotExistException, InvalidParameterException, |
321 | |
MissingParameterException, OperationFailedException, PermissionDeniedException { |
322 | |
|
323 | 0 | ProcessEntity processEntity = processDao.find(processKey); |
324 | 0 | StatusInfo status = new StatusInfo(); |
325 | |
|
326 | 0 | if (processEntity == null) { |
327 | 0 | status.setSuccess(false); |
328 | 0 | return status; |
329 | |
} |
330 | |
|
331 | 0 | List<InstructionEntity> instructionEntities = instructionDao.getByProcess(processKey); |
332 | 0 | for (InstructionEntity instructionEntity : instructionEntities) { |
333 | 0 | instructionDao.remove(instructionEntity); |
334 | |
} |
335 | |
|
336 | 0 | processDao.remove(processEntity); |
337 | |
|
338 | 0 | status.setSuccess(true); |
339 | 0 | return status; |
340 | |
|
341 | |
} |
342 | |
|
343 | |
@Override |
344 | |
public CheckInfo getCheck(String checkId, |
345 | |
@WebParam(name = "contextInfo") ContextInfo contextInfo) throws DoesNotExistException, |
346 | |
InvalidParameterException, |
347 | |
MissingParameterException, OperationFailedException, PermissionDeniedException { |
348 | 0 | CheckEntity checkEntity = checkDao.find(checkId); |
349 | 0 | if (checkEntity == null) { |
350 | 0 | throw new DoesNotExistException(checkId); |
351 | |
} |
352 | 0 | return checkEntity.toDto(); |
353 | |
} |
354 | |
|
355 | |
@Override |
356 | |
public List<CheckInfo> getChecksByIds(List<String> checkIds, |
357 | |
@WebParam(name = "contextInfo") ContextInfo contextInfo) throws DoesNotExistException, |
358 | |
InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException { |
359 | 0 | List<CheckEntity> checkEntities = checkDao.findByIds(checkIds); |
360 | 0 | if (checkEntities == null || checkEntities.isEmpty()) { |
361 | 0 | throw new DoesNotExistException("No records found"); |
362 | |
} |
363 | 0 | List<CheckInfo> checkInfoList = new ArrayList<CheckInfo>(); |
364 | 0 | for (CheckEntity checkEntity : checkEntities) { |
365 | 0 | if (checkEntity == null) { |
366 | 0 | throw new DoesNotExistException(); |
367 | |
} |
368 | 0 | checkInfoList.add(checkEntity.toDto()); |
369 | |
} |
370 | 0 | return checkInfoList; |
371 | |
} |
372 | |
|
373 | |
@Override |
374 | |
public List<String> getCheckKeysByType(@WebParam(name = "checkTypeKey") String checkTypeKey, |
375 | |
@WebParam(name = "contextInfo") ContextInfo contextInfo) throws InvalidParameterException, |
376 | |
MissingParameterException, OperationFailedException, PermissionDeniedException { |
377 | 0 | List<CheckEntity> checkEntities = checkDao.getByCheckTypeId(checkTypeKey); |
378 | |
|
379 | 0 | List<String> checkIds = new ArrayList<String>(); |
380 | 0 | for (CheckEntity processEntity : checkEntities) { |
381 | 0 | checkIds.add(processEntity.getId()); |
382 | |
} |
383 | |
|
384 | 0 | return checkIds; |
385 | |
} |
386 | |
|
387 | |
@Override |
388 | |
public List<String> searchForCheckKeys(@WebParam(name = "criteria") QueryByCriteria criteria, |
389 | |
@WebParam(name = "contextInfo") ContextInfo contextInfo) throws InvalidParameterException, |
390 | |
MissingParameterException, OperationFailedException, PermissionDeniedException { |
391 | 0 | throw new OperationFailedException("Method not implemented."); |
392 | |
|
393 | |
} |
394 | |
|
395 | |
@Override |
396 | |
public List<CheckInfo> searchForChecks(@WebParam(name = "criteria") QueryByCriteria criteria, |
397 | |
@WebParam(name = "contextInfo") ContextInfo contextInfo) throws InvalidParameterException, |
398 | |
MissingParameterException, OperationFailedException, PermissionDeniedException { |
399 | 0 | throw new OperationFailedException("Method not implemented."); |
400 | |
|
401 | |
} |
402 | |
|
403 | |
@Override |
404 | |
public List<ValidationResultInfo> validateCheck(@WebParam(name = "validationTypeKey") String validationTypeKey, |
405 | |
String checkTypeKey, |
406 | |
@WebParam(name = "checkInfo") CheckInfo checkInfo, |
407 | |
@WebParam(name = "contextInfo") ContextInfo contextInfo) throws DoesNotExistException, |
408 | |
InvalidParameterException, MissingParameterException, OperationFailedException, |
409 | |
PermissionDeniedException { |
410 | 0 | throw new OperationFailedException("Method not implemented."); |
411 | |
|
412 | |
} |
413 | |
|
414 | |
@Override |
415 | |
@Transactional(readOnly = false) |
416 | |
public CheckInfo createCheck(String checkTypeKey, |
417 | |
@WebParam(name = "checkInfo") CheckInfo checkInfo, @WebParam(name = "contextInfo") ContextInfo contextInfo) |
418 | |
throws DataValidationErrorException, InvalidParameterException, |
419 | |
MissingParameterException, OperationFailedException, PermissionDeniedException, ReadOnlyException { |
420 | |
|
421 | 0 | CheckEntity checkEntity = new CheckEntity(checkInfo); |
422 | 0 | checkEntity.setCheckType(checkTypeKey); |
423 | 0 | checkEntity.setCheckState(ProcessServiceConstants.CHECK_LIFECYCLE_KEY); |
424 | |
|
425 | 0 | if (StringUtils.isNotBlank(checkInfo.getProcessKey())) { |
426 | 0 | ProcessEntity process = processDao.find(checkInfo.getProcessKey()); |
427 | 0 | if (null == process) { |
428 | 0 | throw new InvalidParameterException("Check processKey not valid."); |
429 | |
} |
430 | 0 | checkEntity.setChildProcessId(process.getId()); |
431 | 0 | } else { |
432 | 0 | checkEntity.setChildProcessId(null); |
433 | |
} |
434 | |
|
435 | 0 | checkDao.persist(checkEntity); |
436 | 0 | return checkEntity.toDto(); |
437 | |
|
438 | |
} |
439 | |
|
440 | |
@Override |
441 | |
@Transactional(readOnly = false) |
442 | |
public CheckInfo updateCheck(String checkId, |
443 | |
@WebParam(name = "checkInfo") CheckInfo checkInfo, @WebParam(name = "contextInfo") ContextInfo contextInfo) |
444 | |
throws DataValidationErrorException, DoesNotExistException, InvalidParameterException, |
445 | |
MissingParameterException, OperationFailedException, PermissionDeniedException, ReadOnlyException, |
446 | |
VersionMismatchException { |
447 | |
|
448 | 0 | CheckEntity exists = checkDao.find(checkId); |
449 | |
|
450 | 0 | if (exists == null) { |
451 | 0 | throw new DoesNotExistException(checkId); |
452 | |
} |
453 | |
|
454 | 0 | CheckEntity toUpdate = new CheckEntity(checkInfo); |
455 | |
|
456 | 0 | toUpdate.setCheckType(checkInfo.getTypeKey()); |
457 | 0 | toUpdate.setCheckState(ProcessServiceConstants.CHECK_LIFECYCLE_KEY); |
458 | |
|
459 | 0 | if (StringUtils.isNotBlank(checkInfo.getProcessKey())) { |
460 | 0 | ProcessEntity process = processDao.find(checkInfo.getProcessKey()); |
461 | 0 | if (null == process) { |
462 | 0 | throw new InvalidParameterException("Check processKey not valid."); |
463 | |
} |
464 | 0 | toUpdate.setChildProcessId(process.getId()); |
465 | 0 | } else { |
466 | 0 | toUpdate.setChildProcessId(null); |
467 | |
} |
468 | |
|
469 | 0 | checkDao.merge(toUpdate); |
470 | |
|
471 | 0 | CheckEntity retrieved = checkDao.find(checkInfo.getId()); |
472 | |
|
473 | 0 | return retrieved.toDto(); |
474 | |
|
475 | |
} |
476 | |
|
477 | |
@Override |
478 | |
@Transactional(readOnly = false) |
479 | |
public StatusInfo deleteCheck(String checkId, |
480 | |
@WebParam(name = "contextInfo") ContextInfo contextInfo) throws DependentObjectsExistException, |
481 | |
DoesNotExistException, |
482 | |
InvalidParameterException, |
483 | |
MissingParameterException, OperationFailedException, PermissionDeniedException { |
484 | |
|
485 | 0 | CheckEntity exists = checkDao.find(checkId); |
486 | 0 | StatusInfo status = new StatusInfo(); |
487 | |
|
488 | 0 | if (exists == null) { |
489 | 0 | status.setSuccess(false); |
490 | 0 | return status; |
491 | |
} |
492 | |
|
493 | 0 | List<InstructionEntity> instructionEntities = instructionDao.getByCheck(checkId); |
494 | 0 | for (InstructionEntity instructionEntity : instructionEntities) { |
495 | 0 | instructionDao.remove(instructionEntity); |
496 | |
} |
497 | |
|
498 | 0 | checkDao.remove(exists); |
499 | 0 | status.setSuccess(true); |
500 | 0 | return status; |
501 | |
} |
502 | |
|
503 | |
@Override |
504 | |
public InstructionInfo getInstruction(@WebParam(name = "instructionId") String instructionId, |
505 | |
@WebParam(name = "contextInfo") ContextInfo contextInfo) throws DoesNotExistException, |
506 | |
InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException { |
507 | 0 | InstructionEntity instructionEntity = instructionDao.find(instructionId); |
508 | 0 | if (instructionEntity == null) { |
509 | 0 | throw new DoesNotExistException(instructionId); |
510 | |
} |
511 | 0 | return instructionEntity.toDto(); |
512 | |
} |
513 | |
|
514 | |
@Override |
515 | |
public List<InstructionInfo> getInstructionsByIds(@WebParam(name = "instructionIds") List<String> instructionIds, |
516 | |
@WebParam(name = "contextInfo") ContextInfo contextInfo) |
517 | |
throws DoesNotExistException, InvalidParameterException, MissingParameterException, |
518 | |
OperationFailedException, PermissionDeniedException { |
519 | 0 | List<InstructionEntity> instructionEntities = instructionDao.findByIds(instructionIds); |
520 | 0 | if (instructionEntities == null || instructionEntities.isEmpty()) { |
521 | 0 | throw new DoesNotExistException(); |
522 | |
} |
523 | 0 | List<InstructionInfo> instructionInfos = new ArrayList<InstructionInfo>(); |
524 | |
|
525 | 0 | for (InstructionEntity instructionEntity : instructionEntities) { |
526 | 0 | if (instructionEntity == null) { |
527 | 0 | throw new DoesNotExistException(); |
528 | |
} |
529 | 0 | instructionInfos.add(instructionEntity.toDto()); |
530 | |
} |
531 | 0 | return instructionInfos; |
532 | |
} |
533 | |
|
534 | |
@Override |
535 | |
public List<String> getInstructionIdsByType(@WebParam(name = "instructionTypeKey") String instructionTypeKey, |
536 | |
@WebParam(name = "contextInfo") ContextInfo contextInfo) |
537 | |
throws InvalidParameterException, MissingParameterException, OperationFailedException, |
538 | |
PermissionDeniedException { |
539 | 0 | List<InstructionEntity> instructionEntities = instructionDao.getByInstructionTypeId(instructionTypeKey); |
540 | |
|
541 | 0 | List<String> instructionIds = new ArrayList<String>(); |
542 | 0 | for (InstructionEntity instructionEntity : instructionEntities) { |
543 | 0 | instructionIds.add(instructionEntity.getId()); |
544 | |
} |
545 | |
|
546 | 0 | return instructionIds; |
547 | |
} |
548 | |
|
549 | |
@Override |
550 | |
public List<InstructionInfo> getInstructionsByProcess(@WebParam(name = "processKey") String processKey, |
551 | |
@WebParam(name = "contextInfo") ContextInfo contextInfo) throws InvalidParameterException, |
552 | |
MissingParameterException, OperationFailedException, PermissionDeniedException { |
553 | 0 | List<InstructionInfo> instructionInfos = new ArrayList<InstructionInfo>(); |
554 | 0 | List<InstructionEntity> instructionEntities = instructionDao.getByProcess(processKey); |
555 | 0 | if (null != instructionEntities) { |
556 | 0 | for (InstructionEntity instructionEntity : instructionEntities) { |
557 | 0 | instructionInfos.add(instructionEntity.toDto()); |
558 | |
} |
559 | |
} |
560 | 0 | return instructionInfos; |
561 | |
} |
562 | |
|
563 | |
@Override |
564 | |
public List<InstructionInfo> getInstructionsByCheck(String checkId, |
565 | |
@WebParam(name = "contextInfo") ContextInfo contextInfo) throws InvalidParameterException, |
566 | |
MissingParameterException, OperationFailedException, PermissionDeniedException { |
567 | 0 | List<InstructionEntity> instructionEntities = instructionDao.getByCheck(checkId); |
568 | 0 | List<InstructionInfo> instructionInfoList = new ArrayList<InstructionInfo>(); |
569 | |
|
570 | 0 | for (InstructionEntity instructionEntity : instructionEntities) { |
571 | 0 | instructionInfoList.add(instructionEntity.toDto()); |
572 | |
} |
573 | |
|
574 | 0 | return instructionInfoList; |
575 | |
} |
576 | |
|
577 | |
@Override |
578 | |
public List<InstructionInfo> getInstructionsByProcessAndCheck(String checkId, |
579 | |
@WebParam(name = "processKey") String processKey, |
580 | |
@WebParam(name = "contextInfo") ContextInfo contextInfo) throws |
581 | |
InvalidParameterException, MissingParameterException, OperationFailedException, |
582 | |
PermissionDeniedException { |
583 | 0 | List<InstructionEntity> instructionEntities = instructionDao.getByProcessAndCheck(processKey, checkId); |
584 | 0 | List<InstructionInfo> instructionInfoList = new ArrayList<InstructionInfo>(); |
585 | |
|
586 | 0 | for (InstructionEntity instructionEntity : instructionEntities) { |
587 | 0 | instructionInfoList.add(instructionEntity.toDto()); |
588 | |
} |
589 | |
|
590 | 0 | return instructionInfoList; |
591 | |
} |
592 | |
|
593 | |
@Override |
594 | |
public List<String> searchForInstructionIds(@WebParam(name = "criteria") QueryByCriteria criteria, |
595 | |
@WebParam(name = "contextInfo") ContextInfo contextInfo) throws InvalidParameterException, |
596 | |
MissingParameterException, OperationFailedException, PermissionDeniedException { |
597 | 0 | throw new OperationFailedException("Method not implemented."); |
598 | |
|
599 | |
} |
600 | |
|
601 | |
@Override |
602 | |
public List<InstructionInfo> searchForInstructions(@WebParam(name = "criteria") QueryByCriteria criteria, |
603 | |
@WebParam(name = "contextInfo") ContextInfo contextInfo) |
604 | |
throws InvalidParameterException, MissingParameterException, OperationFailedException, |
605 | |
PermissionDeniedException { |
606 | 0 | throw new OperationFailedException("Method not implemented."); |
607 | |
|
608 | |
} |
609 | |
|
610 | |
@Override |
611 | |
public List<ValidationResultInfo> validateInstruction( |
612 | |
@WebParam(name = "validationTypeKey") String validationTypeKey, |
613 | |
@WebParam(name = "processKey") String processKey, |
614 | |
String checkId, |
615 | |
String instructionTypeKey, |
616 | |
@WebParam(name = "instructionInfo") InstructionInfo instructionInfo, |
617 | |
@WebParam(name = "contextInfo") ContextInfo contextInfo) |
618 | |
throws DoesNotExistException, InvalidParameterException, MissingParameterException, |
619 | |
OperationFailedException, PermissionDeniedException { |
620 | 0 | throw new OperationFailedException("Method not implemented."); |
621 | |
|
622 | |
} |
623 | |
|
624 | |
@Override |
625 | |
@Transactional(readOnly = false) |
626 | |
public InstructionInfo createInstruction(@WebParam(name = "processKey") String processKey, |
627 | |
String checkId, String instructionTypeKey, |
628 | |
@WebParam(name = "instructionInfo") InstructionInfo instructionInfo, |
629 | |
@WebParam(name = "contextInfo") ContextInfo contextInfo) throws DataValidationErrorException, |
630 | |
InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException, |
631 | |
ReadOnlyException { |
632 | |
|
633 | 0 | InstructionEntity instruction = new InstructionEntity(instructionInfo); |
634 | 0 | instruction.setInstructionState(instructionInfo.getStateKey()); |
635 | 0 | instruction.setInstructionType(instructionTypeKey); |
636 | |
|
637 | 0 | List<String> appliedAtpTypes = instructionInfo.getAppliedAtpTypeKeys(); |
638 | 0 | if (appliedAtpTypes.contains(null)) { |
639 | 0 | throw new InvalidParameterException("Could not find all appliedAtpTypes: " |
640 | |
+ instructionInfo.getAppliedAtpTypeKeys()); |
641 | |
} |
642 | 0 | instruction.setAppliedAtpTypes(appliedAtpTypes); |
643 | |
|
644 | 0 | ProcessEntity process = processDao.find(processKey); |
645 | 0 | if (null == process) { |
646 | 0 | throw new InvalidParameterException("processKey"); |
647 | |
} |
648 | 0 | instruction.setProcess(process); |
649 | |
|
650 | 0 | CheckEntity check = checkDao.find(checkId); |
651 | 0 | if (null == check) { |
652 | 0 | throw new InvalidParameterException("checkId"); |
653 | |
} |
654 | 0 | instruction.setCheck(check); |
655 | |
|
656 | 0 | instructionDao.persist(instruction); |
657 | 0 | return instruction.toDto(); |
658 | |
} |
659 | |
|
660 | |
@Override |
661 | |
@Transactional(readOnly = false) |
662 | |
public InstructionInfo updateInstruction(@WebParam(name = "instructionId") String instructionId, |
663 | |
@WebParam(name = "instructionInfo") InstructionInfo instructionInfo, |
664 | |
@WebParam(name = "contextInfo") ContextInfo contextInfo) throws DataValidationErrorException, |
665 | |
DoesNotExistException, InvalidParameterException, MissingParameterException, |
666 | |
OperationFailedException, PermissionDeniedException, ReadOnlyException, VersionMismatchException { |
667 | 0 | InstructionEntity exists = instructionDao.find(instructionId); |
668 | |
|
669 | 0 | if (exists == null) { |
670 | 0 | throw new DoesNotExistException(instructionId); |
671 | |
} |
672 | |
|
673 | 0 | InstructionEntity toUpdate = new InstructionEntity(instructionInfo); |
674 | 0 | toUpdate.setInstructionState( |
675 | |
instructionInfo.getStateKey()); |
676 | 0 | toUpdate.setInstructionType(instructionInfo.getTypeKey()); |
677 | |
|
678 | 0 | List<String> appliedAtpTypes = instructionInfo.getAppliedAtpTypeKeys(); |
679 | 0 | if (appliedAtpTypes.contains(null)) { |
680 | 0 | throw new InvalidParameterException("Could not find all appliedAtpTypes: " |
681 | |
+ instructionInfo.getAppliedAtpTypeKeys()); |
682 | |
} |
683 | 0 | toUpdate.setAppliedAtpTypes(appliedAtpTypes); |
684 | |
|
685 | 0 | ProcessEntity process = processDao.find(instructionInfo.getProcessKey()); |
686 | 0 | if (null == process) { |
687 | 0 | throw new InvalidParameterException("Instruction processKey"); |
688 | |
} |
689 | 0 | toUpdate.setProcess(process); |
690 | |
|
691 | 0 | CheckEntity check = checkDao.find(instructionInfo.getCheckKey()); |
692 | 0 | if (null == check) { |
693 | 0 | throw new InvalidParameterException("Instruction checkId"); |
694 | |
} |
695 | 0 | toUpdate.setCheck(check); |
696 | |
|
697 | 0 | instructionDao.merge(toUpdate); |
698 | |
|
699 | 0 | return instructionDao.find(instructionId).toDto(); |
700 | |
|
701 | |
} |
702 | |
|
703 | |
@Override |
704 | |
@Transactional(readOnly = false) |
705 | |
public StatusInfo deleteInstruction(@WebParam(name = "instructionId") String instructionId, |
706 | |
@WebParam(name = "contextInfo") ContextInfo contextInfo) throws DoesNotExistException, |
707 | |
InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException { |
708 | |
|
709 | 0 | InstructionEntity exists = instructionDao.find(instructionId); |
710 | 0 | StatusInfo status = new StatusInfo(); |
711 | |
|
712 | 0 | if (exists == null) { |
713 | 0 | status.setSuccess(false); |
714 | 0 | return status; |
715 | |
} |
716 | |
|
717 | 0 | instructionDao.remove(exists); |
718 | |
|
719 | 0 | status.setSuccess(true); |
720 | 0 | return status; |
721 | |
} |
722 | |
|
723 | |
@Override |
724 | |
public List<InstructionInfo> getInstructionsForEvaluation(@WebParam(name = "processKey") String processKey, |
725 | |
@WebParam(name = "contextInfo") ContextInfo contextInfo) |
726 | |
throws InvalidParameterException, MissingParameterException, OperationFailedException, |
727 | |
PermissionDeniedException { |
728 | 0 | List<InstructionInfo> instructions = getInstructionsByProcess(processKey, contextInfo); |
729 | 0 | for (InstructionInfo instruction : instructions) { |
730 | 0 | if (!ProcessServiceConstants.PROCESS_ENABLED_STATE_KEY.equals(instruction.getStateKey())) { |
731 | |
|
732 | 0 | instructions.remove(instruction); |
733 | 0 | } else if (!isInstructionCurrent(instruction, contextInfo)) { |
734 | |
|
735 | 0 | instructions.remove(instruction); |
736 | |
} |
737 | |
} |
738 | |
|
739 | |
|
740 | 0 | Collections.sort(instructions, new Comparator<InstructionInfo>() { |
741 | |
@Override |
742 | |
public int compare(InstructionInfo instruction1, InstructionInfo instruction2) { |
743 | 0 | return instruction1.getPosition().compareTo(instruction2.getPosition()); |
744 | |
} |
745 | |
}); |
746 | |
|
747 | 0 | return instructions; |
748 | |
} |
749 | |
|
750 | |
|
751 | |
|
752 | |
|
753 | |
|
754 | |
|
755 | |
|
756 | |
|
757 | |
|
758 | |
|
759 | |
|
760 | |
|
761 | |
|
762 | |
|
763 | |
|
764 | |
|
765 | |
|
766 | |
private boolean isInstructionCurrent(InstructionInfo instruction, ContextInfo contextInfo) |
767 | |
throws InvalidParameterException { |
768 | 0 | boolean result = false; |
769 | 0 | Date effectiveDate = instruction.getEffectiveDate(); |
770 | 0 | Date expirationDate = instruction.getExpirationDate(); |
771 | 0 | Date currentDate = Calendar.getInstance().getTime(); |
772 | |
|
773 | |
|
774 | 0 | if (null == effectiveDate) { |
775 | 0 | throw new InvalidParameterException("Instruction does not have an effective date."); |
776 | |
} |
777 | |
|
778 | 0 | if (!effectiveDate.after(currentDate)) { |
779 | 0 | if (null == expirationDate) { |
780 | 0 | result = true; |
781 | 0 | } else if (!expirationDate.before(currentDate)) { |
782 | 0 | result = true; |
783 | |
} |
784 | |
} |
785 | |
|
786 | 0 | return result; |
787 | |
} |
788 | |
|
789 | |
} |