working
This commit is contained in:
parent
6233af8e11
commit
b8dab8846b
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>
|
||||||
|
@ -1,17 +1,28 @@
|
|||||||
package com.wmi.lti.controllers;
|
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.Grade;
|
||||||
import com.wmi.lti.model.grade.GradeRepository;
|
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.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Controller;
|
|
||||||
import org.springframework.web.bind.annotation.PostMapping;
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
import org.springframework.web.bind.annotation.RequestParam;
|
import org.springframework.web.bind.annotation.RequestParam;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
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.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.IOException;
|
||||||
|
import java.io.StringReader;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Optional;
|
||||||
import java.util.Scanner;
|
import java.util.Scanner;
|
||||||
|
|
||||||
@RequestMapping("/grades")
|
@RequestMapping("/grades")
|
||||||
@ -21,14 +32,27 @@ public class GradeController {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private GradeRepository gradeRepository;
|
private GradeRepository gradeRepository;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private UserRepository userRepository;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private CourseRepository courseRepository;
|
||||||
|
|
||||||
@PostMapping("")
|
@PostMapping("")
|
||||||
public String addCourse(@RequestParam(required = false) Map<String, String> args, HttpServletRequest request) throws IOException {
|
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(".*_", ""));
|
||||||
|
|
||||||
Grade grade = new Grade();
|
Optional<Grade> gradeCheck = gradeRepository.findGradeByCourseAndUser(course, user);
|
||||||
grade.setDescription(extractPostRequestBody(request));
|
Grade grade = gradeCheck.orElseGet(Grade::new);
|
||||||
System.out.println(grade.getDescription());
|
grade.setCourse(course);
|
||||||
|
grade.setGrade(gradeValue);
|
||||||
|
grade.setUser(user);
|
||||||
gradeRepository.save(grade);
|
gradeRepository.save(grade);
|
||||||
return "done";
|
return response();
|
||||||
}
|
}
|
||||||
|
|
||||||
static String extractPostRequestBody(HttpServletRequest request) throws IOException {
|
static String extractPostRequestBody(HttpServletRequest request) throws IOException {
|
||||||
@ -39,4 +63,28 @@ public class GradeController {
|
|||||||
return "";
|
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,6 +33,9 @@ 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();
|
||||||
@ -44,7 +50,9 @@ public class StartController {
|
|||||||
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("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();
|
/* String link = course.getUrl();
|
||||||
@ -57,7 +65,15 @@ public class StartController {
|
|||||||
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
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
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;
|
||||||
|
}
|
@ -1,6 +1,14 @@
|
|||||||
package com.wmi.lti.model.grade;
|
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 org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
public interface GradeRepository extends JpaRepository<Grade, Long> {
|
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
|
||||||
|
|
||||||
|
@ -10,6 +10,23 @@
|
|||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
|
||||||
|
<style>
|
||||||
|
table {
|
||||||
|
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}">
|
<tr th:each="course: ${courses}">
|
||||||
<form target = "_blank" th:action="${course.url}" method="POST">
|
<form target = "_blank" th:action="${course.url}" method="POST">
|
||||||
<th:block th:each="parameter : ${course.signedParameters}">
|
<th:block th:each="parameter : ${course.signedParameters}">
|
||||||
@ -24,5 +41,23 @@
|
|||||||
<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