View Javadoc

1   /**
2    * Copyright 2012 The Kuali Foundation Licensed under the
3    * Educational Community License, Version 2.0 (the "License"); you may
4    * not use this file except in compliance with the License. You may
5    * obtain a copy of the License at
6    *
7    * http://www.osedu.org/licenses/ECL-2.0
8    *
9    * Unless required by applicable law or agreed to in writing,
10   * software distributed under the License is distributed on an "AS IS"
11   * BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
12   * or implied. See the License for the specific language governing
13   * permissions and limitations under the License.
14   *
15   * Created by Li Pan on 3/6/12
16   */
17  package org.kuali.student.enrollment.class2.acal.keyvalue;
18  
19  import org.kuali.rice.core.api.resourceloader.GlobalResourceLoader;
20  import org.kuali.rice.core.api.util.ConcreteKeyValue;
21  import org.kuali.rice.core.api.util.KeyValue;
22  import org.kuali.rice.krad.uif.control.UifKeyValuesFinderBase;
23  import org.kuali.rice.krad.uif.view.ViewModel;
24  import org.kuali.student.enrollment.acal.service.AcademicCalendarService;
25  import org.kuali.student.enrollment.class2.acal.form.CalendarSearchForm;
26  import org.kuali.student.enrollment.class2.acal.util.CalendarConstants;
27  import org.kuali.student.mock.utilities.TestHelper;
28  import org.kuali.student.r2.common.constants.CommonServiceConstants;
29  import org.kuali.student.r2.common.dto.ContextInfo;
30  import org.kuali.student.r2.common.exceptions.InvalidParameterException;
31  import org.kuali.student.r2.common.exceptions.MissingParameterException;
32  import org.kuali.student.r2.common.exceptions.OperationFailedException;
33  import org.kuali.student.r2.common.exceptions.PermissionDeniedException;
34  import org.kuali.student.r2.core.class1.state.dto.StateInfo;
35  
36  import javax.xml.namespace.QName;
37  import java.io.Serializable;
38  import java.util.ArrayList;
39  import java.util.Collections;
40  import java.util.List;
41  
42  /**
43   * This class //TODO ...
44   *
45   * @author Kuali Student Team
46   */
47  //Core slice class.
48  @Deprecated
49  public class AtpStateKeyValues extends UifKeyValuesFinderBase implements Serializable {
50  
51      private static final long serialVersionUID = 1L;
52  
53      private transient AcademicCalendarService acalService;
54  
55      private static List<StateInfo> holidayStates;
56  
57      private static List<StateInfo> acalStates;
58  
59      private static List<StateInfo> termStates;
60  
61  
62      @Override
63      public List<KeyValue> getKeyValues(ViewModel model) {
64          CalendarSearchForm form = (CalendarSearchForm)model;
65          String atpType = form.getCalendarType();
66  
67          List<KeyValue> keyValues = new ArrayList<KeyValue>();
68  
69  
70          try {
71              List<StateInfo> states = null;
72  
73              if(atpType.equals(CalendarConstants.HOLIDAYCALENDER)){
74                  states = getHolidayStates();
75              }else if(atpType.equals(CalendarConstants.ACADEMICCALENDER)) {
76                  states = getAcalStates();
77              }else if(atpType.equals(CalendarConstants.TERM)){
78                  states = getTermStates();
79              }
80  
81              for (StateInfo state : states) {
82                  ConcreteKeyValue keyValue = new ConcreteKeyValue();
83                  keyValue.setKey(state.getKey());
84                  keyValue.setValue(state.getName());
85                  keyValues.add(keyValue);
86              }
87          } catch (Exception e) {
88              throw new RuntimeException(e);
89          }
90  
91          return keyValues;
92      }
93  
94      public List<StateInfo> getHolidayStates() throws InvalidParameterException, MissingParameterException, PermissionDeniedException, OperationFailedException {
95          if(holidayStates == null) {
96              //TODO:Build real context.
97              ContextInfo context = TestHelper.getContext1();
98  
99              holidayStates = Collections.unmodifiableList(getAcalService().getHolidayCalendarStates(context));
100         }
101         return holidayStates;
102     }
103 
104     public List<StateInfo> getAcalStates() throws InvalidParameterException, MissingParameterException, PermissionDeniedException, OperationFailedException {
105         if(acalStates == null) {
106             //TODO:Build real context.
107             ContextInfo context = TestHelper.getContext1();
108 
109             acalStates = Collections.unmodifiableList(getAcalService().getAcademicCalendarStates(context));
110         }
111 
112         return acalStates;
113     }
114 
115     public List<StateInfo> getTermStates() throws InvalidParameterException, MissingParameterException, PermissionDeniedException, OperationFailedException {
116         if(termStates == null) {
117             //TODO:Build real context.
118             ContextInfo context = TestHelper.getContext1();
119 
120             termStates = Collections.unmodifiableList(getAcalService().getTermStates(context));
121         }
122         return termStates;
123     }
124 
125     public AcademicCalendarService getAcalService() {
126         if(acalService == null) {
127             acalService = (AcademicCalendarService) GlobalResourceLoader.getService(new QName(CommonServiceConstants.REF_OBJECT_URI_GLOBAL_PREFIX + "acal", "AcademicCalendarService"));
128         }
129         return this.acalService;
130     }
131 }