| 1 | |
package org.kuali.student.enrollment.class1.lui.model; |
| 2 | |
|
| 3 | |
import org.kuali.student.common.entity.KSEntityConstants; |
| 4 | |
import org.kuali.student.enrollment.lui.dto.LuiLuiRelationInfo; |
| 5 | |
import org.kuali.student.enrollment.lui.infc.LuiLuiRelation; |
| 6 | |
import org.kuali.student.r2.common.dto.AttributeInfo; |
| 7 | |
import org.kuali.student.r2.common.entity.MetaEntity; |
| 8 | |
import org.kuali.student.r2.common.infc.Attribute; |
| 9 | |
import org.kuali.student.r2.common.util.RichTextHelper; |
| 10 | |
|
| 11 | |
import javax.persistence.*; |
| 12 | |
import java.util.ArrayList; |
| 13 | |
import java.util.Date; |
| 14 | |
import java.util.List; |
| 15 | |
|
| 16 | |
@Entity |
| 17 | |
@Table(name = "KSEN_LUILUI_RELTN") |
| 18 | |
public class LuiLuiRelationEntity extends MetaEntity { |
| 19 | |
|
| 20 | |
@Column(name = "NAME") |
| 21 | |
private String name; |
| 22 | |
@Column(name = "DESCR_FORMATTED", length = KSEntityConstants.EXTRA_LONG_TEXT_LENGTH) |
| 23 | |
private String formatted; |
| 24 | |
@Column(name = "DESCR_PLAIN", length = KSEntityConstants.EXTRA_LONG_TEXT_LENGTH) |
| 25 | |
private String plain; |
| 26 | |
@ManyToOne |
| 27 | |
@JoinColumn(name = "LUI_ID") |
| 28 | |
private LuiEntity lui; |
| 29 | |
@ManyToOne |
| 30 | |
@JoinColumn(name = "RELATED_LUI_ID") |
| 31 | |
private LuiEntity relatedLui; |
| 32 | |
@Column(name = "LUILUI_RELTN_TYPE") |
| 33 | |
private String luiLuiRelationType; |
| 34 | |
@Column(name = "LUILUI_RELTN_STATE") |
| 35 | |
private String luiLuiRelationState; |
| 36 | |
@Temporal(TemporalType.TIMESTAMP) |
| 37 | |
@Column(name = "EFF_DT") |
| 38 | |
private Date effectiveDate; |
| 39 | |
@Temporal(TemporalType.TIMESTAMP) |
| 40 | |
@Column(name = "EXPIR_DT") |
| 41 | |
private Date expirationDate; |
| 42 | |
@OneToMany(cascade = CascadeType.ALL, mappedBy = "owner") |
| 43 | |
private List<LuiLuiRelationAttributeEntity> attributes; |
| 44 | |
|
| 45 | 0 | public LuiLuiRelationEntity() { |
| 46 | 0 | } |
| 47 | |
|
| 48 | 0 | public LuiLuiRelationEntity(LuiLuiRelation luiLuiRelation) { |
| 49 | 0 | this.setId(luiLuiRelation.getId()); |
| 50 | 0 | this.setLuiLuiRelationType(luiLuiRelation.getTypeKey()); |
| 51 | 0 | fromDto(luiLuiRelation); |
| 52 | 0 | } |
| 53 | |
|
| 54 | |
public void fromDto(LuiLuiRelation luiLuiRelation) { |
| 55 | 0 | this.setEffectiveDate(luiLuiRelation.getEffectiveDate()); |
| 56 | 0 | this.setExpirationDate(luiLuiRelation.getExpirationDate()); |
| 57 | 0 | this.setLuiLuiRelationState(luiLuiRelation.getStateKey()); |
| 58 | 0 | this.setName(luiLuiRelation.getName()); |
| 59 | 0 | if (luiLuiRelation.getDescr() == null) { |
| 60 | 0 | this.setDescrFormatted(null); |
| 61 | 0 | this.setDescrPlain(null); |
| 62 | |
} else { |
| 63 | 0 | this.setDescrFormatted(luiLuiRelation.getDescr().getFormatted()); |
| 64 | 0 | this.setDescrPlain(luiLuiRelation.getDescr().getPlain()); |
| 65 | |
} |
| 66 | 0 | this.setAttributes(new ArrayList<LuiLuiRelationAttributeEntity>()); |
| 67 | 0 | for (Attribute att : luiLuiRelation.getAttributes()) { |
| 68 | 0 | this.getAttributes().add(new LuiLuiRelationAttributeEntity(att)); |
| 69 | |
} |
| 70 | 0 | } |
| 71 | |
|
| 72 | |
public LuiLuiRelationInfo toDto() { |
| 73 | 0 | LuiLuiRelationInfo info = new LuiLuiRelationInfo(); |
| 74 | 0 | info.setId(getId()); |
| 75 | 0 | if (lui != null) { |
| 76 | 0 | info.setLuiId(lui.getId()); |
| 77 | |
} |
| 78 | 0 | if (relatedLui != null) { |
| 79 | 0 | info.setRelatedLuiId(relatedLui.getId()); |
| 80 | |
} |
| 81 | 0 | info.setEffectiveDate(effectiveDate); |
| 82 | 0 | info.setExpirationDate(expirationDate); |
| 83 | 0 | info.setStateKey(luiLuiRelationState); |
| 84 | 0 | info.setTypeKey(luiLuiRelationType); |
| 85 | 0 | info.setMeta(super.toDTO()); |
| 86 | 0 | info.setDescr(new RichTextHelper().toRichTextInfo(plain, formatted)); |
| 87 | 0 | if (getAttributes() != null) { |
| 88 | 0 | for (LuiLuiRelationAttributeEntity att : getAttributes()) { |
| 89 | 0 | AttributeInfo attInfo = att.toDto(); |
| 90 | 0 | info.getAttributes().add(attInfo); |
| 91 | 0 | } |
| 92 | |
} |
| 93 | 0 | return info; |
| 94 | |
} |
| 95 | |
|
| 96 | |
public String getName() { |
| 97 | 0 | return name; |
| 98 | |
} |
| 99 | |
|
| 100 | |
public void setName(String name) { |
| 101 | 0 | this.name = name; |
| 102 | 0 | } |
| 103 | |
|
| 104 | |
public String getDescrFormatted() { |
| 105 | 0 | return formatted; |
| 106 | |
} |
| 107 | |
|
| 108 | |
public void setDescrFormatted(String formatted) { |
| 109 | 0 | this.formatted = formatted; |
| 110 | 0 | } |
| 111 | |
|
| 112 | |
public String getDescrPlain() { |
| 113 | 0 | return plain; |
| 114 | |
} |
| 115 | |
|
| 116 | |
public void setDescrPlain(String plain) { |
| 117 | 0 | this.plain = plain; |
| 118 | 0 | } |
| 119 | |
|
| 120 | |
public LuiEntity getLui() { |
| 121 | 0 | return lui; |
| 122 | |
} |
| 123 | |
|
| 124 | |
public void setLui(LuiEntity lui) { |
| 125 | 0 | this.lui = lui; |
| 126 | 0 | } |
| 127 | |
|
| 128 | |
public LuiEntity getRelatedLui() { |
| 129 | 0 | return relatedLui; |
| 130 | |
} |
| 131 | |
|
| 132 | |
public void setRelatedLui(LuiEntity relatedLui) { |
| 133 | 0 | this.relatedLui = relatedLui; |
| 134 | 0 | } |
| 135 | |
|
| 136 | |
public String getLuiLuiRelationType() { |
| 137 | 0 | return luiLuiRelationType; |
| 138 | |
} |
| 139 | |
|
| 140 | |
public void setLuiLuiRelationType(String luiLuiRelationType) { |
| 141 | 0 | this.luiLuiRelationType = luiLuiRelationType; |
| 142 | 0 | } |
| 143 | |
|
| 144 | |
public String getLuiLuiRelationState() { |
| 145 | 0 | return luiLuiRelationState; |
| 146 | |
} |
| 147 | |
|
| 148 | |
public void setLuiLuiRelationState(String luiLuiRelationState) { |
| 149 | 0 | this.luiLuiRelationState = luiLuiRelationState; |
| 150 | 0 | } |
| 151 | |
|
| 152 | |
public Date getEffectiveDate() { |
| 153 | 0 | return effectiveDate; |
| 154 | |
} |
| 155 | |
|
| 156 | |
public void setEffectiveDate(Date effectiveDate) { |
| 157 | 0 | this.effectiveDate = effectiveDate; |
| 158 | 0 | } |
| 159 | |
|
| 160 | |
public Date getExpirationDate() { |
| 161 | 0 | return expirationDate; |
| 162 | |
} |
| 163 | |
|
| 164 | |
public void setExpirationDate(Date expirationDate) { |
| 165 | 0 | this.expirationDate = expirationDate; |
| 166 | 0 | } |
| 167 | |
|
| 168 | |
public void setAttributes(List<LuiLuiRelationAttributeEntity> attributes) { |
| 169 | 0 | this.attributes = attributes; |
| 170 | |
|
| 171 | 0 | } |
| 172 | |
|
| 173 | |
public List<LuiLuiRelationAttributeEntity> getAttributes() { |
| 174 | 0 | return attributes; |
| 175 | |
} |
| 176 | |
} |