View Javadoc

1   package org.kuali.student.enrollment.class1.roster.model;
2   
3   import java.util.ArrayList;
4   import java.util.Date;
5   import java.util.HashSet;
6   import java.util.List;
7   import java.util.Set;
8   
9   import javax.persistence.CascadeType;
10  import javax.persistence.Column;
11  import javax.persistence.Entity;
12  import javax.persistence.FetchType;
13  import javax.persistence.OneToMany;
14  import javax.persistence.Table;
15  import javax.persistence.Temporal;
16  import javax.persistence.TemporalType;
17  
18  import org.kuali.student.enrollment.roster.dto.LprRosterEntryInfo;
19  import org.kuali.student.r2.common.dto.AttributeInfo;
20  import org.kuali.student.r2.common.entity.AttributeOwner;
21  import org.kuali.student.r2.common.entity.MetaEntity;
22  import org.kuali.student.r2.common.infc.Attribute;
23  
24  @Entity
25  @Table(name = "KSEN_LPR_ROSTER_ENTRY")
26  public class LprRosterEntryEntity extends MetaEntity implements AttributeOwner<LprRosterEntryAttributeEntity>{
27  
28      @Column(name = "LPRROSTER_ID")
29      private String lprRosterId;
30  
31      @Column(name = "LPR_ID")
32      private String lprId;
33  
34      @Column(name = "POSITION")
35      private Integer position;
36  
37      @Temporal(TemporalType.TIMESTAMP)
38      private Date effectiveDate;
39  
40      @Temporal(TemporalType.TIMESTAMP)
41      private Date expirationDate;
42  
43      @Column(name = "RELATION_TYPE_ID")
44      private String lprEntryRelationType;
45  
46      @Column(name = "RELATION_STATE_ID")
47      private String lprEntryRelationState;
48  
49      @OneToMany(cascade = CascadeType.ALL, mappedBy = "owner", fetch = FetchType.EAGER, orphanRemoval=true)
50      private Set<LprRosterEntryAttributeEntity> attributes;
51  
52      public LprRosterEntryEntity() {}
53  
54      public LprRosterEntryEntity(LprRosterEntryInfo dto) {
55          if (dto != null) {
56              this.setId(dto.getId());
57              this.setLprId(dto.getLprId());
58              this.setLprRosterId(dto.getLprRosterId());
59              this.setExpirationDate(dto.getExpirationDate());
60              this.setEffectiveDate(dto.getEffectiveDate());
61              this.setPosition(dto.getPosition());
62              if (dto.getStateKey() != null) {
63                  this.setLprEntryRelationState(dto.getStateKey());
64              }
65              this.setAttributes(new HashSet<LprRosterEntryAttributeEntity>());
66              if (null != dto.getAttributes()) {
67                  for (Attribute att : dto.getAttributes()) {
68                      LprRosterEntryAttributeEntity attEntity = new LprRosterEntryAttributeEntity(att, this);
69                      this.getAttributes().add(attEntity);
70                  }
71              }
72          }
73      }
74  
75      public Date getEffectiveDate() {
76          return effectiveDate;
77      }
78  
79      public void setEffectiveDate(Date effectiveDate) {
80          this.effectiveDate = effectiveDate;
81      }
82  
83      public Date getExpirationDate() {
84          return expirationDate;
85      }
86  
87      public void setExpirationDate(Date expirationDate) {
88          this.expirationDate = expirationDate;
89      }
90  
91      public String getLprId() {
92          return lprId;
93      }
94  
95      public void setLprId(String lprId) {
96          this.lprId = lprId;
97      }
98  
99      public String getLprRosterId() {
100         return lprRosterId;
101     }
102 
103     public void setLprRosterId(String lprRosterId) {
104         this.lprRosterId = lprRosterId;
105     }
106 
107     public Integer getPosition() {
108         return position;
109     }
110 
111     public void setPosition(Integer position) {
112         this.position = position;
113     }
114 
115     public Set<LprRosterEntryAttributeEntity> getAttributes() {
116         return attributes;
117     }
118 
119     public void setAttributes(Set<LprRosterEntryAttributeEntity> attributes) {
120         this.attributes = attributes;
121     }
122 
123     public String getLprEntryRelationState() {
124         return lprEntryRelationState;
125     }
126 
127     public void setLprEntryRelationState(String lprEntryRelationState) {
128         this.lprEntryRelationState = lprEntryRelationState;
129     }
130 
131     public String getLprEntryRelationType() {
132         return lprEntryRelationType;
133     }
134 
135     public void setLprEntryRelationType(String lprEntryRelationType) {
136         this.lprEntryRelationType = lprEntryRelationType;
137     }
138 
139     public LprRosterEntryInfo toDto() {
140         LprRosterEntryInfo info = new LprRosterEntryInfo();
141         info.setId(this.getId());
142         info.setEffectiveDate(getEffectiveDate());
143         info.setExpirationDate(getExpirationDate());
144         info.setLprId(getLprId());
145         info.setLprRosterId(getLprRosterId());
146         info.setPosition(getPosition());
147 
148         if (getLprEntryRelationState() != null) {
149             info.setStateKey(getLprEntryRelationState());
150         }
151         if (getLprEntryRelationType() != null) {
152             info.setTypeKey(getLprEntryRelationType());
153         }
154 
155         List<AttributeInfo> atts = new ArrayList<AttributeInfo>();
156         for (LprRosterEntryAttributeEntity att : getAttributes()) {
157             AttributeInfo attInfo = att.toDto();
158             atts.add(attInfo);
159         }
160         info.setAttributes(atts);
161         info.setMeta(super.toDTO());
162 
163         return info;
164     }
165 
166 }