001/* 002 * Copyright 2012 The Kuali Foundation Licensed under the 003 * Educational Community License, Version 2.0 (the "License"); you may 004 * not use this file except in compliance with the License. You may 005 * obtain a copy of the License at 006 * 007 * http://www.osedu.org/licenses/ECL-2.0 008 * 009 * Unless required by applicable law or agreed to in writing, 010 * software distributed under the License is distributed on an "AS IS" 011 * BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 012 * or implied. See the License for the specific language governing 013 * permissions and limitations under the License. 014 */ 015package org.kuali.student.enrollment.class2.courseoffering.dto; 016 017import org.apache.commons.lang.StringUtils; 018import org.kuali.student.r2.core.room.dto.BuildingInfo; 019import org.kuali.student.r2.core.room.dto.RoomInfo; 020import org.kuali.student.r2.core.scheduling.dto.ScheduleComponentInfo; 021import org.kuali.student.r2.core.scheduling.dto.ScheduleInfo; 022import org.kuali.student.r2.core.scheduling.dto.ScheduleRequestComponentInfo; 023import org.kuali.student.r2.core.scheduling.dto.ScheduleRequestInfo; 024import org.kuali.student.r2.core.scheduling.dto.TimeSlotInfo; 025 026import java.io.Serializable; 027import java.util.ArrayList; 028import java.util.List; 029 030/** 031 * Wrapper class for both {@link ScheduleRequestComponentInfo} as well as {@link ScheduleComponentInfo} used at 032 * Edit Activity Offering Screen. As we display the same information for RDL and ADL at UI, there is no 033 * need for having seperate wrappers for ScheduleRequestComponentInfo and ScheduleComponentInfo. 034 * 035 * @author Kuali Student Team 036 */ 037public class ScheduleWrapper implements Serializable{ 038 039 //DTOs 040 private TimeSlotInfo timeSlot; 041 private BuildingInfo building; 042 private RoomInfo room; 043 044 private ScheduleRequestComponentInfo scheduleRequestComponentInfo; 045 private ScheduleComponentInfo scheduleComponentInfo; 046 private ScheduleRequestInfo scheduleRequestInfo; 047 private ScheduleInfo scheduleInfo; 048 049 //Properties 050 private String days; 051 private String startTime; 052 private String endTime; 053 054 private boolean tba; 055 056 private String buildingCode; 057 private String buildingId; 058 private String roomCode; 059 private int roomCapacity; 060 061 private List<String> features; 062 063 //For informational display only 064 private String daysUI; 065 066 private List<String> colocatedAOs; 067 068 private EditRenderHelper editRenderHelper; 069 private boolean modified; 070 private List<String> endTimes; 071 072 public ScheduleWrapper(){ 073 features = new ArrayList<String>(); 074 this.colocatedAOs = new ArrayList<String>(); 075 this.editRenderHelper = new EditRenderHelper(); 076 endTimes = new ArrayList<String>(); 077 } 078 079 public ScheduleWrapper(ScheduleWrapper wrapper){ 080 this.scheduleComponentInfo = wrapper.getScheduleComponentInfo(); 081 this.scheduleRequestComponentInfo = wrapper.getScheduleRequestComponentInfo(); 082 this.days = wrapper.getDays(); 083 this.startTime = wrapper.getStartTime(); 084 this.endTime = wrapper.getEndTime(); 085 this.tba = wrapper.isTba(); 086 this.buildingCode = wrapper.getBuildingCode(); 087 this.buildingId = wrapper.getBuildingId(); 088 this.roomCode = wrapper.getRoomCode(); 089 this.roomCapacity = wrapper.getRoomCapacity(); 090 this.features = wrapper.getFeatures(); 091 this.daysUI = wrapper.getDaysUI(); 092 this.room = wrapper.getRoom(); 093 this.building = wrapper.getBuilding(); 094 this.colocatedAOs = new ArrayList<String>(); 095 this.editRenderHelper = new EditRenderHelper(); 096 } 097 098 public void copyForEditing(ScheduleWrapper wrapper){ 099 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 //JIRA FIX : KSENROLL-8731 - Replaced StringBuffer with StringBuilder 364 StringBuilder sb = new StringBuilder(); 365 sb.append("This activity is colocated with:<br>"); 366 for (String code : colocatedAOs){ 367 sb.append(code + "<br>"); 368 } 369 370 return StringUtils.removeEnd(sb.toString(),"<br>"); 371 } 372 373 } 374 375 public List<String> getEndTimes() { 376 return endTimes; 377 } 378 379 public void setEndTimes(List<String> endTimes) { 380 this.endTimes = endTimes; 381 } 382 383 public String[] getEndTimesArray(){ 384 if (!endTimes.isEmpty()){ 385 String[] array = endTimes.toArray(new String[endTimes.size()]); 386 return array; 387 } else{ 388 return new String[0]; 389 } 390 } 391}