View Javadoc

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          
47          super.fromDTO(luCode);
48          
49          List<Object> orphansToDelete = new ArrayList<Object>();
50  
51          this.setValue(luCode.getValue());
52          if (luCode.getDescr() != null) {
53              RichText rt = luCode.getDescr();
54              this.setDescrFormatted(rt.getFormatted());
55              this.setDescrPlain(rt.getPlain());
56          }
57  
58          //Attributes
59          orphansToDelete.addAll(TransformUtility.mergeToEntityAttributes(LuCodeAttributeEntity.class, luCode, this));
60  
61          return orphansToDelete;
62      }
63  
64      public LuCodeInfo toDto() {
65          LuCodeInfo obj = new LuCodeInfo();
66          obj.setId(getId());
67          obj.setTypeKey(type);
68          obj.setValue(value);
69          if (getDescrPlain() != null) {
70              RichTextInfo rti = new RichTextInfo();
71              rti.setPlain(getDescrPlain());
72              rti.setFormatted(getDescrFormatted());
73              obj.setDescr(rti);
74          }
75          obj.setMeta(super.toDTO());
76  
77          // Attributes
78          obj.setAttributes(TransformUtility.toAttributeInfoList(this));
79  
80          return obj;
81      }
82  
83      public String getDescrFormatted() {
84          return formatted;
85      }
86  
87      public void setDescrFormatted(String formatted) {
88          this.formatted = formatted;
89      }
90  
91      public String getDescrPlain() {
92          return plain;
93      }
94  
95      public void setDescrPlain(String plain) {
96          this.plain = plain;
97      }
98  
99      public String getValue() {
100         return value;
101     }
102 
103     public void setValue(String value) {
104         this.value = value;
105     }
106 
107     public String getType() {
108         return type;
109     }
110 
111     public void setType(String type) {
112         this.type = type;
113     }
114 
115     public LuiEntity getLui() {
116         return lui;
117     }
118 
119     public void setLui(LuiEntity lui) {
120         this.lui = lui;
121     }
122 
123     @Override
124     public void setAttributes(Set<LuCodeAttributeEntity> attributes) {
125         this.attributes = attributes;
126     }
127 
128     @Override
129     public Set<LuCodeAttributeEntity> getAttributes() {
130         return attributes;
131     }
132 
133 
134 }