1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.kew.impl.document.search;
17
18 import org.apache.commons.lang.StringUtils;
19 import org.kuali.rice.kew.api.document.Document;
20 import org.kuali.rice.kew.api.document.DocumentStatus;
21 import org.kuali.rice.kew.api.document.search.DocumentSearchResult;
22 import org.kuali.rice.kew.doctype.bo.DocumentType;
23 import org.kuali.rice.kew.service.KEWServiceLocator;
24 import org.kuali.rice.kim.api.group.Group;
25 import org.kuali.rice.kim.api.identity.Person;
26 import org.kuali.rice.kim.api.identity.name.EntityName;
27 import org.kuali.rice.kim.api.identity.principal.EntityNamePrincipalName;
28 import org.kuali.rice.kim.api.identity.principal.Principal;
29 import org.kuali.rice.kim.api.services.KimApiServiceLocator;
30 import org.kuali.rice.kim.impl.group.GroupBo;
31 import org.kuali.rice.krad.bo.BusinessObject;
32
33 import java.sql.Timestamp;
34
35
36
37
38
39
40 public class DocumentSearchCriteriaBo implements BusinessObject {
41
42 private String documentTypeName;
43 private String documentId;
44 private String statusCode;
45 private String applicationDocumentId;
46 private String applicationDocumentStatus;
47 private String title;
48 private String initiatorPrincipalName;
49 private String initiatorPrincipalId;
50 private String viewerPrincipalName;
51 private String viewerPrincipalId;
52 private String groupViewerName;
53 private String groupViewerId;
54 private String approverPrincipalName;
55 private String approverPrincipalId;
56 private String routeNodeName;
57 private String routeNodeLogic;
58 private Timestamp dateCreated;
59 private Timestamp dateLastModified;
60 private Timestamp dateApproved;
61 private Timestamp dateFinalized;
62 private Timestamp dateApplicationDocumentStatusChanged;
63 private String saveName;
64
65 @Override
66 public void refresh() {
67
68 }
69
70 public String getDocumentTypeName() {
71 return documentTypeName;
72 }
73
74 public void setDocumentTypeName(String documentTypeName) {
75 this.documentTypeName = documentTypeName;
76 }
77
78 public String getDocumentId() {
79 return documentId;
80 }
81
82 public void setDocumentId(String documentId) {
83 this.documentId = documentId;
84 }
85
86 public String getStatusCode() {
87 return statusCode;
88 }
89
90 public void setStatusCode(String statusCode) {
91 this.statusCode = statusCode;
92 }
93
94 public String getApplicationDocumentId() {
95 return applicationDocumentId;
96 }
97
98 public void setApplicationDocumentId(String applicationDocumentId) {
99 this.applicationDocumentId = applicationDocumentId;
100 }
101
102 public String getApplicationDocumentStatus() {
103 return applicationDocumentStatus;
104 }
105
106 public void setApplicationDocumentStatus(String applicationDocumentStatus) {
107 this.applicationDocumentStatus = applicationDocumentStatus;
108 }
109
110 public String getTitle() {
111 return title;
112 }
113
114 public void setTitle(String title) {
115 this.title = title;
116 }
117
118 public String getInitiatorPrincipalName() {
119 return initiatorPrincipalName;
120 }
121
122 public void setInitiatorPrincipalName(String initiatorPrincipalName) {
123 this.initiatorPrincipalName = initiatorPrincipalName;
124 }
125
126 public String getInitiatorPrincipalId() {
127 return initiatorPrincipalId;
128 }
129
130 public void setInitiatorPrincipalId(String initiatorPrincipalId) {
131 this.initiatorPrincipalId = initiatorPrincipalId;
132 }
133
134 public String getViewerPrincipalName() {
135 return viewerPrincipalName;
136 }
137
138 public void setViewerPrincipalName(String viewerPrincipalName) {
139 this.viewerPrincipalName = viewerPrincipalName;
140 }
141
142 public String getViewerPrincipalId() {
143 return viewerPrincipalId;
144 }
145
146 public void setViewerPrincipalId(String viewerPrincipalId) {
147 this.viewerPrincipalId = viewerPrincipalId;
148 }
149
150 public String getGroupViewerName() {
151 return groupViewerName;
152 }
153
154 public void setGroupViewerName(String groupViewerName) {
155 this.groupViewerName = groupViewerName;
156 }
157
158 public String getGroupViewerId() {
159 return groupViewerId;
160 }
161
162 public void setGroupViewerId(String groupViewerId) {
163 this.groupViewerId = groupViewerId;
164 }
165
166 public String getApproverPrincipalName() {
167 return approverPrincipalName;
168 }
169
170 public void setApproverPrincipalName(String approverPrincipalName) {
171 this.approverPrincipalName = approverPrincipalName;
172 }
173
174 public String getApproverPrincipalId() {
175 return approverPrincipalId;
176 }
177
178 public void setApproverPrincipalId(String approverPrincipalId) {
179 this.approverPrincipalId = approverPrincipalId;
180 }
181
182 public String getRouteNodeName() {
183 return routeNodeName;
184 }
185
186 public void setRouteNodeName(String routeNodeName) {
187 this.routeNodeName = routeNodeName;
188 }
189
190 public String getRouteNodeLogic() {
191 return routeNodeLogic;
192 }
193
194 public void setRouteNodeLogic(String routeNodeLogic) {
195 this.routeNodeLogic = routeNodeLogic;
196 }
197
198 public Timestamp getDateCreated() {
199 return dateCreated;
200 }
201
202 public void setDateCreated(Timestamp dateCreated) {
203 this.dateCreated = dateCreated;
204 }
205
206 public Timestamp getDateLastModified() {
207 return dateLastModified;
208 }
209
210 public void setDateLastModified(Timestamp dateLastModified) {
211 this.dateLastModified = dateLastModified;
212 }
213
214 public Timestamp getDateApproved() {
215 return dateApproved;
216 }
217
218 public void setDateApproved(Timestamp dateApproved) {
219 this.dateApproved = dateApproved;
220 }
221
222 public Timestamp getDateFinalized() {
223 return dateFinalized;
224 }
225
226 public void setDateFinalized(Timestamp dateFinalized) {
227 this.dateFinalized = dateFinalized;
228 }
229
230 public Timestamp getDateApplicationDocumentStatusChanged() {
231 return dateApplicationDocumentStatusChanged;
232 }
233
234 public void setDateApplicationDocumentStatusChanged(Timestamp dateApplicationDocumentStatusChanged) {
235 this.dateApplicationDocumentStatusChanged = dateApplicationDocumentStatusChanged;
236 }
237
238 public String getSaveName() {
239 return saveName;
240 }
241
242 public void setSaveName(String saveName) {
243 this.saveName = saveName;
244 }
245
246 public DocumentType getDocumentType() {
247 if (documentTypeName == null) {
248 return null;
249 }
250 return KEWServiceLocator.getDocumentTypeService().findByName(documentTypeName);
251 }
252
253 public Person getInitiatorPerson() {
254 if (initiatorPrincipalId == null) {
255 return null;
256 }
257 return KimApiServiceLocator.getPersonService().getPerson(initiatorPrincipalId);
258 }
259
260
261
262
263
264 public String getInitiatorDisplayName() {
265
266 if (StringUtils.isNotBlank(initiatorPrincipalId)) {
267 EntityNamePrincipalName entityNamePrincipalName = KimApiServiceLocator.getIdentityService().getDefaultNamesForPrincipalId(initiatorPrincipalId);
268 if (entityNamePrincipalName != null){
269 EntityName entityName = entityNamePrincipalName.getDefaultName();
270 return entityName == null ? initiatorPrincipalId : entityName.getCompositeName();
271 }
272 }
273
274 return initiatorPrincipalId;
275 }
276
277 public Person getApproverPerson() {
278 if (approverPrincipalName == null) {
279 return null;
280 }
281 return KimApiServiceLocator.getPersonService().getPersonByPrincipalName(approverPrincipalName);
282 }
283
284 public Person getViewerPerson() {
285 if (viewerPrincipalName == null) {
286 return null;
287 }
288 return KimApiServiceLocator.getPersonService().getPersonByPrincipalName(viewerPrincipalName);
289 }
290
291 public GroupBo getGroupViewer() {
292 if (groupViewerId == null) {
293 return null;
294 }
295 Group grp = KimApiServiceLocator.getGroupService().getGroup(groupViewerId);
296 if (null != grp){
297 return GroupBo.from(grp);
298 } else {
299 return null;
300 }
301 }
302
303 public String getStatusLabel() {
304 if (statusCode == null) {
305 return "";
306 }
307 return DocumentStatus.fromCode(statusCode).getLabel();
308 }
309
310 public String getDocumentTypeLabel() {
311 DocumentType documentType = getDocumentType();
312 if (documentType != null) {
313 return documentType.getLabel();
314 }
315 return "";
316 }
317
318
319
320
321 public String getRouteLog() {
322 return "<img alt=\"Route Log for Document\" src=\"images/my_route_log.gif\"/>";
323 }
324
325 public void populateFromDocumentSearchResult(DocumentSearchResult result) {
326 Document document = result.getDocument();
327 documentTypeName = document.getDocumentTypeName();
328 documentId = document.getDocumentId();
329 statusCode = document.getStatus().getCode();
330 applicationDocumentId = document.getApplicationDocumentId();
331 applicationDocumentStatus = document.getApplicationDocumentStatus();
332 title = document.getTitle();
333 initiatorPrincipalName = principalIdToName(document.getInitiatorPrincipalId());
334 initiatorPrincipalId = document.getInitiatorPrincipalId();
335 dateCreated = new Timestamp(document.getDateCreated().getMillis());
336 }
337
338
339
340
341
342
343
344
345 private String principalIdToName(String principalId) {
346 if (StringUtils.isNotBlank(principalId)) {
347 Principal principal = KimApiServiceLocator.getIdentityService().getPrincipal(principalId);
348 if (principal != null){
349 return principal.getPrincipalName();
350 }
351 }
352 return principalId;
353 }
354
355 }
356