| 1 | |
package org.kuali.student.r2.core.classI.atp.model; |
| 2 | |
|
| 3 | |
import java.util.ArrayList; |
| 4 | |
import java.util.Date; |
| 5 | |
import java.util.List; |
| 6 | |
|
| 7 | |
import javax.persistence.CascadeType; |
| 8 | |
import javax.persistence.Column; |
| 9 | |
import javax.persistence.Entity; |
| 10 | |
import javax.persistence.FetchType; |
| 11 | |
import javax.persistence.JoinColumn; |
| 12 | |
import javax.persistence.ManyToOne; |
| 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.r2.common.entity.AttributeOwner; |
| 19 | |
import org.kuali.student.r2.common.entity.MetaEntity; |
| 20 | |
import org.kuali.student.r2.common.infc.Attribute; |
| 21 | |
import org.kuali.student.r2.core.atp.dto.AtpInfo; |
| 22 | |
import org.kuali.student.r2.core.atp.infc.Atp; |
| 23 | |
|
| 24 | |
@Entity |
| 25 | |
@Table(name = "KSEN_ATP") |
| 26 | |
public class AtpEntity extends MetaEntity implements AttributeOwner<AtpAttributeEntity>{ |
| 27 | |
@Column(name = "NAME") |
| 28 | |
private String name; |
| 29 | |
|
| 30 | |
@ManyToOne(cascade = CascadeType.ALL) |
| 31 | |
@JoinColumn(name = "RT_DESCR_ID") |
| 32 | |
private AtpRichTextEntity descr; |
| 33 | |
|
| 34 | |
@Temporal(TemporalType.TIMESTAMP) |
| 35 | |
@Column(name = "START_DT") |
| 36 | |
private Date startDate; |
| 37 | |
|
| 38 | |
@Temporal(TemporalType.TIMESTAMP) |
| 39 | |
@Column(name = "END_DT") |
| 40 | |
private Date endDate; |
| 41 | |
|
| 42 | |
|
| 43 | |
@ManyToOne(cascade = CascadeType.ALL) |
| 44 | |
@JoinColumn(name = "ATP_TYPE_ID") |
| 45 | |
private AtpTypeEntity atpType; |
| 46 | |
|
| 47 | |
@ManyToOne(cascade = CascadeType.ALL) |
| 48 | |
@JoinColumn(name = "ATP_STATE_ID") |
| 49 | |
private AtpStateEntity atpState; |
| 50 | |
|
| 51 | |
@OneToMany(cascade = CascadeType.ALL, fetch=FetchType.EAGER) |
| 52 | |
private List<AtpAttributeEntity> attributes; |
| 53 | |
|
| 54 | |
|
| 55 | 0 | public AtpEntity(){} |
| 56 | |
|
| 57 | 0 | public AtpEntity(Atp atp){ |
| 58 | |
try{ |
| 59 | 0 | this.setId(atp.getKey()); |
| 60 | 0 | this.setName(atp.getName()); |
| 61 | |
|
| 62 | 0 | if (atp.getStartDate() != null) |
| 63 | 0 | this.setStartDate(atp.getStartDate()); |
| 64 | 0 | if (atp.getEndDate() != null) |
| 65 | 0 | this.setEndDate(atp.getEndDate()); |
| 66 | 0 | if(atp.getDescr() != null) |
| 67 | 0 | this.setDescr(new AtpRichTextEntity(atp.getDescr())); |
| 68 | |
|
| 69 | 0 | this.setAttributes(new ArrayList<AtpAttributeEntity>()); |
| 70 | 0 | if (null != atp.getAttributes()) { |
| 71 | 0 | for (Attribute att : atp.getAttributes()) { |
| 72 | 0 | this.getAttributes().add(new AtpAttributeEntity(att)); |
| 73 | |
} |
| 74 | |
} |
| 75 | 0 | }catch (Exception e){ |
| 76 | 0 | e.printStackTrace(); |
| 77 | 0 | } |
| 78 | 0 | } |
| 79 | |
|
| 80 | |
public String getName() { |
| 81 | 0 | return name; |
| 82 | |
} |
| 83 | |
|
| 84 | |
public void setName(String name) { |
| 85 | 0 | this.name = name; |
| 86 | 0 | } |
| 87 | |
|
| 88 | |
public AtpRichTextEntity getDescr() { |
| 89 | 0 | return descr; |
| 90 | |
} |
| 91 | |
|
| 92 | |
public void setDescr(AtpRichTextEntity descr) { |
| 93 | 0 | this.descr = descr; |
| 94 | 0 | } |
| 95 | |
|
| 96 | |
public Date getStartDate() { |
| 97 | 0 | return startDate; |
| 98 | |
} |
| 99 | |
|
| 100 | |
public void setStartDate(Date startDate) { |
| 101 | 0 | this.startDate = startDate; |
| 102 | 0 | } |
| 103 | |
|
| 104 | |
public Date getEndDate() { |
| 105 | 0 | return endDate; |
| 106 | |
} |
| 107 | |
|
| 108 | |
public void setEndDate(Date endDate) { |
| 109 | 0 | this.endDate = endDate; |
| 110 | 0 | } |
| 111 | |
|
| 112 | |
|
| 113 | |
public AtpTypeEntity getAtpType() { |
| 114 | 0 | return atpType; |
| 115 | |
} |
| 116 | |
|
| 117 | |
public void setAtpType(AtpTypeEntity atpType) { |
| 118 | 0 | this.atpType = atpType; |
| 119 | 0 | } |
| 120 | |
|
| 121 | |
public AtpStateEntity getAtpState() { |
| 122 | 0 | return atpState; |
| 123 | |
} |
| 124 | |
|
| 125 | |
public void setAtpState(AtpStateEntity atpState) { |
| 126 | 0 | this.atpState = atpState; |
| 127 | 0 | } |
| 128 | |
|
| 129 | |
@Override |
| 130 | |
public void setAttributes(List<AtpAttributeEntity> attributes) { |
| 131 | 0 | this.attributes = attributes; |
| 132 | |
|
| 133 | 0 | } |
| 134 | |
|
| 135 | |
@Override |
| 136 | |
public List<AtpAttributeEntity> getAttributes() { |
| 137 | 0 | return attributes; |
| 138 | |
} |
| 139 | |
|
| 140 | |
public AtpInfo toDto() { |
| 141 | 0 | AtpInfo atp = AtpInfo.newInstance(); |
| 142 | 0 | atp.setKey(getId()); |
| 143 | 0 | atp.setName(name); |
| 144 | 0 | atp.setStartDate(startDate); |
| 145 | 0 | atp.setEndDate(endDate); |
| 146 | 0 | if(atpType != null) |
| 147 | 0 | atp.setTypeKey(atpType.getId()); |
| 148 | 0 | if(atpState != null) |
| 149 | 0 | atp.setStateKey(atpState.getId()); |
| 150 | 0 | atp.setMetaInfo(super.toDTO()); |
| 151 | 0 | if(descr != null) |
| 152 | 0 | atp.setDescr(descr.toDto()); |
| 153 | |
|
| 154 | 0 | List<Attribute> atts = new ArrayList<Attribute>(); |
| 155 | 0 | for (AtpAttributeEntity att : getAttributes()) { |
| 156 | 0 | Attribute attInfo = att.toDto(); |
| 157 | 0 | atts.add(attInfo); |
| 158 | 0 | } |
| 159 | 0 | atp.setAttributes(atts); |
| 160 | |
|
| 161 | 0 | return atp; |
| 162 | |
} |
| 163 | |
} |