1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
package org.kuali.rice.kew.actiontaken; |
18 | |
|
19 | |
import org.apache.commons.beanutils.BeanUtils; |
20 | |
import org.apache.commons.lang.StringUtils; |
21 | |
import org.kuali.rice.core.jpa.annotations.Sequence; |
22 | |
import org.kuali.rice.core.util.OrmUtils; |
23 | |
import org.kuali.rice.core.util.RiceConstants; |
24 | |
import org.kuali.rice.kew.actionrequest.ActionRequestValue; |
25 | |
import org.kuali.rice.kew.actionrequest.KimGroupRecipient; |
26 | |
import org.kuali.rice.kew.actionrequest.KimPrincipalRecipient; |
27 | |
import org.kuali.rice.kew.actionrequest.Recipient; |
28 | |
import org.kuali.rice.kew.actionrequest.service.ActionRequestService; |
29 | |
import org.kuali.rice.kew.bo.WorkflowPersistable; |
30 | |
import org.kuali.rice.kew.routeheader.DocumentRouteHeaderValue; |
31 | |
import org.kuali.rice.kew.service.KEWServiceLocator; |
32 | |
import org.kuali.rice.kew.util.CodeTranslator; |
33 | |
import org.kuali.rice.kew.util.KEWConstants; |
34 | |
import org.kuali.rice.kim.bo.Group; |
35 | |
import org.kuali.rice.kim.bo.entity.KimPrincipal; |
36 | |
import org.kuali.rice.kim.service.KIMServiceLocator; |
37 | |
|
38 | |
import javax.persistence.*; |
39 | |
import java.sql.Timestamp; |
40 | |
import java.util.ArrayList; |
41 | |
import java.util.Collection; |
42 | |
|
43 | |
|
44 | |
|
45 | |
|
46 | |
|
47 | |
|
48 | |
|
49 | |
|
50 | |
@Entity |
51 | |
@Sequence(name="KREW_ACTN_TKN_S", property="actionTakenId") |
52 | |
@Table(name="KREW_ACTN_TKN_T") |
53 | 0 | public class ActionTakenValue implements WorkflowPersistable { |
54 | |
|
55 | |
|
56 | |
|
57 | |
|
58 | |
private static final long serialVersionUID = -81505450567067594L; |
59 | |
@Id |
60 | |
@Column(name="ACTN_TKN_ID") |
61 | |
private Long actionTakenId; |
62 | |
@Column(name="DOC_HDR_ID",insertable=false, updatable=false) |
63 | |
private Long routeHeaderId; |
64 | |
@Column(name="ACTN_CD") |
65 | |
private String actionTaken; |
66 | |
@Column(name="ACTN_DT") |
67 | |
private Timestamp actionDate; |
68 | 0 | @Column(name="ANNOTN") |
69 | |
private String annotation = ""; |
70 | |
@Column(name="DOC_VER_NBR") |
71 | |
private Integer docVersion; |
72 | |
@Version |
73 | |
@Column(name="VER_NBR") |
74 | |
private Integer lockVerNbr; |
75 | |
@Column(name="PRNCPL_ID") |
76 | |
private String principalId; |
77 | |
@Column(name="DLGTR_PRNCPL_ID") |
78 | |
private String delegatorPrincipalId; |
79 | |
@Column(name="DLGTR_GRP_ID") |
80 | |
private String delegatorGroupId; |
81 | |
@ManyToOne(fetch=FetchType.EAGER, cascade={CascadeType.PERSIST}) |
82 | |
@JoinColumn(name="DOC_HDR_ID") |
83 | |
private DocumentRouteHeaderValue routeHeader; |
84 | |
@OneToMany(mappedBy="actionTaken") |
85 | |
private Collection<ActionRequestValue> actionRequests; |
86 | 0 | @Column(name="CUR_IND") |
87 | |
private Boolean currentIndicator = Boolean.TRUE; |
88 | |
@Transient |
89 | |
private String actionDateString; |
90 | |
|
91 | |
public KimPrincipal getPrincipal() { |
92 | 0 | return getPrincipalForId( principalId ); |
93 | |
} |
94 | |
|
95 | |
@PrePersist |
96 | |
public void beforeInsert(){ |
97 | 0 | OrmUtils.populateAutoIncValue(this, KEWServiceLocator.getEntityManagerFactory().createEntityManager()); |
98 | 0 | } |
99 | |
|
100 | |
public String getPrincipalDisplayName() { |
101 | |
|
102 | 0 | return KEWServiceLocator.getIdentityHelperService().getPerson(getPrincipalId()).getName(); |
103 | |
} |
104 | |
|
105 | |
public KimPrincipal getDelegatorPrincipal() { |
106 | 0 | return getPrincipalForId(delegatorPrincipalId); |
107 | |
} |
108 | |
|
109 | |
public Group getDelegatorGroup() |
110 | |
{ |
111 | 0 | return KIMServiceLocator.getIdentityManagementService() |
112 | |
.getGroup(String.valueOf(delegatorGroupId)); |
113 | |
} |
114 | |
|
115 | |
public void setDelegator(Recipient recipient) { |
116 | 0 | if (recipient instanceof KimPrincipalRecipient) { |
117 | 0 | setDelegatorPrincipalId(((KimPrincipalRecipient)recipient).getPrincipalId()); |
118 | 0 | } else if (recipient instanceof KimGroupRecipient) { |
119 | 0 | setDelegatorGroupId(((KimGroupRecipient)recipient).getGroup().getGroupId()); |
120 | |
} else { |
121 | 0 | setDelegatorPrincipalId(null); |
122 | 0 | setDelegatorGroupId(null); |
123 | |
} |
124 | 0 | } |
125 | |
|
126 | |
public boolean isForDelegator() { |
127 | 0 | return getDelegatorPrincipalId() != null || getDelegatorGroupId() != null; |
128 | |
} |
129 | |
|
130 | |
public String getDelegatorDisplayName() { |
131 | 0 | if (! isForDelegator()) { |
132 | 0 | return ""; |
133 | |
} |
134 | 0 | if (getDelegatorPrincipalId() != null) { |
135 | |
|
136 | 0 | return KEWServiceLocator.getIdentityHelperService().getPerson(this.getDelegatorPrincipalId()).getName(); |
137 | |
} else { |
138 | 0 | return getDelegatorGroup().getGroupName(); |
139 | |
} |
140 | |
} |
141 | |
|
142 | |
private KimPrincipal getPrincipalForId(String principalId) { |
143 | 0 | KimPrincipal principal = null; |
144 | |
|
145 | 0 | if (!StringUtils.isBlank(principalId)) { |
146 | 0 | principal = KEWServiceLocator.getIdentityHelperService().getPrincipal(principalId); |
147 | |
} |
148 | |
|
149 | 0 | return principal; |
150 | |
} |
151 | |
|
152 | |
public String getActionTakenLabel() { |
153 | 0 | return CodeTranslator.getActionTakenLabel(actionTaken); |
154 | |
} |
155 | |
|
156 | |
public Collection<ActionRequestValue> getActionRequests() { |
157 | 0 | if (actionRequests == null) { |
158 | 0 | setActionRequests(new ArrayList<ActionRequestValue>()); |
159 | |
} |
160 | 0 | return actionRequests; |
161 | |
} |
162 | |
|
163 | |
public void setActionRequests(Collection<ActionRequestValue> actionRequests) { |
164 | 0 | this.actionRequests = actionRequests; |
165 | 0 | } |
166 | |
|
167 | |
public DocumentRouteHeaderValue getRouteHeader() { |
168 | 0 | return routeHeader; |
169 | |
} |
170 | |
|
171 | |
public void setRouteHeader(DocumentRouteHeaderValue routeHeader) { |
172 | 0 | this.routeHeader = routeHeader; |
173 | 0 | } |
174 | |
|
175 | |
public Timestamp getActionDate() { |
176 | 0 | return actionDate; |
177 | |
} |
178 | |
|
179 | |
|
180 | |
public void setActionDate(Timestamp actionDate) { |
181 | 0 | this.actionDate = actionDate; |
182 | 0 | } |
183 | |
|
184 | |
|
185 | |
public String getActionTaken() { |
186 | 0 | return actionTaken; |
187 | |
} |
188 | |
|
189 | |
|
190 | |
public void setActionTaken(String actionTaken) { |
191 | 0 | this.actionTaken = actionTaken; |
192 | 0 | } |
193 | |
|
194 | |
|
195 | |
public Long getActionTakenId() { |
196 | 0 | return actionTakenId; |
197 | |
} |
198 | |
|
199 | |
public void setActionTakenId(Long actionTakenId) { |
200 | 0 | this.actionTakenId = actionTakenId; |
201 | 0 | } |
202 | |
|
203 | |
public String getAnnotation() { |
204 | 0 | return annotation; |
205 | |
} |
206 | |
|
207 | |
public void setAnnotation(String annotation) { |
208 | 0 | this.annotation = annotation; |
209 | 0 | } |
210 | |
|
211 | |
public String getDelegatorPrincipalId() { |
212 | 0 | return delegatorPrincipalId; |
213 | |
} |
214 | |
|
215 | |
public void setDelegatorPrincipalId(String delegatorPrincipalId) { |
216 | 0 | this.delegatorPrincipalId = delegatorPrincipalId; |
217 | 0 | } |
218 | |
|
219 | |
public String getDelegatorGroupId() { |
220 | 0 | return delegatorGroupId; |
221 | |
} |
222 | |
public void setDelegatorGroupId(String delegatorGroupId) { |
223 | 0 | this.delegatorGroupId = delegatorGroupId; |
224 | 0 | } |
225 | |
public Integer getDocVersion() { |
226 | 0 | return docVersion; |
227 | |
} |
228 | |
|
229 | |
public void setDocVersion(Integer docVersion) { |
230 | 0 | this.docVersion = docVersion; |
231 | 0 | } |
232 | |
|
233 | |
public Integer getLockVerNbr() { |
234 | 0 | return lockVerNbr; |
235 | |
} |
236 | |
|
237 | |
public void setLockVerNbr(Integer lockVerNbr) { |
238 | 0 | this.lockVerNbr = lockVerNbr; |
239 | 0 | } |
240 | |
|
241 | |
public Long getRouteHeaderId() { |
242 | |
|
243 | 0 | return routeHeaderId; |
244 | |
} |
245 | |
|
246 | |
public void setRouteHeaderId(Long routeHeaderId) { |
247 | 0 | this.routeHeaderId = routeHeaderId; |
248 | 0 | } |
249 | |
|
250 | |
public String getPrincipalId() { |
251 | 0 | return principalId; |
252 | |
} |
253 | |
|
254 | |
public void setPrincipalId(String principalId) { |
255 | 0 | this.principalId = principalId; |
256 | 0 | } |
257 | |
|
258 | |
public Boolean getCurrentIndicator() { |
259 | 0 | return currentIndicator; |
260 | |
} |
261 | |
|
262 | |
public void setCurrentIndicator(Boolean currentIndicator) { |
263 | 0 | this.currentIndicator = currentIndicator; |
264 | 0 | } |
265 | |
|
266 | |
public Collection getRootActionRequests() { |
267 | 0 | return getActionRequestService().getRootRequests(getActionRequests()); |
268 | |
} |
269 | |
|
270 | |
public Object copy(boolean preserveKeys) { |
271 | 0 | ActionTakenValue clone = new ActionTakenValue(); |
272 | |
try { |
273 | 0 | BeanUtils.copyProperties(clone, this); |
274 | 0 | } catch(Exception e) { |
275 | 0 | throw new RuntimeException(e); |
276 | 0 | } |
277 | |
|
278 | 0 | if (!preserveKeys) { |
279 | 0 | clone.setActionTakenId(null); |
280 | |
} |
281 | 0 | return clone; |
282 | |
} |
283 | |
|
284 | |
private ActionRequestService getActionRequestService() { |
285 | 0 | return (ActionRequestService) KEWServiceLocator.getService(KEWServiceLocator.ACTION_REQUEST_SRV); |
286 | |
} |
287 | |
|
288 | |
public String getActionDateString() { |
289 | 0 | if(actionDateString == null || actionDateString.trim().equals("")){ |
290 | 0 | return RiceConstants.getDefaultDateFormat().format(getActionDate()); |
291 | |
} else { |
292 | 0 | return actionDateString; |
293 | |
} |
294 | |
} |
295 | |
public void setActionDateString(String actionDateString) { |
296 | 0 | this.actionDateString = actionDateString; |
297 | 0 | } |
298 | |
|
299 | |
public boolean isApproval() { |
300 | 0 | return KEWConstants.ACTION_TAKEN_APPROVED_CD.equals(getActionTaken()); |
301 | |
} |
302 | |
|
303 | |
public boolean isCompletion() { |
304 | 0 | return KEWConstants.ACTION_TAKEN_COMPLETED_CD.equals(getActionTaken()); |
305 | |
} |
306 | |
} |