-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathQualtrics_teacher.java
88 lines (70 loc) · 2.45 KB
/
Qualtrics_teacher.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
package org.assistments.connector.lti;
import java.io.IOException;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import org.oscelot.lti.tp.Callback;
import org.oscelot.lti.tp.DataConnector;
import org.oscelot.lti.tp.ResourceLink;
import org.oscelot.lti.tp.ToolProvider;
import org.oscelot.lti.tp.User;
import org.oscelot.lti.tp.dataconnector.None;
@WebServlet({ "/qualtrics_teacher/*" })
public class Qualtrics extends HttpServlet {
private static final long serialVersionUID = 1L;
public Qualtrics() {
super();
}
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
doPost(req, resp);
}
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
String pathInfo = req.getPathInfo();
String sid = pathInfo.substring(1);
String urlPattern = req.getParameter("custom_url_pattern");
String url = urlPattern + "?SID=" + sid;
String teacher_url = req.getParameter("custom_teacher_url");
url = "https://" + url;
String role = req.getParameter("roles");
DataConnector dc = new None();
Callback doLaunch = new DoLaunch(url);
ToolProvider toolProvider = new ToolProvider(req, resp, doLaunch, dc);
toolProvider.execute();
}
class DoLaunch implements Callback {
String url;
public DoLaunch(String url) {
this.url = url;
}
@Override
public boolean execute(ToolProvider toolProvider) {
User ltiUser = toolProvider.getUser();
ResourceLink resourceLink = toolProvider.getResourceLink();
String userId = ltiUser.getId();
String resourceId = resourceLink.getId();
//Determine user role from LTI
if(ltiUser.isAdmin() || ltiUser.isStaff()) {
String teacher_url = toolProvider.getRequest().getParameter("custom_teacher_url");
url = teacher_url;
toolProvider.setRedirectUrl(teacher_url);
}
else {
url += "&user_id="+userId + "&resource_id=" + resourceId;
userId += "_" + resourceId;
ServletContext context = toolProvider.getRequest().getServletContext();
context.setAttribute(userId, ltiUser);
context.setAttribute(resourceId, resourceLink);
toolProvider.setRedirectUrl(url);
}
return true;
}
}
}