001 package org.kuali.student.enrollment.class1.roster.model;
002
003 import java.util.ArrayList;
004 import java.util.Date;
005 import java.util.HashSet;
006 import java.util.List;
007 import java.util.Set;
008
009 import javax.persistence.CascadeType;
010 import javax.persistence.Column;
011 import javax.persistence.Entity;
012 import javax.persistence.FetchType;
013 import javax.persistence.OneToMany;
014 import javax.persistence.Table;
015 import javax.persistence.Temporal;
016 import javax.persistence.TemporalType;
017
018 import org.kuali.student.enrollment.roster.dto.LprRosterEntryInfo;
019 import org.kuali.student.r2.common.dto.AttributeInfo;
020 import org.kuali.student.r2.common.entity.AttributeOwner;
021 import org.kuali.student.r2.common.entity.MetaEntity;
022 import org.kuali.student.r2.common.infc.Attribute;
023
024 @Entity
025 @Table(name = "KSEN_LPR_ROSTER_ENTRY")
026 public class LprRosterEntryEntity extends MetaEntity implements AttributeOwner<LprRosterEntryAttributeEntity>{
027
028 @Column(name = "LPRROSTER_ID")
029 private String lprRosterId;
030
031 @Column(name = "LPR_ID")
032 private String lprId;
033
034 @Column(name = "POSITION")
035 private Integer position;
036
037 @Temporal(TemporalType.TIMESTAMP)
038 private Date effectiveDate;
039
040 @Temporal(TemporalType.TIMESTAMP)
041 private Date expirationDate;
042
043 @Column(name = "RELATION_TYPE_ID")
044 private String lprEntryRelationType;
045
046 @Column(name = "RELATION_STATE_ID")
047 private String lprEntryRelationState;
048
049 @OneToMany(cascade = CascadeType.ALL, mappedBy = "owner", fetch = FetchType.EAGER, orphanRemoval=true)
050 private Set<LprRosterEntryAttributeEntity> attributes;
051
052 public LprRosterEntryEntity() {}
053
054 public LprRosterEntryEntity(LprRosterEntryInfo dto) {
055 if (dto != null) {
056 this.setId(dto.getId());
057 this.setLprId(dto.getLprId());
058 this.setLprRosterId(dto.getLprRosterId());
059 this.setExpirationDate(dto.getExpirationDate());
060 this.setEffectiveDate(dto.getEffectiveDate());
061 this.setPosition(dto.getPosition());
062 if (dto.getStateKey() != null) {
063 this.setLprEntryRelationState(dto.getStateKey());
064 }
065 this.setAttributes(new HashSet<LprRosterEntryAttributeEntity>());
066 if (null != dto.getAttributes()) {
067 for (Attribute att : dto.getAttributes()) {
068 LprRosterEntryAttributeEntity attEntity = new LprRosterEntryAttributeEntity(att, this);
069 this.getAttributes().add(attEntity);
070 }
071 }
072 }
073 }
074
075 public Date getEffectiveDate() {
076 return effectiveDate;
077 }
078
079 public void setEffectiveDate(Date effectiveDate) {
080 this.effectiveDate = effectiveDate;
081 }
082
083 public Date getExpirationDate() {
084 return expirationDate;
085 }
086
087 public void setExpirationDate(Date expirationDate) {
088 this.expirationDate = expirationDate;
089 }
090
091 public String getLprId() {
092 return lprId;
093 }
094
095 public void setLprId(String lprId) {
096 this.lprId = lprId;
097 }
098
099 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 }