Coverage Report - org.kuali.student.r2.core.class1.appointment.model.AppointmentSlotEntity
 
Classes in this File Line Coverage Branch Coverage Complexity
AppointmentSlotEntity
0%
0/46
0%
0/8
1.25
 
 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 3/8/12
 16  
  */
 17  
 package org.kuali.student.r2.core.class1.appointment.model;
 18  
 
 19  
 import org.kuali.student.r2.common.entity.MetaEntity;
 20  
 import org.kuali.student.r2.common.infc.Attribute;
 21  
 import org.kuali.student.r2.core.appointment.dto.AppointmentSlotInfo;
 22  
 import org.kuali.student.r2.core.appointment.infc.AppointmentSlot;
 23  
 
 24  
 import javax.persistence.CascadeType;
 25  
 import javax.persistence.Column;
 26  
 import javax.persistence.Entity;
 27  
 import javax.persistence.JoinColumn;
 28  
 import javax.persistence.ManyToOne;
 29  
 import javax.persistence.OneToMany;
 30  
 import javax.persistence.Table;
 31  
 import javax.persistence.Temporal;
 32  
 import javax.persistence.TemporalType;
 33  
 import java.util.ArrayList;
 34  
 import java.util.Date;
 35  
 import java.util.List;
 36  
 
 37  
 /**
 38  
  * This class //TODO ...
 39  
  *
 40  
  * @author Kuali Student Team
 41  
  */
 42  
 @Entity
 43  
 @Table(name = "KSEN_APPT_SLOT")
 44  
 public class AppointmentSlotEntity extends MetaEntity {
 45  
     // These refer to columns unique to AppointmentSlotEntity (i.e., not inherited)
 46  
     // We use AppointmentWindowEntity because ORMs recognize foreign keys not by strings, but by objects that
 47  
     // represent a row in that table.  The ORM handles looking up the foreign key.
 48  
     @ManyToOne
 49  
     @JoinColumn(name = "APPT_WINDOW_ID")
 50  
     private AppointmentWindowEntity apptWinEntity;
 51  
 
 52  
     @Temporal(TemporalType.TIMESTAMP)
 53  
     @Column(name = "START_DT")
 54  
     private Date startDate;  // When registration starts (for individual) month/day/year
 55  
 
 56  
     @Temporal(TemporalType.TIMESTAMP)
 57  
     @Column(name = "END_DT")
 58  
     private Date endDate;    // When registration ends (for individual) month/day/year
 59  
 
 60  
     // --------------------------------------------------
 61  
     // These instance variables are not inherited, so they need to be explicitly put here
 62  
     @Column(name = "APPT_SLOT_TYPE")
 63  
     private String apptSlotType;
 64  
 
 65  
     @Column(name = "APPT_SLOT_STATE")
 66  
     private String apptSlotState;
 67  
 
 68  0
     @OneToMany(cascade = CascadeType.ALL, mappedBy = "owner")
 69  
     private List<AppointmentSlotAttributeEntity> attributes = new ArrayList<AppointmentSlotAttributeEntity>();
 70  
     // -- Note: version number, create time, create id, update time, update id should be
 71  
     // inherited via MetaEntity.  id and object id are inherited as well
 72  
 
 73  
     // ==================== METHODS =======================
 74  0
     public AppointmentSlotEntity() {
 75  
 
 76  0
     }
 77  
 
 78  
     public AppointmentSlotEntity(String appointmentSlotTypeKey, AppointmentSlot apptSlot) {
 79  0
         super(apptSlot);
 80  0
         this.setId(apptSlot.getId());
 81  0
         this.setApptSlotType(appointmentSlotTypeKey);
 82  0
         this.fromDto(apptSlot);
 83  0
     }
 84  
 
 85  
     public AppointmentWindowEntity getApptWinEntity() {
 86  0
         return apptWinEntity;
 87  
     }
 88  
 
 89  
     public void setApptWinEntity(AppointmentWindowEntity apptWinEntity) {
 90  0
         this.apptWinEntity = apptWinEntity;
 91  0
     }
 92  
 
 93  
     public Date getStartDate() {
 94  0
         return startDate;
 95  
     }
 96  
 
 97  
     public void setStartDate(Date startDate) {
 98  0
         this.startDate = startDate;
 99  0
     }
 100  
 
 101  
     public Date getEndDate() {
 102  0
         return endDate;
 103  
     }
 104  
 
 105  
     public void setEndDate(Date endDate) {
 106  0
         this.endDate = endDate;
 107  0
     }
 108  
 
 109  
     public String getApptSlotType() {
 110  0
         return apptSlotType;
 111  
     }
 112  
 
 113  
     public void setApptSlotType(String apptSlotType) {
 114  0
         this.apptSlotType = apptSlotType;
 115  0
     }
 116  
 
 117  
     public String getApptSlotState() {
 118  0
         return apptSlotState;
 119  
     }
 120  
 
 121  
     public void setApptSlotState(String apptSlotState) {
 122  0
         this.apptSlotState = apptSlotState;
 123  0
     }
 124  
 
 125  
     public void setAttributes(List<AppointmentSlotAttributeEntity> attributes) {
 126  0
         this.attributes = attributes;
 127  0
     }
 128  
 
 129  
     public List<AppointmentSlotAttributeEntity> getAttributes() {
 130  0
         return attributes;
 131  
     }
 132  
 
 133  
     public void fromDto(AppointmentSlot apptSlot) {
 134  
         // AppointmentSlot specific fields set below
 135  0
         this.setStartDate(apptSlot.getStartDate());
 136  0
         this.setEndDate(apptSlot.getEndDate());
 137  
         // Type are in every entity though, in this case, named to AppointmentSlot
 138  0
         this.setApptSlotState(apptSlot.getStateKey());
 139  
         // Add attributes individually
 140  0
         this.setAttributes(new ArrayList<AppointmentSlotAttributeEntity>());
 141  0
         if (null != apptSlot.getAttributes()) {
 142  0
             for (Attribute att : apptSlot.getAttributes()) {
 143  0
                 this.getAttributes().add(new AppointmentSlotAttributeEntity(att, this));
 144  
             }
 145  
         }
 146  
         // Note: apptWinEntity can't be set from apptSlot which only contains the
 147  
         // id (which is a string) for AppointmentWindow.  When constructing an AppointmentSlotEntity
 148  
         // in AssignmentServiceImpl, one needs to use the appointmentWindowDao to "find" (call the find
 149  
         // method) to get the AppointmentWindowEntity and call setApptWinEntity to set the value
 150  
         // separately
 151  0
     }
 152  
 
 153  
     // Converts AppoinmentSlotEntity to AppointmentSlotInfo
 154  
     public AppointmentSlotInfo toDto() {
 155  0
         AppointmentSlotInfo slotInfo = new AppointmentSlotInfo();
 156  
         // Data specific to AppointmentSlotInfo--all are not null in the DB
 157  0
         slotInfo.setStartDate(getStartDate());
 158  0
         slotInfo.setEndDate(getEndDate());
 159  0
         slotInfo.setAppointmentWindowId(getApptWinEntity().getId());
 160  
         // -------------------------------------------------
 161  
         // Stuff that is updated for nearly all entities
 162  0
         slotInfo.setId(getId()); // id is assumed not null
 163  0
         slotInfo.setTypeKey(getApptSlotType()); // type is assumed not null
 164  0
         slotInfo.setStateKey(getApptSlotState()); // state is assumed not null
 165  0
         slotInfo.setMeta(super.toDTO());
 166  0
         if (getAttributes() != null) {
 167  0
             for (AppointmentSlotAttributeEntity att : getAttributes()) {
 168  0
                 slotInfo.getAttributes().add(att.toDto());
 169  
             }
 170  
         }
 171  0
         return slotInfo;
 172  
     }
 173  
 }