Coverage Report - org.kuali.student.r2.core.class1.appointment.model.AppointmentEntity
 
Classes in this File Line Coverage Branch Coverage Complexity
AppointmentEntity
0%
0/50
0%
0/6
1.167
 
 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  
  */
 16  
 
 17  
 package org.kuali.student.r2.core.class1.appointment.model;
 18  
 
 19  
 import java.util.ArrayList;
 20  
 import org.kuali.student.r2.core.appointment.infc.Appointment;
 21  
 import org.kuali.student.r2.common.entity.MetaEntity;
 22  
 import org.kuali.student.r2.core.appointment.dto.AppointmentInfo;
 23  
 
 24  
 import javax.persistence.*;
 25  
 import java.util.Date;
 26  
 import java.util.List;
 27  
 import org.kuali.student.r2.common.infc.Attribute;
 28  
 
 29  
 
 30  
 /**
 31  
  * JPA Entity for the appointment table
 32  
  *
 33  
  * @author Kuali Student Team
 34  
  */
 35  
 @Entity
 36  
 @Table(name = "KSEN_APPT")
 37  
 public class AppointmentEntity extends MetaEntity {
 38  
 
 39  
     @Column(name = "APPT_TYPE")
 40  
     String apptType;
 41  
     @Column(name = "APPT_STATE")
 42  
     String apptState;
 43  
 
 44  
     @Column(name = "PERS_ID")
 45  
     String personId;
 46  
 
 47  
     @ManyToOne
 48  
     @JoinColumn(name = "SLOT_ID")
 49  
     AppointmentSlotEntity slotEntity;
 50  
 
 51  
     @Temporal(TemporalType.TIMESTAMP)
 52  
     @Column(name = "EFF_DT")
 53  
     Date effectiveDate;
 54  
 
 55  
     @Temporal(TemporalType.TIMESTAMP)
 56  
     @Column(name = "EXPIR_DT")
 57  
     Date expirationDate;
 58  
 
 59  0
     @OneToMany(cascade = CascadeType.ALL, mappedBy = "owner")
 60  
     private List<AppointmentAttributeEntity> attributes = new ArrayList<AppointmentAttributeEntity>();
 61  
 
 62  0
     public AppointmentEntity() {
 63  
 
 64  0
     }
 65  
 
 66  
     public AppointmentEntity(Appointment appointment) {
 67  0
         super(appointment);
 68  0
         this.setId(appointment.getId());
 69  0
         this.setApptType(appointment.getTypeKey());
 70  0
         this.setPersonId(appointment.getPersonId());
 71  
 
 72  0
         this.fromDto(appointment);
 73  0
     }
 74  
 
 75  
     public String getApptType() {
 76  0
         return apptType;
 77  
     }
 78  
 
 79  
     public void setApptType(String apptType) {
 80  0
         this.apptType = apptType;
 81  0
     }
 82  
 
 83  
     public String getApptState() {
 84  0
         return apptState;
 85  
     }
 86  
 
 87  
     public void setApptState(String apptState) {
 88  0
         this.apptState = apptState;
 89  0
     }
 90  
 
 91  
     public String getPersonId() {
 92  0
         return personId;
 93  
     }
 94  
 
 95  
     public void setPersonId(String personId) {
 96  0
         this.personId = personId;
 97  0
     }
 98  
 
 99  
     public AppointmentSlotEntity getSlotEntity() {
 100  0
         return slotEntity;
 101  
     }
 102  
 
 103  
     public void setSlotEntity(AppointmentSlotEntity slotEntity) {
 104  0
         this.slotEntity = slotEntity;
 105  0
     }
 106  
 
 107  
     public Date getEffectiveDate() {
 108  0
         return effectiveDate;
 109  
     }
 110  
 
 111  
     public void setEffectiveDate(Date effectiveDate) {
 112  0
         this.effectiveDate = effectiveDate;
 113  0
     }
 114  
 
 115  
     public Date getExpirationDate() {
 116  0
         return expirationDate;
 117  
     }
 118  
 
 119  
     public void setExpirationDate(Date expirationDate) {
 120  0
         this.expirationDate = expirationDate;
 121  0
     }
 122  
 
 123  
     public List<AppointmentAttributeEntity> getAttributes() {
 124  0
         return attributes;
 125  
     }
 126  
 
 127  
     public void setAttributes(List<AppointmentAttributeEntity> attributes) {
 128  0
         this.attributes = attributes;
 129  0
     }
 130  
     
 131  
     public AppointmentInfo toDto() {
 132  0
         AppointmentInfo info = new AppointmentInfo();
 133  
         // -------------------------------------------------
 134  
         // Stuff that is updated for nearly all entities
 135  0
         info.setId(getId()); // id is assumed not null
 136  0
         info.setTypeKey(getApptType()); // type is assumed not null
 137  0
         info.setStateKey(getApptState()); // state is assumed not null
 138  0
         info.setPersonId(this.getPersonId());
 139  0
         info.setSlotId(this.getSlotEntity().getId());
 140  0
         info.setEffectiveDate(this.getEffectiveDate());
 141  0
         info.setExpirationDate(this.getExpirationDate());
 142  0
         info.setMeta(super.toDTO());
 143  0
         if (getAttributes() != null) {
 144  0
             for (AppointmentAttributeEntity att : getAttributes()) {
 145  0
                 info.getAttributes().add(att.toDto());
 146  
             }
 147  
         }
 148  0
         return info;
 149  
     }
 150  
 
 151  
     public void fromDto(Appointment appt) {
 152  0
         this.setApptState(appt.getStateKey());
 153  0
         this.setEffectiveDate(appt.getEffectiveDate());
 154  0
         this.setExpirationDate(appt.getExpirationDate());
 155  
         //
 156  
         // Note: apptSlotEntity can't be set from appt which only contains the
 157  
         // id (which is a string) for AppointmentSlot.  When constructing an AppointmentEntity
 158  
         // in AppointmentServiceImpl, one needs to use the appointmentSlotDao to "find" (call the find
 159  
         // method) to get the AppointmentSlotEntity and call setSlotEntity to set the value
 160  
         // separately
 161  
         // Add attributes individually
 162  0
         this.setAttributes(new ArrayList<AppointmentAttributeEntity>());
 163  0
         for (Attribute att : appt.getAttributes()) {
 164  0
             this.getAttributes().add(new AppointmentAttributeEntity(att, this));
 165  
         }
 166  0
     }
 167  
 
 168  
 }