1 | |
package org.kuali.student.enrollment.class2.appointment.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 | |
|
9 | |
import org.kuali.student.enrollment.acal.constants.AcademicCalendarServiceConstants; |
10 | |
import org.kuali.student.enrollment.acal.dto.KeyDateInfo; |
11 | |
import org.kuali.student.enrollment.acal.dto.TermInfo; |
12 | |
import org.kuali.student.enrollment.acal.service.AcademicCalendarService; |
13 | |
import org.kuali.student.enrollment.class2.appointment.form.RegistrationWindowsManagementForm; |
14 | |
import org.kuali.student.r2.common.dto.ContextInfo; |
15 | |
import org.kuali.student.r2.common.exceptions.*; |
16 | |
import org.kuali.student.r2.common.util.constants.AtpServiceConstants; |
17 | |
import org.kuali.student.r2.common.util.constants.TypeServiceConstants; |
18 | |
import org.kuali.student.r2.core.type.dto.TypeTypeRelationInfo; |
19 | |
import org.kuali.student.r2.core.type.service.TypeService; |
20 | |
import org.kuali.student.mock.utilities.TestHelper; |
21 | |
|
22 | |
import javax.xml.namespace.QName; |
23 | |
import java.io.Serializable; |
24 | |
import java.util.ArrayList; |
25 | |
import java.util.List; |
26 | |
|
27 | 0 | public class PeriodKeyDatesFinder extends UifKeyValuesFinderBase implements Serializable { |
28 | |
private static final long serialVersionUID = 1L; |
29 | |
private transient AcademicCalendarService acalService; |
30 | |
private transient TypeService typeService; |
31 | |
private ContextInfo contextInfo; |
32 | |
|
33 | |
|
34 | |
|
35 | |
|
36 | |
@Override |
37 | |
public List<KeyValue> getKeyValues(ViewModel model) { |
38 | 0 | List<KeyValue> keyValues = new ArrayList<KeyValue>(); |
39 | 0 | RegistrationWindowsManagementForm form = (RegistrationWindowsManagementForm)model; |
40 | 0 | ContextInfo context = TestHelper.getContext1(); |
41 | |
try { |
42 | 0 | TermInfo term = form.getTermInfo(); |
43 | 0 | if (term.getId() != null && !term.getId().isEmpty()) { |
44 | 0 | List<KeyDateInfo> keyDateInfoList = getAcalService().getKeyDatesForTerm(term.getId(), context); |
45 | |
|
46 | |
try{ |
47 | 0 | List<TypeTypeRelationInfo> relations = getTypeService().getTypeTypeRelationsByOwnerAndType("kuali.milestone.type.group.appt.regperiods","kuali.type.type.relation.type.group",context); |
48 | 0 | for (KeyDateInfo keyDateInfo : keyDateInfoList) { |
49 | 0 | for (TypeTypeRelationInfo relationInfo : relations) { |
50 | 0 | String relatedTypeKey = relationInfo.getRelatedTypeKey(); |
51 | 0 | if (keyDateInfo.getTypeKey().equals(relatedTypeKey) && |
52 | |
(AtpServiceConstants.MILESTONE_OFFICIAL_STATE_KEY.equals(keyDateInfo.getStateKey()) || |
53 | |
AtpServiceConstants.ATP_OFFICIAL_STATE_KEY.equals(keyDateInfo.getStateKey()))) { |
54 | 0 | keyValues.add(new ConcreteKeyValue(keyDateInfo.getId(), keyDateInfo.getName())); |
55 | 0 | break; |
56 | |
} |
57 | 0 | } |
58 | |
} |
59 | |
|
60 | 0 | }catch (Exception e){ |
61 | |
|
62 | 0 | } |
63 | |
|
64 | 0 | if (!keyValues.isEmpty()) |
65 | 0 | keyValues.add(new ConcreteKeyValue("all", "All Registration Periods for this Term")); |
66 | |
} |
67 | |
|
68 | 0 | }catch (DoesNotExistException dnee){ |
69 | 0 | System.out.println("call getAcalService().getKeyDatesForTerm(term.getId(), context), and get DoesNotExistException: "+dnee.toString()); |
70 | 0 | }catch (InvalidParameterException ipe){ |
71 | 0 | System.out.println("call getAcalService().getKeyDatesForTerm(term.getId(), context), and get InvalidParameterException: "+ipe.toString()); |
72 | 0 | }catch (MissingParameterException mpe){ |
73 | 0 | System.out.println("call getAcalService().getKeyDatesForTerm(term.getId(), context), and get MissingParameterException: "+mpe.toString()); |
74 | 0 | }catch (OperationFailedException ofe){ |
75 | 0 | System.out.println("call getAcalService().getKeyDatesForTerm(term.getId(), context), and get OperationFailedException: "+ofe.toString()); |
76 | 0 | }catch (PermissionDeniedException pde){ |
77 | 0 | System.out.println("call getAcalService().getKeyDatesForTerm(term.getId(), context), and get PermissionDeniedException: "+pde.toString()); |
78 | 0 | } |
79 | |
|
80 | 0 | return keyValues; |
81 | |
} |
82 | |
|
83 | |
public AcademicCalendarService getAcalService() { |
84 | 0 | if(acalService == null) { |
85 | 0 | acalService = (AcademicCalendarService) GlobalResourceLoader.getService(new QName(AcademicCalendarServiceConstants.NAMESPACE, AcademicCalendarServiceConstants.SERVICE_NAME_LOCAL_PART)); |
86 | |
} |
87 | 0 | return this.acalService; |
88 | |
} |
89 | |
public TypeService getTypeService() { |
90 | 0 | if(typeService == null) { |
91 | 0 | typeService = (TypeService) GlobalResourceLoader.getService(new QName(TypeServiceConstants.NAMESPACE, TypeServiceConstants.SERVICE_NAME_LOCAL_PART)); |
92 | |
} |
93 | 0 | return this.typeService; |
94 | |
} |
95 | |
|
96 | |
private ContextInfo getContextInfo() { |
97 | 0 | if (null == contextInfo) { |
98 | |
|
99 | 0 | contextInfo = TestHelper.getContext1(); |
100 | |
} |
101 | 0 | return contextInfo; |
102 | |
} |
103 | |
} |