01: /*
02: * Copyright 2005-2006 The Kuali Foundation.
03: *
04: *
05: * Licensed under the Educational Community License, Version 1.0 (the "License");
06: * you may not use this file except in compliance with the License.
07: * You may obtain a copy of the License at
08: *
09: * http://www.opensource.org/licenses/ecl1.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 edu.iu.uis.eden.edl;
18:
19: import edu.iu.uis.eden.KEWServiceLocator;
20: import edu.iu.uis.eden.clientapp.WorkflowInfo;
21: import edu.iu.uis.eden.clientapp.vo.UserIdVO;
22: import edu.iu.uis.eden.clientapp.vo.WorkflowIdVO;
23: import edu.iu.uis.eden.exception.EdenUserNotFoundException;
24: import edu.iu.uis.eden.exception.WorkflowException;
25: import edu.iu.uis.eden.user.WorkflowUser;
26: import edu.iu.uis.eden.util.Utilities;
27: import edu.iu.uis.eden.web.session.UserSession;
28: import edu.iu.uis.eden.workgroup.GroupNameId;
29:
30: /**
31: * A collection of handy workflow queries to be used from style sheets.
32: *
33: * @author rkirkend
34: *
35: */
36: public class WorkflowFunctions {
37:
38: private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger
39: .getLogger(WorkflowFunctions.class);
40:
41: public static boolean isUserRouteLogAuthenticated(String id) {
42: boolean authenticated = false;
43: WorkflowInfo workflowInfo = new WorkflowInfo();
44:
45: UserSession userSession = UserSession.getAuthenticatedUser();
46: if (userSession != null) {
47: UserIdVO userId = new WorkflowIdVO(userSession
48: .getWorkflowUser().getWorkflowId());
49: try {
50: Long routeHeaderId = new Long(id);
51: authenticated = workflowInfo
52: .isUserAuthenticatedByRouteLog(routeHeaderId,
53: userId, true);
54: } catch (NumberFormatException e) {
55: LOG
56: .error("Invalid format routeHeaderId (should be LONG): "
57: + id);
58: } catch (WorkflowException e) {
59: LOG
60: .error("Error checking if user is route log authenticated: userId: "
61: + userId + ";routeHeaderId: " + id);
62: }
63: }
64:
65: return authenticated;
66: }
67:
68: public static boolean isUserInGroup(String groupName) {
69: boolean isUserInGroup = false;
70: try {
71: UserSession userSession = UserSession
72: .getAuthenticatedUser();
73: if (userSession != null) {
74: WorkflowUser user = userSession.getWorkflowUser();
75: if (!Utilities.isEmpty(groupName)) {
76: GroupNameId groupId = new GroupNameId(groupName);
77: isUserInGroup = KEWServiceLocator
78: .getWorkgroupService().isUserMemberOfGroup(
79: groupId, user);
80: }
81: }
82: } catch (EdenUserNotFoundException ex) {
83: LOG
84: .error("Current User is not found in group with the name: "
85: + groupName);
86: }
87: return isUserInGroup;
88: }
89:
90: public static String escapeJavascript(String value) {
91:
92: return value.replace("\\", "\\\\").replace("\"", "\\\"");
93:
94: }
95: }
|