| 1 | |
package org.kuali.student.enrollment.class1.lui.model; |
| 2 | |
|
| 3 | |
import java.util.ArrayList; |
| 4 | |
import java.util.List; |
| 5 | |
|
| 6 | |
import javax.persistence.CascadeType; |
| 7 | |
import javax.persistence.Column; |
| 8 | |
import javax.persistence.Entity; |
| 9 | |
import javax.persistence.JoinColumn; |
| 10 | |
import javax.persistence.ManyToOne; |
| 11 | |
import javax.persistence.OneToMany; |
| 12 | |
import javax.persistence.Table; |
| 13 | |
|
| 14 | |
import org.kuali.student.common.entity.KSEntityConstants; |
| 15 | |
import org.kuali.student.r2.common.dto.AttributeInfo; |
| 16 | |
import org.kuali.student.r2.common.dto.RichTextInfo; |
| 17 | |
import org.kuali.student.r2.common.entity.AttributeOwner; |
| 18 | |
import org.kuali.student.r2.common.entity.MetaEntity; |
| 19 | |
import org.kuali.student.r2.common.infc.Attribute; |
| 20 | |
import org.kuali.student.r2.common.infc.RichText; |
| 21 | |
import org.kuali.student.r2.lum.clu.dto.LuCodeInfo; |
| 22 | |
import org.kuali.student.r2.lum.clu.infc.LuCode; |
| 23 | |
|
| 24 | |
@Entity |
| 25 | |
@Table(name = "KSEN_LUI_LU_CD") |
| 26 | |
public class LuCodeEntity extends MetaEntity implements AttributeOwner<LuCodeAttributeEntity> { |
| 27 | |
|
| 28 | |
@Column(name = "DESCR_FORMATTED", length = KSEntityConstants.EXTRA_LONG_TEXT_LENGTH) |
| 29 | |
private String formatted; |
| 30 | |
@Column(name = "DESCR_PLAIN", length = KSEntityConstants.EXTRA_LONG_TEXT_LENGTH) |
| 31 | |
private String plain; |
| 32 | |
@Column(name = "VALUE") |
| 33 | |
private String value; |
| 34 | |
@Column(name = "LUI_LUCD_TYPE") |
| 35 | |
private String type; |
| 36 | |
@ManyToOne |
| 37 | |
@JoinColumn(name = "LUI_ID") |
| 38 | |
private LuiEntity lui; |
| 39 | |
@OneToMany(cascade = CascadeType.ALL, mappedBy = "owner") |
| 40 | |
private List<LuCodeAttributeEntity> attributes; |
| 41 | |
|
| 42 | 0 | public LuCodeEntity() { |
| 43 | 0 | } |
| 44 | |
|
| 45 | |
public LuCodeEntity(LuCode luCode) { |
| 46 | 0 | super(luCode); |
| 47 | 0 | this.setId(luCode.getId()); |
| 48 | 0 | this.setType(luCode.getTypeKey()); |
| 49 | 0 | this.setValue(luCode.getValue()); |
| 50 | 0 | if (luCode.getDescr() != null) { |
| 51 | 0 | RichText rt = luCode.getDescr(); |
| 52 | 0 | this.setDescrFormatted(rt.getFormatted()); |
| 53 | 0 | this.setDescrPlain(rt.getPlain()); |
| 54 | |
} |
| 55 | 0 | this.setAttributes(new ArrayList<LuCodeAttributeEntity>()); |
| 56 | 0 | if (null != luCode.getAttributes()) { |
| 57 | 0 | for (Attribute att : luCode.getAttributes()) { |
| 58 | 0 | LuCodeAttributeEntity attEntity = new LuCodeAttributeEntity(att); |
| 59 | 0 | this.getAttributes().add(attEntity); |
| 60 | 0 | } |
| 61 | |
} |
| 62 | 0 | } |
| 63 | |
|
| 64 | |
public LuCodeInfo toDto() { |
| 65 | 0 | LuCodeInfo obj = new LuCodeInfo(); |
| 66 | 0 | obj.setId(getId()); |
| 67 | 0 | obj.setTypeKey(type); |
| 68 | 0 | obj.setValue(value); |
| 69 | 0 | if (getDescrPlain() != null) { |
| 70 | 0 | RichTextInfo rti = new RichTextInfo(); |
| 71 | 0 | rti.setPlain(getDescrPlain()); |
| 72 | 0 | rti.setFormatted(getDescrFormatted()); |
| 73 | 0 | obj.setDescr(rti); |
| 74 | |
} |
| 75 | 0 | obj.setMeta(super.toDTO()); |
| 76 | 0 | List<AttributeInfo> atts = new ArrayList<AttributeInfo>(); |
| 77 | 0 | for (LuCodeAttributeEntity att : getAttributes()) { |
| 78 | 0 | AttributeInfo attInfo = att.toDto(); |
| 79 | 0 | atts.add(attInfo); |
| 80 | 0 | } |
| 81 | 0 | obj.setAttributes(atts); |
| 82 | |
|
| 83 | 0 | return obj; |
| 84 | |
} |
| 85 | |
|
| 86 | |
public String getDescrFormatted() { |
| 87 | 0 | return formatted; |
| 88 | |
} |
| 89 | |
|
| 90 | |
public void setDescrFormatted(String formatted) { |
| 91 | 0 | this.formatted = formatted; |
| 92 | 0 | } |
| 93 | |
|
| 94 | |
public String getDescrPlain() { |
| 95 | 0 | return plain; |
| 96 | |
} |
| 97 | |
|
| 98 | |
public void setDescrPlain(String plain) { |
| 99 | 0 | this.plain = plain; |
| 100 | 0 | } |
| 101 | |
|
| 102 | |
public String getValue() { |
| 103 | 0 | return value; |
| 104 | |
} |
| 105 | |
|
| 106 | |
public void setValue(String value) { |
| 107 | 0 | this.value = value; |
| 108 | 0 | } |
| 109 | |
|
| 110 | |
public String getType() { |
| 111 | 0 | return type; |
| 112 | |
} |
| 113 | |
|
| 114 | |
public void setType(String type) { |
| 115 | 0 | this.type = type; |
| 116 | 0 | } |
| 117 | |
|
| 118 | |
public LuiEntity getLui() { |
| 119 | 0 | return lui; |
| 120 | |
} |
| 121 | |
|
| 122 | |
public void setLui(LuiEntity lui) { |
| 123 | 0 | this.lui = lui; |
| 124 | 0 | } |
| 125 | |
|
| 126 | |
@Override |
| 127 | |
public void setAttributes(List<LuCodeAttributeEntity> attributes) { |
| 128 | 0 | this.attributes = attributes; |
| 129 | 0 | } |
| 130 | |
|
| 131 | |
@Override |
| 132 | |
public List<LuCodeAttributeEntity> getAttributes() { |
| 133 | 0 | return attributes; |
| 134 | |
} |
| 135 | |
} |