1 | |
package org.kuali.student.r2.common.model; |
2 | |
|
3 | |
import java.util.ArrayList; |
4 | |
import java.util.Date; |
5 | |
import java.util.List; |
6 | |
|
7 | |
import javax.persistence.CascadeType; |
8 | |
import javax.persistence.Column; |
9 | |
import javax.persistence.Entity; |
10 | |
import javax.persistence.OneToMany; |
11 | |
import javax.persistence.Table; |
12 | |
import javax.persistence.Temporal; |
13 | |
import javax.persistence.TemporalType; |
14 | |
|
15 | |
import org.kuali.student.r2.common.dto.AttributeInfo; |
16 | |
import org.kuali.student.r2.common.dto.StateProcessInfo; |
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.StateProcess; |
21 | |
import org.kuali.student.r2.core.class1.state.model.StateAttributeEntity; |
22 | |
|
23 | |
@Entity |
24 | |
@Table(name = "KSEN_STATE_PROCESS") |
25 | |
public class StateProcessEntity extends MetaEntity implements AttributeOwner<StateAttributeEntity> { |
26 | |
@Column(name="NAME") |
27 | |
private String name; |
28 | |
|
29 | |
@Column(name="DESCR") |
30 | |
private String description; |
31 | |
|
32 | |
@Temporal(TemporalType.TIMESTAMP) |
33 | |
@Column(name = "EFF_DT") |
34 | |
private Date effectiveDate; |
35 | |
|
36 | |
@Temporal(TemporalType.TIMESTAMP) |
37 | |
@Column(name = "EXPIR_DT") |
38 | |
private Date expirationDate; |
39 | |
|
40 | |
@OneToMany(cascade = CascadeType.ALL, mappedBy = "owner") |
41 | |
private List<StateAttributeEntity> attributes; |
42 | |
|
43 | |
public String getName() { |
44 | 0 | return name; |
45 | |
} |
46 | |
|
47 | |
public void setName(String name) { |
48 | 0 | this.name = name; |
49 | 0 | } |
50 | |
|
51 | |
public String getDescription() { |
52 | 0 | return description; |
53 | |
} |
54 | |
|
55 | |
public void setDescription(String description) { |
56 | 0 | this.description = description; |
57 | 0 | } |
58 | |
|
59 | |
public Date getEffectiveDate() { |
60 | 0 | return effectiveDate; |
61 | |
} |
62 | |
|
63 | |
public void setEffectiveDate(Date effectiveDate) { |
64 | 0 | this.effectiveDate = effectiveDate; |
65 | 0 | } |
66 | |
|
67 | |
public Date getExpirationDate() { |
68 | 0 | return expirationDate; |
69 | |
} |
70 | |
|
71 | |
public void setExpirationDate(Date expirationDate) { |
72 | 0 | this.expirationDate = expirationDate; |
73 | 0 | } |
74 | |
|
75 | |
public List<StateAttributeEntity> getAttributes() { |
76 | 0 | return attributes; |
77 | |
} |
78 | |
|
79 | |
public void setAttributes(List<StateAttributeEntity> attributes) { |
80 | 0 | this.attributes = attributes; |
81 | 0 | } |
82 | |
|
83 | 0 | public StateProcessEntity(){} |
84 | |
|
85 | |
public StateProcessEntity(StateProcess process){ |
86 | 0 | super(); |
87 | |
try{ |
88 | 0 | this.setId(process.getKey()); |
89 | 0 | this.setName(process.getName()); |
90 | 0 | this.setDescription(process.getDescr().getPlain()); |
91 | 0 | this.setVersionNumber((long) 0); |
92 | 0 | this.setEffectiveDate(process.getEffectiveDate()); |
93 | 0 | this.setExpirationDate(process.getExpirationDate()); |
94 | 0 | this.setAttributes(new ArrayList<StateAttributeEntity>()); |
95 | 0 | if(null != process.getAttributes()){ |
96 | 0 | for (Attribute att : process.getAttributes()) { |
97 | 0 | StateAttributeEntity attEntity = new StateAttributeEntity(att); |
98 | 0 | this.getAttributes().add(attEntity); |
99 | 0 | } |
100 | |
} |
101 | 0 | } catch (Exception e){ |
102 | 0 | e.printStackTrace(); |
103 | 0 | } |
104 | 0 | } |
105 | |
|
106 | |
public StateProcessInfo toDto(){ |
107 | 0 | StateProcessInfo process = StateProcessInfo.newInstance(); |
108 | 0 | process.setKey(getId()); |
109 | 0 | process.setName(name); |
110 | 0 | process.setEffectiveDate(effectiveDate); |
111 | 0 | process.setExpirationDate(expirationDate); |
112 | |
|
113 | 0 | List<AttributeInfo> atts = new ArrayList<AttributeInfo>(); |
114 | 0 | for (StateAttributeEntity att : getAttributes()) { |
115 | 0 | AttributeInfo attInfo = att.toDto(); |
116 | 0 | atts.add(attInfo); |
117 | 0 | } |
118 | 0 | process.setAttributes(atts); |
119 | |
|
120 | 0 | return process; |
121 | |
} |
122 | |
} |