View Javadoc

1   /**
2    * Copyright 2013 The Kuali Foundation Licensed under the
3    * Educational Community License, Version 2.0 (the "License"); you may
4    * not use this file except in compliance with the License. You may
5    * obtain a copy of the License at
6    *
7    * http://www.osedu.org/licenses/ECL-2.0
8    *
9    * Unless required by applicable law or agreed to in writing,
10   * software distributed under the License is distributed on an "AS IS"
11   * BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
12   * or implied. See the License for the specific language governing
13   * permissions and limitations under the License.
14   *
15   * Created by Charles on 7/17/13
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   * Used to record information within rolloverCourseOffering so it can be accessed in future
28   * rolloverCourseOfferings.  Useful for rolling over colocated AOs.
29   *
30   * @author Kuali Student Team
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  }