1 /*
2 * Copyright 2005-2008 The Kuali Foundation
3 *
4 *
5 * Licensed under the Educational Community License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.opensource.org/licenses/ecl2.php
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17 package org.kuali.rice.kew.service;
18
19 import java.io.Serializable;
20
21 import org.kuali.rice.kew.exception.WorkflowException;
22
23
24 public class WorkflowReports implements Serializable {
25
26 private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(WorkflowReports.class);
27
28 private static final long serialVersionUID = 2859218832130678115L;
29 public WorkflowInfo workflowInfo;
30
31 public WorkflowReports() {
32 workflowInfo = new WorkflowInfo();
33 }
34
35 public boolean isUserAuthenticatedByRouteLog(Long routeHeaderId, String principalId, boolean lookFuture) throws WorkflowException {
36 return workflowInfo.isUserAuthenticatedByRouteLog(routeHeaderId, principalId, lookFuture);
37 }
38
39 /**
40 * @deprecated use isLastApproverAtNode instead
41 */
42 public boolean isLastApproverInRouteLevel(Long routeHeaderId, String principalId, Integer routeLevel) throws WorkflowException {
43 return workflowInfo.isLastApproverInRouteLevel(routeHeaderId, principalId, routeLevel);
44 }
45
46 public boolean isLastApproverAtNode(Long routeHeaderId, String principalId, String nodeName) throws WorkflowException {
47 return workflowInfo.isLastApproverAtNode(routeHeaderId, principalId, nodeName);
48 }
49
50 /**
51 * @deprecated use routeNodeHasApproverActionRequest instead
52 */
53 public boolean routeLevelHasApproverActionRequest(String docType, String docContent, Integer routeLevel) throws WorkflowException {
54 return workflowInfo.routeLevelHasApproverActionRequest(docType, docContent, routeLevel);
55 }
56
57 public boolean routeNodeHasApproverActionRequest(String docType, String docContent, String nodeName) throws WorkflowException {
58 return workflowInfo.routeNodeHasApproverActionRequest(docType, docContent, nodeName);
59 }
60
61 /**
62 * User is considered the final approver for this document.
63 *
64 * @return True if user context applies to the final approver request for this document.
65 */
66 public boolean isFinalApprover(Long routeHeaderId, String principalId) throws WorkflowException {
67 return workflowInfo.isFinalApprover(routeHeaderId, principalId);
68 }
69
70 /*public boolean isUserAuthenticatedByRouteLog(Long routeHeaderId, UserIdVO userId, boolean lookFuture) throws WorkflowException {
71 ReportCriteriaDTO criteria = new ReportCriteriaDTO(routeHeaderId);
72 criteria.setUsersToFilterIn(new UserIdVO[] { userId });
73 RouteHeaderDetailVO detail = workflowInfo.routingReport(criteria);
74 if (isUser(detail.getInitiator(), userId) || detail.getActionsTaken().length > 0) {
75 return true;
76 }
77 lookFuture = lookFuture && new Boolean(Utilities.getApplicationConstant(KEWConstants.CHECK_ROUTE_LOG_AUTH_FUTURE)).booleanValue();
78 for (int index = 0; index < detail.getActionRequests().length; index++) {
79 ActionRequestVO actionRequest = detail.getActionRequests()[index];
80 if (actionRequest.getRouteLevel().intValue() > detail.getDocRouteLevel().intValue() && ! lookFuture) {
81 continue;
82 }
83 return true;
84 }
85 return false;
86 }
87
88 public boolean isLastApproverInRouteLevel(Long routeHeaderId, UserIdVO userId, Integer routeLevel) throws WorkflowException {
89 ReportCriteriaDTO criteria = new ReportCriteriaDTO(routeHeaderId, new Integer(0), routeLevel);
90 RouteHeaderDetailVO detail = workflowInfo.routingReport(criteria);
91 ActionTakenVO actionTaken = new ActionTakenVO();
92 actionTaken.setActionTaken(KEWConstants.ACTION_TAKEN_APPROVED_CD);
93 actionTaken.setRouteHeaderId(routeHeaderId);
94 actionTaken.setUserVO(workflowInfo.getWorkflowUser(userId));
95 actionTaken.setActionDate(Calendar.getInstance());
96 RouteHeaderDetailVO resultDetail = workflowInfo.routingSimulation(detail, new ActionTakenVO[] { actionTaken });
97 boolean lastApprover = true;
98 // see if there are any non-deactivated requests left at this level
99 for (int index = 0; index < resultDetail.getActionRequests().length; index++) {
100 ActionRequestVO request = resultDetail.getActionRequests()[index];
101 if (request.getRouteLevel().equals(routeLevel) && !KEWConstants.ACTION_REQUEST_DONE_STATE.equals(request.getStatus())) {
102 lastApprover = false;
103 break;
104 }
105 }
106 return lastApprover;
107 //return workflowInfo.isLastApproverInRouteLevel(routeHeaderId, userId, routeLevel);
108 }
109
110 public boolean routeLevelHasApproverActionRequest(String docType, String docContent, Integer routeLevel) throws WorkflowException {
111 //DocumentContentVO documentContent = new DocumentContentVO();
112 //documentContent.setAttributeContent(docContent);
113 ReportCriteriaDTO criteria = new ReportCriteriaDTO(docType, docContent, routeLevel, routeLevel);
114 RouteHeaderDetailVO detail = workflowInfo.routingReport(criteria);
115 for (int index = 0; index < detail.getActionRequests().length; index++) {
116 ActionRequestVO actionRequest = detail.getActionRequests()[index];
117 if (actionRequest.isApprovalRequest()) {
118 return true;
119 }
120 }
121 return false;
122 }
123
124 public boolean hasMember(WorkgroupVO workgroup, UserVO user) {
125 UserVO[] users = workgroup.getMembers();
126 for (int index = 0; index < users.length; index++) {
127 UserVO workgroupUser = users[index];
128 if (user.getNetworkId().equals(workgroupUser.getNetworkId())) {
129 return true;
130 }
131 }
132 return false;
133 }
134
135 private boolean isUser(UserVO user, UserIdVO userId) {
136 boolean isUser = false;
137 if (userId instanceof EmplIdVO) {
138 isUser = ((EmplIdVO)userId).getEmplId().equals(user.getEmplId());
139 } else if (userId instanceof NetworkIdVO) {
140 isUser = ((NetworkIdVO)userId).getNetworkId().equals(user.getNetworkId());
141 } else if (userId instanceof UuIdVO) {
142 isUser = ((UuIdVO)userId).getUuId().equals(user.getUuId());
143 } else if (userId instanceof WorkflowIdVO) {
144 isUser = ((WorkflowIdVO)userId).getWorkflowId().equals(user.getWorkflowId());
145 }
146 return isUser;
147 }*/
148
149 }