1
2
3
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.enrollment.courseofferingset.dto.SocInfo;
12 import org.kuali.student.enrollment.courseofferingset.dto.SocRolloverResultInfo;
13 import org.kuali.student.enrollment.courseofferingset.dto.SocRolloverResultItemInfo;
14 import org.kuali.student.enrollment.courseofferingset.service.CourseOfferingSetService;
15 import org.kuali.student.enrollment.courseofferingset.service.CourseOfferingSetServiceBusinessLogic;
16 import org.kuali.student.r2.common.dto.ContextInfo;
17 import org.kuali.student.r2.common.dto.MetaInfo;
18 import org.kuali.student.r2.common.dto.StatusInfo;
19 import org.kuali.student.r2.common.dto.ValidationResultInfo;
20 import org.kuali.student.r2.common.exceptions.*;
21 import org.kuali.student.r2.common.util.RichTextHelper;
22 import org.kuali.student.r2.common.util.constants.CourseOfferingSetServiceConstants;
23
24 import javax.jws.WebParam;
25 import java.util.*;
26
27 public class CourseOfferingSetServiceMockImpl implements CourseOfferingSetService, MockService {
28
29 private CourseOfferingSetServiceBusinessLogic businessLogic;
30
31
32 @Override
33 public void clear() {
34 this.socMap.clear();
35 this.socRolloverResultItemMap.clear();
36 this.socRolloverResultMap.clear();
37
38 }
39
40 public CourseOfferingSetServiceBusinessLogic getBusinessLogic() {
41 return businessLogic;
42 }
43
44 public void setBusinessLogic(CourseOfferingSetServiceBusinessLogic businessLogic) {
45 this.businessLogic = businessLogic;
46 }
47
48 public CourseOfferingSetServiceMockImpl(){
49 Integer year = 2001;
50 for(int i=0;i<10;i++){
51 SocRolloverResultInfo result = new SocRolloverResultInfo();
52 result.setMessage(new RichTextHelper().toRichTextInfo("message plain " +i, "message formatted "+i));
53 result.setTypeKey(CourseOfferingSetServiceConstants.ROLLOVER_RESULT_TYPE_KEY);
54 result.setStateKey(CourseOfferingSetServiceConstants.SUBMITTED_RESULT_STATE_KEY);
55 result.setItemsExpected(5);
56 result.setItemsProcessed(2);
57 result.setCourseOfferingsSkipped(3);
58 result.setSourceSocId("sourceSocId"+i);
59 result.setTargetSocId("targetSocId"+i);
60 result.setSourceTermId("Fall " + year);
61 result.setTargetTermId("Fall " + ++year);
62 result.getOptionKeys().add("my first option");
63 result.getOptionKeys().add("my 2nd option");
64 try{
65 result = createSocRolloverResult(result.getTypeKey(), result,new ContextInfo());
66 List<SocRolloverResultItemInfo> socRolloverResultItemInfos = new ArrayList<SocRolloverResultItemInfo>();
67 SocRolloverResultItemInfo socRolloverResultItemInfo1 = new SocRolloverResultItemInfo();
68 socRolloverResultItemInfo1.setSocRolloverResultId(result.getSourceSocId()+result.getTargetSocId());
69 socRolloverResultItemInfo1.setMessage(new RichTextHelper().toRichTextInfo("Cancelled;Cancelled during source term", "Cancelled;Cancelled during source term"));
70 socRolloverResultItemInfo1.setSourceCourseOfferingId("ENG428");
71 socRolloverResultItemInfo1.setTargetCourseOfferingId("ENG428");
72 socRolloverResultItemInfo1.setTypeKey(CourseOfferingSetServiceConstants.ROLLOVER_RESULT_TYPE_KEY);
73 socRolloverResultItemInfos.add(socRolloverResultItemInfo1);
74 SocRolloverResultItemInfo socRolloverResultItemInfo2 = new SocRolloverResultItemInfo();
75 socRolloverResultItemInfo2.setSocRolloverResultId(result.getSourceSocId()+result.getTargetSocId());
76 socRolloverResultItemInfo2.setMessage(new RichTextHelper().toRichTextInfo("New version;New version of the course exists","New version;New version of the course exists"));
77 socRolloverResultItemInfo2.setSourceCourseOfferingId("ENG364");
78 socRolloverResultItemInfo2.setTargetCourseOfferingId("ENG364");
79 socRolloverResultItemInfo2.setTypeKey(CourseOfferingSetServiceConstants.ROLLOVER_RESULT_TYPE_KEY);
80 socRolloverResultItemInfos.add(socRolloverResultItemInfo2);
81 SocRolloverResultItemInfo socRolloverResultItemInfo3 = new SocRolloverResultItemInfo();
82 socRolloverResultItemInfo3.setSocRolloverResultId(result.getSourceSocId()+result.getTargetSocId());
83 socRolloverResultItemInfo3.setMessage(new RichTextHelper().toRichTextInfo("Retired;No longer offered,as of January 1, 2012","Retired;No longer offered,as of January 1, 2012"));
84 socRolloverResultItemInfo3.setSourceCourseOfferingId("MATH140");
85 socRolloverResultItemInfo3.setTargetCourseOfferingId("MATH140");
86 socRolloverResultItemInfo3.setTypeKey(CourseOfferingSetServiceConstants.ROLLOVER_RESULT_TYPE_KEY);
87 socRolloverResultItemInfos.add(socRolloverResultItemInfo3);
88 SocRolloverResultItemInfo socRolloverResultItemInfo4 = new SocRolloverResultItemInfo();
89 socRolloverResultItemInfo4.setSocRolloverResultId(result.getSourceSocId()+result.getTargetSocId());
90 socRolloverResultItemInfo4.setMessage(new RichTextHelper().toRichTextInfo("Cancelled;Cancelled during source term","Cancelled;Cancelled during source term"));
91 socRolloverResultItemInfo4.setSourceCourseOfferingId("MATH140");
92 socRolloverResultItemInfo4.setTargetCourseOfferingId("MATH140");
93 socRolloverResultItemInfo4.setTypeKey(CourseOfferingSetServiceConstants.ROLLOVER_RESULT_TYPE_KEY);
94 socRolloverResultItemInfos.add(socRolloverResultItemInfo4);
95 createSocRolloverResultItems(result.getSourceSocId()+result.getTargetSocId(),CourseOfferingSetServiceConstants.ROLLOVER_RESULT_TYPE_KEY,socRolloverResultItemInfos,new ContextInfo());
96 }catch(DoesNotExistException de){
97
98 }
99 catch(DataValidationErrorException dve){
100
101 }
102 catch(ReadOnlyException roe){
103
104 }
105 catch(MissingParameterException mpe){
106
107 }
108 catch(PermissionDeniedException pde){
109
110 }
111 catch(InvalidParameterException ipe){
112
113 }
114 catch(OperationFailedException ofe){
115
116 }
117 }
118 }
119
120
121
122
123 @Override
124 public SocInfo getSoc(String socId, ContextInfo context)
125 throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException,
126 PermissionDeniedException {
127 if (!this.socMap.containsKey(socId)) {
128 throw new DoesNotExistException(socId);
129 }
130 return this.socMap.get(socId);
131 }
132
133 @Override
134 public List<SocInfo> getSocsByIds(List<String> socIds, ContextInfo context)
135 throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException,
136 PermissionDeniedException {
137 List<SocInfo> list = new ArrayList<SocInfo>();
138 for (String id : socIds) {
139 list.add(this.getSoc(id, context));
140 }
141 return list;
142 }
143
144 @Override
145 public List<String> getSocIdsByTerm(String termId, ContextInfo context)
146 throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException,
147 PermissionDeniedException {
148 List<String> list = new ArrayList<String>();
149 for (SocInfo info : socMap.values()) {
150 if (termId.equals(info.getTermId())) {
151 list.add(info.getId());
152 }
153 }
154 return list;
155 }
156
157 @Override
158 public List<String> getSocIdsByTermAndSubjectArea(String termId, String subjectArea, ContextInfo context)
159 throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException,
160 PermissionDeniedException {
161 List<String> list = new ArrayList<String>();
162 for (SocInfo info : socMap.values()) {
163 if (termId.equals(info.getTermId())) {
164 if (subjectArea.equals(info.getSubjectArea())) {
165 list.add(info.getId());
166 }
167 }
168 }
169 return list;
170 }
171
172 @Override
173 public List<String> getSocIdsByTermAndUnitsContentOwner(String termId, String unitsContentOwnerId, ContextInfo context)
174 throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException,
175 PermissionDeniedException {
176 List<String> list = new ArrayList<String>();
177 for (SocInfo info : socMap.values()) {
178 if (termId.equals(info.getTermId())) {
179 if (unitsContentOwnerId.equals(info.getUnitsContentOwnerId())) {
180 list.add(info.getId());
181 }
182 }
183 }
184 return list;
185 }
186
187 @Override
188 public List<String> getSocIdsByType(String typeKey, ContextInfo context)
189 throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException,
190 PermissionDeniedException {
191 List<String> list = new ArrayList<String>();
192 for (SocInfo info : socMap.values()) {
193 if (typeKey.equals(info.getTypeKey())) {
194 list.add(info.getId());
195 }
196 }
197 return list;
198 }
199
200
201 private Map<String, SocInfo> socMap = new LinkedHashMap<String, SocInfo>();
202
203 @Override
204 public SocInfo createSoc(String termId, String socTypeKey, SocInfo socInfo, ContextInfo context)
205 throws DoesNotExistException, DataValidationErrorException, InvalidParameterException, MissingParameterException,
206 OperationFailedException, PermissionDeniedException, ReadOnlyException {
207
208 if (!socTypeKey.equals(socInfo.getTypeKey())) {
209 throw new InvalidParameterException("The type parameter does not match the type on the info object");
210 }
211
212 SocInfo copy = new SocInfo(socInfo);
213 if (copy.getId() == null) {
214 copy.setId(socMap.size() + "");
215 }
216 copy.setMeta(newMeta(context));
217 socMap.put(copy.getId(), copy);
218 return new SocInfo(copy);
219 }
220
221 @Override
222 public SocInfo updateSoc(String socId, SocInfo socInfo, ContextInfo context)
223 throws DataValidationErrorException, DoesNotExistException, InvalidParameterException, MissingParameterException,
224 OperationFailedException, PermissionDeniedException, ReadOnlyException, VersionMismatchException {
225
226 if (!socId.equals(socInfo.getId())) {
227 throw new InvalidParameterException("The id parameter does not match the id on the info object");
228 }
229 SocInfo copy = new SocInfo(socInfo);
230 SocInfo old = this.getSoc(socInfo.getId(), context);
231 if (!old.getMeta().getVersionInd().equals(copy.getMeta().getVersionInd())) {
232 throw new VersionMismatchException(old.getMeta().getVersionInd());
233 }
234 copy.setMeta(updateMeta(copy.getMeta(), context));
235 this.socMap.put(socInfo.getId(), copy);
236 return new SocInfo(copy);
237 }
238
239 @Override
240 public StatusInfo deleteSoc(String socId, ContextInfo context)
241 throws DependentObjectsExistException, DoesNotExistException, InvalidParameterException, MissingParameterException,
242 OperationFailedException, PermissionDeniedException {
243 if (this.socMap.remove(socId) == null) {
244 throw new DoesNotExistException(socId);
245 }
246 return newStatus();
247 }
248
249 @Override
250 public List<ValidationResultInfo> validateSoc(String validationType, SocInfo socInfo, ContextInfo context)
251 throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException {
252
253 return new ArrayList<ValidationResultInfo>();
254 }
255
256 @Override
257 public List<String> getSocIdsByCourseOffering(String courseOfferingId, ContextInfo context)
258 throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException,
259 PermissionDeniedException {
260 List<String> list = new ArrayList<String>();
261 for (SocInfo info : socMap.values()) {
262 if (this.isCourseOfferingInSoc(info.getId(), courseOfferingId, context)) {
263 list.add(info.getId());
264 }
265 }
266 return list;
267 }
268
269 @Override
270 public List<String> getCourseOfferingIdsBySoc(String socId, ContextInfo context)
271 throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException,
272 PermissionDeniedException {
273 return this.businessLogic.getCourseOfferingIdsBySoc(socId, context);
274 }
275
276 @Override
277 public Integer deleteCourseOfferingsBySoc(String socId, ContextInfo context)
278 throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException,
279 PermissionDeniedException {
280 return this.businessLogic.deleteCourseOfferingsBySoc(socId, context);
281 }
282
283 @Override
284 public Boolean isCourseOfferingInSoc(String socId, String courseOfferingId, ContextInfo context)
285 throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException,
286 PermissionDeniedException {
287 return this.businessLogic.isCourseOfferingInSoc(socId, courseOfferingId, context);
288 }
289
290 @Override
291 public List<String> getPublishedCourseOfferingIdsBySoc(String socId, ContextInfo context)
292 throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException,
293 PermissionDeniedException {
294 return this.businessLogic.getPublishedCourseOfferingIdsBySoc(socId, context);
295 }
296
297 @Override
298 public List<String> getUnpublishedCourseOfferingIdsBySoc(String socId, ContextInfo context)
299 throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException,
300 PermissionDeniedException {
301 return this.businessLogic.getUnpublishedActivityOfferingIdsBySoc(socId, context);
302 }
303
304 @Override
305 public List<String> getUnpublishedActivityOfferingIdsBySoc(String socId, ContextInfo context)
306 throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException,
307 PermissionDeniedException {
308 return this.businessLogic.getUnpublishedActivityOfferingIdsBySoc(socId, context);
309 }
310
311 @Override
312 public List<String> getUnscheduledActivityOfferingIdsBySoc(String socId, ContextInfo context)
313 throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException,
314 PermissionDeniedException {
315 throw new OperationFailedException("not impemented");
316 }
317
318 @Override
319 public List<String> getCourseOfferingIdsWithUnscheduledFinalExamsBySoc(String socId, ContextInfo context)
320 throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException,
321 PermissionDeniedException {
322 throw new OperationFailedException("not been implemented");
323 }
324
325 @Override
326 public StatusInfo scheduleSoc(String socId, ContextInfo context)
327 throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException,
328 PermissionDeniedException {
329 throw new OperationFailedException("scheduleSoc has not been implemented");
330 }
331
332 @Override
333 public SocInfo rolloverSoc(String sourceSocId, String targetTermId, List<String> optionKeys, ContextInfo context)
334 throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException,
335 PermissionDeniedException {
336 return this.businessLogic.rolloverSoc(sourceSocId, targetTermId, optionKeys, context);
337 }
338
339 @Override
340 public SocRolloverResultInfo getSocRolloverResult(String rolloverResultId, ContextInfo context)
341 throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException,
342 PermissionDeniedException {
343 if (!this.socRolloverResultMap.containsKey(rolloverResultId)) {
344 throw new DoesNotExistException(rolloverResultId);
345 }
346 SocRolloverResultInfo info = new SocRolloverResultInfo(this.socRolloverResultMap.get(rolloverResultId));
347 this.updateCalculatedFields(info, context);
348 return info;
349 }
350
351 private void updateCalculatedFields(SocRolloverResultInfo info, ContextInfo context) throws OperationFailedException {
352 try {
353 if (info.getSourceSocId() != null) {
354 SocInfo sourceSoc = this.getSoc(info.getSourceSocId(), context);
355 info.setSourceTermId(sourceSoc.getTermId());
356 }
357
358 if (info.getStateKey().equals(CourseOfferingSetServiceConstants.FINISHED_RESULT_STATE_KEY)) {
359 List<SocRolloverResultItemInfo> items = this.getSocRolloverResultItemsByResultId(info.getId(), context);
360 int success = 0;
361 int failure = 0;
362 for (SocRolloverResultItemInfo item : items) {
363 if (CourseOfferingSetServiceConstants.SUCCESSFUL_RESULT_ITEM_STATES.contains(item.getStateKey())) {
364 success++;
365 } else {
366 failure++;
367 }
368 }
369 info.setCourseOfferingsCreated(success);
370 info.setCourseOfferingsSkipped(failure);
371 }
372 } catch (Exception ex) {
373 throw new OperationFailedException("unexpected", ex);
374 }
375 }
376
377 @Override
378 public List<SocRolloverResultInfo> getSocRolloverResultsByIds(List<String> rolloverResultIds, ContextInfo context)
379 throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException,
380 PermissionDeniedException {
381 List<SocRolloverResultInfo> list = new ArrayList<SocRolloverResultInfo>();
382 for (String id : rolloverResultIds) {
383 list.add(this.getSocRolloverResult(id, context));
384 }
385 return list;
386 }
387
388 @Override
389 public List<SocRolloverResultItemInfo> getSocRolloverResultItemsByIds(List<String> rolloverResultItemIds, ContextInfo context)
390 throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException,
391 PermissionDeniedException {
392 List<SocRolloverResultItemInfo> list = new ArrayList<SocRolloverResultItemInfo>();
393 for (String id : rolloverResultItemIds) {
394 list.add(this.getSocRolloverResultItem(id, context));
395 }
396 return list;
397 }
398
399 @Override
400 public List<SocRolloverResultItemInfo> getSocRolloverResultItemsByResultId(String socRolloverResultId, ContextInfo context)
401 throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException,
402 PermissionDeniedException {
403 List<SocRolloverResultItemInfo> list = new ArrayList<SocRolloverResultItemInfo>();
404 for (SocRolloverResultItemInfo info : socRolloverResultItemMap.values()) {
405 if (socRolloverResultId.equals(info.getSocRolloverResultId())) {
406 list.add(info);
407 }
408 }
409 return list;
410 }
411
412 @Override
413 public List<SocRolloverResultInfo> getSocRolloverResultsBySourceAndTargetSocs(String sourceSocId, String targetSocId, ContextInfo context) throws
414 DoesNotExistException,
415 InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException {
416 List<SocRolloverResultInfo> list = new ArrayList<SocRolloverResultInfo>();
417
418 for (SocRolloverResultInfo info : socRolloverResultMap.values()) {
419 if (sourceSocId.equals(info.getSourceSocId())) {
420 if (targetSocId.equals(info.getTargetSocId())) {
421 list.add(info);
422 }
423 }
424 }
425 return list;
426 }
427
428 @Override
429 public List<SocRolloverResultItemInfo> getSocRolloverResultItemsByResultIdAndSourceCourseOfferingId(String socRolloverResultId, String sourceCourseOfferingId, ContextInfo context)
430 throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException,
431 PermissionDeniedException {
432 List<SocRolloverResultItemInfo> list = new ArrayList<SocRolloverResultItemInfo>();
433 for (SocRolloverResultItemInfo info : socRolloverResultItemMap.values()) {
434 if (socRolloverResultId.equals(info.getSocRolloverResultId())) {
435 if (sourceCourseOfferingId.equals(info.getTargetCourseOfferingId())) {
436 list.add(info);
437 }
438 }
439 }
440 return list;
441 }
442
443 @Override
444 public List<SocRolloverResultItemInfo> getSocRolloverResultItemsByResultIdAndTargetCourseOfferingId(String socRolloverResultId, String targetCourseOfferingId, ContextInfo context)
445 throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException,
446 PermissionDeniedException {
447 List<SocRolloverResultItemInfo> list = new ArrayList<SocRolloverResultItemInfo>();
448 for (SocRolloverResultItemInfo info : socRolloverResultItemMap.values()) {
449 if (socRolloverResultId.equals(info.getSocRolloverResultId())) {
450 if (targetCourseOfferingId.equals(info.getTargetCourseOfferingId())) {
451 list.add(info);
452 }
453 }
454 }
455 return list;
456 }
457
458 @Override
459 public List<String> getSocRolloverResultIdsByTargetSoc(String targetSocId, ContextInfo context)
460 throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException,
461 PermissionDeniedException {
462 List<String> list = new ArrayList<String>();
463 for (SocRolloverResultInfo info : socRolloverResultMap.values()) {
464 if (targetSocId.equals(info.getTargetSocId())) {
465 list.add(info.getId());
466 }
467 }
468 return list;
469 }
470
471 @Override
472 public List<String> getSocRolloverResultIdsBySourceSoc(String sourceSocId, ContextInfo context)
473 throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException,
474 PermissionDeniedException {
475 List<String> list = new ArrayList<String>();
476 for (SocRolloverResultInfo info : socRolloverResultMap.values()) {
477 if (sourceSocId.equals(info.getSourceSocId())) {
478 list.add(info.getId());
479 }
480 }
481 return list;
482 }
483
484 @Override
485 public SocRolloverResultInfo reverseRollover(String rolloverResultId, List<String> optionKeys, ContextInfo context)
486 throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException,
487 PermissionDeniedException {
488 return this.businessLogic.reverseRollover(rolloverResultId, optionKeys, context);
489 }
490
491
492 private Map<String, SocRolloverResultInfo> socRolloverResultMap = new LinkedHashMap<String, SocRolloverResultInfo>();
493
494 @Override
495 public SocRolloverResultInfo createSocRolloverResult(String socRolloverResultTypeKey, SocRolloverResultInfo socRolloverResultInfo, ContextInfo context)
496 throws DoesNotExistException, DataValidationErrorException, InvalidParameterException, MissingParameterException,
497 OperationFailedException, PermissionDeniedException, ReadOnlyException {
498
499 if (!socRolloverResultTypeKey.equals(socRolloverResultInfo.getTypeKey())) {
500 throw new InvalidParameterException("The type parameter does not match the type on the info object");
501 }
502 SocRolloverResultInfo copy = new SocRolloverResultInfo(socRolloverResultInfo);
503 if (copy.getId() == null) {
504 copy.setId(socRolloverResultMap.size() + "");
505 }
506 copy.setMeta(newMeta(context));
507 socRolloverResultMap.put(copy.getId(), copy);
508 return new SocRolloverResultInfo(copy);
509 }
510
511 @Override
512 public SocRolloverResultInfo updateSocRolloverResult(String socRolloverResultId, SocRolloverResultInfo socRolloverResultInfo, ContextInfo context)
513 throws DataValidationErrorException, DoesNotExistException, InvalidParameterException, MissingParameterException,
514 OperationFailedException, PermissionDeniedException, ReadOnlyException, VersionMismatchException {
515
516 if (!socRolloverResultId.equals(socRolloverResultInfo.getId())) {
517 throw new InvalidParameterException("The id parameter does not match the id on the info object");
518 }
519 SocRolloverResultInfo copy = new SocRolloverResultInfo(socRolloverResultInfo);
520 SocRolloverResultInfo old = this.getSocRolloverResult(socRolloverResultInfo.getId(), context);
521 if (!old.getMeta().getVersionInd().equals(copy.getMeta().getVersionInd())) {
522 throw new VersionMismatchException(old.getMeta().getVersionInd());
523 }
524 copy.setMeta(updateMeta(copy.getMeta(), context));
525 this.socRolloverResultMap.put(socRolloverResultInfo.getId(), copy);
526 return new SocRolloverResultInfo(copy);
527 }
528
529 @Override
530 public SocRolloverResultInfo updateSocRolloverProgress(String socRolloverResultId, Integer itemsProcessed, ContextInfo context)
531 throws DataValidationErrorException, DoesNotExistException, InvalidParameterException, MissingParameterException,
532 OperationFailedException, PermissionDeniedException, ReadOnlyException, VersionMismatchException {
533 SocRolloverResultInfo info = this.getSocRolloverResult(socRolloverResultId, context);
534 info = new SocRolloverResultInfo(info);
535 info.setItemsProcessed(itemsProcessed);
536 return this.updateSocRolloverResult(info.getId(), info, context);
537 }
538
539 @Override
540 public StatusInfo deleteSocRolloverResult(String socRolloverResultId, ContextInfo context)
541 throws DoesNotExistException, DependentObjectsExistException,
542 InvalidParameterException, MissingParameterException, OperationFailedException,
543 PermissionDeniedException {
544 List<SocRolloverResultItemInfo> items = this.getSocRolloverResultItemsByResultId(socRolloverResultId, context);
545 if (!items.isEmpty()) {
546 throw new DependentObjectsExistException(items.size() + " items exist");
547 }
548 if (this.socRolloverResultMap.remove(socRolloverResultId) == null) {
549 throw new DoesNotExistException(socRolloverResultId);
550 }
551 return newStatus();
552 }
553
554 @Override
555 public List<ValidationResultInfo> validateSocRolloverResult(String validationType, SocRolloverResultInfo socRolloverResultInfo, ContextInfo context)
556 throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException {
557
558 return new ArrayList<ValidationResultInfo>();
559 }
560
561 @Override
562 public SocRolloverResultItemInfo getSocRolloverResultItem(String socRolloverResultItemId, ContextInfo context)
563 throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException,
564 PermissionDeniedException {
565 if (!this.socRolloverResultItemMap.containsKey(socRolloverResultItemId)) {
566 throw new DoesNotExistException(socRolloverResultItemId);
567 }
568 return this.socRolloverResultItemMap.get(socRolloverResultItemId);
569 }
570
571
572 private Map<String, SocRolloverResultItemInfo> socRolloverResultItemMap = new LinkedHashMap<String, SocRolloverResultItemInfo>();
573
574 @Override
575 public SocRolloverResultItemInfo createSocRolloverResultItem(String socRolloverResultId, String socRolloverResultItemTypeKey, SocRolloverResultItemInfo socRolloverResultItemInfo, ContextInfo context)
576 throws DoesNotExistException, DataValidationErrorException, InvalidParameterException, MissingParameterException,
577 OperationFailedException, PermissionDeniedException, ReadOnlyException {
578
579 if (!socRolloverResultItemTypeKey.equals(socRolloverResultItemInfo.getTypeKey())) {
580 throw new InvalidParameterException("The type parameter does not match the type on the info object");
581 }
582
583 SocRolloverResultItemInfo copy = new SocRolloverResultItemInfo(socRolloverResultItemInfo);
584 if (copy.getId() == null) {
585 copy.setId(socRolloverResultItemMap.size() + "");
586 }
587 copy.setMeta(newMeta(context));
588 socRolloverResultItemMap.put(copy.getId(), copy);
589 return new SocRolloverResultItemInfo(copy);
590 }
591
592 @Override
593 public Integer createSocRolloverResultItems(String socRolloverResultId, String typeKey,
594 List<SocRolloverResultItemInfo> infos, ContextInfo context)
595 throws DoesNotExistException, DataValidationErrorException, InvalidParameterException, MissingParameterException,
596 OperationFailedException, PermissionDeniedException, ReadOnlyException {
597 int count = 0;
598 for (SocRolloverResultItemInfo info : infos) {
599 count++;
600 this.createSocRolloverResultItem(socRolloverResultId, typeKey, info, context);
601 }
602 return new Integer(count);
603 }
604
605 @Override
606 public SocRolloverResultItemInfo updateSocRolloverResultItem(String socRolloverResultItemId, SocRolloverResultItemInfo socRolloverResultItemInfo, ContextInfo context)
607 throws DataValidationErrorException, DoesNotExistException, InvalidParameterException, MissingParameterException,
608 OperationFailedException, PermissionDeniedException, ReadOnlyException, VersionMismatchException {
609
610 if (!socRolloverResultItemId.equals(socRolloverResultItemInfo.getId())) {
611 throw new InvalidParameterException("The id parameter does not match the id on the info object");
612 }
613 SocRolloverResultItemInfo copy = new SocRolloverResultItemInfo(socRolloverResultItemInfo);
614 SocRolloverResultItemInfo old = this.getSocRolloverResultItem(socRolloverResultItemInfo.getId(), context);
615 if (!old.getMeta().getVersionInd().equals(copy.getMeta().getVersionInd())) {
616 throw new VersionMismatchException(old.getMeta().getVersionInd());
617 }
618 copy.setMeta(updateMeta(copy.getMeta(), context));
619 this.socRolloverResultItemMap.put(socRolloverResultItemInfo.getId(), copy);
620 return new SocRolloverResultItemInfo(copy);
621 }
622
623 @Override
624 public StatusInfo deleteSocRolloverResultItem(String socRolloverResultItemId, ContextInfo context)
625 throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException,
626 PermissionDeniedException {
627 if (this.socRolloverResultItemMap.remove(socRolloverResultItemId) == null) {
628 throw new DoesNotExistException(socRolloverResultItemId);
629 }
630 return newStatus();
631 }
632
633 @Override
634 public List<ValidationResultInfo> validateSocRolloverResultItem(String validationType, SocRolloverResultItemInfo socRolloverResultItemInfo, ContextInfo context)
635 throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException {
636
637 return new ArrayList<ValidationResultInfo>();
638 }
639
640 @Override
641 public List<String> searchForSocRolloverResultIds(@WebParam(name = "criteria") QueryByCriteria criteria, @WebParam(name = "context") ContextInfo context) throws
642 InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException {
643 throw new UnsupportedOperationException("Not supported yet.");
644 }
645
646 @Override
647 public List<SocRolloverResultInfo> searchForSocRolloverResults(@WebParam(name = "criteria") QueryByCriteria criteria, @WebParam(name = "context") ContextInfo context) throws
648 InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException {
649
650 List<SocRolloverResultInfo> socRolloverResultInfos = new ArrayList<SocRolloverResultInfo>();
651
652 EqualPredicate predicate = (EqualPredicate)criteria.getPredicate();
653 String targetTerm = (String)predicate.getValue().getValue();
654 SocRolloverResultInfo result = new SocRolloverResultInfo();
655 for(Map.Entry<String,SocRolloverResultInfo> entry : socRolloverResultMap.entrySet()){
656 if(entry.getValue().getTargetTermId().equalsIgnoreCase(targetTerm)){
657 socRolloverResultInfos.add(entry.getValue());
658 try{
659 List<SocRolloverResultItemInfo> socRolloverResultItemInfos = getSocRolloverResultItemsByResultId(entry.getValue().getSourceSocId()+entry.getValue().getTargetSocId(),
660 new ContextInfo());
661 }catch(UnhandledException ue){
662
663 }
664 catch(DoesNotExistException dne){
665
666 }
667 }
668 }
669 return socRolloverResultInfos;
670 }
671
672 private MetaInfo newMeta(ContextInfo context) {
673 MetaInfo meta = new MetaInfo();
674 meta.setCreateId(context.getPrincipalId());
675 meta.setCreateTime(new Date());
676 meta.setUpdateId(context.getPrincipalId());
677 meta.setUpdateTime(meta.getCreateTime());
678 meta.setVersionInd("0");
679 return meta;
680 }
681
682 private StatusInfo newStatus() {
683 StatusInfo status = new StatusInfo();
684 status.setSuccess(Boolean.TRUE);
685 return status;
686 }
687
688 private MetaInfo updateMeta(MetaInfo old, ContextInfo context) {
689 MetaInfo meta = new MetaInfo(old);
690 meta.setUpdateId(context.getPrincipalId());
691 meta.setUpdateTime(new Date());
692 meta.setVersionInd((Integer.parseInt(meta.getVersionInd()) + 1) + "");
693 return meta;
694 }
695 }