Commit d1c9c9ad authored by inusha maduranga's avatar inusha maduranga

Spring boot web service with flask integration

parent ff1483e2
<?xml version="1.0" encoding="UTF-8"?>
<project-shared-configuration>
<!--
This file contains additional configuration written by modules in the NetBeans IDE.
The configuration is intended to be shared among all the users of project and
therefore it is assumed to be part of version control checkout.
Without this configuration present, some functionality in the IDE may be limited or fail altogether.
-->
<properties xmlns="http://www.netbeans.org/ns/maven-properties-data/1">
<!--
Properties that influence various parts of the IDE, especially code formatting and the like.
You can copy and paste the single properties, into the pom.xml file and the IDE will pick them up.
That way multiple projects can share the same settings (useful for formatting rules for example).
Any value defined here will override the pom.xml file value but is only applicable to the current project.
-->
<org-netbeans-modules-maven-j2ee.netbeans_2e_hint_2e_j2eeVersion>1.7-web</org-netbeans-modules-maven-j2ee.netbeans_2e_hint_2e_j2eeVersion>
<org-netbeans-modules-maven-j2ee.netbeans_2e_hint_2e_deploy_2e_server>Tomcat</org-netbeans-modules-maven-j2ee.netbeans_2e_hint_2e_deploy_2e_server>
<netbeans.compile.on.save>none</netbeans.compile.on.save>
</properties>
</project-shared-configuration>
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.cdap_2020_027</groupId>
<artifactId>elearning-ws</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>war</packaging>
<name>elearning-ws</name>
<description>E-learning Spring Boot </description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.0.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- In production build use below dependency -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
<!-- https://mvnrepository.com/artifact/javax.mail/mail -->
<dependency>
<groupId>javax.mail</groupId>
<artifactId>mail</artifactId>
<version>1.4</version>
</dependency>
<!-- send email -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-mail</artifactId>
</dependency>
</dependencies>
<build>
<finalName>${artifactId}</finalName>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
package com.cdap_2020_027.elearning.ws;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
@SpringBootApplication
public class ElearningWsApplication extends SpringBootServletInitializer{
public static void main(String[] args) {
SpringApplication.run(ElearningWsApplication.class, args);
}
}
package com.cdap_2020_027.elearning.ws.controller;
import com.cdap_2020_027.elearning.ws.model.LoginResponse;
import com.cdap_2020_027.elearning.ws.model.PaperResult;
import com.cdap_2020_027.elearning.ws.model.PaperResultFinal;
import com.cdap_2020_027.elearning.ws.model.ProgressData;
import com.cdap_2020_027.elearning.ws.model.Question;
import com.cdap_2020_027.elearning.ws.model.QuestionResult;
import com.cdap_2020_027.elearning.ws.model.SearchList;
import com.cdap_2020_027.elearning.ws.service.QuestionServiceImpl;
import com.cdap_2020_027.elearning.ws.service.SystemUserServiceImpl;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
/**
*
* @author IT17119122 Liyanage I.M
*/
@RestController
@CrossOrigin
public class QuestionController {
@Autowired
QuestionServiceImpl questionServiceImpl;
@Autowired
SystemUserServiceImpl systemUserServiceImpl;
// get area / topic /sub topic Details
@RequestMapping(value = "/searchlist", method = RequestMethod.GET)
public ResponseEntity<SearchList> getAreas() {
try {
SearchList searchList = questionServiceImpl.getSearchList();
return new ResponseEntity<>(searchList, HttpStatus.OK);
} catch (Exception ex) {
System.out.println(ex);
return new ResponseEntity<>(null, HttpStatus.INTERNAL_SERVER_ERROR);
}
}
// get qustion paper Details
@RequestMapping(value = "/questions/{area}/{topic}", method = RequestMethod.POST)
public ResponseEntity<List<Question>> getQuestionList(@PathVariable(value = "area") String area,
@PathVariable(value = "topic") String topic, @RequestBody List<String> subtopic) {
try {
System.out.println(subtopic);
List<Question> questionList = questionServiceImpl.getQuestionList(area, topic, subtopic);
return new ResponseEntity<>(questionList, HttpStatus.OK);
} catch (Exception ex) {
System.out.println(ex);
return new ResponseEntity<>(null, HttpStatus.INTERNAL_SERVER_ERROR);
}
}
// Save qustion paper result Details
@RequestMapping(value = "/paperresult", method = RequestMethod.POST)
public ResponseEntity<LoginResponse> questionPaperResult(@RequestBody PaperResult paperResult) {
try {
LoginResponse loginResponse = questionServiceImpl.questionPaperResult(paperResult);
return new ResponseEntity<>(loginResponse, HttpStatus.OK);
} catch (Exception ex) {
System.out.println(ex);
return new ResponseEntity<>(null, HttpStatus.INTERNAL_SERVER_ERROR);
}
}
// get Question papers by student id
@RequestMapping(value = "/getpapers/{id}", method = RequestMethod.GET)
public ResponseEntity<List<PaperResultFinal>> getPapers(@PathVariable(value = "id") int id) {
try {
List<PaperResultFinal> paperResultFinalList = questionServiceImpl.getPapers(id);
return new ResponseEntity<>(paperResultFinalList, HttpStatus.OK);
} catch (Exception ex) {
System.out.println(ex);
return new ResponseEntity<>(null, HttpStatus.INTERNAL_SERVER_ERROR);
}
}
// get Question paper by student id , paper number , subtopic
@RequestMapping(value = "/getpaper/{id}/", method = RequestMethod.GET)
public ResponseEntity<QuestionResult> getPaper(@PathVariable(value = "id") int id) {
try {
QuestionResult questionResult = questionServiceImpl.getPaper(id);
return new ResponseEntity<>(questionResult, HttpStatus.OK);
} catch (Exception ex) {
System.out.println(ex);
return new ResponseEntity<>(null, HttpStatus.INTERNAL_SERVER_ERROR);
}
}
// get Question paper by student id , paper number , subtopic
@RequestMapping(value = "/getprogress/{sid}/", method = RequestMethod.GET)
public ResponseEntity<List<ProgressData>> getLearningProgress(@PathVariable(value = "sid") int sid) {
try {
List<ProgressData> ProgressDataList = questionServiceImpl.getLearningProgress(sid);
return new ResponseEntity<>(ProgressDataList, HttpStatus.OK);
} catch (Exception ex) {
System.out.println(ex);
return new ResponseEntity<>(null, HttpStatus.INTERNAL_SERVER_ERROR);
}
}
}
package com.cdap_2020_027.elearning.ws.controller;
import com.cdap_2020_027.elearning.ws.model.CommonResponse;
import com.cdap_2020_027.elearning.ws.model.LoginRequest;
import com.cdap_2020_027.elearning.ws.model.LoginResponse;
import com.cdap_2020_027.elearning.ws.model.SystemUser;
import com.cdap_2020_027.elearning.ws.service.SystemUserServiceImpl;
import javax.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
/**
*
* @author (IT17119122 ** Liyanage I.M)
*/
@RestController
@CrossOrigin
public class UserController {
@Autowired
SystemUserServiceImpl systemUserServiceImpl;
@RequestMapping(value = "/login", method = RequestMethod.POST)
public ResponseEntity<LoginResponse> login(@RequestBody LoginRequest loginRequest) {
try{
SystemUser systemUser = systemUserServiceImpl.findByUsernameandPassword(loginRequest.getUsername(),loginRequest.getPassword());
if(systemUser == null) {
LoginResponse loginResponse = new LoginResponse();
loginResponse.setResponseCode("LOGIN_FAILED’");
loginResponse.setResponseMessage("Login failed");
return new ResponseEntity<>(loginResponse, HttpStatus.OK);
}
LoginResponse loginResponse = new LoginResponse();
loginResponse.setResponseCode("LOGIN_SUCCESS");
loginResponse.setResponseMessage("Successfully logged in");
loginResponse.setSystemUser(systemUser);
return new ResponseEntity<>(loginResponse, HttpStatus.OK);
} catch (Exception ex) {
System.out.println(ex);
return new ResponseEntity<>(null, HttpStatus.INTERNAL_SERVER_ERROR);
}
}
@RequestMapping(value = "/save/systemuser", method = RequestMethod.POST)
public ResponseEntity<CommonResponse> saveSystemUser(@Valid @RequestBody SystemUser systemUser) {
try {
systemUserServiceImpl.saveUser(systemUser);
return new ResponseEntity<>(new CommonResponse("SUCSESS", "Item successfully saved"), HttpStatus.OK);
} catch (Exception ex) {
System.out.println(ex);
return new ResponseEntity<>(null, HttpStatus.INTERNAL_SERVER_ERROR);
}
}
}
package com.cdap_2020_027.elearning.ws.model;
/**
*
* @author IT17119122
*/
public class CommonResponse {
private String responseCode;
private String responseText;
public CommonResponse() {
}
public CommonResponse(String responseCode, String responseText) {
this.responseCode = responseCode;
this.responseText = responseText;
}
public String getResponseCode() {
return responseCode;
}
public void setResponseCode(String responseCode) {
this.responseCode = responseCode;
}
public String getResponseText() {
return responseText;
}
public void setResponseText(String responseText) {
this.responseText = responseText;
}
}
package com.cdap_2020_027.elearning.ws.model;
/**
*
* @author (IT17119122 ** Liyanage I.M)
*/
public class LoginRequest {
private String username;
private String password;
public LoginRequest(String username, String password) {
this.username = username;
this.password = password;
}
public LoginRequest() {
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
}
package com.cdap_2020_027.elearning.ws.model;
/**
*
* @author (IT17119122 ** Liyanage I.M)
*/
public class LoginResponse {
private String responseCode;
private String responseMessage;
private String type;
private SystemUser systemUser;
public LoginResponse(String responseCode, String responseMessage, String type , SystemUser systemUser) {
this.responseCode = responseCode;
this.responseMessage = responseMessage;
this.systemUser = systemUser;
this.type = type;
}
public LoginResponse() {
}
public String getResponseCode() {
return responseCode;
}
public void setResponseCode(String responseCode) {
this.responseCode = responseCode;
}
public String getResponseMessage() {
return responseMessage;
}
public void setResponseMessage(String responseMessage) {
this.responseMessage = responseMessage;
}
public SystemUser getSystemUser() {
return systemUser;
}
public void setSystemUser(SystemUser systemUser) {
this.systemUser = systemUser;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
}
package com.cdap_2020_027.elearning.ws.model;
import java.util.List;
/**
*
* @author IT17119122 Liyanage I.M
*/
public class PaperResult {
LoginResponse loginResponse;
List<StudentAnswer> studentAnswerList;
Integer paperNo;
Integer totalQuestionNo;
Integer correctQuestionNo;
Integer averageScore;
String grade;
String status;
String area;
String topic;
List<String> subtopic;
String date;
Integer previouPaperId;
String uniqueId;
public LoginResponse getLoginResponse() {
return loginResponse;
}
public void setLoginResponse(LoginResponse loginResponse) {
this.loginResponse = loginResponse;
}
public List<StudentAnswer> getStudentAnswerList() {
return studentAnswerList;
}
public void setStudentAnswerList(List<StudentAnswer> studentAnswerList) {
this.studentAnswerList = studentAnswerList;
}
public Integer getPaperNo() {
return paperNo;
}
public void setPaperNo(Integer paperNo) {
this.paperNo = paperNo;
}
public Integer getTotalQuestionNo() {
return totalQuestionNo;
}
public void setTotalQuestionNo(Integer totalQuestionNo) {
this.totalQuestionNo = totalQuestionNo;
}
public Integer getCorrectQuestionNo() {
return correctQuestionNo;
}
public void setCorrectQuestionNo(Integer correctQuestionNo) {
this.correctQuestionNo = correctQuestionNo;
}
public Integer getAverageScore() {
return averageScore;
}
public void setAverageScore(Integer averageScore) {
this.averageScore = averageScore;
}
public String getGrade() {
return grade;
}
public void setGrade(String grade) {
this.grade = grade;
}
public String getStatus() {
return status;
}
public void setStatus(String status) {
this.status = status;
}
public String getArea() {
return area;
}
public void setArea(String area) {
this.area = area;
}
public String getTopic() {
return topic;
}
public void setTopic(String topic) {
this.topic = topic;
}
public List<String> getSubtopic() {
return subtopic;
}
public void setSubtopic(List<String> subtopic) {
this.subtopic = subtopic;
}
public String getDate() {
return date;
}
public void setDate(String date) {
this.date = date;
}
public Integer getPreviouPaperId() {
return previouPaperId;
}
public void setPreviouPaperId(Integer previouPaperId) {
this.previouPaperId = previouPaperId;
}
public String getUniqueId() {
return uniqueId;
}
public void setUniqueId(String uniqueId) {
this.uniqueId = uniqueId;
}
}
package com.cdap_2020_027.elearning.ws.model;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
/**
*
* @author IT17119122 Liyanage I.M
*/
@Entity
@Table(name = "paper_result_student_final")
public class PaperResultFinal {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "ID")
private Integer id;
@Column(name = "SID")
private Integer sid;
@Column(name = "PAPER_NO")
private Integer paperNo;
@Column(name = "UNIQUE_ID")
private String uniqueId;
@Column(name = "TOTAL_QUESTION_NO")
private Integer totalQuestionNo;
@Column(name = "CORRECT_QUESTION_NO")
private Integer correctQuestionNo;
@Column(name = "AVERAGE_SCORE")
private Integer averageScore;
@Column(name = "GRADE")
private String grade;
@Column(name = "STATUS")
private String status;
@Column(name = "AREA")
private String area;
@Column(name = "TOPIC")
private String topic;
@Column(name = "SUB_TOPIC")
private String subtopic;
@Column(name = "FLAG")
private String flag;
@Column(name = "DATE")
private String date;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public Integer getSid() {
return sid;
}
public void setSid(Integer sid) {
this.sid = sid;
}
public Integer getPaperNo() {
return paperNo;
}
public void setPaperNo(Integer paperNo) {
this.paperNo = paperNo;
}
public String getUniqueId() {
return uniqueId;
}
public void setUniqueId(String uniqueId) {
this.uniqueId = uniqueId;
}
public Integer getTotalQuestionNo() {
return totalQuestionNo;
}
public void setTotalQuestionNo(Integer totalQuestionNo) {
this.totalQuestionNo = totalQuestionNo;
}
public Integer getCorrectQuestionNo() {
return correctQuestionNo;
}
public void setCorrectQuestionNo(Integer correctQuestionNo) {
this.correctQuestionNo = correctQuestionNo;
}
public Integer getAverageScore() {
return averageScore;
}
public void setAverageScore(Integer averageScore) {
this.averageScore = averageScore;
}
public String getGrade() {
return grade;
}
public void setGrade(String grade) {
this.grade = grade;
}
public String getStatus() {
return status;
}
public void setStatus(String status) {
this.status = status;
}
public String getArea() {
return area;
}
public void setArea(String area) {
this.area = area;
}
public String getTopic() {
return topic;
}
public void setTopic(String topic) {
this.topic = topic;
}
public String getSubtopic() {
return subtopic;
}
public void setSubtopic(String subtopic) {
this.subtopic = subtopic;
}
public String getFlag() {
return flag;
}
public void setFlag(String flag) {
this.flag = flag;
}
public String getDate() {
return date;
}
public void setDate(String date) {
this.date = date;
}
}
package com.cdap_2020_027.elearning.ws.model;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
/**
*
* @author IT17119122 Liyanage I.M
*/
@Entity
@Table(name = "paper_result_student")
public class PaperResultStudent {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "ID")
private Integer id;
@Column(name = "UNIQUE_ID")
private String uniqueId;
@Column(name = "FINAL_PAPER_ID")
private Integer finalPaperId;
@Column(name = "PAPER_NO")
private Integer paperNo;
@Column(name = "QUESTION_ID")
private Integer questionId;
@Column(name = "WEIGHT")
private Integer weight;
@Column(name = "STUDENT_ANSWER")
private Integer studentAnswer;
@Column(name = "CORRECT_ANSWER")
private Integer correctAnswer;
@Column(name = "TIME")
private String time;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getUniqueId() {
return uniqueId;
}
public void setUniqueId(String uniqueId) {
this.uniqueId = uniqueId;
}
public Integer getFinalPaperId() {
return finalPaperId;
}
public void setFinalPaperId(Integer finalPaperId) {
this.finalPaperId = finalPaperId;
}
public Integer getPaperNo() {
return paperNo;
}
public void setPaperNo(Integer paperNo) {
this.paperNo = paperNo;
}
public Integer getQuestionId() {
return questionId;
}
public void setQuestionId(Integer questionId) {
this.questionId = questionId;
}
public Integer getWeight() {
return weight;
}
public void setWeight(Integer weight) {
this.weight = weight;
}
public Integer getStudentAnswer() {
return studentAnswer;
}
public void setStudentAnswer(Integer studentAnswer) {
this.studentAnswer = studentAnswer;
}
public Integer getCorrectAnswer() {
return correctAnswer;
}
public void setCorrectAnswer(Integer correctAnswer) {
this.correctAnswer = correctAnswer;
}
public String getTime() {
return time;
}
public void setTime(String time) {
this.time = time;
}
}
package com.cdap_2020_027.elearning.ws.model;
import java.util.ArrayList;
/**
*
* @author IT17119122 Liyanage I.M
*/
public class ProgressData {
ArrayList<Float> learningProgresList;
ArrayList<String> PaperLabelList;
String subTopic;
public ArrayList<Float> getLearningProgresList() {
return learningProgresList;
}
public void setLearningProgresList(ArrayList<Float> learningProgresList) {
this.learningProgresList = learningProgresList;
}
public ArrayList<String> getPaperLabelList() {
return PaperLabelList;
}
public void setPaperLabelList(ArrayList<String> PaperLabelList) {
this.PaperLabelList = PaperLabelList;
}
public String getSubTopic() {
return subTopic;
}
public void setSubTopic(String subTopic) {
this.subTopic = subTopic;
}
}
package com.cdap_2020_027.elearning.ws.model;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
/**
*
* @author IT17119122 Liyanage I.M
*/
@Entity
@Table(name = "question_bank")
public class Question {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "ID")
private Integer id;
@Column(name = "AREA")
private String area;
@Column(name = "TOPIC")
private String topic;
@Column(name = "SUB_TOPIC")
private String subTopic;
@Column(name = "WEIGHT")
private Integer weight;
@Column(name = "QUESTION")
private String question;
@Column(name = "ANSWER_1")
private String answer1;
@Column(name = "ANSWER_2")
private String answer2;
@Column(name = "ANSWER_3")
private String answer3;
@Column(name = "ANSWER_4")
private String answer4;
@Column(name = "CORRECT_ANSWER")
private Integer correctAnswer;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getArea() {
return area;
}
public void setArea(String area) {
this.area = area;
}
public String getTopic() {
return topic;
}
public void setTopic(String topic) {
this.topic = topic;
}
public String getSubTopic() {
return subTopic;
}
public void setSubTopic(String subTopic) {
this.subTopic = subTopic;
}
public Integer getWeight() {
return weight;
}
public void setWeight(Integer weight) {
this.weight = weight;
}
public String getQuestion() {
return question;
}
public void setQuestion(String question) {
this.question = question;
}
public String getAnswer1() {
return answer1;
}
public void setAnswer1(String answer1) {
this.answer1 = answer1;
}
public String getAnswer2() {
return answer2;
}
public void setAnswer2(String answer2) {
this.answer2 = answer2;
}
public String getAnswer3() {
return answer3;
}
public void setAnswer3(String answer3) {
this.answer3 = answer3;
}
public String getAnswer4() {
return answer4;
}
public void setAnswer4(String answer4) {
this.answer4 = answer4;
}
public Integer getCorrectAnswer() {
return correctAnswer;
}
public void setCorrectAnswer(Integer correctAnswer) {
this.correctAnswer = correctAnswer;
}
}
package com.cdap_2020_027.elearning.ws.model;
import java.util.List;
/**
*
* @author IT17119122 Liyanage I.M
*/
public class QuestionResult {
List<PaperResultStudent> answerList;
List<Question> questionList;
public List<PaperResultStudent> getAnswerList() {
return answerList;
}
public void setAnswerList(List<PaperResultStudent> answerList) {
this.answerList = answerList;
}
public List<Question> getQuestionList() {
return questionList;
}
public void setQuestionList(List<Question> questionList) {
this.questionList = questionList;
}
}
package com.cdap_2020_027.elearning.ws.model;
import java.util.List;
/**
*
* @author IT17119122 Liyanage I.M
*/
public class SearchList {
List<String> areaList;
List<String> topicList;
List<Question> SubTopicList;
public List<String> getAreaList() {
return areaList;
}
public void setAreaList(List<String> areaList) {
this.areaList = areaList;
}
public List<String> getTopicList() {
return topicList;
}
public void setTopicList(List<String> topicList) {
this.topicList = topicList;
}
public List<Question> getSubTopicList() {
return SubTopicList;
}
public void setSubTopicList(List<Question> SubTopicList) {
this.SubTopicList = SubTopicList;
}
}
package com.cdap_2020_027.elearning.ws.model;
import java.util.Date;
/**
*
* @author IT17119122 Liyanage I.M
*/
public class StudentAnswer {
Integer questionId;
Integer weight;
String studentAnswer;
Integer correctAnswer;
String time;
public Integer getQuestionId() {
return questionId;
}
public void setQuestionId(Integer questionId) {
this.questionId = questionId;
}
public Integer getWeight() {
return weight;
}
public void setWeight(Integer weight) {
this.weight = weight;
}
public String getStudentAnswer() {
return studentAnswer;
}
public void setStudentAnswer(String studentAnswer) {
this.studentAnswer = studentAnswer;
}
public Integer getCorrectAnswer() {
return correctAnswer;
}
public void setCorrectAnswer(Integer correctAnswer) {
this.correctAnswer = correctAnswer;
}
public String getTime() {
return time;
}
public void setTime(String time) {
this.time = time;
}
}
package com.cdap_2020_027.elearning.ws.model;
/**
*
* @author IT17119122 Liyanage I.M
*/
public class SubTopicDto {
String topic;
String subtopic;
public String getTopic() {
return topic;
}
public void setTopic(String topic) {
this.topic = topic;
}
public String getSubtopic() {
return subtopic;
}
public void setSubtopic(String subtopic) {
this.subtopic = subtopic;
}
}
package com.cdap_2020_027.elearning.ws.model;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Table;
import javax.persistence.Id;
/**
*
* @author (IT17119122 ** Liyanage I.M)
*/
@Entity
@Table(name = "systemuser")
public class SystemUser {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "ID")
private Integer id;
@Column(name = "USERNAME")
private String username;
@Column(name = "PASSWORD")
private String password;
@Column(name = "EMAIL")
private String email;
@Column(name = "TYPE")
private String type;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
}
package com.cdap_2020_027.elearning.ws.repository;
import com.cdap_2020_027.elearning.ws.model.PaperResultFinal;
import java.util.List;
import javax.transaction.Transactional;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
/**
*
* @author IT17119122 Liyanage I.M
*/
public interface PaperResultFinalRepository extends JpaRepository<PaperResultFinal, Integer>{
@Query(value = "SELECT * FROM paper_result_student_final WHERE SID = ?1 ", nativeQuery = true)
List<PaperResultFinal> getPapers(int id);
@Query(value = "SELECT * FROM paper_result_student_final WHERE ID = ?1", nativeQuery = true)
PaperResultFinal getPaper(int id);
@Modifying
@Transactional
@Query(value = "update paper_result_student_final set FLAG = ?1 where ID = ?2", nativeQuery = true)
int updateFlag(String flag,int id);
@Modifying
@Transactional
@Query(value = "update paper_result_student_final set FLAG = ?1 where ID = ?2", nativeQuery = true)
int updateFlagPrevious(String flag,int previouPaperId);
// @Query(value = "SELECT DISTINCT UNIQUE_ID,SUB_TOPIC FROM paper_result_student_final WHERE SID = ?1", nativeQuery = true)
@Query("SELECT DISTINCT p.uniqueId,p.subtopic FROM PaperResultFinal p WHERE p.sid = ?1")
List<Object[]> getUniqueIds(int sid);
}
package com.cdap_2020_027.elearning.ws.repository;
import com.cdap_2020_027.elearning.ws.model.PaperResultStudent;
import java.util.List;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
/**
*
* @author IT17119122 Liyanage I.M
*/
public interface PaperResultStudentRepository extends JpaRepository<PaperResultStudent, Integer>{
@Query(value = "SELECT * FROM paper_result_student WHERE FINAL_PAPER_ID = ?1", nativeQuery = true)
List<PaperResultStudent> getPaper(int paperNo);
}
package com.cdap_2020_027.elearning.ws.repository;
import com.cdap_2020_027.elearning.ws.model.Question;
import java.util.List;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
/**
*
* @author IT17119122 Liyanage I.M
*/
public interface QuestionRepository extends JpaRepository<Question, Integer>{
@Query(value = "SELECT DISTINCT AREA FROM question_bank", nativeQuery = true)
List<String> getQuestionAreas();
@Query(value = "SELECT DISTINCT TOPIC FROM question_bank", nativeQuery = true)
List<String> getQuestionTopics();
@Query("SELECT DISTINCT b.subTopic,b.topic FROM Question b")
List<Question> getQuestionSubTopics();
@Query(value = "SELECT * FROM question_bank WHERE AREA = ?1 AND TOPIC = ?2 AND SUB_TOPIC IN ?3 ORDER BY RAND() LIMIT 30", nativeQuery = true)
List<Question> getQuestionList(String area,String topic,List<String> subtopic);
@Query(value = "SELECT * FROM question_bank WHERE ID = ?1 ", nativeQuery = true)
Question getQuestion(int id);
}
package com.cdap_2020_027.elearning.ws.repository;
import com.cdap_2020_027.elearning.ws.model.SystemUser;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
public interface SystemUserRepository extends JpaRepository<SystemUser, Integer>{
@Query("select su from SystemUser su where su.username = ?1 and su.password = ?2")
SystemUser findByUsernameandPassword(String username,String password);
}
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package com.cdap_2020_027.elearning.ws.service;
/**
*
* @author IT17119122 Liyanage I.M
*/
public class NewClass {
}
package com.cdap_2020_027.elearning.ws.service;
import com.cdap_2020_027.elearning.ws.model.LoginResponse;
import com.cdap_2020_027.elearning.ws.model.PaperResult;
import com.cdap_2020_027.elearning.ws.model.PaperResultFinal;
import com.cdap_2020_027.elearning.ws.model.PaperResultStudent;
import com.cdap_2020_027.elearning.ws.model.ProgressData;
import com.cdap_2020_027.elearning.ws.model.Question;
import com.cdap_2020_027.elearning.ws.model.QuestionResult;
import com.cdap_2020_027.elearning.ws.model.SearchList;
import com.cdap_2020_027.elearning.ws.model.StudentAnswer;
import com.cdap_2020_027.elearning.ws.repository.PaperResultFinalRepository;
import com.cdap_2020_027.elearning.ws.repository.PaperResultStudentRepository;
import com.cdap_2020_027.elearning.ws.repository.QuestionRepository;
import com.cdap_2020_027.elearning.ws.util.FetchDataIntegration;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.UUID;
import com.fasterxml.jackson.databind.ObjectMapper;
/**
*
* @author IT17119122 Liyanage I.M
*/
@Service
public class QuestionServiceImpl {
@Autowired
QuestionRepository questionRepository;
@Autowired
PaperResultStudentRepository paperResultStudentRepository;
@Autowired
PaperResultFinalRepository paperResultFinalRepository;
public SearchList getSearchList() {
List<String> areaList = questionRepository.getQuestionAreas();
List<String> topicList = questionRepository.getQuestionTopics();
List<Question> SubTopicList = questionRepository.getQuestionSubTopics();
// List<SubTopicDto> SubTopicDtoList = new ArrayList<>();
// int i=1;
// //create Value, lable paire for the react-selecter
// for (String SubTopic : SubTopicList) {
// SubTopicDto subTopicDto = new SubTopicDto();
// subTopicDto.setId(i);
// subTopicDto.setLabel(SubTopic);
//
// SubTopicDtoList.add(subTopicDto);
// i++;
// }
SearchList searchList = new SearchList();
searchList.setAreaList(areaList);
searchList.setTopicList(topicList);
searchList.setSubTopicList(SubTopicList);
return searchList;
}
public List<Question> getQuestionList(String area, String topic, List<String> subtopic) {
return questionRepository.getQuestionList(area, topic, subtopic);
}
public LoginResponse questionPaperResult(PaperResult paperResult) {
//get paper result details and save in a Paper Result final table
PaperResultFinal paperResultFinal = new PaperResultFinal();
paperResultFinal.setSid(paperResult.getLoginResponse().getSystemUser().getId());
paperResultFinal.setPaperNo(paperResult.getPaperNo());
paperResultFinal.setTotalQuestionNo(paperResult.getTotalQuestionNo());
paperResultFinal.setCorrectQuestionNo(paperResult.getCorrectQuestionNo());
paperResultFinal.setAverageScore(paperResult.getAverageScore());
paperResultFinal.setGrade(paperResult.getGrade());
paperResultFinal.setStatus(paperResult.getStatus());
paperResultFinal.setArea(paperResult.getArea());
paperResultFinal.setTopic(paperResult.getTopic());
paperResultFinal.setDate(paperResult.getDate());
//get subtopic array list
List<String> subtopic = paperResult.getSubtopic();
String subTopicString = ""; //initialize
//Concat first item of the array
subTopicString = subTopicString.concat(subtopic.get(0));
//SubTopic list convert to comma seperated string
int s = 0;
for (String subTopic : paperResult.getSubtopic()) {
if (s != 0) {
subTopicString = subTopicString.concat("," + subTopic);
}
s++;
}
paperResultFinal.setSubtopic(subTopicString);
//Unique id Assign
long uniqueId = 0;
if (paperResult.getPaperNo() == 1) {
//generate uniq id for the new paper collection
uniqueId = UUID.randomUUID().hashCode();
paperResultFinal.setUniqueId(Long.toString(uniqueId));
} else {
//same previous uniqeID set to the object
paperResultFinal.setUniqueId(paperResult.getUniqueId());
}
PaperResultFinal paperResultFinalNew = paperResultFinalRepository.save(paperResultFinal);
//Set the flag for identify contine quation paper
if (paperResult.getPaperNo() == 1) {
paperResultFinalRepository.updateFlag("ACTIVE", paperResultFinalNew.getId());
} else {
//set current paper ACTIVATE
paperResultFinalRepository.updateFlag("ACTIVE", paperResultFinalNew.getId());
//set previous(LAST) paper DEACTIVATE
paperResultFinalRepository.updateFlagPrevious("DEACTIVE", paperResult.getPreviouPaperId());
}
//save result obj one by one in to paperResultStudent table
for (StudentAnswer studentAnswer : paperResult.getStudentAnswerList()) {
PaperResultStudent paperResultStudent = new PaperResultStudent();
if (paperResult.getPaperNo() == 1) {
paperResultStudent.setUniqueId(Long.toString(uniqueId));
} else {
//same previous uniqeID set to the object
paperResultStudent.setUniqueId(paperResult.getUniqueId());
}
paperResultStudent.setFinalPaperId(paperResultFinalNew.getId());
paperResultStudent.setPaperNo(paperResult.getPaperNo());
paperResultStudent.setQuestionId(studentAnswer.getQuestionId());
paperResultStudent.setWeight(studentAnswer.getWeight());
paperResultStudent.setStudentAnswer(Integer.parseInt(studentAnswer.getStudentAnswer()));
paperResultStudent.setCorrectAnswer(studentAnswer.getCorrectAnswer());
paperResultStudent.setTime(studentAnswer.getTime());
paperResultStudentRepository.save(paperResultStudent);
}
//return the current logged user
return paperResult.getLoginResponse();
}
public List<PaperResultFinal> getPapers(int id) {
return paperResultFinalRepository.getPapers(id);
}
public QuestionResult getPaper(int id) {
//Find the paper
PaperResultFinal paperResultFinal = paperResultFinalRepository.getPaper(id);
//get all question belong to the paper
List<PaperResultStudent> answerList = paperResultStudentRepository.getPaper(paperResultFinal.getId());
List<Question> questionList = new ArrayList<>();
for (PaperResultStudent paperResultStudent : answerList) {
Question question = new Question();
question = questionRepository.getQuestion(paperResultStudent.getQuestionId());
questionList.add(question);
}
//Set Question Result and Question list to new objct for pass to frontend
QuestionResult questionResult = new QuestionResult();
questionResult.setAnswerList(answerList);
questionResult.setQuestionList(questionList);
return questionResult;
}
//Flask web service integration method
public List<ProgressData> getLearningProgress(int sid) throws IOException {
List<Object[]> uniqueIdList = paperResultFinalRepository.getUniqueIds(sid);
List<ProgressData> ProgressDataList = new ArrayList<ProgressData>();
for (Object[] obj : uniqueIdList) {
//Http Request class Object
FetchDataIntegration fetchData = new FetchDataIntegration();
//Call the flask web service throuh the FetchDataIntegration class
// String jsonString = fetchData.fetch("/progress/" + Integer.parseInt(paperResultFinal.getUniqueId()));
String jsonString = fetchData.fetch("/progress/" + obj[0]);
ObjectMapper mapper = new ObjectMapper();
ProgressData progressData = mapper.readValue(jsonString, ProgressData.class); // Json String convert to the ProgressData class
//Add Paper label list using LearningProgresList size
ArrayList<String> PaperLabelList = new ArrayList<>();
for (int i = 1; i <= progressData.getLearningProgresList().size(); i++) {
String paperStr = "Paper " + Integer.toString(i);
PaperLabelList.add(paperStr);
}
progressData.setPaperLabelList(PaperLabelList); //Set the PaperLabelList to progressData Object
progressData.setSubTopic(obj[1]+" _ "+obj[0]);
ProgressDataList.add(progressData); //add the progressData Object to ProgressDataList
}
return ProgressDataList;
}
// if (uniqueId == "first") {
//
// }
// ProgressData obj = progressData;
//
// System.out.println(progressData.getLearningProgresList());
// return MinistryV3;
}
package com.cdap_2020_027.elearning.ws.service;
import com.cdap_2020_027.elearning.ws.model.SystemUser;
import com.cdap_2020_027.elearning.ws.repository.SystemUserRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
/**
*
* @author (IT17119122 ** Liyanage I.M)
*/
@Service
public class SystemUserServiceImpl {
@Autowired
SystemUserRepository systemUserRepository;
@Autowired
private JavaMailSender javaMailSender;
//Get standeard character UTF_8 UNICODE
private static final Charset UTF_8 = StandardCharsets.UTF_8;
public SystemUser findByUsernameandPassword(String username, String password) {
//Passwordconvert to MD5(Encription)
byte[] md5InBytes = this.digest(password.getBytes(UTF_8)); //password convert to MD5 byte code
String passwordMd5 = bytesToHex(md5InBytes); //byte code encripted password convert to string MD5
SystemUser systemUser = systemUserRepository.findByUsernameandPassword(username, passwordMd5);
return systemUser;
}
public void saveUser(SystemUser systemUser) {
String password = systemUser.getPassword();
//Passwordconvert to MD5(Encription)
byte[] md5InBytes = this.digest(password.getBytes(UTF_8));
//Set SEncripted password
systemUser.setPassword(bytesToHex(md5InBytes));
systemUserRepository.save(systemUser);
this.sendMail(systemUser);
}
public void sendMail(SystemUser systemUser) {
// Create a default MimeMessage object.
SimpleMailMessage message = new SimpleMailMessage();
message.setFrom("inusham45@gmail.com");
message.setTo(systemUser.getEmail());
// Set Subject: header field
message.setSubject("E-Learning platform register confirmation");
// Now set the actual message
message.setText("Congratulations! , You are successfully register to the E-Learning platform");
// Send message
javaMailSender.send(message);
System.out.println("Sent message successfully....");
}
//encripted input to MD5 byte code
private static byte[] digest(byte[] input) {
MessageDigest md;
try {
md = MessageDigest.getInstance("MD5");
} catch (NoSuchAlgorithmException e) {
throw new IllegalArgumentException(e);
}
byte[] result = md.digest(input);
return result;
}
//MD5 byte code convert to String
private static String bytesToHex(byte[] bytes) {
StringBuilder sb = new StringBuilder();
for (byte b : bytes) {
sb.append(String.format("%02x", b));
}
return sb.toString();
}
}
package com.cdap_2020_027.elearning.ws.util;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
/**
*
* @author IT17119122 Liyanage I.M
*/
@Component
public class FetchDataIntegration {
public static String flaskIntegration;
@Value("${spring.url.flask_integration}")
public void setUrl(String url) {
this.flaskIntegration = url;
}
public static String fetch(String urlString) throws MalformedURLException, IOException {
StringBuilder urlBuilder = new StringBuilder();
urlBuilder.append(flaskIntegration);
urlBuilder.append(urlString);
URL url = new URL(urlBuilder.toString());
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("GET");
conn.setRequestProperty("Accept", "application/json");
BufferedReader br = new BufferedReader(new InputStreamReader(conn.getInputStream(), "UTF-8"));
StringBuilder stringBuilder = new StringBuilder();
String output = null;
while ((output = br.readLine()) != null) {
stringBuilder.append(output);
}
conn.disconnect();
return stringBuilder.toString();
}
}
## datasource
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.datasource.url=jdbc:mysql://localhost:3306/elearning_db?useUnicode=true&zeroDateTimeBehavior=convertToNull
spring.datasource.initialize=true
spring.datasource.username=root
spring.datasource.password=123
spring.jpa.hibernate.ddl-auto=none
spring.jpa.show-sql=true
server.port = 8090
#Enable multiple application in single tomcat server
spring.jmx.enabled= false
spring.mail.host=smtp.gmail.com
spring.mail.port=587
spring.mail.username=inusham45@gmail.com
#google app password
spring.mail.password=uujckremtfnhhjjr
# Other properties
spring.mail.properties.mail.smtp.auth=true
spring.mail.properties.mail.smtp.connectiontimeout=5000
spring.mail.properties.mail.smtp.timeout=5000
spring.mail.properties.mail.smtp.writetimeout=5000
# TLS , port 587
spring.mail.properties.mail.smtp.starttls.enable=true
#Flask webService URL
spring.url.flask_integration=http://localhost:5000
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<Context path="/elearning-ws2"/>
<!DOCTYPE html>
<html>
<head>
<title>Start Page</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<h1>Hello World!</h1>
</body>
</html>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment