001package org.kuali.student.enrollment.class1.roster.model; 002 003import java.util.ArrayList; 004import java.util.HashSet; 005import java.util.List; 006import java.util.Set; 007 008import javax.persistence.CascadeType; 009import javax.persistence.Column; 010import javax.persistence.Entity; 011import javax.persistence.FetchType; 012import javax.persistence.JoinColumn; 013import javax.persistence.ManyToOne; 014import javax.persistence.OneToMany; 015import javax.persistence.Table; 016 017import org.kuali.student.enrollment.roster.dto.LprRosterInfo; 018import org.kuali.student.r2.common.dto.AttributeInfo; 019import org.kuali.student.r2.common.dto.TimeAmountInfo; 020import org.kuali.student.r2.common.entity.AttributeOwner; 021import org.kuali.student.r2.common.entity.MetaEntity; 022import org.kuali.student.r2.common.infc.Attribute; 023 024@Entity 025@Table(name = "KSEN_LPR_ROSTER") 026public class LprRosterEntity extends MetaEntity implements AttributeOwner<LprRosterAttributeEntity>{ 027 028 @Column(name = "NAME") 029 private String name; 030 031 @ManyToOne(cascade = CascadeType.ALL) 032 @JoinColumn(name = "RT_DESCR_ID") 033 private LprRichTextEntity descr; 034 035// @ManyToMany(cascade = CascadeType.ALL) 036// @JoinTable(name = "KSEN_LPRROSTER_LUI_RELTN", joinColumns = @JoinColumn(name = "LPRROSTER_ID"), inverseJoinColumns = @JoinColumn(name = "LUI_ID")) 037// private List<String> associatedLuiIds; 038 039 @Column(name = "MAX_CAPACITY") 040 private int maximumCapacity; 041 042 @Column(name = "CHECK_IN_REQ") 043 private boolean checkInRequired; 044 045 @Column(name = "TYPE_ID") 046 private String lprRosterType; 047 048 @Column(name = "STATE_ID") 049 private String lprRosterState; 050 051 @Column(name = "ATP_DUR_TYP_KEY") 052 private String atpDurationTypeKey; 053 054 @Column(name = "TM_QUANTITY") 055 private Integer timeQuantity; 056 057 @OneToMany(cascade = CascadeType.ALL, mappedBy = "owner", fetch=FetchType.EAGER, orphanRemoval=true) 058 private Set<LprRosterAttributeEntity> attributes; 059 060 public LprRosterEntity() { 061 062 } 063 064 public LprRosterEntity(LprRosterInfo dto) { 065 super(dto); 066 this.setCheckInRequired(dto.getCheckInRequired()); 067 this.setMaximumCapacity(dto.getMaximumCapacity()); 068 this.setId(dto.getId()); 069 if (dto.getStateKey() != null) { 070 this.setLprRosterState(dto.getStateKey()); 071 } 072 073 if (dto.getCheckInFrequency() != null) { 074 this.setAtpDurationTypeKey(dto.getCheckInFrequency().getAtpDurationTypeKey()); 075 this.setTimeQuantity(dto.getCheckInFrequency().getTimeQuantity()); 076 } 077 this.setName(dto.getName()); 078 if (dto.getDescr() != null) { 079 LprRichTextEntity entityDesc = new LprRichTextEntity(dto.getDescr()); 080 this.setDescr(entityDesc); 081 } 082 083 this.setAttributes(new HashSet<LprRosterAttributeEntity>()); 084 085 if (null != dto.getAttributes()) { 086 for (Attribute att : dto.getAttributes()) { 087 LprRosterAttributeEntity attEntity = new LprRosterAttributeEntity(att, this); 088 this.getAttributes().add(attEntity); 089 } 090 } 091 } 092 093// public List<String> getAssociatedLuiIds() { 094// return associatedLuiIds; 095// } 096// 097// public void setAssociatedLuiIds(List<String> associatedLuis) { 098// this.associatedLuiIds = associatedLuis; 099// } 100 101 public void setCheckInRequired(boolean checkInRequired) { 102 this.checkInRequired = checkInRequired; 103 } 104 105 public int getMaximumCapacity() { 106 return maximumCapacity; 107 } 108 109 public void setMaximumCapacity(int maximumCapacity) { 110 this.maximumCapacity = maximumCapacity; 111 } 112 113 public Boolean getCheckInRequired() { 114 return checkInRequired; 115 } 116 117 public void setCheckInRequired(Boolean checkInRequired) { 118 this.checkInRequired = checkInRequired; 119 } 120 121 public String getLprRosterType() { 122 return lprRosterType; 123 } 124 125 public void setLprRosterType(String lprRosterType) { 126 this.lprRosterType = lprRosterType; 127 } 128 129 public String getLprRosterState() { 130 return lprRosterState; 131 } 132 133 public void setLprRosterState(String lprRosterState) { 134 this.lprRosterState = lprRosterState; 135 } 136 137 public String getAtpDurationTypeKey() { 138 return atpDurationTypeKey; 139 } 140 141 public void setAtpDurationTypeKey(String atpDurationTypeKey) { 142 this.atpDurationTypeKey = atpDurationTypeKey; 143 } 144 145 public Integer getTimeQuantity() { 146 return timeQuantity; 147 } 148 149 public void setTimeQuantity(Integer timeQuantity) { 150 this.timeQuantity = timeQuantity; 151 } 152 153 @Override 154 public Set<LprRosterAttributeEntity> getAttributes() { 155 return attributes; 156 } 157 158 public void setAttributes(Set<LprRosterAttributeEntity> attributes) { 159 this.attributes = attributes; 160 } 161 162 public LprRichTextEntity getDescr() { 163 return descr; 164 } 165 166 public void setDescr(LprRichTextEntity descr) { 167 this.descr = descr; 168 } 169 170 public String getName() { 171 return name; 172 } 173 174 public void setName(String name) { 175 this.name = name; 176 } 177 178 public LprRosterInfo toDto() { 179 LprRosterInfo info = new LprRosterInfo(); 180 info.setId(this.getId()); 181 TimeAmountInfo timeAmountInfo = new TimeAmountInfo(); 182 timeAmountInfo.setAtpDurationTypeKey(this.getAtpDurationTypeKey()); 183 timeAmountInfo.setTimeQuantity(this.getTimeQuantity()); 184 info.setCheckInFrequency(timeAmountInfo); 185 info.setCheckInRequired(this.getCheckInRequired()); 186 info.setMaximumCapacity(this.getMaximumCapacity()); 187 info.setName(this.getName()); 188 info.setStateKey(getLprRosterState()); 189 info.setTypeKey(getLprRosterType()); 190// info.setAssociatedLuiIds(this.getAssociatedLuiIds()); 191 192 List<AttributeInfo> atts = new ArrayList<AttributeInfo>(); 193 for (LprRosterAttributeEntity att : getAttributes()) { 194 AttributeInfo attInfo = att.toDto(); 195 atts.add(attInfo); 196 } 197 info.setAttributes(atts); 198 199 info.setMeta(super.toDTO()); 200 201 if (descr != null) { 202 info.setDescr(descr.toDto()); 203 } 204 205 /** 206 * FIXME: Do we need to copy create and update time/id? 207 */ 208 return info; 209 } 210}