1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
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 | |
|
32 | |
|
33 | |
|
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 | |
|
135 | 0 | info.setId(getId()); |
136 | 0 | info.setTypeKey(getApptType()); |
137 | 0 | info.setStateKey(getApptState()); |
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 | |
|
157 | |
|
158 | |
|
159 | |
|
160 | |
|
161 | |
|
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 | |
} |