1 | |
package org.kuali.student.r2.core.process.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.r2.common.dto.AttributeInfo; |
15 | |
import org.kuali.student.r2.common.entity.AttributeOwner; |
16 | |
import org.kuali.student.r2.common.entity.MetaEntity; |
17 | |
import org.kuali.student.r2.common.infc.Attribute; |
18 | |
import org.kuali.student.r2.core.class1.state.model.StateEntity; |
19 | |
import org.kuali.student.r2.core.process.dto.ProcessInfo; |
20 | |
import org.kuali.student.r2.core.process.infc.Process; |
21 | |
|
22 | |
@Entity |
23 | |
@Table(name = "KSEN_PROCESS") |
24 | |
public class ProcessEntity extends MetaEntity implements AttributeOwner<ProcessAttributeEntity>{ |
25 | |
|
26 | |
@Column(name = "NAME") |
27 | |
private String name; |
28 | |
|
29 | |
@ManyToOne(cascade = CascadeType.ALL) |
30 | |
@JoinColumn(name = "RT_DESCR_ID") |
31 | |
private ProcessRichTextEntity descr; |
32 | |
|
33 | |
@Column(name = "PROCESS_STATE") |
34 | |
private String processState; |
35 | |
|
36 | |
@Column(name = "PROCESS_TYPE") |
37 | |
private String processType; |
38 | |
|
39 | |
@Column(name = "OWNER_ORG_ID") |
40 | |
private String ownerOrgID; |
41 | |
|
42 | |
@OneToMany(cascade = CascadeType.ALL, mappedBy = "owner",orphanRemoval = true) |
43 | |
private List<ProcessAttributeEntity> attributes; |
44 | |
|
45 | 0 | public ProcessEntity(){ |
46 | |
|
47 | 0 | } |
48 | |
|
49 | |
public ProcessEntity(Process process){ |
50 | 0 | super(process); |
51 | |
|
52 | 0 | this.setId(process.getKey()); |
53 | 0 | this.setName(process.getName()); |
54 | |
|
55 | 0 | if(process.getDescr() != null) { |
56 | 0 | this.setDescr(new ProcessRichTextEntity(process.getDescr())); |
57 | |
} |
58 | 0 | this.setProcessType (process.getTypeKey()); |
59 | 0 | this.setProcessState(process.getStateKey()); |
60 | 0 | this.setOwnerOrgID(process.getOwnerOrgId()); |
61 | |
|
62 | 0 | this.setAttributes(new ArrayList<ProcessAttributeEntity>()); |
63 | 0 | if (null != process.getAttributes()) { |
64 | 0 | for (Attribute att : process.getAttributes()) { |
65 | 0 | ProcessAttributeEntity attEntity = new ProcessAttributeEntity(att); |
66 | 0 | this.getAttributes().add(attEntity); |
67 | 0 | } |
68 | |
} |
69 | |
|
70 | 0 | } |
71 | |
|
72 | |
|
73 | |
|
74 | |
|
75 | |
public ProcessInfo toDto(){ |
76 | |
|
77 | 0 | ProcessInfo obj = new ProcessInfo(); |
78 | |
|
79 | 0 | obj.setKey(getId()); |
80 | 0 | obj.setName(name); |
81 | 0 | obj.setOwnerOrgId(getOwnerOrgID()); |
82 | |
|
83 | 0 | if (processType != null){ |
84 | 0 | obj.setTypeKey(processType); |
85 | |
} |
86 | |
|
87 | 0 | if (processState != null){ |
88 | 0 | obj.setStateKey(processState); |
89 | |
} |
90 | |
|
91 | 0 | obj.setMeta(super.toDTO()); |
92 | |
|
93 | 0 | if (descr != null){ |
94 | 0 | obj.setDescr(descr.toDto()); |
95 | |
} |
96 | |
|
97 | 0 | List<AttributeInfo> atts = new ArrayList<AttributeInfo>(); |
98 | 0 | for (ProcessAttributeEntity att : getAttributes()) { |
99 | 0 | AttributeInfo attInfo = att.toDto(); |
100 | 0 | atts.add(attInfo); |
101 | 0 | } |
102 | 0 | obj.setAttributes(atts); |
103 | |
|
104 | 0 | return obj; |
105 | |
} |
106 | |
|
107 | |
|
108 | 0 | public String getName() { return name; } |
109 | 0 | public void setName(String name) { this.name = name; } |
110 | |
|
111 | |
|
112 | 0 | public ProcessRichTextEntity getDescr() { return descr; } |
113 | 0 | public void setDescr(ProcessRichTextEntity descr) { this.descr = descr; } |
114 | |
|
115 | |
|
116 | |
public String getProcessState() { |
117 | 0 | return processState; |
118 | |
} |
119 | |
public void setProcessState(String processState) { |
120 | 0 | this.processState = processState; |
121 | 0 | } |
122 | |
|
123 | |
|
124 | |
public String getProcessType() { |
125 | 0 | return processType; |
126 | |
} |
127 | |
public void setProcessType(String processType) { |
128 | 0 | this.processType = processType; |
129 | 0 | } |
130 | |
|
131 | |
|
132 | 0 | public String getOwnerOrgID() { return ownerOrgID; } |
133 | 0 | public void setOwnerOrgID(String ownerOrgID) { this.ownerOrgID = ownerOrgID; } |
134 | |
|
135 | |
@Override |
136 | |
public List<ProcessAttributeEntity> getAttributes() { |
137 | 0 | return attributes; |
138 | |
} |
139 | |
|
140 | |
@Override |
141 | |
public void setAttributes(List<ProcessAttributeEntity> attributes) { |
142 | 0 | this.attributes = attributes; |
143 | 0 | } |
144 | |
} |