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