Compare commits
4 Commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
b8dab8846b | ||
![]() |
6233af8e11 | ||
![]() |
3a861f03c3 | ||
![]() |
9671929787 |
6
pom.xml
6
pom.xml
@ -33,7 +33,11 @@
|
|||||||
<artifactId>basiclti-util</artifactId>
|
<artifactId>basiclti-util</artifactId>
|
||||||
<version>1.1.2</version>
|
<version>1.1.2</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>javax.xml.parsers</groupId>
|
||||||
|
<artifactId>jaxp-api</artifactId>
|
||||||
|
<version>1.4.5</version>
|
||||||
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>mysql</groupId>
|
<groupId>mysql</groupId>
|
||||||
<artifactId>mysql-connector-java</artifactId>
|
<artifactId>mysql-connector-java</artifactId>
|
||||||
|
@ -46,7 +46,7 @@ public class CourseController {
|
|||||||
String url, @RequestParam(name = "name", required = false, defaultValue = "")
|
String url, @RequestParam(name = "name", required = false, defaultValue = "")
|
||||||
String name, Model model) {
|
String name, Model model) {
|
||||||
|
|
||||||
courseRepository.save(new Course(null, name, url, key, secret));
|
courseRepository.save(new Course(null, name, url, key, secret, null));
|
||||||
return "start"; //view
|
return "start"; //view
|
||||||
|
|
||||||
}
|
}
|
||||||
|
90
src/main/java/com/wmi/lti/controllers/GradeController.java
Normal file
90
src/main/java/com/wmi/lti/controllers/GradeController.java
Normal file
@ -0,0 +1,90 @@
|
|||||||
|
package com.wmi.lti.controllers;
|
||||||
|
|
||||||
|
import com.wmi.lti.model.course.Course;
|
||||||
|
import com.wmi.lti.model.course.CourseRepository;
|
||||||
|
import com.wmi.lti.model.grade.Grade;
|
||||||
|
import com.wmi.lti.model.grade.GradeRepository;
|
||||||
|
import com.wmi.lti.model.user.User;
|
||||||
|
import com.wmi.lti.model.user.UserRepository;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestParam;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
import org.w3c.dom.Document;
|
||||||
|
import org.xml.sax.InputSource;
|
||||||
|
import org.xml.sax.SAXException;
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import javax.xml.parsers.DocumentBuilder;
|
||||||
|
import javax.xml.parsers.DocumentBuilderFactory;
|
||||||
|
import javax.xml.parsers.ParserConfigurationException;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.StringReader;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Optional;
|
||||||
|
import java.util.Scanner;
|
||||||
|
|
||||||
|
@RequestMapping("/grades")
|
||||||
|
@RestController
|
||||||
|
public class GradeController {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private GradeRepository gradeRepository;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private UserRepository userRepository;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private CourseRepository courseRepository;
|
||||||
|
|
||||||
|
@PostMapping("")
|
||||||
|
public String addCourse(@RequestParam(required = false) Map<String, String> args, HttpServletRequest request) throws IOException {
|
||||||
|
String gradeXML = extractPostRequestBody(request);
|
||||||
|
double gradeValue = Double.valueOf(gradeXML.split("<textString>")[1].split("</textString>")[0]);
|
||||||
|
String cell = gradeXML.split("<sourcedId>")[1].split("</sourcedId>")[0];
|
||||||
|
User user = userRepository.findByUsername(cell.replaceFirst("_.*", ""));
|
||||||
|
Course course = courseRepository.findFirstByName(cell.replaceFirst(".*_", ""));
|
||||||
|
|
||||||
|
Optional<Grade> gradeCheck = gradeRepository.findGradeByCourseAndUser(course, user);
|
||||||
|
Grade grade = gradeCheck.orElseGet(Grade::new);
|
||||||
|
grade.setCourse(course);
|
||||||
|
grade.setGrade(gradeValue);
|
||||||
|
grade.setUser(user);
|
||||||
|
gradeRepository.save(grade);
|
||||||
|
return response();
|
||||||
|
}
|
||||||
|
|
||||||
|
static String extractPostRequestBody(HttpServletRequest request) throws IOException {
|
||||||
|
if ("POST".equalsIgnoreCase(request.getMethod())) {
|
||||||
|
Scanner s = new Scanner(request.getInputStream(), "UTF-8").useDelimiter("\\A");
|
||||||
|
return s.hasNext() ? s.next() : "";
|
||||||
|
}
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
private String response(){
|
||||||
|
return "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
|
||||||
|
"<imsx_POXEnvelopeResponse xmlns=\"http://www.imsglobal.org/services/ltiv1p1/xsd/imsoms_v1p0\">\n" +
|
||||||
|
" <imsx_POXHeader>\n" +
|
||||||
|
" <imsx_POXResponseHeaderInfo>\n" +
|
||||||
|
" <imsx_version>V1.0</imsx_version>\n" +
|
||||||
|
" <imsx_messageIdentifier>4560</imsx_messageIdentifier>\n" +
|
||||||
|
" <imsx_statusInfo>\n" +
|
||||||
|
" <imsx_codeMajor>success</imsx_codeMajor>\n" +
|
||||||
|
" <imsx_severity>status</imsx_severity>\n" +
|
||||||
|
" <imsx_messageRefIdentifier>999999123</imsx_messageRefIdentifier>\n" +
|
||||||
|
" <imsx_operationRefIdentifier>replaceResult</imsx_operationRefIdentifier>\n" +
|
||||||
|
" </imsx_statusInfo>\n" +
|
||||||
|
" </imsx_POXResponseHeaderInfo>\n" +
|
||||||
|
" </imsx_POXHeader>\n" +
|
||||||
|
" <imsx_POXBody>\n" +
|
||||||
|
" <replaceResultResponse />\n" +
|
||||||
|
" </imsx_POXBody>\n" +
|
||||||
|
"</imsx_POXEnvelopeResponse>";
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -2,6 +2,9 @@ package com.wmi.lti.controllers;
|
|||||||
|
|
||||||
import com.wmi.lti.model.course.Course;
|
import com.wmi.lti.model.course.Course;
|
||||||
import com.wmi.lti.model.course.CourseRepository;
|
import com.wmi.lti.model.course.CourseRepository;
|
||||||
|
import com.wmi.lti.model.grade.Grade;
|
||||||
|
import com.wmi.lti.model.grade.GradeDTO;
|
||||||
|
import com.wmi.lti.model.grade.GradeRepository;
|
||||||
import com.wmi.lti.model.user.User;
|
import com.wmi.lti.model.user.User;
|
||||||
import com.wmi.lti.model.user.UserPrincipal;
|
import com.wmi.lti.model.user.UserPrincipal;
|
||||||
import com.wmi.lti.model.user.UserRepository;
|
import com.wmi.lti.model.user.UserRepository;
|
||||||
@ -30,32 +33,47 @@ public class StartController {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private UserRepository userRepository;
|
private UserRepository userRepository;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private GradeRepository gradeRepository;
|
||||||
|
|
||||||
@GetMapping("")
|
@GetMapping("")
|
||||||
public String start(Model model){
|
public String start(Model model){
|
||||||
List<Course> courses = courseRepository.findAll();
|
List<Course> courses = courseRepository.findAll();
|
||||||
List<Course> coursesToReturn = new ArrayList<>();
|
List<Course> coursesToReturn = new ArrayList<>();
|
||||||
|
User user = userRepository.findByUsername(((UserPrincipal) SecurityContextHolder.getContext().getAuthentication().getPrincipal()).getUsername());
|
||||||
for (Course course : courses) {
|
for (Course course : courses) {
|
||||||
LtiSigner signer = new LtiOauthSigner();
|
LtiSigner signer = new LtiOauthSigner();
|
||||||
Map<String, String> parameters = new HashMap<>();
|
Map<String, String> parameters = new HashMap<>();
|
||||||
User user = userRepository.findByUsername(((UserPrincipal) SecurityContextHolder.getContext().getAuthentication().getPrincipal()).getUsername());
|
|
||||||
parameters.put("lti_message_type", "basic-lti-launch-request");
|
parameters.put("lti_message_type", "basic-lti-launch-request");
|
||||||
parameters.put("lti_version", "LTI-1p0");
|
parameters.put("lti_version", "LTI-1p0");
|
||||||
parameters.put("resource_link_id", user.getUsername() + "_" + course.getCourse_key());
|
parameters.put("resource_link_id", user.getUsername() + "_" + course.getCourse_key());
|
||||||
parameters.put("user_id", user.getId().toString());
|
parameters.put("user_id", user.getId().toString());
|
||||||
parameters.put("lis_person_name_given", user.getUsername());
|
parameters.put("lis_person_name_given", user.getUsername());
|
||||||
parameters.put("tool_consumer_instance_name", "wmi.lti");
|
parameters.put("tool_consumer_instance_name", "wmi.lti");
|
||||||
|
//parameters.put("target", "frame");
|
||||||
|
parameters.put("lis_outcome_service_url", "http://localhost:8080/grades");
|
||||||
|
parameters.put("lis_result_sourcedid", user.getUsername() + "_" + course.getCourse_key());
|
||||||
try {
|
try {
|
||||||
Map<String, String> signedParameters = signer.signParameters(parameters, course.getCourse_key(), course.getSecret(), course.getUrl(), "POST");
|
Map<String, String> signedParameters = signer.signParameters(parameters, course.getCourse_key(), course.getSecret(), course.getUrl(), "POST");
|
||||||
String link = course.getUrl() + "?" + "oauth_nonce=" + signedParameters.get("oauth_nonce") + "&oauth_signature=" + signedParameters.get("oauth_signature") + "&oauth_consumer_key=" + signedParameters.get("oauth_consumer_key") + "&oauth_signature_method=" + signedParameters.get("oauth_signature_method") + "&oauth_timestamp=" + signedParameters.get("oauth_timestamp") + "&oauth_version=" + signedParameters.get("oauth_version") + "<i_message_type=" + signedParameters.get("lti_message_type") + "<i_version=" + signedParameters.get("lti_version") + "&resource_link_id=" + signedParameters.get("resource_link_id") + "&user_id=" + signedParameters.get("user_id") + "&lis_person_name_given=" + signedParameters.get("lis_person_name_given") + "&tool_consumer_instance_name=" + signedParameters.get("tool_consumer_instance_name");
|
/* String link = course.getUrl();
|
||||||
|
link += "?oauth_nonce=" + signedParameters.get("oauth_nonce") + "&oauth_signature=" + signedParameters.get("oauth_signature") + "&oauth_consumer_key=" + signedParameters.get("oauth_consumer_key") + "&oauth_signature_method=" + signedParameters.get("oauth_signature_method") + "&oauth_timestamp=" + signedParameters.get("oauth_timestamp") + "&oauth_version=" + signedParameters.get("oauth_version") + "<i_message_type=" + signedParameters.get("lti_message_type") + "<i_version=" + signedParameters.get("lti_version") + "&resource_link_id=" + signedParameters.get("resource_link_id") + "&user_id=" + signedParameters.get("user_id") + "&lis_person_name_given=" + signedParameters.get("lis_person_name_given") + "&tool_consumer_instance_name=" + signedParameters.get("tool_consumer_instance_name") + "&target=" + signedParameters.get("target");
|
||||||
|
*/
|
||||||
course.setSecret(null);
|
course.setSecret(null);
|
||||||
course.setCourse_key(null);
|
course.setSignedParameters(signedParameters);
|
||||||
course.setUrl(link);
|
|
||||||
coursesToReturn.add(course);
|
coursesToReturn.add(course);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
List<Grade> grades = gradeRepository.findAllByUser(user);
|
||||||
|
List<GradeDTO> gradeDTOS = new ArrayList<>();
|
||||||
|
for (Grade grade : grades){
|
||||||
|
gradeDTOS.add(new GradeDTO(grade.getCourse().getName(), grade.getGrade()* 100 + "%"));
|
||||||
|
}
|
||||||
|
|
||||||
model.addAttribute("courses", coursesToReturn);
|
model.addAttribute("courses", coursesToReturn);
|
||||||
|
model.addAttribute("grades", gradeDTOS);
|
||||||
return "start"; //view
|
return "start"; //view
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,10 +5,8 @@ import lombok.Getter;
|
|||||||
import lombok.NoArgsConstructor;
|
import lombok.NoArgsConstructor;
|
||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
|
|
||||||
import javax.persistence.Entity;
|
import javax.persistence.*;
|
||||||
import javax.persistence.GeneratedValue;
|
import java.util.Map;
|
||||||
import javax.persistence.GenerationType;
|
|
||||||
import javax.persistence.Id;
|
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
@ -37,4 +35,9 @@ public class Course {
|
|||||||
@Setter
|
@Setter
|
||||||
private String secret;
|
private String secret;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
@Transient
|
||||||
|
private Map<String, String> signedParameters;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,6 @@ import org.springframework.data.jpa.repository.JpaRepository;
|
|||||||
|
|
||||||
public interface CourseRepository extends JpaRepository<Course, Long> {
|
public interface CourseRepository extends JpaRepository<Course, Long> {
|
||||||
|
|
||||||
|
Course findFirstByName(String name);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
41
src/main/java/com/wmi/lti/model/grade/Grade.java
Normal file
41
src/main/java/com/wmi/lti/model/grade/Grade.java
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
package com.wmi.lti.model.grade;
|
||||||
|
|
||||||
|
import com.wmi.lti.model.course.Course;
|
||||||
|
import com.wmi.lti.model.user.User;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
import lombok.Setter;
|
||||||
|
|
||||||
|
import javax.persistence.*;
|
||||||
|
|
||||||
|
@Entity
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
public class Grade {
|
||||||
|
|
||||||
|
@Id
|
||||||
|
@GeneratedValue(strategy = GenerationType.AUTO)
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
@ManyToOne
|
||||||
|
private Course course;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
@ManyToOne
|
||||||
|
private User user;
|
||||||
|
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
private Double grade;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
private String description;
|
||||||
|
}
|
14
src/main/java/com/wmi/lti/model/grade/GradeDTO.java
Normal file
14
src/main/java/com/wmi/lti/model/grade/GradeDTO.java
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
package com.wmi.lti.model.grade;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
|
||||||
|
@AllArgsConstructor
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
public class GradeDTO {
|
||||||
|
|
||||||
|
private String courseName;
|
||||||
|
private String score;
|
||||||
|
}
|
14
src/main/java/com/wmi/lti/model/grade/GradeRepository.java
Normal file
14
src/main/java/com/wmi/lti/model/grade/GradeRepository.java
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
package com.wmi.lti.model.grade;
|
||||||
|
|
||||||
|
import com.wmi.lti.model.course.Course;
|
||||||
|
import com.wmi.lti.model.user.User;
|
||||||
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
public interface GradeRepository extends JpaRepository<Grade, Long> {
|
||||||
|
Optional<Grade> findGradeByCourseAndUser(Course course, User user);
|
||||||
|
|
||||||
|
List<Grade> findAllByUser(User user);
|
||||||
|
}
|
@ -1,5 +1,5 @@
|
|||||||
spring.jpa.hibernate.ddl-auto=update
|
spring.jpa.hibernate.ddl-auto=update
|
||||||
spring.datasource.url=jdbc:mysql://localhost:3306/lti
|
spring.datasource.url=jdbc:mysql://localhost:3307/lti
|
||||||
spring.datasource.username=lti
|
spring.datasource.username=lti
|
||||||
spring.datasource.password=YnBDC0hqqhKaxt94
|
spring.datasource.password=YnBDC0hqqhKaxt94
|
||||||
|
|
||||||
|
@ -9,15 +9,55 @@
|
|||||||
<link rel="stylesheet" th:href="@{/css/main.css}"/>
|
<link rel="stylesheet" th:href="@{/css/main.css}"/>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<tr th:each="course : ${courses}">
|
|
||||||
<form th:action="${course.url}" method="POST">
|
<style>
|
||||||
<input type="submit">Launch Tool</input>
|
table {
|
||||||
</form>
|
border-collapse: collapse;
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
td, th {
|
||||||
|
border: 1px solid #dddddd;
|
||||||
|
text-align: left;
|
||||||
|
padding: 8px;
|
||||||
|
}
|
||||||
|
|
||||||
|
tr:nth-child(even) {
|
||||||
|
background-color: #dddddd;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
|
||||||
|
<tr th:each="course: ${courses}">
|
||||||
|
<form target = "_blank" th:action="${course.url}" method="POST">
|
||||||
|
<th:block th:each="parameter : ${course.signedParameters}">
|
||||||
|
<input type="hidden" th:name="${parameter.key}" th:value="${parameter.value}" />
|
||||||
|
</th:block>
|
||||||
|
<input th:value="${course.name}" type="submit"/>
|
||||||
|
</form>
|
||||||
</tr>
|
</tr>
|
||||||
|
|
||||||
|
|
||||||
<br><br><br>
|
<br><br><br>
|
||||||
<form th:action="@{/courses/addCourse}" method="GET">
|
<form th:action="@{/courses/addCourse}" method="GET">
|
||||||
<div><input type="submit" value="Add new content"/></div>
|
<div><input type="submit" value="Add new content"/></div>
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
|
<br><br><br>
|
||||||
|
<H3>Grades</H3>
|
||||||
|
|
||||||
|
<table>
|
||||||
|
<tr>
|
||||||
|
<th>Course</th>
|
||||||
|
<th>Grade</th>
|
||||||
|
</tr>
|
||||||
|
<th:block th:each="grade: ${grades}">
|
||||||
|
|
||||||
|
<tr>
|
||||||
|
<td th:text="${grade.courseName}">...</td>
|
||||||
|
<td th:text="${grade.score}">...</td>
|
||||||
|
</tr>
|
||||||
|
</th:block>
|
||||||
|
</table>
|
||||||
|
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
Loading…
Reference in New Issue
Block a user