View Javadoc

1   package org.kuali.student.enrollment.class1.hold.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.entity.AttributeOwner;
6   import org.kuali.student.r2.common.entity.MetaEntity;
7   import org.kuali.student.r2.common.infc.Attribute;
8   import org.kuali.student.r2.core.hold.dto.AppliedHoldInfo;
9   import org.kuali.student.r2.core.hold.infc.AppliedHold;
10  
11  import javax.persistence.CascadeType;
12  import javax.persistence.Column;
13  import javax.persistence.Entity;
14  import javax.persistence.FetchType;
15  import javax.persistence.JoinColumn;
16  import javax.persistence.ManyToOne;
17  import javax.persistence.OneToMany;
18  import javax.persistence.Table;
19  import javax.persistence.Temporal;
20  import javax.persistence.TemporalType;
21  import java.util.Date;
22  import java.util.HashSet;
23  import java.util.Set;
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_HOLD")
30  @NamedQueries({
31      @NamedQuery(name = "AppliedHoldEntity.getIdsByType",
32      query = "select id from AppliedHoldEntity where holdType = :type"),
33      @NamedQuery(name = "AppliedHoldEntity.getIdsByIssue",
34      query = "select AH.id from AppliedHoldEntity AH where AH.holdIssue.id = :holdIssueId"),
35      @NamedQuery(name = "AppliedHoldEntity.getByPerson",
36      query = "select AH from AppliedHoldEntity AH where AH.personId = :personId"),
37      @NamedQuery(name = "AppliedHoldEntity.getByPersonAndState",
38      query = "select AH from AppliedHoldEntity AH where AH.personId = :personId and AH.holdState = :stateKey"),
39      @NamedQuery(name = "AppliedHoldEntity.getByIssueAndPerson",
40      query = "select AH from AppliedHoldEntity AH where AH.holdIssue.id = :holdIssueId and AH.personId = :personId"),
41      @NamedQuery(name = "AppliedHoldEntity.getByIssuePersonAndState",
42      query = "select AH from AppliedHoldEntity AH where AH.holdIssue.id = :holdIssueId and AH.personId = :personId and AH.holdState = :stateKey")
43  })
44  public class AppliedHoldEntity
45          extends MetaEntity
46          implements AttributeOwner<AppliedHoldAttributeEntity> {
47  
48      @Column(name = "NAME")
49      private String name;
50      @Column(name = "DESCR_PLAIN", length = KSEntityConstants.EXTRA_LONG_TEXT_LENGTH, nullable = false)
51      private String descrPlain;
52      @Column(name = "DESCR_FORMATTED", length = KSEntityConstants.EXTRA_LONG_TEXT_LENGTH)
53      private String descrFormatted;
54      @Column(name = "HOLD_STATE")
55      private String holdState;
56      @Column(name = "HOLD_TYPE")
57      private String holdType;
58      @Temporal(TemporalType.TIMESTAMP)
59      @Column(name = "EFF_DT")
60      private Date effectiveDate;
61      @Temporal(TemporalType.TIMESTAMP)
62      @Column(name = "RELEASED_DT")
63      private Date releasedDate;
64      @ManyToOne(optional = false)
65      @JoinColumn(name = "ISSUE_ID")
66      private HoldIssueEntity holdIssue;
67      @Column(name = "PERS_ID")
68      private String personId;
69      @OneToMany(cascade = CascadeType.ALL, mappedBy = "owner", fetch = FetchType.EAGER, orphanRemoval = true)
70      private final Set<AppliedHoldAttributeEntity> attributes = new HashSet<AppliedHoldAttributeEntity>();
71  
72      @Override
73      public void setAttributes(Set<AppliedHoldAttributeEntity> attributes) {
74          this.attributes.clear();
75          if (attributes != null) {
76              this.attributes.addAll(attributes);
77          }
78      }
79  
80      public AppliedHoldEntity() {
81      }
82  
83      public AppliedHoldEntity(AppliedHold hold) {
84          super(hold);
85          this.setId(hold.getId());
86          this.personId = hold.getPersonId();
87          // issue an an entity so it gets set in the service
88  //        this.holdIssue = hold.getIssueId();
89          this.holdType = hold.getTypeKey();
90          this.fromDto(hold);
91      }
92  
93      public void fromDto(AppliedHold dto) {
94          this.setName(dto.getName());
95          this.setHoldState(dto.getStateKey());
96          if (dto.getDescr() != null) {
97              this.setDescrFormatted(dto.getDescr().getFormatted());
98              this.setDescrPlain(dto.getDescr().getPlain());
99          } else {
100             this.setDescrFormatted(null);
101             this.setDescrPlain(null);
102         }
103         this.setEffectiveDate(dto.getEffectiveDate());
104         this.setReleasedDate(dto.getReleasedDate());
105 
106         // dynamic attributes
107         this.attributes.clear();
108         for (Attribute att : dto.getAttributes()) {
109             AppliedHoldAttributeEntity attEntity = new AppliedHoldAttributeEntity(att, this);
110             this.getAttributes().add(attEntity);
111         }
112     }
113 
114     public AppliedHoldInfo toDto() {
115         AppliedHoldInfo info = new AppliedHoldInfo();
116         info.setId(getId());
117         info.setName(name);
118         info.setEffectiveDate(effectiveDate);
119         info.setReleasedDate(releasedDate);
120         info.setPersonId(personId);
121         info.setTypeKey(holdType);
122         info.setStateKey(holdState);
123         if (holdIssue != null) {
124             info.setHoldIssueId(holdIssue.getId());
125         }
126         info.setDescr(new RichTextHelper().toRichTextInfo(getDescrPlain(), getDescrFormatted()));
127 
128         info.setMeta(super.toDTO());
129         for (AppliedHoldAttributeEntity att : getAttributes()) {
130             AttributeInfo attInfo = att.toDto();
131             info.getAttributes().add(attInfo);
132         }
133         return info;
134     }
135 
136     public String getName() {
137         return name;
138     }
139 
140     public void setName(String name) {
141         this.name = name;
142     }
143 
144     public String getDescrPlain() {
145         return descrPlain;
146     }
147 
148     public String getDescrFormatted() {
149         return descrFormatted;
150     }
151 
152     public void setDescrPlain(String plain) {
153         this.descrPlain = plain;
154     }
155 
156     public void setDescrFormatted(String formatted) {
157         this.descrFormatted = formatted;
158     }
159 
160     public String getHoldType() {
161         return holdType;
162     }
163 
164     public void setHoldType(String holdType) {
165         this.holdType = holdType;
166     }
167 
168     public String getHoldState() {
169         return holdState;
170     }
171 
172     public void setHoldState(String holdState) {
173         this.holdState = holdState;
174     }
175 
176     public Date getEffectiveDate() {
177         return effectiveDate;
178     }
179 
180     public void setEffectiveDate(Date effectiveDate) {
181         this.effectiveDate = effectiveDate;
182     }
183 
184     public Date getReleasedDate() {
185         return releasedDate;
186     }
187 
188     public void setReleasedDate(Date releasedDate) {
189         this.releasedDate = releasedDate;
190     }
191 
192     public HoldIssueEntity getHoldIssue() {
193         return holdIssue;
194     }
195 
196     public void setHoldIssue(HoldIssueEntity issue) {
197         this.holdIssue = issue;
198     }
199 
200     public String getPersonId() {
201         return personId;
202     }
203 
204     public void setPersonId(String personId) {
205         this.personId = personId;
206     }
207 
208     @Override
209     public Set<AppliedHoldAttributeEntity> getAttributes() {
210         return attributes;
211     }
212 }