| 1 | |
package org.kuali.student.r2.core.class1.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.JoinColumn; |
| 11 | |
import javax.persistence.ManyToOne; |
| 12 | |
import javax.persistence.OneToMany; |
| 13 | |
import javax.persistence.Table; |
| 14 | |
import javax.persistence.Temporal; |
| 15 | |
import javax.persistence.TemporalType; |
| 16 | |
|
| 17 | |
import org.kuali.student.r2.common.dto.AttributeInfo; |
| 18 | |
import org.kuali.student.r2.common.entity.MetaEntity; |
| 19 | |
import org.kuali.student.r2.common.infc.Attribute; |
| 20 | |
import org.kuali.student.r2.core.atp.dto.AtpAtpRelationInfo; |
| 21 | |
import org.kuali.student.r2.core.atp.infc.AtpAtpRelation; |
| 22 | |
|
| 23 | |
@Entity |
| 24 | |
@Table(name = "KSEN_ATPATP_RELTN") |
| 25 | |
public class AtpAtpRelationEntity extends MetaEntity { |
| 26 | |
|
| 27 | |
@ManyToOne |
| 28 | |
@JoinColumn(name = "ATP_ID", nullable = false) |
| 29 | |
private AtpEntity atp; |
| 30 | |
@ManyToOne |
| 31 | |
@JoinColumn(name = "RELATED_ATP_ID", nullable = false) |
| 32 | |
private AtpEntity relatedAtp; |
| 33 | |
@Temporal(TemporalType.TIMESTAMP) |
| 34 | |
@Column(name = "EFF_DT") |
| 35 | |
private Date effectiveDate; |
| 36 | |
@Temporal(TemporalType.TIMESTAMP) |
| 37 | |
@Column(name = "EXPIR_DT") |
| 38 | |
private Date expirationDate; |
| 39 | |
@Column(name = "ATP_TYPE", nullable = false) |
| 40 | |
private String atpType; |
| 41 | |
@Column(name = "ATP_STATE", nullable = false) |
| 42 | |
private String atpState; |
| 43 | |
@OneToMany(cascade = CascadeType.ALL, mappedBy = "owner") |
| 44 | |
private List<AtpAtpRelationAttributeEntity> attributes; |
| 45 | |
|
| 46 | 0 | public AtpAtpRelationEntity() { |
| 47 | 0 | } |
| 48 | |
|
| 49 | 0 | public AtpAtpRelationEntity(AtpAtpRelation atpAtpRelation) { |
| 50 | 0 | this.setId(atpAtpRelation.getId()); |
| 51 | 0 | this.setAtpType(atpAtpRelation.getTypeKey()); |
| 52 | 0 | this.fromDTO(atpAtpRelation); |
| 53 | 0 | } |
| 54 | |
|
| 55 | |
public void fromDTO(AtpAtpRelation atpAtpRelation) { |
| 56 | 0 | this.setAtpState(atpAtpRelation.getStateKey()); |
| 57 | 0 | this.setEffectiveDate(atpAtpRelation.getEffectiveDate()); |
| 58 | 0 | this.setExpirationDate(atpAtpRelation.getExpirationDate()); |
| 59 | 0 | this.setAttributes(new ArrayList<AtpAtpRelationAttributeEntity>()); |
| 60 | 0 | for (Attribute att : atpAtpRelation.getAttributes()) { |
| 61 | 0 | this.getAttributes().add(new AtpAtpRelationAttributeEntity(att)); |
| 62 | |
} |
| 63 | 0 | } |
| 64 | |
|
| 65 | |
public AtpEntity getAtp() { |
| 66 | 0 | return atp; |
| 67 | |
} |
| 68 | |
|
| 69 | |
public void setAtp(AtpEntity atp) { |
| 70 | 0 | this.atp = atp; |
| 71 | 0 | } |
| 72 | |
|
| 73 | |
public AtpEntity getRelatedAtp() { |
| 74 | 0 | return relatedAtp; |
| 75 | |
} |
| 76 | |
|
| 77 | |
public void setRelatedAtp(AtpEntity relatedAtp) { |
| 78 | 0 | this.relatedAtp = relatedAtp; |
| 79 | 0 | } |
| 80 | |
|
| 81 | |
public String getAtpType() { |
| 82 | 0 | return atpType; |
| 83 | |
} |
| 84 | |
|
| 85 | |
public void setAtpType(String atpType) { |
| 86 | 0 | this.atpType = atpType; |
| 87 | 0 | } |
| 88 | |
|
| 89 | |
public Date getEffectiveDate() { |
| 90 | 0 | return effectiveDate != null ? new Date(effectiveDate.getTime()) : null; |
| 91 | |
} |
| 92 | |
|
| 93 | |
public void setEffectiveDate(Date effectiveDate) { |
| 94 | 0 | if (effectiveDate != null) { |
| 95 | 0 | this.effectiveDate = new Date(effectiveDate.getTime()); |
| 96 | |
} |
| 97 | 0 | } |
| 98 | |
|
| 99 | |
public Date getExpirationDate() { |
| 100 | 0 | return expirationDate != null ? new Date(expirationDate.getTime()) : null; |
| 101 | |
} |
| 102 | |
|
| 103 | |
public void setExpirationDate(Date expirationDate) { |
| 104 | 0 | if (expirationDate != null) { |
| 105 | 0 | this.expirationDate = new Date(expirationDate.getTime()); |
| 106 | |
} |
| 107 | 0 | } |
| 108 | |
|
| 109 | |
public String getAtpState() { |
| 110 | 0 | return atpState; |
| 111 | |
} |
| 112 | |
|
| 113 | |
public void setAtpState(String atpState) { |
| 114 | 0 | this.atpState = atpState; |
| 115 | 0 | } |
| 116 | |
|
| 117 | |
public void setAttributes(List<AtpAtpRelationAttributeEntity> attributes) { |
| 118 | 0 | this.attributes = attributes; |
| 119 | 0 | } |
| 120 | |
|
| 121 | |
public List<AtpAtpRelationAttributeEntity> getAttributes() { |
| 122 | 0 | return attributes; |
| 123 | |
} |
| 124 | |
|
| 125 | |
public AtpAtpRelationInfo toDto() { |
| 126 | 0 | AtpAtpRelationInfo info = new AtpAtpRelationInfo(); |
| 127 | 0 | info.setId(getId()); |
| 128 | 0 | info.setAtpId(atp.getId()); |
| 129 | 0 | info.setRelatedAtpId(relatedAtp.getId()); |
| 130 | 0 | info.setEffectiveDate(effectiveDate); |
| 131 | 0 | info.setExpirationDate(expirationDate); |
| 132 | 0 | info.setStateKey(atpState); |
| 133 | 0 | info.setTypeKey(atpType); |
| 134 | 0 | info.setMeta(super.toDTO()); |
| 135 | 0 | if (getAttributes() != null) { |
| 136 | 0 | for (AtpAtpRelationAttributeEntity att : getAttributes()) { |
| 137 | 0 | AttributeInfo attInfo = att.toDto(); |
| 138 | 0 | info.getAttributes().add(attInfo); |
| 139 | 0 | } |
| 140 | |
} |
| 141 | 0 | return info; |
| 142 | |
} |
| 143 | |
} |