diff --git a/eval-plus.eml b/eval-plus.eml new file mode 100644 index 0000000..907fa42 --- /dev/null +++ b/eval-plus.eml @@ -0,0 +1,82 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/pom.xml b/pom.xml index 03e0d4a..66622c7 100644 --- a/pom.xml +++ b/pom.xml @@ -24,11 +24,11 @@ 1.8 1.8 3.1.0 + 1.7.4 - javax.mail mail @@ -58,10 +58,15 @@ ${spring.version} - + + + org.springframework + spring-context + 4.1.6.RELEASE @@ -143,6 +148,42 @@ ${spring-security.version} + + + org.springframework + spring-aop + ${spring.version} + + + + + org.aspectj + aspectjrt + 1.8.5 + + + org.aspectj + aspectjweaver + 1.8.5 + + + + org.springframework + spring-jms + 4.1.6.RELEASE + + + org.hornetq + hornetq-jms-client + 2.4.1.Final + + + jboss + jnp-client + 4.2.2.GA + + + diff --git a/src/main/java/edu/mum/evalplus/model/ClassOffered.java b/src/main/java/edu/mum/evalplus/model/ClassOffered.java index ffa930e..2aa8c5f 100644 --- a/src/main/java/edu/mum/evalplus/model/ClassOffered.java +++ b/src/main/java/edu/mum/evalplus/model/ClassOffered.java @@ -15,10 +15,10 @@ public class ClassOffered implements Serializable { private Boolean active; private String name; - @ManyToMany(mappedBy = "classOfferedSet", fetch = FetchType.EAGER) + @ManyToMany(mappedBy = "classOfferedSet") private List students; - @OneToMany(mappedBy = "classOffered", fetch = FetchType.EAGER) + @OneToMany(mappedBy = "classOffered") private List surveys; @ManyToOne diff --git a/src/main/java/edu/mum/evalplus/model/Course.java b/src/main/java/edu/mum/evalplus/model/Course.java index 0375509..4178064 100644 --- a/src/main/java/edu/mum/evalplus/model/Course.java +++ b/src/main/java/edu/mum/evalplus/model/Course.java @@ -18,7 +18,7 @@ public class Course implements Serializable { private String code; - @OneToMany(mappedBy = "faculty", fetch = FetchType.EAGER) + @OneToMany(mappedBy = "faculty") private List classOfferedList; public Course() { diff --git a/src/main/java/edu/mum/evalplus/model/Faculty.java b/src/main/java/edu/mum/evalplus/model/Faculty.java index 5f8f467..325d22c 100644 --- a/src/main/java/edu/mum/evalplus/model/Faculty.java +++ b/src/main/java/edu/mum/evalplus/model/Faculty.java @@ -17,19 +17,19 @@ public class Faculty implements Serializable { private String department; private String username; - @Embedded - private Person person; - @OneToMany(mappedBy = "faculty", fetch = FetchType.EAGER) + private String firstName; + private String lastName; + private Gender gender; + private String email; + @OneToMany(mappedBy = "faculty") private List classOfferedSet; public Faculty() { - this.person=new Person(); classOfferedSet = new ArrayList<>(); } public Faculty(String firstName, String lastName, Gender gender, String email, String username) { this.username = username; - this.person=new Person(firstName,lastName,gender,email); classOfferedSet = new ArrayList<>(); } @@ -67,13 +67,43 @@ public void setUsername(String username) { this.username = username; } - public Person getPerson() { - return person; - } - public List getClassOfferedSet() { return Collections.unmodifiableList(classOfferedSet); } + public String getFirstName() { + return firstName; + } + + public void setFirstName(String firstName) { + this.firstName = firstName; + } + + public String getLastName() { + return lastName; + } + + public void setLastName(String lastName) { + this.lastName = lastName; + } + + public Gender getGender() { + return gender; + } + public void setGender(Gender gender) { + this.gender = gender; + } + + public String getEmail() { + return email; + } + + public void setEmail(String email) { + this.email = email; + } + + public void setClassOfferedSet(List classOfferedSet) { + this.classOfferedSet = classOfferedSet; + } } diff --git a/src/main/java/edu/mum/evalplus/model/Person.java b/src/main/java/edu/mum/evalplus/model/Person.java deleted file mode 100644 index 3db4483..0000000 --- a/src/main/java/edu/mum/evalplus/model/Person.java +++ /dev/null @@ -1,56 +0,0 @@ -package edu.mum.evalplus.model; - -import javax.persistence.Embeddable; -import java.io.Serializable; - -@Embeddable -class Person implements Serializable { - - private String firstName; - private String lastName; - private Gender gender; - private String email; - - Person(String firstName, String lastName, Gender gender, String email) { - this.firstName = firstName; - this.lastName = lastName; - this.gender = gender; - this.email = email; - } - - public Person() { - } - - - public String getFirstName() { - return firstName; - } - - public void setFirstName(String firstName) { - this.firstName = firstName; - } - - public String getLastName() { - return lastName; - } - - public void setLastName(String lastName) { - this.lastName = lastName; - } - - public Gender getGender() { - return gender; - } - - public void setGender(Gender gender) { - this.gender = gender; - } - - public String getEmail() { - return email; - } - - public void setEmail(String email) { - this.email = email; - } -} diff --git a/src/main/java/edu/mum/evalplus/model/Question.java b/src/main/java/edu/mum/evalplus/model/Question.java index 885c1c0..a9fde8b 100644 --- a/src/main/java/edu/mum/evalplus/model/Question.java +++ b/src/main/java/edu/mum/evalplus/model/Question.java @@ -13,6 +13,7 @@ public class Question implements Serializable { @Enumerated private QuestionType type; private Boolean enabled; + private Boolean required; public Question() { } @@ -55,4 +56,26 @@ public void setEnabled(Boolean enabled) { this.enabled = enabled; } + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + Question question = (Question) o; + + return getId() != null ? getId().equals(question.getId()) : question.getId() == null; + } + + @Override + public int hashCode() { + return getId() != null ? getId().hashCode() : 0; + } + + public Boolean getRequired() { + return required; + } + + public void setRequired(Boolean required) { + this.required = required; + } } diff --git a/src/main/java/edu/mum/evalplus/model/Role.java b/src/main/java/edu/mum/evalplus/model/Role.java index 255fe8f..acf2d79 100644 --- a/src/main/java/edu/mum/evalplus/model/Role.java +++ b/src/main/java/edu/mum/evalplus/model/Role.java @@ -1,9 +1,6 @@ package edu.mum.evalplus.model; -import org.hibernate.validator.constraints.NotEmpty; - import javax.persistence.*; -import javax.validation.constraints.NotNull; import java.util.Set; @Entity @@ -39,4 +36,19 @@ public Set getUsers() { public void setUsers(Set users) { this.users = users; } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + Role role = (Role) o; + + return getId() != null ? getId().equals(role.getId()) : role.getId() == null; + } + + @Override + public int hashCode() { + return getId() != null ? getId().hashCode() : 0; + } } diff --git a/src/main/java/edu/mum/evalplus/model/Student.java b/src/main/java/edu/mum/evalplus/model/Student.java index 421e3e3..dee2fae 100644 --- a/src/main/java/edu/mum/evalplus/model/Student.java +++ b/src/main/java/edu/mum/evalplus/model/Student.java @@ -13,20 +13,20 @@ public class Student implements Serializable { @GeneratedValue private Integer id; private String username; - @Embedded - private Person person; - @ManyToMany(fetch = FetchType.EAGER) + private String firstName; + private String lastName; + private Gender gender; + private String email; + @ManyToMany @JoinTable(name = "student_class", joinColumns = @JoinColumn(name = "student_id"), inverseJoinColumns = @JoinColumn(name = "class_id")) private List classOfferedSet; public Student() { - this.person=new Person(); this.classOfferedSet = new ArrayList<>(); } public Student(String firstName, String lastName, Gender gender, String email,String username) { this.username = username; - this.person=new Person(firstName,lastName,gender,email); this.classOfferedSet = new ArrayList<>(); } @@ -57,13 +57,54 @@ public void setUsername(String username) { this.username = username; } - public Person getPerson() { - return person; + public List getClassOfferedSet() { + return Collections.unmodifiableList(classOfferedSet); } + public String getFirstName() { + return firstName; + } - public List getClassOfferedSet() { - return Collections.unmodifiableList(classOfferedSet); + public void setFirstName(String firstName) { + this.firstName = firstName; + } + + public String getLastName() { + return lastName; + } + + public void setLastName(String lastName) { + this.lastName = lastName; + } + + public Gender getGender() { + return gender; } + public void setGender(Gender gender) { + this.gender = gender; + } + + public String getEmail() { + return email; + } + + public void setEmail(String email) { + this.email = email; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + Student student = (Student) o; + + return getId() != null ? getId().equals(student.getId()) : student.getId() == null; + } + + @Override + public int hashCode() { + return getId() != null ? getId().hashCode() : 0; + } } diff --git a/src/main/java/edu/mum/evalplus/model/Survey.java b/src/main/java/edu/mum/evalplus/model/Survey.java index 4c12375..3ae15a6 100644 --- a/src/main/java/edu/mum/evalplus/model/Survey.java +++ b/src/main/java/edu/mum/evalplus/model/Survey.java @@ -1,12 +1,15 @@ package edu.mum.evalplus.model; +import edu.mum.evalplus.util.SurveyReport; + import javax.persistence.*; +import javax.servlet.http.HttpServletRequest; import java.io.Serializable; import java.util.*; @Entity -@Table(name="surveys") +@Table(name = "surveys") public class Survey implements Serializable { @Id @GeneratedValue @@ -16,21 +19,21 @@ public class Survey implements Serializable { @Enumerated private SurveyStatus status; - @OneToMany(fetch = FetchType.EAGER) + @OneToMany @JoinTable(name = "survey_question", joinColumns = @JoinColumn(name = "survey_id"), inverseJoinColumns = @JoinColumn(name = "question_id")) private Set questions; - @OneToMany(mappedBy = "survey", cascade = CascadeType.ALL, fetch = FetchType.EAGER) - private List answers; + @OneToMany(mappedBy = "survey", cascade = CascadeType.ALL) + private Set answers; @ManyToOne - @JoinColumn(name="class_id") + @JoinColumn(name = "class_id") private ClassOffered classOffered; public Survey() { this.questions = new HashSet<>(); - this.answers = new ArrayList<>(); + this.answers = new HashSet<>(); this.classOffered = new ClassOffered(); } @@ -38,27 +41,29 @@ public Survey(Date createdDate, SurveyStatus status, ClassOffered classOffered) this.createdDate = createdDate; this.status = status; this.questions = new HashSet<>(); - this.answers = new ArrayList<>(); + this.answers = new HashSet<>(); this.classOffered = classOffered; } - public void addQuestion(Question question){ + public void addQuestion(Question question) { questions.add(question); - } - public Question removeQuestion(Question question){ - if(questions.remove(question)){ - return question; - } - return null; - } - - public void addAnswer(SurveyAnswer answer){ - answer.setSurvey(this); + } + + public Question removeQuestion(Question question) { + if (questions.remove(question)) { + return question; + } + return null; + } + + public void addAnswer(SurveyAnswer answer) { + answer.setSurvey(this); answers.add(answer); } - public SurveyAnswer removeAnswer(SurveyAnswer answer){ - if(answers.remove(answer)){ + public SurveyAnswer removeAnswer(SurveyAnswer answer) { + + if (answers.remove(answer)) { answer.setSurvey(null); return answer; } @@ -94,8 +99,8 @@ public Set getQuestions() { } - public List getAnswers() { - return Collections.unmodifiableList(answers); + public Set getAnswers() { + return Collections.unmodifiableSet(answers); } @@ -122,4 +127,106 @@ public boolean equals(Object o) { public int hashCode() { return getId().hashCode(); } + + public Map prepareReport() { + Map reports = new HashMap<>(); + for (SurveyAnswer surveyAnswer : this.getAnswers()) { + if (surveyAnswer.getQuestion().getType().equals(QuestionType.MCQ)) { + if (reports.containsKey(surveyAnswer.getQuestion())) { + computeResponse(reports.get(surveyAnswer.getQuestion()), surveyAnswer); + } else { + SurveyReport mcqQuestionReport = new SurveyReport(); + mcqQuestionReport.setQuestionType(QuestionType.MCQ); + mcqQuestionReport.setQuestion(surveyAnswer.getQuestion().getQuestion()); + reports.put(surveyAnswer.getQuestion(), computeResponse(mcqQuestionReport, surveyAnswer)); + } + + } else { + + if (reports.containsKey(surveyAnswer.getQuestion())) { + reports.get(surveyAnswer.getQuestion()).getOpenedAnswers().add(surveyAnswer.getAnswer()); + } else { + SurveyReport report = new SurveyReport(); + report.setQuestionType(QuestionType.OPENED); + report.setQuestion(surveyAnswer.getQuestion().getQuestion()); + report.getOpenedAnswers().add(surveyAnswer.getAnswer()); + reports.put(surveyAnswer.getQuestion(), report); + } + + + } + } + return reports; + } + + private SurveyReport computeResponse(SurveyReport mcqQuestionReport, SurveyAnswer surveyAnswer) { + if (surveyAnswer.getAnswer().equalsIgnoreCase("CompletelyAgree")) + mcqQuestionReport.setCompletelyAgree(mcqQuestionReport.getCompletelyAgree() + 1); + if (surveyAnswer.getAnswer().equalsIgnoreCase("Agree")) + mcqQuestionReport.setAgree(mcqQuestionReport.getAgree() + 1); + if (surveyAnswer.getAnswer().equalsIgnoreCase("Neutral")) + mcqQuestionReport.setNeutral(mcqQuestionReport.getNeutral() + 1); + if (surveyAnswer.getAnswer().equalsIgnoreCase("Disagree")) + mcqQuestionReport.setDisagree(mcqQuestionReport.getDisagree() + 1); + if (surveyAnswer.getAnswer().equalsIgnoreCase("CompletelyDisagree")) + mcqQuestionReport.setCompletelyDisagree(mcqQuestionReport.getCompletelyDisagree() + 1); + return mcqQuestionReport; + } + + public Survey prepareAnswers(HttpServletRequest request, Student student) { + + for (Question question : this.getQuestions()) { + //Retreive param from view + String answer = request.getParameter(question.getId() + ""); + + //SurveyAnswer preparation + SurveyAnswer surveyAnswer = new SurveyAnswer(); + surveyAnswer.setAnswer(answer); + surveyAnswer.setQuestion(question); + surveyAnswer.setStudent(student); + //Adding SurveyAnswer into Survey + this.addAnswer(surveyAnswer); + + } + return this; + } + + public Survey bindParam(HttpServletRequest request) { + Survey survey = new Survey(); + try { + String[] questionsId = request.getParameterValues("questions"); + String classOfferedId = request.getParameter("classOffered"); + + if (questionsId.length == 0) + return this; + + Integer status = Integer.parseInt(request.getParameter("status")); + ClassOffered classOffered = new ClassOffered(); + + classOffered.setId(Integer.parseInt(classOfferedId)); + survey.setClassOffered(classOffered); + survey.setStatus(status == 0 ? SurveyStatus.OPENED : SurveyStatus.CLOSED); + survey.setCreatedDate(new Date()); + for (int i = 0; i < questionsId.length; i++) { + Question question = new Question(); + question.setId(Integer.parseInt(questionsId[i])); + survey.addQuestion(question); + } + + } catch (Exception ex) { + return survey; + } + return survey; + } + + public boolean availableForStudent(Student student) { + if (this.status.equals(SurveyStatus.CLOSED)) + return false; + for (Student stud : this.getClassOffered().getStudents()) { + if (stud.equals(student)) { + return true; + } + } + return false; + } } diff --git a/src/main/java/edu/mum/evalplus/model/User.java b/src/main/java/edu/mum/evalplus/model/User.java index e58df6f..3f472b3 100644 --- a/src/main/java/edu/mum/evalplus/model/User.java +++ b/src/main/java/edu/mum/evalplus/model/User.java @@ -1,11 +1,8 @@ package edu.mum.evalplus.model; -import org.hibernate.validator.constraints.Length; - import javax.persistence.*; -import javax.validation.Valid; -import javax.validation.constraints.NotNull; +import java.util.HashSet; import java.util.Set; @Entity @@ -22,6 +19,10 @@ public class User { private Set roles; + public User() { + roles = new HashSet<>(); + } + @Id @GeneratedValue(strategy = GenerationType.AUTO) public Long getId() { @@ -66,4 +67,14 @@ public Set getRoles() { public void setRoles(Set roles) { this.roles = roles; } + + @Transient + public boolean isAdmin() { + for (Role role : this.getRoles()) { + if (role.getName().equals("ROLE_ADMIN")) + return true; + } + return false; + + } } diff --git a/src/main/java/edu/mum/evalplus/repository/FacultyRepository.java b/src/main/java/edu/mum/evalplus/repository/FacultyRepository.java new file mode 100644 index 0000000..80fb411 --- /dev/null +++ b/src/main/java/edu/mum/evalplus/repository/FacultyRepository.java @@ -0,0 +1,9 @@ +package edu.mum.evalplus.repository; + +import edu.mum.evalplus.model.Faculty; +import org.springframework.data.jpa.repository.JpaRepository; + +public interface FacultyRepository extends JpaRepository { + + Faculty findFacultyByUsername(String username); +} diff --git a/src/main/java/edu/mum/evalplus/repository/QuestionRepository.java b/src/main/java/edu/mum/evalplus/repository/QuestionRepository.java index a86df87..0996f81 100644 --- a/src/main/java/edu/mum/evalplus/repository/QuestionRepository.java +++ b/src/main/java/edu/mum/evalplus/repository/QuestionRepository.java @@ -4,6 +4,9 @@ import edu.mum.evalplus.model.Question; import org.springframework.data.jpa.repository.JpaRepository; +import java.util.List; + public interface QuestionRepository extends JpaRepository { + List findQuestionsByEnabled(Boolean enabled); } diff --git a/src/main/java/edu/mum/evalplus/repository/RoleRepository.java b/src/main/java/edu/mum/evalplus/repository/RoleRepository.java index 511878c..1c4d305 100644 --- a/src/main/java/edu/mum/evalplus/repository/RoleRepository.java +++ b/src/main/java/edu/mum/evalplus/repository/RoleRepository.java @@ -4,4 +4,5 @@ import org.springframework.data.jpa.repository.JpaRepository; public interface RoleRepository extends JpaRepository{ + Role findByName(String name); } diff --git a/src/main/java/edu/mum/evalplus/repository/StudentRepository.java b/src/main/java/edu/mum/evalplus/repository/StudentRepository.java index d242e1d..c37dd88 100644 --- a/src/main/java/edu/mum/evalplus/repository/StudentRepository.java +++ b/src/main/java/edu/mum/evalplus/repository/StudentRepository.java @@ -3,13 +3,12 @@ import edu.mum.evalplus.model.Student; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Query; -import org.springframework.data.repository.query.Param; import java.util.List; public interface StudentRepository extends JpaRepository { Student findByUsername(String username); - @Query("from Student s where s.username =:username ") - List findStudentWithNoAccount(@Param("username") String username); + @Query("from Student s where s.username =NULL ") + List findStudentWithNoAccount(); } diff --git a/src/main/java/edu/mum/evalplus/service/IClassOfferedServiceImpl.java b/src/main/java/edu/mum/evalplus/service/IClassOfferedServiceImpl.java index ca5ce09..7be559d 100644 --- a/src/main/java/edu/mum/evalplus/service/IClassOfferedServiceImpl.java +++ b/src/main/java/edu/mum/evalplus/service/IClassOfferedServiceImpl.java @@ -4,19 +4,18 @@ import edu.mum.evalplus.repository.ClassOfferedRepository; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Propagation; import org.springframework.transaction.annotation.Transactional; import java.util.List; @Service +@Transactional public class IClassOfferedServiceImpl implements IClassOfferedService{ @Autowired private ClassOfferedRepository ClassOfferedRepository; @Override - @Transactional(propagation=Propagation.REQUIRED) public void save(ClassOffered classOffered) { ClassOfferedRepository.save(classOffered); } diff --git a/src/main/java/edu/mum/evalplus/service/IEmailServiceImpl.java b/src/main/java/edu/mum/evalplus/service/IEmailServiceImpl.java index 9a07034..8d5a213 100644 --- a/src/main/java/edu/mum/evalplus/service/IEmailServiceImpl.java +++ b/src/main/java/edu/mum/evalplus/service/IEmailServiceImpl.java @@ -3,8 +3,10 @@ import edu.mum.evalplus.util.MailMail; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; @Service +@Transactional public class IEmailServiceImpl implements IEmailService { @Autowired private MailMail mailSender; diff --git a/src/main/java/edu/mum/evalplus/service/IFacultyService.java b/src/main/java/edu/mum/evalplus/service/IFacultyService.java new file mode 100644 index 0000000..425f6f6 --- /dev/null +++ b/src/main/java/edu/mum/evalplus/service/IFacultyService.java @@ -0,0 +1,17 @@ +package edu.mum.evalplus.service; + +import edu.mum.evalplus.model.Faculty; + +import java.util.List; + +public interface IFacultyService { + public void save(Faculty question); + + List findAll(); + + Faculty find(Integer id); + + void delete(Integer id); + + Faculty findFacultyByUsername(String username); +} diff --git a/src/main/java/edu/mum/evalplus/service/IFacultyServiceImpl.java b/src/main/java/edu/mum/evalplus/service/IFacultyServiceImpl.java new file mode 100644 index 0000000..a63e5f2 --- /dev/null +++ b/src/main/java/edu/mum/evalplus/service/IFacultyServiceImpl.java @@ -0,0 +1,44 @@ +package edu.mum.evalplus.service; + + +import edu.mum.evalplus.model.Faculty; +import edu.mum.evalplus.repository.FacultyRepository; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.util.List; + +@Service +@Transactional +public class IFacultyServiceImpl implements IFacultyService { + + @Autowired + private FacultyRepository questionRepository; + + @Override + public void save(Faculty survey) { + questionRepository.save(survey); + } + + @Override + public List findAll() { + return questionRepository.findAll(); + } + + @Override + public Faculty find(Integer id) { + return questionRepository.findOne(id); + } + + @Override + public void delete(Integer id) { + questionRepository.delete(id); + } + + @Override + public Faculty findFacultyByUsername(String username) { + return questionRepository.findFacultyByUsername(username); + } + +} diff --git a/src/main/java/edu/mum/evalplus/service/IQuestionService.java b/src/main/java/edu/mum/evalplus/service/IQuestionService.java index ffe6894..508706c 100644 --- a/src/main/java/edu/mum/evalplus/service/IQuestionService.java +++ b/src/main/java/edu/mum/evalplus/service/IQuestionService.java @@ -9,4 +9,6 @@ public interface IQuestionService { List findAll(); Question find(Integer id); void delete(Integer id); + + List findQuestionByEnabled(Boolean enabled); } diff --git a/src/main/java/edu/mum/evalplus/service/IQuestionServiceImpl.java b/src/main/java/edu/mum/evalplus/service/IQuestionServiceImpl.java index b0034f3..df6dc12 100644 --- a/src/main/java/edu/mum/evalplus/service/IQuestionServiceImpl.java +++ b/src/main/java/edu/mum/evalplus/service/IQuestionServiceImpl.java @@ -4,19 +4,18 @@ import edu.mum.evalplus.repository.QuestionRepository; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Propagation; import org.springframework.transaction.annotation.Transactional; import java.util.List; @Service +@Transactional public class IQuestionServiceImpl implements IQuestionService{ @Autowired private QuestionRepository questionRepository; @Override - @Transactional(propagation=Propagation.REQUIRED) public void save(Question survey) { questionRepository.save(survey); } @@ -36,4 +35,9 @@ public void delete(Integer id) { questionRepository.delete(id); } + @Override + public List findQuestionByEnabled(Boolean enabled) { + return questionRepository.findQuestionsByEnabled(enabled); + } + } diff --git a/src/main/java/edu/mum/evalplus/service/IRoleService.java b/src/main/java/edu/mum/evalplus/service/IRoleService.java new file mode 100644 index 0000000..2f9018c --- /dev/null +++ b/src/main/java/edu/mum/evalplus/service/IRoleService.java @@ -0,0 +1,7 @@ +package edu.mum.evalplus.service; + +import edu.mum.evalplus.model.Role; + +public interface IRoleService { + Role findByName(String name); +} diff --git a/src/main/java/edu/mum/evalplus/service/IRoleServiceImpl.java b/src/main/java/edu/mum/evalplus/service/IRoleServiceImpl.java new file mode 100644 index 0000000..2ba76ae --- /dev/null +++ b/src/main/java/edu/mum/evalplus/service/IRoleServiceImpl.java @@ -0,0 +1,19 @@ +package edu.mum.evalplus.service; + +import edu.mum.evalplus.model.Role; +import edu.mum.evalplus.repository.RoleRepository; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +@Service +@Transactional +public class IRoleServiceImpl implements IRoleService { + @Autowired + private RoleRepository roleRepository; + + @Override + public Role findByName(String name) { + return roleRepository.findByName(name); + } +} diff --git a/src/main/java/edu/mum/evalplus/service/IStudentService.java b/src/main/java/edu/mum/evalplus/service/IStudentService.java index 0e11a88..692d3a4 100644 --- a/src/main/java/edu/mum/evalplus/service/IStudentService.java +++ b/src/main/java/edu/mum/evalplus/service/IStudentService.java @@ -15,5 +15,7 @@ public interface IStudentService { Student findByUsername(String username); - List findAllByUsername(String username); + List findStudentWithNoAccount(); + + void generateStudentAccount(Integer studentId); } diff --git a/src/main/java/edu/mum/evalplus/service/IStudentServiceImpl.java b/src/main/java/edu/mum/evalplus/service/IStudentServiceImpl.java index f5adf7c..bda72f2 100644 --- a/src/main/java/edu/mum/evalplus/service/IStudentServiceImpl.java +++ b/src/main/java/edu/mum/evalplus/service/IStudentServiceImpl.java @@ -1,19 +1,35 @@ package edu.mum.evalplus.service; +import edu.mum.evalplus.model.Role; import edu.mum.evalplus.model.Student; +import edu.mum.evalplus.model.User; import edu.mum.evalplus.repository.StudentRepository; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; import java.util.ArrayList; +import java.util.HashSet; import java.util.List; +import java.util.Set; @Service +@Transactional public class IStudentServiceImpl implements IStudentService { @Autowired private StudentRepository studentRepository; + @Autowired + private UserService userService; + @Autowired + private IRoleService roleService; + @Autowired + private BCryptPasswordEncoder encoder; + @Autowired + private IEmailService emailService; + private final String DEFAULT_PASSWORD = "$2a$11$X2.qF1gFgCbpTa1eAo4gO.kAKaVRvBwl/26Ckk2Ph0S2S6tdxKs/O"; @Override @@ -42,9 +58,32 @@ public Student findByUsername(String username) { } @Override - public List findAllByUsername(String username) { + public List findStudentWithNoAccount() { List list = new ArrayList<>(); - list.addAll(studentRepository.findStudentWithNoAccount(username)); + list.addAll(studentRepository.findStudentWithNoAccount()); return list; } + + @Override + public void generateStudentAccount(Integer studentId) { + Student student = studentRepository.findOne(studentId); + User user = new User(); + Role role = roleService.findByName("ROLE_STUDENT"); + Set roles = new HashSet<>(); + roles.add(role); + user.setRoles(roles); + user.setUsername(student.getFirstName().toLowerCase()); + user.setPassword(DEFAULT_PASSWORD); + student.setUsername(student.getFirstName().toLowerCase()); + for (Role rol : user.getRoles()) { + System.out.println("LOG:StudentService=====================roleName=" + rol.getName()); + if (!role.getName().equals("ROLE_STUDENT")) { + user.getRoles().remove(rol); + } + } + userService.save(user); + studentRepository.save(student); + emailService.sendMail(student.getEmail(), "Survey System credentials", "Welcome to Eval Plus!! " + + "We created an account for you: username: " + user.getUsername().toLowerCase() + " and password:wisleo "); + } } diff --git a/src/main/java/edu/mum/evalplus/service/ISurveyService.java b/src/main/java/edu/mum/evalplus/service/ISurveyService.java index af4624b..05c3a16 100644 --- a/src/main/java/edu/mum/evalplus/service/ISurveyService.java +++ b/src/main/java/edu/mum/evalplus/service/ISurveyService.java @@ -1,6 +1,7 @@ package edu.mum.evalplus.service; import edu.mum.evalplus.model.Survey; +import edu.mum.evalplus.model.User; import java.util.List; @@ -12,4 +13,5 @@ public interface ISurveyService { List findStudentSurvey(String username); + List findFacultySurvey(User user); } diff --git a/src/main/java/edu/mum/evalplus/service/ISurveyServiceImpl.java b/src/main/java/edu/mum/evalplus/service/ISurveyServiceImpl.java index 4477322..a1975b4 100644 --- a/src/main/java/edu/mum/evalplus/service/ISurveyServiceImpl.java +++ b/src/main/java/edu/mum/evalplus/service/ISurveyServiceImpl.java @@ -1,12 +1,10 @@ package edu.mum.evalplus.service; -import edu.mum.evalplus.model.ClassOffered; -import edu.mum.evalplus.model.Student; -import edu.mum.evalplus.model.Survey; -import edu.mum.evalplus.model.SurveyStatus; +import edu.mum.evalplus.model.*; import edu.mum.evalplus.repository.SurveyRepository; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; import java.util.ArrayList; import java.util.List; @@ -14,12 +12,15 @@ import java.util.stream.Collectors; @Service +@Transactional public class ISurveyServiceImpl implements ISurveyService{ @Autowired private SurveyRepository surveyRepository; @Autowired private IStudentService studentService; + @Autowired + private IFacultyService facultyService; @Override public void save(Survey survey) { surveyRepository.save(survey); @@ -51,7 +52,34 @@ public List findStudentSurvey(String username) { List sveys = new ArrayList<>(); for (ClassOffered lect : lects) { for (Survey surv : lect.getSurveys()) { - if (surv.getStatus().equals(SurveyStatus.OPENED)) + if (surv.getStatus().equals(SurveyStatus.OPENED) && !alreadyTook(student, surv)) + sveys.add(surv); + } + } + return sveys; + }; + return function.apply(lectures); + } + + private boolean alreadyTook(Student student, Survey surv) { + for (SurveyAnswer answer : surv.getAnswers()) { + if (answer.getStudent().getId() == student.getId()) + return true; + } + return false; + } + + @Override + public List findFacultySurvey(User user) { + Faculty faculty = facultyService.findFacultyByUsername(user.getUsername()); + List surveys = new ArrayList<>(); + if (faculty == null) + return surveys; + List lectures = faculty.getClassOfferedSet().stream().filter(lecture -> lecture.getActive()).collect(Collectors.toList()); + Function, List> function = (lects) -> { + List sveys = new ArrayList<>(); + for (ClassOffered lect : lects) { + for (Survey surv : lect.getSurveys()) { sveys.add(surv); } } diff --git a/src/main/java/edu/mum/evalplus/service/SecurityServiceImpl.java b/src/main/java/edu/mum/evalplus/service/SecurityServiceImpl.java index d3f26e0..0bde98f 100644 --- a/src/main/java/edu/mum/evalplus/service/SecurityServiceImpl.java +++ b/src/main/java/edu/mum/evalplus/service/SecurityServiceImpl.java @@ -9,8 +9,10 @@ import org.springframework.security.core.userdetails.UserDetails; import org.springframework.security.core.userdetails.UserDetailsService; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; @Service +@Transactional public class SecurityServiceImpl implements SecurityService{ @Autowired private AuthenticationManager authenticationManager; diff --git a/src/main/java/edu/mum/evalplus/service/UserDetailsServiceImpl.java b/src/main/java/edu/mum/evalplus/service/UserDetailsServiceImpl.java index dc3b1a4..b927831 100644 --- a/src/main/java/edu/mum/evalplus/service/UserDetailsServiceImpl.java +++ b/src/main/java/edu/mum/evalplus/service/UserDetailsServiceImpl.java @@ -15,6 +15,7 @@ import java.util.HashSet; import java.util.Set; +@Transactional public class UserDetailsServiceImpl implements UserDetailsService{ @Autowired private UserRepository userRepository; diff --git a/src/main/java/edu/mum/evalplus/service/UserService.java b/src/main/java/edu/mum/evalplus/service/UserService.java index 9e62232..f7d07bd 100644 --- a/src/main/java/edu/mum/evalplus/service/UserService.java +++ b/src/main/java/edu/mum/evalplus/service/UserService.java @@ -3,8 +3,14 @@ import edu.mum.evalplus.model.User; +import java.util.List; + public interface UserService { void save(User user); User findByUsername(String username); + + User findById(Long id); + + List findAll(); } diff --git a/src/main/java/edu/mum/evalplus/service/UserServiceImpl.java b/src/main/java/edu/mum/evalplus/service/UserServiceImpl.java index 62a6c99..cf8a15a 100644 --- a/src/main/java/edu/mum/evalplus/service/UserServiceImpl.java +++ b/src/main/java/edu/mum/evalplus/service/UserServiceImpl.java @@ -1,32 +1,50 @@ package edu.mum.evalplus.service; +import edu.mum.evalplus.model.Role; import edu.mum.evalplus.model.User; import edu.mum.evalplus.repository.RoleRepository; import edu.mum.evalplus.repository.UserRepository; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; -import java.util.HashSet; +import java.util.List; @Service +@Transactional public class UserServiceImpl implements UserService { @Autowired - private UserRepository userRepository; + private UserRepository userService; @Autowired - private RoleRepository roleRepository; + private RoleRepository roleService; @Autowired private BCryptPasswordEncoder bCryptPasswordEncoder; @Override public void save(User user) { - user.setPassword(bCryptPasswordEncoder.encode(user.getPassword())); - user.setRoles(new HashSet<>(roleRepository.findAll())); - userRepository.save(user); + if (user.getId() == null) { + user.setPassword(bCryptPasswordEncoder.encode(user.getPassword())); + Role role = roleService.findByName("ROLE_ADMIN"); + user.getRoles().add(role); + } + userService.save(user); } @Override public User findByUsername(String username) { - return userRepository.findByUsername(username); + return userService.findByUsername(username); } + + @Override + public List findAll() { + return userService.findAll(); + } + + @Override + public User findById(Long id) { + return userService.findOne(id); + } + + } diff --git a/src/main/java/edu/mum/evalplus/util/MyJMSMessageListener.java b/src/main/java/edu/mum/evalplus/util/MyJMSMessageListener.java new file mode 100644 index 0000000..22366bc --- /dev/null +++ b/src/main/java/edu/mum/evalplus/util/MyJMSMessageListener.java @@ -0,0 +1,25 @@ +package edu.mum.evalplus.util; + + +import cs544.exercise9_2.sender.ClassOffered; + +import javax.jms.JMSException; +import javax.jms.Message; +import javax.jms.MessageListener; +import javax.jms.ObjectMessage; + +public class MyJMSMessageListener implements MessageListener { + @Override + public void onMessage(Message message) { + ObjectMessage objMessage = (ObjectMessage) message; + try { + if (objMessage instanceof ClassOffered) { + System.out.println("Yes==========================="); + } + ClassOffered classOffered = (ClassOffered) objMessage.getObject(); + System.out.println("Message is received:" + classOffered.getName()); + } catch (JMSException e) { + e.printStackTrace(); + } + } +} diff --git a/src/main/java/edu/mum/evalplus/util/SecurityAspect.java b/src/main/java/edu/mum/evalplus/util/SecurityAspect.java new file mode 100644 index 0000000..35c5a42 --- /dev/null +++ b/src/main/java/edu/mum/evalplus/util/SecurityAspect.java @@ -0,0 +1,15 @@ +package edu.mum.evalplus.util; + + +import org.aspectj.lang.annotation.Aspect; +import org.aspectj.lang.annotation.Before; + +@Aspect +public class SecurityAspect { + + @Before("execution(* edu.mum.evalplus.web.*.login(..))") + public void checkUser() { + System.out.println("User=========================================================="); + } + +} diff --git a/src/main/java/edu/mum/evalplus/util/SurveyReport.java b/src/main/java/edu/mum/evalplus/util/SurveyReport.java new file mode 100644 index 0000000..4ea1887 --- /dev/null +++ b/src/main/java/edu/mum/evalplus/util/SurveyReport.java @@ -0,0 +1,91 @@ +package edu.mum.evalplus.util; + +import edu.mum.evalplus.model.QuestionType; + +import java.util.ArrayList; +import java.util.List; + +public class SurveyReport { + + private String question; + private Integer completelyAgree; + private Integer agree; + private Integer neutral; + private Integer disagree; + private Integer completelyDisagree; + private List openedAnswers; + private QuestionType questionType; + + public SurveyReport() { + this.completelyAgree = 0; + this.agree = 0; + this.neutral = 0; + this.disagree = 0; + this.completelyDisagree = 0; + openedAnswers = new ArrayList<>(); + } + + public String getQuestion() { + return question; + } + + public void setQuestion(String question) { + this.question = question; + } + + public Integer getCompletelyAgree() { + return completelyAgree; + } + + public void setCompletelyAgree(Integer completelyAgree) { + this.completelyAgree = completelyAgree; + } + + public Integer getAgree() { + return agree; + } + + public void setAgree(Integer agree) { + this.agree = agree; + } + + public Integer getNeutral() { + return neutral; + } + + public void setNeutral(Integer neutral) { + this.neutral = neutral; + } + + public Integer getDisagree() { + return disagree; + } + + public void setDisagree(Integer disagree) { + this.disagree = disagree; + } + + public Integer getCompletelyDisagree() { + return completelyDisagree; + } + + public void setCompletelyDisagree(Integer completelyDisagree) { + this.completelyDisagree = completelyDisagree; + } + + public List getOpenedAnswers() { + return openedAnswers; + } + + public void setOpenedAnswers(List openedAnswers) { + this.openedAnswers = openedAnswers; + } + + public QuestionType getQuestionType() { + return questionType; + } + + public void setQuestionType(QuestionType questionType) { + this.questionType = questionType; + } +} diff --git a/src/main/java/edu/mum/evalplus/web/DefaultController.java b/src/main/java/edu/mum/evalplus/web/DefaultController.java index 679902e..d9718da 100644 --- a/src/main/java/edu/mum/evalplus/web/DefaultController.java +++ b/src/main/java/edu/mum/evalplus/web/DefaultController.java @@ -5,6 +5,8 @@ import org.springframework.ui.Model; import org.springframework.web.bind.annotation.RequestMapping; +import javax.servlet.http.HttpSession; + @Controller public class DefaultController { @@ -13,4 +15,16 @@ public class DefaultController { public String welcome(Model model) { return "404"; } + + @RequestMapping("/403") + public String welcome() { + return "403"; + } + + @RequestMapping("/logout") + public String welcome(HttpSession session) { + session.invalidate(); + return "redirect:/login"; + } + } diff --git a/src/main/java/edu/mum/evalplus/web/QuestionController.java b/src/main/java/edu/mum/evalplus/web/QuestionController.java new file mode 100644 index 0000000..8483bda --- /dev/null +++ b/src/main/java/edu/mum/evalplus/web/QuestionController.java @@ -0,0 +1,60 @@ +package edu.mum.evalplus.web; + +import edu.mum.evalplus.model.Question; +import edu.mum.evalplus.service.IQuestionService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Controller; +import org.springframework.ui.Model; +import org.springframework.web.bind.annotation.ModelAttribute; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; + +import javax.validation.Valid; + + +@Controller +public class QuestionController { + + @Autowired + private IQuestionService questionService; + + + @RequestMapping(value = "/newQuestion", method = RequestMethod.GET) + public String questionForm(Model model) { + model.addAttribute("question", new Question()); + return "questionForm"; + } + + @RequestMapping(value = "/questionList", method = RequestMethod.GET) + public String questionList(Model model) { + model.addAttribute("questions", questionService.findAll()); + return "questionList"; + } + + @RequestMapping(value = "/newQuestion", method = RequestMethod.POST) + public String createQuestion(@ModelAttribute("question") @Valid Question question) { + questionService.save(question); + return "redirect:/questionList"; + } + + @RequestMapping(value = "/removeQuestion/{id}", method = RequestMethod.GET) + public String removeQuestion(@PathVariable("id") Integer id) { + Question question = questionService.find(id); + question.setEnabled(false); + questionService.save(question); + return "redirect:/questionList"; + } + + @RequestMapping(value = "/updateQuestion/{id}", method = RequestMethod.GET) + public String updateQuestion(@PathVariable("id") Integer id, Model model) { + model.addAttribute("question", questionService.find(id)); + return "updateQuestion"; + } + + @RequestMapping(value = "/updateQuestion", method = RequestMethod.POST) + public String updated(@ModelAttribute("question") @Valid Question question) { + questionService.save(question); + return "redirect:/questionList"; + } +} \ No newline at end of file diff --git a/src/main/java/edu/mum/evalplus/web/SurveyController.java b/src/main/java/edu/mum/evalplus/web/SurveyController.java index cf7fdf0..a460a4d 100644 --- a/src/main/java/edu/mum/evalplus/web/SurveyController.java +++ b/src/main/java/edu/mum/evalplus/web/SurveyController.java @@ -3,6 +3,7 @@ import edu.mum.evalplus.model.*; import edu.mum.evalplus.service.*; +import edu.mum.evalplus.util.SurveyReport; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; @@ -14,6 +15,7 @@ import javax.servlet.http.HttpServletRequest; import java.security.Principal; +import java.util.Map; @Controller public class SurveyController { @@ -27,82 +29,95 @@ public class SurveyController { private IStudentService studentService; @Autowired private IEmailService emailService; + @Autowired + private UserService userService; @RequestMapping(value = "/newSurvey", method = RequestMethod.GET) - public ModelAndView surveyForm() { + public ModelAndView surveyForm(Principal principal, Model model) { ModelAndView modelAndView = new ModelAndView("surveyForm"); - modelAndView.addObject("questionList", questionService.findAll()); + modelAndView.addObject("questionList", questionService.findQuestionByEnabled(true)); modelAndView.addObject("classList", classOfferedService.findAll()); return modelAndView; } @RequestMapping(value = "/newSurvey", method = RequestMethod.POST) - public String createSurvey(@RequestParam("status") SurveyStatus status, @RequestParam("classOffered") Integer id, - @RequestParam("questions") Integer[] questionsId) { - ClassOffered classOffered = new ClassOffered(); - Survey survey = new Survey(); - classOffered.setId(id); - survey.setClassOffered(classOffered); - for (int i = 0; i < questionsId.length; i++) { - Question question = new Question(); - question.setId(questionsId[i]); - survey.addQuestion(question); + public String createSurvey(HttpServletRequest request, Principal principal, Model model) { + Survey survey = new Survey().bindParam(request); + if (survey.getQuestions().size() > 0) + surveyService.save(survey); + else { + model.addAttribute("error", "Survey should have at least one question"); + return "redirect:/newSurvey"; } - surveyService.save(survey); - emailService.sendMail("ebayarkhuu@mum.edu", "Survey", "A new survey is created"); + return "redirect:/manageSurvey"; } @RequestMapping(value = "/manageSurvey", method = RequestMethod.GET) - public ModelAndView manage(Model model) { - ModelAndView mav = new ModelAndView("manageSurvey"); - mav.addObject("surveys", surveyService.findAll()); - return mav; + public String manage(Model model, Principal principal) { + if (principal == null) + return "redirect:/login"; + User user = userService.findByUsername(principal.getName()); + if (user.isAdmin()) + model.addAttribute("surveys", surveyService.findAll()); + else + model.addAttribute("surveys", surveyService.findFacultySurvey(user)); + return "manageSurvey"; } @RequestMapping(value = "/takeSurvey", method = RequestMethod.GET) public String takeSurvey(Model model, Principal principal) { + if (principal == null) + return "redirect:/login"; model.addAttribute("surveys", surveyService.findStudentSurvey(principal.getName())); return "studentSurvey"; } @RequestMapping(value = "/takeSurvey/{id}", method = RequestMethod.GET) - public String takeSurvey(@PathVariable("id") int id, Model model) { - for (Question quest : surveyService.find(id).getQuestions()) { - System.out.println("Question" + quest.getQuestion()); - } - - model.addAttribute("survey", surveyService.find(id)); + public String takeSurvey(@PathVariable("id") int id, Model model, Principal principal) { + if (principal == null) + return "redirect:/login"; + Survey survey = surveyService.find(id); + Student student = studentService.findByUsername(principal.getName()); + if (survey == null || student == null) + return "redirect:/welcome"; + if (!survey.availableForStudent(student)) + return "redirect:/welcome"; + model.addAttribute("survey", survey); return "takeSurvey"; } @RequestMapping(value = "/takeSurvey", method = RequestMethod.POST) public String saveSurvey(@RequestParam("surveyId") Integer surveyId, HttpServletRequest request, Model model, Principal principal) { - Survey survey = surveyService.find(surveyId); - for (int i = 0; i < survey.getQuestions().size(); i++) { - //Retreive param from view - String param = "quest" + (i + 1); - String value = request.getParameter(param); - String values[] = value.split(","); - Integer questionId = Integer.parseInt(values[0]); - String answer = values[1]; - //Question preparation - Question question = new Question(); - question.setId(questionId); - //SurveyAnswer preparation - SurveyAnswer surveyAnswer = new SurveyAnswer(); - surveyAnswer.setAnswer(answer); - surveyAnswer.setQuestion(question); - surveyAnswer.setStudent(studentService.findByUsername(principal.getName())); - //Adding SurveyAnswer into Survey - survey.addAnswer(surveyAnswer); + Survey survey = surveyService.find(surveyId).prepareAnswers(request, studentService.findByUsername(principal.getName())); + surveyService.save(survey); + return "home"; + } + + @RequestMapping(value = "/surveyDetails/{id}", method = RequestMethod.GET) + public String surveyDetails(@PathVariable("id") int id, Model model, Principal principal) { + Survey survey = surveyService.find(id); + if (survey != null) { + Map reports = survey.prepareReport(); + model.addAttribute("reports", reports); } + return "surveyDetails"; + } + + @RequestMapping(value = "/updateStatus/{id}", method = RequestMethod.GET) + public String updateStatus(@PathVariable("id") int id, Model model, Principal principal) { + Survey survey = surveyService.find(id); + if (survey.getStatus().equals(SurveyStatus.OPENED)) + survey.setStatus(SurveyStatus.CLOSED); + else + survey.setStatus(SurveyStatus.OPENED); surveyService.save(survey); - return "home"; + return "redirect:/manageSurvey"; } + } diff --git a/src/main/java/edu/mum/evalplus/web/UserAccountController.java b/src/main/java/edu/mum/evalplus/web/UserAccountController.java index f0e5e4d..ee7f4c4 100644 --- a/src/main/java/edu/mum/evalplus/web/UserAccountController.java +++ b/src/main/java/edu/mum/evalplus/web/UserAccountController.java @@ -11,9 +11,13 @@ import org.springframework.ui.Model; import org.springframework.validation.BindingResult; import org.springframework.web.bind.annotation.ModelAttribute; +import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; +import java.security.Principal; +import java.util.List; + @Controller public class UserAccountController { @Autowired @@ -29,31 +33,46 @@ public class UserAccountController { private IStudentService studentService; @RequestMapping(value = "/generateAccount", method = RequestMethod.GET) - public String addAccount(Model model) { - model.addAttribute("students",studentService.findAllByUsername("eb") ); + public String addAccount(Model model, Principal principal) { + model.addAttribute("students", studentService.findStudentWithNoAccount()); return "generateStudentAccount"; } - @RequestMapping(value = "/generateStundentAccount", method = RequestMethod.POST) - public String addAccount(@ModelAttribute("userForm") User userForm, BindingResult bindingResult, Model model) { - - userService.save(userForm); - - return "redirect:/welcome"; + @RequestMapping(value = "/generateStudentAccount/{id}", method = RequestMethod.POST) + public String addAccount(@PathVariable("id") Integer studentId, Principal principal) { + studentService.generateStudentAccount(studentId); + return "redirect:/generateAccount"; } - @RequestMapping(value = "/manageAccount", method = RequestMethod.GET) - public String manageAccount(Model model) { + /*@RequestMapping(value = "/manageAccount", method = RequestMethod.GET) + public String manageAccount(Model model, Principal principal) { model.addAttribute("userForm", new User()); return "manageAccount"; } @RequestMapping(value = "/manageAccount", method = RequestMethod.POST) - public String manageAccount(@ModelAttribute("userForm") User userForm, BindingResult bindingResult, Model model) { + public String manageAccount(@ModelAttribute("userForm") User userForm, BindingResult bindingResult, Model model, Principal principal) { + return "redirect:/welcome"; + }*/ + @RequestMapping(value = "/manageAccount", method = RequestMethod.GET) + public String manageAccount(Model model) { + List userList = userService.findAll(); + model.addAttribute("users", userList); + return "manageAccount"; + } + @RequestMapping(value = "/manageAccount/{userId}", method = RequestMethod.GET) + public String manageAccountEdit(@PathVariable Long userId, Model model) { + User user = userService.findById(userId); + model.addAttribute("userForm", user); + return "manageAccountEdit"; + } + @RequestMapping(value = "/manageAccount", method = RequestMethod.POST) + public String manageAccountEdit(@ModelAttribute("userForm") User userForm, BindingResult bindingResult, Model model) { + userService.save(userForm); return "redirect:/welcome"; } diff --git a/src/main/java/edu/mum/evalplus/web/UserController.java b/src/main/java/edu/mum/evalplus/web/UserController.java index ff0a685..896bb4c 100644 --- a/src/main/java/edu/mum/evalplus/web/UserController.java +++ b/src/main/java/edu/mum/evalplus/web/UserController.java @@ -13,6 +13,8 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; +import java.security.Principal; + @Controller public class UserController { @Autowired @@ -25,14 +27,14 @@ public class UserController { private UserValidator userValidator; @RequestMapping(value = "/registration", method = RequestMethod.GET) - public String registration(Model model) { + public String registration(Model model, Principal principal) { model.addAttribute("userForm", new User()); return "registration"; } @RequestMapping(value = "/registration", method = RequestMethod.POST) - public String registration(@ModelAttribute("userForm") User userForm, BindingResult bindingResult, Model model) { + public String registration(@ModelAttribute("userForm") User userForm, BindingResult bindingResult, Model model, Principal principal) { // userValidator.validate(userForm, bindingResult); /* if (bindingResult.hasErrors()) { @@ -47,7 +49,7 @@ public String registration(@ModelAttribute("userForm") User userForm, BindingRes } @RequestMapping(value = "/login", method = RequestMethod.GET) - public String login(Model model, String error, String logout) { + public String login(Model model, String error, String logout, Principal principal) { if (error != null) model.addAttribute("error", "Your username and password is invalid."); @@ -58,7 +60,7 @@ public String login(Model model, String error, String logout) { } @RequestMapping(value = {"/", "/welcome"}, method = RequestMethod.GET) - public String welcome(Model model) { + public String welcome(Model model, Principal principal) { return "home"; } } diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 1221e76..bceb165 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -1,4 +1,4 @@ jdbc.driverClassName=com.mysql.jdbc.Driver jdbc.url=jdbc:mysql://localhost:3306/cs544?useUnicode=true&characterEncoding=UTF-8&zeroDateTimeBehavior=convertToNull jdbc.username=root -jdbc.password= +jdbc.password=wisleo diff --git a/src/main/resources/messages.properties b/src/main/resources/messages.properties new file mode 100644 index 0000000..d2ab880 --- /dev/null +++ b/src/main/resources/messages.properties @@ -0,0 +1,18 @@ +# 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. +account.generate=Generate +account.manage=Manage +account.registration=Create admin +account.settings=Settings +app.home=Dashboard +general.account=Account +menu.question=Questions +menu.question.manage=Manage +menu.question.new=New +menu.survey=Survey +menu.survey.manage=Manage +menu.survey.new=New +menu.survey.take=Take +user.logout=Logout +user.profile=User Profile diff --git a/src/main/resources/messages_fr.properties b/src/main/resources/messages_fr.properties new file mode 100644 index 0000000..a5287f2 --- /dev/null +++ b/src/main/resources/messages_fr.properties @@ -0,0 +1,18 @@ +# 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. +account.generate=Generate +account.manage=Manage +account.registration=Create admin +account.settings=Settings +app.home=Dashboard +general.account=Account +menu.question=Questions +menu.question.manage=Manage +menu.question.new=New +menu.survey=Survey +menu.survey.manage=Manage +menu.survey.new=New +menu.survey.take=Take +user.logout=Logout +user.profile=Profile Utilisateur diff --git a/src/main/webapp/WEB-INF/appconfig-data.xml b/src/main/webapp/WEB-INF/appconfig-data.xml index 2e2eda1..872c745 100644 --- a/src/main/webapp/WEB-INF/appconfig-data.xml +++ b/src/main/webapp/WEB-INF/appconfig-data.xml @@ -2,15 +2,17 @@ + http://www.springframework.org/schema/tx/spring-tx.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd"> + + @@ -69,6 +71,7 @@ org.hibernate.dialect.MySQL5Dialect true update + true @@ -80,13 +83,54 @@ - - + - + - \ No newline at end of file + + + + + + + + + + + org.jnp.interfaces.NamingContextFactory + + + localhost + + + org.jnp.interfaces:org.jboss.naming + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/main/webapp/WEB-INF/appconfig-mvc.xml b/src/main/webapp/WEB-INF/appconfig-mvc.xml index dd268ad..d833044 100644 --- a/src/main/webapp/WEB-INF/appconfig-mvc.xml +++ b/src/main/webapp/WEB-INF/appconfig-mvc.xml @@ -5,17 +5,8 @@ http://www.springframework.org/schema/beans/spring-beans.xsd"> - - - - - classpath:validation - - - - /WEB-INF/views/ @@ -24,4 +15,29 @@ .jsp + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/main/webapp/WEB-INF/appconfig-security.xml b/src/main/webapp/WEB-INF/appconfig-security.xml index 646db52..60913d9 100644 --- a/src/main/webapp/WEB-INF/appconfig-security.xml +++ b/src/main/webapp/WEB-INF/appconfig-security.xml @@ -8,12 +8,30 @@ http://www.springframework.org/schema/security/spring-security.xsd"> - - - + + + + + + + + + + + + + + + + + + - - + + diff --git a/src/main/webapp/WEB-INF/views/403.jsp b/src/main/webapp/WEB-INF/views/403.jsp new file mode 100644 index 0000000..ee0b699 --- /dev/null +++ b/src/main/webapp/WEB-INF/views/403.jsp @@ -0,0 +1,50 @@ + + + + + + + + + + +
+
+
+
+

+ Oops!

+

+ 403

+
+ Access is denied!!!! +
+ +
+
+
+
+ + \ No newline at end of file diff --git a/src/main/webapp/WEB-INF/views/404.jsp b/src/main/webapp/WEB-INF/views/404.jsp new file mode 100644 index 0000000..5d913d3 --- /dev/null +++ b/src/main/webapp/WEB-INF/views/404.jsp @@ -0,0 +1,50 @@ + + + + + + + + + + +
+
+
+
+

+ Oops!

+

+ 404

+
+ Sorry, an error has occurred, Requested page not found! +
+ +
+
+
+
+ + \ No newline at end of file diff --git a/src/main/webapp/WEB-INF/views/generateAccount.jsp b/src/main/webapp/WEB-INF/views/generateAccount.jsp deleted file mode 100644 index 2987c45..0000000 --- a/src/main/webapp/WEB-INF/views/generateAccount.jsp +++ /dev/null @@ -1,54 +0,0 @@ -<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %> -<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> -<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %> - - - - - - - - - - - - - - Create a new survey - - - - - - - - - - -
- - - -
- - - - - diff --git a/src/main/webapp/WEB-INF/views/generateStudentAccount.jsp b/src/main/webapp/WEB-INF/views/generateStudentAccount.jsp index 5455e6e..2379c14 100644 --- a/src/main/webapp/WEB-INF/views/generateStudentAccount.jsp +++ b/src/main/webapp/WEB-INF/views/generateStudentAccount.jsp @@ -50,98 +50,8 @@
- + +
@@ -159,7 +69,7 @@
- + <%--
@@ -175,15 +85,49 @@ - - - - + + + + +
#
${student.id}${student.person.firstName}${student.person.lastName}${student.person.email}${student.person.gender}${student.firstName}${student.lastName}${student.email}${student.gender} ${student.username} Generate an account
--%> + + + + + + + + + + + + + + + + + + + + + + + + +
#FirstnameLastnameEmailGenderUsername
${student.id}${student.firstName}${student.lastName}${student.email}${student.gender}${student.username} + Generate an + account +
+ +
+
diff --git a/src/main/webapp/WEB-INF/views/home.jsp b/src/main/webapp/WEB-INF/views/home.jsp index ec39cf7..5db95f6 100644 --- a/src/main/webapp/WEB-INF/views/home.jsp +++ b/src/main/webapp/WEB-INF/views/home.jsp @@ -44,98 +44,8 @@
- + +
diff --git a/src/main/webapp/WEB-INF/views/manageAccount.jsp b/src/main/webapp/WEB-INF/views/manageAccount.jsp index c16c1fb..fbae387 100644 --- a/src/main/webapp/WEB-INF/views/manageAccount.jsp +++ b/src/main/webapp/WEB-INF/views/manageAccount.jsp @@ -1,48 +1,149 @@ <%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %> <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> <%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %> - +<%@ taglib prefix="security" uri="http://www.springframework.org/security/tags" %> - + + - - Create a new survey + Available Survey + + + + + + + + + - - + + - + + + + + + + + + + + + -
+
+ + + + +
+
+
+

Manage Account

+
+ + + +
+
+
+ Account List +
+ +
+
+ + + + + + + + + + + + + + + + + +
#userName
${user.id}${user.username} + Edit an account +
+
+ +
+ +
+ +
+ - + +
+
- - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/main/webapp/WEB-INF/views/manageAccountEdit.jsp b/src/main/webapp/WEB-INF/views/manageAccountEdit.jsp new file mode 100644 index 0000000..9fe309a --- /dev/null +++ b/src/main/webapp/WEB-INF/views/manageAccountEdit.jsp @@ -0,0 +1,143 @@ +<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %> +<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> +<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %> +<%@ taglib prefix="security" uri="http://www.springframework.org/security/tags" %> + + + + + + + + + + + + + Available Survey + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + +
+
+
+

Manage Account

+
+ + + +
+
+
+ Account List +
+ +
+ + Edit account + +
+ ${message} + +
+
+ ${message} + +
+ ${error} + + + +
+
+ +
+ +
+ + + +
+ + +
+ + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/main/webapp/WEB-INF/views/manageSurvey.jsp b/src/main/webapp/WEB-INF/views/manageSurvey.jsp index 261bf2a..cb70b57 100644 --- a/src/main/webapp/WEB-INF/views/manageSurvey.jsp +++ b/src/main/webapp/WEB-INF/views/manageSurvey.jsp @@ -51,98 +51,8 @@
- + +
@@ -169,6 +79,7 @@ Class Status + @@ -179,6 +90,7 @@ ${survey.classOffered.name} ${survey.status} Details + Update Status diff --git a/src/main/webapp/WEB-INF/views/menu.jsp b/src/main/webapp/WEB-INF/views/menu.jsp new file mode 100644 index 0000000..0ca5009 --- /dev/null +++ b/src/main/webapp/WEB-INF/views/menu.jsp @@ -0,0 +1,118 @@ +<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %> +<%@ taglib prefix="sec" uri="http://www.springframework.org/security/tags" %> + diff --git a/src/main/webapp/WEB-INF/views/questionForm.jsp b/src/main/webapp/WEB-INF/views/questionForm.jsp new file mode 100644 index 0000000..5025fed --- /dev/null +++ b/src/main/webapp/WEB-INF/views/questionForm.jsp @@ -0,0 +1,169 @@ +<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %> +<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> +<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %> + + + + + + + + + + + + + + Eval Plus Home page + + + + + + + + + + + + + + + + + + + + + + + + +
+ + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/main/webapp/WEB-INF/views/questionList.jsp b/src/main/webapp/WEB-INF/views/questionList.jsp new file mode 100644 index 0000000..b0502c1 --- /dev/null +++ b/src/main/webapp/WEB-INF/views/questionList.jsp @@ -0,0 +1,154 @@ +<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %> +<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> +<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %> + + + + + + + + + + + + + Survey report + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + +
+
+
+

Questions

+
+ + + +
+
+
+ Available questions for survey +
+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + + +
#DescriptionTypeStatus
${question.id}${question.question}${question.type}${question.enabled}updateremove
+
+ +
+ +
+ +
+ + + +
+ + +
+ + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/main/webapp/WEB-INF/views/registration.jsp b/src/main/webapp/WEB-INF/views/registration.jsp index 8e531b8..74677c2 100644 --- a/src/main/webapp/WEB-INF/views/registration.jsp +++ b/src/main/webapp/WEB-INF/views/registration.jsp @@ -1,66 +1,151 @@ <%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %> <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> <%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %> - + + - - Create an account + Eval Plus Home page + + + + + + - - + + - + + + + + + + + + -
+
-