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 appliedHoldDao.getEm().flush();
164 return entity.toDto();
165 }
166
167 @Override
168 @Transactional
169 public AppliedHoldInfo updateAppliedHold(String holdId,
170 AppliedHoldInfo holdInfo,
171 ContextInfo context)
172 throws DataValidationErrorException,
173 DoesNotExistException,
174 InvalidParameterException,
175 MissingParameterException,
176 OperationFailedException,
177 PermissionDeniedException,
178 VersionMismatchException {
179 if (!holdId.equals(holdInfo.getId())) {
180 throw new InvalidParameterException(holdId + " does not match the id in the object " + holdInfo.getId());
181 }
182 AppliedHoldEntity entity = appliedHoldDao.find(holdId);
183 if (null == entity) {
184 throw new DoesNotExistException(holdId);
185 }
186 entity.fromDto(holdInfo);
187 entity.setEntityUpdated(context);
188 entity = appliedHoldDao.merge(entity);
189 appliedHoldDao.getEm().flush();
190 return entity.toDto();
191 }
192
193 @Override
194 @Transactional
195 public AppliedHoldInfo releaseAppliedHold(String holdId,
196 ContextInfo context)
197 throws DoesNotExistException,
198 InvalidParameterException,
199 MissingParameterException,
200 OperationFailedException,
201 PermissionDeniedException {
202 AppliedHoldInfo info = this.getAppliedHold(holdId, context);
203 info.setStateKey(HoldServiceConstants.HOLD_RELEASED_STATE_KEY);
204 info.setReleasedDate(new Date());
205 try {
206 return updateAppliedHold(holdId, info, context);
207 } catch (DataValidationErrorException ex) {
208 throw new OperationFailedException("unexpected", ex);
209 } catch (VersionMismatchException ex) {
210 throw new OperationFailedException("unexpected", ex);
211 }
212 }
213
214 @Override
215 @Transactional
216 public StatusInfo deleteAppliedHold(String holdId,
217 ContextInfo context)
218 throws DoesNotExistException,
219 InvalidParameterException,
220 MissingParameterException,
221 OperationFailedException,
222 PermissionDeniedException {
223 AppliedHoldEntity entity = appliedHoldDao.find(holdId);
224 if (null == entity) {
225 throw new DoesNotExistException(holdId);
226 }
227 appliedHoldDao.remove(entity);
228 StatusInfo status = new StatusInfo();
229 status.setSuccess(Boolean.TRUE);
230 return status;
231 }
232
233 @Override
234 @Transactional(readOnly = true)
235 public HoldIssueInfo getHoldIssue(String issueId,
236 ContextInfo context)
237 throws DoesNotExistException,
238 InvalidParameterException,
239 MissingParameterException,
240 OperationFailedException,
241 PermissionDeniedException {
242 HoldIssueEntity entity = holdIssueDao.find(issueId);
243 if (entity == null) {
244 throw new DoesNotExistException(issueId);
245 }
246 return entity.toDto();
247 }
248
249 @Override
250 @Transactional(readOnly = true)
251 public List<String> getHoldIssueIdsByType(String issueTypeKey,
252 ContextInfo context)
253 throws InvalidParameterException,
254 MissingParameterException,
255 OperationFailedException,
256 PermissionDeniedException {
257 return holdIssueDao.getIdsByType(issueTypeKey);
258 }
259
260 @Override
261 @Transactional(readOnly = true)
262 public List<HoldIssueInfo> getHoldIssuesByOrg(String organizationId,
263 ContextInfo context)
264 throws InvalidParameterException,
265 MissingParameterException,
266 OperationFailedException,
267 PermissionDeniedException {
268 List<HoldIssueEntity> holdIssues = holdIssueDao.getByOrganizationId(organizationId);
269 List<HoldIssueInfo> results = new ArrayList<HoldIssueInfo>(holdIssues.size());
270 for (HoldIssueEntity holdIssue : holdIssues) {
271 results.add(holdIssue.toDto());
272 }
273 return results;
274 }
275
276 @Override
277 @Transactional(readOnly = true)
278 public List<String> searchForHoldIssueIds(QueryByCriteria criteria,
279 ContextInfo context)
280 throws InvalidParameterException,
281 MissingParameterException,
282 OperationFailedException,
283 PermissionDeniedException {
284 List<String> results = new ArrayList<String>();
285 GenericQueryResults<HoldIssueEntity> holdIssues = criteriaLookupService.lookup(HoldIssueEntity.class, criteria);
286 if (null != holdIssues && holdIssues.getResults().size() > 0) {
287 for (HoldIssueEntity holdIssue : holdIssues.getResults()) {
288 results.add(holdIssue.getId());
289 }
290 }
291 return results;
292 }
293
294 @Override
295 @Transactional(readOnly = true)
296 public List<HoldIssueInfo> searchForHoldIssues(QueryByCriteria criteria,
297 ContextInfo context)
298 throws InvalidParameterException,
299 MissingParameterException,
300 OperationFailedException,
301 PermissionDeniedException {
302 List<HoldIssueInfo> results = new ArrayList<HoldIssueInfo>();
303 GenericQueryResults<HoldIssueEntity> holdIssues = criteriaLookupService.lookup(HoldIssueEntity.class, criteria);
304 if (null != holdIssues && holdIssues.getResults().size() > 0) {
305 for (HoldIssueEntity holdIssue : holdIssues.getResults()) {
306 results.add(holdIssue.toDto());
307 }
308 }
309 return results;
310 }
311
312 @Override
313 public List<ValidationResultInfo> validateHoldIssue(String validationTypeKey,
314 HoldIssueInfo issueInfo,
315 ContextInfo context)
316 throws DoesNotExistException,
317 InvalidParameterException,
318 MissingParameterException,
319 OperationFailedException {
320 return new ArrayList<ValidationResultInfo>();
321 }
322
323 @Override
324 @Transactional
325 public HoldIssueInfo createHoldIssue(String issueTypeKey,
326 HoldIssueInfo issueInfo,
327 ContextInfo context)
328 throws DataValidationErrorException,
329 InvalidParameterException,
330 MissingParameterException,
331 OperationFailedException,
332 PermissionDeniedException {
333 issueInfo.setTypeKey(issueTypeKey);
334 HoldIssueEntity entity = new HoldIssueEntity(issueInfo);
335 entity.setEntityCreated(context);
336 holdIssueDao.persist(entity);
337 holdIssueDao.getEm().flush();
338 return entity.toDto();
339 }
340
341 @Override
342 @Transactional
343 public HoldIssueInfo updateHoldIssue(String issueId,
344 HoldIssueInfo issueInfo,
345 ContextInfo context)
346 throws DataValidationErrorException,
347 DoesNotExistException,
348 InvalidParameterException,
349 MissingParameterException,
350 OperationFailedException,
351 PermissionDeniedException,
352 VersionMismatchException {
353 if (!issueId.equals(issueInfo.getId())) {
354 throw new InvalidParameterException(issueId + " does not match the id in the object " + issueInfo.getId());
355 }
356 HoldIssueEntity entity = holdIssueDao.find(issueId);
357 if (null == entity) {
358 throw new DoesNotExistException(issueId);
359 }
360 entity.fromDto(issueInfo);
361 entity.setEntityUpdated(context);
362 entity = holdIssueDao.merge(entity);
363 holdIssueDao.getEm().flush();
364 return entity.toDto();
365 }
366
367 @Override
368 @Transactional
369 public StatusInfo deleteHoldIssue(String issueId,
370 ContextInfo contextInfo)
371 throws DoesNotExistException,
372 InvalidParameterException,
373 MissingParameterException,
374 OperationFailedException,
375 PermissionDeniedException,
376 DependentObjectsExistException {
377 HoldIssueEntity entity = holdIssueDao.find(issueId);
378 if (null == entity) {
379 throw new DoesNotExistException(issueId);
380 }
381 List<String> list = this.getAppliedHoldIdsByIssue(issueId, contextInfo);
382 if (!list.isEmpty()) {
383 throw new DependentObjectsExistException(list.size() + " hold(s) with this issue");
384 }
385 holdIssueDao.remove(entity);
386 StatusInfo status = new StatusInfo();
387 status.setSuccess(Boolean.TRUE);
388 return status;
389 }
390
391 @Override
392 @Transactional(readOnly = true)
393 public List<AppliedHoldInfo> getAppliedHoldsByIds(List<String> holdIds,
394 ContextInfo contextInfo)
395 throws DoesNotExistException,
396 InvalidParameterException,
397 MissingParameterException,
398 OperationFailedException,
399 PermissionDeniedException {
400 List<AppliedHoldEntity> entities = appliedHoldDao.findByIds(holdIds);
401 List<AppliedHoldInfo> result = new ArrayList<AppliedHoldInfo>(entities.size());
402 for (AppliedHoldEntity entity : entities) {
403 if (entity == null) {
404
405 throw new DoesNotExistException();
406 }
407 result.add(entity.toDto());
408 }
409 return result;
410 }
411
412 @Override
413 @Transactional(readOnly = true)
414 public List<String> getAppliedHoldIdsByType(String holdTypeKey,
415 ContextInfo contextInfo)
416 throws InvalidParameterException,
417 MissingParameterException,
418 OperationFailedException,
419 PermissionDeniedException {
420 return appliedHoldDao.getIdsByType(holdTypeKey);
421 }
422
423 @Override
424 @Transactional(readOnly = true)
425 public List<String> getAppliedHoldIdsByIssue(String issueId,
426 ContextInfo contextInfo)
427 throws InvalidParameterException,
428 MissingParameterException,
429 OperationFailedException,
430 PermissionDeniedException {
431 return appliedHoldDao.getIdsByIssue(issueId);
432 }
433
434 @Override
435 @Transactional(readOnly = true)
436 public List<AppliedHoldInfo> getAppliedHoldsByPerson(String personId,
437 ContextInfo contextInfo)
438 throws InvalidParameterException,
439 MissingParameterException,
440 OperationFailedException,
441 PermissionDeniedException {
442 List<AppliedHoldEntity> entities = this.appliedHoldDao.getByPerson(personId);
443 List<AppliedHoldInfo> result = new ArrayList<AppliedHoldInfo>(entities.size());
444 for (AppliedHoldEntity entity : entities) {
445 result.add(entity.toDto());
446 }
447 return result;
448 }
449
450 @Override
451 @Transactional(readOnly = true)
452 public List<AppliedHoldInfo> getActiveAppliedHoldsByPerson(String personId,
453 ContextInfo contextInfo)
454 throws InvalidParameterException,
455 MissingParameterException,
456 OperationFailedException,
457 PermissionDeniedException {
458 Date now = new Date();
459 List<AppliedHoldEntity> entities = this.appliedHoldDao.getByPersonAndState(personId, HoldServiceConstants.HOLD_ACTIVE_STATE_KEY);
460 List<AppliedHoldInfo> result = new ArrayList<AppliedHoldInfo>(entities.size());
461 for (AppliedHoldEntity entity : entities) {
462 AppliedHoldInfo info = entity.toDto();
463 if (EffectiveDateUtils.isTargetDateEffective(info.getEffectiveDate(), info.getReleasedDate(), now)) {
464 result.add(info);
465 }
466 }
467 return result;
468 }
469
470 @Override
471 @Transactional(readOnly = true)
472 public List<AppliedHoldInfo> getAppliedHoldsByIssueAndPerson(String issueId,
473 String personId,
474 ContextInfo contextInfo)
475 throws InvalidParameterException,
476 MissingParameterException,
477 OperationFailedException,
478 PermissionDeniedException {
479 List<AppliedHoldEntity> entities = this.appliedHoldDao.getByIssueAndPerson(issueId, personId);
480 List<AppliedHoldInfo> result = new ArrayList<AppliedHoldInfo>(entities.size());
481 for (AppliedHoldEntity entity : entities) {
482 result.add(entity.toDto());
483 }
484 return result;
485 }
486
487 @Override
488 @Transactional(readOnly = true)
489 public List<AppliedHoldInfo> getActiveAppliedHoldsByIssueAndPerson(String issueId,
490 String personId,
491 ContextInfo contextInfo)
492 throws InvalidParameterException,
493 MissingParameterException,
494 OperationFailedException,
495 PermissionDeniedException {
496 Date now = new Date();
497 List<AppliedHoldEntity> entities = this.appliedHoldDao.getByIssuePersonAndState(issueId, personId,
498 HoldServiceConstants.HOLD_ACTIVE_STATE_KEY);
499 List<AppliedHoldInfo> result = new ArrayList<AppliedHoldInfo>(entities.size());
500 for (AppliedHoldEntity entity : entities) {
501 AppliedHoldInfo info = entity.toDto();
502 if (EffectiveDateUtils.isTargetDateEffective(info.getEffectiveDate(), info.getReleasedDate(), now)) {
503 result.add(info);
504 }
505 }
506 return result;
507 }
508
509 @Override
510 @Transactional(readOnly = true)
511 public List<HoldIssueInfo> getHoldIssuesByIds(List<String> issueIds,
512 ContextInfo contextInfo)
513 throws DoesNotExistException,
514 InvalidParameterException,
515 MissingParameterException,
516 OperationFailedException,
517 PermissionDeniedException {
518 List<HoldIssueEntity> holdIssues = holdIssueDao.findByIds(issueIds);
519 List<HoldIssueInfo> result = new ArrayList<HoldIssueInfo>(holdIssues.size());
520 for (HoldIssueEntity entity : holdIssues) {
521 if (entity == null) {
522
523 throw new DoesNotExistException();
524 }
525 result.add(entity.toDto());
526 }
527 return result;
528 }
529 }