View Javadoc

1   /*
2    * To change this template, choose Tools | Templates
3    * and open the template in the editor.
4    */
5   package org.kuali.student.enrollment.class2.courseofferingset.service.impl;
6   
7   import org.apache.commons.lang.UnhandledException;
8   import org.kuali.rice.core.api.criteria.EqualPredicate;
9   import org.kuali.rice.core.api.criteria.QueryByCriteria;
10  import org.kuali.student.common.mock.MockService;
11  import org.kuali.student.common.util.UUIDHelper;
12  import org.kuali.student.enrollment.courseofferingset.dto.SocInfo;
13  import org.kuali.student.enrollment.courseofferingset.dto.SocRolloverResultInfo;
14  import org.kuali.student.enrollment.courseofferingset.dto.SocRolloverResultItemInfo;
15  import org.kuali.student.enrollment.courseofferingset.service.CourseOfferingSetService;
16  import org.kuali.student.enrollment.courseofferingset.service.CourseOfferingSetServiceBusinessLogic;
17  import org.kuali.student.r2.common.dto.AttributeInfo;
18  import org.kuali.student.r2.common.dto.ContextInfo;
19  import org.kuali.student.r2.common.dto.MetaInfo;
20  import org.kuali.student.r2.common.dto.StatusInfo;
21  import org.kuali.student.r2.common.dto.ValidationResultInfo;
22  import org.kuali.student.r2.common.exceptions.*;
23  import org.kuali.student.r2.common.util.constants.CourseOfferingSetServiceConstants;
24  
25  import javax.jws.WebParam;
26  import java.text.SimpleDateFormat;
27  import java.util.ArrayList;
28  import java.util.Date;
29  import java.util.LinkedHashMap;
30  import java.util.List;
31  import java.util.Map;
32  
33  public class CourseOfferingSetServiceMockImpl implements CourseOfferingSetService, MockService {
34  
35      private CourseOfferingSetServiceBusinessLogic businessLogic;
36  
37      @Override
38      public void clear() {
39          this.socMap.clear();
40          this.socRolloverResultItemMap.clear();
41          this.socRolloverResultMap.clear();
42  
43      }
44  
45      public CourseOfferingSetServiceBusinessLogic getBusinessLogic() {
46          return businessLogic;
47      }
48  
49      public void setBusinessLogic(CourseOfferingSetServiceBusinessLogic businessLogic) {
50          this.businessLogic = businessLogic;
51      }
52  
53      public CourseOfferingSetServiceMockImpl() {
54      }
55  
56      // implement the methods
57      @Override
58      public SocInfo getSoc(String socId, ContextInfo context)
59              throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException,
60              PermissionDeniedException {
61          if ( ! this.socMap.containsKey(socId)) {
62              throw new DoesNotExistException(socId);
63          }
64          return new SocInfo (this.socMap.get(socId));
65      }
66  
67      @Override
68      public List<SocInfo> getSocsByIds(List<String> socIds, ContextInfo context)
69              throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException,
70              PermissionDeniedException {
71          List<SocInfo> list = new ArrayList<SocInfo>();
72          for (String id : socIds) {
73              list.add(this.getSoc(id, context));
74          }
75          return list;
76      }
77  
78      @Override
79      public List<String> getSocIdsByTerm(String termId, ContextInfo context)
80              throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException,
81              PermissionDeniedException {
82          List<String> list = new ArrayList<String>();
83          for (SocInfo info : socMap.values()) {
84              if (termId.equals(info.getTermId())) {
85                  list.add(info.getId());
86              }
87          }
88          return list;
89      }
90  
91      @Override
92      public List<String> getSocIdsByTermAndSubjectArea(String termId, String subjectArea, ContextInfo context)
93              throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException,
94              PermissionDeniedException {
95          List<String> list = new ArrayList<String>();
96          for (SocInfo info : socMap.values()) {
97              if (termId.equals(info.getTermId())) {
98                  if (subjectArea.equals(info.getSubjectArea())) {
99                      list.add(info.getId());
100                 }
101             }
102         }
103         return list;
104     }
105 
106     @Override
107     public List<String> getSocIdsByTermAndUnitsContentOwner(String termId, String unitsContentOwnerId, ContextInfo context)
108             throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException,
109             PermissionDeniedException {
110         List<String> list = new ArrayList<String>();
111         for (SocInfo info : socMap.values()) {
112             if (termId.equals(info.getTermId())) {
113                 if (unitsContentOwnerId.equals(info.getUnitsContentOwnerId())) {
114                     list.add(info.getId());
115                 }
116             }
117         }
118         return list;
119     }
120 
121     @Override
122     public List<String> getSocIdsByType(String typeKey, ContextInfo context)
123             throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException,
124             PermissionDeniedException {
125         List<String> list = new ArrayList<String>();
126         for (SocInfo info : socMap.values()) {
127             if (typeKey.equals(info.getTypeKey())) {
128                 list.add(info.getId());
129             }
130         }
131         return list;
132     }
133 
134     @Override
135     public List<SocInfo> searchForSocs(@WebParam(name = "criteria") QueryByCriteria criteria, @WebParam(name = "contextInfo") ContextInfo context) throws InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException {
136         throw new UnsupportedOperationException("To be Implemented by services team");
137     }
138 
139     @Override
140     public List<String> searchForSocIds(@WebParam(name = "criteria") QueryByCriteria criteria, @WebParam(name = "contextInfo") ContextInfo context) throws InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException {
141         throw new UnsupportedOperationException("To be Implemented by services team");
142     }
143 
144     // cache variable
145     // The LinkedHashMap is just so the values come back in a predictable order
146     private Map<String, SocInfo> socMap = new LinkedHashMap<String, SocInfo>();
147 
148     @Override
149     public SocInfo createSoc(String termId, String socTypeKey, SocInfo socInfo, ContextInfo context)
150             throws DoesNotExistException, DataValidationErrorException, InvalidParameterException, MissingParameterException,
151             OperationFailedException, PermissionDeniedException, ReadOnlyException {
152         // create 
153         if ( ! socTypeKey.equals(socInfo.getTypeKey())) {
154             throw new InvalidParameterException("The type parameter does not match the type on the info object");
155         }
156         // TODO: check the rest of the readonly fields that are specified on the create to make sure they match the info object
157         SocInfo copy = new SocInfo(socInfo);
158         if (copy.getId() == null) {
159             copy.setId(UUIDHelper.genStringUUID());
160         }
161         this.logStateChange(copy, context);
162         copy.setMeta(newMeta(context));
163         socMap.put(copy.getId(), copy);
164         return new SocInfo(copy);
165     }
166 
167     @Override
168     public SocInfo updateSoc(String socId, SocInfo socInfo, ContextInfo context)
169             throws DataValidationErrorException, DoesNotExistException, InvalidParameterException, MissingParameterException,
170             OperationFailedException, PermissionDeniedException, ReadOnlyException, VersionMismatchException {
171         // update
172         if ( ! socId.equals(socInfo.getId())) {
173             throw new InvalidParameterException("The id parameter does not match the id on the info object");
174         }
175         SocInfo copy = new SocInfo(socInfo);
176         SocInfo old = this.getSoc(socInfo.getId(), context);
177         if (!socInfo.getStateKey().equals(old.getStateKey())) {
178             throw new ReadOnlyException ("state key can only be changed by calling updateSocState");
179         }
180         if ( ! old.getMeta().getVersionInd().equals(copy.getMeta().getVersionInd())) {
181             throw new VersionMismatchException(old.getMeta().getVersionInd());
182         }
183         copy.setMeta(updateMeta(copy.getMeta(), context));
184         this.socMap.put(socInfo.getId(), copy);
185         return new SocInfo(copy);
186     }
187 
188     @Override
189     public StatusInfo deleteSoc(String socId, ContextInfo context)
190             throws DependentObjectsExistException, DoesNotExistException, InvalidParameterException, MissingParameterException,
191             OperationFailedException, PermissionDeniedException {
192         if (this.socMap.remove(socId) == null) {
193             throw new DoesNotExistException(socId);
194         }
195         return newStatus();
196     }
197 
198     @Override
199     public List<ValidationResultInfo> validateSoc(String validationType, SocInfo socInfo, ContextInfo context)
200             throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException {
201         // validate
202         return new ArrayList<ValidationResultInfo>();
203     }
204 
205     @Override
206     public List<String> getSocIdsByCourseOffering(String courseOfferingId, ContextInfo context)
207             throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException,
208             PermissionDeniedException {
209         List<String> list = new ArrayList<String>();
210         for (SocInfo info : socMap.values()) {
211             if (this.isCourseOfferingInSoc(info.getId(), courseOfferingId, context)) {
212                 list.add(info.getId());
213             }
214         }
215         return list;
216     }
217 
218     @Override
219     public List<String> getCourseOfferingIdsBySoc(String socId, ContextInfo context)
220             throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException,
221             PermissionDeniedException {
222         return this.businessLogic.getCourseOfferingIdsBySoc(socId, context);
223     }
224 
225     @Override
226     public Integer deleteCourseOfferingsBySoc(String socId, ContextInfo context)
227             throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException,
228             PermissionDeniedException {
229         return this.businessLogic.deleteCourseOfferingsBySoc(socId, context);
230     }
231 
232     @Override
233     public Boolean isCourseOfferingInSoc(String socId, String courseOfferingId, ContextInfo context)
234             throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException,
235             PermissionDeniedException {
236         return this.businessLogic.isCourseOfferingInSoc(socId, courseOfferingId, context);
237     }
238 
239     @Override
240     public List<String> getPublishedCourseOfferingIdsBySoc(String socId, ContextInfo context)
241             throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException,
242             PermissionDeniedException {
243         return this.businessLogic.getPublishedCourseOfferingIdsBySoc(socId, context);
244     }
245 
246     @Override
247     public List<String> getUnpublishedCourseOfferingIdsBySoc(String socId, ContextInfo context)
248             throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException,
249             PermissionDeniedException {
250         return this.businessLogic.getUnpublishedActivityOfferingIdsBySoc(socId, context);
251     }
252 
253     @Override
254     public List<String> getUnpublishedActivityOfferingIdsBySoc(String socId, ContextInfo context)
255             throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException,
256             PermissionDeniedException {
257         return this.businessLogic.getUnpublishedActivityOfferingIdsBySoc(socId, context);
258     }
259 
260     @Override
261     public List<String> getUnscheduledActivityOfferingIdsBySoc(String socId, ContextInfo context)
262             throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException,
263             PermissionDeniedException {
264         throw new OperationFailedException("not impemented");
265     }
266 
267     @Override
268     public List<String> getCourseOfferingIdsWithUnscheduledFinalExamsBySoc(String socId, ContextInfo context)
269             throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException,
270             PermissionDeniedException {
271         throw new OperationFailedException("not been implemented");
272     }
273 
274     @Override
275     public StatusInfo startScheduleSoc(String socId, List<String> optionKeys, ContextInfo context)
276             throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException,
277             PermissionDeniedException {
278         throw new OperationFailedException("implement in M5");
279     }
280 
281     @Override
282     public SocInfo rolloverSoc(String sourceSocId, String targetTermId, List<String> optionKeys, ContextInfo context)
283             throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException,
284             PermissionDeniedException {
285         return this.businessLogic.rolloverSoc(sourceSocId, targetTermId, optionKeys, context);
286     }
287 
288     @Override
289     public SocRolloverResultInfo getSocRolloverResult(String rolloverResultId, ContextInfo context)
290             throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException,
291             PermissionDeniedException {
292         if ( ! this.socRolloverResultMap.containsKey(rolloverResultId)) {
293             throw new DoesNotExistException(rolloverResultId);
294         }
295         SocRolloverResultInfo info = new SocRolloverResultInfo(this.socRolloverResultMap.get(rolloverResultId));
296         this.updateCalculatedFields(info, context);
297         return info;
298     }
299 
300     private void updateCalculatedFields(SocRolloverResultInfo info, ContextInfo context) throws OperationFailedException {
301         try {
302             if (info.getSourceSocId() != null) {
303                 SocInfo sourceSoc = this.getSoc(info.getSourceSocId(), context);
304                 info.setSourceTermId(sourceSoc.getTermId());
305             }
306             // only do the calc once finished or the querying while running will be too long
307             if (info.getStateKey().equals(CourseOfferingSetServiceConstants.FINISHED_RESULT_STATE_KEY)) {
308                 List<SocRolloverResultItemInfo> items = this.getSocRolloverResultItemsByResultId(info.getId(), context);
309                 int success = 0;
310                 int failure = 0;
311                 for (SocRolloverResultItemInfo item : items) {
312                     if (CourseOfferingSetServiceConstants.SUCCESSFUL_RESULT_ITEM_STATES.contains(item.getStateKey())) {
313                         success ++;
314                     } else {
315                         failure ++;
316                     }
317                 }
318                 info.setCourseOfferingsCreated(success);
319                 info.setCourseOfferingsSkipped(failure);
320             }
321         } catch (Exception ex) {
322             throw new OperationFailedException("unexpected", ex);
323         }
324     }
325 
326     @Override
327     public List<SocRolloverResultInfo> getSocRolloverResultsByIds(List<String> rolloverResultIds, ContextInfo context)
328             throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException,
329             PermissionDeniedException {
330         List<SocRolloverResultInfo> list = new ArrayList<SocRolloverResultInfo>();
331         for (String id : rolloverResultIds) {
332             list.add(this.getSocRolloverResult(id, context));
333         }
334         return list;
335     }
336 
337     @Override
338     public List<SocRolloverResultItemInfo> getSocRolloverResultItemsByIds(List<String> rolloverResultItemIds, ContextInfo context)
339             throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException,
340             PermissionDeniedException {
341         List<SocRolloverResultItemInfo> list = new ArrayList<SocRolloverResultItemInfo>();
342         for (String id : rolloverResultItemIds) {
343             list.add(this.getSocRolloverResultItem(id, context));
344         }
345         return list;
346     }
347 
348     @Override
349     public List<SocRolloverResultItemInfo> getSocRolloverResultItemsByResultId(String socRolloverResultId, ContextInfo context)
350             throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException,
351             PermissionDeniedException {
352         List<SocRolloverResultItemInfo> list = new ArrayList<SocRolloverResultItemInfo>();
353         for (SocRolloverResultItemInfo info : socRolloverResultItemMap.values()) {
354             if (socRolloverResultId.equals(info.getSocRolloverResultId())) {
355                 list.add(info);
356             }
357         }
358         return list;
359     }
360 
361     @Override
362     public List<SocRolloverResultInfo> getSocRolloverResultsBySourceAndTargetSocs(String sourceSocId, String targetSocId, ContextInfo context) throws
363             DoesNotExistException,
364             InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException {
365         List<SocRolloverResultInfo> list = new ArrayList<SocRolloverResultInfo>();
366 
367         for (SocRolloverResultInfo info : socRolloverResultMap.values()) {
368             if (sourceSocId.equals(info.getSourceSocId())) {
369                 if (targetSocId.equals(info.getTargetSocId())) {
370                     list.add(info);
371                 }
372             }
373         }
374         return list;
375     }
376 
377     @Override
378     public List<SocRolloverResultItemInfo> getSocRolloverResultItemsByResultIdAndSourceCourseOfferingId(String socRolloverResultId, String sourceCourseOfferingId, ContextInfo context)
379             throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException,
380             PermissionDeniedException {
381         List<SocRolloverResultItemInfo> list = new ArrayList<SocRolloverResultItemInfo>();
382         for (SocRolloverResultItemInfo info : socRolloverResultItemMap.values()) {
383             if (socRolloverResultId.equals(info.getSocRolloverResultId())) {
384                 if (sourceCourseOfferingId.equals(info.getTargetCourseOfferingId())) {
385                     list.add(info);
386                 }
387             }
388         }
389         return list;
390     }
391 
392     @Override
393     public List<SocRolloverResultItemInfo> getSocRolloverResultItemsByResultIdAndTargetCourseOfferingId(String socRolloverResultId, String targetCourseOfferingId, ContextInfo context)
394             throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException,
395             PermissionDeniedException {
396         List<SocRolloverResultItemInfo> list = new ArrayList<SocRolloverResultItemInfo>();
397         for (SocRolloverResultItemInfo info : socRolloverResultItemMap.values()) {
398             if (socRolloverResultId.equals(info.getSocRolloverResultId())) {
399                 if (targetCourseOfferingId.equals(info.getTargetCourseOfferingId())) {
400                     list.add(info);
401                 }
402             }
403         }
404         return list;
405     }
406 
407     @Override
408     public List<String> getSocRolloverResultIdsByTargetSoc(String targetSocId, ContextInfo context)
409             throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException,
410             PermissionDeniedException {
411         List<String> list = new ArrayList<String>();
412         for (SocRolloverResultInfo info : socRolloverResultMap.values()) {
413             if (targetSocId.equals(info.getTargetSocId())) {
414                 list.add(info.getId());
415             }
416         }
417         return list;
418     }
419 
420     @Override
421     public List<String> getSocRolloverResultIdsBySourceSoc(String sourceSocId, ContextInfo context)
422             throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException,
423             PermissionDeniedException {
424         List<String> list = new ArrayList<String>();
425         for (SocRolloverResultInfo info : socRolloverResultMap.values()) {
426             if (sourceSocId.equals(info.getSourceSocId())) {
427                 list.add(info.getId());
428             }
429         }
430         return list;
431     }
432 
433     @Override
434     public SocRolloverResultInfo reverseRollover(String rolloverResultId, List<String> optionKeys, ContextInfo context)
435             throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException,
436             PermissionDeniedException {
437         return this.businessLogic.reverseRollover(rolloverResultId, optionKeys, context);
438     }
439     // cache variable 
440     // The LinkedHashMap is just so the values come back in a predictable order
441     private Map<String, SocRolloverResultInfo> socRolloverResultMap = new LinkedHashMap<String, SocRolloverResultInfo>();
442 
443     @Override
444     public SocRolloverResultInfo createSocRolloverResult(String socRolloverResultTypeKey, SocRolloverResultInfo socRolloverResultInfo, ContextInfo context)
445             throws DoesNotExistException, DataValidationErrorException, InvalidParameterException, MissingParameterException,
446             OperationFailedException, PermissionDeniedException, ReadOnlyException {
447         // create 
448         if ( ! socRolloverResultTypeKey.equals(socRolloverResultInfo.getTypeKey())) {
449             throw new InvalidParameterException("The type parameter does not match the type on the info object");
450         }
451         SocRolloverResultInfo copy = new SocRolloverResultInfo(socRolloverResultInfo);
452         if (copy.getId() == null) {
453             copy.setId(UUIDHelper.genStringUUID());
454         }
455         copy.setMeta(newMeta(context));
456         socRolloverResultMap.put(copy.getId(), copy);
457         return new SocRolloverResultInfo(copy);
458     }
459 
460     @Override
461     public SocRolloverResultInfo updateSocRolloverResult(String socRolloverResultId, SocRolloverResultInfo socRolloverResultInfo, ContextInfo context)
462             throws DataValidationErrorException, DoesNotExistException, InvalidParameterException, MissingParameterException,
463             OperationFailedException, PermissionDeniedException, ReadOnlyException, VersionMismatchException {
464         // update
465         if ( ! socRolloverResultId.equals(socRolloverResultInfo.getId())) {
466             throw new InvalidParameterException("The id parameter does not match the id on the info object");
467         }
468         SocRolloverResultInfo copy = new SocRolloverResultInfo(socRolloverResultInfo);
469         SocRolloverResultInfo old = this.getSocRolloverResult(socRolloverResultInfo.getId(), context);
470         if ( ! old.getMeta().getVersionInd().equals(copy.getMeta().getVersionInd())) {
471             throw new VersionMismatchException(old.getMeta().getVersionInd());
472         }
473         copy.setMeta(updateMeta(copy.getMeta(), context));
474         this.socRolloverResultMap.put(socRolloverResultInfo.getId(), copy);
475         return new SocRolloverResultInfo(copy);
476     }
477 
478     @Override
479     public SocRolloverResultInfo updateSocRolloverProgress(String socRolloverResultId, Integer itemsProcessed, ContextInfo context)
480             throws DataValidationErrorException, DoesNotExistException, InvalidParameterException, MissingParameterException,
481             OperationFailedException, PermissionDeniedException, ReadOnlyException, VersionMismatchException {
482         SocRolloverResultInfo info = this.getSocRolloverResult(socRolloverResultId, context);
483         info = new SocRolloverResultInfo(info);
484         info.setItemsProcessed(itemsProcessed);
485         return this.updateSocRolloverResult(info.getId(), info, context);
486     }
487 
488     @Override
489     public StatusInfo deleteSocRolloverResult(String socRolloverResultId, ContextInfo context)
490             throws DoesNotExistException, DependentObjectsExistException,
491             InvalidParameterException, MissingParameterException, OperationFailedException,
492             PermissionDeniedException {
493         List<SocRolloverResultItemInfo> items = this.getSocRolloverResultItemsByResultId(socRolloverResultId, context);
494         if ( ! items.isEmpty()) {
495             throw new DependentObjectsExistException(items.size() + " items exist");
496         }
497         if (this.socRolloverResultMap.remove(socRolloverResultId) == null) {
498             throw new DoesNotExistException(socRolloverResultId);
499         }
500         return newStatus();
501     }
502 
503     @Override
504     public List<ValidationResultInfo> validateSocRolloverResult(String validationType, SocRolloverResultInfo socRolloverResultInfo, ContextInfo context)
505             throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException {
506         // validate
507         return new ArrayList<ValidationResultInfo>();
508     }
509 
510     @Override
511     public SocRolloverResultItemInfo getSocRolloverResultItem(String socRolloverResultItemId, ContextInfo context)
512             throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException,
513             PermissionDeniedException {
514         if ( ! this.socRolloverResultItemMap.containsKey(socRolloverResultItemId)) {
515             throw new DoesNotExistException(socRolloverResultItemId);
516         }
517         return this.socRolloverResultItemMap.get(socRolloverResultItemId);
518     }
519     // cache variable 
520     // The LinkedHashMap is just so the values come back in a predictable order
521     private Map<String, SocRolloverResultItemInfo> socRolloverResultItemMap = new LinkedHashMap<String, SocRolloverResultItemInfo>();
522 
523     @Override
524     public SocRolloverResultItemInfo createSocRolloverResultItem(String socRolloverResultId, String socRolloverResultItemTypeKey, SocRolloverResultItemInfo socRolloverResultItemInfo, ContextInfo context)
525             throws DoesNotExistException, DataValidationErrorException, InvalidParameterException, MissingParameterException,
526             OperationFailedException, PermissionDeniedException, ReadOnlyException {
527         // create 
528         if ( ! socRolloverResultItemTypeKey.equals(socRolloverResultItemInfo.getTypeKey())) {
529             throw new InvalidParameterException("The type parameter does not match the type on the info object");
530         }
531         // TODO: check the rest of the readonly fields that are specified on the create to make sure they match the info object
532         SocRolloverResultItemInfo copy = new SocRolloverResultItemInfo(socRolloverResultItemInfo);
533         if (copy.getId() == null) {
534             copy.setId(UUIDHelper.genStringUUID());
535         }
536         copy.setMeta(newMeta(context));
537         socRolloverResultItemMap.put(copy.getId(), copy);
538         return new SocRolloverResultItemInfo(copy);
539     }
540 
541     @Override
542     public Integer createSocRolloverResultItems(String socRolloverResultId, String typeKey,
543             List<SocRolloverResultItemInfo> infos, ContextInfo context)
544             throws DoesNotExistException, DataValidationErrorException, InvalidParameterException, MissingParameterException,
545             OperationFailedException, PermissionDeniedException, ReadOnlyException {
546         int count = 0;
547         for (SocRolloverResultItemInfo info : infos) {
548             count ++;
549             this.createSocRolloverResultItem(socRolloverResultId, typeKey, info, context);
550         }
551         return Integer.valueOf(count);
552     }
553 
554     @Override
555     public SocRolloverResultItemInfo updateSocRolloverResultItem(String socRolloverResultItemId, SocRolloverResultItemInfo socRolloverResultItemInfo, ContextInfo context)
556             throws DataValidationErrorException, DoesNotExistException, InvalidParameterException, MissingParameterException,
557             OperationFailedException, PermissionDeniedException, ReadOnlyException, VersionMismatchException {
558         // update
559         if ( ! socRolloverResultItemId.equals(socRolloverResultItemInfo.getId())) {
560             throw new InvalidParameterException("The id parameter does not match the id on the info object");
561         }
562         SocRolloverResultItemInfo copy = new SocRolloverResultItemInfo(socRolloverResultItemInfo);
563         SocRolloverResultItemInfo old = this.getSocRolloverResultItem(socRolloverResultItemInfo.getId(), context);
564         if ( ! old.getMeta().getVersionInd().equals(copy.getMeta().getVersionInd())) {
565             throw new VersionMismatchException(old.getMeta().getVersionInd());
566         }
567         copy.setMeta(updateMeta(copy.getMeta(), context));
568         this.socRolloverResultItemMap.put(socRolloverResultItemInfo.getId(), copy);
569         return new SocRolloverResultItemInfo(copy);
570     }
571 
572     @Override
573     public StatusInfo deleteSocRolloverResultItem(String socRolloverResultItemId, ContextInfo context)
574             throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException,
575             PermissionDeniedException {
576         if (this.socRolloverResultItemMap.remove(socRolloverResultItemId) == null) {
577             throw new DoesNotExistException(socRolloverResultItemId);
578         }
579         return newStatus();
580     }
581 
582     @Override
583     public List<ValidationResultInfo> validateSocRolloverResultItem(String validationType, SocRolloverResultItemInfo socRolloverResultItemInfo, ContextInfo context)
584             throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException {
585         // validate
586         return new ArrayList<ValidationResultInfo>();
587     }
588 
589     @Override
590     public List<String> searchForSocRolloverResultIds(@WebParam(name = "criteria") QueryByCriteria criteria, @WebParam(name = "context") ContextInfo context) throws
591             InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException {
592         throw new UnsupportedOperationException("Not supported yet.");
593     }
594 
595     @Override
596     public List<SocRolloverResultInfo> searchForSocRolloverResults(@WebParam(name = "criteria") QueryByCriteria criteria, @WebParam(name = "context") ContextInfo context) throws
597             InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException {
598         //throw new UnsupportedOperationException("Not supported yet.");
599         List<SocRolloverResultInfo> socRolloverResultInfos = new ArrayList<SocRolloverResultInfo>();
600 
601         EqualPredicate predicate = (EqualPredicate) criteria.getPredicate();
602         String targetTerm = (String) predicate.getValue().getValue();
603         for (Map.Entry<String, SocRolloverResultInfo> entry : socRolloverResultMap.entrySet()) {
604             if (entry.getValue().getTargetTermId().equalsIgnoreCase(targetTerm)) {
605                 socRolloverResultInfos.add(entry.getValue());
606                 try {
607                     // TODO: This looks strange --cclin
608                     List<SocRolloverResultItemInfo> socRolloverResultItemInfos = getSocRolloverResultItemsByResultId(entry.getValue().getSourceSocId() + entry.getValue().getTargetSocId(),
609                             new ContextInfo());
610                 } catch (UnhandledException ue) {
611                 } catch (DoesNotExistException dne) {
612                 }
613             }
614         }
615         return socRolloverResultInfos;
616     }
617 
618     private MetaInfo newMeta(ContextInfo context) {
619         MetaInfo meta = new MetaInfo();
620         meta.setCreateId(context.getPrincipalId());
621         meta.setCreateTime(new Date());
622         meta.setUpdateId(context.getPrincipalId());
623         meta.setUpdateTime(meta.getCreateTime());
624         meta.setVersionInd("0");
625         return meta;
626     }
627 
628     private StatusInfo newStatus() {
629         StatusInfo status = new StatusInfo();
630         status.setSuccess(Boolean.TRUE);
631         return status;
632     }
633 
634     private MetaInfo updateMeta(MetaInfo old, ContextInfo context) {
635         MetaInfo meta = new MetaInfo(old);
636         meta.setUpdateId(context.getPrincipalId());
637         meta.setUpdateTime(new Date());
638         meta.setVersionInd((Integer.parseInt(meta.getVersionInd()) + 1) + "");
639         return meta;
640     }
641 
642     @Override
643     public StatusInfo updateSocState(@WebParam(name = "socId") String socId,
644             @WebParam(name = "nextStateKey") String nextStateKey,
645             @WebParam(name = "contextInfo") ContextInfo contextInfo)
646             throws DoesNotExistException, InvalidParameterException,
647             MissingParameterException, OperationFailedException,
648             PermissionDeniedException {
649 
650         try {
651             /*
652              * get won't work because it doesn't return the map bound instance.
653              * We need to get that instance ourselves manually.
654              */
655             SocInfo soc = this.socMap.get(socId);
656 
657             if (soc == null) {
658                 throw new DoesNotExistException("No Soc for id= " + socId);
659             }
660             // TODO: call verifySocForState to make sure it is legal to change the state
661             soc.setStateKey(nextStateKey);
662             this.updateMeta(soc.getMeta(), contextInfo);
663             this.logStateChange(soc, contextInfo);
664             return newStatus();
665 
666         } catch (Exception e) {
667             throw new OperationFailedException("updateSocState (id=" + socId + ", nextStateKey=" + nextStateKey, e);
668         }
669     }
670 
671     private void logStateChange(SocInfo soc, ContextInfo contextInfo) {
672         // add the state change to the log
673         // TODO: consider changing this to a call to a real logging facility instead of stuffing it in the dynamic attributes
674         SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ");
675         Date date = contextInfo.getCurrentDate();
676         soc.getAttributes().add(new AttributeInfo(soc.getStateKey(), formatter.format(date)));
677     }
678     
679     @Override
680     public StatusInfo updateSocRolloverResultState(
681             @WebParam(name = "socRolloverResultId") String socRolloverResultId,
682             @WebParam(name = "nextStateKey") String nextStateKey,
683             @WebParam(name = "contextInfo") ContextInfo contextInfo)
684             throws DoesNotExistException, InvalidParameterException,
685             MissingParameterException, OperationFailedException,
686             PermissionDeniedException {
687         try {
688             /*
689              * get won't work because it doesn't return the map bound instance.
690              * We need to get that instance ourselves manually.
691              */
692             SocRolloverResultInfo socRolloverResults = this.socRolloverResultMap.get(socRolloverResultId);
693 
694             if (socRolloverResults == null) {
695                 throw new DoesNotExistException("No SocRolloverResult for id= " + socRolloverResultId);
696             }
697             socRolloverResults.setStateKey(nextStateKey);
698             return newStatus();
699 
700         } catch (Exception e) {
701             throw new OperationFailedException("updateSocRolloverResultState (id=" + socRolloverResultId + ", nextStateKey=" + nextStateKey, e);
702         }
703     }
704 
705     @Override
706     public StatusInfo updateSocRolloverResultItemState(
707             @WebParam(name = "socRolloverResultItemId") String socRolloverResultItemId,
708             @WebParam(name = "nextStateKey") String nextStateKey,
709             @WebParam(name = "contextInfo") ContextInfo contextInfo)
710             throws DoesNotExistException, InvalidParameterException,
711             MissingParameterException, OperationFailedException,
712             PermissionDeniedException {
713         try {
714             /*
715              * get won't work because it doesn't return the map bound instance.
716              * We need to get that instance ourselves manually.
717              */
718             SocInfo socRolloverResultItem = this.socMap.get(socRolloverResultItemId);
719 
720             if (socRolloverResultItem == null) {
721                 throw new DoesNotExistException("No SocRolloverResultItem for id= " + socRolloverResultItemId);
722             }
723 
724             socRolloverResultItem.setStateKey(nextStateKey);
725 
726             return newStatus();
727 
728         } catch (Exception e) {
729             throw new OperationFailedException("updateSocRolloverResultItemState (id=" + socRolloverResultItemId + ", nextStateKey=" + nextStateKey, e);
730         }
731     }
732 
733     @Override
734     public List<String> searchForSocRolloverResultItemIds(QueryByCriteria criteria, ContextInfo context) throws InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException {
735         throw new UnsupportedOperationException("Not supported yet.");
736     }
737 
738     @Override
739     public List<SocRolloverResultItemInfo> searchForSocRolloverResultItems(QueryByCriteria criteria, ContextInfo context) throws InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException {
740         throw new UnsupportedOperationException("Not supported yet.");
741     }
742     
743     
744 }