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.StateInfo; |
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.State; |
21 | |
|
22 | |
@Entity |
23 | |
@Table(name = "KSEN_COMM_STATE") |
24 | |
public class StateEntity extends MetaEntity implements AttributeOwner<StateAttributeEntity> { |
25 | |
@Column(name="NAME") |
26 | |
private String name; |
27 | |
|
28 | |
@Column(name="DESCR") |
29 | |
private String description; |
30 | |
|
31 | |
@Column(name="PROCESS_KEY") |
32 | |
private String processKey; |
33 | |
|
34 | |
@Temporal(TemporalType.TIMESTAMP) |
35 | |
@Column(name = "EFF_DT") |
36 | |
private Date effectiveDate; |
37 | |
|
38 | |
@Temporal(TemporalType.TIMESTAMP) |
39 | |
@Column(name = "EXPIR_DT") |
40 | |
private Date expirationDate; |
41 | |
|
42 | |
@OneToMany(cascade = CascadeType.ALL, mappedBy = "owner") |
43 | |
private List<StateAttributeEntity> attributes; |
44 | |
|
45 | |
public String getName() { |
46 | 0 | return name; |
47 | |
} |
48 | |
|
49 | |
public void setName(String name) { |
50 | 0 | this.name = name; |
51 | 0 | } |
52 | |
|
53 | |
public String getDescription() { |
54 | 0 | return description; |
55 | |
} |
56 | |
|
57 | |
public void setDescription(String description) { |
58 | 0 | this.description = description; |
59 | 0 | } |
60 | |
|
61 | |
public String getProcessKey() { |
62 | 0 | return processKey; |
63 | |
} |
64 | |
|
65 | |
public void setProcessKey(String processKey) { |
66 | 0 | this.processKey = processKey; |
67 | 0 | } |
68 | |
|
69 | |
public Date getEffectiveDate() { |
70 | 0 | return effectiveDate; |
71 | |
} |
72 | |
|
73 | |
public void setEffectiveDate(Date effectiveDate) { |
74 | 0 | this.effectiveDate = effectiveDate; |
75 | 0 | } |
76 | |
|
77 | |
public Date getExpirationDate() { |
78 | 0 | return expirationDate; |
79 | |
} |
80 | |
|
81 | |
public void setExpirationDate(Date expirationDate) { |
82 | 0 | this.expirationDate = expirationDate; |
83 | 0 | } |
84 | |
|
85 | |
public List<StateAttributeEntity> getAttributes() { |
86 | 0 | return attributes; |
87 | |
} |
88 | |
|
89 | |
public void setAttributes(List<StateAttributeEntity> attributes) { |
90 | 0 | this.attributes = attributes; |
91 | 0 | } |
92 | |
|
93 | 0 | public StateEntity(){} |
94 | |
|
95 | |
public StateEntity(State state){ |
96 | 0 | super(); |
97 | |
try{ |
98 | 0 | this.setId(state.getKey()); |
99 | 0 | this.setName(state.getName()); |
100 | 0 | this.setDescription(state.getDescr()); |
101 | 0 | this.setVersionNumber((long) 0); |
102 | 0 | this.setEffectiveDate(state.getEffectiveDate()); |
103 | 0 | this.setExpirationDate(state.getExpirationDate()); |
104 | 0 | this.setAttributes(new ArrayList<StateAttributeEntity>()); |
105 | 0 | if(null != state.getAttributes()){ |
106 | 0 | for (Attribute att : state.getAttributes()) { |
107 | 0 | StateAttributeEntity attEntity = new StateAttributeEntity(att); |
108 | 0 | this.getAttributes().add(attEntity); |
109 | 0 | } |
110 | |
} |
111 | 0 | } catch (Exception e){ |
112 | 0 | e.printStackTrace(); |
113 | 0 | } |
114 | 0 | } |
115 | |
|
116 | |
public StateInfo toDto(){ |
117 | 0 | StateInfo state = StateInfo.newInstance(); |
118 | 0 | state.setKey(getId()); |
119 | 0 | state.setName(name); |
120 | 0 | state.setDescr(description); |
121 | 0 | state.setEffectiveDate(effectiveDate); |
122 | 0 | state.setExpirationDate(expirationDate); |
123 | |
|
124 | 0 | List<AttributeInfo> atts = new ArrayList<AttributeInfo>(); |
125 | 0 | for (StateAttributeEntity att : getAttributes()) { |
126 | 0 | AttributeInfo attInfo = att.toDto(); |
127 | 0 | atts.add(attInfo); |
128 | 0 | } |
129 | 0 | state.setAttributes(atts); |
130 | |
|
131 | 0 | return state; |
132 | |
} |
133 | |
} |