1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.kew.rule;
17
18 import javax.persistence.CascadeType;
19 import javax.persistence.Column;
20 import javax.persistence.Entity;
21 import javax.persistence.FetchType;
22 import javax.persistence.GeneratedValue;
23 import javax.persistence.Id;
24 import javax.persistence.JoinColumn;
25 import javax.persistence.OneToOne;
26 import javax.persistence.Table;
27
28 import org.hibernate.annotations.GenericGenerator;
29 import org.hibernate.annotations.Parameter;
30 import org.kuali.rice.core.api.delegation.DelegationType;
31 import org.kuali.rice.kew.api.rule.RuleDelegationContract;
32 import org.kuali.rice.kew.doctype.bo.DocumentType;
33 import org.kuali.rice.kew.service.KEWServiceLocator;
34 import org.kuali.rice.krad.bo.PersistableBusinessObjectBase;
35
36
37
38
39
40
41
42
43
44 @Entity
45 @Table(name="KREW_DLGN_RSP_T")
46
47 public class RuleDelegationBo extends PersistableBusinessObjectBase implements RuleDelegationContract {
48
49 private static final long serialVersionUID = 7989203310473741293L;
50 @Id
51 @GeneratedValue(generator="KREW_RTE_TMPL_S")
52 @GenericGenerator(name="KREW_RTE_TMPL_S",strategy="org.hibernate.id.enhanced.SequenceStyleGenerator",parameters={
53 @Parameter(name="sequence_name",value="KREW_RTE_TMPL_S"),
54 @Parameter(name="value_column",value="id")
55 })
56 @Column(name="DLGN_RULE_ID")
57 private String ruleDelegationId;
58 @Column(name="RSP_ID")
59 private String responsibilityId;
60 @Column(name="DLGN_RULE_BASE_VAL_ID", insertable=false, updatable=false)
61 private String delegateRuleId;
62 @Column(name="DLGN_TYP")
63 private String delegationTypeCode = DelegationType.PRIMARY.getCode();
64
65 @OneToOne(fetch=FetchType.EAGER, cascade={CascadeType.PERSIST})
66 @JoinColumn(name="DLGN_RULE_BASE_VAL_ID")
67 private RuleBaseValues delegationRule;
68
69
70
71
72 public RuleDelegationBo() {
73 }
74
75 public Object copy(boolean preserveKeys) {
76 RuleDelegationBo clone = new RuleDelegationBo();
77 if (ruleDelegationId != null && preserveKeys) {
78 clone.setRuleDelegationId(ruleDelegationId);
79 }
80 clone.setDelegationRule(delegationRule);
81 clone.setDelegateRuleId(delegationRule.getId());
82 if (delegationTypeCode != null) {
83 clone.setDelegationType(DelegationType.fromCode(delegationTypeCode));
84 }
85 return clone;
86 }
87
88 public String getDelegateRuleId() {
89 return delegateRuleId;
90 }
91 public void setDelegateRuleId(String delegateRuleId) {
92 this.delegateRuleId = delegateRuleId;
93 }
94 @Override
95 public RuleBaseValues getDelegationRule() {
96 return delegationRule;
97 }
98
99 public RuleBaseValues getDelegationRuleBaseValues() {
100 return delegationRule;
101 }
102
103 public void setDelegationRule(RuleBaseValues delegationRule) {
104 this.delegationRule = delegationRule;
105 }
106
107
108
109
110
111 public void setDelegationTypeCode(String delegationTypeCode) {
112 DelegationType.fromCode(delegationTypeCode);
113 this.delegationTypeCode = delegationTypeCode;
114 }
115
116
117
118
119
120 public String getDelegationTypeCode() {
121 return delegationTypeCode;
122 }
123
124 @Override
125 public DelegationType getDelegationType() {
126 return DelegationType.fromCode(delegationTypeCode);
127 }
128 public void setDelegationType(DelegationType delegationType) {
129 this.delegationTypeCode = delegationType.getCode();
130 }
131 public String getRuleDelegationId() {
132 return ruleDelegationId;
133 }
134 public void setRuleDelegationId(String ruleDelegationId) {
135 this.ruleDelegationId = ruleDelegationId;
136 }
137
138
139
140
141
142 public RuleResponsibilityBo getRuleResponsibility() {
143 if ( getResponsibilityId() == null ) {
144 return null;
145 }
146 return KEWServiceLocator.getRuleService().findRuleResponsibility(getResponsibilityId());
147 }
148
149 public DocumentType getDocumentType() {
150 return this.getDelegationRule().getDocumentType();
151 }
152
153 public String getResponsibilityId() {
154 return responsibilityId;
155 }
156 public void setResponsibilityId(String ruleResponsibilityId) {
157 this.responsibilityId = ruleResponsibilityId;
158 }
159
160
161
162
163
164
165
166
167
168
169
170 @Override
171 public void refresh() {
172 RuleBaseValues oldRuleBaseValues = this.getDelegationRule();
173 super.refresh();
174 if (this.getDelegationRule() == null) {
175 this.refreshReferenceObject("delegationRuleBaseValues");
176 if (this.getDelegationRule() == null) {
177 this.setDelegationRule(oldRuleBaseValues);
178 }
179 }
180 }
181
182 public static org.kuali.rice.kew.api.rule.RuleDelegation to(RuleDelegationBo bo) {
183 if (bo == null) {
184 return null;
185 }
186 return org.kuali.rice.kew.api.rule.RuleDelegation.Builder.create(bo).build();
187
188
189
190
191
192 }
193 }
194