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.List; |
20 | |
|
21 | |
import javax.persistence.CascadeType; |
22 | |
import javax.persistence.Column; |
23 | |
import javax.persistence.Entity; |
24 | |
import javax.persistence.JoinColumn; |
25 | |
import javax.persistence.ManyToOne; |
26 | |
import javax.persistence.OneToMany; |
27 | |
import javax.persistence.Table; |
28 | |
|
29 | |
import org.kuali.student.common.entity.KSEntityConstants; |
30 | |
import org.kuali.student.enrollment.lpr.dto.LprTransactionItemInfo; |
31 | |
import org.kuali.student.enrollment.lpr.dto.LprTransactionItemRequestOptionInfo; |
32 | |
import org.kuali.student.enrollment.lpr.dto.LprTransactionItemResultInfo; |
33 | |
import org.kuali.student.enrollment.lpr.infc.LprTransactionItem; |
34 | |
import org.kuali.student.enrollment.lpr.infc.LprTransactionItemRequestOption; |
35 | |
import org.kuali.student.r2.common.dto.AttributeInfo; |
36 | |
import org.kuali.student.r2.common.entity.MetaEntity; |
37 | |
import org.kuali.student.r2.common.helper.EntityMergeHelper; |
38 | |
import org.kuali.student.r2.common.helper.EntityMergeHelper.EntityMergeOptions; |
39 | |
import org.kuali.student.r2.common.helper.EntityMergeHelper.EntityMergeResult; |
40 | |
import org.kuali.student.r2.common.infc.Attribute; |
41 | |
import org.kuali.student.r2.common.util.RichTextHelper; |
42 | |
|
43 | |
@Entity |
44 | |
@Table(name = "KSEN_LPR_TRANS_ITEM") |
45 | |
public class LprTransactionItemEntity extends MetaEntity { |
46 | |
|
47 | |
@Column(name = "PERS_ID") |
48 | |
private String personId; |
49 | |
|
50 | |
@Column(name = "NEW_LUI_ID") |
51 | |
private String newLuiId; |
52 | |
|
53 | |
@Column(name = "EXISTING_LUI_ID") |
54 | |
private String existingLuiId; |
55 | |
|
56 | |
@Column(name = "LTI_RESULTING_LPR_ID") |
57 | |
private String resultingLprId; |
58 | |
|
59 | |
@Column(name = "LTI_RESULT_MESSAGE") |
60 | |
private String resultMessage; |
61 | |
|
62 | |
@Column(name = "LTI_RESULTING_STATUS") |
63 | |
private String status; |
64 | |
|
65 | |
@Column(name = "GROUP_ID") |
66 | |
private String groupId; |
67 | |
|
68 | |
@Column(name = "NAME") |
69 | |
private String name; |
70 | |
|
71 | |
@Column(name = "DESCR_FORMATTED", length = KSEntityConstants.EXTRA_LONG_TEXT_LENGTH) |
72 | |
private String descrFormatted; |
73 | |
|
74 | |
@Column(name = "DESCR_PLAIN", length = KSEntityConstants.EXTRA_LONG_TEXT_LENGTH) |
75 | |
private String descrPlain; |
76 | |
|
77 | |
@Column(name = "LPR_TRANS_ITEM_TYPE") |
78 | |
private String lprTransactionItemType; |
79 | |
|
80 | |
@Column(name = "LPR_TRANS_ITEM_STATE") |
81 | |
private String lprTransactionItemState; |
82 | |
|
83 | |
@OneToMany(cascade = CascadeType.ALL, mappedBy = "owner") |
84 | |
private List<LprTransactionItemAttributeEntity> attributes; |
85 | |
|
86 | |
@OneToMany (cascade = CascadeType.ALL, mappedBy = "lprTransactionItem") |
87 | |
private List<LprTransactionItemRequestOptionEntity>requestOptions; |
88 | |
|
89 | |
@OneToMany (cascade = CascadeType.ALL, mappedBy = "lprTransactionItem") |
90 | |
private List<LprTransactionItemResultValueGroupEntity>resultValueGroups; |
91 | |
|
92 | |
@ManyToOne |
93 | |
@JoinColumn(name="LPR_TRANS_ID") |
94 | |
private LprTransactionEntity owner; |
95 | |
|
96 | 0 | public LprTransactionItemEntity() { |
97 | 0 | } |
98 | |
|
99 | |
public LprTransactionItemEntity(LprTransactionItem lprTransactionItem) { |
100 | |
|
101 | 0 | super(lprTransactionItem); |
102 | 0 | if (lprTransactionItem != null) { |
103 | 0 | this.setId(lprTransactionItem.getId()); |
104 | |
|
105 | 0 | this.fromDto(lprTransactionItem); |
106 | |
} |
107 | 0 | } |
108 | |
|
109 | |
|
110 | |
public List<Object> fromDto(LprTransactionItem lprTransactionItem) { |
111 | |
|
112 | 0 | List<Object>orphanList = new ArrayList<Object>(); |
113 | |
|
114 | 0 | this.setNewLuiId(lprTransactionItem.getNewLuiId()); |
115 | 0 | this.setExistingLuiId(lprTransactionItem.getExistingLuiId()); |
116 | 0 | this.setPersonId(lprTransactionItem.getPersonId()); |
117 | |
|
118 | 0 | this.setLprTransactionItemState(lprTransactionItem.getStateKey()); |
119 | 0 | this.setLprTransactionItemType(lprTransactionItem.getTypeKey()); |
120 | |
|
121 | 0 | if (lprTransactionItem.getDescr() != null) { |
122 | 0 | this.setDescrFormatted(lprTransactionItem.getDescr() |
123 | |
.getFormatted()); |
124 | 0 | this.setDescrPlain(lprTransactionItem.getDescr().getPlain()); |
125 | |
} else { |
126 | 0 | this.setDescrFormatted(null); |
127 | 0 | this.setDescrPlain(null); |
128 | |
} |
129 | |
|
130 | 0 | if (lprTransactionItem.getLprTransactionItemResult() != null) { |
131 | 0 | this.setResultingLprId(lprTransactionItem |
132 | |
.getLprTransactionItemResult().getResultingLprId()); |
133 | 0 | this.setStatus(lprTransactionItem.getLprTransactionItemResult() |
134 | |
.getStatus() ? "Y" : "N"); |
135 | |
} |
136 | |
|
137 | |
|
138 | 0 | EntityMergeHelper<LprTransactionItemAttributeEntity, Attribute>attributeMergeHelper = new EntityMergeHelper<LprTransactionItemAttributeEntity, Attribute>(); |
139 | |
|
140 | 0 | EntityMergeResult<LprTransactionItemAttributeEntity> attributesMergeResult = attributeMergeHelper.merge(attributes, (List<Attribute>) lprTransactionItem.getAttributes(), new EntityMergeHelper.EntityMergeOptions<LprTransactionItemAttributeEntity, Attribute>() { |
141 | |
|
142 | |
@Override |
143 | |
public String getEntityId(LprTransactionItemAttributeEntity entity) { |
144 | 0 | return entity.getId(); |
145 | |
} |
146 | |
|
147 | |
@Override |
148 | |
public String getInfoId(Attribute info) { |
149 | 0 | return info.getId(); |
150 | |
} |
151 | |
|
152 | |
@Override |
153 | |
public List<Object> merge(LprTransactionItemAttributeEntity entity, |
154 | |
Attribute info) { |
155 | |
|
156 | 0 | entity.fromDto(info); |
157 | |
|
158 | 0 | entity.setOwner(LprTransactionItemEntity.this); |
159 | |
|
160 | 0 | return new ArrayList<Object>(); |
161 | |
} |
162 | |
|
163 | |
@Override |
164 | |
public LprTransactionItemAttributeEntity create(Attribute info) { |
165 | |
|
166 | 0 | LprTransactionItemAttributeEntity entity = new LprTransactionItemAttributeEntity(info); |
167 | |
|
168 | 0 | entity.setOwner(LprTransactionItemEntity.this); |
169 | |
|
170 | 0 | return entity; |
171 | |
} |
172 | |
|
173 | |
|
174 | |
}); |
175 | |
|
176 | 0 | this.attributes = attributesMergeResult.getMergedList(); |
177 | |
|
178 | 0 | orphanList.addAll(attributesMergeResult.getOrphanList()); |
179 | |
|
180 | 0 | EntityMergeHelper<LprTransactionItemRequestOptionEntity, LprTransactionItemRequestOption>requestOptionMergeHelper = new EntityMergeHelper<LprTransactionItemRequestOptionEntity, LprTransactionItemRequestOption>(); |
181 | |
|
182 | 0 | EntityMergeResult<LprTransactionItemRequestOptionEntity> requestOptionMergeResults = requestOptionMergeHelper.merge(this.requestOptions, (List<LprTransactionItemRequestOption>) lprTransactionItem.getRequestOptions(), new EntityMergeOptions<LprTransactionItemRequestOptionEntity, LprTransactionItemRequestOption>() { |
183 | |
|
184 | |
@Override |
185 | |
public String getEntityId( |
186 | |
LprTransactionItemRequestOptionEntity entity) { |
187 | 0 | return entity.getId(); |
188 | |
} |
189 | |
|
190 | |
@Override |
191 | |
public String getInfoId(LprTransactionItemRequestOption info) { |
192 | 0 | return info.getId(); |
193 | |
} |
194 | |
|
195 | |
@Override |
196 | |
public List<Object> merge( |
197 | |
LprTransactionItemRequestOptionEntity entity, |
198 | |
LprTransactionItemRequestOption info) { |
199 | |
|
200 | 0 | entity.fromDto(info); |
201 | |
|
202 | 0 | entity.setLprTransactionItem(LprTransactionItemEntity.this); |
203 | |
|
204 | 0 | return new ArrayList<Object>(); |
205 | |
} |
206 | |
|
207 | |
@Override |
208 | |
public LprTransactionItemRequestOptionEntity create( |
209 | |
LprTransactionItemRequestOption info) { |
210 | |
|
211 | 0 | LprTransactionItemRequestOptionEntity entity = new LprTransactionItemRequestOptionEntity(info); |
212 | |
|
213 | 0 | entity.setLprTransactionItem(LprTransactionItemEntity.this); |
214 | |
|
215 | 0 | return entity; |
216 | |
} |
217 | |
|
218 | |
|
219 | |
}); |
220 | |
|
221 | |
|
222 | 0 | this.requestOptions = requestOptionMergeResults.getMergedList(); |
223 | |
|
224 | 0 | orphanList.addAll(requestOptionMergeResults.getOrphanList()); |
225 | |
|
226 | 0 | EntityMergeHelper<LprTransactionItemResultValueGroupEntity, String> resultValueGroupMergeHelper = new EntityMergeHelper<LprTransactionItemResultValueGroupEntity, String>(); |
227 | |
|
228 | 0 | EntityMergeResult<LprTransactionItemResultValueGroupEntity> resultValueGroupMergeResult = resultValueGroupMergeHelper.mergeStringList(this.resultValueGroups, lprTransactionItem.getResultValuesGroupKeys(), new EntityMergeHelper.StringMergeOptions<LprTransactionItemResultValueGroupEntity>() { |
229 | |
|
230 | |
@Override |
231 | |
public String getKey(LprTransactionItemResultValueGroupEntity entity) { |
232 | 0 | return entity.getResultValueGroupId(); |
233 | |
} |
234 | |
|
235 | |
@Override |
236 | |
public LprTransactionItemResultValueGroupEntity create(String value) { |
237 | |
|
238 | 0 | LprTransactionItemResultValueGroupEntity entity = new LprTransactionItemResultValueGroupEntity(value); |
239 | |
|
240 | 0 | entity.setLprTransactionItem(LprTransactionItemEntity.this); |
241 | |
|
242 | 0 | return entity; |
243 | |
} |
244 | |
|
245 | |
}); |
246 | |
|
247 | 0 | this.resultValueGroups = resultValueGroupMergeResult.getMergedList(); |
248 | |
|
249 | 0 | orphanList.addAll(resultValueGroupMergeResult.getOrphanList()); |
250 | |
|
251 | 0 | return orphanList; |
252 | |
} |
253 | |
|
254 | |
public LprTransactionItemInfo toDto() { |
255 | |
|
256 | 0 | LprTransactionItemInfo lprTransItemInfo = new LprTransactionItemInfo(); |
257 | 0 | lprTransItemInfo.setId(getId()); |
258 | |
|
259 | 0 | lprTransItemInfo.setTypeKey(this.getLprTransactionItemType()); |
260 | 0 | lprTransItemInfo.setStateKey(this.getLprTransactionItemState()); |
261 | 0 | lprTransItemInfo.setExistingLuiId(this.getExistingLuiId()); |
262 | 0 | lprTransItemInfo.setNewLuiId(this.getNewLuiId()); |
263 | 0 | lprTransItemInfo.setPersonId(this.getPersonId()); |
264 | |
|
265 | 0 | if (this.owner != null) |
266 | 0 | lprTransItemInfo.setTransactionId(this.owner.getId()); |
267 | |
else |
268 | 0 | lprTransItemInfo.setTransactionId(null); |
269 | |
|
270 | 0 | lprTransItemInfo.setMeta(super.toDTO()); |
271 | |
|
272 | 0 | lprTransItemInfo.setDescr(new RichTextHelper().toRichTextInfo( |
273 | |
getDescrPlain(), getDescrFormatted())); |
274 | |
|
275 | 0 | if (getAttributes() != null) { |
276 | 0 | List<AttributeInfo> atts = new ArrayList<AttributeInfo>(); |
277 | 0 | for (LprTransactionItemAttributeEntity att : getAttributes()) { |
278 | 0 | AttributeInfo attInfo = att.toDto(); |
279 | 0 | atts.add(attInfo); |
280 | 0 | } |
281 | 0 | lprTransItemInfo.setAttributes(atts); |
282 | |
} |
283 | |
|
284 | 0 | List<LprTransactionItemRequestOptionEntity> requestOptionsList = getRequestOptions(); |
285 | |
|
286 | 0 | if (requestOptionsList != null) { |
287 | |
|
288 | 0 | List<LprTransactionItemRequestOptionInfo> rOptions = new ArrayList<LprTransactionItemRequestOptionInfo>(); |
289 | |
|
290 | 0 | for (LprTransactionItemRequestOptionEntity lprTransactionItemRequestOptionEntity : requestOptionsList) { |
291 | |
|
292 | 0 | rOptions.add(lprTransactionItemRequestOptionEntity.toDto()); |
293 | |
} |
294 | |
|
295 | 0 | lprTransItemInfo.setRequestOptions(rOptions); |
296 | 0 | } |
297 | |
else { |
298 | 0 | lprTransItemInfo.setRequestOptions(new ArrayList<LprTransactionItemRequestOptionInfo>()); |
299 | |
} |
300 | |
|
301 | 0 | List<LprTransactionItemResultValueGroupEntity> resultValueGroupsList = getResultValueGroups(); |
302 | |
|
303 | 0 | if (resultValueGroupsList != null) { |
304 | |
|
305 | 0 | for (LprTransactionItemResultValueGroupEntity lprTransactionItemResultValueGroup : resultValueGroupsList) { |
306 | 0 | lprTransItemInfo.getResultValuesGroupKeys().add(lprTransactionItemResultValueGroup.getResultValueGroupId()); |
307 | |
} |
308 | |
|
309 | |
} |
310 | |
|
311 | 0 | if (this.getResultingLprId() != null && this.getStatus() != null) { |
312 | |
|
313 | 0 | LprTransactionItemResultInfo lprItemResult = new LprTransactionItemResultInfo(); |
314 | |
|
315 | 0 | lprItemResult.setResultingLprId(this.getResultingLprId()); |
316 | 0 | lprItemResult.setStatus(new Boolean( |
317 | |
"Y".equals(this.getStatus()) ? true : false)); |
318 | 0 | lprTransItemInfo.setLprTransactionItemResult(lprItemResult); |
319 | |
} |
320 | 0 | return lprTransItemInfo; |
321 | |
|
322 | |
} |
323 | |
|
324 | |
public String getDescrFormatted() { |
325 | 0 | return descrFormatted; |
326 | |
} |
327 | |
|
328 | |
public void setDescrFormatted(String descrFormatted) { |
329 | 0 | this.descrFormatted = descrFormatted; |
330 | 0 | } |
331 | |
|
332 | |
public String getDescrPlain() { |
333 | 0 | return descrPlain; |
334 | |
} |
335 | |
|
336 | |
public void setDescrPlain(String descrPlain) { |
337 | 0 | this.descrPlain = descrPlain; |
338 | 0 | } |
339 | |
|
340 | |
public String getResultingLprId() { |
341 | 0 | return resultingLprId; |
342 | |
} |
343 | |
|
344 | |
public void setResultingLprId(String resultingLprId) { |
345 | 0 | this.resultingLprId = resultingLprId; |
346 | 0 | } |
347 | |
|
348 | |
public String getPersonId() { |
349 | 0 | return personId; |
350 | |
} |
351 | |
|
352 | |
public String getGroupId() { |
353 | 0 | return groupId; |
354 | |
} |
355 | |
|
356 | |
public void setGroupId(String groupId) { |
357 | 0 | this.groupId = groupId; |
358 | 0 | } |
359 | |
|
360 | |
public void setPersonId(String personId) { |
361 | 0 | this.personId = personId; |
362 | 0 | } |
363 | |
|
364 | |
public String getNewLuiId() { |
365 | 0 | return newLuiId; |
366 | |
} |
367 | |
|
368 | |
public String getStatus() { |
369 | 0 | return status; |
370 | |
} |
371 | |
|
372 | |
public void setStatus(String status) { |
373 | 0 | this.status = status; |
374 | 0 | } |
375 | |
|
376 | |
public void setNewLuiId(String newLuiId) { |
377 | 0 | this.newLuiId = newLuiId; |
378 | 0 | } |
379 | |
|
380 | |
public String getExistingLuiId() { |
381 | 0 | return existingLuiId; |
382 | |
} |
383 | |
|
384 | |
public void setExistingLuiId(String existingLuiId) { |
385 | 0 | this.existingLuiId = existingLuiId; |
386 | 0 | } |
387 | |
|
388 | |
public String getLprTransactionItemType() { |
389 | 0 | return lprTransactionItemType; |
390 | |
} |
391 | |
|
392 | |
public void setLprTransactionItemType(String lprTransactionType) { |
393 | 0 | this.lprTransactionItemType = lprTransactionType; |
394 | 0 | } |
395 | |
|
396 | |
public String getLprTransactionItemState() { |
397 | 0 | return lprTransactionItemState; |
398 | |
} |
399 | |
|
400 | |
public void setLprTransactionItemState(String lprTransactionState) { |
401 | 0 | this.lprTransactionItemState = lprTransactionState; |
402 | 0 | } |
403 | |
|
404 | |
public List<LprTransactionItemAttributeEntity> getAttributes() { |
405 | 0 | return attributes; |
406 | |
} |
407 | |
|
408 | |
public void setAttributes(List<LprTransactionItemAttributeEntity> attributes) { |
409 | 0 | this.attributes = attributes; |
410 | 0 | } |
411 | |
|
412 | |
public String getResultMessage() { |
413 | 0 | return resultMessage; |
414 | |
} |
415 | |
|
416 | |
public void setResultMessage(String resultMessage) { |
417 | 0 | this.resultMessage = resultMessage; |
418 | 0 | } |
419 | |
|
420 | |
public String getName() { |
421 | 0 | return name; |
422 | |
} |
423 | |
|
424 | |
public void setName(String name) { |
425 | 0 | this.name = name; |
426 | 0 | } |
427 | |
|
428 | |
public LprTransactionEntity getOwner() { |
429 | 0 | return owner; |
430 | |
} |
431 | |
|
432 | |
public void setOwner(LprTransactionEntity owner) { |
433 | 0 | this.owner = owner; |
434 | 0 | } |
435 | |
|
436 | |
public List<LprTransactionItemRequestOptionEntity> getRequestOptions() { |
437 | 0 | return requestOptions; |
438 | |
} |
439 | |
|
440 | |
public void setRequestOptions( |
441 | |
List<LprTransactionItemRequestOptionEntity> requestOptions) { |
442 | 0 | this.requestOptions = requestOptions; |
443 | 0 | } |
444 | |
|
445 | |
public List<LprTransactionItemResultValueGroupEntity> getResultValueGroups() { |
446 | 0 | return resultValueGroups; |
447 | |
} |
448 | |
|
449 | |
public void setResultValueGroups( |
450 | |
List<LprTransactionItemResultValueGroupEntity> resultValueGroups) { |
451 | 0 | this.resultValueGroups = resultValueGroups; |
452 | 0 | } |
453 | |
|
454 | |
@Override |
455 | |
public String toString() { |
456 | 0 | StringBuilder builder = new StringBuilder(); |
457 | 0 | builder.append("LprTransactionItemEntity [id="); |
458 | 0 | builder.append(getId()); |
459 | 0 | builder.append(", personId="); |
460 | 0 | builder.append(personId); |
461 | 0 | builder.append(", newLuiId="); |
462 | 0 | builder.append(newLuiId); |
463 | 0 | builder.append(", existingLuiId="); |
464 | 0 | builder.append(existingLuiId); |
465 | 0 | builder.append(", resultingLprId="); |
466 | 0 | builder.append(resultingLprId); |
467 | 0 | builder.append(", groupId="); |
468 | 0 | builder.append(groupId); |
469 | 0 | builder.append(", lprTransactionItemType="); |
470 | 0 | builder.append(lprTransactionItemType); |
471 | 0 | builder.append(", lprTransactionItemState="); |
472 | 0 | builder.append(lprTransactionItemState); |
473 | 0 | builder.append("]"); |
474 | 0 | return builder.toString(); |
475 | |
} |
476 | |
|
477 | |
|
478 | |
|
479 | |
} |