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.OneToMany; |
25 | |
import javax.persistence.Table; |
26 | |
|
27 | |
import org.kuali.student.common.entity.KSEntityConstants; |
28 | |
import org.kuali.student.enrollment.lpr.dto.LprTransactionInfo; |
29 | |
import org.kuali.student.enrollment.lpr.dto.LprTransactionItemInfo; |
30 | |
import org.kuali.student.enrollment.lpr.infc.LprTransaction; |
31 | |
import org.kuali.student.enrollment.lpr.infc.LprTransactionItem; |
32 | |
import org.kuali.student.r2.common.dto.AttributeInfo; |
33 | |
import org.kuali.student.r2.common.entity.MetaEntity; |
34 | |
import org.kuali.student.r2.common.helper.EntityMergeHelper; |
35 | |
import org.kuali.student.r2.common.helper.EntityMergeHelper.EntityMergeResult; |
36 | |
import org.kuali.student.r2.common.infc.Attribute; |
37 | |
import org.kuali.student.r2.common.util.RichTextHelper; |
38 | |
|
39 | |
@Entity |
40 | |
@Table(name = "KSEN_LPR_TRANS") |
41 | |
public class LprTransactionEntity extends MetaEntity { |
42 | |
|
43 | |
@Column(name = "NAME") |
44 | |
private String name; |
45 | |
|
46 | |
@Column(name = "REQUESTING_PERS_ID") |
47 | |
private String requestingPersonId; |
48 | |
|
49 | |
@Column(name = "ATP_ID") |
50 | |
private String atpId; |
51 | |
|
52 | |
@Column(name = "DESCR_FORMATTED", length = KSEntityConstants.EXTRA_LONG_TEXT_LENGTH) |
53 | |
private String descrFormatted; |
54 | |
|
55 | |
@Column(name = "DESCR_PLAIN", length = KSEntityConstants.EXTRA_LONG_TEXT_LENGTH) |
56 | |
private String descrPlain; |
57 | |
|
58 | |
@Column(name = "LPR_TRANS_TYPE", nullable=false) |
59 | |
private String lprTransType; |
60 | |
|
61 | |
@Column(name = "LRP_TRANS_STATE", nullable=false) |
62 | |
private String lprTransState; |
63 | |
|
64 | |
@OneToMany(cascade = CascadeType.ALL, mappedBy = "owner") |
65 | |
private List<LprTransactionAttributeEntity> attributes; |
66 | |
|
67 | |
@OneToMany(cascade = CascadeType.ALL, mappedBy="owner") |
68 | |
private List<LprTransactionItemEntity> lprTransactionItems; |
69 | |
|
70 | |
|
71 | 0 | public LprTransactionEntity() {} |
72 | |
|
73 | |
public LprTransactionEntity(LprTransaction lprTransaction) { |
74 | 0 | super(lprTransaction); |
75 | |
|
76 | |
|
77 | 0 | this.setId(lprTransaction.getId()); |
78 | 0 | this.setLprTransType(lprTransaction.getTypeKey()); |
79 | |
|
80 | 0 | this.fromDto(lprTransaction); |
81 | 0 | } |
82 | |
|
83 | |
@SuppressWarnings("unchecked") |
84 | |
public List<Object>fromDto (LprTransaction lprTransaction) { |
85 | |
|
86 | 0 | List<Object>orphanList = new ArrayList<Object>(); |
87 | |
|
88 | 0 | this.setName(lprTransaction.getName()); |
89 | |
|
90 | 0 | this.setRequestingPersonId(lprTransaction.getRequestingPersonId()); |
91 | 0 | this.setAtpId(lprTransaction.getAtpId()); |
92 | |
|
93 | 0 | this.setLprTransState(lprTransaction.getStateKey()); |
94 | |
|
95 | |
|
96 | 0 | if (lprTransaction.getDescr() != null) { |
97 | 0 | this.setDescrFormatted(lprTransaction.getDescr().getFormatted()); |
98 | 0 | this.setDescrPlain(lprTransaction.getDescr().getPlain()); |
99 | |
} else { |
100 | 0 | this.setDescrFormatted(null); |
101 | 0 | this.setDescrPlain(null); |
102 | |
} |
103 | |
|
104 | |
|
105 | 0 | EntityMergeHelper<LprTransactionAttributeEntity, Attribute>attributeMergeHelper = new EntityMergeHelper<LprTransactionAttributeEntity, Attribute>(); |
106 | |
|
107 | 0 | EntityMergeResult<LprTransactionAttributeEntity> attributeMergeResults = attributeMergeHelper.merge(this.attributes, (List<Attribute>) lprTransaction.getAttributes(), new EntityMergeHelper.EntityMergeOptions<LprTransactionAttributeEntity, Attribute>() { |
108 | |
|
109 | |
@Override |
110 | |
public String getEntityId(LprTransactionAttributeEntity entity) { |
111 | 0 | return entity.getId(); |
112 | |
} |
113 | |
|
114 | |
@Override |
115 | |
public String getInfoId(Attribute info) { |
116 | 0 | return info.getId(); |
117 | |
} |
118 | |
|
119 | |
@Override |
120 | |
public List<Object> merge(LprTransactionAttributeEntity entity, |
121 | |
Attribute info) { |
122 | |
|
123 | 0 | entity.fromDto(info); |
124 | |
|
125 | 0 | entity.setOwner(LprTransactionEntity.this); |
126 | |
|
127 | 0 | return new ArrayList<Object>(); |
128 | |
} |
129 | |
|
130 | |
@Override |
131 | |
public LprTransactionAttributeEntity create(Attribute att) { |
132 | 0 | LprTransactionAttributeEntity attr = new LprTransactionAttributeEntity(att); |
133 | |
|
134 | 0 | attr.setOwner(LprTransactionEntity.this); |
135 | |
|
136 | 0 | return attr; |
137 | |
|
138 | |
} |
139 | |
|
140 | |
}); |
141 | |
|
142 | 0 | this.setAttributes(attributeMergeResults.getMergedList()); |
143 | |
|
144 | 0 | orphanList.addAll(attributeMergeResults.getOrphanList()); |
145 | |
|
146 | |
|
147 | 0 | EntityMergeHelper<LprTransactionItemEntity, LprTransactionItem>transactionItemMergeHelper = new EntityMergeHelper<LprTransactionItemEntity, LprTransactionItem>(); |
148 | |
|
149 | 0 | EntityMergeResult<LprTransactionItemEntity> transactionItemMergeResult = transactionItemMergeHelper.merge(this.lprTransactionItems, (List<LprTransactionItem>) lprTransaction.getLprTransactionItems(), new EntityMergeHelper.EntityMergeOptions<LprTransactionItemEntity, LprTransactionItem>() { |
150 | |
|
151 | |
@Override |
152 | |
public String getEntityId(LprTransactionItemEntity entity) { |
153 | 0 | return entity.getId(); |
154 | |
} |
155 | |
|
156 | |
@Override |
157 | |
public String getInfoId(LprTransactionItem info) { |
158 | 0 | return info.getId(); |
159 | |
} |
160 | |
|
161 | |
@Override |
162 | |
public List<Object> merge(LprTransactionItemEntity entity, |
163 | |
LprTransactionItem info) { |
164 | |
|
165 | 0 | List<Object>orphanList = entity.fromDto(info); |
166 | |
|
167 | 0 | entity.setOwner(LprTransactionEntity.this); |
168 | |
|
169 | 0 | return orphanList; |
170 | |
} |
171 | |
|
172 | |
@Override |
173 | |
public LprTransactionItemEntity create(LprTransactionItem info) { |
174 | 0 | LprTransactionItemEntity lprTransactionItemEntity = new LprTransactionItemEntity(info); |
175 | |
|
176 | 0 | lprTransactionItemEntity.setOwner(LprTransactionEntity.this); |
177 | |
|
178 | 0 | return lprTransactionItemEntity; |
179 | |
} |
180 | |
|
181 | |
}); |
182 | |
|
183 | 0 | this.setLprTransactionItems(transactionItemMergeResult.getMergedList()); |
184 | |
|
185 | 0 | orphanList.addAll(transactionItemMergeResult.getOrphanList()); |
186 | |
|
187 | 0 | return orphanList; |
188 | |
} |
189 | |
|
190 | |
|
191 | |
public LprTransactionInfo toDto() { |
192 | |
|
193 | 0 | LprTransactionInfo lpr = new LprTransactionInfo(); |
194 | 0 | lpr.setId(getId()); |
195 | |
|
196 | 0 | if (this.getLprTransType() != null) |
197 | 0 | lpr.setTypeKey(this.getLprTransType()); |
198 | 0 | if (this.getLprTransState() != null) |
199 | 0 | lpr.setStateKey(this.getLprTransState()); |
200 | |
|
201 | 0 | lpr.setMeta(super.toDTO()); |
202 | |
|
203 | 0 | if (getAttributes() != null) { |
204 | 0 | List<AttributeInfo> atts = new ArrayList<AttributeInfo>(); |
205 | 0 | for (LprTransactionAttributeEntity att : getAttributes()) { |
206 | 0 | AttributeInfo attInfo = att.toDto(); |
207 | 0 | atts.add(attInfo); |
208 | 0 | } |
209 | 0 | lpr.setAttributes(atts); |
210 | |
} |
211 | |
|
212 | 0 | lpr.setDescr(new RichTextHelper().toRichTextInfo(getDescrPlain(), getDescrFormatted())); |
213 | |
|
214 | 0 | lpr.setName(getName()); |
215 | 0 | lpr.setRequestingPersonId(getRequestingPersonId()); |
216 | 0 | lpr.setAtpId(getAtpId()); |
217 | 0 | List<LprTransactionItemInfo> lprItemsInfo = new ArrayList<LprTransactionItemInfo>(); |
218 | 0 | if (lprTransactionItems != null) { |
219 | 0 | for (LprTransactionItemEntity lprItemEntity : lprTransactionItems) { |
220 | 0 | lprItemsInfo.add(lprItemEntity.toDto()); |
221 | |
} |
222 | |
} |
223 | 0 | lpr.setLprTransactionItems(lprItemsInfo); |
224 | 0 | return lpr; |
225 | |
|
226 | |
} |
227 | |
|
228 | |
public String getName() { |
229 | 0 | return name; |
230 | |
} |
231 | |
|
232 | |
public void setName(String name) { |
233 | 0 | this.name = name; |
234 | 0 | } |
235 | |
|
236 | |
public String getLprTransType() { |
237 | 0 | return lprTransType; |
238 | |
} |
239 | |
|
240 | |
public void setLprTransType(String lprTransType) { |
241 | 0 | this.lprTransType = lprTransType; |
242 | 0 | } |
243 | |
|
244 | |
public String getLprTransState() { |
245 | 0 | return lprTransState; |
246 | |
} |
247 | |
|
248 | |
public void setLprTransState(String lprTransState) { |
249 | 0 | this.lprTransState = lprTransState; |
250 | 0 | } |
251 | |
|
252 | |
public String getRequestingPersonId() { |
253 | 0 | return requestingPersonId; |
254 | |
} |
255 | |
|
256 | |
public void setRequestingPersonId(String requestingPersonId) { |
257 | 0 | this.requestingPersonId = requestingPersonId; |
258 | 0 | } |
259 | |
|
260 | |
public String getAtpId() { |
261 | 0 | return atpId; |
262 | |
} |
263 | |
|
264 | |
public void setAtpId(String atpId) { |
265 | 0 | this.atpId = atpId; |
266 | 0 | } |
267 | |
|
268 | |
|
269 | |
|
270 | |
public List<LprTransactionItemEntity> getLprTransactionItems() { |
271 | 0 | return lprTransactionItems; |
272 | |
} |
273 | |
|
274 | |
public void setLprTransactionItems(List<LprTransactionItemEntity> lprTransactionItems) { |
275 | 0 | this.lprTransactionItems = lprTransactionItems; |
276 | 0 | } |
277 | |
|
278 | |
public void setAttributes(List<LprTransactionAttributeEntity> attributes) { |
279 | 0 | this.attributes = attributes; |
280 | 0 | } |
281 | |
|
282 | |
public List<LprTransactionAttributeEntity> getAttributes() { |
283 | 0 | return this.attributes; |
284 | |
} |
285 | |
|
286 | |
public String getDescrFormatted() { |
287 | 0 | return descrFormatted; |
288 | |
} |
289 | |
|
290 | |
public void setDescrFormatted(String descrFormatted) { |
291 | 0 | this.descrFormatted = descrFormatted; |
292 | 0 | } |
293 | |
|
294 | |
public String getDescrPlain() { |
295 | 0 | return descrPlain; |
296 | |
} |
297 | |
|
298 | |
public void setDescrPlain(String descrPlain) { |
299 | 0 | this.descrPlain = descrPlain; |
300 | 0 | } |
301 | |
|
302 | |
@Override |
303 | |
public String toString() { |
304 | 0 | StringBuilder builder = new StringBuilder(); |
305 | 0 | builder.append("LprTransactionEntity [version="); |
306 | 0 | builder.append(getVersionNumber()); |
307 | 0 | builder.append(", id="); |
308 | 0 | builder.append(getId()); |
309 | 0 | builder.append(", name="); |
310 | 0 | builder.append(name); |
311 | 0 | builder.append(", requestingPersonId="); |
312 | 0 | builder.append(requestingPersonId); |
313 | 0 | builder.append(", atpId="); |
314 | 0 | builder.append(atpId); |
315 | 0 | builder.append(", lprTransType="); |
316 | 0 | builder.append(lprTransType); |
317 | 0 | builder.append(", lprTransState="); |
318 | 0 | builder.append(lprTransState); |
319 | 0 | builder.append("]"); |
320 | 0 | return builder.toString(); |
321 | |
} |
322 | |
|
323 | |
|
324 | |
} |