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.core.type.dto.TypeInfo; |
15 | |
import org.kuali.student.test.utilities.TestHelper; |
16 | |
|
17 | |
import javax.xml.namespace.QName; |
18 | |
import java.io.Serializable; |
19 | |
import java.util.ArrayList; |
20 | |
import java.util.List; |
21 | |
|
22 | 0 | public class TermTypeKeyValues extends UifKeyValuesFinderBase implements Serializable { |
23 | |
|
24 | |
private static final long serialVersionUID = 1L; |
25 | |
|
26 | |
private transient AcademicCalendarService acalService; |
27 | |
|
28 | |
|
29 | |
public AcademicCalendarService getAcalService() { |
30 | 0 | if(acalService == null) { |
31 | 0 | acalService = (AcademicCalendarService) GlobalResourceLoader.getService(new QName(CommonServiceConstants.REF_OBJECT_URI_GLOBAL_PREFIX + "acal", "AcademicCalendarService")); |
32 | |
} |
33 | 0 | return this.acalService; |
34 | |
} |
35 | |
|
36 | |
@Override |
37 | |
public List<KeyValue> getKeyValues(ViewModel model) { |
38 | |
|
39 | 0 | List<KeyValue> keyValues = new ArrayList<KeyValue>(); |
40 | |
|
41 | 0 | AcademicCalendarForm acalForm = (AcademicCalendarForm)model; |
42 | 0 | List<String> availableTermTypes = new ArrayList(); |
43 | 0 | for (AcademicTermWrapper termWrapper : acalForm.getTermWrapperList()) { |
44 | 0 | availableTermTypes.add(termWrapper.getTermType()); |
45 | |
} |
46 | |
|
47 | |
|
48 | 0 | ContextInfo context = TestHelper.getContext1(); |
49 | 0 | List<TypeInfo> types = null; |
50 | |
try { |
51 | |
|
52 | 0 | types = getAcalService().getTermTypesForAcademicCalendarType(AcademicCalendarServiceConstants.ACADEMIC_CALENDAR_TYPE_KEY,context); |
53 | |
|
54 | 0 | for (TypeInfo type : types) { |
55 | 0 | if (!availableTermTypes.contains(type.getKey())){ |
56 | 0 | ConcreteKeyValue keyValue = new ConcreteKeyValue(); |
57 | 0 | keyValue.setKey(type.getKey()); |
58 | 0 | keyValue.setValue(type.getName()); |
59 | 0 | keyValues.add(keyValue); |
60 | 0 | } |
61 | |
} |
62 | 0 | } catch (Exception e) { |
63 | 0 | throw new RuntimeException(e); |
64 | 0 | } |
65 | |
|
66 | 0 | return keyValues; |
67 | |
} |
68 | |
} |