1 package org.kuali.student.enrollment.class1.lui.model;
2
3 import org.kuali.student.r1.common.entity.KSEntityConstants;
4 import org.kuali.student.r2.common.assembler.TransformUtility;
5 import org.kuali.student.r2.common.dto.RichTextInfo;
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.RichText;
9 import org.kuali.student.r2.lum.clu.dto.LuCodeInfo;
10 import org.kuali.student.r2.lum.clu.infc.LuCode;
11
12 import javax.persistence.*;
13 import java.util.ArrayList;
14 import java.util.List;
15 import java.util.Set;
16
17 @Entity
18 @Table(name = "KSEN_LUI_LU_CD")
19 public class LuCodeEntity extends MetaEntity implements AttributeOwner<LuCodeAttributeEntity> {
20
21 @Column(name = "DESCR_FORMATTED", length = KSEntityConstants.EXTRA_LONG_TEXT_LENGTH)
22 private String formatted;
23 @Column(name = "DESCR_PLAIN", length = KSEntityConstants.EXTRA_LONG_TEXT_LENGTH)
24 private String plain;
25 @Column(name = "VALUE")
26 private String value;
27 @Column(name = "LUI_LUCD_TYPE")
28 private String type;
29 @ManyToOne
30 @JoinColumn(name = "LUI_ID")
31 private LuiEntity lui;
32 @OneToMany(cascade = CascadeType.ALL, mappedBy = "owner", fetch = FetchType.EAGER)
33 private Set<LuCodeAttributeEntity> attributes;
34
35 public LuCodeEntity() {
36 }
37
38 public LuCodeEntity(LuCode luCode) {
39 super(luCode);
40 this.setId(luCode.getId());
41 this.setType(luCode.getTypeKey());
42 fromDto(luCode);
43 }
44
45 public List<Object> fromDto(LuCode luCode) {
46 List<Object> orphansToDelete = new ArrayList<Object>();
47
48 this.setValue(luCode.getValue());
49 if (luCode.getDescr() != null) {
50 RichText rt = luCode.getDescr();
51 this.setDescrFormatted(rt.getFormatted());
52 this.setDescrPlain(rt.getPlain());
53 }
54
55
56 orphansToDelete.addAll(TransformUtility.mergeToEntityAttributes(LuCodeAttributeEntity.class, luCode, this));
57
58 return orphansToDelete;
59 }
60
61 public LuCodeInfo toDto() {
62 LuCodeInfo obj = new LuCodeInfo();
63 obj.setId(getId());
64 obj.setTypeKey(type);
65 obj.setValue(value);
66 if (getDescrPlain() != null) {
67 RichTextInfo rti = new RichTextInfo();
68 rti.setPlain(getDescrPlain());
69 rti.setFormatted(getDescrFormatted());
70 obj.setDescr(rti);
71 }
72 obj.setMeta(super.toDTO());
73
74
75 obj.setAttributes(TransformUtility.toAttributeInfoList(this));
76
77 return obj;
78 }
79
80 public String getDescrFormatted() {
81 return formatted;
82 }
83
84 public void setDescrFormatted(String formatted) {
85 this.formatted = formatted;
86 }
87
88 public String getDescrPlain() {
89 return plain;
90 }
91
92 public void setDescrPlain(String plain) {
93 this.plain = plain;
94 }
95
96 public String getValue() {
97 return value;
98 }
99
100 public void setValue(String value) {
101 this.value = value;
102 }
103
104 public String getType() {
105 return type;
106 }
107
108 public void setType(String type) {
109 this.type = type;
110 }
111
112 public LuiEntity getLui() {
113 return lui;
114 }
115
116 public void setLui(LuiEntity lui) {
117 this.lui = lui;
118 }
119
120 @Override
121 public void setAttributes(Set<LuCodeAttributeEntity> attributes) {
122 this.attributes = attributes;
123 }
124
125 @Override
126 public Set<LuCodeAttributeEntity> getAttributes() {
127 return attributes;
128 }
129
130
131 }