1 | |
package org.kuali.student.enrollment.class2.acal.keyvalue; |
2 | |
|
3 | |
import org.kuali.rice.core.api.resourceloader.GlobalResourceLoader; |
4 | |
import org.kuali.rice.core.api.util.ConcreteKeyValue; |
5 | |
import org.kuali.rice.core.api.util.KeyValue; |
6 | |
import org.kuali.rice.krad.uif.control.UifKeyValuesFinderBase; |
7 | |
import org.kuali.rice.krad.uif.view.ViewModel; |
8 | |
import org.kuali.student.enrollment.acal.constants.AcademicCalendarServiceConstants; |
9 | |
import org.kuali.student.enrollment.acal.service.AcademicCalendarService; |
10 | |
import org.kuali.student.enrollment.class2.acal.dto.AcademicTermWrapper; |
11 | |
import org.kuali.student.enrollment.class2.acal.form.AcademicCalendarForm; |
12 | |
import org.kuali.student.r2.common.constants.CommonServiceConstants; |
13 | |
import org.kuali.student.r2.common.dto.ContextInfo; |
14 | |
import org.kuali.student.r2.common.exceptions.*; |
15 | |
import org.kuali.student.r2.core.type.dto.TypeInfo; |
16 | |
|
17 | |
import javax.xml.namespace.QName; |
18 | |
import java.io.Serializable; |
19 | |
import java.util.ArrayList; |
20 | |
import java.util.Collections; |
21 | |
import java.util.List; |
22 | |
|
23 | 0 | public class AcademicTermTypeKeyValues extends UifKeyValuesFinderBase implements Serializable { |
24 | |
|
25 | |
private static final long serialVersionUID = 1L; |
26 | |
|
27 | |
private transient AcademicCalendarService acalService; |
28 | |
|
29 | |
private static List<TypeInfo> acalTermTypes; |
30 | |
|
31 | |
@Override |
32 | |
public List<KeyValue> getKeyValues(ViewModel model) { |
33 | |
|
34 | 0 | List<KeyValue> keyValues = new ArrayList<KeyValue>(); |
35 | 0 | List<String> availableTermTypes = new ArrayList(); |
36 | |
|
37 | 0 | if (model instanceof AcademicCalendarForm){ |
38 | 0 | AcademicCalendarForm acalForm = (AcademicCalendarForm)model; |
39 | |
|
40 | 0 | for (AcademicTermWrapper termWrapper : acalForm.getTermWrapperList()) { |
41 | 0 | availableTermTypes.add(termWrapper.getTermType()); |
42 | |
} |
43 | |
} |
44 | |
|
45 | 0 | keyValues.add(new ConcreteKeyValue("", "Select Term Type")); |
46 | |
|
47 | 0 | List<TypeInfo> types = null; |
48 | |
try { |
49 | |
|
50 | 0 | types = getAcalTermTypes(); |
51 | |
|
52 | 0 | for (TypeInfo type : types) { |
53 | 0 | if (!availableTermTypes.contains(type.getKey())){ |
54 | 0 | ConcreteKeyValue keyValue = new ConcreteKeyValue(); |
55 | 0 | keyValue.setKey(type.getKey()); |
56 | 0 | keyValue.setValue(type.getName()); |
57 | 0 | keyValues.add(keyValue); |
58 | 0 | } |
59 | |
} |
60 | 0 | } catch (Exception e) { |
61 | 0 | throw new RuntimeException(e); |
62 | 0 | } |
63 | |
|
64 | 0 | return keyValues; |
65 | |
} |
66 | |
|
67 | |
private List<TypeInfo> getAcalTermTypes() throws InvalidParameterException, MissingParameterException, DoesNotExistException, PermissionDeniedException, OperationFailedException { |
68 | |
|
69 | 0 | if(acalTermTypes == null) { |
70 | |
|
71 | |
|
72 | 0 | ContextInfo context = new ContextInfo(); |
73 | |
|
74 | 0 | acalTermTypes = Collections.unmodifiableList(getAcalService().getTermTypesForAcademicCalendarType(AcademicCalendarServiceConstants.ACADEMIC_CALENDAR_TYPE_KEY, context)); |
75 | |
} |
76 | |
|
77 | 0 | return acalTermTypes; |
78 | |
} |
79 | |
|
80 | |
public AcademicCalendarService getAcalService() { |
81 | 0 | if(acalService == null) { |
82 | 0 | acalService = (AcademicCalendarService) GlobalResourceLoader.getService(new QName(CommonServiceConstants.REF_OBJECT_URI_GLOBAL_PREFIX + "acal", "AcademicCalendarService")); |
83 | |
} |
84 | 0 | return this.acalService; |
85 | |
} |
86 | |
|
87 | |
} |