View Javadoc

1   /* Copyright 2011 The Kuali Foundation
2    * 
3    * Licensed under the Educational Community License, Version 1.0 (the
4    * "License"); you may not use this file except in compliance with the License.
5    * You may obtain a copy of the License at
6    * 
7    * http://www.opensource.org/licenses/ecl1.php
8    * 
9    * Unless required by applicable law or agreed to in writing, software
10   * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11   * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12   * License for the specific language governing permissions and limitations under
13   * the License.
14   */
15  package org.kuali.student.enrollment.class2.acal.form;
16  
17  import org.apache.commons.lang.StringUtils;
18  import org.apache.commons.lang.time.DateFormatUtils;
19  import org.kuali.student.common.uif.form.KSUifForm;
20  import org.kuali.student.enrollment.class2.acal.dto.AcademicTermWrapper;
21  import org.kuali.student.enrollment.class2.acal.dto.AcalEventWrapper;
22  import org.kuali.student.enrollment.class2.acal.dto.HolidayCalendarWrapper;
23  import org.kuali.student.enrollment.class2.acal.util.CalendarConstants;
24  import org.kuali.student.r2.core.acal.dto.AcademicCalendarInfo;
25  import org.kuali.student.r2.core.constants.AcademicCalendarServiceConstants;
26  
27  import java.util.ArrayList;
28  import java.util.Date;
29  import java.util.List;
30  
31  /**
32   * This is the model class for Academic Calendar.
33   *
34   * @author Kuali Student Team
35   */
36  public class AcademicCalendarForm extends KSUifForm {
37  
38      private AcademicCalendarInfo academicCalendarInfo;
39      private AcademicCalendarInfo copyFromAcal;
40      private String adminOrgName;
41      private String updateTimeString;
42  
43      private List<AcalEventWrapper> events;
44      private List<HolidayCalendarWrapper> holidayCalendarList;
45      private List<AcademicTermWrapper> termWrapperList;
46  
47      //used by copying
48      private boolean newCalendar;
49      private boolean officialCalendar;
50      private boolean officialParentTerm;
51  
52      private String defaultTabToShow;
53  
54      private List<AcalEventWrapper> eventsToDeleteOnSave;
55      private List<AcademicTermWrapper> termsToDeleteOnSave;
56  
57      private boolean reload;
58  
59      // needed to delete term
60      private String selectedCollectionPath;
61      private String selectedLineIndex;
62  
63      //Temporarily add the following two fields to overcome DD validation on addLine problem
64      private boolean addLineValid;
65      private String validationJSONString;
66  
67      private boolean makeOfficial;
68      private boolean makeOfficialIsSubterm;
69      private String makeOfficialParentTermName;
70      private String makeOfficialName;
71      private String messageForDeleteTermOrSubterm;
72  
73      private String dirtyFields;
74      private List<String> fieldsToSave;
75  
76      public String getValidationJSONString() {
77          return validationJSONString;
78      }
79  
80      public void setValidationJSONString(String validationJSONString) {
81          this.validationJSONString = validationJSONString;
82      }
83  
84      public boolean isAddLineValid() {
85          return addLineValid;
86      }
87  
88      public void setAddLineValid(boolean addLineValid) {
89          this.addLineValid = addLineValid;
90      }
91  
92      public AcademicCalendarForm() {
93          super();
94          academicCalendarInfo = new AcademicCalendarInfo();
95          termWrapperList = new ArrayList<AcademicTermWrapper>();
96          events = new ArrayList<AcalEventWrapper>();
97          holidayCalendarList = new ArrayList<HolidayCalendarWrapper>();
98          newCalendar = true;
99          officialCalendar = false;
100         defaultTabToShow = CalendarConstants.ACAL_INFO_TAB;
101         eventsToDeleteOnSave = new ArrayList<AcalEventWrapper>();
102         termsToDeleteOnSave = new ArrayList<AcademicTermWrapper>();
103         addLineValid = true;
104         validationJSONString = new String();
105         fieldsToSave= new ArrayList<String>();
106     }
107 
108     /**
109      * Returns an associated acal.
110      *
111      * @return the acal which is currently in use at the view
112      */
113     public AcademicCalendarInfo getAcademicCalendarInfo() {
114         return academicCalendarInfo;
115     }
116 
117     /**
118      * New Acal or editing an existing acal object
119      *
120      * @param academicCalendarInfo current acal in use
121      */
122     public void setAcademicCalendarInfo(AcademicCalendarInfo academicCalendarInfo) {
123         this.academicCalendarInfo = academicCalendarInfo;
124     }
125 
126     /**
127      * See <code>setCopyFromAcal()</code>
128      *
129      * @return acal which is the source for the copy
130      */
131     public AcademicCalendarInfo getCopyFromAcal() {
132         return copyFromAcal;
133     }
134 
135     /**
136      * Sets the recent acal, from which create a new one
137      *
138      * @param copyFromAcal source acal for copy
139      */
140     public void setCopyFromAcal(AcademicCalendarInfo copyFromAcal) {
141         this.copyFromAcal = copyFromAcal;
142     }
143 
144     /**
145      * Organization for the acal
146      *
147      * @return org name
148      */
149     public String getAdminOrgName() {
150         return adminOrgName;
151     }
152 
153     /**
154      * Organization involved with an acal.
155      *
156      * @param adminOrgName organization name
157      */
158     public void setAdminOrgName(String adminOrgName) {
159         this.adminOrgName = adminOrgName;
160     }
161 
162     /**
163      * List of holiday calendars associated with an academic calendar.
164      *
165      * @param holidayCalendarList list of hcals
166      */
167     public void setHolidayCalendarList(List<HolidayCalendarWrapper> holidayCalendarList) {
168         this.holidayCalendarList = holidayCalendarList;
169     }
170 
171     /**
172      * Returns all the associated Holiday Calendars
173      *
174      * @return all the hcal associated with the acal
175      */
176     public List<HolidayCalendarWrapper> getHolidayCalendarList() {
177         return holidayCalendarList;
178     }
179 
180     /**
181      * This is a list of terms associated with an academic calendar.
182      *
183      * @param termWrapperList list of terms associated with the acal
184      */
185     public void setTermWrapperList(List<AcademicTermWrapper> termWrapperList) {
186         this.termWrapperList = termWrapperList;
187     }
188 
189     /**
190      * Returns all the associated terms.
191      *
192      * @return list of terms associated with the acal
193      */
194     public List<AcademicTermWrapper> getTermWrapperList() {
195         return termWrapperList;
196     }
197 
198     /**
199      * Returns the last updated time stamp. It's being called from the xml and by KRAD. So, there would not be any
200      * java references to this method.
201      *
202      * @return
203      */
204     @SuppressWarnings("unused")
205     public String getLastUpdatedTime(){
206         updateTimeString = StringUtils.EMPTY;
207         if (StringUtils.isNotBlank(getAcademicCalendarInfo().getId())){
208             Date updateTime = academicCalendarInfo.getMeta().getUpdateTime();
209             if (updateTime != null){
210                 updateTimeString = DateFormatUtils.format(updateTime,CalendarConstants.DATE_FORMAT);
211             }
212         }
213         return updateTimeString;
214     }
215 
216     /**
217      * Returns a list of Events
218      *
219      * @return list of acal events
220      */
221     public List<AcalEventWrapper> getEvents() {
222         return events;
223     }
224 
225     /**
226      * This is a list of events associated with an academic calendar.
227      *
228      * @param events list of events
229      */
230     public void setEvents(List<AcalEventWrapper> events) {
231         this.events = events;
232     }
233 
234     /**
235      * See <code>setNewCalendar()</code>. (Used in view xml).
236      *
237      * @return true if it's a new calendar
238      */
239     @SuppressWarnings("unused")
240     public boolean isNewCalendar() {
241         return newCalendar;
242     }
243 
244     public void setNewCalendar(boolean newCalendar) {
245         this.newCalendar = newCalendar;
246     }
247 
248     /**
249      * See <code>setOfficialCalendar()</code>. (Used in view xml).
250      *
251      * @return true if it's a new calendar
252      */
253     @SuppressWarnings("unused")
254     public boolean isOfficialCalendar() {
255         return officialCalendar;
256     }
257 
258     /**
259      * Sets whether the acal is official or not
260      *
261      * @param officialCalendar true or false
262      */
263     public void setOfficialCalendar(boolean officialCalendar) {
264         this.officialCalendar = officialCalendar;
265     }
266 
267     /**
268      * See setTermsToDeleteOnSave()
269      *
270      * @return
271      */
272     public List<AcademicTermWrapper> getTermsToDeleteOnSave() {
273         return termsToDeleteOnSave;
274     }
275 
276     /**
277      * This holds all the terms which needs to be deleted on Save. When user deletes terms from the ui,
278      * it'll be added to this collection and all the terms will be deleted on Acal Save action.
279      *
280      * @param termsToDeleteOnSave
281      */
282     public void setTermsToDeleteOnSave(List<AcademicTermWrapper> termsToDeleteOnSave) {
283         this.termsToDeleteOnSave = termsToDeleteOnSave;
284     }
285 
286     /**
287      * See <code>setDefaultTabToShow()</code> (Used in xml)
288      *
289      * @return 'info' to show information tab or 'term' to open term term on calendar open.
290      */
291     @SuppressWarnings("unused")
292     public String getDefaultTabToShow() {
293         return defaultTabToShow;
294     }
295 
296     /**
297      * This is to set which tab should be selected when user edits.
298      * If user selects editing term, then we need to display the term tab. By default, it shows the Info tab.
299      * Allowed values are <p>info</p> for info tab and <p>term</p> for term tab. Passing any other invalid
300      * data displays the info tab.
301      *
302      * @param defaultTabToShow
303      */
304      public void setDefaultTabToShow(String defaultTabToShow) {
305         this.defaultTabToShow = defaultTabToShow;
306      }
307 
308     /**
309      * This returns the index of tab to be selected when user edits. This value will be passed in as template actions.
310      * (Used in xml)
311      *
312      * @return 1 for term tab and 0 for info tab
313      */
314     @SuppressWarnings("unused")
315     public int getDefaultSelectedTabIndex() {
316         if (StringUtils.equals(defaultTabToShow,CalendarConstants.ACAL_TERM_TAB)){
317             return 1;
318         }
319         return 0;
320     }
321 
322     /**
323      * This method returns whether the Academic Calendar is Official or not. Based on this flag, delete button will be displayed.
324      * (Used in xml)
325      *
326      * @return true if acal official
327      */
328     @SuppressWarnings("unused")
329     public boolean isOfficialUI(){
330         if (academicCalendarInfo != null){
331             return StringUtils.equals(AcademicCalendarServiceConstants.ACADEMIC_CALENDAR_OFFICIAL_STATE_KEY,academicCalendarInfo.getStateKey());
332         }
333         return false;
334     }
335 
336     /**
337      *
338      * @return true if the user needs to load the latest version
339      */
340     @SuppressWarnings("unused")
341     public boolean isReload() {
342         return reload;
343     }
344 
345     public void setReload(boolean reload) {
346         this.reload = reload;
347     }
348 
349     /**
350      * Resets the form data.
351      *
352      */
353     public void reset(){
354         setAcademicCalendarInfo(new AcademicCalendarInfo());
355         setOfficialCalendar(false);
356         getView().setReadOnly(false);
357         setEvents(new ArrayList<AcalEventWrapper>());
358         setHolidayCalendarList(new ArrayList<HolidayCalendarWrapper>());
359         setTermsToDeleteOnSave(new ArrayList<AcademicTermWrapper>());
360         setTermWrapperList(new ArrayList<AcademicTermWrapper>());
361         setNewCalendar(false);
362     }
363 
364     public String getSelectedLineIndex() {
365         return selectedLineIndex;
366     }
367 
368     public void setSelectedLineIndex(String selectedLineIndex) {
369         this.selectedLineIndex = selectedLineIndex;
370     }
371 
372     public String getSelectedCollectionPath() {
373         return selectedCollectionPath;
374     }
375 
376     public void setSelectedCollectionPath(String selectedCollectionPath) {
377         this.selectedCollectionPath = selectedCollectionPath;
378     }
379 
380     /**
381      * Whether the Calendar should be made official on save
382      * @return
383      */
384     public boolean isMakeOfficial() {
385         return makeOfficial;
386     }
387 
388     public void setMakeOfficial(boolean makeOfficial) {
389         this.makeOfficial = makeOfficial;
390     }
391 
392     /**
393      * The name of the calendar or term being made official
394      * @return
395      */
396     public String getMakeOfficialName() {
397         return makeOfficialName;
398     }
399 
400     public void setMakeOfficialName(String makeOfficialName) {
401         this.makeOfficialName = makeOfficialName;
402     }
403 
404     public String getMessageForDeleteTermOrSubterm() {
405         return messageForDeleteTermOrSubterm;
406     }
407 
408     public void setMessageForDeleteTermOrSubterm(String messageForDeleteTermOrSubterm) {
409         this.messageForDeleteTermOrSubterm = messageForDeleteTermOrSubterm;
410     }
411 
412     public boolean isMakeOfficialIsSubterm() {
413         return makeOfficialIsSubterm;
414     }
415 
416     public void setMakeOfficialIsSubterm(boolean makeOfficialIsSubterm) {
417         this.makeOfficialIsSubterm = makeOfficialIsSubterm;
418     }
419 
420     public String getMakeOfficialParentTermName() {
421         return makeOfficialParentTermName;
422     }
423 
424     public void setMakeOfficialParentTermName(String makeOfficialParentTermName) {
425         this.makeOfficialParentTermName = makeOfficialParentTermName;
426     }
427 
428     /**
429      * A list of properties that have been changed (are dirty) contained in a csv string.
430      *
431      *
432      * @return
433      */
434     public String getDirtyFields() {
435         return dirtyFields;
436     }
437 
438     public void setDirtyFields(String dirtyFields) {
439         this.dirtyFields = dirtyFields;
440     }
441 
442     /**
443      * A list of Events that have been deleted in the UI and need to be deleted during save.
444      *
445      * @return
446      */
447     public List<AcalEventWrapper> getEventsToDeleteOnSave() {
448         return eventsToDeleteOnSave;
449     }
450 
451     public void setEventsToDeleteOnSave(List<AcalEventWrapper> eventsToDeleteOnSave) {
452         this.eventsToDeleteOnSave = eventsToDeleteOnSave;
453     }
454 
455     public List<String> getFieldsToSave() {
456         return fieldsToSave;
457     }
458 
459     public void setFieldsToSave(List<String> fieldsToSave) {
460         this.fieldsToSave = fieldsToSave;
461     }
462 
463     public boolean isOfficialParentTerm() {
464         return officialParentTerm;
465     }
466 
467     public void setOfficialParentTerm(boolean officialParentTerm) {
468         this.officialParentTerm = officialParentTerm;
469     }
470 }