1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.student.enrollment.class1.hold.service.impl;
17
18 import org.kuali.rice.core.api.criteria.GenericQueryResults;
19 import org.kuali.rice.core.api.criteria.QueryByCriteria;
20 import org.kuali.student.common.date.utils.EffectiveDateUtils;
21 import org.kuali.student.enrollment.class1.hold.dao.AppliedHoldDao;
22 import org.kuali.student.enrollment.class1.hold.dao.HoldIssueDao;
23 import org.kuali.student.enrollment.class1.hold.model.AppliedHoldEntity;
24 import org.kuali.student.enrollment.class1.hold.model.HoldIssueEntity;
25 import org.kuali.student.r2.common.criteria.CriteriaLookupService;
26 import org.kuali.student.r2.common.dto.ContextInfo;
27 import org.kuali.student.r2.common.dto.StatusInfo;
28 import org.kuali.student.r2.common.dto.ValidationResultInfo;
29 import org.kuali.student.r2.common.exceptions.*;
30 import org.kuali.student.r2.core.constants.HoldServiceConstants;
31 import org.kuali.student.r2.core.hold.dto.AppliedHoldInfo;
32 import org.kuali.student.r2.core.hold.dto.HoldIssueInfo;
33 import org.kuali.student.r2.core.hold.service.HoldService;
34 import org.springframework.transaction.annotation.Transactional;
35
36 import javax.jws.WebService;
37 import java.util.ArrayList;
38 import java.util.Date;
39 import java.util.List;
40
41 @WebService(name = "HoldService", serviceName = "HoldService", portName = "HoldService",
42 targetNamespace = "http://student.kuali.org/wsdl/hold")
43 @Transactional(readOnly = true, noRollbackFor = {DoesNotExistException.class}, rollbackFor = {Throwable.class})
44 public class HoldServiceImpl
45 implements HoldService {
46
47 private HoldIssueDao holdIssueDao;
48 private AppliedHoldDao appliedHoldDao;
49 private CriteriaLookupService criteriaLookupService;
50
51 public HoldIssueDao getHoldIssueDao() {
52 return holdIssueDao;
53 }
54
55 public void setHoldIssueDao(HoldIssueDao holdIssueDao) {
56 this.holdIssueDao = holdIssueDao;
57 }
58
59 public AppliedHoldDao getAppliedHoldDao() {
60 return appliedHoldDao;
61 }
62
63 public void setAppliedHoldDao(AppliedHoldDao appliedHoldDao) {
64 this.appliedHoldDao = appliedHoldDao;
65 }
66
67 public void setCriteriaLookupService(CriteriaLookupService criteriaLookupService) {
68 this.criteriaLookupService = criteriaLookupService;
69 }
70
71 public CriteriaLookupService getCriteriaLookupService() {
72 return criteriaLookupService;
73 }
74
75 @Override
76 @Transactional(readOnly = true)
77 public AppliedHoldInfo getAppliedHold(String holdId,
78 ContextInfo context)
79 throws DoesNotExistException,
80 InvalidParameterException,
81 MissingParameterException,
82 OperationFailedException,
83 PermissionDeniedException {
84 AppliedHoldEntity entity = appliedHoldDao.find(holdId);
85 if (entity == null) {
86 throw new DoesNotExistException(holdId);
87 }
88 return entity.toDto();
89 }
90
91 @Override
92 @Transactional(readOnly = true)
93 public List<String> searchForAppliedHoldIds(QueryByCriteria criteria,
94 ContextInfo context)
95 throws InvalidParameterException,
96 MissingParameterException,
97 OperationFailedException,
98 PermissionDeniedException {
99 List<String> results = new ArrayList<String>();
100 GenericQueryResults<AppliedHoldEntity> appliedHolds = criteriaLookupService.lookup(AppliedHoldEntity.class, criteria);
101 if (null != appliedHolds && appliedHolds.getResults().size() > 0) {
102 for (AppliedHoldEntity appliedHold : appliedHolds.getResults()) {
103 results.add(appliedHold.getId());
104 }
105 }
106 return results;
107 }
108
109 @Override
110 @Transactional(readOnly = true)
111 public List<AppliedHoldInfo> searchForAppliedHolds(QueryByCriteria criteria,
112 ContextInfo context)
113 throws InvalidParameterException,
114 MissingParameterException,
115 OperationFailedException,
116 PermissionDeniedException {
117 List<AppliedHoldInfo> results = new ArrayList<AppliedHoldInfo>();
118 GenericQueryResults<AppliedHoldEntity> appliedHolds = criteriaLookupService.lookup(AppliedHoldEntity.class, criteria);
119 if (null != appliedHolds && appliedHolds.getResults().size() > 0) {
120 for (AppliedHoldEntity appliedHold : appliedHolds.getResults()) {
121 results.add(appliedHold.toDto());
122 }
123 }
124 return results;
125 }
126
127 @Override
128 public List<ValidationResultInfo> validateAppliedHold(String validationTypeKey,
129 AppliedHoldInfo holdInfo,
130 ContextInfo context)
131 throws DoesNotExistException,
132 InvalidParameterException,
133 MissingParameterException,
134 OperationFailedException {
135 return new ArrayList<ValidationResultInfo>();
136 }
137
138 @Override
139 @Transactional
140 public AppliedHoldInfo createAppliedHold(String personId,
141 String issueId,
142 String holdTypeKey,
143 AppliedHoldInfo holdInfo,
144 ContextInfo context)
145 throws
146 DataValidationErrorException,
147 InvalidParameterException,
148 MissingParameterException,
149 OperationFailedException,
150 PermissionDeniedException {
151 holdInfo.setPersonId(personId);
152 holdInfo.setHoldIssueId(issueId);
153 holdInfo.setTypeKey(holdTypeKey);
154
155 HoldIssueEntity holdIssueEntity = holdIssueDao.find(issueId);
156 if (holdIssueEntity == null) {
157 throw new InvalidParameterException(issueId);
158 }
159 AppliedHoldEntity entity = new AppliedHoldEntity(holdInfo);
160 entity.setHoldIssue(holdIssueEntity);
161 entity.setEntityCreated(context);
162 appliedHoldDao.persist(entity);
163 return entity.toDto();
164 }
165
166 @Override
167 @Transactional
168 public AppliedHoldInfo updateAppliedHold(String holdId,
169 AppliedHoldInfo holdInfo,
170 ContextInfo context)
171 throws DataValidationErrorException,
172 DoesNotExistException,
173 InvalidParameterException,
174 MissingParameterException,
175 OperationFailedException,
176 PermissionDeniedException,
177 VersionMismatchException {
178 if (!holdId.equals(holdInfo.getId())) {
179 throw new InvalidParameterException(holdId + " does not match the id in the object " + holdInfo.getId());
180 }
181 AppliedHoldEntity entity = appliedHoldDao.find(holdId);
182 if (null == entity) {
183 throw new DoesNotExistException(holdId);
184 }
185 entity.fromDto(holdInfo);
186 entity.setEntityUpdated(context);
187 entity = appliedHoldDao.merge(entity);
188 appliedHoldDao.getEm().flush();
189 return entity.toDto();
190 }
191
192 @Override
193 @Transactional
194 public AppliedHoldInfo releaseAppliedHold(String holdId,
195 ContextInfo context)
196 throws DoesNotExistException,
197 InvalidParameterException,
198 MissingParameterException,
199 OperationFailedException,
200 PermissionDeniedException {
201 AppliedHoldInfo info = this.getAppliedHold(holdId, context);
202 info.setStateKey(HoldServiceConstants.HOLD_RELEASED_STATE_KEY);
203 info.setReleasedDate(new Date());
204 try {
205 return updateAppliedHold(holdId, info, context);
206 } catch (DataValidationErrorException ex) {
207 throw new OperationFailedException("unexpected", ex);
208 } catch (VersionMismatchException ex) {
209 throw new OperationFailedException("unexpected", ex);
210 }
211 }
212
213 @Override
214 @Transactional
215 public StatusInfo deleteAppliedHold(String holdId,
216 ContextInfo context)
217 throws DoesNotExistException,
218 InvalidParameterException,
219 MissingParameterException,
220 OperationFailedException,
221 PermissionDeniedException {
222 AppliedHoldEntity entity = appliedHoldDao.find(holdId);
223 if (null == entity) {
224 throw new DoesNotExistException(holdId);
225 }
226 appliedHoldDao.remove(entity);
227 StatusInfo status = new StatusInfo();
228 status.setSuccess(Boolean.TRUE);
229 return status;
230 }
231
232 @Override
233 @Transactional(readOnly = true)
234 public HoldIssueInfo getHoldIssue(String issueId,
235 ContextInfo context)
236 throws DoesNotExistException,
237 InvalidParameterException,
238 MissingParameterException,
239 OperationFailedException,
240 PermissionDeniedException {
241 HoldIssueEntity entity = holdIssueDao.find(issueId);
242 if (entity == null) {
243 throw new DoesNotExistException(issueId);
244 }
245 return entity.toDto();
246 }
247
248 @Override
249 @Transactional(readOnly = true)
250 public List<String> getHoldIssueIdsByType(String issueTypeKey,
251 ContextInfo context)
252 throws InvalidParameterException,
253 MissingParameterException,
254 OperationFailedException,
255 PermissionDeniedException {
256 return holdIssueDao.getIdsByType(issueTypeKey);
257 }
258
259 @Override
260 @Transactional(readOnly = true)
261 public List<HoldIssueInfo> getHoldIssuesByOrg(String organizationId,
262 ContextInfo context)
263 throws InvalidParameterException,
264 MissingParameterException,
265 OperationFailedException,
266 PermissionDeniedException {
267 List<HoldIssueEntity> holdIssues = holdIssueDao.getByOrganizationId(organizationId);
268 List<HoldIssueInfo> results = new ArrayList<HoldIssueInfo>(holdIssues.size());
269 for (HoldIssueEntity holdIssue : holdIssues) {
270 results.add(holdIssue.toDto());
271 }
272 return results;
273 }
274
275 @Override
276 @Transactional(readOnly = true)
277 public List<String> searchForHoldIssueIds(QueryByCriteria criteria,
278 ContextInfo context)
279 throws InvalidParameterException,
280 MissingParameterException,
281 OperationFailedException,
282 PermissionDeniedException {
283 List<String> results = new ArrayList<String>();
284 GenericQueryResults<HoldIssueEntity> holdIssues = criteriaLookupService.lookup(HoldIssueEntity.class, criteria);
285 if (null != holdIssues && holdIssues.getResults().size() > 0) {
286 for (HoldIssueEntity holdIssue : holdIssues.getResults()) {
287 results.add(holdIssue.getId());
288 }
289 }
290 return results;
291 }
292
293 @Override
294 @Transactional(readOnly = true)
295 public List<HoldIssueInfo> searchForHoldIssues(QueryByCriteria criteria,
296 ContextInfo context)
297 throws InvalidParameterException,
298 MissingParameterException,
299 OperationFailedException,
300 PermissionDeniedException {
301 List<HoldIssueInfo> results = new ArrayList<HoldIssueInfo>();
302 GenericQueryResults<HoldIssueEntity> holdIssues = criteriaLookupService.lookup(HoldIssueEntity.class, criteria);
303 if (null != holdIssues && holdIssues.getResults().size() > 0) {
304 for (HoldIssueEntity holdIssue : holdIssues.getResults()) {
305 results.add(holdIssue.toDto());
306 }
307 }
308 return results;
309 }
310
311 @Override
312 public List<ValidationResultInfo> validateHoldIssue(String validationTypeKey,
313 HoldIssueInfo issueInfo,
314 ContextInfo context)
315 throws DoesNotExistException,
316 InvalidParameterException,
317 MissingParameterException,
318 OperationFailedException {
319 return new ArrayList<ValidationResultInfo>();
320 }
321
322 @Override
323 @Transactional
324 public HoldIssueInfo createHoldIssue(String issueTypeKey,
325 HoldIssueInfo issueInfo,
326 ContextInfo context)
327 throws DataValidationErrorException,
328 InvalidParameterException,
329 MissingParameterException,
330 OperationFailedException,
331 PermissionDeniedException {
332 issueInfo.setTypeKey(issueTypeKey);
333 HoldIssueEntity entity = new HoldIssueEntity(issueInfo);
334 entity.setEntityCreated(context);
335 holdIssueDao.persist(entity);
336 return entity.toDto();
337 }
338
339 @Override
340 @Transactional
341 public HoldIssueInfo updateHoldIssue(String issueId,
342 HoldIssueInfo issueInfo,
343 ContextInfo context)
344 throws DataValidationErrorException,
345 DoesNotExistException,
346 InvalidParameterException,
347 MissingParameterException,
348 OperationFailedException,
349 PermissionDeniedException,
350 VersionMismatchException {
351 if (!issueId.equals(issueInfo.getId())) {
352 throw new InvalidParameterException(issueId + " does not match the id in the object " + issueInfo.getId());
353 }
354 HoldIssueEntity entity = holdIssueDao.find(issueId);
355 if (null == entity) {
356 throw new DoesNotExistException(issueId);
357 }
358 entity.fromDto(issueInfo);
359 entity.setEntityUpdated(context);
360 entity = holdIssueDao.merge(entity);
361 holdIssueDao.getEm().flush();
362 return entity.toDto();
363 }
364
365 @Override
366 @Transactional
367 public StatusInfo deleteHoldIssue(String issueId,
368 ContextInfo contextInfo)
369 throws DoesNotExistException,
370 InvalidParameterException,
371 MissingParameterException,
372 OperationFailedException,
373 PermissionDeniedException,
374 DependentObjectsExistException {
375 HoldIssueEntity entity = holdIssueDao.find(issueId);
376 if (null == entity) {
377 throw new DoesNotExistException(issueId);
378 }
379 List<String> list = this.getAppliedHoldIdsByIssue(issueId, contextInfo);
380 if (!list.isEmpty()) {
381 throw new DependentObjectsExistException(list.size() + " hold(s) with this issue");
382 }
383 holdIssueDao.remove(entity);
384 StatusInfo status = new StatusInfo();
385 status.setSuccess(Boolean.TRUE);
386 return status;
387 }
388
389 @Override
390 @Transactional(readOnly = true)
391 public List<AppliedHoldInfo> getAppliedHoldsByIds(List<String> holdIds,
392 ContextInfo contextInfo)
393 throws DoesNotExistException,
394 InvalidParameterException,
395 MissingParameterException,
396 OperationFailedException,
397 PermissionDeniedException {
398 List<AppliedHoldEntity> entities = appliedHoldDao.findByIds(holdIds);
399 List<AppliedHoldInfo> result = new ArrayList<AppliedHoldInfo>(entities.size());
400 for (AppliedHoldEntity entity : entities) {
401 if (entity == null) {
402
403 throw new DoesNotExistException();
404 }
405 result.add(entity.toDto());
406 }
407 return result;
408 }
409
410 @Override
411 @Transactional(readOnly = true)
412 public List<String> getAppliedHoldIdsByType(String holdTypeKey,
413 ContextInfo contextInfo)
414 throws InvalidParameterException,
415 MissingParameterException,
416 OperationFailedException,
417 PermissionDeniedException {
418 return appliedHoldDao.getIdsByType(holdTypeKey);
419 }
420
421 @Override
422 @Transactional(readOnly = true)
423 public List<String> getAppliedHoldIdsByIssue(String issueId,
424 ContextInfo contextInfo)
425 throws InvalidParameterException,
426 MissingParameterException,
427 OperationFailedException,
428 PermissionDeniedException {
429 return appliedHoldDao.getIdsByIssue(issueId);
430 }
431
432 @Override
433 @Transactional(readOnly = true)
434 public List<AppliedHoldInfo> getAppliedHoldsByPerson(String personId,
435 ContextInfo contextInfo)
436 throws InvalidParameterException,
437 MissingParameterException,
438 OperationFailedException,
439 PermissionDeniedException {
440 List<AppliedHoldEntity> entities = this.appliedHoldDao.getByPerson(personId);
441 List<AppliedHoldInfo> result = new ArrayList<AppliedHoldInfo>(entities.size());
442 for (AppliedHoldEntity entity : entities) {
443 result.add(entity.toDto());
444 }
445 return result;
446 }
447
448 @Override
449 @Transactional(readOnly = true)
450 public List<AppliedHoldInfo> getActiveAppliedHoldsByPerson(String personId,
451 ContextInfo contextInfo)
452 throws InvalidParameterException,
453 MissingParameterException,
454 OperationFailedException,
455 PermissionDeniedException {
456 Date now = new Date();
457 List<AppliedHoldEntity> entities = this.appliedHoldDao.getByPersonAndState(personId, HoldServiceConstants.HOLD_ACTIVE_STATE_KEY);
458 List<AppliedHoldInfo> result = new ArrayList<AppliedHoldInfo>(entities.size());
459 for (AppliedHoldEntity entity : entities) {
460 AppliedHoldInfo info = entity.toDto();
461 if (EffectiveDateUtils.isTargetDateEffective(info.getEffectiveDate(), info.getReleasedDate(), now)) {
462 result.add(info);
463 }
464 }
465 return result;
466 }
467
468 @Override
469 @Transactional(readOnly = true)
470 public List<AppliedHoldInfo> getAppliedHoldsByIssueAndPerson(String issueId,
471 String personId,
472 ContextInfo contextInfo)
473 throws InvalidParameterException,
474 MissingParameterException,
475 OperationFailedException,
476 PermissionDeniedException {
477 List<AppliedHoldEntity> entities = this.appliedHoldDao.getByIssueAndPerson(issueId, personId);
478 List<AppliedHoldInfo> result = new ArrayList<AppliedHoldInfo>(entities.size());
479 for (AppliedHoldEntity entity : entities) {
480 result.add(entity.toDto());
481 }
482 return result;
483 }
484
485 @Override
486 @Transactional(readOnly = true)
487 public List<AppliedHoldInfo> getActiveAppliedHoldsByIssueAndPerson(String issueId,
488 String personId,
489 ContextInfo contextInfo)
490 throws InvalidParameterException,
491 MissingParameterException,
492 OperationFailedException,
493 PermissionDeniedException {
494 Date now = new Date();
495 List<AppliedHoldEntity> entities = this.appliedHoldDao.getByIssuePersonAndState(issueId, personId,
496 HoldServiceConstants.HOLD_ACTIVE_STATE_KEY);
497 List<AppliedHoldInfo> result = new ArrayList<AppliedHoldInfo>(entities.size());
498 for (AppliedHoldEntity entity : entities) {
499 AppliedHoldInfo info = entity.toDto();
500 if (EffectiveDateUtils.isTargetDateEffective(info.getEffectiveDate(), info.getReleasedDate(), now)) {
501 result.add(info);
502 }
503 }
504 return result;
505 }
506
507 @Override
508 @Transactional(readOnly = true)
509 public List<HoldIssueInfo> getHoldIssuesByIds(List<String> issueIds,
510 ContextInfo contextInfo)
511 throws DoesNotExistException,
512 InvalidParameterException,
513 MissingParameterException,
514 OperationFailedException,
515 PermissionDeniedException {
516 List<HoldIssueEntity> holdIssues = holdIssueDao.findByIds(issueIds);
517 List<HoldIssueInfo> result = new ArrayList<HoldIssueInfo>(holdIssues.size());
518 for (HoldIssueEntity entity : holdIssues) {
519 if (entity == null) {
520
521 throw new DoesNotExistException();
522 }
523 result.add(entity.toDto());
524 }
525 return result;
526 }
527 }