View Javadoc

1   package org.kuali.student.r2.lum.lrc.model;
2   
3   import java.math.BigDecimal;
4   import java.util.ArrayList;
5   import org.kuali.student.r1.common.entity.KSEntityConstants;
6   import org.kuali.student.r2.common.dto.AttributeInfo;
7   import org.kuali.student.r2.common.entity.AttributeOwner;
8   import org.kuali.student.r2.common.entity.MetaEntity;
9   import org.kuali.student.r2.common.infc.Attribute;
10  import org.kuali.student.r2.lum.lrc.dto.ResultValueInfo;
11  
12  import javax.persistence.CascadeType;
13  import javax.persistence.Column;
14  import javax.persistence.Entity;
15  import javax.persistence.FetchType;
16  import javax.persistence.OneToMany;
17  import javax.persistence.Table;
18  import javax.persistence.Temporal;
19  import javax.persistence.TemporalType;
20  import java.util.Date;
21  import java.util.HashSet;
22  import java.util.Set;
23  import javax.persistence.EntityManager;
24  import javax.persistence.NamedQueries;
25  import javax.persistence.NamedQuery;
26  import org.kuali.student.r2.common.util.RichTextHelper;
27  
28  @Entity
29  @Table(name = "KSEN_LRC_RESULT_VALUE")
30  @NamedQueries({
31      @NamedQuery(name = "ResultValueEntity.getIdsByType",
32      query = "select id from ResultValueEntity where type = :type"),
33      @NamedQuery(name = "ResultValueEntity.getByScale",
34      query = "select RV from ResultValueEntity RV where RV.resultScaleId = :resultScaleKey"),
35      @NamedQuery(name = "ResultValueEntity.getByScaleAndValue",
36      query = "select RV from ResultValueEntity RV where RV.resultScaleId = :resultScaleKey and RV.value = :value")
37  })
38  public class ResultValueEntity extends MetaEntity implements AttributeOwner<ResultValueAttributeEntity> {
39  
40      @Column(name = "RESULT_VALUE_TYPE")
41      private String type;
42      @Column(name = "RESULT_VALUE_STATE")
43      private String state;
44      @Column(name = "NAME")
45      private String name;
46      @Column(name = "DESCR_PLAIN", length = KSEntityConstants.EXTRA_LONG_TEXT_LENGTH)
47      private String descrPlain;
48      @Column(name = "DESCR_FORMATTED", length = KSEntityConstants.EXTRA_LONG_TEXT_LENGTH)
49      private String descrFormatted;
50      @Column(name = "RESULT_SCALE_ID")
51      private String resultScaleId;
52      @Column(name = "NUMERIC_VALUE")
53      private BigDecimal numericValue;
54      @Column(name = "RESULT_VALUE")
55      private String value;
56      @Temporal(TemporalType.TIMESTAMP)
57      @Column(name = "EFF_DT")
58      private Date effectiveDate;
59      @Temporal(TemporalType.TIMESTAMP)
60      @Column(name = "EXPIR_DT")
61      private Date expirationDate;
62      @OneToMany(cascade = CascadeType.ALL, mappedBy = "owner", fetch = FetchType.EAGER, orphanRemoval=true)
63      private Set<ResultValueAttributeEntity> attributes;
64  
65      public ResultValueEntity() {
66      }
67  
68      public ResultValueEntity(ResultValueInfo dto) {
69          super(dto);
70          this.setId(dto.getKey());
71          this.setType(dto.getTypeKey());
72          setResultScaleId(dto.getResultScaleKey());
73          this.fromDTO(dto);
74      }
75  
76      public void fromDTO(ResultValueInfo dto) {
77          this.setName(dto.getName());
78          this.setState(dto.getStateKey());
79          if (dto.getDescr() != null) {
80              this.setDescrFormatted(dto.getDescr().getFormatted());
81              this.setDescrPlain(dto.getDescr().getPlain());
82          } else {
83              this.setDescrFormatted(null);
84              this.setDescrPlain(null);
85          }
86          setEffectiveDate(dto.getEffectiveDate());
87          setExpirationDate(dto.getExpirationDate());
88          if(dto.getNumericValue() != null){
89              setNumericValue(new BigDecimal(dto.getNumericValue()));
90          }
91          else
92          {
93              setNumericValue (null);
94          }
95          setValue(dto.getValue()); 
96          // dynamic attributes
97          if (this.getAttributes() == null) {
98              this.setAttributes(new HashSet<ResultValueAttributeEntity>());
99          }
100         else
101             this.attributes.clear();
102        
103         for (Attribute att : dto.getAttributes()) {
104             ResultValueAttributeEntity attEntity = new ResultValueAttributeEntity(att, this);
105             this.getAttributes().add(attEntity);
106         }
107     }
108 
109     public String getResultScaleId() {
110         return resultScaleId;
111     }
112 
113     public void setResultScaleId(String resultScaleId) {
114         this.resultScaleId = resultScaleId;
115     }
116 
117     public BigDecimal getNumericValue() {
118         return numericValue;
119     }
120 
121     public void setNumericValue(BigDecimal numericValue) {
122         this.numericValue = numericValue;
123     }
124 
125     public String getValue() {
126         return value;
127     }
128 
129     public void setValue(String value) {
130         this.value = value;
131     }
132 
133     public Date getEffectiveDate() {
134         return effectiveDate;
135     }
136 
137     public void setEffectiveDate(Date effectiveDate) {
138         this.effectiveDate = effectiveDate;
139     }
140 
141     public Date getExpirationDate() {
142         return expirationDate;
143     }
144 
145     public void setExpirationDate(Date expirationDate) {
146         this.expirationDate = expirationDate;
147     }
148 
149     public String getName() {
150         return name;
151     }
152 
153     public void setName(String name) {
154         this.name = name;
155     }
156 
157     public String getDescrFormatted() {
158         return descrFormatted;
159     }
160 
161     public void setDescrFormatted(String descrFormatted) {
162         this.descrFormatted = descrFormatted;
163     }
164 
165     public String getDescrPlain() {
166         return descrPlain;
167     }
168 
169     public void setDescrPlain(String descrPlain) {
170         this.descrPlain = descrPlain;
171     }
172 
173     public String getType() {
174         return type;
175     }
176 
177     public void setType(String type) {
178         this.type = type;
179     }
180 
181     public String getState() {
182         return state;
183     }
184 
185     public void setState(String state) {
186         this.state = state;
187     }
188 
189     @Override
190     public void setAttributes(Set<ResultValueAttributeEntity> attributes) {
191         this.attributes = attributes;
192     }
193 
194     @Override
195     public Set<ResultValueAttributeEntity> getAttributes() {
196         return attributes;
197     }
198 
199     public ResultValueInfo toDto() {
200         ResultValueInfo info = new ResultValueInfo();
201         info.setKey(getId());
202         info.setTypeKey(getType());
203         info.setStateKey(getState());
204         info.setName(getName());
205         info.setDescr(new RichTextHelper().toRichTextInfo(getDescrPlain(), getDescrFormatted()));
206         info.setResultScaleKey(getResultScaleId());
207         info.setNumericValue(String.valueOf(getNumericValue()));
208         info.setValue(getValue());
209         info.setEffectiveDate(getEffectiveDate());
210         info.setExpirationDate(getExpirationDate());
211         if (this.getAttributes() != null) {
212             for (ResultValueAttributeEntity att : getAttributes()) {
213                 AttributeInfo attInfo = att.toDto();
214                 info.getAttributes().add(attInfo);
215             }
216         }
217         info.setMeta(super.toDTO());
218         return info;
219     }
220 }