View Javadoc

1   /**
2    * Copyright 2013 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 mharmath on 8/8/13
16   */
17  package org.kuali.student.enrollment.class2.acal.dto;
18  
19  
20  import org.apache.commons.lang.StringUtils;
21  import org.kuali.student.r2.common.dto.RichTextInfo;
22  import org.kuali.student.r2.common.util.date.DateFormatters;
23  import org.kuali.student.r2.core.acal.dto.ExamPeriodInfo;
24  import org.kuali.student.r2.core.class1.type.dto.TypeInfo;
25  import org.kuali.student.r2.core.constants.AtpServiceConstants;
26  
27  import java.util.Date;
28  
29  /**
30   * Wrapper class for <code>ExamPeriodInfo</code> dto.
31   *
32   * @author Kuali Student Team
33   */
34  public class ExamPeriodWrapper {
35  
36      private String examPeriodType;
37      private String examPeriodNameUI;
38      private Date startDate;
39      private Date endDate;
40      private boolean excludeSaturday = true;
41      private boolean excludeSunday = true;
42  
43      private ExamPeriodInfo examPeriodInfo;
44      private TypeInfo typeInfo;
45  
46      public ExamPeriodWrapper(){
47          examPeriodInfo = new ExamPeriodInfo();
48          examPeriodInfo.setStateKey(AtpServiceConstants.ATP_DRAFT_STATE_KEY);
49          RichTextInfo desc = new RichTextInfo();
50          desc.setPlain("test");
51          examPeriodInfo.setDescr(desc);
52          setExamPeriodType(AtpServiceConstants.ATP_EXAM_PERIOD_TYPE_KEY);
53          setExamPeriodNameUI("Final Exam Period");
54      }
55  
56      public ExamPeriodWrapper(ExamPeriodInfo examPeriodInfo, boolean isCopy){
57          this.startDate = examPeriodInfo.getStartDate();
58          this.endDate = examPeriodInfo.getEndDate();
59          setExamPeriodType(examPeriodInfo.getTypeKey());
60          setExamPeriodNameUI("Final Exam Period");
61  
62          if (isCopy){
63              setExamPeriodInfo(new ExamPeriodInfo());
64              RichTextInfo desc = new RichTextInfo();
65              desc.setPlain(examPeriodInfo.getTypeKey());
66              getExamPeriodInfo().setDescr(desc);
67              getExamPeriodInfo().setStateKey(AtpServiceConstants.ATP_DRAFT_STATE_KEY);
68          }else{
69              setExamPeriodInfo(examPeriodInfo);
70          }
71  
72      }
73  
74  
75      public String getExamPeriodType() {
76          return examPeriodType;
77      }
78  
79      public void setExamPeriodType(String examPeriodType) {
80          if (examPeriodType == null || examPeriodType.equals("")) {
81              this.examPeriodType = AtpServiceConstants.ATP_EXAM_PERIOD_TYPE_KEY;
82          } else {
83              this.examPeriodType = examPeriodType;
84          }
85      }
86  
87      public String getExamPeriodNameUI() {
88          return examPeriodNameUI;
89      }
90  
91      public void setExamPeriodNameUI(String examPeriodNameUI) {
92          if (examPeriodNameUI == null || examPeriodNameUI.equals("")) {
93              this.examPeriodNameUI = "Final Exam Period";
94          } else {
95              this.examPeriodNameUI = examPeriodNameUI;
96          }
97      }
98  
99      public ExamPeriodInfo getExamPeriodInfo() {
100         return examPeriodInfo;
101     }
102 
103     public void setExamPeriodInfo(ExamPeriodInfo examPeriodInfo) {
104         this.examPeriodInfo = examPeriodInfo;
105     }
106 
107     public TypeInfo getTypeInfo() {
108         return typeInfo;
109     }
110 
111     public void setTypeInfo(TypeInfo typeInfo) {
112         this.typeInfo = typeInfo;
113     }
114 
115     public Date getStartDate() {
116         return startDate;
117     }
118 
119     public void setStartDate(Date startDate) {
120         this.startDate = startDate;
121     }
122 
123     public Date getEndDate() {
124         return endDate;
125     }
126 
127     public void setEndDate(Date endDate) {
128         this.endDate = endDate;
129     }
130 
131     public boolean isNew() {
132         return StringUtils.isBlank(examPeriodInfo.getId());
133     }
134 
135     //This is for UI display purpose
136     public String getStartDateUI(){
137         return formatStartEndDateUI(examPeriodInfo.getStartDate());
138     }
139 
140     //This is for UI display purpose
141     public String getEndDateUI(){
142         return formatStartEndDateUI(examPeriodInfo.getEndDate());
143     }
144 
145     public boolean isExcludeSaturday() {
146         return excludeSaturday;
147     }
148 
149     public void setExcludeSaturday(boolean excludeSaturday) {
150         this.excludeSaturday = excludeSaturday;
151     }
152 
153     public boolean isExcludeSunday() {
154         return excludeSunday;
155     }
156 
157     public void setExcludeSunday(boolean excludeSunday) {
158         this.excludeSunday = excludeSunday;
159     }
160 
161     //This is for UI display purpose
162     protected String formatStartEndDateUI(Date date){
163         if (date != null) {
164             return DateFormatters.MONTH_DAY_YEAR_DATE_FORMATTER.format(date);
165         }else{
166             return StringUtils.EMPTY;
167         }
168 
169     }
170 
171 }