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.courseoffering.dto;
16  
17  import org.apache.commons.lang.StringUtils;
18  import org.kuali.student.r2.core.room.dto.BuildingInfo;
19  import org.kuali.student.r2.core.room.dto.RoomInfo;
20  import org.kuali.student.r2.core.scheduling.dto.ScheduleComponentInfo;
21  import org.kuali.student.r2.core.scheduling.dto.ScheduleInfo;
22  import org.kuali.student.r2.core.scheduling.dto.ScheduleRequestComponentInfo;
23  import org.kuali.student.r2.core.scheduling.dto.ScheduleRequestInfo;
24  import org.kuali.student.r2.core.scheduling.dto.TimeSlotInfo;
25  
26  import java.io.Serializable;
27  import java.util.ArrayList;
28  import java.util.List;
29  
30  /**
31   * Wrapper class for both {@link ScheduleRequestComponentInfo} as well as {@link ScheduleComponentInfo} used at
32   * Edit Activity Offering Screen. As we display the same information for RDL and ADL at UI, there is no
33   * need for having seperate wrappers for ScheduleRequestComponentInfo and ScheduleComponentInfo.
34   *
35   * @author Kuali Student Team
36   */
37  public class ScheduleWrapper implements Serializable{
38  
39      //DTOs
40      private TimeSlotInfo timeSlot;
41      private BuildingInfo building;
42      private RoomInfo room;
43  
44      private ScheduleRequestComponentInfo scheduleRequestComponentInfo;
45      private ScheduleComponentInfo scheduleComponentInfo;
46      private ScheduleRequestInfo scheduleRequestInfo;
47      private ScheduleInfo scheduleInfo;
48  
49      //Properties
50      private String days;
51      private String startTime;
52      private String endTime;
53  
54      private boolean tba;
55  
56      private String buildingCode;
57      private String buildingId;
58      private String roomCode;
59      private int roomCapacity;
60  
61      private List<String> features;
62  
63      //For informational display only
64      private String daysUI;
65  
66      private List<String> colocatedAOs;
67  
68      private EditRenderHelper editRenderHelper;
69      private boolean modified;
70      private List<String> endTimes;
71  
72      public ScheduleWrapper(){
73          features = new ArrayList<String>();
74          this.colocatedAOs = new ArrayList<String>();
75          this.editRenderHelper = new EditRenderHelper();
76          endTimes = new ArrayList<String>();
77      }
78  
79      public ScheduleWrapper(ScheduleWrapper wrapper){
80          this.scheduleComponentInfo = wrapper.getScheduleComponentInfo();
81          this.scheduleRequestComponentInfo = wrapper.getScheduleRequestComponentInfo();
82          this.days = wrapper.getDays();
83          this.startTime = wrapper.getStartTime();
84          this.endTime = wrapper.getEndTime();
85          this.tba = wrapper.isTba();
86          this.buildingCode = wrapper.getBuildingCode();
87          this.buildingId = wrapper.getBuildingId();
88          this.roomCode = wrapper.getRoomCode();
89          this.roomCapacity = wrapper.getRoomCapacity();
90          this.features = wrapper.getFeatures();
91          this.daysUI = wrapper.getDaysUI();
92          this.room = wrapper.getRoom();
93          this.building = wrapper.getBuilding();
94          this.colocatedAOs = new ArrayList<String>();
95          this.editRenderHelper = new EditRenderHelper();
96      }
97  
98      public void copyForEditing(ScheduleWrapper wrapper){
99          this.scheduleComponentInfo = null;
100         this.scheduleRequestComponentInfo = null;
101         this.days = wrapper.getDays();
102         this.tba = wrapper.isTba();
103         this.startTime = wrapper.getStartTime();
104         this.endTime = wrapper.getEndTime();
105         this.buildingId = wrapper.getBuildingId();
106         this.buildingCode = wrapper.getBuildingCode();
107         this.roomCode = wrapper.getRoomCode();
108         this.roomCapacity = wrapper.getRoomCapacity();
109         this.room = wrapper.getRoom();
110         this.building = wrapper.getBuilding();
111         this.colocatedAOs = new ArrayList<String>();
112         this.editRenderHelper = new EditRenderHelper();
113     }
114 
115     public ScheduleWrapper(ScheduleRequestInfo scheduleRequestInfo, ScheduleRequestComponentInfo scheduleRequestComponentInfo){
116         this();
117         this.scheduleRequestComponentInfo = scheduleRequestComponentInfo;
118         this.scheduleRequestInfo = scheduleRequestInfo;
119     }
120 
121     public ScheduleWrapper(ScheduleInfo scheduleInfo, ScheduleComponentInfo scheduleComponentInfo){
122         this();
123         this.scheduleComponentInfo = scheduleComponentInfo;
124         this.scheduleInfo = scheduleInfo;
125     }
126 
127     /**
128      * This method resets the schedule request and component info object sothat the same data can be used to recreate
129      * the request and component.
130      *
131      * Use case: When the user deletes the AO from the colo set, then we need to create all the request and components
132      * for the AO with all the schdule information from the coloset
133      *
134      */
135     public void resetForNewRDL(){
136         this.scheduleRequestInfo = new ScheduleRequestInfo();
137         this.scheduleRequestComponentInfo = new ScheduleRequestComponentInfo();
138     }
139 
140     public TimeSlotInfo getTimeSlot() {
141         return timeSlot;
142     }
143 
144     public void setTimeSlot(TimeSlotInfo timeSlot) {
145         this.timeSlot = timeSlot;
146     }
147 
148     public BuildingInfo getBuilding() {
149         return building;
150     }
151 
152     public void setBuilding(BuildingInfo building) {
153         this.building = building;
154     }
155 
156     public RoomInfo getRoom() {
157         return room;
158     }
159 
160     public void setRoom(RoomInfo room) {
161         this.room = room;
162     }
163 
164     public String getDays() {
165         return days;
166     }
167 
168     public void setDays(String days) {
169         this.days = days;
170     }
171 
172     public String getStartTime() {
173         return startTime;
174     }
175 
176     public void setStartTime(String startTime) {
177         this.startTime = startTime;
178     }
179 
180     public String getEndTime() {
181         return endTime;
182     }
183 
184     public void setEndTime(String endTime) {
185         this.endTime = endTime;
186     }
187 
188     public String getBuildingName() {
189         if (building != null){
190             return building.getName();
191         }
192         return StringUtils.EMPTY;
193     }
194 
195     public String getRoomCode() {
196         return roomCode;
197     }
198 
199     public void setRoomCode(String roomCode) {
200         this.roomCode = roomCode;
201     }
202 
203     public int getRoomCapacity() {
204         return roomCapacity;
205     }
206 
207     public void setRoomCapacity(int roomCapacity) {
208         this.roomCapacity = roomCapacity;
209     }
210 
211     public List<String> getFeatures() {
212         return features;
213     }
214 
215     public void setFeatures(List<String> features) {
216         this.features = features;
217     }
218 
219     public String getDaysUI() {
220         return daysUI;
221     }
222 
223     public void setDaysUI(String daysUI) {
224         this.daysUI = daysUI;
225     }
226 
227     public boolean isRequestAlreadySaved() {
228         if (scheduleRequestComponentInfo != null){
229             return StringUtils.isNotBlank(scheduleRequestComponentInfo.getId());
230         }
231         return false;
232     }
233 
234     public String getBuildingCode() {
235         return buildingCode;
236     }
237 
238     public void setBuildingCode(String buildingCode) {
239         this.buildingCode = buildingCode;
240     }
241 
242     public String getRoomName() {
243         if (room != null){
244             return room.getRoomCode();
245         }
246         return StringUtils.EMPTY;
247     }
248 
249     public boolean isTba() {
250         return tba;
251     }
252 
253     public void setTba(boolean tba) {
254         this.tba = tba;
255     }
256 
257     public String getTbaUI(){
258         if (isTba()){
259             return "TBA";
260         }
261         return StringUtils.EMPTY;
262     }
263 
264     public String getFeaturesUI() {
265         return "N/A";
266     }
267 
268     public ScheduleRequestInfo getScheduleRequestInfo() {
269         return scheduleRequestInfo;
270     }
271 
272     public void setScheduleRequestInfo(ScheduleRequestInfo scheduleRequestInfo) {
273         this.scheduleRequestInfo = scheduleRequestInfo;
274     }
275 
276     public ScheduleRequestComponentInfo getScheduleRequestComponentInfo() {
277         return scheduleRequestComponentInfo;
278     }
279 
280     public ScheduleComponentInfo getScheduleComponentInfo() {
281         return scheduleComponentInfo;
282     }
283 
284     public ScheduleInfo getScheduleInfo() {
285         return scheduleInfo;
286     }
287 
288     public void setScheduleInfo(ScheduleInfo scheduleInfo) {
289         this.scheduleInfo = scheduleInfo;
290     }
291 
292     public String getBuildingId() {
293         return buildingId;
294     }
295 
296     public void setBuildingId(String buildingId) {
297         this.buildingId = buildingId;
298     }
299 
300     /* KSENROLL-6378 replaces displaying the checkboxes instead as simple-text due to partial-colocation not yet being
301      * implemented; this is a simple UI-helper to build a simple string for that purpose.
302      * See ActivityOfferingEdit-ScheduleSection.xml id="ActivityOffering-CoLocated-checkbox"
303      * ~brandon.gresham
304      */
305     public String getColocatedAOsAsStringForUi() {
306         StringBuilder sb = new StringBuilder();
307 
308         if( colocatedAOs != null && !colocatedAOs.isEmpty() ) {
309             for( String s : colocatedAOs ) {
310                 sb.append(" " + s).append(",");
311             }
312             sb.setLength(sb.length()-1); // trim trailing comma
313         }
314 
315         String result = sb.toString().trim();
316         if( result.isEmpty() ) {
317             result = "(nothing)";
318         }
319 
320         return result;
321     }
322 
323     public List<String> getColocatedAOs() {
324         return colocatedAOs;
325     }
326 
327     public void setColocatedAOs(List<String> colocatedAOs) {
328         this.colocatedAOs = colocatedAOs;
329     }
330 
331     public boolean isModified() {
332         return modified;
333     }
334 
335     public void setModified(boolean modified) {
336         this.modified = modified;
337     }
338 
339     public EditRenderHelper getEditRenderHelper() {
340         return editRenderHelper;
341     }
342 
343     public class EditRenderHelper implements Serializable{
344 
345         public String getBuildingName() {
346             return buildingName;
347         }
348 
349         public void setBuildingName(String buildingName) {
350             this.buildingName = buildingName;
351         }
352 
353         private String buildingName;
354 
355         public boolean isShowColocateToolTip(){
356             return colocatedAOs != null && !colocatedAOs.isEmpty();
357         }
358 
359         public String getColocatedAOs(){
360             if (colocatedAOs == null){
361                 return StringUtils.EMPTY;
362             }
363             StringBuilder sb = new StringBuilder();
364             sb.append("This activity is colocated with:<br>");
365             for (String code : colocatedAOs){
366                 sb.append(code + "<br>");
367             }
368 
369             return StringUtils.removeEnd(sb.toString(),"<br>");
370         }
371 
372     }
373 
374     public List<String> getEndTimes() {
375         return endTimes;
376     }
377 
378     public void setEndTimes(List<String> endTimes) {
379         this.endTimes = endTimes;
380     }
381 
382     public String[] getEndTimesArray(){
383         if (!endTimes.isEmpty()){
384             String[] array = endTimes.toArray(new String[endTimes.size()]);
385             return array;
386         } else{
387             return new String[0];
388         }
389     }
390 }