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  package org.kuali.student.enrollment.class2.acal.form;
16  
17  import org.apache.commons.lang.StringUtils;
18  import org.kuali.student.common.uif.form.KSUifForm;
19  import org.kuali.student.enrollment.class2.acal.dto.HolidayWrapper;
20  import org.kuali.student.r2.common.util.date.DateFormatters;
21  import org.kuali.student.r2.core.acal.dto.HolidayCalendarInfo;
22  import org.kuali.student.r2.core.constants.AcademicCalendarServiceConstants;
23  
24  import java.util.ArrayList;
25  import java.util.Date;
26  import java.util.List;
27  
28  /**
29   * This class is the formClass for  HolidayCalendar views
30   *
31   * @author Kuali Student Team
32   */
33  
34  public class HolidayCalendarForm extends KSUifForm {
35      private static final long serialVersionUID = 7526472595622776147L;
36  
37      private HolidayCalendarInfo holidayCalendarInfo;
38      private List<HolidayWrapper> holidays;
39      private String stateName;
40      private String adminOrgName;
41      private String newCalendarName;
42      private Date newCalendarStartDate;
43      private Date newCalendarEndDate;
44      private String hcId;
45      private String orgHcId;
46      private boolean newCalendar;
47      private boolean officialCalendar;
48  
49      //Just to display buttons (delete) based on this flag
50      private boolean officialUI;
51  
52      public HolidayCalendarForm() {
53          super();
54          holidayCalendarInfo = new HolidayCalendarInfo();
55          holidays = new ArrayList<HolidayWrapper>();
56          newCalendar = true;
57          officialCalendar = false;
58      }
59  
60      /**
61       * @return the HolidayCalendarInfo which is currently in use at the view
62       */
63      public HolidayCalendarInfo getHolidayCalendarInfo() {
64          return holidayCalendarInfo;
65      }
66  
67      /**
68       * New Hcal or editing an existing Hcal object
69       *
70       * @param holidayCalendarInfo
71       */
72      public void setHolidayCalendarInfo(HolidayCalendarInfo holidayCalendarInfo) {
73          this.holidayCalendarInfo = holidayCalendarInfo;
74      }
75  
76      /**
77       * @return the list of HolidayWrapper which are currently in use at the holiday view
78       */
79      public List<HolidayWrapper> getHolidays() {
80          // Putting sort here causes list to be sorted when addLine "add" clicked, instead of having
81          // the new row added to the top of the collection as desired.  Just so you know.
82          //Collections.sort(holidays);
83          return holidays;
84      }
85  
86      /**
87       * Update new list of HolidayWrapper or Save the edited an existing list of HolidayWrapper object
88       *
89       * @param holidays
90       */
91      public void setHolidays(List<HolidayWrapper> holidays) {
92          this.holidays = holidays;
93      }
94  
95      /**
96       * State of the current holiday calendar.
97       *
98       * @return stateName
99       */
100     public String getStateName() {
101         return stateName;
102     }
103 
104     /**
105      * State name involved with a hcal.
106      *
107      * @param stateName
108      */
109     public void setStateName(String stateName) {
110         this.stateName = stateName;
111     }
112 
113     /**
114      * Organization involved with a hcal.
115      *
116      * @return adminOrgName
117      */
118     public String getAdminOrgName() {
119         return adminOrgName;
120     }
121 
122     /**
123      * Organization involved with a hcal.
124      *
125      * @param adminOrgName
126      */
127     public void setAdminOrgName(String adminOrgName) {
128         this.adminOrgName = adminOrgName;
129     }
130 
131     /**
132      * new hcal.
133      *
134      * @return newCalendarName
135      */
136     public String getNewCalendarName() {
137         return newCalendarName;
138     }
139 
140     /**
141      * New Hcal object
142      *
143      * @param newCalendarName
144      */
145     public void setNewCalendarName(String newCalendarName) {
146         this.newCalendarName = newCalendarName;
147     }
148 
149     /**
150      * Start date of the new hcal.
151      *
152      * @return newCalendarStartDate
153      */
154     public Date getNewCalendarStartDate() {
155         return newCalendarStartDate;
156     }
157 
158     /**
159      * Start date of the new hcal.
160      *
161      * @param newCalendarStartDate
162      */
163     public void setNewCalendarStartDate(Date newCalendarStartDate) {
164         this.newCalendarStartDate = newCalendarStartDate;
165     }
166 
167     /**
168      * The new calendar end date.
169      *
170      * @return newCalendarEndDate
171      */
172     public Date getNewCalendarEndDate() {
173         return newCalendarEndDate;
174     }
175 
176     /**
177      * End date of the new hcal.
178      *
179      * @param newCalendarEndDate
180      */
181     public void setNewCalendarEndDate(Date newCalendarEndDate) {
182         this.newCalendarEndDate = newCalendarEndDate;
183     }
184 
185     /**
186      * Holiday calendar id.
187      *
188      * @return hcId
189      */
190     public String getHcId() {
191         return hcId;
192     }
193 
194     /**
195      * Holiday calendar id.
196      *
197      * @param hcId
198      */
199     public void setHcId(String hcId) {
200         this.hcId = hcId;
201     }
202 
203     /**
204      * Original holiday calendar id.
205      *
206      * @return orgHcId
207      */
208     public String getOrgHcId() {
209         return orgHcId;
210     }
211 
212     /**
213      * Original holiday calendar id.
214      *
215      * @param orgHcId
216      */
217     public void setOrgHcId(String orgHcId) {
218         this.orgHcId = orgHcId;
219     }
220 
221     /**
222      * indicate new calendar exists or not.
223      *
224      * @return newCalendar
225      */
226     public boolean isNewCalendar() {
227         return newCalendar;
228     }
229 
230     /**
231      * Set New calendar.
232      *
233      * @param newCalendar
234      */
235     public void setNewCalendar(boolean newCalendar) {
236         this.newCalendar = newCalendar;
237     }
238 
239     /**
240      * It is an official Calendar or not with a hcal.
241      *
242      * @return
243      */
244     public boolean isOfficialCalendar() {
245         return officialCalendar;
246     }
247 
248     /**
249      * It is an official Calendar or not with a hcal.
250      *
251      * @param officialCalendar
252      */
253     public void setOfficialCalendar(boolean officialCalendar) {
254         this.officialCalendar = officialCalendar;
255     }
256 
257     /**
258      * The last updated time involved with a hcal.
259      *
260      * @return
261      */
262     public String getUpdateTimeString() {
263         if (getHolidayCalendarInfo() != null &&
264                 getHolidayCalendarInfo().getMeta() != null &&
265                 getHolidayCalendarInfo().getMeta().getUpdateTime() != null) {
266             Date updateTime = getHolidayCalendarInfo().getMeta().getUpdateTime();
267 
268             return "Last saved at " + DateFormatters.SIMPLE_TIMESTAMP_FORMATTER.format(updateTime);
269         } else {
270             return StringUtils.EMPTY;
271         }
272     }
273 
274     /**
275      * UI data if an Calendar is official or not with a hcal.
276      *
277      * @return
278      */
279     public boolean isOfficialUI() {
280         if (holidayCalendarInfo != null) {
281             return StringUtils.equals(AcademicCalendarServiceConstants.ACADEMIC_CALENDAR_OFFICIAL_STATE_KEY, holidayCalendarInfo.getStateKey());
282         }
283         return false;
284     }
285 }