| 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.AtpAtpRelationInfo; |
| 22 | |
import org.kuali.student.r2.core.atp.infc.AtpAtpRelation; |
| 23 | |
|
| 24 | |
@Entity |
| 25 | |
@Table(name = "KSEN_ATPATP_RELTN") |
| 26 | |
public class AtpAtpRelationEntity extends MetaEntity implements AttributeOwner<AtpAtpRelationAttributeEntity>{ |
| 27 | |
@ManyToOne |
| 28 | |
@JoinColumn(name="ATP_ID") |
| 29 | |
private AtpEntity atp; |
| 30 | |
|
| 31 | |
@ManyToOne |
| 32 | |
@JoinColumn(name="RELATED_ATP_ID") |
| 33 | |
private AtpEntity relatedAtp; |
| 34 | |
|
| 35 | |
@ManyToOne |
| 36 | |
@JoinColumn(name="ATP_RELTN_TYPE_ID") |
| 37 | |
private AtpAtpRelationTypeEntity atpAtpRelationType; |
| 38 | |
|
| 39 | |
@Temporal(TemporalType.TIMESTAMP) |
| 40 | |
@Column(name = "EFF_DT") |
| 41 | |
private Date effectiveDate; |
| 42 | |
|
| 43 | |
@Temporal(TemporalType.TIMESTAMP) |
| 44 | |
@Column(name = "EXPIR_DT") |
| 45 | |
private Date expirationDate; |
| 46 | |
|
| 47 | |
@ManyToOne(cascade = CascadeType.ALL) |
| 48 | |
@JoinColumn(name = "ATP_STATE_ID") |
| 49 | |
private AtpStateEntity atpState; |
| 50 | |
|
| 51 | |
@OneToMany(cascade = CascadeType.ALL) |
| 52 | |
private List<AtpAtpRelationAttributeEntity> attributes; |
| 53 | |
|
| 54 | 0 | public AtpAtpRelationEntity(){} |
| 55 | |
|
| 56 | 0 | public AtpAtpRelationEntity(AtpAtpRelation atpAtpRelation){ |
| 57 | 0 | this.setId(atpAtpRelation.getId()); |
| 58 | 0 | this.setEffectiveDate(atpAtpRelation.getEffectiveDate()); |
| 59 | 0 | this.setExpirationDate(atpAtpRelation.getExpirationDate()); |
| 60 | |
|
| 61 | 0 | this.setAttributes(new ArrayList<AtpAtpRelationAttributeEntity>()); |
| 62 | 0 | if (null != atpAtpRelation.getAttributes()) { |
| 63 | 0 | for (Attribute att : atpAtpRelation.getAttributes()) { |
| 64 | 0 | this.getAttributes().add(new AtpAtpRelationAttributeEntity(att)); |
| 65 | |
} |
| 66 | |
} |
| 67 | 0 | } |
| 68 | |
|
| 69 | |
public AtpEntity getAtp() { |
| 70 | 0 | return atp; |
| 71 | |
} |
| 72 | |
|
| 73 | |
public void setAtp(AtpEntity atp) { |
| 74 | 0 | this.atp = atp; |
| 75 | 0 | } |
| 76 | |
|
| 77 | |
public AtpEntity getRelatedAtp() { |
| 78 | 0 | return relatedAtp; |
| 79 | |
} |
| 80 | |
|
| 81 | |
public void setRelatedAtp(AtpEntity relatedAtp) { |
| 82 | 0 | this.relatedAtp = relatedAtp; |
| 83 | 0 | } |
| 84 | |
|
| 85 | |
public AtpAtpRelationTypeEntity getAtpAtpRelationType() { |
| 86 | 0 | return atpAtpRelationType; |
| 87 | |
} |
| 88 | |
|
| 89 | |
public void setAtpAtpRelationType(AtpAtpRelationTypeEntity atpAtpRelationType) { |
| 90 | 0 | this.atpAtpRelationType = atpAtpRelationType; |
| 91 | 0 | } |
| 92 | |
|
| 93 | |
public Date getEffectiveDate() { |
| 94 | 0 | return effectiveDate; |
| 95 | |
} |
| 96 | |
|
| 97 | |
public void setEffectiveDate(Date effectiveDate) { |
| 98 | 0 | this.effectiveDate = effectiveDate; |
| 99 | 0 | } |
| 100 | |
|
| 101 | |
public Date getExpirationDate() { |
| 102 | 0 | return expirationDate; |
| 103 | |
} |
| 104 | |
|
| 105 | |
public void setExpirationDate(Date expirationDate) { |
| 106 | 0 | this.expirationDate = expirationDate; |
| 107 | 0 | } |
| 108 | |
|
| 109 | |
|
| 110 | |
public AtpStateEntity getAtpState() { |
| 111 | 0 | return atpState; |
| 112 | |
} |
| 113 | |
|
| 114 | |
public void setAtpState(AtpStateEntity atpState) { |
| 115 | 0 | this.atpState = atpState; |
| 116 | 0 | } |
| 117 | |
|
| 118 | |
@Override |
| 119 | |
public void setAttributes(List<AtpAtpRelationAttributeEntity> attributes) { |
| 120 | 0 | this.attributes = attributes; |
| 121 | 0 | } |
| 122 | |
|
| 123 | |
@Override |
| 124 | |
public List<AtpAtpRelationAttributeEntity> getAttributes() { |
| 125 | 0 | return attributes; |
| 126 | |
} |
| 127 | |
|
| 128 | |
public AtpAtpRelationInfo toDto() { |
| 129 | 0 | AtpAtpRelationInfo aarInfo = AtpAtpRelationInfo.newInstance(); |
| 130 | 0 | aarInfo.setId(getId()); |
| 131 | 0 | aarInfo.setAtpKey(atp.getId()); |
| 132 | 0 | aarInfo.setRelatedAtpKey(relatedAtp.getId()); |
| 133 | 0 | aarInfo.setEffectiveDate(effectiveDate); |
| 134 | 0 | aarInfo.setExpirationDate(expirationDate); |
| 135 | 0 | aarInfo.setStateKey(atpState.getId()); |
| 136 | 0 | aarInfo.setTypeKey(atpAtpRelationType.getId()); |
| 137 | 0 | aarInfo.setMetaInfo(super.toDTO()); |
| 138 | |
|
| 139 | 0 | List<Attribute> atts = new ArrayList<Attribute>(); |
| 140 | 0 | for (AtpAtpRelationAttributeEntity att : getAttributes()) { |
| 141 | 0 | Attribute attInfo = att.toDto(); |
| 142 | 0 | atts.add(attInfo); |
| 143 | 0 | } |
| 144 | 0 | aarInfo.setAttributes(atts); |
| 145 | |
|
| 146 | 0 | return aarInfo; |
| 147 | |
} |
| 148 | |
} |