1 | |
package org.kuali.student.r2.core.class1.atp.model; |
2 | |
|
3 | |
import org.kuali.student.common.entity.KSEntityConstants; |
4 | |
import org.kuali.student.r2.common.dto.AttributeInfo; |
5 | |
import org.kuali.student.r2.common.entity.MetaEntity; |
6 | |
import org.kuali.student.r2.common.infc.Attribute; |
7 | |
import org.kuali.student.r2.common.util.RichTextHelper; |
8 | |
import org.kuali.student.r2.core.atp.dto.AtpInfo; |
9 | |
import org.kuali.student.r2.core.atp.infc.Atp; |
10 | |
|
11 | |
import javax.persistence.CascadeType; |
12 | |
import javax.persistence.Column; |
13 | |
import javax.persistence.Entity; |
14 | |
import javax.persistence.OneToMany; |
15 | |
import javax.persistence.Table; |
16 | |
import javax.persistence.Temporal; |
17 | |
import javax.persistence.TemporalType; |
18 | |
import java.util.ArrayList; |
19 | |
import java.util.Date; |
20 | |
import java.util.List; |
21 | |
|
22 | |
@Entity |
23 | |
@Table(name = "KSEN_ATP") |
24 | |
public class AtpEntity extends MetaEntity { |
25 | |
|
26 | |
@Column(name = "NAME") |
27 | |
private String name; |
28 | |
@Column(name = "ADMIN_ORG_ID") |
29 | |
private String adminOrgId; |
30 | |
@Column(name = "ATP_CD") |
31 | |
private String atpCode; |
32 | |
@Temporal(TemporalType.TIMESTAMP) |
33 | |
@Column(name = "START_DT", nullable = false) |
34 | |
private Date startDate; |
35 | |
@Temporal(TemporalType.TIMESTAMP) |
36 | |
@Column(name = "END_DT", nullable = false) |
37 | |
private Date endDate; |
38 | |
@Column(name = "DESCR_FORMATTED", length = KSEntityConstants.EXTRA_LONG_TEXT_LENGTH) |
39 | |
private String formatted; |
40 | |
@Column(name = "DESCR_PLAIN", length = KSEntityConstants.EXTRA_LONG_TEXT_LENGTH, nullable = false) |
41 | |
private String plain; |
42 | |
@Column(name = "ATP_TYPE", nullable = false) |
43 | |
private String atpType; |
44 | |
@Column(name = "ATP_STATE", nullable = false) |
45 | |
private String atpState; |
46 | 0 | @OneToMany(cascade = CascadeType.ALL, mappedBy = "owner") |
47 | |
private List<AtpAttributeEntity> attributes = new ArrayList<AtpAttributeEntity>(); |
48 | |
|
49 | 0 | public AtpEntity() { |
50 | 0 | } |
51 | |
|
52 | |
public AtpEntity(Atp atp) { |
53 | 0 | super(atp); |
54 | 0 | this.setId(atp.getId()); |
55 | 0 | this.setAtpType(atp.getTypeKey()); |
56 | 0 | this.fromDTO(atp); |
57 | 0 | } |
58 | |
|
59 | |
public void fromDTO(Atp atp) { |
60 | 0 | this.setAtpCode(atp.getCode()); |
61 | 0 | this.setName(atp.getName()); |
62 | 0 | if (atp.getDescr() != null) { |
63 | 0 | this.setDescrFormatted(atp.getDescr().getFormatted()); |
64 | 0 | this.setDescrPlain(atp.getDescr().getPlain()); |
65 | |
} else { |
66 | 0 | this.setDescrFormatted(null); |
67 | 0 | this.setDescrPlain(null); |
68 | |
} |
69 | 0 | this.setAdminOrgId(atp.getAdminOrgId()); |
70 | 0 | this.setAtpState(atp.getStateKey()); |
71 | 0 | this.setStartDate(atp.getStartDate()); |
72 | 0 | this.setEndDate(atp.getEndDate()); |
73 | 0 | this.setAttributes(new ArrayList<AtpAttributeEntity>()); |
74 | 0 | for (Attribute att : atp.getAttributes()) { |
75 | 0 | this.getAttributes().add(new AtpAttributeEntity(att, this)); |
76 | |
} |
77 | 0 | } |
78 | |
|
79 | |
public String getName() { |
80 | 0 | return name; |
81 | |
} |
82 | |
|
83 | |
public void setName(String name) { |
84 | 0 | this.name = name; |
85 | 0 | } |
86 | |
|
87 | |
public Date getStartDate() { |
88 | 0 | return startDate; |
89 | |
} |
90 | |
|
91 | |
public void setStartDate(Date startDate) { |
92 | 0 | this.startDate = startDate; |
93 | 0 | } |
94 | |
|
95 | |
public Date getEndDate() { |
96 | 0 | return endDate; |
97 | |
} |
98 | |
|
99 | |
public void setEndDate(Date endDate) { |
100 | 0 | this.endDate = endDate; |
101 | 0 | } |
102 | |
|
103 | |
public String getAtpType() { |
104 | 0 | return atpType; |
105 | |
} |
106 | |
|
107 | |
public void setAtpType(String atpType) { |
108 | 0 | this.atpType = atpType; |
109 | 0 | } |
110 | |
|
111 | |
public String getAtpState() { |
112 | 0 | return atpState; |
113 | |
} |
114 | |
|
115 | |
public void setAtpState(String atpState) { |
116 | 0 | this.atpState = atpState; |
117 | 0 | } |
118 | |
|
119 | |
public void setAttributes(List<AtpAttributeEntity> attributes) { |
120 | 0 | this.attributes = attributes; |
121 | |
|
122 | 0 | } |
123 | |
|
124 | |
public List<AtpAttributeEntity> getAttributes() { |
125 | 0 | return attributes; |
126 | |
} |
127 | |
|
128 | |
public String getAdminOrgId() { |
129 | 0 | return adminOrgId; |
130 | |
} |
131 | |
|
132 | |
public void setAdminOrgId(String adminOrgId) { |
133 | 0 | this.adminOrgId = adminOrgId; |
134 | 0 | } |
135 | |
|
136 | |
public AtpInfo toDto() { |
137 | 0 | AtpInfo atp = new AtpInfo(); |
138 | 0 | atp.setId(getId()); |
139 | 0 | atp.setCode(atpCode); |
140 | 0 | atp.setName(name); |
141 | 0 | atp.setStartDate(startDate); |
142 | 0 | atp.setEndDate(endDate); |
143 | 0 | atp.setAdminOrgId(getAdminOrgId()); |
144 | 0 | atp.setTypeKey(atpType); |
145 | 0 | atp.setStateKey(atpState); |
146 | 0 | atp.setMeta(super.toDTO()); |
147 | 0 | atp.setDescr(new RichTextHelper().toRichTextInfo(getDescrPlain(), getDescrFormatted())); |
148 | 0 | if (getAttributes() != null) { |
149 | 0 | for (AtpAttributeEntity att : getAttributes()) { |
150 | 0 | AttributeInfo attInfo = att.toDto(); |
151 | 0 | atp.getAttributes().add(attInfo); |
152 | 0 | } |
153 | |
} |
154 | |
|
155 | 0 | return atp; |
156 | |
} |
157 | |
|
158 | |
public String getDescrFormatted() { |
159 | 0 | return formatted; |
160 | |
} |
161 | |
|
162 | |
public void setDescrFormatted(String formatted) { |
163 | 0 | this.formatted = formatted; |
164 | 0 | } |
165 | |
|
166 | |
public String getDescrPlain() { |
167 | 0 | return plain; |
168 | |
} |
169 | |
|
170 | |
public void setDescrPlain(String plain) { |
171 | 0 | this.plain = plain; |
172 | 0 | } |
173 | |
|
174 | |
public String getAtpCode() { |
175 | 0 | return atpCode; |
176 | |
} |
177 | |
|
178 | |
public void setAtpCode(String atpCode) { |
179 | 0 | this.atpCode = atpCode; |
180 | 0 | } |
181 | |
} |