| 1 | |
package org.kuali.student.enrollment.class2.courseofferingset.model; |
| 2 | |
|
| 3 | |
import org.kuali.student.common.entity.KSEntityConstants; |
| 4 | |
import org.kuali.student.r2.common.dto.AttributeInfo; |
| 5 | |
import org.kuali.student.r2.common.entity.MetaEntity; |
| 6 | |
import org.kuali.student.r2.common.infc.Attribute; |
| 7 | |
import org.kuali.student.r2.common.util.RichTextHelper; |
| 8 | |
|
| 9 | |
import javax.persistence.CascadeType; |
| 10 | |
import javax.persistence.Column; |
| 11 | |
import javax.persistence.Entity; |
| 12 | |
import javax.persistence.OneToMany; |
| 13 | |
import javax.persistence.Table; |
| 14 | |
import java.util.ArrayList; |
| 15 | |
import java.util.List; |
| 16 | |
import org.kuali.student.enrollment.courseofferingset.dto.SocInfo; |
| 17 | |
import org.kuali.student.enrollment.courseofferingset.infc.Soc; |
| 18 | |
|
| 19 | |
@Entity |
| 20 | |
@Table(name = "KSEN_SOC") |
| 21 | |
public class SocEntity extends MetaEntity { |
| 22 | |
|
| 23 | |
@Column(name = "SOC_TYPE", nullable = false) |
| 24 | |
private String socType; |
| 25 | |
@Column(name = "SOC_STATE", nullable = false) |
| 26 | |
private String socState; |
| 27 | |
@Column(name = "NAME") |
| 28 | |
private String name; |
| 29 | |
@Column(name = "DESCR_FORMATTED", length = KSEntityConstants.EXTRA_LONG_TEXT_LENGTH) |
| 30 | |
private String formatted; |
| 31 | |
@Column(name = "DESCR_PLAIN", length = KSEntityConstants.EXTRA_LONG_TEXT_LENGTH) |
| 32 | |
private String plain; |
| 33 | |
@Column(name = "TERM_ID") |
| 34 | |
private String termId; |
| 35 | |
@Column(name = "SUBJECT_AREA") |
| 36 | |
private String subjectArea; |
| 37 | |
@Column(name = "UNITS_CONTENT_OWNER_ID") |
| 38 | |
private String unitsContentOwnerId; |
| 39 | 0 | @OneToMany(cascade = CascadeType.ALL, mappedBy = "owner") |
| 40 | |
private List<SocAttributeEntity> attributes = new ArrayList<SocAttributeEntity>(); |
| 41 | |
|
| 42 | 0 | public SocEntity() { |
| 43 | 0 | } |
| 44 | |
|
| 45 | |
public SocEntity(Soc soc) { |
| 46 | 0 | super(soc); |
| 47 | 0 | this.setId(soc.getId()); |
| 48 | 0 | this.setSocType(soc.getTypeKey()); |
| 49 | 0 | this.setTermId(soc.getTermId()); |
| 50 | 0 | this.fromDTO(soc); |
| 51 | 0 | } |
| 52 | |
|
| 53 | |
public void fromDTO(Soc soc) { |
| 54 | 0 | this.setSocState(soc.getStateKey()); |
| 55 | 0 | this.setName(soc.getName()); |
| 56 | 0 | if (soc.getDescr() != null) { |
| 57 | 0 | this.setDescrFormatted(soc.getDescr().getFormatted()); |
| 58 | 0 | this.setDescrPlain(soc.getDescr().getPlain()); |
| 59 | |
} else { |
| 60 | 0 | this.setDescrFormatted(null); |
| 61 | 0 | this.setDescrPlain(null); |
| 62 | |
} |
| 63 | 0 | this.setSubjectArea(soc.getSubjectArea()); |
| 64 | 0 | this.setUnitsContentOwnerId(soc.getUnitsContentOwnerId()); |
| 65 | 0 | this.setAttributes(new ArrayList<SocAttributeEntity>()); |
| 66 | 0 | for (Attribute att : soc.getAttributes()) { |
| 67 | 0 | this.getAttributes().add(new SocAttributeEntity(att, this)); |
| 68 | |
} |
| 69 | 0 | } |
| 70 | |
|
| 71 | |
public String getName() { |
| 72 | 0 | return name; |
| 73 | |
} |
| 74 | |
|
| 75 | |
public void setName(String name) { |
| 76 | 0 | this.name = name; |
| 77 | 0 | } |
| 78 | |
|
| 79 | |
|
| 80 | |
public String getSocType() { |
| 81 | 0 | return socType; |
| 82 | |
} |
| 83 | |
|
| 84 | |
public void setSocType(String socType) { |
| 85 | 0 | this.socType = socType; |
| 86 | 0 | } |
| 87 | |
|
| 88 | |
public String getSocState() { |
| 89 | 0 | return socState; |
| 90 | |
} |
| 91 | |
|
| 92 | |
public void setSocState(String socState) { |
| 93 | 0 | this.socState = socState; |
| 94 | 0 | } |
| 95 | |
|
| 96 | |
public void setAttributes(List<SocAttributeEntity> attributes) { |
| 97 | 0 | this.attributes = attributes; |
| 98 | |
|
| 99 | 0 | } |
| 100 | |
|
| 101 | |
public List<SocAttributeEntity> getAttributes() { |
| 102 | 0 | return attributes; |
| 103 | |
} |
| 104 | |
|
| 105 | |
public SocInfo toDto() { |
| 106 | 0 | SocInfo soc = new SocInfo(); |
| 107 | 0 | soc.setId(getId()); |
| 108 | 0 | soc.setTypeKey(socType); |
| 109 | 0 | soc.setStateKey(socState); |
| 110 | 0 | soc.setName(name); |
| 111 | 0 | soc.setDescr(new RichTextHelper().toRichTextInfo(getDescrPlain(), getDescrFormatted())); |
| 112 | 0 | soc.setTermId(termId); |
| 113 | 0 | soc.setSubjectArea(subjectArea); |
| 114 | 0 | soc.setUnitsContentOwnerId(unitsContentOwnerId); |
| 115 | 0 | soc.setMeta(super.toDTO()); |
| 116 | 0 | if (getAttributes() != null) { |
| 117 | 0 | for (SocAttributeEntity att : getAttributes()) { |
| 118 | 0 | AttributeInfo attInfo = att.toDto(); |
| 119 | 0 | soc.getAttributes().add(attInfo); |
| 120 | 0 | } |
| 121 | |
} |
| 122 | |
|
| 123 | 0 | return soc; |
| 124 | |
} |
| 125 | |
|
| 126 | |
public String getDescrFormatted() { |
| 127 | 0 | return formatted; |
| 128 | |
} |
| 129 | |
|
| 130 | |
public void setDescrFormatted(String formatted) { |
| 131 | 0 | this.formatted = formatted; |
| 132 | 0 | } |
| 133 | |
|
| 134 | |
public String getDescrPlain() { |
| 135 | 0 | return plain; |
| 136 | |
} |
| 137 | |
|
| 138 | |
public void setDescrPlain(String plain) { |
| 139 | 0 | this.plain = plain; |
| 140 | 0 | } |
| 141 | |
|
| 142 | |
public String getSubjectArea() { |
| 143 | 0 | return subjectArea; |
| 144 | |
} |
| 145 | |
|
| 146 | |
public void setSubjectArea(String subjectArea) { |
| 147 | 0 | this.subjectArea = subjectArea; |
| 148 | 0 | } |
| 149 | |
|
| 150 | |
public String getTermId() { |
| 151 | 0 | return termId; |
| 152 | |
} |
| 153 | |
|
| 154 | |
public void setTermId(String termId) { |
| 155 | 0 | this.termId = termId; |
| 156 | 0 | } |
| 157 | |
|
| 158 | |
public String getUnitsContentOwnerId() { |
| 159 | 0 | return unitsContentOwnerId; |
| 160 | |
} |
| 161 | |
|
| 162 | |
public void setUnitsContentOwnerId(String unitsContentOwnerId) { |
| 163 | 0 | this.unitsContentOwnerId = unitsContentOwnerId; |
| 164 | 0 | } |
| 165 | |
|
| 166 | |
|
| 167 | |
} |