1 | |
package org.kuali.student.r2.core.class1.state.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.OneToMany; |
10 | |
import javax.persistence.Table; |
11 | |
|
12 | |
import org.kuali.student.common.entity.KSEntityConstants; |
13 | |
import org.kuali.student.r2.common.dto.AttributeInfo; |
14 | |
import org.kuali.student.r2.common.entity.MetaEntity; |
15 | |
import org.kuali.student.r2.common.infc.Attribute; |
16 | |
import org.kuali.student.r2.common.util.RichTextHelper; |
17 | |
import org.kuali.student.r2.core.state.dto.LifecycleInfo; |
18 | |
import org.kuali.student.r2.core.state.infc.Lifecycle; |
19 | |
|
20 | |
@Entity |
21 | |
@Table(name = "KSEN_STATE_LIFECYCLE") |
22 | |
|
23 | |
|
24 | |
|
25 | |
|
26 | |
public class LifecycleEntity extends MetaEntity { |
27 | |
|
28 | |
@Column(name = "NAME") |
29 | |
private String name; |
30 | |
@Column(name = "DESCR_PLAIN") |
31 | |
private String descrPlain; |
32 | |
@Column(name = "DESCR_FORMATTED", length = KSEntityConstants.EXTRA_LONG_TEXT_LENGTH) |
33 | |
private String descrFormatted; |
34 | |
@Column(name = "REF_OBJECT_URI", length = KSEntityConstants.EXTRA_LONG_TEXT_LENGTH, nullable=false) |
35 | |
private String refObjectUri; |
36 | |
@OneToMany(cascade = CascadeType.ALL, mappedBy = "owner") |
37 | |
private List<LifecycleAttributeEntity> attributes; |
38 | |
|
39 | |
public String getName() { |
40 | 0 | return name; |
41 | |
} |
42 | |
|
43 | |
public void setName(String name) { |
44 | 0 | this.name = name; |
45 | 0 | } |
46 | |
|
47 | |
public List<LifecycleAttributeEntity> getAttributes() { |
48 | 0 | return attributes; |
49 | |
} |
50 | |
|
51 | |
public void setAttributes(List<LifecycleAttributeEntity> attributes) { |
52 | 0 | this.attributes = attributes; |
53 | 0 | } |
54 | |
|
55 | |
public String getDescrFormatted() { |
56 | 0 | return descrFormatted; |
57 | |
} |
58 | |
|
59 | |
public void setDescrFormatted(String descrFormatted) { |
60 | 0 | this.descrFormatted = descrFormatted; |
61 | 0 | } |
62 | |
|
63 | |
public String getDescrPlain() { |
64 | 0 | return descrPlain; |
65 | |
} |
66 | |
|
67 | |
public void setDescrPlain(String descrPlain) { |
68 | 0 | this.descrPlain = descrPlain; |
69 | 0 | } |
70 | |
|
71 | |
public String getRefObjectUri() { |
72 | 0 | return refObjectUri; |
73 | |
} |
74 | |
|
75 | |
public void setRefObjectUri(String refObjectUri) { |
76 | 0 | this.refObjectUri = refObjectUri; |
77 | 0 | } |
78 | |
|
79 | 0 | public LifecycleEntity() { |
80 | 0 | } |
81 | |
|
82 | |
public LifecycleEntity(Lifecycle lifecycle) { |
83 | 0 | super(); |
84 | 0 | this.setId(lifecycle.getKey()); |
85 | 0 | this.fromDto(lifecycle); |
86 | 0 | } |
87 | |
|
88 | |
public void fromDto(Lifecycle lifecycle) { |
89 | 0 | this.setName(lifecycle.getName()); |
90 | 0 | this.refObjectUri = lifecycle.getRefObjectUri(); |
91 | 0 | if (lifecycle.getDescr() == null) { |
92 | 0 | this.descrPlain = null; |
93 | 0 | this.descrFormatted = null; |
94 | |
} else { |
95 | 0 | this.descrPlain = lifecycle.getDescr().getPlain(); |
96 | 0 | this.descrFormatted = lifecycle.getDescr().getFormatted(); |
97 | |
} |
98 | 0 | this.setAttributes(new ArrayList<LifecycleAttributeEntity>()); |
99 | 0 | for (Attribute att : lifecycle.getAttributes()) { |
100 | 0 | LifecycleAttributeEntity attEntity = new LifecycleAttributeEntity(att); |
101 | 0 | this.getAttributes().add(attEntity); |
102 | 0 | } |
103 | 0 | } |
104 | |
|
105 | |
public LifecycleInfo toDto() { |
106 | 0 | LifecycleInfo info = new LifecycleInfo(); |
107 | 0 | info.setKey(getId()); |
108 | 0 | info.setName(name); |
109 | 0 | info.setDescr(new RichTextHelper().toRichTextInfo(descrPlain, descrFormatted)); |
110 | 0 | info.setRefObjectUri(this.refObjectUri); |
111 | 0 | info.setMeta(super.toDTO()); |
112 | 0 | if (attributes != null) { |
113 | 0 | for (LifecycleAttributeEntity att : attributes) { |
114 | 0 | AttributeInfo attInfo = att.toDto(); |
115 | 0 | info.getAttributes().add(attInfo); |
116 | 0 | } |
117 | |
} |
118 | 0 | return info; |
119 | |
} |
120 | |
} |