1 package org.kuali.student.r2.lum.lrc.service.impl;
2
3 import org.kuali.rice.core.api.criteria.GenericQueryResults;
4 import org.kuali.rice.core.api.criteria.QueryByCriteria;
5 import org.kuali.student.r2.common.criteria.CriteriaLookupService;
6 import org.kuali.student.r2.common.dto.ContextInfo;
7 import org.kuali.student.r2.common.dto.StatusInfo;
8 import org.kuali.student.r2.common.dto.ValidationResultInfo;
9 import org.kuali.student.r2.common.exceptions.*;
10 import org.kuali.student.r2.core.search.dto.SearchParamInfo;
11 import org.kuali.student.r2.core.search.dto.SearchRequestInfo;
12 import org.kuali.student.r2.core.search.dto.SearchResultInfo;
13 import org.kuali.student.r2.core.search.dto.SearchResultRowInfo;
14 import org.kuali.student.r2.core.search.service.SearchManager;
15 import org.kuali.student.r2.core.class1.type.dto.TypeInfo;
16 import org.kuali.student.r2.lum.lrc.dao.ResultScaleDao;
17 import org.kuali.student.r2.lum.lrc.dao.ResultValueDao;
18 import org.kuali.student.r2.lum.lrc.dao.ResultValuesGroupDao;
19 import org.kuali.student.r2.lum.lrc.dto.ResultScaleInfo;
20 import org.kuali.student.r2.lum.lrc.dto.ResultValueInfo;
21 import org.kuali.student.r2.lum.lrc.dto.ResultValuesGroupInfo;
22 import org.kuali.student.r2.lum.lrc.model.ResultScaleEntity;
23 import org.kuali.student.r2.lum.lrc.model.ResultValueEntity;
24 import org.kuali.student.r2.lum.lrc.model.ResultValuesGroupEntity;
25 import org.kuali.student.r2.lum.lrc.service.LRCService;
26 import org.kuali.student.r2.lum.lrc.service.LrcServiceBusinessLogic;
27 import org.springframework.transaction.annotation.Transactional;
28
29 import javax.jws.WebParam;
30 import java.util.ArrayList;
31 import java.util.HashSet;
32 import java.util.List;
33 import java.util.Set;
34
35 public class LRCServiceImpl implements LRCService {
36
37 private ResultValuesGroupDao resultValuesGroupDao;
38 private ResultValueDao resultValueDao;
39 private ResultScaleDao resultScaleDao;
40 private LrcServiceBusinessLogic lrcServiceBusinessLogic;
41 private SearchManager searchManager;
42 private CriteriaLookupService resultScaleCriteriaLookupService;
43 private CriteriaLookupService resultValueCriteriaLookupService;
44 private CriteriaLookupService resultValuesGroupCriteriaLookupService;
45
46 public SearchManager getSearchManager() {
47 return searchManager;
48 }
49
50 public void setSearchManager(SearchManager searchManager) {
51 this.searchManager = searchManager;
52 }
53
54 public LrcServiceBusinessLogic getLrcServiceBusinessLogic() {
55 return lrcServiceBusinessLogic;
56 }
57
58 public void setLrcServiceBusinessLogic(LrcServiceBusinessLogic lrcServiceBusinessLogic) {
59 this.lrcServiceBusinessLogic = lrcServiceBusinessLogic;
60 }
61
62 public ResultScaleDao getResultScaleDao() {
63 return resultScaleDao;
64 }
65
66 public void setResultScaleDao(ResultScaleDao resultScaleDao) {
67 this.resultScaleDao = resultScaleDao;
68 }
69
70 public ResultValueDao getResultValueDao() {
71 return resultValueDao;
72 }
73
74 public void setResultValueDao(ResultValueDao resultValueDao) {
75 this.resultValueDao = resultValueDao;
76 }
77
78 public ResultValuesGroupDao getResultValuesGroupDao() {
79 return resultValuesGroupDao;
80 }
81
82 public void setResultValuesGroupDao(ResultValuesGroupDao resultValuesGroupDao) {
83 this.resultValuesGroupDao = resultValuesGroupDao;
84 }
85
86 public CriteriaLookupService getResultScaleCriteriaLookupService() {
87 return resultScaleCriteriaLookupService;
88 }
89
90 public void setResultScaleCriteriaLookupService(CriteriaLookupService resultScaleCriteriaLookupService) {
91 this.resultScaleCriteriaLookupService = resultScaleCriteriaLookupService;
92 }
93
94 public CriteriaLookupService getResultValueCriteriaLookupService() {
95 return resultValueCriteriaLookupService;
96 }
97
98 public void setResultValueCriteriaLookupService(CriteriaLookupService resultValueCriteriaLookupService) {
99 this.resultValueCriteriaLookupService = resultValueCriteriaLookupService;
100 }
101
102 public CriteriaLookupService getResultValuesGroupCriteriaLookupService() {
103 return resultValuesGroupCriteriaLookupService;
104 }
105
106 public void setResultValuesGroupCriteriaLookupService(CriteriaLookupService resultValuesGroupCriteriaLookupService) {
107 this.resultValuesGroupCriteriaLookupService = resultValuesGroupCriteriaLookupService;
108 }
109
110
111
112
113 @Override
114 @Transactional(readOnly = false, noRollbackFor = {DoesNotExistException.class}, rollbackFor = {Throwable.class})
115 public ResultScaleInfo createResultScale(String typeKey,
116 ResultScaleInfo info,
117 ContextInfo contextInfo)
118 throws AlreadyExistsException,
119 DataValidationErrorException,
120 InvalidParameterException,
121 MissingParameterException,
122 OperationFailedException,
123 PermissionDeniedException {
124 ResultScaleEntity entity = this.resultScaleDao.find(info.getKey());
125 if (entity != null) {
126 throw new AlreadyExistsException(info.getKey());
127 }
128 info.setTypeKey(typeKey);
129 entity = new ResultScaleEntity(info);
130 entity.setEntityCreated(contextInfo);
131 resultScaleDao.persist(entity);
132
133 resultScaleDao.getEm().flush();
134
135 return entity.toDto();
136 }
137
138 @Override
139 @Transactional(readOnly = false, noRollbackFor = {DoesNotExistException.class}, rollbackFor = {Throwable.class})
140 public ResultValueInfo createResultValue(String resultScaleKey,
141 String typeKey,
142 ResultValueInfo info,
143 ContextInfo contextInfo)
144 throws AlreadyExistsException,
145 DataValidationErrorException,
146 DoesNotExistException,
147 InvalidParameterException,
148 MissingParameterException,
149 OperationFailedException,
150 PermissionDeniedException {
151 ResultValueEntity entity = this.resultValueDao.find(info.getKey());
152 if (entity != null) {
153 throw new AlreadyExistsException(info.getKey());
154 }
155 info.setResultScaleKey(resultScaleKey);
156 info.setTypeKey(typeKey);
157 entity = new ResultValueEntity(info);
158 entity.setEntityCreated(contextInfo);
159 resultValueDao.persist(entity);
160 resultValueDao.getEm().flush();
161 return entity.toDto();
162 }
163
164 @Override
165 @Transactional(readOnly = false, noRollbackFor = {DoesNotExistException.class}, rollbackFor = {Throwable.class})
166 public ResultValuesGroupInfo createResultValuesGroup(String resultScaleKey,
167 String typeKey,
168 ResultValuesGroupInfo info,
169 ContextInfo contextInfo)
170 throws AlreadyExistsException,
171 DataValidationErrorException,
172 InvalidParameterException,
173 MissingParameterException,
174 OperationFailedException,
175 PermissionDeniedException {
176 ResultValuesGroupEntity entity = this.resultValuesGroupDao.find(info.getKey());
177 if (entity != null) {
178 throw new AlreadyExistsException(info.getKey());
179 }
180 info.setResultScaleKey(resultScaleKey);
181 info.setTypeKey(typeKey);
182 entity = new ResultValuesGroupEntity(info);
183 entity.setEntityCreated(contextInfo);
184 resultValuesGroupDao.persist(entity);
185 resultValuesGroupDao.getEm().flush();
186 return entity.toDto();
187 }
188
189 @Override
190 @Transactional(readOnly = false, noRollbackFor = {DoesNotExistException.class}, rollbackFor = {Throwable.class})
191 public StatusInfo deleteResultScale(String key,
192 ContextInfo contextInfo)
193 throws DoesNotExistException,
194 DependentObjectsExistException,
195 InvalidParameterException,
196 MissingParameterException,
197 OperationFailedException,
198 PermissionDeniedException {
199 ResultScaleEntity entity = resultScaleDao.find(key);
200 if (entity == null) {
201 throw new DoesNotExistException(key);
202 }
203 List<ResultValuesGroupInfo> list = this.getResultValuesGroupsByResultScale(key, contextInfo);
204 if (!list.isEmpty()) {
205 throw new DependentObjectsExistException(list.size() + " rvgs exist");
206 }
207 List<ResultValueInfo> list2 = this.getResultValuesForScale(key, contextInfo);
208 if (!list2.isEmpty()) {
209 throw new DependentObjectsExistException(list2.size() + " values exist");
210 }
211 resultScaleDao.remove(entity);
212 StatusInfo status = new StatusInfo();
213 status.setSuccess(Boolean.TRUE);
214 return status;
215 }
216
217 @Override
218 @Transactional(readOnly = false, noRollbackFor = {DoesNotExistException.class}, rollbackFor = {Throwable.class})
219 public StatusInfo deleteResultValue(String key,
220 ContextInfo contextInfo)
221 throws DoesNotExistException,
222 DependentObjectsExistException,
223 InvalidParameterException,
224 MissingParameterException,
225 OperationFailedException,
226 PermissionDeniedException {
227 ResultValueEntity entity = resultValueDao.find(key);
228 if (entity == null) {
229 throw new DoesNotExistException(key);
230 }
231 List<ResultValuesGroupInfo> list = this.getResultValuesGroupsByResultValue(key, contextInfo);
232 if (!list.isEmpty()) {
233 throw new DependentObjectsExistException(list.size() + " rvgs exist");
234 }
235 resultValueDao.remove(entity);
236 StatusInfo status = new StatusInfo();
237 status.setSuccess(Boolean.TRUE);
238 return status;
239 }
240
241 @Override
242 @Transactional(readOnly = false, noRollbackFor = {DoesNotExistException.class}, rollbackFor = {Throwable.class})
243 public StatusInfo deleteResultValuesGroup(String key,
244 ContextInfo contextInfo)
245 throws DoesNotExistException,
246 InvalidParameterException,
247 MissingParameterException,
248 OperationFailedException,
249 PermissionDeniedException {
250 ResultValuesGroupEntity entity = resultValuesGroupDao.find(key);
251 if (entity == null) {
252 throw new DoesNotExistException(key);
253 }
254 resultValuesGroupDao.remove(entity);
255 StatusInfo status = new StatusInfo();
256 status.setSuccess(Boolean.TRUE);
257 return status;
258 }
259
260 @Override
261 @Transactional(readOnly = false, noRollbackFor = {DoesNotExistException.class}, rollbackFor = {Throwable.class})
262 public ResultValuesGroupInfo getCreateFixedCreditResultValuesGroup(String creditValue,
263 String scaleKey,
264 ContextInfo context)
265 throws InvalidParameterException,
266 MissingParameterException,
267 OperationFailedException,
268 PermissionDeniedException {
269 return this.getLrcServiceBusinessLogic().getCreateFixedCreditResultValuesGroup(creditValue, scaleKey, context);
270 }
271
272 @Override
273 @Transactional(readOnly = false, noRollbackFor = {DoesNotExistException.class}, rollbackFor = {Throwable.class})
274 public ResultValuesGroupInfo getCreateRangeCreditResultValuesGroup(String creditValueMin,
275 String creditValueMax,
276 String creditValueIncrement,
277 String scaleKey,
278 ContextInfo context)
279 throws InvalidParameterException,
280 MissingParameterException,
281 OperationFailedException,
282 PermissionDeniedException {
283 ResultValuesGroupInfo rvg = this.getLrcServiceBusinessLogic().getCreateRangeCreditResultValuesGroup(creditValueMin,
284 creditValueMax,
285 creditValueIncrement, scaleKey, context);
286 return rvg;
287
288 }
289
290 @Override
291 @Transactional(readOnly = false, noRollbackFor = {DoesNotExistException.class}, rollbackFor = {Throwable.class})
292 public ResultValuesGroupInfo getCreateMultipleCreditResultValuesGroup(List<String> creditValues,
293 String scaleKey,
294 ContextInfo context)
295 throws InvalidParameterException,
296 MissingParameterException,
297 OperationFailedException,
298 PermissionDeniedException {
299 return this.getLrcServiceBusinessLogic().getCreateMultipleCreditResultValuesGroup(creditValues, scaleKey, context);
300 }
301
302 @Override
303 @Transactional(readOnly = false, noRollbackFor = {DoesNotExistException.class}, rollbackFor = {Throwable.class})
304 public ResultValueInfo getCreateResultValueForScale(String resultValue,
305 String scaleKey,
306 ContextInfo context)
307 throws InvalidParameterException,
308 MissingParameterException,
309 OperationFailedException,
310 PermissionDeniedException {
311 return this.getLrcServiceBusinessLogic().getCreateResultValueForScale(resultValue, scaleKey, context);
312 }
313
314 @Override
315 @Transactional(readOnly = true)
316 public ResultScaleInfo getResultScale(String key,
317 ContextInfo contextInfo)
318 throws DoesNotExistException,
319 InvalidParameterException,
320 MissingParameterException,
321 OperationFailedException,
322 PermissionDeniedException {
323 ResultScaleEntity entity = resultScaleDao.find(key);
324 if (entity == null) {
325 throw new DoesNotExistException(key);
326 }
327 return entity.toDto();
328 }
329
330 @Override
331 @Transactional(readOnly = true)
332 public List<String> getResultScaleKeysByType(String resultScaleTypeKey,
333 ContextInfo contextInfo)
334 throws DoesNotExistException,
335 InvalidParameterException,
336 MissingParameterException,
337 OperationFailedException,
338 PermissionDeniedException {
339 return resultScaleDao.getIdsByType(resultScaleTypeKey);
340 }
341
342 @Override
343 @Transactional(readOnly = true)
344 public List<ResultScaleInfo> getResultScalesByKeys(List<String> keys,
345 ContextInfo contextInfo)
346 throws DoesNotExistException,
347 InvalidParameterException,
348 MissingParameterException,
349 OperationFailedException,
350 PermissionDeniedException {
351 List<ResultScaleInfo> infos = new ArrayList<ResultScaleInfo>();
352 List<ResultScaleEntity> entities = resultScaleDao.findByIds(keys);
353 for (ResultScaleEntity entity : entities) {
354 ResultScaleInfo info = entity.toDto();
355 infos.add(info);
356 }
357 return infos;
358 }
359
360 @Override
361 @Transactional(readOnly = true)
362 public ResultValueInfo getResultValue(String key,
363 ContextInfo contextInfo)
364 throws DoesNotExistException,
365 InvalidParameterException,
366 MissingParameterException,
367 OperationFailedException,
368 PermissionDeniedException {
369 ResultValueEntity entity = resultValueDao.find(key);
370 if (entity == null) {
371 throw new DoesNotExistException(key);
372 }
373 return entity.toDto();
374 }
375
376 @Override
377 @Transactional(readOnly = true)
378 public ResultValueInfo getResultValueForScaleAndValue(String resultScaleKey,
379 String value,
380 ContextInfo contextInfo)
381 throws DoesNotExistException,
382 InvalidParameterException,
383 MissingParameterException,
384 OperationFailedException,
385 PermissionDeniedException {
386 ResultValueEntity entity = resultValueDao.getByScaleAndValue(resultScaleKey, value);
387 if (entity == null) {
388 throw new DoesNotExistException (resultScaleKey + "." + value);
389 }
390 ResultValueInfo info = entity.toDto();
391 return info;
392 }
393
394 @Override
395 @Transactional(readOnly = true)
396 public List<String> getResultValueKeysByType(String resultValueTypeKey,
397 ContextInfo contextInfo)
398 throws DoesNotExistException,
399 InvalidParameterException,
400 MissingParameterException,
401 OperationFailedException,
402 PermissionDeniedException {
403 return resultValueDao.getIdsByType(resultValueTypeKey);
404 }
405
406 @Override
407 @Transactional(readOnly = true)
408 public List<ResultValueInfo> getResultValuesByKeys(List<String> keys,
409 ContextInfo contextInfo)
410 throws DoesNotExistException,
411 InvalidParameterException,
412 MissingParameterException,
413 OperationFailedException,
414 PermissionDeniedException {
415 List<ResultValueInfo> infos = new ArrayList<ResultValueInfo>();
416 if(keys != null && !keys.isEmpty()){
417 List<ResultValueEntity> entities = resultValueDao.findByIds(keys);
418 for (ResultValueEntity entity : entities) {
419 ResultValueInfo info = entity.toDto();
420 infos.add(info);
421 }
422 }
423 return infos;
424 }
425
426 @Override
427 @Transactional(readOnly = true)
428 public List<ResultValueInfo> getResultValuesForResultValuesGroup(String resultValuesGroupKey,
429 ContextInfo contextInfo)
430 throws DoesNotExistException,
431 InvalidParameterException,
432 MissingParameterException,
433 OperationFailedException,
434 PermissionDeniedException {
435
436 ResultValuesGroupInfo info = this.getResultValuesGroup(resultValuesGroupKey, contextInfo);
437 return this.getResultValuesByKeys(info.getResultValueKeys(), contextInfo);
438 }
439
440 @Override
441 @Transactional(readOnly = true)
442 public List<ResultValueInfo> getResultValuesForResultValuesGroups(List<String> resultValuesGroupKeys,
443 ContextInfo contextInfo)
444 throws DoesNotExistException,
445 InvalidParameterException,
446 MissingParameterException,
447 OperationFailedException,
448 PermissionDeniedException {
449
450
451 List<ResultValueInfo> list = new ArrayList<ResultValueInfo>();
452 Set<String> keys = new HashSet<String>();
453 for (String rvgKey : resultValuesGroupKeys) {
454 ResultValuesGroupInfo rvg = this.getResultValuesGroup(rvgKey, contextInfo);
455 for (String rvKey : rvg.getResultValueKeys()) {
456 if (keys.add(rvKey)) {
457 list.add(this.getResultValue(rvKey, contextInfo));
458 }
459 }
460 }
461 return list;
462 }
463
464 @Override
465 @Transactional(readOnly = true)
466 public List<ResultValueInfo> getResultValuesForScale(String resultScaleKey,
467 ContextInfo contextInfo)
468 throws DoesNotExistException,
469 InvalidParameterException,
470 MissingParameterException,
471 OperationFailedException,
472 PermissionDeniedException {
473 List<ResultValueInfo> infos = new ArrayList<ResultValueInfo>();
474 List<ResultValueEntity> entities = resultValueDao.getByScale(resultScaleKey);
475 for (ResultValueEntity entity : entities) {
476 ResultValueInfo info = entity.toDto();
477 infos.add(info);
478 }
479 return infos;
480 }
481
482 @Override
483 @Transactional(readOnly = true)
484 public ResultValuesGroupInfo getResultValuesGroup(String key,
485 ContextInfo contextInfo)
486 throws DoesNotExistException,
487 InvalidParameterException,
488 MissingParameterException,
489 OperationFailedException,
490 PermissionDeniedException {
491 ResultValuesGroupEntity entity = resultValuesGroupDao.find(key);
492 if (entity == null) {
493 throw new DoesNotExistException(key);
494 }
495 return entity.toDto();
496 }
497
498 @Override
499 @Transactional(readOnly = true)
500 public List<String> getResultValuesGroupKeysByType(String resultValuesGroupTypeKey,
501 ContextInfo contextInfo)
502 throws DoesNotExistException,
503 InvalidParameterException,
504 MissingParameterException,
505 OperationFailedException,
506 PermissionDeniedException {
507 return resultValuesGroupDao.getIdsByType(resultValuesGroupTypeKey);
508 }
509
510 @Override
511 @Transactional(readOnly = true)
512 public List<ResultValuesGroupInfo> getResultValuesGroupsByKeys(List<String> keys,
513 ContextInfo contextInfo)
514 throws DoesNotExistException,
515 InvalidParameterException,
516 MissingParameterException,
517 OperationFailedException,
518 PermissionDeniedException {
519 List<ResultValuesGroupInfo> infos = new ArrayList<ResultValuesGroupInfo>();
520 List<ResultValuesGroupEntity> entities = resultValuesGroupDao.findByIds(keys);
521 for (ResultValuesGroupEntity entity : entities) {
522 ResultValuesGroupInfo info = entity.toDto();
523 infos.add(info);
524 }
525 return infos;
526 }
527
528 @Override
529 @Transactional(readOnly = true)
530 public List<ResultValuesGroupInfo> getResultValuesGroupsByResultScale(String resultScaleKey,
531 ContextInfo contextInfo)
532 throws DoesNotExistException,
533 InvalidParameterException,
534 MissingParameterException,
535 OperationFailedException,
536 PermissionDeniedException {
537 List<ResultValuesGroupInfo> infos = new ArrayList<ResultValuesGroupInfo>();
538 List<ResultValuesGroupEntity> entities = resultValuesGroupDao.getByResultScale(resultScaleKey);
539 for (ResultValuesGroupEntity entity : entities) {
540 ResultValuesGroupInfo info = entity.toDto();
541 infos.add(info);
542 }
543 return infos;
544 }
545
546 @Override
547 @Transactional(readOnly = true)
548 public List<ResultValuesGroupInfo> getResultValuesGroupsByResultScaleType(String resultScaleTypeKey,
549 ContextInfo contextInfo)
550 throws DoesNotExistException,
551 InvalidParameterException,
552 MissingParameterException,
553 OperationFailedException,
554 PermissionDeniedException {
555
556 List<ResultValuesGroupInfo> list = new ArrayList<ResultValuesGroupInfo>();
557 List<String> scaleKeys = this.getResultScaleKeysByType(resultScaleTypeKey, contextInfo);
558 for (String scaleKey : scaleKeys) {
559 list.addAll(this.getResultValuesGroupsByResultScale(scaleKey, contextInfo));
560 }
561 return list;
562 }
563
564 @Override
565 @Transactional(readOnly = true)
566 public List<ResultValuesGroupInfo> getResultValuesGroupsByResultValue(String resultValueKey,
567 ContextInfo contextInfo)
568 throws DoesNotExistException,
569 InvalidParameterException,
570 MissingParameterException,
571 OperationFailedException,
572 PermissionDeniedException {
573 List<ResultValuesGroupInfo> list = new ArrayList<ResultValuesGroupInfo>();
574 for (ResultValuesGroupEntity entity : this.resultValuesGroupDao.getByResultValue(resultValueKey)) {
575 list.add(entity.toDto());
576 }
577 return list;
578 }
579
580 @Override
581 @Transactional(readOnly = false, noRollbackFor = {DoesNotExistException.class}, rollbackFor = {Throwable.class})
582 public ResultScaleInfo updateResultScale(String key,
583 ResultScaleInfo info,
584 ContextInfo contextInfo)
585 throws DataValidationErrorException,
586 DoesNotExistException,
587 InvalidParameterException,
588 MissingParameterException,
589 OperationFailedException,
590 PermissionDeniedException,
591 VersionMismatchException {
592 if (!key.equals(info.getKey())) {
593 throw new InvalidParameterException(key + " does not match the key in the info object " + info.getKey());
594 }
595 ResultScaleEntity entity = resultScaleDao.find(key);
596 if (entity == null) {
597 throw new DoesNotExistException(key);
598 }
599 entity.fromDTO(info);
600 entity.setEntityUpdated(contextInfo);
601 entity = resultScaleDao.merge(entity);
602 resultScaleDao.getEm().flush();
603 return entity.toDto();
604 }
605
606 @Override
607 @Transactional(readOnly = false, noRollbackFor = {DoesNotExistException.class}, rollbackFor = {Throwable.class})
608 public ResultValueInfo updateResultValue(String key,
609 ResultValueInfo info,
610 ContextInfo contextInfo)
611 throws DataValidationErrorException,
612 DoesNotExistException,
613 InvalidParameterException,
614 MissingParameterException,
615 OperationFailedException,
616 PermissionDeniedException,
617 VersionMismatchException {
618 if (!key.equals(info.getKey())) {
619 throw new InvalidParameterException(key + " does not match the key in the info object " + info.getKey());
620 }
621 ResultValueEntity entity = resultValueDao.find(key);
622 if (entity == null) {
623 throw new DoesNotExistException(key);
624 }
625 entity.fromDTO(info);
626 entity.setEntityUpdated(contextInfo);
627 entity = resultValueDao.merge(entity);
628 resultValueDao.getEm().flush();
629 return entity.toDto();
630 }
631
632 @Override
633 @Transactional(readOnly = false, noRollbackFor = {DoesNotExistException.class}, rollbackFor = {Throwable.class})
634 public ResultValuesGroupInfo updateResultValuesGroup(String key,
635 ResultValuesGroupInfo info,
636 ContextInfo contextInfo)
637 throws DataValidationErrorException,
638 DoesNotExistException,
639 InvalidParameterException,
640 MissingParameterException,
641 OperationFailedException,
642 PermissionDeniedException,
643 VersionMismatchException {
644 if (!key.equals(info.getKey())) {
645 throw new InvalidParameterException(key + " does not match the key in the info object " + info.getKey());
646 }
647 ResultValuesGroupEntity entity = resultValuesGroupDao.find(key);
648 if (entity == null) {
649 throw new DoesNotExistException(key);
650 }
651 entity.fromDTO(info);
652 entity.setEntityUpdated(contextInfo);
653 entity = resultValuesGroupDao.merge(entity);
654 this.resultValuesGroupDao.getEm().flush();
655 return entity.toDto();
656 }
657
658 @Override
659 public List<ValidationResultInfo> validateResultScale(String validationType,
660 ResultScaleInfo gradeScaleInfo,
661 ContextInfo contextInfo)
662 throws DoesNotExistException,
663 InvalidParameterException,
664 MissingParameterException,
665 OperationFailedException {
666 return new ArrayList<ValidationResultInfo>();
667 }
668
669 @Override
670 public List<ValidationResultInfo> validateResultValue(String validationType,
671 ResultValueInfo resultValueInfo,
672 ContextInfo contextInfo)
673 throws DoesNotExistException,
674 InvalidParameterException,
675 MissingParameterException,
676 OperationFailedException {
677 return new ArrayList<ValidationResultInfo>();
678 }
679
680 @Override
681 public List<ValidationResultInfo> validateResultValuesGroup(String validationType,
682 ResultValuesGroupInfo gradeValuesGroupInfo,
683 ContextInfo contextInfo)
684 throws DoesNotExistException,
685 InvalidParameterException,
686 MissingParameterException,
687 OperationFailedException {
688 return new ArrayList<ValidationResultInfo>();
689 }
690
691 @Override
692 public List<TypeInfo> getSearchTypes(ContextInfo contextInfo) throws OperationFailedException, InvalidParameterException, MissingParameterException {
693 return searchManager.getSearchTypes(contextInfo);
694 }
695
696 @Override
697 public TypeInfo getSearchType(String searchTypeKey, ContextInfo contextInfo) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException {
698 return searchManager.getSearchType(searchTypeKey, contextInfo);
699 }
700
701 @Override
702 public SearchResultInfo search(SearchRequestInfo searchRequest, ContextInfo contextInfo) throws MissingParameterException, OperationFailedException, PermissionDeniedException, InvalidParameterException {
703 if (searchRequest==null) {
704 throw new MissingParameterException(searchRequest + " can not be null");
705 }
706 List<ResultValueEntity> returnValues = new ArrayList<ResultValueEntity>();
707
708 SearchResultInfo searchResult = new SearchResultInfo();
709 if ("lrc.search.resultValue".equals(searchRequest.getSearchKey())) {
710
711 String resultValueId = null;
712 String resultValueValue = null;
713 String resultComponentId = null;
714 for (SearchParamInfo parm : searchRequest.getParams()) {
715 if ((parm.getKey().equals("lrc.queryParam.resultValue.id") && (parm.getValues() != null)&& parm.getValues().get(0)!=null)) {
716 resultValueId = parm.getValues().get(0);
717 } else if ((parm.getKey().equals("lrc.queryParam.resultValue.value") && (parm.getValues() != null)&& parm.getValues().get(0)!=null)) {
718 resultValueValue = parm.getValues().get(0);
719 } else if ((parm.getKey().equals("lrc.queryParam.resultValue.resultComponent.id") && (parm.getValues() != null) && parm.getValues().get(0)!=null)) {
720 resultComponentId = parm.getValues().get(0);
721 }
722 }
723
724 try {
725
726 if (resultValueId != null){
727 ResultValueEntity resultValue = resultValueDao.find(resultValueId);
728 returnValues.add(resultValue);
729 } else if (resultComponentId != null) {
730 ResultValuesGroupEntity resultValueGroup = resultValuesGroupDao.find(resultComponentId);
731 List<String> resultValueKeys = new ArrayList<String>();
732 resultValueKeys.addAll(resultValueGroup.getResultValueKeys());
733 returnValues = resultValueDao.findByIds(resultValueKeys);
734 } else {
735 returnValues = resultValueDao.findAll();
736 }
737
738 if (resultValueValue != null) {
739 List<ResultValueEntity> resultValues = new ArrayList<ResultValueEntity>();
740 for (ResultValueEntity resultValue : returnValues) {
741 if (resultValue.getValue().equals(resultValueValue)) {
742 resultValues.add(resultValue);
743 }
744 }
745 returnValues = resultValues;
746 }
747
748 } catch (Exception e) {
749 }
750
751 if (returnValues == null) {
752 return null;
753 }
754
755 for (ResultValueEntity returnValue : returnValues) {
756 SearchResultRowInfo row = new SearchResultRowInfo();
757 row.addCell("lrc.resultColumn.resultValue.id", returnValue.getId());
758 row.addCell("lrc.resultColumn.resultValue.value", returnValue.getValue());
759 searchResult.getRows().add(row);
760 }
761 } else {
762 searchResult = searchManager.search(searchRequest, contextInfo);
763 }
764 return searchResult;
765 }
766
767 @Override
768 @Transactional(readOnly = true)
769 public List<String> searchForResultScaleIds(QueryByCriteria criteria, ContextInfo context) throws InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException {
770 GenericQueryResults<String> results = resultScaleCriteriaLookupService.lookupIds(ResultScaleEntity.class, criteria);
771 return results.getResults();
772 }
773
774 @Override
775 @Transactional(readOnly = true)
776 public List<ResultScaleInfo> searchForResultScales(QueryByCriteria criteria, ContextInfo context) throws InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException {
777 GenericQueryResults<ResultScaleEntity> results = resultScaleCriteriaLookupService.lookup(ResultScaleEntity.class, criteria);
778 List<ResultScaleInfo> infos = new ArrayList<ResultScaleInfo>(results.getResults().size());
779 for (ResultScaleEntity entity : results.getResults()) {
780 infos.add(entity.toDto());
781 }
782 return infos;
783 }
784
785 @Override
786 @Transactional(readOnly = true)
787 public List<String> searchForResultValueIds(QueryByCriteria criteria, ContextInfo context) throws InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException {
788 GenericQueryResults<String> results = resultValueCriteriaLookupService.lookupIds(ResultValueEntity.class, criteria);
789 return results.getResults();
790 }
791
792 @Override
793 @Transactional(readOnly = true)
794 public List<ResultValueInfo> searchForResultValues(QueryByCriteria criteria, ContextInfo context) throws InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException {
795 GenericQueryResults<ResultValueEntity> results = resultValueCriteriaLookupService.lookup(ResultValueEntity.class, criteria);
796 List<ResultValueInfo> infos = new ArrayList<ResultValueInfo>(results.getResults().size());
797 for (ResultValueEntity entity : results.getResults()) {
798 infos.add(entity.toDto());
799 }
800 return infos;
801 }
802
803 @Override
804 @Transactional(readOnly = true)
805 public List<String> searchForResultValuesGroupIds(QueryByCriteria criteria, ContextInfo context) throws InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException {
806 GenericQueryResults<String> results = resultValuesGroupCriteriaLookupService.lookupIds(ResultValuesGroupEntity.class, criteria);
807 return results.getResults();
808 }
809
810 @Override
811 @Transactional(readOnly = true)
812 public List<ResultValuesGroupInfo> searchForResultValuesGroups(QueryByCriteria criteria, ContextInfo context) throws InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException {
813 GenericQueryResults<ResultValuesGroupEntity> results = resultValuesGroupCriteriaLookupService.lookup(ResultValuesGroupEntity.class, criteria);
814 List<ResultValuesGroupInfo> infos = new ArrayList<ResultValuesGroupInfo>(results.getResults().size());
815 for (ResultValuesGroupEntity entity : results.getResults()) {
816 infos.add(entity.toDto());
817 }
818 return infos;
819 }
820
821
822 }