1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.student.enrollment.class1.lpr.model;
17
18 import java.util.ArrayList;
19 import java.util.HashSet;
20 import java.util.List;
21 import java.util.Set;
22
23 import javax.persistence.CascadeType;
24 import javax.persistence.Column;
25 import javax.persistence.Entity;
26 import javax.persistence.FetchType;
27 import javax.persistence.OneToMany;
28 import javax.persistence.Table;
29
30 import org.kuali.student.r1.common.entity.KSEntityConstants;
31 import org.kuali.student.enrollment.lpr.dto.LprTransactionInfo;
32 import org.kuali.student.enrollment.lpr.dto.LprTransactionItemInfo;
33 import org.kuali.student.enrollment.lpr.infc.LprTransaction;
34 import org.kuali.student.enrollment.lpr.infc.LprTransactionItem;
35 import org.kuali.student.r2.common.dto.AttributeInfo;
36 import org.kuali.student.r2.common.entity.AttributeOwner;
37 import org.kuali.student.r2.common.entity.MetaEntity;
38 import org.kuali.student.r2.common.infc.Attribute;
39 import org.kuali.student.r2.common.util.RichTextHelper;
40
41 @Entity
42 @Table(name = "KSEN_LPR_TRANS")
43 public class LprTransactionEntity extends MetaEntity implements AttributeOwner<LprTransactionAttributeEntity> {
44
45 @Column(name = "NAME")
46 private String name;
47
48 @Column(name = "REQUESTING_PERS_ID")
49 private String requestingPersonId;
50
51 @Column(name = "ATP_ID")
52 private String atpId;
53
54 @Column(name = "DESCR_FORMATTED", length = KSEntityConstants.EXTRA_LONG_TEXT_LENGTH)
55 private String descrFormatted;
56
57 @Column(name = "DESCR_PLAIN", length = KSEntityConstants.EXTRA_LONG_TEXT_LENGTH)
58 private String descrPlain;
59
60 @Column(name = "LPR_TRANS_TYPE", nullable=false)
61 private String lprTransType;
62
63 @Column(name = "LPR_TRANS_STATE", nullable=false)
64 private String lprTransState;
65
66 @OneToMany(cascade = CascadeType.ALL, mappedBy = "owner", fetch = FetchType.EAGER, orphanRemoval=true)
67 private final Set<LprTransactionAttributeEntity> attributes = new HashSet<LprTransactionAttributeEntity>();
68
69 @OneToMany(cascade = CascadeType.ALL, mappedBy = "owner", fetch = FetchType.EAGER, orphanRemoval=true)
70 private final Set<LprTransactionItemEntity> lprTransactionItems = new HashSet<LprTransactionItemEntity>();
71
72
73 public LprTransactionEntity() {}
74
75 public LprTransactionEntity(LprTransaction lprTransaction) {
76 super(lprTransaction);
77
78
79 this.setId(lprTransaction.getId());
80
81 this.setLprTransType(lprTransaction.getTypeKey());
82
83 this.fromDto(lprTransaction);
84 }
85
86 @SuppressWarnings("unchecked")
87 public void fromDto (LprTransaction lprTransaction) {
88
89
90 this.setName(lprTransaction.getName());
91
92 this.setRequestingPersonId(lprTransaction.getRequestingPersonId());
93 this.setAtpId(lprTransaction.getAtpId());
94
95 this.setLprTransState(lprTransaction.getStateKey());
96
97
98 if (lprTransaction.getDescr() != null) {
99 this.setDescrFormatted(lprTransaction.getDescr().getFormatted());
100 this.setDescrPlain(lprTransaction.getDescr().getPlain());
101 } else {
102 this.setDescrFormatted(null);
103 this.setDescrPlain(null);
104 }
105
106 this.attributes.clear();
107
108 for (Attribute attr : lprTransaction.getAttributes()) {
109
110 this.attributes.add(new LprTransactionAttributeEntity(attr, this));
111 }
112
113 this.lprTransactionItems.clear();
114
115 for (LprTransactionItem lprTransactionItem : lprTransaction.getLprTransactionItems()) {
116
117 LprTransactionItemEntity item;
118 this.lprTransactionItems.add(item = new LprTransactionItemEntity(lprTransactionItem));
119 item.setOwner(this);
120 }
121
122 }
123
124
125 public LprTransactionInfo toDto() {
126
127 LprTransactionInfo lpr = new LprTransactionInfo();
128 lpr.setId(getId());
129
130 if (this.getLprTransType() != null)
131 lpr.setTypeKey(this.getLprTransType());
132 if (this.getLprTransState() != null)
133 lpr.setStateKey(this.getLprTransState());
134
135 lpr.setMeta(super.toDTO());
136
137 if (getAttributes() != null) {
138 List<AttributeInfo> atts = new ArrayList<AttributeInfo>();
139 for (LprTransactionAttributeEntity att : getAttributes()) {
140 AttributeInfo attInfo = att.toDto();
141 atts.add(attInfo);
142 }
143 lpr.setAttributes(atts);
144 }
145
146 lpr.setDescr(new RichTextHelper().toRichTextInfo(getDescrPlain(), getDescrFormatted()));
147
148 lpr.setName(getName());
149 lpr.setRequestingPersonId(getRequestingPersonId());
150 lpr.setAtpId(getAtpId());
151 List<LprTransactionItemInfo> lprItemsInfo = new ArrayList<LprTransactionItemInfo>();
152 if (lprTransactionItems != null) {
153 for (LprTransactionItemEntity lprItemEntity : lprTransactionItems) {
154 lprItemsInfo.add(lprItemEntity.toDto());
155 }
156 }
157 lpr.setLprTransactionItems(lprItemsInfo);
158 return lpr;
159
160 }
161
162 public String getName() {
163 return name;
164 }
165
166 public void setName(String name) {
167 this.name = name;
168 }
169
170 public String getLprTransType() {
171 return lprTransType;
172 }
173
174 public void setLprTransType(String lprTransType) {
175 this.lprTransType = lprTransType;
176 }
177
178 public String getLprTransState() {
179 return lprTransState;
180 }
181
182 public void setLprTransState(String lprTransState) {
183 this.lprTransState = lprTransState;
184 }
185
186 public String getRequestingPersonId() {
187 return requestingPersonId;
188 }
189
190 public void setRequestingPersonId(String requestingPersonId) {
191 this.requestingPersonId = requestingPersonId;
192 }
193
194 public String getAtpId() {
195 return atpId;
196 }
197
198 public void setAtpId(String atpId) {
199 this.atpId = atpId;
200 }
201
202
203
204 public Set<LprTransactionItemEntity> getLprTransactionItems() {
205 return lprTransactionItems;
206 }
207
208 public void setLprTransactionItems(Set<LprTransactionItemEntity> lprTransactionItems) {
209
210 this.lprTransactionItems.clear();
211
212 if (lprTransactionItems != null)
213 this.lprTransactionItems.addAll(lprTransactionItems);
214 }
215
216
217 @Override
218 public void setAttributes(Set<LprTransactionAttributeEntity> attributes) {
219 this.attributes.clear();
220
221 if (attributes != null)
222 this.attributes.addAll(attributes);
223 }
224
225 @Override
226 public Set<LprTransactionAttributeEntity> getAttributes() {
227 return this.attributes;
228 }
229
230 public String getDescrFormatted() {
231 return descrFormatted;
232 }
233
234 public void setDescrFormatted(String descrFormatted) {
235 this.descrFormatted = descrFormatted;
236 }
237
238 public String getDescrPlain() {
239 return descrPlain;
240 }
241
242 public void setDescrPlain(String descrPlain) {
243 this.descrPlain = descrPlain;
244 }
245
246 @Override
247 public String toString() {
248 StringBuilder builder = new StringBuilder();
249 builder.append("LprTransactionEntity [version=");
250 builder.append(getVersionNumber());
251 builder.append(", id=");
252 builder.append(getId());
253 builder.append(", name=");
254 builder.append(name);
255 builder.append(", requestingPersonId=");
256 builder.append(requestingPersonId);
257 builder.append(", atpId=");
258 builder.append(atpId);
259 builder.append(", lprTransType=");
260 builder.append(lprTransType);
261 builder.append(", lprTransState=");
262 builder.append(lprTransState);
263 builder.append("]");
264 return builder.toString();
265 }
266
267
268 }