View Javadoc

1   /**
2    * Copyright 2012 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 10/9/12
16   */
17  package org.kuali.student.enrollment.class2.courseoffering.service.util;
18  
19  import org.kuali.student.enrollment.courseoffering.dto.ActivityOfferingInfo;
20  import org.kuali.student.enrollment.courseoffering.dto.RegistrationGroupInfo;
21  import org.kuali.student.enrollment.courseoffering.service.CourseOfferingService;
22  import org.kuali.student.r2.common.dto.ContextInfo;
23  import org.kuali.student.r2.common.exceptions.DoesNotExistException;
24  import org.kuali.student.r2.common.exceptions.InvalidParameterException;
25  import org.kuali.student.r2.common.exceptions.MissingParameterException;
26  import org.kuali.student.r2.common.exceptions.OperationFailedException;
27  import org.kuali.student.r2.common.exceptions.PermissionDeniedException;
28  
29  import java.util.Collections;
30  import java.util.Comparator;
31  import java.util.HashMap;
32  import java.util.List;
33  import java.util.Map;
34  
35  /**
36   * This class provides utility functions for Registration group management to the application
37   *
38   * @author Kuali Student Team
39   */
40  public class RegistrationGroupUtil {
41  
42      public static void orderActivityOfferingIdsInRegistrationGroup(RegistrationGroupInfo rgInfo,
43                                                                     final Map<String, String> aoIdsToAoTypes) {
44  
45          Collections.sort(rgInfo.getActivityOfferingIds(),
46                  new Comparator<String>() {
47                      @Override
48                      public int compare(String aoIdFirst, String aoIdSecond) {
49                          String firstType = aoIdsToAoTypes.get(aoIdFirst);
50                          String secondType = aoIdsToAoTypes.get(aoIdSecond);
51                          if (aoIdFirst == null || aoIdSecond == null) {
52                              throw new RuntimeException("aoIdsToAoTypes does not contain types for all ao IDs");
53                          }
54                          int compare = ActivityOfferingTypePrioritizer.compare(firstType, secondType);
55                          return compare;  //To change body of implemented methods use File | Settings | File Templates.
56                      }
57  
58                      @Override
59                      public boolean equals(Object obj) {
60                          return super.equals(obj);  // Put something in to satisfy the interface
61                      }
62  
63                      @Override
64                      public int hashCode(){
65                          return super.hashCode();
66                      }
67                  });
68      }
69  
70      public static Map<String, String> createAoIdsToAoTypesMap(List<String> aoIds,
71                                                                CourseOfferingService coService,
72                                                                ContextInfo contextInfo)
73              throws InvalidParameterException, MissingParameterException, DoesNotExistException,
74                     PermissionDeniedException, OperationFailedException {
75  
76          Map<String, String> aoIdsToAoTypes = new HashMap<String, String>();
77          List<ActivityOfferingInfo> aoInfoList = coService.getActivityOfferingsByIds(aoIds, contextInfo);
78          for (ActivityOfferingInfo aoInfo: aoInfoList) {
79              aoIdsToAoTypes.put(aoInfo.getId(), aoInfo.getTypeKey());
80          }
81          return aoIdsToAoTypes;
82      }
83  }