1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.kuali.student.enrollment.class2.courseoffering.model;
18
19 import org.kuali.student.enrollment.courseoffering.dto.ActivityOfferingClusterInfo;
20 import org.kuali.student.enrollment.courseoffering.dto.ActivityOfferingSetInfo;
21 import org.kuali.student.enrollment.courseoffering.infc.ActivityOfferingCluster;
22 import org.kuali.student.enrollment.courseoffering.infc.ActivityOfferingSet;
23 import org.kuali.student.r1.common.entity.KSEntityConstants;
24 import org.kuali.student.r2.common.assembler.TransformUtility;
25 import org.kuali.student.r2.common.dto.AttributeInfo;
26 import org.kuali.student.r2.common.entity.AttributeOwner;
27 import org.kuali.student.r2.common.entity.MetaEntity;
28 import org.kuali.student.r2.common.util.RichTextHelper;
29
30 import javax.persistence.CascadeType;
31 import javax.persistence.Column;
32 import javax.persistence.Entity;
33 import javax.persistence.JoinColumn;
34 import javax.persistence.NamedQueries;
35 import javax.persistence.NamedQuery;
36 import javax.persistence.OneToMany;
37 import javax.persistence.Table;
38 import java.util.ArrayList;
39 import java.util.HashMap;
40 import java.util.HashSet;
41 import java.util.List;
42 import java.util.Map;
43 import java.util.Set;
44
45
46
47
48
49
50
51 @Entity
52 @Table(name = "KSEN_CO_AO_CLUSTER")
53 @NamedQueries({
54 @NamedQuery(name="ActivityOfferingClusterENR.getAOCsByIds", query="Select aoc from ActivityOfferingClusterEntity aoc where aoc.id in (:aocIds)"),
55 @NamedQuery(name="ActivityOfferingClusterENR.getAOCsByFormatOfferingIds", query="Select aoc from ActivityOfferingClusterEntity aoc where aoc.formatOfferingId in (:foIds)"),
56 @NamedQuery(name="ActivityOfferingClusterENR.getAOCsByCourseOfferingId", query="Select aoc from ActivityOfferingClusterEntity aoc, LuiLuiRelationEntity rel where rel.lui.id = :coId and rel.luiLuiRelationType = 'kuali.lui.lui.relation.type.deliveredvia.co2fo' and aoc.formatOfferingId = rel.relatedLui.id "),
57 @NamedQuery(name="ActivityOfferingClusterENR.getAOCsByActivityOfferingId", query="Select aoc from ActivityOfferingClusterEntity aoc, IN (aoc.aoSets) aocJoinSets,IN (aocJoinSets.aoIds) aoJoinIds where aoJoinIds in (:aoId)")
58 })
59 public class ActivityOfferingClusterEntity extends MetaEntity implements AttributeOwner<ActivityOfferingClusterAttributeEntity> {
60
61 @Column(name = "NAME")
62 private String name;
63
64 @Column(name = "PRIVATE_NAME")
65 private String privateName;
66
67 @Column(name = "DESCR_PLAIN", length = KSEntityConstants.EXTRA_LONG_TEXT_LENGTH)
68 private String descrPlain;
69
70 @Column(name = "DESCR_FORMATTED", length = KSEntityConstants.EXTRA_LONG_TEXT_LENGTH)
71 private String descrFormatted;
72
73 @Column(name = "FORMAT_OFFERING_ID")
74 private String formatOfferingId;
75
76 @Column(name = "AO_CLUSTER_TYPE")
77 private String activityOfferingClusterType;
78
79 @Column(name = "AO_CLUSTER_STATE")
80 private String activityOfferingClusterState;
81
82 @OneToMany(cascade = CascadeType.ALL, mappedBy = "owner")
83
84 private Set<ActivityOfferingClusterAttributeEntity> attributes = new HashSet<ActivityOfferingClusterAttributeEntity>();
85
86 @OneToMany(cascade = CascadeType.ALL)
87 @JoinColumn(name="AO_CLUSTER_ID", nullable=false)
88
89 private Set<ActivityOfferingSetEntity> aoSets = new HashSet<ActivityOfferingSetEntity>();
90
91 public ActivityOfferingClusterEntity() {
92 }
93
94 public ActivityOfferingClusterEntity(ActivityOfferingCluster aoCluster) {
95 super(aoCluster);
96 this.setId(aoCluster.getId());
97 this.setActivityOfferingClusterType(aoCluster.getTypeKey());
98 this.fromDto(aoCluster);
99 }
100
101 public List<Object> fromDto(ActivityOfferingCluster aoCluster) {
102 super.fromDTO(aoCluster);
103
104 this.setActivityOfferingClusterState(aoCluster.getStateKey());
105 this.setActivityOfferingClusterType(aoCluster.getTypeKey());
106 this.setName(aoCluster.getName());
107 this.setPrivateName(aoCluster.getPrivateName());
108 this.setFormatOfferingId(aoCluster.getFormatOfferingId());
109 if (aoCluster.getDescr() != null) {
110 this.setDescrFormatted(aoCluster.getDescr().getFormatted());
111 this.setDescrPlain(aoCluster.getDescr().getPlain());
112 } else {
113 this.setDescrFormatted(null);
114 this.setDescrPlain(null);
115 }
116
117 List<Object> orphans = new ArrayList<Object>();
118
119
120 orphans.addAll(TransformUtility.mergeToEntityAttributes(ActivityOfferingClusterAttributeEntity.class, aoCluster, this));
121
122
123 Map<String,ActivityOfferingSetEntity> existingAOSets = new HashMap<String,ActivityOfferingSetEntity>();
124 if (aoSets != null) {
125 for (ActivityOfferingSetEntity aoSetEntity : aoSets) {
126 existingAOSets.put(aoSetEntity.getId(), aoSetEntity);
127 }
128 }
129
130
131 aoSets = new HashSet<ActivityOfferingSetEntity>();
132
133 for (ActivityOfferingSet aoSet : aoCluster.getActivityOfferingSets()){
134 ActivityOfferingSetEntity aoSetEntity;
135 if (existingAOSets.containsKey(aoSet.getId())){
136 aoSetEntity = existingAOSets.remove(aoSet.getId());
137 aoSetEntity.getAoIds().clear();
138 aoSetEntity.getAoIds().addAll(aoSet.getActivityOfferingIds());
139 } else {
140 aoSetEntity = new ActivityOfferingSetEntity(aoSet);
141 }
142 aoSets.add(aoSetEntity);
143 }
144
145 orphans.addAll(existingAOSets.values());
146
147 return orphans;
148 }
149
150 public ActivityOfferingClusterInfo toDto() {
151 ActivityOfferingClusterInfo aoClusterInfo = new ActivityOfferingClusterInfo();
152
153 aoClusterInfo.setId(getId());
154 aoClusterInfo.setStateKey(getActivityOfferingClusterState());
155 aoClusterInfo.setTypeKey(getActivityOfferingClusterType());
156
157 aoClusterInfo.setName(getName());
158 aoClusterInfo.setPrivateName(getPrivateName());
159 aoClusterInfo.setFormatOfferingId(getFormatOfferingId());
160 aoClusterInfo.setDescr(RichTextHelper.buildRichTextInfo(getDescrPlain(), getDescrFormatted()));
161
162
163 aoClusterInfo.setMeta(super.toDTO());
164
165 for (ActivityOfferingClusterAttributeEntity att: getAttributes()) {
166 AttributeInfo attInfo = att.toDto();
167 aoClusterInfo.getAttributes().add(attInfo);
168 }
169
170 for (ActivityOfferingSetEntity aoSetEntity: getAoSets()) {
171 ActivityOfferingSetInfo aoSetInfo = aoSetEntity.toDto();
172 aoClusterInfo.getActivityOfferingSets().add(aoSetInfo);
173 }
174 return aoClusterInfo;
175 }
176
177 public String getName() {
178 return name;
179 }
180
181 public void setName(String name) {
182 this.name = name;
183 }
184
185 public String getDescrPlain() {
186 return descrPlain;
187 }
188
189 public void setDescrPlain(String descrPlain) {
190 this.descrPlain = descrPlain;
191 }
192
193 public String getDescrFormatted() {
194 return descrFormatted;
195 }
196
197 public void setDescrFormatted(String descrFormatted) {
198 this.descrFormatted = descrFormatted;
199 }
200
201 public String getFormatOfferingId() {
202 return formatOfferingId;
203 }
204
205 public void setFormatOfferingId(String formatOfferingId) {
206 this.formatOfferingId = formatOfferingId;
207 }
208
209 public String getActivityOfferingClusterType() {
210 return activityOfferingClusterType;
211 }
212
213 public void setActivityOfferingClusterType(String activityOfferingClusterType) {
214 this.activityOfferingClusterType = activityOfferingClusterType;
215 }
216
217 public String getActivityOfferingClusterState() {
218 return activityOfferingClusterState;
219 }
220
221 public void setActivityOfferingClusterState(String activityOfferingClusterState) {
222 this.activityOfferingClusterState = activityOfferingClusterState;
223 }
224
225 public Set<ActivityOfferingClusterAttributeEntity> getAttributes() {
226 return attributes;
227 }
228
229 public void setAttributes(Set<ActivityOfferingClusterAttributeEntity> attributes) {
230 this.attributes = attributes;
231 }
232
233 public String getPrivateName() {
234 return privateName;
235 }
236
237 public void setPrivateName(String privateName) {
238 this.privateName = privateName;
239 }
240
241 public Set<ActivityOfferingSetEntity> getAoSets() {
242 return aoSets;
243 }
244
245 public void setAoSets(Set<ActivityOfferingSetEntity> aoSets) {
246 this.aoSets = aoSets;
247 }
248
249 @Override
250 public boolean equals(Object o) {
251 if (this == o) return true;
252 if (!(o instanceof ActivityOfferingClusterEntity)) return false;
253
254 ActivityOfferingClusterEntity that = (ActivityOfferingClusterEntity) o;
255
256 if (activityOfferingClusterState != null ? !activityOfferingClusterState.equals(that.activityOfferingClusterState) : that.activityOfferingClusterState != null)
257 return false;
258 if (activityOfferingClusterType != null ? !activityOfferingClusterType.equals(that.activityOfferingClusterType) : that.activityOfferingClusterType != null)
259 return false;
260 if (aoSets != null ? !aoSets.equals(that.aoSets) : that.aoSets != null) return false;
261 if (attributes != null ? !attributes.equals(that.attributes) : that.attributes != null) return false;
262 if (descrFormatted != null ? !descrFormatted.equals(that.descrFormatted) : that.descrFormatted != null)
263 return false;
264 if (descrPlain != null ? !descrPlain.equals(that.descrPlain) : that.descrPlain != null) return false;
265 if (formatOfferingId != null ? !formatOfferingId.equals(that.formatOfferingId) : that.formatOfferingId != null)
266 return false;
267 if (name != null ? !name.equals(that.name) : that.name != null) return false;
268 if (privateName != null ? !privateName.equals(that.privateName) : that.privateName != null) return false;
269
270 return true;
271 }
272
273 @Override
274 public int hashCode() {
275 int result = name != null ? name.hashCode() : 0;
276 result = 31 * result + (privateName != null ? privateName.hashCode() : 0);
277 result = 31 * result + (descrPlain != null ? descrPlain.hashCode() : 0);
278 result = 31 * result + (descrFormatted != null ? descrFormatted.hashCode() : 0);
279 result = 31 * result + (formatOfferingId != null ? formatOfferingId.hashCode() : 0);
280 result = 31 * result + (activityOfferingClusterType != null ? activityOfferingClusterType.hashCode() : 0);
281 result = 31 * result + (activityOfferingClusterState != null ? activityOfferingClusterState.hashCode() : 0);
282 result = 31 * result + (attributes != null ? attributes.hashCode() : 0);
283 result = 31 * result + (aoSets != null ? aoSets.hashCode() : 0);
284 return result;
285 }
286 }