1 | |
package org.kuali.student.enrollment.class1.hold.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.hold.dto.RestrictionInfo; |
19 | |
import org.kuali.student.r2.core.hold.infc.Restriction; |
20 | |
|
21 | |
@Entity |
22 | |
@Table(name = "KSEN_RESTRICTION") |
23 | |
public class RestrictionEntity extends MetaEntity implements AttributeOwner<RestrictionAttributeEntity> { |
24 | |
@Column(name = "NAME") |
25 | |
private String name; |
26 | |
|
27 | |
@ManyToOne(cascade = CascadeType.ALL) |
28 | |
@JoinColumn(name = "RT_DESCR_ID") |
29 | |
private HoldRichTextEntity descr; |
30 | |
|
31 | |
@Column(name = "RESTRICTION_TYPE_ID") |
32 | |
private String restrictionType; |
33 | |
|
34 | |
@Column(name = "RESTRICTION_STATE_ID") |
35 | |
private String restrictionState; |
36 | |
|
37 | |
@OneToMany(cascade = CascadeType.ALL, mappedBy = "owner") |
38 | |
private List<RestrictionAttributeEntity> attributes; |
39 | |
|
40 | 0 | public RestrictionEntity() {} |
41 | |
|
42 | |
public RestrictionEntity(Restriction restriction) { |
43 | 0 | super(restriction); |
44 | |
try { |
45 | 0 | this.setId(restriction.getKey()); |
46 | 0 | this.setName(restriction.getName()); |
47 | 0 | if (restriction.getStateKey() != null) |
48 | 0 | this.setRestrictionState(restriction.getStateKey()); |
49 | 0 | if (restriction.getDescr() != null) { |
50 | 0 | this.setDescr(new HoldRichTextEntity(restriction.getDescr())); |
51 | |
} |
52 | 0 | this.setAttributes(new ArrayList<RestrictionAttributeEntity>()); |
53 | 0 | if (null != restriction.getAttributes()) { |
54 | 0 | for (Attribute att : restriction.getAttributes()) { |
55 | 0 | RestrictionAttributeEntity attEntity = new RestrictionAttributeEntity(att); |
56 | 0 | this.getAttributes().add(attEntity); |
57 | 0 | } |
58 | |
} |
59 | 0 | } catch (Exception e) { |
60 | 0 | e.printStackTrace(); |
61 | 0 | } |
62 | 0 | } |
63 | |
|
64 | |
public RestrictionInfo toDto() { |
65 | 0 | RestrictionInfo obj = new RestrictionInfo(); |
66 | 0 | obj.setKey(getId()); |
67 | 0 | obj.setName(name); |
68 | 0 | if (restrictionType != null) |
69 | 0 | obj.setTypeKey(restrictionType); |
70 | 0 | if (restrictionState != null) |
71 | 0 | obj.setStateKey(restrictionState); |
72 | 0 | obj.setMeta(super.toDTO()); |
73 | 0 | if (descr != null) |
74 | 0 | obj.setDescr(descr.toDto()); |
75 | |
|
76 | 0 | List<AttributeInfo> atts = new ArrayList<AttributeInfo>(); |
77 | 0 | for (RestrictionAttributeEntity att : getAttributes()) { |
78 | 0 | AttributeInfo attInfo = att.toDto(); |
79 | 0 | atts.add(attInfo); |
80 | 0 | } |
81 | 0 | obj.setAttributes(atts); |
82 | |
|
83 | 0 | return obj; |
84 | |
} |
85 | |
|
86 | |
public String getRestrictionType() { |
87 | 0 | return restrictionType; |
88 | |
} |
89 | |
|
90 | |
public void setRestrictionType(String restrictionType) { |
91 | 0 | this.restrictionType = restrictionType; |
92 | 0 | } |
93 | |
|
94 | |
public String getName() { |
95 | 0 | return name; |
96 | |
} |
97 | |
|
98 | |
public void setName(String name) { |
99 | 0 | this.name = name; |
100 | 0 | } |
101 | |
|
102 | |
public HoldRichTextEntity getDescr() { |
103 | 0 | return descr; |
104 | |
} |
105 | |
|
106 | |
public void setDescr(HoldRichTextEntity descr) { |
107 | 0 | this.descr = descr; |
108 | 0 | } |
109 | |
|
110 | |
public String getRestrictionState() { |
111 | 0 | return restrictionState; |
112 | |
} |
113 | |
|
114 | |
public void setRestrictionState(String restrictionState) { |
115 | 0 | this.restrictionState = restrictionState; |
116 | 0 | } |
117 | |
|
118 | |
@Override |
119 | |
public void setAttributes(List<RestrictionAttributeEntity> attributes) { |
120 | 0 | this.attributes = attributes; |
121 | 0 | } |
122 | |
|
123 | |
@Override |
124 | |
public List<RestrictionAttributeEntity> getAttributes() { |
125 | 0 | return attributes; |
126 | |
} |
127 | |
|
128 | |
} |