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.dto.AttributeInfo;
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.Attribute;
9   import org.kuali.student.r2.common.infc.RichText;
10  import org.kuali.student.r2.lum.clu.dto.FeeInfo;
11  import org.kuali.student.r2.lum.clu.infc.Fee;
12  
13  import javax.persistence.CascadeType;
14  import javax.persistence.Column;
15  import javax.persistence.Entity;
16  import javax.persistence.FetchType;
17  import javax.persistence.JoinColumn;
18  import javax.persistence.ManyToOne;
19  import javax.persistence.OneToMany;
20  import javax.persistence.Table;
21  import java.util.ArrayList;
22  import java.util.HashSet;
23  import java.util.List;
24  import java.util.Set;
25  
26  @Entity
27  @Table(name = "KSEN_LUI_FEE")
28  public class LuiFeeEntity extends MetaEntity implements AttributeOwner<LuiFeeAttributeEntity> {
29  
30      @Column(name = "FEE_TYPE")
31      private String feeType;
32  
33      @Column(name = "RATE_TYPE")
34      private String rateType;
35  
36      @Column(name = "FEE_KEY")
37      private String feeKey;
38  
39      @Column(name = "DESCR_FORMATTED", length = KSEntityConstants.EXTRA_LONG_TEXT_LENGTH)
40      private String formatted;
41  
42      @Column(name = "DESCR_PLAIN", length = KSEntityConstants.EXTRA_LONG_TEXT_LENGTH, nullable = false)
43      private String plain;
44  
45      @ManyToOne
46      @JoinColumn(name = "LUI_ID")
47      private LuiEntity lui;
48  
49      @OneToMany(cascade = CascadeType.ALL, mappedBy = "owner", fetch = FetchType.EAGER)
50      private Set<LuiFeeAttributeEntity> attributes;
51  
52      public LuiFeeEntity() {}
53  
54      public LuiFeeEntity(Fee fee) {
55          super(fee);
56          this.setFeeKey(fee.getKey());
57          this.setFeeType(fee.getFeeType());
58          this.setRateType(fee.getRateType());
59  
60          // Description
61          if (fee.getDescr() != null) {
62              RichText rt = fee.getDescr();
63              this.setFormatted(rt.getFormatted());
64              this.setPlain(rt.getPlain());
65          }
66  
67          // Attributes
68          this.setAttributes(new HashSet<LuiFeeAttributeEntity>());
69          if (null != fee.getAttributes()) {
70              for (Attribute att : fee.getAttributes()) {
71                  LuiFeeAttributeEntity attEntity = new LuiFeeAttributeEntity(att, this);
72                  this.getAttributes().add(attEntity);
73              }
74          }
75      }
76  
77      public String getFeeType() {
78          return feeType;
79      }
80  
81      public void setFeeType(String feeType) {
82          this.feeType = feeType;
83      }
84  
85      public String getRateType() {
86          return rateType;
87      }
88  
89      public void setRateType(String rateType) {
90          this.rateType = rateType;
91      }
92  
93      public String getFeeKey() {
94          return feeKey;
95      }
96  
97      public void setFeeKey(String feeKey) {
98          this.feeKey = feeKey;
99      }
100 
101     public String getFormatted() {
102         return formatted;
103     }
104 
105     public void setFormatted(String formatted) {
106         this.formatted = formatted;
107     }
108 
109     public String getPlain() {
110         return plain;
111     }
112 
113     public void setPlain(String plain) {
114         this.plain = plain;
115     }
116 
117     public LuiEntity getLui() {
118         return lui;
119     }
120 
121     public void setLui(LuiEntity lui) {
122         this.lui = lui;
123     }
124 
125     public FeeInfo toDto() {
126         FeeInfo obj = new FeeInfo();
127         obj.setId(this.getId());
128         //if(lui!=null)
129         //    obj.setLuiId(lui.getId());
130         obj.setFeeType(this.getFeeType());
131         obj.setRateType(this.getRateType());
132         // TODO: obj.setFeeAmounts(feeAmounts)
133 
134         RichTextInfo rtInfo = new RichTextInfo();
135         rtInfo.setFormatted(this.getFormatted());
136         rtInfo.setPlain(this.getPlain());
137         obj.setDescr(rtInfo);
138 
139         // Attributes
140         List<AttributeInfo> atts = new ArrayList<AttributeInfo>();
141         for (LuiFeeAttributeEntity att : getAttributes()) {
142             AttributeInfo attInfo = att.toDto();
143             atts.add(attInfo);
144         }
145         obj.setAttributes(atts);
146         
147         obj.setMeta(super.toDTO());
148 
149         return obj;
150 
151     }
152 
153     @Override
154     public void setAttributes(Set<LuiFeeAttributeEntity> attributes) {
155         this.attributes = attributes;
156     }
157 
158     @Override
159     public Set<LuiFeeAttributeEntity> getAttributes() {
160         return attributes;
161     }
162 }