View Javadoc

1   package org.kuali.student.enrollment.class2.acal.service;
2   
3   import org.kuali.rice.core.api.resourceloader.GlobalResourceLoader;
4   import org.kuali.rice.krad.lookup.LookupableImpl;
5   import org.kuali.rice.krad.web.form.LookupForm;
6   import org.kuali.student.enrollment.acal.dto.AcademicCalendarInfo;
7   import org.kuali.student.enrollment.acal.dto.KeyDateInfo;
8   import org.kuali.student.enrollment.acal.dto.TermInfo;
9   import org.kuali.student.enrollment.acal.service.AcademicCalendarService;
10  import org.kuali.student.enrollment.class2.acal.dto.AcademicCalendarWrapper;
11  import org.kuali.student.enrollment.class2.acal.dto.TermWrapper;
12  import org.kuali.student.r2.common.dto.ContextInfo;
13  import org.kuali.student.r2.common.exceptions.*;
14  import org.kuali.student.r2.core.constants.AtpServiceConstants;
15  
16  import javax.xml.namespace.QName;
17  import java.util.ArrayList;
18  import java.util.List;
19  import java.util.Map;
20  
21  //Core slice class.
22  @Deprecated
23  public class AcademicCalendarWrapperLookupableImpl extends LookupableImpl {
24      public final static String CREDENTIAL_PROGRAM_TYPE_KEY = "academicCalendarInfo.credentialProgramTypeKey";
25      public final static String ACADEMIC_CALENDAR_NAME = "academicCalendarInfo.name";
26      public final static String ACADEMIC_CALENDAR_WRAPPER_KEY = "id";
27   	private transient AcademicCalendarService academicCalendarService;
28   	
29  
30      @Override
31      protected List<?> getSearchResults(LookupForm lookupForm, Map<String, String> fieldValues, boolean unbounded) {
32      	List<AcademicCalendarWrapper> academicCalendarWrapperList = new ArrayList<AcademicCalendarWrapper>();
33          List<AcademicCalendarInfo> academicCalendarInfoList = new ArrayList<AcademicCalendarInfo>();
34  
35      	String academicCalendarKey = fieldValues.get(ACADEMIC_CALENDAR_WRAPPER_KEY);
36          String academicCalendarName = fieldValues.get(ACADEMIC_CALENDAR_NAME);
37          String credentialProgramType =  fieldValues.get(CREDENTIAL_PROGRAM_TYPE_KEY);
38          System.out.println(">>>academicCalendarKey = "+academicCalendarKey);
39      	ContextInfo context = new ContextInfo();
40      	try{
41              if(academicCalendarKey != null && !academicCalendarKey.trim().isEmpty()){
42      		    AcademicCalendarInfo acal = getAcademicCalendarService().getAcademicCalendar(academicCalendarKey, context);
43                  if (acal != null) academicCalendarInfoList.add(acal);
44              }
45              else {
46                  // TODO fix the search by Admin Org.  Switch from credential program to admin org cuased issues
47                  /*
48                  List<AcademicCalendarInfo> acals = getAcademicCalendarService().getAcademicCalendarsByCredentialProgramType(credentialProgramType, context);
49                  if(!acals.isEmpty()){
50                      if(academicCalendarName != null && !academicCalendarName.trim().isEmpty()){
51                          for (AcademicCalendarInfo academicCalendarInfo : acals){
52                              if(academicCalendarInfo.getName()!= null && academicCalendarInfo.getName().equals(academicCalendarName))
53                                  academicCalendarInfoList.add(academicCalendarInfo);
54                          }
55                      }
56                      else
57                          academicCalendarInfoList = acals;
58                  }
59                  */
60              }
61  
62              if(!academicCalendarInfoList.isEmpty()){
63                  for(AcademicCalendarInfo academicCalendarInfo : academicCalendarInfoList){
64                      AcademicCalendarWrapper academicCalendarWrapper = new AcademicCalendarWrapper();
65      	            List<TermWrapper> termWrapperList = academicCalendarWrapper.getTermWrapperList();
66  
67                      academicCalendarWrapper.setAcademicCalendarInfo(academicCalendarInfo);
68                      List<TermInfo> terms = getAcademicCalendarService().getTermsForAcademicCalendar(academicCalendarInfo.getId(), context);
69                      for (TermInfo term : terms){
70                          TermWrapper termWrapper = new TermWrapper();
71                          termWrapper.setTermInfo(term);
72                          List<KeyDateInfo>  keyDateInfoList = getAcademicCalendarService().getKeyDatesForTerm(term.getId(), context);
73                          for (KeyDateInfo keyDateInfo : keyDateInfoList){
74                              if(AtpServiceConstants.MILESTONE_INSTRUCTIONAL_PERIOD_TYPE_KEY.equals(keyDateInfo.getTypeKey())){
75                                  termWrapper.setClassesMeetDates(keyDateInfo);
76                              }
77                              else if(AtpServiceConstants.MILESTONE_REGISTRATION_PERIOD_TYPE_KEY.equals(keyDateInfo.getTypeKey())){
78                                  termWrapper.setRegistrationPeriod(keyDateInfo);
79                              }
80                              else if(AtpServiceConstants.MILESTONE_DROP_DATE_TYPE_KEY.equals(keyDateInfo.getTypeKey())){
81                                  termWrapper.setDropPeriodEndsDate(keyDateInfo);
82                              }
83                              else if(AtpServiceConstants.MILESTONE_FINAL_EXAM_PERIOD_TYPE_KEY.equals(keyDateInfo.getTypeKey())){
84                                  termWrapper.setFinalExaminationsDates(keyDateInfo);
85                              }
86                              else if(AtpServiceConstants.MILESTONE_GRADES_DUE_TYPE_KEY.equals(keyDateInfo.getTypeKey())){
87                                  termWrapper.setGradesDueDate(keyDateInfo);
88                              }
89                          }
90                          termWrapperList.add(termWrapper);
91                      }
92                      academicCalendarWrapper.setTermWrapperList(termWrapperList);
93                      academicCalendarWrapperList.add(academicCalendarWrapper);
94                  }
95              }
96  
97          }catch (DoesNotExistException dnee){
98             System.out.println("call getAcademicCalendarService().getAcademicCalendar(academicCalendarKey, context), and get DoesNotExistException:  "+dnee.toString());
99  	    }catch (InvalidParameterException ipe){
100 	    	    System.out.println("call getAcademicCalendarService().getAcademicCalendar(academicCalendarKey, context), and get InvalidParameterException:  "+ipe.toString());
101 	    }catch (MissingParameterException mpe){
102                 System.out.println("call getAcademicCalendarService().getAcademicCalendar(academicCalendarKey, context), and get MissingParameterException:  "+mpe.toString());
103 	    }catch (OperationFailedException ofe){
104                 System.out.println("call getAcademicCalendarService().getAcademicCalendar(academicCalendarKey, context), and get OperationFailedException:  "+ofe.toString());
105 	    }catch (PermissionDeniedException pde){
106                 System.out.println("call getAcademicCalendarService().getAcademicCalendar(academicCalendarKey, context), and get PermissionDeniedException:  "+pde.toString());
107 	    }
108     	return academicCalendarWrapperList;
109         
110     }
111     
112     protected AcademicCalendarService getAcademicCalendarService() {
113         if(academicCalendarService == null) {
114         	 academicCalendarService = (AcademicCalendarService) GlobalResourceLoader.getService(new QName("http://student.kuali.org/wsdl/acal","AcademicCalendarService"));
115         }
116         return academicCalendarService;
117     }
118 
119 
120 }