1 | |
package org.kuali.student.r2.core.class1.process.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.AttributeOwnerNew; |
6 | |
import org.kuali.student.r2.common.entity.MetaEntity; |
7 | |
import org.kuali.student.r2.common.infc.Attribute; |
8 | |
import org.kuali.student.r2.common.util.RichTextHelper; |
9 | |
import org.kuali.student.r2.core.process.dto.ProcessInfo; |
10 | |
import org.kuali.student.r2.core.process.infc.Process; |
11 | |
|
12 | |
import javax.persistence.CascadeType; |
13 | |
import javax.persistence.Column; |
14 | |
import javax.persistence.Entity; |
15 | |
import javax.persistence.OneToMany; |
16 | |
import javax.persistence.Table; |
17 | |
import java.util.ArrayList; |
18 | |
import java.util.List; |
19 | |
|
20 | |
@Entity |
21 | |
@Table(name = "KSEN_PROCESS") |
22 | |
public class ProcessEntity extends MetaEntity implements AttributeOwnerNew<ProcessAttributeEntity> { |
23 | |
|
24 | |
|
25 | |
|
26 | |
|
27 | |
|
28 | |
@Column(name = "PROCESS_TYPE", nullable = false) |
29 | |
private String processType; |
30 | |
|
31 | |
@Column(name = "PROCESS_STATE", nullable = false) |
32 | |
private String processState; |
33 | |
|
34 | |
@Column(name = "NAME") |
35 | |
private String name; |
36 | |
|
37 | |
@Column(name = "DESCR_PLAIN", length = KSEntityConstants.EXTRA_LONG_TEXT_LENGTH) |
38 | |
private String descrPlain; |
39 | |
|
40 | |
@Column(name = "DESCR_FORMATTED", length = KSEntityConstants.EXTRA_LONG_TEXT_LENGTH) |
41 | |
private String descrFormatted; |
42 | |
|
43 | |
@Column(name = "OWNER_ORG_ID") |
44 | |
private String ownerOrgID; |
45 | |
|
46 | |
@OneToMany(cascade = CascadeType.ALL, mappedBy = "owner", orphanRemoval = true) |
47 | |
private List<ProcessAttributeEntity> attributes; |
48 | |
|
49 | |
|
50 | |
|
51 | |
|
52 | |
|
53 | 0 | public ProcessEntity() {} |
54 | |
|
55 | |
public ProcessEntity(Process process){ |
56 | 0 | super(process); |
57 | 0 | this.setId(process.getKey()); |
58 | 0 | this.setProcessType(process.getTypeKey()); |
59 | 0 | fromDTO(process); |
60 | 0 | } |
61 | |
|
62 | |
public void fromDTO(Process process) { |
63 | 0 | this.setProcessState(process.getStateKey()); |
64 | 0 | this.setName(process.getName()); |
65 | 0 | if (process.getDescr() != null) { |
66 | 0 | this.setDescrFormatted(process.getDescr().getFormatted()); |
67 | 0 | this.setDescrPlain(process.getDescr().getPlain()); |
68 | |
} else { |
69 | 0 | this.setDescrFormatted(null); |
70 | 0 | this.setDescrPlain(null); |
71 | |
} |
72 | 0 | this.setOwnerOrgID(process.getOwnerOrgId()); |
73 | 0 | this.setAttributes(new ArrayList<ProcessAttributeEntity>()); |
74 | 0 | for (Attribute att : process.getAttributes()) { |
75 | 0 | this.getAttributes().add(new ProcessAttributeEntity(att, this)); |
76 | |
} |
77 | 0 | } |
78 | |
|
79 | |
|
80 | |
|
81 | |
|
82 | |
public ProcessInfo toDto(){ |
83 | 0 | ProcessInfo processInfo = new ProcessInfo(); |
84 | 0 | processInfo.setMeta(super.toDTO()); |
85 | 0 | processInfo.setKey(getId()); |
86 | 0 | processInfo.setTypeKey(processType); |
87 | 0 | processInfo.setStateKey(processState); |
88 | 0 | processInfo.setName(name); |
89 | 0 | processInfo.setDescr(new RichTextHelper().toRichTextInfo(descrPlain, descrFormatted)); |
90 | 0 | processInfo.setOwnerOrgId(getOwnerOrgID()); |
91 | 0 | List<AttributeInfo> attributes = processInfo.getAttributes(); |
92 | 0 | if (getAttributes() != null) { |
93 | 0 | for (ProcessAttributeEntity att : getAttributes()) { |
94 | 0 | AttributeInfo attInfo = att.toDto(); |
95 | 0 | attributes.add(attInfo); |
96 | 0 | } |
97 | |
} |
98 | 0 | return processInfo; |
99 | |
} |
100 | |
|
101 | |
|
102 | |
|
103 | |
|
104 | |
|
105 | |
public String getProcessType() { |
106 | 0 | return processType; |
107 | |
} |
108 | |
|
109 | |
public void setProcessType(String processType) { |
110 | 0 | this.processType = processType; |
111 | 0 | } |
112 | |
|
113 | |
public String getProcessState() { |
114 | 0 | return processState; |
115 | |
} |
116 | |
|
117 | |
public void setProcessState(String processState) { |
118 | 0 | this.processState = processState; |
119 | 0 | } |
120 | |
|
121 | |
public String getName() { |
122 | 0 | return name; |
123 | |
} |
124 | |
|
125 | |
public void setName(String name) { |
126 | 0 | this.name = name; |
127 | 0 | } |
128 | |
|
129 | |
public String getDescrPlain() { |
130 | 0 | return descrPlain; |
131 | |
} |
132 | |
|
133 | |
public void setDescrPlain(String descrPlain) { |
134 | 0 | this.descrPlain = descrPlain; |
135 | 0 | } |
136 | |
|
137 | |
public String getDescrFormatted() { |
138 | 0 | return descrFormatted; |
139 | |
} |
140 | |
|
141 | |
public void setDescrFormatted(String descrFormatted) { |
142 | 0 | this.descrFormatted = descrFormatted; |
143 | 0 | } |
144 | |
|
145 | |
public String getOwnerOrgID() { |
146 | 0 | return ownerOrgID; |
147 | |
} |
148 | |
|
149 | |
public void setOwnerOrgID(String ownerOrgID) { |
150 | 0 | this.ownerOrgID = ownerOrgID; |
151 | 0 | } |
152 | |
|
153 | |
@Override |
154 | |
public List<ProcessAttributeEntity> getAttributes() { |
155 | 0 | return attributes; |
156 | |
} |
157 | |
|
158 | |
@Override |
159 | |
public void setAttributes(List<ProcessAttributeEntity> attributes) { |
160 | 0 | this.attributes = attributes; |
161 | 0 | } |
162 | |
} |