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 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 | |
|
39 | |
|
40 | |
|
41 | |
|
42 | |
@Entity |
43 | |
@Table(name = "KSEN_APPT_SLOT") |
44 | |
public class AppointmentSlotEntity extends MetaEntity { |
45 | |
|
46 | |
|
47 | |
|
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; |
55 | |
|
56 | |
@Temporal(TemporalType.TIMESTAMP) |
57 | |
@Column(name = "END_DT") |
58 | |
private Date endDate; |
59 | |
|
60 | |
|
61 | |
|
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 | |
|
71 | |
|
72 | |
|
73 | |
|
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 | |
|
135 | 0 | this.setStartDate(apptSlot.getStartDate()); |
136 | 0 | this.setEndDate(apptSlot.getEndDate()); |
137 | |
|
138 | 0 | this.setApptSlotState(apptSlot.getStateKey()); |
139 | |
|
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 | |
|
147 | |
|
148 | |
|
149 | |
|
150 | |
|
151 | 0 | } |
152 | |
|
153 | |
|
154 | |
public AppointmentSlotInfo toDto() { |
155 | 0 | AppointmentSlotInfo slotInfo = new AppointmentSlotInfo(); |
156 | |
|
157 | 0 | slotInfo.setStartDate(getStartDate()); |
158 | 0 | slotInfo.setEndDate(getEndDate()); |
159 | 0 | slotInfo.setAppointmentWindowId(getApptWinEntity().getId()); |
160 | |
|
161 | |
|
162 | 0 | slotInfo.setId(getId()); |
163 | 0 | slotInfo.setTypeKey(getApptSlotType()); |
164 | 0 | slotInfo.setStateKey(getApptSlotState()); |
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 | |
} |