1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
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
37
38
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;
56 }
57
58 @Override
59 public boolean equals(Object obj) {
60 return super.equals(obj);
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 }