1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.kuali.student.enrollment.class2.courseofferingset.service.facade;
18
19 import org.kuali.student.r2.common.exceptions.DoesNotExistException;
20 import org.kuali.student.r2.common.exceptions.OperationFailedException;
21
22 import java.util.Date;
23 import java.util.HashMap;
24 import java.util.Map;
25
26
27
28
29
30
31
32 public class RolloverAssistImpl implements RolloverAssist {
33 private Map<String, Map<String, String>> idToSRSSourceIdToSRSTargId = new HashMap<String, Map<String, String>>();
34 private Map<String, Map<String, String>> idToSourceWaitlistIdToTargetWaitlistId = new HashMap<String, Map<String, String>>();
35
36 @Override
37 public String getRolloverId() {
38 Date date = new Date();
39 Long millis = date.getTime();
40 String millisStr = millis.toString();
41 idToSRSSourceIdToSRSTargId.put(millisStr, new HashMap<String, String>());
42 idToSourceWaitlistIdToTargetWaitlistId.put(millisStr, new HashMap<String, String>());
43 return millisStr;
44 }
45
46 @Override
47 public boolean deleteRolloverId(String rolloverId) {
48 int count = 0;
49 if (idToSRSSourceIdToSRSTargId.containsKey(rolloverId)) {
50 idToSRSSourceIdToSRSTargId.remove(rolloverId);
51 count++;
52 }
53 if (idToSourceWaitlistIdToTargetWaitlistId.containsKey(rolloverId)) {
54 idToSourceWaitlistIdToTargetWaitlistId.remove(rolloverId);
55 count++;
56 }
57 return count == 2;
58 }
59
60 @Override
61 public boolean mapSourceSRSIdToTargetSRSId(String rolloverId, String sourceSRSId, String targetSRSId) throws OperationFailedException {
62 if (sourceSRSId == null || targetSRSId == null) {
63 throw new OperationFailedException("source or target SRS ID is null");
64 }
65 if (!idToSRSSourceIdToSRSTargId.containsKey(rolloverId)) {
66 return false;
67 }
68 idToSRSSourceIdToSRSTargId.get(rolloverId).put(sourceSRSId, targetSRSId);
69 return true;
70 }
71
72 public String getTargetSRSId(String rolloverId, String sourceSRSId) throws DoesNotExistException {
73 if (!idToSRSSourceIdToSRSTargId.containsKey(rolloverId)) {
74 throw new DoesNotExistException("rolloverId=" + rolloverId + "does not exist");
75 }
76 return idToSRSSourceIdToSRSTargId.get(rolloverId).get(sourceSRSId);
77 }
78
79 @Override
80 public boolean mapSourceSharedWaitlistIdToTargetSharedWaitlistId(String rolloverId, String sourceWaitlistId, String targetWaitlistId)
81 throws OperationFailedException {
82 if (sourceWaitlistId == null || targetWaitlistId == null) {
83 throw new OperationFailedException("source or target waitlist ID is null");
84 }
85 if (!idToSourceWaitlistIdToTargetWaitlistId.containsKey(rolloverId)) {
86 return false;
87 }
88 idToSourceWaitlistIdToTargetWaitlistId.get(rolloverId).put(sourceWaitlistId, targetWaitlistId);
89 return true;
90 }
91
92 @Override
93 public String getTargetSharedWaitlistId(String rolloverId, String sourceWaitlistId) throws DoesNotExistException {
94 if (!idToSourceWaitlistIdToTargetWaitlistId.containsKey(rolloverId)) {
95 throw new DoesNotExistException("rolloverId=" + rolloverId + "does not exist");
96 }
97 return idToSourceWaitlistIdToTargetWaitlistId.get(rolloverId).get(sourceWaitlistId);
98 }
99 }