1 | |
package org.kuali.student.enrollment.class1.lrr.model; |
2 | |
|
3 | |
import org.kuali.student.enrollment.lrr.dto.LearningResultRecordInfo; |
4 | |
import org.kuali.student.enrollment.lrr.infc.LearningResultRecord; |
5 | |
import org.kuali.student.r2.common.dto.AttributeInfo; |
6 | |
import org.kuali.student.r2.common.entity.AttributeOwner; |
7 | |
import org.kuali.student.r2.common.entity.MetaEntity; |
8 | |
import org.kuali.student.r2.common.infc.Attribute; |
9 | |
|
10 | |
import javax.persistence.*; |
11 | |
import java.util.ArrayList; |
12 | |
import java.util.List; |
13 | |
|
14 | |
@Entity |
15 | |
@Table(name = "KSEN_LRR") |
16 | |
public class LearningResultRecordEntity extends MetaEntity implements AttributeOwner<LrrAttributeEntity> { |
17 | |
|
18 | |
@Column(name = "NAME") |
19 | |
private String name; |
20 | |
|
21 | |
@ManyToOne(cascade = CascadeType.ALL) |
22 | |
@JoinColumn(name = "RT_DESCR_ID") |
23 | |
private LrrRichTextEntity descr; |
24 | |
|
25 | |
@Column(name = "TYPE_ID") |
26 | |
private String lrrType; |
27 | |
|
28 | |
@Column(name = "STATE_ID") |
29 | |
private String lrrState; |
30 | |
|
31 | |
@Column(name = "LPR_ID") |
32 | |
private String lprId; |
33 | |
|
34 | |
@Column(name = "RESULT_VALUE_ID") |
35 | |
private String resultValueId; |
36 | |
|
37 | |
@ManyToMany(cascade = CascadeType.ALL) |
38 | |
@JoinTable(name = "KSEN_LRR_RES_SRC_RELTN", joinColumns = @JoinColumn(name = "LRR_ID"), inverseJoinColumns = @JoinColumn(name = "RES_SRC_ID")) |
39 | |
private List<ResultSourceEntity> resultSourceList; |
40 | |
|
41 | |
@OneToMany(cascade = CascadeType.ALL, mappedBy = "owner") |
42 | |
private List<LrrAttributeEntity> attributes; |
43 | |
|
44 | 0 | public LearningResultRecordEntity() { |
45 | |
|
46 | 0 | } |
47 | |
|
48 | |
public LearningResultRecordEntity(LearningResultRecord dto) { |
49 | 0 | super(dto); |
50 | |
|
51 | 0 | this.setId(dto.getId()); |
52 | 0 | this.setName(dto.getName()); |
53 | 0 | this.setLprId(dto.getLprId()); |
54 | 0 | this.setResultValueId(dto.getResultValueKey()); |
55 | 0 | this.setLrrState(dto.getStateKey()); |
56 | 0 | this.setLrrType(dto.getTypeKey()); |
57 | 0 | if(dto.getDescr() != null){ |
58 | 0 | this.setDescr(new LrrRichTextEntity(dto.getDescr())); |
59 | |
} |
60 | |
|
61 | 0 | this.setAttributes(new ArrayList<LrrAttributeEntity>()); |
62 | 0 | if (null != dto.getAttributes()) { |
63 | 0 | for (Attribute att : dto.getAttributes()) { |
64 | 0 | this.getAttributes().add(new LrrAttributeEntity(att)); |
65 | |
} |
66 | |
} |
67 | 0 | } |
68 | |
|
69 | |
public String getName() { |
70 | 0 | return name; |
71 | |
} |
72 | |
|
73 | |
public void setName(String name) { |
74 | 0 | this.name = name; |
75 | 0 | } |
76 | |
|
77 | |
public LrrRichTextEntity getDescr() { |
78 | 0 | return descr; |
79 | |
} |
80 | |
|
81 | |
public void setDescr(LrrRichTextEntity descr) { |
82 | 0 | this.descr = descr; |
83 | 0 | } |
84 | |
|
85 | |
public String getLrrType() { |
86 | 0 | return lrrType; |
87 | |
} |
88 | |
|
89 | |
public void setLrrType(String lrrType) { |
90 | 0 | this.lrrType = lrrType; |
91 | 0 | } |
92 | |
|
93 | |
public String getLrrState() { |
94 | 0 | return lrrState; |
95 | |
} |
96 | |
|
97 | |
public void setLrrState(String lrrState) { |
98 | 0 | this.lrrState = lrrState; |
99 | 0 | } |
100 | |
|
101 | |
public String getLprId() { |
102 | 0 | return lprId; |
103 | |
} |
104 | |
|
105 | |
public void setLprId(String lprId) { |
106 | 0 | this.lprId = lprId; |
107 | 0 | } |
108 | |
|
109 | |
public String getResultValueId() { |
110 | 0 | return resultValueId; |
111 | |
} |
112 | |
|
113 | |
public void setResultValueId(String resultValueId) { |
114 | 0 | this.resultValueId = resultValueId; |
115 | 0 | } |
116 | |
|
117 | |
@Override |
118 | |
public void setAttributes(List<LrrAttributeEntity> attributes) { |
119 | 0 | this.attributes = attributes; |
120 | 0 | } |
121 | |
|
122 | |
@Override |
123 | |
public List<LrrAttributeEntity> getAttributes() { |
124 | 0 | if (attributes == null) { |
125 | 0 | attributes = new ArrayList<LrrAttributeEntity>(); |
126 | |
} |
127 | 0 | return attributes; |
128 | |
} |
129 | |
|
130 | |
public List<ResultSourceEntity> getResultSourceList() { |
131 | 0 | return resultSourceList; |
132 | |
} |
133 | |
|
134 | |
public void setResultSourceList(List<ResultSourceEntity> resultSourceList) { |
135 | 0 | this.resultSourceList = resultSourceList; |
136 | 0 | } |
137 | |
|
138 | |
public LearningResultRecordInfo toDto() { |
139 | |
|
140 | 0 | LearningResultRecordInfo info = new LearningResultRecordInfo(); |
141 | 0 | info.setId(getId()); |
142 | 0 | info.setLprId(lprId); |
143 | 0 | info.setName(getName()); |
144 | |
|
145 | 0 | if (getDescr() != null){ |
146 | 0 | info.setDescr(getDescr().toDto()); |
147 | |
} |
148 | |
|
149 | 0 | info.setResultValueKey(getResultValueId()); |
150 | |
|
151 | 0 | List<String> resSource = new ArrayList(); |
152 | 0 | for(ResultSourceEntity resultSourceEntity : getResultSourceList()){ |
153 | 0 | resSource.add(resultSourceEntity.getId()); |
154 | |
} |
155 | 0 | info.setResultSourceIds(resSource); |
156 | |
|
157 | 0 | if (getLrrState() != null){ |
158 | 0 | info.setStateKey(getLrrState()); |
159 | |
} |
160 | |
|
161 | 0 | if (getLrrType() != null){ |
162 | 0 | info.setTypeKey(getLrrType()); |
163 | |
} |
164 | |
|
165 | 0 | List<AttributeInfo> atts = new ArrayList<AttributeInfo>(); |
166 | 0 | for (LrrAttributeEntity att : getAttributes()) { |
167 | 0 | AttributeInfo attInfo = att.toDto(); |
168 | 0 | atts.add(attInfo); |
169 | 0 | } |
170 | 0 | info.setAttributes(atts); |
171 | 0 | info.setMeta(super.toDTO()); |
172 | |
|
173 | 0 | return info; |
174 | |
} |
175 | |
} |