1 | |
package org.kuali.student.enrollment.class1.hold.model; |
2 | |
|
3 | |
import java.util.ArrayList; |
4 | |
import java.util.Date; |
5 | |
import java.util.List; |
6 | |
|
7 | |
import javax.persistence.CascadeType; |
8 | |
import javax.persistence.Column; |
9 | |
import javax.persistence.Entity; |
10 | |
import javax.persistence.JoinColumn; |
11 | |
import javax.persistence.ManyToOne; |
12 | |
import javax.persistence.OneToMany; |
13 | |
import javax.persistence.Table; |
14 | |
import javax.persistence.Temporal; |
15 | |
import javax.persistence.TemporalType; |
16 | |
|
17 | |
import org.kuali.student.common.entity.KSEntityConstants; |
18 | |
import org.kuali.student.r2.common.dto.AttributeInfo; |
19 | |
import org.kuali.student.r2.common.dto.RichTextInfo; |
20 | |
import org.kuali.student.r2.common.entity.AttributeOwner; |
21 | |
import org.kuali.student.r2.common.entity.MetaEntity; |
22 | |
import org.kuali.student.r2.common.infc.Attribute; |
23 | |
import org.kuali.student.r2.core.hold.dto.HoldInfo; |
24 | |
import org.kuali.student.r2.core.hold.infc.Hold; |
25 | |
|
26 | |
@Entity |
27 | |
@Table(name = "KSEN_HOLD") |
28 | |
public class HoldEntity extends MetaEntity implements AttributeOwner<HoldAttributeEntity> { |
29 | |
|
30 | |
@Column(name = "DESCR_PLAIN", length = KSEntityConstants.EXTRA_LONG_TEXT_LENGTH, nullable=false) |
31 | |
private String descrPlain; |
32 | |
|
33 | |
@Column(name = "DESCR_FORMATTED", length = KSEntityConstants.EXTRA_LONG_TEXT_LENGTH) |
34 | |
private String descrFormatted; |
35 | |
|
36 | |
@Column(name = "HOLD_STATE") |
37 | |
private String holdState; |
38 | |
|
39 | |
@Column(name = "HOLD_TYPE") |
40 | |
private String holdType; |
41 | |
|
42 | |
@Temporal(TemporalType.TIMESTAMP) |
43 | |
@Column(name = "EFF_DT") |
44 | |
private Date effectiveDate; |
45 | |
|
46 | |
@Temporal(TemporalType.TIMESTAMP) |
47 | |
@Column(name = "RELEASED_DT") |
48 | |
private Date releasedDate; |
49 | |
|
50 | |
@ManyToOne(optional = false) |
51 | |
@JoinColumn(name = "ISSUE_ID") |
52 | |
private HoldIssueEntity holdIssue; |
53 | |
|
54 | |
@Column(name = "PERS_ID") |
55 | |
private String personId; |
56 | |
|
57 | |
@OneToMany(cascade = CascadeType.ALL, mappedBy = "owner") |
58 | |
private List<HoldAttributeEntity> attributes; |
59 | |
|
60 | |
@Override |
61 | |
public void setAttributes(List<HoldAttributeEntity> attributes) { |
62 | 0 | this.attributes = attributes; |
63 | 0 | } |
64 | |
|
65 | 0 | public HoldEntity() { |
66 | 0 | } |
67 | |
|
68 | |
public HoldEntity(Hold hold) { |
69 | 0 | super(hold); |
70 | 0 | this.setId(hold.getId()); |
71 | 0 | this.setHoldType(hold.getTypeKey()); |
72 | 0 | this.fromDto(hold); |
73 | 0 | this.setPersonId(hold.getPersonId()); |
74 | 0 | } |
75 | |
|
76 | |
public void fromDto(Hold hold) { |
77 | 0 | this.setHoldState(hold.getStateKey()); |
78 | 0 | this.setEffectiveDate(hold.getEffectiveDate()); |
79 | 0 | this.setReleasedDate(hold.getReleasedDate()); |
80 | 0 | this.setDescrPlain(hold.getDescr().getPlain()); |
81 | 0 | this.setDescrFormatted(hold.getDescr().getFormatted()); |
82 | 0 | this.setAttributes(new ArrayList<HoldAttributeEntity>()); |
83 | 0 | for (Attribute att : hold.getAttributes()) { |
84 | 0 | HoldAttributeEntity attEntity = new HoldAttributeEntity(att); |
85 | 0 | this.getAttributes().add(attEntity); |
86 | 0 | } |
87 | 0 | } |
88 | |
|
89 | |
public HoldInfo toDto() { |
90 | 0 | HoldInfo info = new HoldInfo(); |
91 | 0 | info.setId(getId()); |
92 | 0 | info.setEffectiveDate(effectiveDate); |
93 | 0 | info.setReleasedDate(releasedDate); |
94 | 0 | info.setPersonId(personId); |
95 | 0 | info.setTypeKey(holdType); |
96 | 0 | info.setStateKey(holdState); |
97 | 0 | if (holdIssue != null) { |
98 | 0 | info.setIssueId(holdIssue.getId()); |
99 | |
} |
100 | 0 | if (descrPlain != null) { |
101 | 0 | info.setDescr(new RichTextInfo(descrPlain, descrFormatted)); |
102 | |
} |
103 | |
|
104 | 0 | info.setMeta(super.toDTO()); |
105 | 0 | for (HoldAttributeEntity att : getAttributes()) { |
106 | 0 | AttributeInfo attInfo = att.toDto(); |
107 | 0 | info.getAttributes().add(attInfo); |
108 | 0 | } |
109 | 0 | return info; |
110 | |
} |
111 | |
|
112 | |
public String getDescrPlain() { |
113 | 0 | return descrPlain; |
114 | |
} |
115 | |
|
116 | |
public String getDescrFormatted() { |
117 | 0 | return descrFormatted; |
118 | |
} |
119 | |
|
120 | |
public void setDescrPlain(String plain) { |
121 | 0 | this.descrPlain = plain; |
122 | 0 | } |
123 | |
|
124 | |
public void setDescrFormatted(String formatted) { |
125 | 0 | this.descrFormatted = formatted; |
126 | 0 | } |
127 | |
|
128 | |
public String getHoldType() { |
129 | 0 | return holdType; |
130 | |
} |
131 | |
|
132 | |
public void setHoldType(String holdType) { |
133 | 0 | this.holdType = holdType; |
134 | 0 | } |
135 | |
|
136 | |
public String getHoldState() { |
137 | 0 | return holdState; |
138 | |
} |
139 | |
|
140 | |
public void setHoldState(String holdState) { |
141 | 0 | this.holdState = holdState; |
142 | 0 | } |
143 | |
|
144 | |
public Date getEffectiveDate() { |
145 | 0 | return effectiveDate; |
146 | |
} |
147 | |
|
148 | |
public void setEffectiveDate(Date effectiveDate) { |
149 | 0 | this.effectiveDate = effectiveDate; |
150 | 0 | } |
151 | |
|
152 | |
public Date getReleasedDate() { |
153 | 0 | return releasedDate; |
154 | |
} |
155 | |
|
156 | |
public void setReleasedDate(Date releasedDate) { |
157 | 0 | this.releasedDate = releasedDate; |
158 | 0 | } |
159 | |
|
160 | |
public HoldIssueEntity getHoldIssue() { |
161 | 0 | return holdIssue; |
162 | |
} |
163 | |
|
164 | |
public void setHoldIssue(HoldIssueEntity issue) { |
165 | 0 | this.holdIssue = issue; |
166 | 0 | } |
167 | |
|
168 | |
public String getPersonId() { |
169 | 0 | return personId; |
170 | |
} |
171 | |
|
172 | |
public void setPersonId(String personId) { |
173 | 0 | this.personId = personId; |
174 | 0 | } |
175 | |
|
176 | |
@Override |
177 | |
public List<HoldAttributeEntity> getAttributes() { |
178 | 0 | return attributes; |
179 | |
} |
180 | |
} |