Coverage Report - org.kuali.student.r2.core.class1.appointment.model.AppointmentWindowEntity
 
Classes in this File Line Coverage Branch Coverage Complexity
AppointmentWindowEntity
0%
0/152
0%
0/40
1.5
 
 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  
  * Created by Charles on 2/29/12
 16  
  */
 17  
 package org.kuali.student.r2.core.class1.appointment.model;
 18  
 
 19  
 import org.kuali.student.common.entity.KSEntityConstants;
 20  
 import org.kuali.student.r2.common.dto.RichTextInfo;
 21  
 import org.kuali.student.r2.common.dto.TimeAmountInfo;
 22  
 import org.kuali.student.r2.common.dto.TimeOfDayInfo;
 23  
 import org.kuali.student.r2.common.entity.MetaEntity;
 24  
 import org.kuali.student.r2.common.infc.Attribute;
 25  
 import org.kuali.student.r2.core.appointment.dto.AppointmentSlotRuleInfo;
 26  
 import org.kuali.student.r2.core.appointment.dto.AppointmentWindowInfo;
 27  
 import org.kuali.student.r2.core.appointment.infc.AppointmentSlotRule;
 28  
 import org.kuali.student.r2.core.appointment.infc.AppointmentWindow;
 29  
 
 30  
 import javax.persistence.CascadeType;
 31  
 import javax.persistence.Column;
 32  
 import javax.persistence.Entity;
 33  
 import javax.persistence.OneToMany;
 34  
 import javax.persistence.Table;
 35  
 import javax.persistence.Temporal;
 36  
 import javax.persistence.TemporalType;
 37  
 import java.util.ArrayList;
 38  
 import java.util.Date;
 39  
 import java.util.List;
 40  
 
 41  
 /**
 42  
  * This class //TODO ...
 43  
  *
 44  
  * @author Kuali Student Team
 45  
  */
 46  
 @Entity
 47  
 @Table(name = "KSEN_APPT_WINDOW")
 48  
 public class AppointmentWindowEntity extends MetaEntity {
 49  
 
 50  
     @Temporal(TemporalType.TIMESTAMP)
 51  
     @Column(name = "START_DT")
 52  
     private Date startDate;  // When registration starts (for individual) month/day/year 
 53  
 
 54  
     @Temporal(TemporalType.TIMESTAMP)
 55  
     @Column(name = "END_DT")
 56  
     private Date endDate;    // When registration ends (for individual) month/day/year 
 57  
 
 58  
     @Column(name = "PRD_MSTONE_ID")
 59  
     private String periodMilestoneId;
 60  
 
 61  
     @Column(name = "ASSIGNED_POPULATION_ID")
 62  
     private String assignedPopulationId;
 63  
 
 64  
     @Column(name = "ASSIGNED_ORDER_TYPE")
 65  
     private String assignedOrderType;
 66  
 
 67  
     @Column(name = "MAX_APPT_PER_SLOT")
 68  
     private Integer maxAppointmentsPerSlot;
 69  
     // ---------------------------------------------------------------------
 70  
     // Fields for AppointmentSlotRule (flattened out)
 71  
     @Column(name = "SR_WEEKDAYS")
 72  
     private String weekdays; // Comma delimited "days of week" when appointments can occur
 73  
 
 74  
     @Column(name = "SR_START_TIME_MS")
 75  
     private Long startTime; // milliseconds since start of day
 76  
 
 77  
     @Column(name = "SR_END_TIME_MS")
 78  
     private Long endTime; // milliseconds since end of day
 79  
 
 80  
     // Next two fields correspond to "slot start interval" which is a TimeAmount (has two fields)
 81  
     @Column(name = "SR_START_INTVL_DUR_TYPE")
 82  
     private String startIntervalDurationType;
 83  
 
 84  
     @Column(name = "SR_START_INTVL_TIME_QTY")
 85  
     private Integer startIntervalTimeQuantity;
 86  
 
 87  
     // Next two fields correspond to "slot duration" which is a TimeAmount (has two fields)
 88  
     @Column(name = "SR_DUR_TYPE")
 89  
     private String durationType;
 90  
 
 91  
     @Column(name = "SR_DUR_TIME_QTY")
 92  
     private Integer durationTimeQuantity;
 93  
 
 94  
     // =====================================================================
 95  
     // The fields below are inherited from IdEntity (and everything IdEntity inherits from)
 96  
     // IdEntity is what AppointmentWindow extends (Meta fields are included by inheritance from MetaIdentity)
 97  
     @Column(name = "NAME")
 98  
     private String name;
 99  
 
 100  
     @Column(name = "DESCR_PLAIN", length = KSEntityConstants.EXTRA_LONG_TEXT_LENGTH)
 101  
     private String plain;
 102  
 
 103  
     @Column(name = "DESCR_FORMATTED", length = KSEntityConstants.EXTRA_LONG_TEXT_LENGTH)
 104  
     private String formatted;
 105  
 
 106  
     @Column(name = "APPT_WINDOW_TYPE")
 107  
     private String apptWindowType;
 108  
 
 109  
     @Column(name = "APPT_WINDOW_STATE")
 110  
     private String apptWindowState;
 111  
 
 112  0
     @OneToMany(cascade = CascadeType.ALL, mappedBy = "owner")
 113  
     private List<AppointmentWindowAttributeEntity> attributes = new ArrayList<AppointmentWindowAttributeEntity>();
 114  
 
 115  0
     public AppointmentWindowEntity() {
 116  0
     }
 117  
 
 118  
     public AppointmentWindowEntity(String appointmentWindowTypeKey, AppointmentWindow apptWin) {
 119  0
         super(apptWin);
 120  0
         this.setId(apptWin.getId());
 121  0
         this.setApptWindowType(appointmentWindowTypeKey);
 122  0
         this.fromDto(apptWin);
 123  0
     }
 124  
 
 125  
     public String getDescrFormatted() {
 126  0
         return formatted;
 127  
     }
 128  
 
 129  
     public void setDescrFormatted(String formatted) {
 130  0
         this.formatted = formatted;
 131  0
     }
 132  
 
 133  
     public String getDescrPlain() {
 134  0
         return plain;
 135  
     }
 136  
 
 137  
     public void setDescrPlain(String plain) {
 138  0
         this.plain = plain;
 139  0
     }
 140  
 
 141  
     public Date getStartDate() {
 142  0
         return startDate;
 143  
     }
 144  
 
 145  
     public void setStartDate(Date startDate) {
 146  0
         this.startDate = startDate;
 147  0
     }
 148  
 
 149  
     public Date getEndDate() {
 150  0
         return endDate;
 151  
     }
 152  
 
 153  
     public void setEndDate(Date endDate) {
 154  0
         this.endDate = endDate;
 155  0
     }
 156  
 
 157  
     public String getPeriodMilestoneId() {
 158  0
         return periodMilestoneId;
 159  
     }
 160  
 
 161  
     public void setPeriodMilestoneId(String periodMilestoneId) {
 162  0
         this.periodMilestoneId = periodMilestoneId;
 163  0
     }
 164  
 
 165  
     public String getAssignedPopulationId() {
 166  0
         return assignedPopulationId;
 167  
     }
 168  
 
 169  
     public void setAssignedPopulationId(String assignedPopulationId) {
 170  0
         this.assignedPopulationId = assignedPopulationId;
 171  0
     }
 172  
 
 173  
     public String getAssignedOrderType() {
 174  0
         return assignedOrderType;
 175  
     }
 176  
 
 177  
     public void setAssignedOrderType(String assignedOrderType) {
 178  0
         this.assignedOrderType = assignedOrderType;
 179  0
     }
 180  
 
 181  
     public Integer getMaxAppointmentsPerSlot() {
 182  0
         return maxAppointmentsPerSlot;
 183  
     }
 184  
 
 185  
     public void setMaxAppointmentsPerSlot(Integer maxAppointmentsPerSlot) {
 186  0
         this.maxAppointmentsPerSlot = maxAppointmentsPerSlot;
 187  0
     }
 188  
 
 189  
     // Getters/setters for AppointmentSlotRule fields
 190  
     public String getWeekdays() {
 191  0
         return weekdays;
 192  
     }
 193  
 
 194  
     public void setWeekdays(String weekdays) {
 195  0
         this.weekdays = weekdays;
 196  0
     }
 197  
 
 198  
     public Long getStartTime() {
 199  0
         return startTime;
 200  
     }
 201  
 
 202  
     public void setStartTime(Long startTime) {
 203  0
         this.startTime = startTime;
 204  0
     }
 205  
 
 206  
     public Long getEndTime() {
 207  0
         return endTime;
 208  
     }
 209  
 
 210  
     public void setEndTime(Long endTime) {
 211  0
         this.endTime = endTime;
 212  0
     }
 213  
 
 214  
     public String getStartIntervalDurationType() {
 215  0
         return startIntervalDurationType;
 216  
     }
 217  
 
 218  
     public void setStartIntervalDurationType(String startIntervalDurationType) {
 219  0
         this.startIntervalDurationType = startIntervalDurationType;
 220  0
     }
 221  
 
 222  
     public Integer getStartIntervalTimeQuantity() {
 223  0
         return startIntervalTimeQuantity;
 224  
     }
 225  
 
 226  
     public void setStartIntervalTimeQuantity(Integer startIntervalTimeQuantity) {
 227  0
         this.startIntervalTimeQuantity = startIntervalTimeQuantity;
 228  0
     }
 229  
 
 230  
     public String getDurationType() {
 231  0
         return durationType;
 232  
     }
 233  
 
 234  
     public void setDurationType(String durationType) {
 235  0
         this.durationType = durationType;
 236  0
     }
 237  
 
 238  
     public Integer getDurationTimeQuantity() {
 239  0
         return durationTimeQuantity;
 240  
     }
 241  
 
 242  
     public void setDurationTimeQuantity(Integer durationTimeQuantity) {
 243  0
         this.durationTimeQuantity = durationTimeQuantity;
 244  0
     }
 245  
 
 246  
     // Getters/setters below from fields derived from IdEntity which are common for all entities
 247  
     // Notew: setDescr()/getDescr() is specialized to this type
 248  
     public String getName() {
 249  0
         return name;
 250  
     }
 251  
 
 252  
     public void setName(String name) {
 253  0
         this.name = name;
 254  0
     }
 255  
 
 256  
     public String getApptWindowType() {
 257  0
         return apptWindowType;
 258  
     }
 259  
 
 260  
     public void setApptWindowType(String apptWinType) {
 261  0
         this.apptWindowType = apptWinType;
 262  0
     }
 263  
 
 264  
     public String getApptWindowState() {
 265  0
         return apptWindowState;
 266  
     }
 267  
 
 268  
     public void setApptWindowState(String apptWinState) {
 269  0
         this.apptWindowState = apptWinState;
 270  0
     }
 271  
 
 272  
     public void setAttributes(List<AppointmentWindowAttributeEntity> attributes) {
 273  0
         this.attributes = attributes;
 274  0
     }
 275  
 
 276  
     public List<AppointmentWindowAttributeEntity> getAttributes() {
 277  0
         return attributes;
 278  
     }
 279  
 
 280  
     private TimeOfDayInfo convertToTimeOfDayInfo(Long time) {
 281  0
         if(time == null){
 282  0
             return null;
 283  
         }
 284  0
         TimeOfDayInfo info = new TimeOfDayInfo();
 285  0
         info.setMilliSeconds(time);
 286  0
         return info;
 287  
     }
 288  
 
 289  
     private TimeAmountInfo convertToTimeAmountInfo(String typeKey, Integer quantity) {
 290  0
         if ((typeKey == null) && (quantity == null)) {
 291  0
             return null;
 292  
         }
 293  0
         TimeAmountInfo info = new TimeAmountInfo();
 294  0
         info.setAtpDurationTypeKey(typeKey);
 295  0
         if (quantity != null) {
 296  0
             info.setTimeQuantity(quantity);
 297  
         }
 298  0
         return info;
 299  
     }
 300  
 
 301  
     public void fromDto(AppointmentWindow apptWin) {
 302  
 
 303  
         // AppointmentWindow specific initialization; readOnly fields go only in the ctor
 304  0
         this.setPeriodMilestoneId(apptWin.getPeriodMilestoneId());
 305  0
         this.setAssignedPopulationId(apptWin.getAssignedPopulationId());
 306  0
         this.setAssignedOrderType(apptWin.getAssignedOrderTypeKey());
 307  0
         this.setStartDate(apptWin.getStartDate()); // startDate not null
 308  0
         this.setEndDate(apptWin.getEndDate());
 309  0
         this.setMaxAppointmentsPerSlot(apptWin.getMaxAppointmentsPerSlot());
 310  
 
 311  0
         AppointmentSlotRule slotRule = apptWin.getSlotRule();
 312  
 
 313  0
         if(slotRule != null){
 314  0
             if(slotRule.getWeekdays() != null){
 315  
                 // Generate comma delimited days of week to save (max length is 13 characters)
 316  0
                 List<Integer> weekdays = slotRule.getWeekdays(); // not null
 317  0
                 StringBuilder weekdaysStr = new StringBuilder();
 318  0
                 for (Integer day : weekdays) {
 319  0
                     if (weekdaysStr.length() > 0) {
 320  0
                         weekdaysStr.append(",");
 321  
                     }
 322  0
                     weekdaysStr.append(day);
 323  
                 }
 324  0
                 this.setWeekdays(weekdaysStr.toString());
 325  0
             }else{
 326  0
                 this.setWeekdays(null);
 327  
             }
 328  
 
 329  0
             this.setStartTime(slotRule.getStartTimeOfDay()==null?null:slotRule.getStartTimeOfDay().getMilliSeconds());
 330  0
             this.setEndTime(slotRule.getEndTimeOfDay()==null?null:slotRule.getEndTimeOfDay().getMilliSeconds());
 331  
 
 332  
             // start interval could be null, duration
 333  0
             if (slotRule.getSlotStartInterval() != null) {
 334  0
                 this.setStartIntervalDurationType(slotRule.getSlotStartInterval().getAtpDurationTypeKey());
 335  0
                 this.setStartIntervalTimeQuantity(slotRule.getSlotStartInterval().getTimeQuantity());
 336  
             }
 337  
             // slot duration could be null
 338  0
             if (slotRule.getSlotDuration() != null) {
 339  0
                 this.setDurationType(slotRule.getSlotDuration().getAtpDurationTypeKey());
 340  0
                 this.setDurationTimeQuantity(slotRule.getSlotDuration().getTimeQuantity());
 341  
             }
 342  
         }else{
 343  
             //Default the slot rule info to null
 344  0
             this.setWeekdays(null);
 345  0
             this.setStartTime(null);
 346  0
             this.setEndTime(null);
 347  0
             this.setDurationType(null);
 348  0
             this.setDurationTimeQuantity(null);
 349  
         }
 350  
         // --- These getters/setters are for inherited fields
 351  0
         this.setName(apptWin.getName());
 352  0
         if (apptWin.getDescr() != null) {
 353  0
             this.setDescrPlain(apptWin.getDescr().getPlain());
 354  0
             this.setDescrFormatted(apptWin.getDescr().getFormatted());
 355  
         }
 356  
         // The state keys are in every entity, but are not explicitly inherited
 357  0
         this.setApptWindowState(apptWin.getStateKey());
 358  
         // Add attributes individually
 359  0
         this.setAttributes(new ArrayList<AppointmentWindowAttributeEntity>());
 360  0
         if (null != apptWin.getAttributes()) {
 361  0
             for (Attribute att : apptWin.getAttributes()) {
 362  0
                 this.getAttributes().add(new AppointmentWindowAttributeEntity(att, this));
 363  
             }
 364  
         }
 365  0
     }
 366  
 
 367  
     public AppointmentWindowInfo toDto() {
 368  
 
 369  0
         AppointmentWindowInfo info = new AppointmentWindowInfo();
 370  0
         info.setStartDate(getStartDate());
 371  0
         info.setEndDate(getEndDate());
 372  
         // AppointmentWindow-specific updates
 373  0
         AppointmentSlotRuleInfo appointmentSlotRuleInfo = new AppointmentSlotRuleInfo();
 374  0
         info.setSlotRule(appointmentSlotRuleInfo);
 375  
         // Set weekdays which takes comma delimited string of numbers and creates List<Integer>
 376  0
         if(getWeekdays()!=null && !getWeekdays().isEmpty()){
 377  0
             String[] numArr = getWeekdays().split(",");
 378  0
             List<Integer> weekdays = new ArrayList<Integer>();
 379  0
             for (String s : numArr) {
 380  0
                 weekdays.add(Integer.parseInt(s));
 381  
             }
 382  0
             appointmentSlotRuleInfo.setWeekdays(weekdays);
 383  0
         }else{
 384  0
             appointmentSlotRuleInfo.setWeekdays(null);
 385  
         }
 386  0
         appointmentSlotRuleInfo.setStartTimeOfDay(convertToTimeOfDayInfo(getStartTime()));
 387  0
         appointmentSlotRuleInfo.setEndTimeOfDay(convertToTimeOfDayInfo(getEndTime()));
 388  0
         appointmentSlotRuleInfo.setSlotStartInterval(convertToTimeAmountInfo(getStartIntervalDurationType(), getStartIntervalTimeQuantity()));
 389  0
         appointmentSlotRuleInfo.setSlotDuration(convertToTimeAmountInfo(getDurationType(), getDurationTimeQuantity()));
 390  0
         info.setPeriodMilestoneId(getPeriodMilestoneId());
 391  0
         info.setAssignedPopulationId(getAssignedPopulationId());
 392  0
         info.setAssignedOrderTypeKey(getAssignedOrderType());
 393  0
         info.setMaxAppointmentsPerSlot(getMaxAppointmentsPerSlot()); // could be null
 394  0
         info.setName(getName());
 395  
         // -------------------------------------------------
 396  
         // Stuff that is updated for nearly all entities
 397  0
         info.setId(getId());
 398  0
         info.setTypeKey(apptWindowType);
 399  0
         info.setStateKey(apptWindowState);
 400  0
         info.setMeta(super.toDTO());
 401  0
         if (getDescrPlain() != null) { // assume if this is not null, formatted also not null
 402  0
             RichTextInfo textInfo = new RichTextInfo();
 403  0
             textInfo.setFormatted(getDescrFormatted());
 404  0
             textInfo.setPlain(getDescrPlain());
 405  0
             info.setDescr(textInfo);
 406  
         }
 407  
 
 408  0
         for (AppointmentWindowAttributeEntity att : getAttributes()) {
 409  0
             info.getAttributes().add(att.toDto());
 410  
         }
 411  0
         return info;
 412  
     }
 413  
 }