View Javadoc
1   /**
2    * Copyright 2005-2014 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
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   * Defines the business object that specifies the criteria used on document searches.
37   *
38   * @author Kuali Rice Team (rice.collab@kuali.org)
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          // nothing to refresh
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     public String getInitiatorDisplayName() {
261         if (initiatorPrincipalId != null) {
262             EntityNamePrincipalName entityNamePrincipalName = KimApiServiceLocator.getIdentityService().getDefaultNamesForPrincipalId(initiatorPrincipalId);
263             if (entityNamePrincipalName != null){
264                 EntityName entityName = entityNamePrincipalName.getDefaultName();
265                 return entityName == null ? null : entityName.getCompositeName();
266             }
267         }
268         return null;
269     }
270 
271     public Person getApproverPerson() {
272         if (approverPrincipalName == null) {
273             return null;
274         }
275         return KimApiServiceLocator.getPersonService().getPersonByPrincipalName(approverPrincipalName);
276     }
277 
278     public Person getViewerPerson() {
279         if (viewerPrincipalName == null) {
280             return null;
281         }
282         return KimApiServiceLocator.getPersonService().getPersonByPrincipalName(viewerPrincipalName);
283     }
284 
285     public GroupBo getGroupViewer() {
286         if (groupViewerId == null) {
287             return null;
288         }
289         Group grp = KimApiServiceLocator.getGroupService().getGroup(groupViewerId);
290         if (null != grp){
291             return GroupBo.from(grp);
292         }  else {
293             return null;
294         }
295     }
296 
297     public String getStatusLabel() {
298         if (statusCode == null) {
299             return "";
300         }
301         return DocumentStatus.fromCode(statusCode).getLabel();
302     }
303 
304     public String getDocumentTypeLabel() {
305         DocumentType documentType = getDocumentType();
306         if (documentType != null) {
307             return documentType.getLabel();
308         }
309         return "";
310     }
311 
312     /**
313      * Returns the route image which can be used to construct the route log link in custom lookup helper code.
314      */
315     public String getRouteLog() {
316         return "<img alt=\"Route Log for Document\" src=\"images/my_route_log.gif\"/>";
317     }
318 
319     public void populateFromDocumentSearchResult(DocumentSearchResult result) {
320         Document document = result.getDocument();
321         documentTypeName = document.getDocumentTypeName();
322         documentId = document.getDocumentId();
323         statusCode = document.getStatus().getCode();
324         applicationDocumentId = document.getApplicationDocumentId();
325         applicationDocumentStatus = document.getApplicationDocumentStatus();
326         title = document.getTitle();
327         initiatorPrincipalName = principalIdToName(document.getInitiatorPrincipalId());
328         initiatorPrincipalId = document.getInitiatorPrincipalId();
329         dateCreated = new Timestamp(document.getDateCreated().getMillis());
330     }
331 
332     private String principalIdToName(String principalId) {
333         if (StringUtils.isNotBlank(principalId)) {
334             Principal principal =  KimApiServiceLocator.getIdentityService().getPrincipal(principalId);
335             if (principal != null){
336                 return principal.getPrincipalName();
337             }
338         }
339         return null;
340     }
341 
342 }
343