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.ElementCollection;
26 import javax.persistence.Entity;
27 import javax.persistence.FetchType;
28 import javax.persistence.JoinColumn;
29 import javax.persistence.JoinTable;
30 import javax.persistence.ManyToOne;
31 import javax.persistence.OneToMany;
32 import javax.persistence.Table;
33
34 import org.kuali.student.r1.common.entity.KSEntityConstants;
35 import org.kuali.student.enrollment.lpr.dto.LprTransactionItemInfo;
36 import org.kuali.student.enrollment.lpr.dto.LprTransactionItemRequestOptionInfo;
37 import org.kuali.student.enrollment.lpr.dto.LprTransactionItemResultInfo;
38 import org.kuali.student.enrollment.lpr.infc.LprTransactionItem;
39 import org.kuali.student.enrollment.lpr.infc.LprTransactionItemRequestOption;
40 import org.kuali.student.r2.common.dto.AttributeInfo;
41 import org.kuali.student.r2.common.entity.AttributeOwner;
42 import org.kuali.student.r2.common.entity.MetaEntity;
43 import org.kuali.student.r2.common.infc.Attribute;
44 import org.kuali.student.r2.common.util.RichTextHelper;
45
46 @Entity
47 @Table(name = "KSEN_LPR_TRANS_ITEM")
48 public class LprTransactionItemEntity extends MetaEntity implements AttributeOwner<LprTransactionItemAttributeEntity> {
49
50 @Column(name = "PERS_ID")
51 private String personId;
52
53 @Column(name = "NEW_LUI_ID")
54 private String newLuiId;
55
56 @Column(name = "EXISTING_LUI_ID")
57 private String existingLuiId;
58
59 @Column(name = "LTI_RESULTING_LPR_ID")
60 private String resultingLprId;
61
62 @Column(name = "LTI_RESULT_MESSAGE")
63 private String resultMessage;
64
65 @Column(name = "LTI_RESULT_STATUS")
66 private String status;
67
68 @Column(name = "GROUP_ID")
69 private String groupId;
70
71 @Column(name = "NAME")
72 private String name;
73
74 @Column(name = "DESCR_FORMATTED", length = KSEntityConstants.EXTRA_LONG_TEXT_LENGTH)
75 private String descrFormatted;
76
77 @Column(name = "DESCR_PLAIN", length = KSEntityConstants.EXTRA_LONG_TEXT_LENGTH)
78 private String descrPlain;
79
80 @Column(name = "LPR_TRANS_ITEM_TYPE")
81 private String lprTransactionItemType;
82
83 @Column(name = "LPR_TRANS_ITEM_STATE")
84 private String lprTransactionItemState;
85
86 @OneToMany(cascade = CascadeType.ALL, mappedBy = "owner", orphanRemoval=true, fetch=FetchType.EAGER)
87 private final Set<LprTransactionItemAttributeEntity> attributes = new HashSet<LprTransactionItemAttributeEntity>();
88
89 @OneToMany (cascade = CascadeType.ALL, mappedBy = "lprTransactionItem", orphanRemoval=true, fetch=FetchType.EAGER)
90 private final Set<LprTransactionItemRequestOptionEntity>requestOptions = new HashSet<LprTransactionItemRequestOptionEntity>();
91
92 @ElementCollection(fetch=FetchType.EAGER)
93 @JoinTable (name="KSEN_LPR_TRANS_ITEM_RVG", joinColumns=@JoinColumn(name="LPR_TRANS_ITEM_ID"))
94 @Column(name="RESULT_VAL_GRP_ID")
95 private final Set<String>resultValueGroupIds = new HashSet<String>();
96
97 @ManyToOne
98 @JoinColumn(name="LPR_TRANS_ID")
99 private LprTransactionEntity owner;
100
101 public LprTransactionItemEntity() {
102 }
103
104 public LprTransactionItemEntity(LprTransactionItem lprTransactionItem) {
105
106 super(lprTransactionItem);
107 if (lprTransactionItem != null) {
108 this.setId(lprTransactionItem.getId());
109
110 this.fromDto(lprTransactionItem);
111 }
112 }
113
114
115 public void fromDto(LprTransactionItem lprTransactionItem) {
116
117
118 super.fromDTO(lprTransactionItem);
119
120 this.setNewLuiId(lprTransactionItem.getNewLuiId());
121 this.setExistingLuiId(lprTransactionItem.getExistingLuiId());
122 this.setPersonId(lprTransactionItem.getPersonId());
123
124 this.setLprTransactionItemState(lprTransactionItem.getStateKey());
125 this.setLprTransactionItemType(lprTransactionItem.getTypeKey());
126
127 if (lprTransactionItem.getDescr() != null) {
128 this.setDescrFormatted(lprTransactionItem.getDescr()
129 .getFormatted());
130 this.setDescrPlain(lprTransactionItem.getDescr().getPlain());
131 } else {
132 this.setDescrFormatted(null);
133 this.setDescrPlain(null);
134 }
135
136 if (lprTransactionItem.getLprTransactionItemResult() != null) {
137 this.setResultingLprId(lprTransactionItem
138 .getLprTransactionItemResult().getResultingLprId());
139 this.setStatus(lprTransactionItem.getLprTransactionItemResult()
140 .getStatus() ? "Y" : "N");
141 }
142
143
144 this.attributes.clear();
145
146 for (Attribute attr : lprTransactionItem.getAttributes()) {
147
148 this.attributes.add(new LprTransactionItemAttributeEntity(attr, this));
149 }
150
151 this.requestOptions.clear();
152
153 for (LprTransactionItemRequestOption requestOption : lprTransactionItem.getRequestOptions()) {
154
155 this.requestOptions.add(new LprTransactionItemRequestOptionEntity(requestOption));
156
157 }
158
159 this.resultValueGroupIds.clear();
160
161 this.resultValueGroupIds.addAll(lprTransactionItem.getResultValuesGroupKeys());
162
163
164 }
165
166 public LprTransactionItemInfo toDto() {
167
168 LprTransactionItemInfo lprTransItemInfo = new LprTransactionItemInfo();
169 lprTransItemInfo.setId(getId());
170
171 lprTransItemInfo.setTypeKey(this.getLprTransactionItemType());
172 lprTransItemInfo.setStateKey(this.getLprTransactionItemState());
173 lprTransItemInfo.setExistingLuiId(this.getExistingLuiId());
174 lprTransItemInfo.setNewLuiId(this.getNewLuiId());
175 lprTransItemInfo.setPersonId(this.getPersonId());
176
177 if (this.owner != null)
178 lprTransItemInfo.setTransactionId(this.owner.getId());
179 else
180 lprTransItemInfo.setTransactionId(null);
181
182 lprTransItemInfo.setMeta(super.toDTO());
183
184 lprTransItemInfo.setDescr(new RichTextHelper().toRichTextInfo(
185 getDescrPlain(), getDescrFormatted()));
186
187 if (getAttributes() != null) {
188 List<AttributeInfo> atts = new ArrayList<AttributeInfo>();
189 for (LprTransactionItemAttributeEntity att : getAttributes()) {
190 AttributeInfo attInfo = att.toDto();
191 atts.add(attInfo);
192 }
193 lprTransItemInfo.setAttributes(atts);
194 }
195
196 Set<LprTransactionItemRequestOptionEntity> requestOptionsList = getRequestOptions();
197
198 if (requestOptionsList != null) {
199
200 List<LprTransactionItemRequestOptionInfo> rOptions = new ArrayList<LprTransactionItemRequestOptionInfo>();
201
202 for (LprTransactionItemRequestOptionEntity lprTransactionItemRequestOptionEntity : requestOptionsList) {
203
204 rOptions.add(lprTransactionItemRequestOptionEntity.toDto());
205 }
206
207 lprTransItemInfo.setRequestOptions(rOptions);
208 }
209 else {
210 lprTransItemInfo.setRequestOptions(new ArrayList<LprTransactionItemRequestOptionInfo>());
211 }
212
213
214 List<String> resultValueGroupKeys = new ArrayList<String> (getResultValueGroupIds().size());
215
216 lprTransItemInfo.setResultValuesGroupKeys(resultValueGroupKeys);
217
218 if (this.getResultingLprId() != null && this.getStatus() != null) {
219
220 LprTransactionItemResultInfo lprItemResult = new LprTransactionItemResultInfo();
221
222 lprItemResult.setResultingLprId(this.getResultingLprId());
223 lprItemResult.setStatus(Boolean.valueOf(
224 "Y".equals(this.getStatus()) ? true : false));
225 lprTransItemInfo.setLprTransactionItemResult(lprItemResult);
226 }
227 return lprTransItemInfo;
228
229 }
230
231 public String getDescrFormatted() {
232 return descrFormatted;
233 }
234
235 public void setDescrFormatted(String descrFormatted) {
236 this.descrFormatted = descrFormatted;
237 }
238 public String getDescrPlain() {
239 return descrPlain;
240 }
241
242 public void setDescrPlain(String descrPlain) {
243 this.descrPlain = descrPlain;
244 }
245
246 public String getResultingLprId() {
247 return resultingLprId;
248 }
249
250 public void setResultingLprId(String resultingLprId) {
251 this.resultingLprId = resultingLprId;
252 }
253
254 public String getPersonId() {
255 return personId;
256 }
257
258 public String getGroupId() {
259 return groupId;
260 }
261
262 public void setGroupId(String groupId) {
263 this.groupId = groupId;
264 }
265
266 public void setPersonId(String personId) {
267 this.personId = personId;
268 }
269
270 public String getNewLuiId() {
271 return newLuiId;
272 }
273
274 public String getStatus() {
275 return status;
276 }
277
278 public void setStatus(String status) {
279 this.status = status;
280 }
281
282 public void setNewLuiId(String newLuiId) {
283 this.newLuiId = newLuiId;
284 }
285
286 public String getExistingLuiId() {
287 return existingLuiId;
288 }
289
290 public void setExistingLuiId(String existingLuiId) {
291 this.existingLuiId = existingLuiId;
292 }
293
294 public String getLprTransactionItemType() {
295 return lprTransactionItemType;
296 }
297
298 public void setLprTransactionItemType(String lprTransactionType) {
299 this.lprTransactionItemType = lprTransactionType;
300 }
301
302 public String getLprTransactionItemState() {
303 return lprTransactionItemState;
304 }
305
306 public void setLprTransactionItemState(String lprTransactionState) {
307 this.lprTransactionItemState = lprTransactionState;
308 }
309
310 public Set<LprTransactionItemAttributeEntity> getAttributes() {
311 return attributes;
312 }
313
314 public void setAttributes(Set<LprTransactionItemAttributeEntity> attributes) {
315
316 this.attributes.clear();
317
318 if (attributes != null)
319 this.attributes.addAll(attributes);
320 }
321
322 public String getResultMessage() {
323 return resultMessage;
324 }
325
326 public void setResultMessage(String resultMessage) {
327 this.resultMessage = resultMessage;
328 }
329
330 public String getName() {
331 return name;
332 }
333
334 public void setName(String name) {
335 this.name = name;
336 }
337
338 public LprTransactionEntity getOwner() {
339 return owner;
340 }
341
342 public void setOwner(LprTransactionEntity owner) {
343 this.owner = owner;
344 }
345
346 public Set<LprTransactionItemRequestOptionEntity> getRequestOptions() {
347 return requestOptions;
348 }
349
350 public void setRequestOptions(
351 Set<LprTransactionItemRequestOptionEntity> requestOptions) {
352 this.requestOptions.clear();
353
354 if (requestOptions != null)
355 this.requestOptions.addAll(requestOptions);
356 }
357
358
359
360 public Set<String> getResultValueGroupIds() {
361 return resultValueGroupIds;
362 }
363
364 public void setResultValueGroupIds(Set<String> resultValueGroupIds) {
365 this.resultValueGroupIds.clear();
366
367 if (resultValueGroupIds != null) {
368 this.resultValueGroupIds.addAll(resultValueGroupIds);
369 }
370 }
371
372 @Override
373 public String toString() {
374 StringBuilder builder = new StringBuilder();
375 builder.append("LprTransactionItemEntity [id=");
376 builder.append(getId());
377 builder.append(", personId=");
378 builder.append(personId);
379 builder.append(", newLuiId=");
380 builder.append(newLuiId);
381 builder.append(", existingLuiId=");
382 builder.append(existingLuiId);
383 builder.append(", resultingLprId=");
384 builder.append(resultingLprId);
385 builder.append(", groupId=");
386 builder.append(groupId);
387 builder.append(", lprTransactionItemType=");
388 builder.append(lprTransactionItemType);
389 builder.append(", lprTransactionItemState=");
390 builder.append(lprTransactionItemState);
391 builder.append("]");
392 return builder.toString();
393 }
394
395
396
397 }