View Javadoc

1   /**
2    * Copyright 2012 The Kuali Foundation
3    *
4    * Licensed under the the Educational Community License, Version 1.0
5    * (the "License"); you may not use this file except in compliance
6    * with the License.  You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl1.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
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 		this.setNewLuiId(lprTransactionItem.getNewLuiId());
119 		this.setExistingLuiId(lprTransactionItem.getExistingLuiId());
120 		this.setPersonId(lprTransactionItem.getPersonId());
121 		
122 		this.setLprTransactionItemState(lprTransactionItem.getStateKey());
123 		this.setLprTransactionItemType(lprTransactionItem.getTypeKey());
124 		
125 		if (lprTransactionItem.getDescr() != null) {
126 			this.setDescrFormatted(lprTransactionItem.getDescr()
127 					.getFormatted());
128 			this.setDescrPlain(lprTransactionItem.getDescr().getPlain());
129 		} else {
130 			this.setDescrFormatted(null);
131 			this.setDescrPlain(null);
132 		}
133 		
134 		if (lprTransactionItem.getLprTransactionItemResult() != null) {
135 			this.setResultingLprId(lprTransactionItem
136 					.getLprTransactionItemResult().getResultingLprId());
137 			this.setStatus(lprTransactionItem.getLprTransactionItemResult()
138 					.getStatus() ? "Y" : "N");
139 		}
140 
141 		
142 		this.attributes.clear();
143 		
144 		for (Attribute attr : lprTransactionItem.getAttributes()) {
145 			
146 			this.attributes.add(new LprTransactionItemAttributeEntity(attr, this));
147 		}
148 		
149 		this.requestOptions.clear();
150 		
151 		for (LprTransactionItemRequestOption requestOption : lprTransactionItem.getRequestOptions()) {
152 		
153 			this.requestOptions.add(new LprTransactionItemRequestOptionEntity(requestOption));
154 			
155 		}
156 		
157 		this.resultValueGroupIds.clear();
158 		
159 		this.resultValueGroupIds.addAll(lprTransactionItem.getResultValuesGroupKeys());
160 		
161 		
162 	}
163 
164 	public LprTransactionItemInfo toDto() {
165 
166 		LprTransactionItemInfo lprTransItemInfo = new LprTransactionItemInfo();
167 		lprTransItemInfo.setId(getId());
168 
169 		lprTransItemInfo.setTypeKey(this.getLprTransactionItemType());
170 		lprTransItemInfo.setStateKey(this.getLprTransactionItemState());
171 		lprTransItemInfo.setExistingLuiId(this.getExistingLuiId());
172 		lprTransItemInfo.setNewLuiId(this.getNewLuiId());
173 		lprTransItemInfo.setPersonId(this.getPersonId());
174 		
175 		if (this.owner != null)
176 			lprTransItemInfo.setTransactionId(this.owner.getId());
177 		else
178 			lprTransItemInfo.setTransactionId(null);
179 		
180 		lprTransItemInfo.setMeta(super.toDTO());
181 		
182 		lprTransItemInfo.setDescr(new RichTextHelper().toRichTextInfo(
183 				getDescrPlain(), getDescrFormatted()));
184 		
185 		if (getAttributes() != null) {
186 			List<AttributeInfo> atts = new ArrayList<AttributeInfo>();
187 			for (LprTransactionItemAttributeEntity att : getAttributes()) {
188 				AttributeInfo attInfo = att.toDto();
189 				atts.add(attInfo);
190 			}
191 			lprTransItemInfo.setAttributes(atts);
192 		}
193 		
194 		Set<LprTransactionItemRequestOptionEntity> requestOptionsList = getRequestOptions();
195 		
196 		if (requestOptionsList != null) {
197 			
198 			List<LprTransactionItemRequestOptionInfo> rOptions = new ArrayList<LprTransactionItemRequestOptionInfo>();
199 		
200 			for (LprTransactionItemRequestOptionEntity lprTransactionItemRequestOptionEntity : requestOptionsList) {
201 				
202 				rOptions.add(lprTransactionItemRequestOptionEntity.toDto());
203 			}
204 			
205 			lprTransItemInfo.setRequestOptions(rOptions);
206 		}
207 		else {
208 			lprTransItemInfo.setRequestOptions(new ArrayList<LprTransactionItemRequestOptionInfo>());
209 		}
210 		
211 
212 		List<String> resultValueGroupKeys = new ArrayList<String> (getResultValueGroupIds().size());
213 		
214 		lprTransItemInfo.setResultValuesGroupKeys(resultValueGroupKeys);
215 		
216 		if (this.getResultingLprId() != null && this.getStatus() != null) {
217 			// only record the details if the values are not null
218 			LprTransactionItemResultInfo lprItemResult = new LprTransactionItemResultInfo();
219 
220 			lprItemResult.setResultingLprId(this.getResultingLprId());
221 			lprItemResult.setStatus(Boolean.valueOf(
222 					"Y".equals(this.getStatus()) ? true : false));
223 			lprTransItemInfo.setLprTransactionItemResult(lprItemResult);
224 		}
225 		return lprTransItemInfo;
226 
227 	}
228 
229 	public String getDescrFormatted() {
230 		return descrFormatted;
231 	}
232 
233 	public void setDescrFormatted(String descrFormatted) {
234 		this.descrFormatted = descrFormatted;
235 	}
236 	public String getDescrPlain() {
237 		return descrPlain;
238 	}
239 
240 	public void setDescrPlain(String descrPlain) {
241 		this.descrPlain = descrPlain;
242 	}
243 
244 	public String getResultingLprId() {
245 		return resultingLprId;
246 	}
247 
248 	public void setResultingLprId(String resultingLprId) {
249 		this.resultingLprId = resultingLprId;
250 	}
251 
252 	public String getPersonId() {
253 		return personId;
254 	}
255 
256 	public String getGroupId() {
257 		return groupId;
258 	}
259 
260 	public void setGroupId(String groupId) {
261 		this.groupId = groupId;
262 	}
263 
264 	public void setPersonId(String personId) {
265 		this.personId = personId;
266 	}
267 
268 	public String getNewLuiId() {
269 		return newLuiId;
270 	}
271 
272 	public String getStatus() {
273 		return status;
274 	}
275 
276 	public void setStatus(String status) {
277 		this.status = status;
278 	}
279 
280 	public void setNewLuiId(String newLuiId) {
281 		this.newLuiId = newLuiId;
282 	}
283 
284 	public String getExistingLuiId() {
285 		return existingLuiId;
286 	}
287 
288 	public void setExistingLuiId(String existingLuiId) {
289 		this.existingLuiId = existingLuiId;
290 	}
291 
292 	public String getLprTransactionItemType() {
293 		return lprTransactionItemType;
294 	}
295 
296 	public void setLprTransactionItemType(String lprTransactionType) {
297 		this.lprTransactionItemType = lprTransactionType;
298 	}
299 
300 	public String getLprTransactionItemState() {
301 		return lprTransactionItemState;
302 	}
303 
304 	public void setLprTransactionItemState(String lprTransactionState) {
305 		this.lprTransactionItemState = lprTransactionState;
306 	}
307 
308 	public Set<LprTransactionItemAttributeEntity> getAttributes() {
309 		return attributes;
310 	}
311 
312 	public void setAttributes(Set<LprTransactionItemAttributeEntity> attributes) {
313 		
314 		this.attributes.clear();
315 		
316 		if (attributes != null)
317 			this.attributes.addAll(attributes);
318 	}
319 
320 	public String getResultMessage() {
321 		return resultMessage;
322 	}
323 
324 	public void setResultMessage(String resultMessage) {
325 		this.resultMessage = resultMessage;
326 	}
327 
328 	public String getName() {
329 		return name;
330 	}
331 
332 	public void setName(String name) {
333 		this.name = name;
334 	}
335 
336 	public LprTransactionEntity getOwner() {
337 		return owner;
338 	}
339 
340 	public void setOwner(LprTransactionEntity owner) {
341 		this.owner = owner;
342 	}
343 
344 	public Set<LprTransactionItemRequestOptionEntity> getRequestOptions() {
345 		return requestOptions;
346 	}
347 
348 	public void setRequestOptions(
349 			Set<LprTransactionItemRequestOptionEntity> requestOptions) {
350 		this.requestOptions.clear();
351 		
352 		if (requestOptions != null)
353 			this.requestOptions.addAll(requestOptions);
354 	}
355 
356 	
357 
358 	public Set<String> getResultValueGroupIds() {
359 		return resultValueGroupIds;
360 	}
361 
362 	public void setResultValueGroupIds(Set<String> resultValueGroupIds) {
363 		this.resultValueGroupIds.clear();
364 		
365 		if (resultValueGroupIds != null) {
366 			this.resultValueGroupIds.addAll(resultValueGroupIds);
367 		}
368 	}
369 
370 	@Override
371 	public String toString() {
372 		StringBuilder builder = new StringBuilder();
373 		builder.append("LprTransactionItemEntity [id=");
374 		builder.append(getId());
375 		builder.append(", personId=");
376 		builder.append(personId);
377 		builder.append(", newLuiId=");
378 		builder.append(newLuiId);
379 		builder.append(", existingLuiId=");
380 		builder.append(existingLuiId);
381 		builder.append(", resultingLprId=");
382 		builder.append(resultingLprId);
383 		builder.append(", groupId=");
384 		builder.append(groupId);
385 		builder.append(", lprTransactionItemType=");
386 		builder.append(lprTransactionItemType);
387 		builder.append(", lprTransactionItemState=");
388 		builder.append(lprTransactionItemState);
389 		builder.append("]");
390 		return builder.toString();
391 	}
392 	
393 	
394 
395 }