| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
|
| 17 | |
package org.kuali.rice.kew.edl; |
| 18 | |
|
| 19 | |
import org.kuali.rice.core.exception.RiceRuntimeException; |
| 20 | |
import org.kuali.rice.kew.dto.RouteNodeInstanceDTO; |
| 21 | |
import org.kuali.rice.kew.exception.WorkflowException; |
| 22 | |
import org.kuali.rice.kew.exception.WorkflowRuntimeException; |
| 23 | |
import org.kuali.rice.kew.service.WorkflowInfo; |
| 24 | |
import org.kuali.rice.kew.util.Utilities; |
| 25 | |
import org.kuali.rice.kew.web.session.UserSession; |
| 26 | |
import org.kuali.rice.kim.bo.Person; |
| 27 | |
|
| 28 | |
|
| 29 | |
|
| 30 | |
|
| 31 | |
|
| 32 | |
|
| 33 | |
|
| 34 | |
|
| 35 | 0 | public class WorkflowFunctions { |
| 36 | |
|
| 37 | |
|
| 38 | 0 | private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(WorkflowFunctions.class); |
| 39 | |
|
| 40 | |
public static boolean isUserInitiator(String id) throws WorkflowException { |
| 41 | 0 | boolean initiator = false; |
| 42 | 0 | UserSession userSession = UserSession.getAuthenticatedUser(); |
| 43 | 0 | if (userSession != null) { |
| 44 | |
try { |
| 45 | 0 | long documentId = Long.parseLong(id.trim()); |
| 46 | 0 | WorkflowInfo workflowInfo = new WorkflowInfo(); |
| 47 | 0 | if (userSession.getPrincipalId().equals(workflowInfo.getRouteHeader(documentId).getInitiatorPrincipalId())) { |
| 48 | 0 | initiator = true; |
| 49 | |
} |
| 50 | 0 | } catch (Exception e) { |
| 51 | 0 | LOG.debug("Exception encountered trying to determine if user is the document initiator:" + e ); |
| 52 | 0 | } |
| 53 | |
} |
| 54 | 0 | return initiator; |
| 55 | |
} |
| 56 | |
|
| 57 | |
public static boolean isUserRouteLogAuthenticated(String id) { |
| 58 | 0 | boolean authenticated=false; |
| 59 | 0 | WorkflowInfo workflowInfo = new WorkflowInfo(); |
| 60 | 0 | UserSession userSession=UserSession.getAuthenticatedUser(); |
| 61 | 0 | if(userSession!=null){ |
| 62 | 0 | String principalId = userSession.getPrincipalId(); |
| 63 | |
try { |
| 64 | 0 | Long routeHeaderId = new Long(id); |
| 65 | 0 | authenticated = workflowInfo.isUserAuthenticatedByRouteLog(routeHeaderId, principalId, true); |
| 66 | 0 | } catch (NumberFormatException e) { |
| 67 | 0 | LOG.debug("Invalid format routeHeaderId (should be LONG): " + id); |
| 68 | 0 | } catch (WorkflowException e) { |
| 69 | 0 | LOG.debug("Error checking if user is route log authenticated: userId: " + principalId + ";routeHeaderId: " + id); |
| 70 | |
|
| 71 | 0 | } catch (RiceRuntimeException e) { |
| 72 | 0 | LOG.error("Runtime Exception checking if user is route log authenticated: userId: " + principalId + ";routeHeaderId: " + id); |
| 73 | |
|
| 74 | 0 | } |
| 75 | |
} |
| 76 | |
|
| 77 | 0 | return authenticated; |
| 78 | |
} |
| 79 | |
|
| 80 | |
public static boolean isPrincipalIdAuthenticated(String principalId) { |
| 81 | 0 | return UserSession.getAuthenticatedUser().getPrincipalId().equals(principalId); |
| 82 | |
} |
| 83 | |
|
| 84 | |
public static boolean isPrincipalNameAuthenticated(String principalName) { |
| 85 | 0 | return UserSession.getAuthenticatedUser().getPrincipalName().equals(principalName); |
| 86 | |
} |
| 87 | |
|
| 88 | |
public static boolean isEmployeeIdAuthenticated(String employeeId) { |
| 89 | 0 | return UserSession.getAuthenticatedUser().getPerson().getEmployeeId().equals(employeeId); |
| 90 | |
} |
| 91 | |
|
| 92 | |
public static boolean isUserInGroup(String namespace, String groupName){ |
| 93 | 0 | boolean isUserInGroup=false; |
| 94 | 0 | UserSession userSession=UserSession.getAuthenticatedUser(); |
| 95 | 0 | if(userSession!=null){ |
| 96 | 0 | if(!Utilities.isEmpty(groupName)){ |
| 97 | |
|
| 98 | |
try{ |
| 99 | 0 | isUserInGroup = userSession.isMemberOfGroupWithName(namespace, groupName); |
| 100 | 0 | }catch(Exception e){ |
| 101 | 0 | LOG.error("Exception encountered trying to determine if user is member of a group: userId: " + userSession.getPrincipalId() + ";groupNamespace/Name: " |
| 102 | |
+ namespace + "/" + groupName + " resulted in error:" + e); |
| 103 | 0 | } |
| 104 | |
|
| 105 | |
} |
| 106 | |
} |
| 107 | 0 | return isUserInGroup; |
| 108 | |
} |
| 109 | |
|
| 110 | |
|
| 111 | |
public static Person getAuthenticatedPerson(){ |
| 112 | 0 | UserSession userSession=UserSession.getAuthenticatedUser(); |
| 113 | 0 | Person user = userSession.getPerson(); |
| 114 | 0 | return user; |
| 115 | |
} |
| 116 | |
|
| 117 | |
public static String getUserId() { |
| 118 | 0 | return getAuthenticatedPerson().getPrincipalId(); |
| 119 | |
} |
| 120 | |
|
| 121 | |
public static String getLastName() { |
| 122 | 0 | return getAuthenticatedPerson().getLastName(); |
| 123 | |
} |
| 124 | |
|
| 125 | |
public static String getGivenName() { |
| 126 | 0 | return getAuthenticatedPerson().getFirstName(); |
| 127 | |
} |
| 128 | |
|
| 129 | |
public static String getEmailAddress() { |
| 130 | 0 | return getAuthenticatedPerson().getEmailAddress(); |
| 131 | |
} |
| 132 | |
|
| 133 | |
public static boolean isNodeInPreviousNodeList(String nodeName, String id) { |
| 134 | 0 | LOG.debug("nodeName came in as: " + nodeName); |
| 135 | 0 | LOG.debug("id came in as: " + id); |
| 136 | |
|
| 137 | |
String[] previousNodeNames; |
| 138 | 0 | WorkflowInfo workflowInfo = new WorkflowInfo(); |
| 139 | |
try { |
| 140 | 0 | previousNodeNames = workflowInfo.getPreviousRouteNodeNames(new Long(id)); |
| 141 | 0 | } catch (Exception e) { |
| 142 | 0 | throw new WorkflowRuntimeException("Problem generating list of previous node names for documentID = " + id, e); |
| 143 | 0 | } |
| 144 | |
|
| 145 | 0 | for (int i = 0; i < previousNodeNames.length; i++) { |
| 146 | 0 | if (previousNodeNames[i].equals(nodeName)) { |
| 147 | 0 | return true; |
| 148 | |
} |
| 149 | |
} |
| 150 | 0 | return false; |
| 151 | |
} |
| 152 | |
|
| 153 | |
public static String escapeJavascript(String value) { |
| 154 | 0 | return value.replace("\\", "\\\\").replace("\"", "\\\""); |
| 155 | |
} |
| 156 | |
|
| 157 | |
public static boolean isNodeBetween(String firstNodeName, String lastNodeName, String id) { |
| 158 | 0 | if (isNodeInPreviousNodeList(firstNodeName, id)) { |
| 159 | 0 | if (isNodeInPreviousNodeList(lastNodeName, id)) { |
| 160 | 0 | return false; |
| 161 | |
}else { |
| 162 | 0 | return true; |
| 163 | |
} |
| 164 | |
} else { |
| 165 | 0 | return false; |
| 166 | |
} |
| 167 | |
} |
| 168 | |
|
| 169 | |
public static boolean isAtNode(String documentId, String nodeName) throws Exception { |
| 170 | 0 | WorkflowInfo workflowInfo = new WorkflowInfo(); |
| 171 | 0 | RouteNodeInstanceDTO[] activeNodeInstances = workflowInfo.getActiveNodeInstances(new Long(documentId)); |
| 172 | 0 | for (RouteNodeInstanceDTO nodeInstance : activeNodeInstances) { |
| 173 | 0 | if (nodeInstance.getName().equals(nodeName)) { |
| 174 | 0 | return true; |
| 175 | |
} |
| 176 | |
} |
| 177 | 0 | return false; |
| 178 | |
} |
| 179 | |
|
| 180 | |
public static boolean hasActiveNode(String documentId) throws Exception { |
| 181 | 0 | WorkflowInfo workflowInfo = new WorkflowInfo(); |
| 182 | 0 | RouteNodeInstanceDTO[] activeNodeInstances = workflowInfo.getActiveNodeInstances(new Long(documentId)); |
| 183 | 0 | if (activeNodeInstances.length > 0) { |
| 184 | 0 | return true; |
| 185 | |
} |
| 186 | 0 | return false; |
| 187 | |
} |
| 188 | |
|
| 189 | |
public static String getAuthenticationId() { |
| 190 | 0 | UserSession userSession=UserSession.getAuthenticatedUser(); |
| 191 | 0 | return userSession.getPrincipalName(); |
| 192 | |
|
| 193 | |
} |
| 194 | |
|
| 195 | |
} |