View Javadoc

1   /*
2    * Copyright 2011 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may	obtain a copy of the License at
7    *
8    * 	http://www.osedu.org/licenses/ECL-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.student.enrollment.class1.lrc.service.impl;
17  
18  import java.util.ArrayList;
19  import java.util.Date;
20  import java.util.HashSet;
21  import java.util.LinkedHashMap;
22  import java.util.List;
23  import java.util.Map;
24  import java.util.Set;
25  import org.kuali.student.r2.common.dto.ContextInfo;
26  import org.kuali.student.r2.common.dto.MetaInfo;
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.AlreadyExistsException;
30  import org.kuali.student.r2.common.exceptions.DataValidationErrorException;
31  import org.kuali.student.r2.common.exceptions.DependentObjectsExistException;
32  import org.kuali.student.r2.common.exceptions.DoesNotExistException;
33  import org.kuali.student.r2.common.exceptions.InvalidParameterException;
34  import org.kuali.student.r2.common.exceptions.MissingParameterException;
35  import org.kuali.student.r2.common.exceptions.OperationFailedException;
36  import org.kuali.student.r2.common.exceptions.PermissionDeniedException;
37  import org.kuali.student.r2.common.exceptions.VersionMismatchException;
38  import org.kuali.student.r2.lum.lrc.dto.ResultScaleInfo;
39  import org.kuali.student.r2.lum.lrc.dto.ResultValueInfo;
40  import org.kuali.student.r2.lum.lrc.dto.ResultValuesGroupInfo;
41  import org.kuali.student.r2.lum.lrc.service.LRCService;
42  import org.kuali.student.r2.lum.lrc.service.LrcServiceBusinessLogic;
43  import org.kuali.student.r2.lum.lrc.service.impl.LrcServiceBusinessLogicImpl;
44  
45  public class LrcServiceMockImpl implements LRCService {
46  
47      private LrcServiceBusinessLogic lrcServiceBusinessLogic;
48  
49      public LrcServiceBusinessLogic getLrcServiceBusinessLogic() {
50          return lrcServiceBusinessLogic;
51      }
52  
53      public void setLrcServiceBusinessLogic(LrcServiceBusinessLogic lrcServiceBusinessLogic) {
54          this.lrcServiceBusinessLogic = lrcServiceBusinessLogic;
55          if (this.lrcServiceBusinessLogic instanceof LrcServiceBusinessLogic) {
56              LrcServiceBusinessLogicImpl impl = (LrcServiceBusinessLogicImpl) lrcServiceBusinessLogic;
57              impl.setLrcService(this);
58          }
59      }
60  
61      @Override
62      public ResultValuesGroupInfo getResultValuesGroup(String resultValuesGroupKey,
63              ContextInfo context)
64              throws DoesNotExistException,
65              InvalidParameterException,
66              MissingParameterException,
67              OperationFailedException,
68              PermissionDeniedException {
69          if (!this.resultValuesGroupMap.containsKey(resultValuesGroupKey)) {
70              throw new DoesNotExistException(resultValuesGroupKey);
71          }
72          ResultValuesGroupInfo rvg = this.resultValuesGroupMap.get(resultValuesGroupKey);
73          return rvg;
74      }
75  //
76  //    private void loadResultValuesWithRange(ResultValuesGroupInfo rvg,
77  //            ContextInfo contextInfo)
78  //            throws OperationFailedException {
79  //        if (!rvg.getTypeKey().equals(LrcServiceConstants.RESULT_VALUES_GROUP_TYPE_KEY_RANGE)) {
80  //            return;
81  //        }
82  //        rvg.getResultValueKeys().clear();
83  //        List<ResultValueInfo> values;
84  //        try {
85  //            values = this.getResultValuesForScale(rvg.getResultScaleKey(), contextInfo);
86  //        } catch (DoesNotExistException ex) {
87  //            throw new OperationFailedException("unexpected", ex);
88  //        } catch (InvalidParameterException ex) {
89  //            throw new OperationFailedException("unexpected", ex);
90  //        } catch (MissingParameterException ex) {
91  //            throw new OperationFailedException("unexpected", ex);
92  //        } catch (OperationFailedException ex) {
93  //            throw new OperationFailedException("unexpected", ex);
94  //        } catch (PermissionDeniedException ex) {
95  //            throw new OperationFailedException("unexpected", ex);
96  //        }
97  //        for (ResultValueInfo rv : values) {
98  //            if (isWithinRange(rv, rvg)) {
99  //                rvg.getResultValueKeys().add(rv.getKey());
100 //            }
101 //        }
102 //    }
103 //
104 //    private boolean isWithinRange(ResultValueInfo rv,
105 //            ResultValuesGroupInfo rvg) {
106 //        float numericValue = Float.parseFloat(rv.getNumericValue());
107 //        float minValue = Float.parseFloat(rvg.getResultValueRange().getMinValue());
108 //        if (numericValue < minValue) {
109 //            return false;
110 //        }
111 //
112 //        float maxValue = Float.parseFloat(rvg.getResultValueRange().getMaxValue());
113 //        if (numericValue > maxValue) {
114 //            return false;
115 //        }
116 //        float increment = Float.parseFloat(rvg.getResultValueRange().getIncrement());
117 //        float diff = numericValue - minValue;
118 //        float remainder = diff % increment;
119 //        if (remainder != 0) {
120 //            return false;
121 //        }
122 //        return true;
123 //    }
124 
125     @Override
126     public List<ResultValuesGroupInfo> getResultValuesGroupsByKeys(List<String> resultValuesGroupKeys,
127             ContextInfo context)
128             throws DoesNotExistException,
129             InvalidParameterException,
130             MissingParameterException,
131             OperationFailedException,
132             PermissionDeniedException {
133         List<ResultValuesGroupInfo> list = new ArrayList<ResultValuesGroupInfo>();
134         for (String id : resultValuesGroupKeys) {
135             list.add(this.getResultValuesGroup(id, context));
136         }
137         return list;
138     }
139 
140     @Override
141     public List<ResultValuesGroupInfo> getResultValuesGroupsByResultValue(String resultValueKey,
142             ContextInfo context)
143             throws DoesNotExistException,
144             InvalidParameterException,
145             MissingParameterException,
146             OperationFailedException,
147             PermissionDeniedException {
148         List<ResultValuesGroupInfo> list = new ArrayList<ResultValuesGroupInfo>();
149         for (ResultValuesGroupInfo info : resultValuesGroupMap.values()) {
150             if (info.getResultValueKeys().contains(resultValueKey)) {
151                 list.add(info);
152             }
153         }
154         return list;
155     }
156 
157     @Override
158     public List<ResultValuesGroupInfo> getResultValuesGroupsByResultScale(String resultScaleKey,
159             ContextInfo context)
160             throws DoesNotExistException,
161             InvalidParameterException,
162             MissingParameterException,
163             OperationFailedException,
164             PermissionDeniedException {
165         List<ResultValuesGroupInfo> list = new ArrayList<ResultValuesGroupInfo>();
166         for (ResultValuesGroupInfo info : resultValuesGroupMap.values()) {
167             if (info.getResultScaleKey().contains(resultScaleKey)) {
168                 list.add(info);
169             }
170         }
171         return list;
172     }
173 
174     @Override
175     public List<String> getResultValuesGroupKeysByType(String resultValuesGroupTypeKey,
176             ContextInfo context)
177             throws DoesNotExistException,
178             InvalidParameterException,
179             MissingParameterException,
180             OperationFailedException,
181             PermissionDeniedException {
182         List<String> list = new ArrayList<String>();
183         for (ResultValuesGroupInfo info : resultValuesGroupMap.values()) {
184             if (resultValuesGroupTypeKey.equals(info.getTypeKey())) {
185                 list.add(info.getKey());
186             }
187         }
188         return list;
189     }
190     // cache variable 
191     // The LinkedHashMap is just so the values come back in a predictable order
192     private Map<String, ResultValuesGroupInfo> resultValuesGroupMap = new LinkedHashMap<String, ResultValuesGroupInfo>();
193 
194     @Override
195     public ResultValuesGroupInfo createResultValuesGroup(String resultScaleKey,
196             String resultValuesGroupTypeKey,
197             ResultValuesGroupInfo resultValuesGroupInfo,
198             ContextInfo context)
199             throws AlreadyExistsException,
200             DataValidationErrorException,
201             InvalidParameterException,
202             MissingParameterException,
203             OperationFailedException,
204             PermissionDeniedException {
205         if (resultValuesGroupMap.containsKey(resultValuesGroupInfo.getKey())) {
206             throw new AlreadyExistsException(resultValuesGroupInfo.getKey());
207         }
208         // create 
209         ResultValuesGroupInfo copy = new ResultValuesGroupInfo(resultValuesGroupInfo);
210         copy.setResultScaleKey(resultScaleKey);
211         copy.setTypeKey(resultValuesGroupTypeKey);
212         if (copy.getKey() == null) {
213             copy.setKey(resultValuesGroupMap.size() + "");
214         }
215         copy.setMeta(newMeta(context));
216         resultValuesGroupMap.put(copy.getKey(), copy);
217         ResultValuesGroupInfo rvgNew = new ResultValuesGroupInfo(copy);
218         return rvgNew;
219     }
220 
221     @Override
222     public ResultValuesGroupInfo updateResultValuesGroup(String resultValuesGroupKey,
223             ResultValuesGroupInfo gradeValuesGroupInfo,
224             ContextInfo context)
225             throws DataValidationErrorException,
226             DoesNotExistException,
227             InvalidParameterException,
228             MissingParameterException,
229             OperationFailedException,
230             PermissionDeniedException,
231             VersionMismatchException {
232         // update
233         if (!resultValuesGroupKey.equals(gradeValuesGroupInfo.getKey())) {
234             throw new InvalidParameterException("The id parameter does not match the id on the info object");
235         }
236         ResultValuesGroupInfo copy = new ResultValuesGroupInfo(gradeValuesGroupInfo);
237         ResultValuesGroupInfo old = this.getResultValuesGroup(gradeValuesGroupInfo.getKey(), context);
238         if (!old.getMeta().getVersionInd().equals(copy.getMeta().getVersionInd())) {
239             throw new VersionMismatchException(old.getMeta().getVersionInd());
240         }
241         copy.setMeta(updateMeta(copy.getMeta(), context));
242         this.resultValuesGroupMap.put(gradeValuesGroupInfo.getKey(), copy);
243         ResultValuesGroupInfo rvgNew = new ResultValuesGroupInfo(copy);
244         return rvgNew;
245     }
246 
247     @Override
248     public StatusInfo deleteResultValuesGroup(String resultValuesGroupKey,
249             ContextInfo context)
250             throws DoesNotExistException,
251             InvalidParameterException,
252             MissingParameterException,
253             OperationFailedException,
254             PermissionDeniedException {
255         if (this.resultValuesGroupMap.remove(resultValuesGroupKey) == null) {
256             throw new DoesNotExistException(resultValuesGroupKey);
257         }
258         return newStatus();
259     }
260 
261     @Override
262     public List<ValidationResultInfo> validateResultValuesGroup(String validationType,
263             ResultValuesGroupInfo gradeValuesGroupInfo,
264             ContextInfo context)
265             throws DoesNotExistException,
266             InvalidParameterException,
267             MissingParameterException,
268             OperationFailedException {
269         // validate
270         return new ArrayList<ValidationResultInfo>();
271     }
272 
273     @Override
274     public ResultValuesGroupInfo getCreateFixedCreditResultValuesGroup(String creditValue,
275             String scaleKey,
276             ContextInfo context)
277             throws InvalidParameterException,
278             MissingParameterException,
279             OperationFailedException,
280             PermissionDeniedException {
281         return this.lrcServiceBusinessLogic.getCreateFixedCreditResultValuesGroup(creditValue, scaleKey, context);
282     }
283 
284     @Override
285     public ResultValuesGroupInfo getCreateRangeCreditResultValuesGroup(String creditValueMin,
286             String creditValueMax,
287             String creditValueIncrement,
288             String scaleKey,
289             ContextInfo context)
290             throws InvalidParameterException,
291             MissingParameterException,
292             OperationFailedException,
293             PermissionDeniedException {
294         ResultValuesGroupInfo rvg = this.lrcServiceBusinessLogic.getCreateRangeCreditResultValuesGroup(creditValueMin,
295                 creditValueMax,
296                 creditValueIncrement, scaleKey, context);
297         return rvg;
298 
299     }
300 
301     @Override
302     public ResultValuesGroupInfo getCreateMultipleCreditResultValuesGroup(List<String> creditValues,
303             String scaleKey,
304             ContextInfo context)
305             throws InvalidParameterException,
306             MissingParameterException,
307             OperationFailedException,
308             PermissionDeniedException {
309         return this.lrcServiceBusinessLogic.getCreateMultipleCreditResultValuesGroup(creditValues, scaleKey, context);
310     }
311 
312     @Override
313     public ResultValueInfo getResultValue(String resultValueKey,
314             ContextInfo context)
315             throws DoesNotExistException,
316             InvalidParameterException,
317             MissingParameterException,
318             OperationFailedException,
319             PermissionDeniedException {
320         if (!this.resultValueMap.containsKey(resultValueKey)) {
321             throw new DoesNotExistException(resultValueKey);
322         }
323         return this.resultValueMap.get(resultValueKey);
324     }
325 
326     @Override
327     public List<ResultValueInfo> getResultValuesByKeys(List<String> resultValueKeys,
328             ContextInfo context)
329             throws DoesNotExistException,
330             InvalidParameterException,
331             MissingParameterException,
332             OperationFailedException,
333             PermissionDeniedException {
334         List<ResultValueInfo> list = new ArrayList<ResultValueInfo>();
335         for (String id : resultValueKeys) {
336             list.add(this.getResultValue(id, context));
337         }
338         return list;
339     }
340 
341     @Override
342     public List<String> getResultValueKeysByType(String resultValueTypeKey,
343             ContextInfo context)
344             throws DoesNotExistException,
345             InvalidParameterException,
346             MissingParameterException,
347             OperationFailedException,
348             PermissionDeniedException {
349         List<String> list = new ArrayList<String>();
350         for (ResultValueInfo info : resultValueMap.values()) {
351             if (resultValueTypeKey.equals(info.getTypeKey())) {
352                 list.add(info.getKey());
353             }
354         }
355         return list;
356     }
357 
358     @Override
359     public List<ResultValueInfo> getResultValuesForResultValuesGroup(String resultValuesGroupKey,
360             ContextInfo contextInfo)
361             throws DoesNotExistException,
362             InvalidParameterException,
363             MissingParameterException,
364             OperationFailedException,
365             PermissionDeniedException {
366         ResultValuesGroupInfo info = this.getResultValuesGroup(resultValuesGroupKey, contextInfo);
367         return this.getResultValuesByKeys(info.getResultValueKeys(), contextInfo);
368     }
369     // cache variable 
370     // The LinkedHashMap is just so the values come back in a predictable order
371     private Map<String, ResultValueInfo> resultValueMap = new LinkedHashMap<String, ResultValueInfo>();
372 
373     @Override
374     public ResultValueInfo createResultValue(String resultScaleKey,
375             String resultValueTypeKey,
376             ResultValueInfo resultValueInfo,
377             ContextInfo context)
378             throws AlreadyExistsException,
379             DataValidationErrorException,
380             DoesNotExistException,
381             InvalidParameterException,
382             MissingParameterException,
383             OperationFailedException,
384             PermissionDeniedException {
385         if (resultValueMap.containsKey(resultValueInfo.getKey())) {
386             throw new AlreadyExistsException(resultValueInfo.getKey());
387         }
388         // create 
389         ResultValueInfo copy = new ResultValueInfo(resultValueInfo);
390         copy.setResultScaleKey(resultScaleKey);
391         copy.setTypeKey(resultValueTypeKey);
392         if (copy.getKey() == null) {
393             copy.setKey(resultValueMap.size() + "");
394         }
395         copy.setMeta(newMeta(context));
396         resultValueMap.put(copy.getKey(), copy);
397         return new ResultValueInfo(copy);
398     }
399 
400     @Override
401     public ResultValueInfo updateResultValue(String resultValueKey,
402             ResultValueInfo resultValueInfo,
403             ContextInfo context)
404             throws DataValidationErrorException,
405             DoesNotExistException,
406             InvalidParameterException,
407             MissingParameterException,
408             OperationFailedException,
409             PermissionDeniedException,
410             VersionMismatchException {
411         // update
412         if (!resultValueKey.equals(resultValueInfo.getKey())) {
413             throw new InvalidParameterException("The id parameter does not match the id on the info object");
414         }
415         ResultValueInfo copy = new ResultValueInfo(resultValueInfo);
416         ResultValueInfo old = this.getResultValue(resultValueInfo.getKey(), context);
417         if (!old.getMeta().getVersionInd().equals(copy.getMeta().getVersionInd())) {
418             throw new VersionMismatchException(old.getMeta().getVersionInd());
419         }
420         copy.setMeta(updateMeta(copy.getMeta(), context));
421         this.resultValueMap.put(resultValueInfo.getKey(), copy);
422         return new ResultValueInfo(copy);
423     }
424 
425     @Override
426     public StatusInfo deleteResultValue(String resultValueKey,
427             ContextInfo context)
428             throws DoesNotExistException,
429             DependentObjectsExistException,
430             InvalidParameterException,
431             MissingParameterException,
432             OperationFailedException,
433             PermissionDeniedException {
434         List<ResultValuesGroupInfo> list = this.getResultValuesGroupsByResultValue(resultValueKey, context);
435         if (!list.isEmpty()) {
436             throw new DependentObjectsExistException(list.size() + " rvgs exist");
437         }
438         if (this.resultValueMap.remove(resultValueKey) == null) {
439             throw new DoesNotExistException(resultValueKey);
440         }
441         return newStatus();
442     }
443 
444     @Override
445     public List<ValidationResultInfo> validateResultValue(String validationType,
446             ResultValueInfo resultValueInfo,
447             ContextInfo context)
448             throws DoesNotExistException,
449             InvalidParameterException,
450             MissingParameterException,
451             OperationFailedException {
452         // validate
453         return new ArrayList<ValidationResultInfo>();
454     }
455 
456     @Override
457     public ResultValueInfo getCreateResultValueForScale(String resultValue,
458             String scaleKey,
459             ContextInfo context)
460             throws InvalidParameterException,
461             MissingParameterException,
462             OperationFailedException,
463             PermissionDeniedException {
464         return this.lrcServiceBusinessLogic.getCreateResultValueForScale(resultValue, scaleKey, context);
465     }
466 
467     @Override
468     public List<ResultValuesGroupInfo> getResultValuesGroupsByResultScaleType(String resultScaleTypeKey,
469             ContextInfo context)
470             throws DoesNotExistException,
471             InvalidParameterException,
472             MissingParameterException,
473             OperationFailedException,
474             PermissionDeniedException {
475         List<ResultValuesGroupInfo> list = new ArrayList<ResultValuesGroupInfo>();
476         List<String> scaleKeys = this.getResultScaleKeysByType(resultScaleTypeKey, context);
477         for (String scaleKey : scaleKeys) {
478             list.addAll(this.getResultValuesGroupsByResultScale(scaleKey, context));
479         }
480         return list;
481     }
482 
483     @Override
484     public ResultScaleInfo getResultScale(String resultScaleKey,
485             ContextInfo context)
486             throws DoesNotExistException,
487             InvalidParameterException,
488             MissingParameterException,
489             OperationFailedException,
490             PermissionDeniedException {
491         if (!this.resultScaleMap.containsKey(resultScaleKey)) {
492             throw new DoesNotExistException(resultScaleKey);
493         }
494         return this.resultScaleMap.get(resultScaleKey);
495     }
496 
497     @Override
498     public List<ResultScaleInfo> getResultScalesByKeys(List<String> resultScaleKeys,
499             ContextInfo context)
500             throws DoesNotExistException,
501             InvalidParameterException,
502             MissingParameterException,
503             OperationFailedException,
504             PermissionDeniedException {
505         List<ResultScaleInfo> list = new ArrayList<ResultScaleInfo>();
506         for (String id : resultScaleKeys) {
507             list.add(this.getResultScale(id, context));
508         }
509         return list;
510     }
511 
512     @Override
513     public List<String> getResultScaleKeysByType(String resultScaleTypeKey,
514             ContextInfo context)
515             throws DoesNotExistException,
516             InvalidParameterException,
517             MissingParameterException,
518             OperationFailedException,
519             PermissionDeniedException {
520         List<String> list = new ArrayList<String>();
521         for (ResultScaleInfo info : resultScaleMap.values()) {
522             if (resultScaleTypeKey.equals(info.getTypeKey())) {
523                 list.add(info.getKey());
524             }
525         }
526         return list;
527     }
528     // cache variable 
529     // The LinkedHashMap is just so the values come back in a predictable order
530     private Map<String, ResultScaleInfo> resultScaleMap = new LinkedHashMap<String, ResultScaleInfo>();
531 
532     @Override
533     public ResultScaleInfo createResultScale(String resultScaleTypeKey,
534             ResultScaleInfo resultScaleInfo,
535             ContextInfo context)
536             throws AlreadyExistsException,
537             DataValidationErrorException,
538             InvalidParameterException,
539             MissingParameterException,
540             OperationFailedException,
541             PermissionDeniedException {
542         if (resultScaleMap.containsKey(resultScaleInfo.getKey())) {
543             throw new AlreadyExistsException(resultScaleInfo.getKey());
544         }
545         // create 
546         ResultScaleInfo copy = new ResultScaleInfo(resultScaleInfo);
547         copy.setTypeKey(resultScaleTypeKey);
548         if (copy.getKey() == null) {
549             copy.setKey(resultScaleMap.size() + "");
550         }
551         copy.setMeta(newMeta(context));
552         resultScaleMap.put(copy.getKey(), copy);
553         return new ResultScaleInfo(copy);
554     }
555 
556     @Override
557     public ResultScaleInfo updateResultScale(String resultScaleKey,
558             ResultScaleInfo gradeScaleInfo,
559             ContextInfo context)
560             throws DataValidationErrorException,
561             DoesNotExistException,
562             InvalidParameterException,
563             MissingParameterException,
564             OperationFailedException,
565             PermissionDeniedException,
566             VersionMismatchException {
567         // update
568         if (!resultScaleKey.equals(gradeScaleInfo.getKey())) {
569             throw new InvalidParameterException("The id parameter does not match the id on the info object");
570         }
571         ResultScaleInfo copy = new ResultScaleInfo(gradeScaleInfo);
572         ResultScaleInfo old = this.getResultScale(gradeScaleInfo.getKey(), context);
573         if (!old.getMeta().getVersionInd().equals(copy.getMeta().getVersionInd())) {
574             throw new VersionMismatchException(old.getMeta().getVersionInd());
575         }
576         copy.setMeta(updateMeta(copy.getMeta(), context));
577         this.resultScaleMap.put(gradeScaleInfo.getKey(), copy);
578         return new ResultScaleInfo(copy);
579     }
580 
581     @Override
582     public StatusInfo deleteResultScale(String resultScaleKey,
583             ContextInfo context)
584             throws DoesNotExistException,
585             DependentObjectsExistException,
586             InvalidParameterException,
587             MissingParameterException,
588             OperationFailedException,
589             PermissionDeniedException {
590         List<ResultValueInfo> values = this.getResultValuesForScale(resultScaleKey, context);
591         if (!values.isEmpty()) {
592             throw new DependentObjectsExistException(values.size() + " ResultValue(s) exist");
593         }
594         List<ResultValuesGroupInfo> groups = this.getResultValuesGroupsByResultScale(resultScaleKey, context);
595         if (!groups.isEmpty()) {
596             throw new DependentObjectsExistException(groups.size() + " ResultValuesGroup(s) exist");
597         }
598         if (this.resultScaleMap.remove(resultScaleKey) == null) {
599             throw new DoesNotExistException(resultScaleKey);
600         }
601         return newStatus();
602     }
603 
604     @Override
605     public List<ValidationResultInfo> validateResultScale(String validationType,
606             ResultScaleInfo gradeScaleInfo,
607             ContextInfo context)
608             throws DoesNotExistException,
609             InvalidParameterException,
610             MissingParameterException,
611             OperationFailedException {
612         // validate
613         return new ArrayList<ValidationResultInfo>();
614     }
615 
616     @Override
617     public List<ResultValueInfo> getResultValuesForScale(String resultScaleKey,
618             ContextInfo context)
619             throws DoesNotExistException,
620             InvalidParameterException,
621             MissingParameterException,
622             OperationFailedException,
623             PermissionDeniedException {
624         List<ResultValueInfo> list = new ArrayList<ResultValueInfo>();
625         for (ResultValueInfo info : this.resultValueMap.values()) {
626             if (info.getResultScaleKey().equals(resultScaleKey)) {
627                 list.add(info);
628             }
629         }
630         return list;
631     }
632 
633     @Override
634     public ResultValueInfo getResultValueForScaleAndValue(String resultScaleKey,
635             String value,
636             ContextInfo contextInfo)
637             throws DoesNotExistException,
638             InvalidParameterException,
639             MissingParameterException,
640             OperationFailedException,
641             PermissionDeniedException {
642         List<ResultValueInfo> list = new ArrayList<ResultValueInfo>();
643         for (ResultValueInfo info : this.resultValueMap.values()) {
644             if (info.getResultScaleKey().equals(resultScaleKey)) {
645                 if (info.getValue().equals(value)) {
646                     list.add(info);
647                 }
648             }
649         }
650         if (list.isEmpty()) {
651             throw new DoesNotExistException(resultScaleKey + " " + value);
652         }
653         if (list.size() > 1) {
654             throw new OperationFailedException("too many matches " + list.size());
655         }
656         return list.get(0);
657     }
658 
659     @Override
660     public List<ResultValueInfo> getResultValuesForResultValuesGroups(List<String> resultValuesGroupKeys,
661             ContextInfo context)
662             throws DoesNotExistException,
663             InvalidParameterException,
664             MissingParameterException,
665             OperationFailedException,
666             PermissionDeniedException {
667         List<ResultValueInfo> list = new ArrayList<ResultValueInfo>();
668         Set<String> keys = new HashSet<String>();
669         for (String rvgKey : resultValuesGroupKeys) {
670             ResultValuesGroupInfo rvg = this.getResultValuesGroup(rvgKey, context);
671             for (String rvKey : rvg.getResultValueKeys()) {
672                 if (keys.add(rvKey)) {
673                     list.add(this.getResultValue(rvKey, context));
674                 }
675             }
676         }
677         return list;
678     }
679 
680     private StatusInfo newStatus() {
681         StatusInfo status = new StatusInfo();
682         status.setSuccess(Boolean.TRUE);
683         return status;
684     }
685 
686     private MetaInfo newMeta(ContextInfo context) {
687         MetaInfo meta = new MetaInfo();
688         meta.setCreateId(context.getPrincipalId());
689         meta.setCreateTime(new Date());
690         meta.setUpdateId(context.getPrincipalId());
691         meta.setUpdateTime(meta.getCreateTime());
692         meta.setVersionInd("0");
693         return meta;
694     }
695 
696     private MetaInfo updateMeta(MetaInfo old,
697             ContextInfo context) {
698         MetaInfo meta = new MetaInfo(old);
699         meta.setUpdateId(context.getPrincipalId());
700         meta.setUpdateTime(new Date());
701         meta.setVersionInd((Integer.parseInt(meta.getVersionInd()) + 1) + "");
702         return meta;
703     }
704 }