1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.kuali.student.r2.core.class1.enumerationmanagement.model; |
17 | |
|
18 | |
import java.util.ArrayList; |
19 | |
import java.util.Date; |
20 | |
import java.util.List; |
21 | |
|
22 | |
import javax.persistence.CascadeType; |
23 | |
import javax.persistence.Column; |
24 | |
import javax.persistence.Entity; |
25 | |
import javax.persistence.FetchType; |
26 | |
import javax.persistence.JoinColumn; |
27 | |
import javax.persistence.JoinTable; |
28 | |
import javax.persistence.ManyToMany; |
29 | |
import javax.persistence.ManyToOne; |
30 | |
import javax.persistence.Table; |
31 | |
import javax.persistence.Temporal; |
32 | |
import javax.persistence.TemporalType; |
33 | |
|
34 | |
import org.kuali.student.r2.common.entity.MetaEntity; |
35 | |
import org.kuali.student.r2.core.enumerationmanagement.dto.EnumContextValueInfo; |
36 | |
import org.kuali.student.r2.core.enumerationmanagement.dto.EnumeratedValueInfo; |
37 | |
import org.kuali.student.r2.core.enumerationmanagement.infc.EnumContextValue; |
38 | |
import org.kuali.student.r2.core.enumerationmanagement.infc.EnumeratedValue; |
39 | |
|
40 | |
@Entity |
41 | |
@Table(name = "KSEN_ENUM_VAL_T") |
42 | |
public class EnumeratedValueEntity extends MetaEntity{ |
43 | |
|
44 | |
@Column(name = "CD") |
45 | |
private String code; |
46 | |
|
47 | |
@Column(name = "ABBREV_VAL") |
48 | |
private String abbrevValue; |
49 | |
|
50 | |
@Column(name = "VAL") |
51 | |
private String value; |
52 | |
|
53 | |
@ManyToOne(cascade = {CascadeType.PERSIST, CascadeType.MERGE}, targetEntity = EnumerationEntity.class) |
54 | |
@JoinColumn(name = "ENUM_KEY") |
55 | |
private EnumerationEntity enumeration; |
56 | |
|
57 | |
@Column(name = "SORT_KEY") |
58 | |
private String sortKey; |
59 | |
|
60 | |
@Temporal(TemporalType.TIMESTAMP) |
61 | |
@Column(name = "EFF_DT") |
62 | |
private Date effectiveDate; |
63 | |
|
64 | |
@Temporal(TemporalType.TIMESTAMP) |
65 | |
@Column(name = "EXPIR_DT") |
66 | |
private Date expirationDate; |
67 | |
|
68 | 0 | @ManyToMany(fetch = FetchType.LAZY, cascade = CascadeType.ALL) |
69 | |
@JoinTable(name = "KSEM_CTX_JN_ENUM_VAL_T", joinColumns = @JoinColumn(name = "ENUM_VAL_ID", referencedColumnName = "ID"), inverseJoinColumns = @JoinColumn(name = "CTX_ID", referencedColumnName = "ID")) |
70 | |
List<EnumContextValueEntity> contextValueEntities = new ArrayList<EnumContextValueEntity>(); |
71 | |
|
72 | 0 | public EnumeratedValueEntity() { |
73 | 0 | } |
74 | |
|
75 | |
public EnumeratedValueEntity(EnumeratedValue enumeratedValue) { |
76 | 0 | super(enumeratedValue); |
77 | 0 | this.setCode(enumeratedValue.getCode()); |
78 | 0 | this.setAbbrevValue(enumeratedValue.getAbbrevValue()); |
79 | 0 | this.setValue(enumeratedValue.getValue()); |
80 | 0 | this.setSortKey(enumeratedValue.getSortKey()); |
81 | |
|
82 | 0 | this.setContextValueEntities(new ArrayList<EnumContextValueEntity>()); |
83 | 0 | if (null != enumeratedValue.getContexts()) { |
84 | 0 | for (EnumContextValue context : enumeratedValue.getContexts()) { |
85 | 0 | this.getContextValueEntities().add(new EnumContextValueEntity(context)); |
86 | |
} |
87 | |
} |
88 | |
|
89 | 0 | this.setEffectiveDate(enumeratedValue.getEffectiveDate()); |
90 | 0 | this.setExpirationDate(enumeratedValue.getExpirationDate()); |
91 | 0 | } |
92 | |
|
93 | |
public String getCode() { |
94 | 0 | return code; |
95 | |
} |
96 | |
|
97 | |
public void setCode(String code) { |
98 | 0 | this.code = code; |
99 | 0 | } |
100 | |
|
101 | |
public String getAbbrevValue() { |
102 | 0 | return abbrevValue; |
103 | |
} |
104 | |
|
105 | |
public void setAbbrevValue(String abbrevValue) { |
106 | 0 | this.abbrevValue = abbrevValue; |
107 | 0 | } |
108 | |
|
109 | |
public String getValue() { |
110 | 0 | return value; |
111 | |
} |
112 | |
|
113 | |
public void setValue(String value) { |
114 | 0 | this.value = value; |
115 | 0 | } |
116 | |
|
117 | |
public String getSortKey() { |
118 | 0 | return sortKey; |
119 | |
} |
120 | |
|
121 | |
public void setSortKey(String sortKey) { |
122 | 0 | this.sortKey = sortKey; |
123 | 0 | } |
124 | |
|
125 | |
public List<EnumContextValueEntity> getContextValueEntities() { |
126 | 0 | return contextValueEntities; |
127 | |
} |
128 | |
|
129 | |
public void setContextValueEntities(List<EnumContextValueEntity> contextValueEntities) { |
130 | 0 | this.contextValueEntities = contextValueEntities; |
131 | 0 | } |
132 | |
|
133 | |
public EnumerationEntity getEnumeration() { |
134 | 0 | return enumeration; |
135 | |
} |
136 | |
|
137 | |
public void setEnumeration(EnumerationEntity enumeration) { |
138 | 0 | this.enumeration = enumeration; |
139 | 0 | } |
140 | |
|
141 | |
public Date getEffectiveDate() { |
142 | 0 | return effectiveDate; |
143 | |
} |
144 | |
|
145 | |
public void setEffectiveDate(Date effectiveDate) { |
146 | 0 | this.effectiveDate = effectiveDate; |
147 | 0 | } |
148 | |
|
149 | |
public Date getExpirationDate() { |
150 | 0 | return expirationDate; |
151 | |
} |
152 | |
|
153 | |
public void setExpirationDate(Date expirationDate) { |
154 | 0 | this.expirationDate = expirationDate; |
155 | 0 | } |
156 | |
|
157 | |
public EnumeratedValueInfo toDto() { |
158 | 0 | EnumeratedValueInfo enumeratedValue = new EnumeratedValueInfo(); |
159 | 0 | enumeratedValue.setCode(this.getCode()); |
160 | 0 | enumeratedValue.setAbbrevValue(this.getAbbrevValue()); |
161 | 0 | enumeratedValue.setValue(this.getValue()); |
162 | 0 | enumeratedValue.setSortKey(this.getSortKey()); |
163 | 0 | enumeratedValue.setMeta(super.toDTO()); |
164 | |
|
165 | 0 | List<EnumContextValueInfo> contextInfos = new ArrayList<EnumContextValueInfo>(); |
166 | 0 | for (EnumContextValueEntity contexts : getContextValueEntities()) { |
167 | 0 | EnumContextValueInfo contextInfo = contexts.toDto(); |
168 | 0 | contextInfos.add(contextInfo); |
169 | 0 | } |
170 | 0 | enumeratedValue.setContexts(contextInfos); |
171 | |
|
172 | 0 | enumeratedValue.setEnumerationKey(this.getEnumeration().getId()); |
173 | |
|
174 | 0 | enumeratedValue.setEffectiveDate(this.getEffectiveDate()); |
175 | 0 | enumeratedValue.setExpirationDate(this.getExpirationDate()); |
176 | |
|
177 | 0 | return enumeratedValue; |
178 | |
} |
179 | |
|
180 | |
} |