diff --git a/README.md b/README.md index 0bdc0ca..8bd138f 100644 --- a/README.md +++ b/README.md @@ -25,7 +25,7 @@ More specifically, the following data will be stored in this application: * Attendance for labs / tutorial sessions #### Coordination -By tracking teaching assistants along with the students in a course, managing who does what, and when they do it, is much easier. Using each teaching assistant's availability, attendance records, student or group statistics, the system can plan optimum solutions for balancing workload among a number of teaching assistants. +By tracking teaching assistants along with the students in a course, managing who does what, and when they do it, is much easier. Using each teaching assistant's availability, attendance records, student or team statistics, the system can plan optimum solutions for balancing workload among a number of teaching assistants. More specifically, this application will take care of the following tasks: diff --git a/src/main/java/nl/andrewlalis/teaching_assistant_assistant/TeachingAssistantAssistantApplication.java b/src/main/java/nl/andrewlalis/teaching_assistant_assistant/TeachingAssistantAssistantApplication.java index cc75294..ff9d888 100644 --- a/src/main/java/nl/andrewlalis/teaching_assistant_assistant/TeachingAssistantAssistantApplication.java +++ b/src/main/java/nl/andrewlalis/teaching_assistant_assistant/TeachingAssistantAssistantApplication.java @@ -1,14 +1,14 @@ package nl.andrewlalis.teaching_assistant_assistant; import nl.andrewlalis.teaching_assistant_assistant.model.Course; -import nl.andrewlalis.teaching_assistant_assistant.model.people.Student; -import nl.andrewlalis.teaching_assistant_assistant.model.people.groups.StudentGroup; import nl.andrewlalis.teaching_assistant_assistant.model.repositories.CourseRepository; +import nl.andrewlalis.teaching_assistant_assistant.model.repositories.TeamRepository; +import nl.andrewlalis.teaching_assistant_assistant.model.repositories.PersonRepository; +import nl.andrewlalis.teaching_assistant_assistant.util.CourseGenerator; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.CommandLineRunner; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.data.repository.CrudRepository; @SpringBootApplication public class TeachingAssistantAssistantApplication implements CommandLineRunner { @@ -16,6 +16,12 @@ public class TeachingAssistantAssistantApplication implements CommandLineRunner @Autowired CourseRepository courseRepository; + @Autowired + TeamRepository teamRepository; + + @Autowired + PersonRepository personRepository; + public static void main(String[] args) { SpringApplication.run(TeachingAssistantAssistantApplication.class, args); } @@ -23,11 +29,19 @@ public class TeachingAssistantAssistantApplication implements CommandLineRunner @Override public void run(String... args) throws Exception { System.out.println("Running startup..."); - courseRepository.save(new Course("Intro to Information Systems", "INF-1")); - courseRepository.save(new Course("Program Correctness", "PC-002")); - System.out.println("Saved two courses."); + + // Generate some example courses. + CourseGenerator courseGenerator = new CourseGenerator(0, 3, 2, 10, 3, this.courseRepository, teamRepository, personRepository); + + Course c1 = courseGenerator.generate(); + Course c2 = courseGenerator.generate(); + + this.courseRepository.save(c1); + System.out.println(c1.toString()); + this.courseRepository.save(c2); + System.out.println(c2.toString()); + System.out.println("Course count: " + courseRepository.count()); - StudentGroup sg = new StudentGroup(); - sg.addMember(new Student("Andrew", "Lalis", "andrewlalisofficial@gmail.com")); + } } diff --git a/src/main/java/nl/andrewlalis/teaching_assistant_assistant/config/DataSourceConfig.java b/src/main/java/nl/andrewlalis/teaching_assistant_assistant/config/DataSourceConfig.java index f73e2a9..f6b0a94 100644 --- a/src/main/java/nl/andrewlalis/teaching_assistant_assistant/config/DataSourceConfig.java +++ b/src/main/java/nl/andrewlalis/teaching_assistant_assistant/config/DataSourceConfig.java @@ -25,7 +25,7 @@ public class DataSourceConfig { public DataSource getDataSource() { return DataSourceBuilder .create() - .url("jdbc:mysql://" + DB_HOST + '/' + DB_NAME) + .url("jdbc:h2:~/" + DB_NAME) .username(USERNAME) .password(PASSWORD) .build(); diff --git a/src/main/java/nl/andrewlalis/teaching_assistant_assistant/controllers/Courses.java b/src/main/java/nl/andrewlalis/teaching_assistant_assistant/controllers/Courses.java index cf5960f..404fa5b 100644 --- a/src/main/java/nl/andrewlalis/teaching_assistant_assistant/controllers/Courses.java +++ b/src/main/java/nl/andrewlalis/teaching_assistant_assistant/controllers/Courses.java @@ -1,10 +1,16 @@ package nl.andrewlalis.teaching_assistant_assistant.controllers; +import nl.andrewlalis.teaching_assistant_assistant.model.Course; import nl.andrewlalis.teaching_assistant_assistant.model.repositories.CourseRepository; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.ModelAttribute; +import org.springframework.web.bind.annotation.PostMapping; +/** + * Controller for the list of courses in the system. + */ @Controller public class Courses { @@ -20,4 +26,14 @@ public class Courses { return "courses"; } + @PostMapping( + value = "/courses", + consumes = "application/json" + ) + public String post(@ModelAttribute Course course) { + System.out.println("Object submitted: " + course); + this.courseRepository.save(course); + return "/courses/created"; + } + } diff --git a/src/main/java/nl/andrewlalis/teaching_assistant_assistant/controllers/courses/Entity.java b/src/main/java/nl/andrewlalis/teaching_assistant_assistant/controllers/courses/Entity.java index 57d6ce5..87ecd34 100644 --- a/src/main/java/nl/andrewlalis/teaching_assistant_assistant/controllers/courses/Entity.java +++ b/src/main/java/nl/andrewlalis/teaching_assistant_assistant/controllers/courses/Entity.java @@ -21,7 +21,10 @@ public class Entity { @GetMapping("/courses/{id}") public String get(@PathVariable Long id, Model model) { Optional courseOptional = this.courseRepository.findById(id); - courseOptional.ifPresent(course -> model.addAttribute("course", course)); + if (courseOptional.isPresent()) { + Course course = courseOptional.get(); + model.addAttribute("course", course); + } return "courses/entity"; } diff --git a/src/main/java/nl/andrewlalis/teaching_assistant_assistant/model/Course.java b/src/main/java/nl/andrewlalis/teaching_assistant_assistant/model/Course.java index 9945b0c..25d41db 100644 --- a/src/main/java/nl/andrewlalis/teaching_assistant_assistant/model/Course.java +++ b/src/main/java/nl/andrewlalis/teaching_assistant_assistant/model/Course.java @@ -1,10 +1,11 @@ package nl.andrewlalis.teaching_assistant_assistant.model; import nl.andrewlalis.teaching_assistant_assistant.model.assignments.Assignment; -import nl.andrewlalis.teaching_assistant_assistant.model.people.Student; -import nl.andrewlalis.teaching_assistant_assistant.model.people.TeachingAssistant; +import nl.andrewlalis.teaching_assistant_assistant.model.people.teams.StudentTeam; +import nl.andrewlalis.teaching_assistant_assistant.model.people.teams.TeachingAssistantTeam; import javax.persistence.*; +import java.util.ArrayList; import java.util.List; /** @@ -28,43 +29,42 @@ public class Course extends BasicEntity { @Column(unique = true, nullable = false) private String code; - /** - * The list of students participating in this course. This is a many-to-many relationship because a course can - * contain multiple students, and a student can participate in multiple courses at once. - */ - @ManyToMany - @JoinTable( - name = "course_student", - joinColumns = @JoinColumn(name = "course_id"), - inverseJoinColumns = @JoinColumn(name = "student_id") - ) - private List students; - - /** - * The list of teaching assistants managing this course. Just like for students, this is a many-to-many relation. - */ - @ManyToMany - @JoinTable( - name = "course_teaching_assistant", - joinColumns = @JoinColumn(name = "course_id"), - inverseJoinColumns = @JoinColumn(name = "teaching_assistant_id") - ) - private List teachingAssistants; - /** * The list of assignments this course contains. */ @OneToMany( - fetch = FetchType.LAZY, - orphanRemoval = true + orphanRemoval = true, + cascade = CascadeType.ALL ) @JoinColumn(name = "course_id") private List assignments; + /** + * The list of student teams in this course. + */ + @OneToMany( + orphanRemoval = true, + cascade = CascadeType.ALL + ) + private List studentTeams; + + /** + * The list of teaching assistant teams that belong to this course. + */ + @OneToMany( + orphanRemoval = true, + cascade = CascadeType.ALL + ) + private List teachingAssistantTeams; + /** * Default constructor for JPA. */ - protected Course() {} + protected Course() { + this.assignments = new ArrayList<>(); + this.studentTeams = new ArrayList<>(); + this.teachingAssistantTeams = new ArrayList<>(); + } /** * Constructs a new Course object. @@ -72,10 +72,19 @@ public class Course extends BasicEntity { * @param code The course's unique code. */ public Course(String name, String code) { + this(); // Initialize all array lists first. this.name = name; this.code = code; } + public void addStudentGroup(StudentTeam group) { + this.studentTeams.add(group); + } + + public void addTeachingAssistantGroup(TeachingAssistantTeam group) { + this.teachingAssistantTeams.add(group); + } + /* Getters and Setters */ @@ -88,15 +97,29 @@ public class Course extends BasicEntity { return code; } - public List getTeachingAssistants() { - return teachingAssistants; - } - - public List getStudents() { - return students; - } - public List getAssignments() { return assignments; } + + public List getStudentTeams() { + return studentTeams; + } + + public List getTeachingAssistantTeams() { + return teachingAssistantTeams; + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(this.getName()).append('\n'); + sb.append("TA teams: \n"); + for (TeachingAssistantTeam team : this.getTeachingAssistantTeams()) { + sb.append(team.toString()).append('\n'); + } + sb.append("Student teams: \n"); + for (StudentTeam team : this.getStudentTeams()) { + sb.append(team.toString()).append('\n'); + } + return sb.toString(); + } } diff --git a/src/main/java/nl/andrewlalis/teaching_assistant_assistant/model/assignments/grades/AssignmentGrade.java b/src/main/java/nl/andrewlalis/teaching_assistant_assistant/model/assignments/grades/AssignmentGrade.java index b1f00ce..4b1eddf 100644 --- a/src/main/java/nl/andrewlalis/teaching_assistant_assistant/model/assignments/grades/AssignmentGrade.java +++ b/src/main/java/nl/andrewlalis/teaching_assistant_assistant/model/assignments/grades/AssignmentGrade.java @@ -2,6 +2,7 @@ package nl.andrewlalis.teaching_assistant_assistant.model.assignments.grades; import nl.andrewlalis.teaching_assistant_assistant.model.BasicEntity; import nl.andrewlalis.teaching_assistant_assistant.model.assignments.Assignment; +import nl.andrewlalis.teaching_assistant_assistant.model.people.teams.StudentTeam; import javax.persistence.*; import java.util.List; @@ -21,6 +22,15 @@ public class AssignmentGrade extends BasicEntity { ) private Assignment assignment; + /** + * The student team to which this assignment grade belongs. + */ + @ManyToOne( + fetch = FetchType.LAZY, + optional = false + ) + private StudentTeam studentTeam; + /** * The list of section grades which make up this total grade. */ @@ -31,4 +41,17 @@ public class AssignmentGrade extends BasicEntity { @JoinColumn(name = "assignment_grade_id") private List sectionGrades; + /** + * Default constructor for JPA + */ + protected AssignmentGrade() {} + + public float getTotalGrade() { + float sum = 0.0f; + for (SectionGrade grade : this.sectionGrades) { + sum += grade.getGrade(); + } + return sum; + } + } diff --git a/src/main/java/nl/andrewlalis/teaching_assistant_assistant/model/assignments/grades/SectionGrade.java b/src/main/java/nl/andrewlalis/teaching_assistant_assistant/model/assignments/grades/SectionGrade.java index c9ae2c3..1529728 100644 --- a/src/main/java/nl/andrewlalis/teaching_assistant_assistant/model/assignments/grades/SectionGrade.java +++ b/src/main/java/nl/andrewlalis/teaching_assistant_assistant/model/assignments/grades/SectionGrade.java @@ -1,7 +1,7 @@ package nl.andrewlalis.teaching_assistant_assistant.model.assignments.grades; import nl.andrewlalis.teaching_assistant_assistant.model.BasicEntity; -import nl.andrewlalis.teaching_assistant_assistant.model.people.TeachingAssistant; +import nl.andrewlalis.teaching_assistant_assistant.model.people.teams.TeachingAssistantTeam; import javax.persistence.*; @@ -12,13 +12,13 @@ import javax.persistence.*; public class SectionGrade extends BasicEntity { /** - * The teaching assistant responsible for giving this grade. + * The teaching assistant team responsible for giving this grade. */ @ManyToOne( fetch = FetchType.LAZY, optional = false ) - private TeachingAssistant teachingAssistant; + private TeachingAssistantTeam teachingAssistantTeam; /** * The overall grade to which this section grade belongs. @@ -43,11 +43,19 @@ public class SectionGrade extends BasicEntity { @Column private float grade; - public SectionGrade(float grade, Feedback feedback, TeachingAssistant teachingAssistant, AssignmentGrade assignmentGrade) { + /** + * Default constructor for JPA. + */ + protected SectionGrade() {} + + public SectionGrade(float grade, Feedback feedback, TeachingAssistantTeam teachingAssistantTeam, AssignmentGrade assignmentGrade) { this.grade = grade; this.feedback = feedback; - this.teachingAssistant = teachingAssistant; + this.teachingAssistantTeam = teachingAssistantTeam; this.assignmentGrade = assignmentGrade; } + public float getGrade() { + return grade; + } } diff --git a/src/main/java/nl/andrewlalis/teaching_assistant_assistant/model/people/Person.java b/src/main/java/nl/andrewlalis/teaching_assistant_assistant/model/people/Person.java index e881785..9633806 100644 --- a/src/main/java/nl/andrewlalis/teaching_assistant_assistant/model/people/Person.java +++ b/src/main/java/nl/andrewlalis/teaching_assistant_assistant/model/people/Person.java @@ -1,14 +1,17 @@ package nl.andrewlalis.teaching_assistant_assistant.model.people; import nl.andrewlalis.teaching_assistant_assistant.model.BasicEntity; -import nl.andrewlalis.teaching_assistant_assistant.model.people.groups.Group; +import nl.andrewlalis.teaching_assistant_assistant.model.people.teams.Team; import javax.persistence.*; +import java.util.ArrayList; +import java.util.List; /** * Represents any person (teaching assistant, student, or other) that exists in this application. */ @Entity +@Table(name = "people") @Inheritance( strategy = InheritanceType.JOINED ) @@ -23,15 +26,21 @@ public abstract class Person extends BasicEntity { @Column private String emailAddress; - @ManyToOne( - fetch = FetchType.LAZY + /** + * The list of teams that this person belongs to. + */ + @ManyToMany( + fetch = FetchType.LAZY, + mappedBy = "members" ) - private Group group; + private List teams; /** * Default constructor for JPA. */ - protected Person () {} + protected Person () { + this.teams = new ArrayList<>(); + } /** * Constructs a new Person. @@ -40,11 +49,16 @@ public abstract class Person extends BasicEntity { * @param emailAddress The person's email address. */ public Person(String firstName, String lastName, String emailAddress) { + this(); this.firstName = firstName; this.lastName = lastName; this.emailAddress = emailAddress; } + public void assignToTeam(Team team) { + this.teams.add(team); + } + /* Getters and Setters */ @@ -61,7 +75,8 @@ public abstract class Person extends BasicEntity { return this.emailAddress; } - public Group getGroup() { - return this.group; + @Override + public String toString() { + return this.getFirstName() + ' ' + this.getLastName() + '[' + this.getId() + ']'; } } diff --git a/src/main/java/nl/andrewlalis/teaching_assistant_assistant/model/people/Student.java b/src/main/java/nl/andrewlalis/teaching_assistant_assistant/model/people/Student.java index ac95e96..e61216f 100644 --- a/src/main/java/nl/andrewlalis/teaching_assistant_assistant/model/people/Student.java +++ b/src/main/java/nl/andrewlalis/teaching_assistant_assistant/model/people/Student.java @@ -1,12 +1,6 @@ package nl.andrewlalis.teaching_assistant_assistant.model.people; -import nl.andrewlalis.teaching_assistant_assistant.model.Course; - import javax.persistence.Entity; -import javax.persistence.JoinColumn; -import javax.persistence.JoinTable; -import javax.persistence.ManyToMany; -import java.util.List; /** * Represents a student, or someone enrolled and submitting assignments for a course. @@ -14,17 +8,6 @@ import java.util.List; @Entity public class Student extends Person { - /** - * The list of courses which this student is taking part in. - */ - @ManyToMany - @JoinTable( - name = "course_student", - joinColumns = @JoinColumn(name = "student_id"), - inverseJoinColumns = @JoinColumn(name = "course_id") - ) - private List courses; - /** * Default constructor for JPA. */ diff --git a/src/main/java/nl/andrewlalis/teaching_assistant_assistant/model/people/TeachingAssistant.java b/src/main/java/nl/andrewlalis/teaching_assistant_assistant/model/people/TeachingAssistant.java index 5208f8a..2dce2e3 100644 --- a/src/main/java/nl/andrewlalis/teaching_assistant_assistant/model/people/TeachingAssistant.java +++ b/src/main/java/nl/andrewlalis/teaching_assistant_assistant/model/people/TeachingAssistant.java @@ -1,10 +1,6 @@ package nl.andrewlalis.teaching_assistant_assistant.model.people; -import nl.andrewlalis.teaching_assistant_assistant.model.Course; -import nl.andrewlalis.teaching_assistant_assistant.model.assignments.grades.SectionGrade; - -import javax.persistence.*; -import java.util.List; +import javax.persistence.Entity; /** * Represents a teaching assistant of a course, or in other words, a grader and administrator. @@ -12,30 +8,29 @@ import java.util.List; @Entity public class TeachingAssistant extends Person { - /** - * The list of courses which this teaching assistant is a member of. - */ - @ManyToMany - @JoinTable( - name = "course_teaching_assistant", - joinColumns = @JoinColumn(name = "teaching_assistant_id"), - inverseJoinColumns = @JoinColumn(name = "course_id") - ) - private List courses; - - /** - * The list of all feedback given by a teaching assistant. - */ - @OneToMany - @JoinColumn(name = "teaching_assistant_id") - private List sectionGrades; - - @Column - private TeachingAssistantRole role; +// /** +// * The list of all feedback given by a teaching assistant. +// */ +// @OneToMany +// @JoinColumn(name = "teaching_assistant_id") +// private List sectionGrades; /** * Default constructor for JPA. */ - protected TeachingAssistant() {} + protected TeachingAssistant() { +// this.sectionGrades = new ArrayList<>(); + } + public TeachingAssistant(String firstName, String lastName, String emailAddress) { + super(firstName, lastName, emailAddress); + } + +// public List getSectionGrades() { +// return this.sectionGrades; +// } +// +// public void setSectionGrades(List newSectionGrades) { +// this.sectionGrades = newSectionGrades; +// } } diff --git a/src/main/java/nl/andrewlalis/teaching_assistant_assistant/model/people/groups/Group.java b/src/main/java/nl/andrewlalis/teaching_assistant_assistant/model/people/groups/Group.java deleted file mode 100644 index dc1a0ae..0000000 --- a/src/main/java/nl/andrewlalis/teaching_assistant_assistant/model/people/groups/Group.java +++ /dev/null @@ -1,48 +0,0 @@ -package nl.andrewlalis.teaching_assistant_assistant.model.people.groups; - -import nl.andrewlalis.teaching_assistant_assistant.model.BasicEntity; -import nl.andrewlalis.teaching_assistant_assistant.model.people.Person; - -import javax.persistence.FetchType; -import javax.persistence.MappedSuperclass; -import javax.persistence.OneToMany; -import java.util.List; - -/** - * A group consisting of one or more members. Child classes should define P as a sub class of Person to define custom - * behavior if needed. - * @param

The type of members this group contains. - */ -@MappedSuperclass -public abstract class Group

extends BasicEntity { - - /** - * The list of members in this group. - */ - @OneToMany( - fetch = FetchType.EAGER, - orphanRemoval = true - ) - protected List

members; - - public void addMember(P person) { - this.members.add(person); - } - - public boolean containsMember(P person) { - return this.members.contains(person); - } - - public void removeMember(P person) { - this.members.remove(person); - } - - /* - Getters and Setters - */ - - public List

getMembers() { - return this.members; - } - -} diff --git a/src/main/java/nl/andrewlalis/teaching_assistant_assistant/model/people/groups/StudentGroup.java b/src/main/java/nl/andrewlalis/teaching_assistant_assistant/model/people/groups/StudentGroup.java deleted file mode 100644 index 36d7360..0000000 --- a/src/main/java/nl/andrewlalis/teaching_assistant_assistant/model/people/groups/StudentGroup.java +++ /dev/null @@ -1,18 +0,0 @@ -package nl.andrewlalis.teaching_assistant_assistant.model.people.groups; - -import nl.andrewlalis.teaching_assistant_assistant.model.people.Student; - -import javax.persistence.Entity; - -/** - * A group of students. - */ -@Entity -public class StudentGroup extends Group { - - /** - * Default constructor for JPA. - */ - public StudentGroup() {} - -} diff --git a/src/main/java/nl/andrewlalis/teaching_assistant_assistant/model/people/groups/TeachingAssistantGroup.java b/src/main/java/nl/andrewlalis/teaching_assistant_assistant/model/people/groups/TeachingAssistantGroup.java deleted file mode 100644 index 1147763..0000000 --- a/src/main/java/nl/andrewlalis/teaching_assistant_assistant/model/people/groups/TeachingAssistantGroup.java +++ /dev/null @@ -1,18 +0,0 @@ -package nl.andrewlalis.teaching_assistant_assistant.model.people.groups; - -import nl.andrewlalis.teaching_assistant_assistant.model.people.TeachingAssistant; - -import javax.persistence.Entity; - -/** - * A group of teaching assistants. - */ -@Entity -public class TeachingAssistantGroup extends Group { - - /** - * Default constructor for JPA. - */ - public TeachingAssistantGroup() {} - -} diff --git a/src/main/java/nl/andrewlalis/teaching_assistant_assistant/model/people/teams/StudentTeam.java b/src/main/java/nl/andrewlalis/teaching_assistant_assistant/model/people/teams/StudentTeam.java new file mode 100644 index 0000000..70fddce --- /dev/null +++ b/src/main/java/nl/andrewlalis/teaching_assistant_assistant/model/people/teams/StudentTeam.java @@ -0,0 +1,34 @@ +package nl.andrewlalis.teaching_assistant_assistant.model.people.teams; + +import nl.andrewlalis.teaching_assistant_assistant.model.assignments.grades.AssignmentGrade; +import nl.andrewlalis.teaching_assistant_assistant.model.people.Student; + +import javax.persistence.Entity; +import javax.persistence.FetchType; +import javax.persistence.OneToMany; +import java.util.List; + +/** + * A group of students. + */ +@Entity +public class StudentTeam extends Team { + + /** + * The list of assignment grades which this student group has received. + */ + @OneToMany( + fetch = FetchType.LAZY + ) + private List assignmentGrades; + + /** + * Default constructor for JPA. + */ + public StudentTeam() {} + + @Override + public void addMember(Student person) { + this.getMembers().add(person); + } +} diff --git a/src/main/java/nl/andrewlalis/teaching_assistant_assistant/model/people/teams/TeachingAssistantTeam.java b/src/main/java/nl/andrewlalis/teaching_assistant_assistant/model/people/teams/TeachingAssistantTeam.java new file mode 100644 index 0000000..2d60d4a --- /dev/null +++ b/src/main/java/nl/andrewlalis/teaching_assistant_assistant/model/people/teams/TeachingAssistantTeam.java @@ -0,0 +1,27 @@ +package nl.andrewlalis.teaching_assistant_assistant.model.people.teams; + +import nl.andrewlalis.teaching_assistant_assistant.model.people.TeachingAssistant; +import nl.andrewlalis.teaching_assistant_assistant.model.people.TeachingAssistantRole; + +import javax.persistence.Column; +import javax.persistence.Entity; + +/** + * A group of teaching assistants. + */ +@Entity +public class TeachingAssistantTeam extends Team { + + @Column + private TeachingAssistantRole role; + + /** + * Default constructor for JPA. + */ + public TeachingAssistantTeam() {} + + @Override + public void addMember(TeachingAssistant person) { + this.getMembers().add(person); + } +} diff --git a/src/main/java/nl/andrewlalis/teaching_assistant_assistant/model/people/teams/Team.java b/src/main/java/nl/andrewlalis/teaching_assistant_assistant/model/people/teams/Team.java new file mode 100644 index 0000000..675b807 --- /dev/null +++ b/src/main/java/nl/andrewlalis/teaching_assistant_assistant/model/people/teams/Team.java @@ -0,0 +1,94 @@ +package nl.andrewlalis.teaching_assistant_assistant.model.people.teams; + +import nl.andrewlalis.teaching_assistant_assistant.model.BasicEntity; +import nl.andrewlalis.teaching_assistant_assistant.model.Course; +import nl.andrewlalis.teaching_assistant_assistant.model.people.Person; + +import javax.persistence.*; +import java.util.ArrayList; +import java.util.List; + +/** + * A group consisting of one or more members. Child classes should define P as a sub class of Person to define custom + * behavior if needed. + * @param

The type of members this group contains. + */ +@Entity +@Inheritance( + strategy = InheritanceType.JOINED +) +public abstract class Team

extends BasicEntity { + + /** + * The list of members in this group. + */ + @ManyToMany( + cascade = CascadeType.ALL + ) + @JoinTable( + name = "team_members", + joinColumns = @JoinColumn(name = "team_id"), + inverseJoinColumns = @JoinColumn(name = "person_id") + ) + protected List

members; + + /** + * The course that this team belongs to. + */ + @ManyToOne( + optional = false + ) + private Course course; + + /** + * Default constructor for JPA and initializing list of members for any child classes. + */ + protected Team() { + this.members = new ArrayList<>(); + } + + public void addMember(P person) { + if (!this.containsMember(person)) { + this.members.add(person); + } + } + + public void addMembers(List

people) { + for (P person : people) { + this.addMember(person); + } + } + + public boolean containsMember(P person) { + return this.members.contains(person); + } + + public void removeMember(P person) { + this.members.remove(person); + } + + /* + Getters and Setters + */ + + public void setCourse(Course course) { + this.course = course; + } + + public List

getMembers() { + return this.members; + } + + public Course getCourse() { + return course; + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + for (P p : this.getMembers()) { + sb.append(p.toString()).append(", "); + } + return sb.toString(); + } +} diff --git a/src/main/java/nl/andrewlalis/teaching_assistant_assistant/model/repositories/PersonRepository.java b/src/main/java/nl/andrewlalis/teaching_assistant_assistant/model/repositories/PersonRepository.java new file mode 100644 index 0000000..885408a --- /dev/null +++ b/src/main/java/nl/andrewlalis/teaching_assistant_assistant/model/repositories/PersonRepository.java @@ -0,0 +1,10 @@ +package nl.andrewlalis.teaching_assistant_assistant.model.repositories; + +import nl.andrewlalis.teaching_assistant_assistant.model.people.Person; +import org.springframework.data.repository.CrudRepository; + +public interface PersonRepository extends CrudRepository { + + Person findByFirstNameAndLastName(String firstName, String lastName); + +} diff --git a/src/main/java/nl/andrewlalis/teaching_assistant_assistant/model/repositories/TeamRepository.java b/src/main/java/nl/andrewlalis/teaching_assistant_assistant/model/repositories/TeamRepository.java new file mode 100644 index 0000000..cf66881 --- /dev/null +++ b/src/main/java/nl/andrewlalis/teaching_assistant_assistant/model/repositories/TeamRepository.java @@ -0,0 +1,7 @@ +package nl.andrewlalis.teaching_assistant_assistant.model.repositories; + +import nl.andrewlalis.teaching_assistant_assistant.model.people.teams.Team; +import org.springframework.data.repository.CrudRepository; + +public interface TeamRepository extends CrudRepository { +} diff --git a/src/main/java/nl/andrewlalis/teaching_assistant_assistant/util/CourseGenerator.java b/src/main/java/nl/andrewlalis/teaching_assistant_assistant/util/CourseGenerator.java new file mode 100644 index 0000000..39215ab --- /dev/null +++ b/src/main/java/nl/andrewlalis/teaching_assistant_assistant/util/CourseGenerator.java @@ -0,0 +1,107 @@ +package nl.andrewlalis.teaching_assistant_assistant.util; + +import nl.andrewlalis.teaching_assistant_assistant.model.Course; +import nl.andrewlalis.teaching_assistant_assistant.model.people.Student; +import nl.andrewlalis.teaching_assistant_assistant.model.people.TeachingAssistant; +import nl.andrewlalis.teaching_assistant_assistant.model.people.teams.StudentTeam; +import nl.andrewlalis.teaching_assistant_assistant.model.people.teams.TeachingAssistantTeam; +import nl.andrewlalis.teaching_assistant_assistant.model.repositories.CourseRepository; +import nl.andrewlalis.teaching_assistant_assistant.model.repositories.PersonRepository; +import nl.andrewlalis.teaching_assistant_assistant.model.repositories.TeamRepository; + +import java.util.ArrayList; +import java.util.List; + +public class CourseGenerator extends TestDataGenerator { + + private static final String[] COURSE_NAMES = { + "Math", + "Biology", + "Psychology", + "Liberal Arts", + "English", + "Spanish", + "German", + "Programming", + "Physics", + "Chemistry", + "Geometry", + "Calculus", + "Algebra" + }; + + private int studentGroupCount = 50; + private int studentGroupSize = 2; + private int teachingAssistantGroupCount = 10; + private int teachingAssistantGroupSize = 2; + + private CourseRepository courseRepository; + private TeamRepository teamRepository; + private PersonRepository personRepository; + + public CourseGenerator(CourseRepository courseRepository, TeamRepository teamRepository, PersonRepository personRepository) { + super(0); + + this.courseRepository = courseRepository; + this.teamRepository = teamRepository; + this.personRepository = personRepository; + } + + public CourseGenerator(long seed, int studentGroupSize, int teachingAssistantGroupSize, int studentGroupCount, int teachingAssistantGroupCount, CourseRepository courseRepository, TeamRepository teamRepository, PersonRepository personRepository) { + super(seed); + this.studentGroupSize = studentGroupSize; + this.teachingAssistantGroupSize = teachingAssistantGroupSize; + this.studentGroupCount = studentGroupCount; + this.teachingAssistantGroupCount = teachingAssistantGroupCount; + + this.courseRepository = courseRepository; + this.teamRepository = teamRepository; + this.personRepository = personRepository; + } + + @Override + public Course generate() { + Course course = new Course(this.getRandomObjectFromArray(COURSE_NAMES), Integer.toString(this.getRandom().nextInt(1000))); + List studentTeams = this.generateStudentTeams(); + List teachingAssistantTeams = this.generateTeachingAssistantTeams(); + for (StudentTeam team : studentTeams) { + course.addStudentGroup(team); + team.setCourse(course); + } + for (TeachingAssistantTeam team : teachingAssistantTeams) { + course.addTeachingAssistantGroup(team); + team.setCourse(course); + } + return course; + } + + private List generateStudentTeams() { + StudentGenerator studentGenerator = new StudentGenerator(this.getSeed()); + List teams = new ArrayList<>(this.studentGroupCount); + for (int i = 0; i < this.studentGroupCount; i++) { + StudentTeam team = new StudentTeam(); + List students = studentGenerator.generateList(this.studentGroupSize); + for (Student s : students) { + s.assignToTeam(team); + team.addMember(s); + } + teams.add(team); + } + return teams; + } + + private List generateTeachingAssistantTeams() { + TeachingAssistantGenerator teachingAssistantGenerator = new TeachingAssistantGenerator(this.getSeed() + 1); + List teams = new ArrayList<>(this.teachingAssistantGroupCount); + for (int i = 0; i < this.teachingAssistantGroupCount; i++) { + TeachingAssistantTeam team = new TeachingAssistantTeam(); + List teachingAssistants = teachingAssistantGenerator.generateList(this.teachingAssistantGroupSize); + for (TeachingAssistant t : teachingAssistants) { + t.assignToTeam(team); + team.addMember(t); + } + teams.add(team); + } + return teams; + } +} diff --git a/src/main/java/nl/andrewlalis/teaching_assistant_assistant/util/PersonGenerator.java b/src/main/java/nl/andrewlalis/teaching_assistant_assistant/util/PersonGenerator.java new file mode 100644 index 0000000..c4750a5 --- /dev/null +++ b/src/main/java/nl/andrewlalis/teaching_assistant_assistant/util/PersonGenerator.java @@ -0,0 +1,67 @@ +package nl.andrewlalis.teaching_assistant_assistant.util; + +import nl.andrewlalis.teaching_assistant_assistant.model.people.Person; + +/** + * Generates random people for testing purposes. + */ +public abstract class PersonGenerator

extends TestDataGenerator

{ + + private static final String[] FIRST_NAMES = { + "Andrew", + "John", + "Klaus", + "William", + "Bruce", + "James", + "Kyle", + "Michael", + "Connor", + "Kate", + "Sarah", + "Alex", + "George", + "Anna", + "Bianca" + }; + + private static final String[] LAST_NAMES = { + "Lalis", + "Smith", + "Williams", + "Willis", + "Peterson", + "van Dijk", + "Rakshiev", + "Jordan", + "Kiel", + "Salamanca", + "Rockwell", + "Rockefeller", + "Armstrong" + }; + + private static final String[] EMAIL_DOMAINS = { + "gmail.com", + "hotmail.com", + "mail.ru", + "student.rug.nl", + "yahoo.com" + }; + + public PersonGenerator(long seed) { + super(seed); + } + + protected String getRandomFirstName() { + return (String) this.getRandomObjectFromArray(FIRST_NAMES); + } + + protected String getRandomLastName() { + return (String) this.getRandomObjectFromArray(LAST_NAMES); + } + + protected String getRandomEmailAddress(String firstName, String lastName) { + return firstName + '.' + lastName + this.getRandom().nextInt(1000) + '@' + this.getRandomObjectFromArray(EMAIL_DOMAINS); + } +} diff --git a/src/main/java/nl/andrewlalis/teaching_assistant_assistant/util/StudentGenerator.java b/src/main/java/nl/andrewlalis/teaching_assistant_assistant/util/StudentGenerator.java new file mode 100644 index 0000000..6d1df25 --- /dev/null +++ b/src/main/java/nl/andrewlalis/teaching_assistant_assistant/util/StudentGenerator.java @@ -0,0 +1,17 @@ +package nl.andrewlalis.teaching_assistant_assistant.util; + +import nl.andrewlalis.teaching_assistant_assistant.model.people.Student; + +public class StudentGenerator extends PersonGenerator { + + public StudentGenerator(long seed) { + super(seed); + } + + @Override + public Student generate() { + String firstName = this.getRandomFirstName(); + String lastName = this.getRandomLastName(); + return new Student(firstName, lastName, this.getRandomEmailAddress(firstName, lastName)); + } +} diff --git a/src/main/java/nl/andrewlalis/teaching_assistant_assistant/util/StudentTeamGenerator.java b/src/main/java/nl/andrewlalis/teaching_assistant_assistant/util/StudentTeamGenerator.java new file mode 100644 index 0000000..855fa29 --- /dev/null +++ b/src/main/java/nl/andrewlalis/teaching_assistant_assistant/util/StudentTeamGenerator.java @@ -0,0 +1,21 @@ +package nl.andrewlalis.teaching_assistant_assistant.util; + +import nl.andrewlalis.teaching_assistant_assistant.model.people.Student; +import nl.andrewlalis.teaching_assistant_assistant.model.people.teams.StudentTeam; + +public class StudentTeamGenerator extends TeamGenerator { + + public StudentTeamGenerator(long seed, int groupSize, boolean groupSizeVariable) { + super(seed, groupSize, groupSizeVariable); + } + + @Override + protected StudentTeam getNewTeam() { + return new StudentTeam(); + } + + @Override + protected PersonGenerator getPersonGenerator(long seed) { + return new StudentGenerator(seed); + } +} diff --git a/src/main/java/nl/andrewlalis/teaching_assistant_assistant/util/TeachingAssistantGenerator.java b/src/main/java/nl/andrewlalis/teaching_assistant_assistant/util/TeachingAssistantGenerator.java new file mode 100644 index 0000000..9e1507d --- /dev/null +++ b/src/main/java/nl/andrewlalis/teaching_assistant_assistant/util/TeachingAssistantGenerator.java @@ -0,0 +1,17 @@ +package nl.andrewlalis.teaching_assistant_assistant.util; + +import nl.andrewlalis.teaching_assistant_assistant.model.people.TeachingAssistant; + +public class TeachingAssistantGenerator extends PersonGenerator { + + public TeachingAssistantGenerator(long seed) { + super(seed); + } + + @Override + public TeachingAssistant generate() { + String firstName = this.getRandomFirstName(); + String lastName = this.getRandomLastName(); + return new TeachingAssistant(firstName, lastName, this.getRandomEmailAddress(firstName, lastName)); + } +} diff --git a/src/main/java/nl/andrewlalis/teaching_assistant_assistant/util/TeachingAssistantTeamGenerator.java b/src/main/java/nl/andrewlalis/teaching_assistant_assistant/util/TeachingAssistantTeamGenerator.java new file mode 100644 index 0000000..abc2557 --- /dev/null +++ b/src/main/java/nl/andrewlalis/teaching_assistant_assistant/util/TeachingAssistantTeamGenerator.java @@ -0,0 +1,21 @@ +package nl.andrewlalis.teaching_assistant_assistant.util; + +import nl.andrewlalis.teaching_assistant_assistant.model.people.TeachingAssistant; +import nl.andrewlalis.teaching_assistant_assistant.model.people.teams.TeachingAssistantTeam; + +public class TeachingAssistantTeamGenerator extends TeamGenerator { + + public TeachingAssistantTeamGenerator(long seed, int groupSize, boolean groupSizeVariable) { + super(seed, groupSize, groupSizeVariable); + } + + @Override + protected TeachingAssistantTeam getNewTeam() { + return new TeachingAssistantTeam(); + } + + @Override + protected PersonGenerator getPersonGenerator(long seed) { + return new TeachingAssistantGenerator(seed); + } +} diff --git a/src/main/java/nl/andrewlalis/teaching_assistant_assistant/util/TeamGenerator.java b/src/main/java/nl/andrewlalis/teaching_assistant_assistant/util/TeamGenerator.java new file mode 100644 index 0000000..5353b37 --- /dev/null +++ b/src/main/java/nl/andrewlalis/teaching_assistant_assistant/util/TeamGenerator.java @@ -0,0 +1,36 @@ +package nl.andrewlalis.teaching_assistant_assistant.util; + +import nl.andrewlalis.teaching_assistant_assistant.model.people.Person; +import nl.andrewlalis.teaching_assistant_assistant.model.people.teams.Team; + +import java.util.ArrayList; +import java.util.List; + +public abstract class TeamGenerator extends TestDataGenerator { + + private int groupSize; + private boolean groupSizeVariable = false; + private PersonGenerator

personGenerator; + + public TeamGenerator(long seed, int groupSize, boolean groupSizeVariable) { + super(seed); + this.groupSize = groupSize; + this.groupSizeVariable = groupSizeVariable; + this.personGenerator = this.getPersonGenerator(seed); + } + + protected abstract T getNewTeam(); + + protected abstract PersonGenerator

getPersonGenerator(long seed); + + @Override + public T generate() { + T team = this.getNewTeam(); + List

members = new ArrayList<>(this.groupSize); + for (int i = 0; i < this.groupSize; i++) { + members.add(this.personGenerator.generate()); + } + //team.addMembers(members); + return team; + } +} diff --git a/src/main/java/nl/andrewlalis/teaching_assistant_assistant/util/TestDataGenerator.java b/src/main/java/nl/andrewlalis/teaching_assistant_assistant/util/TestDataGenerator.java new file mode 100644 index 0000000..54dd86a --- /dev/null +++ b/src/main/java/nl/andrewlalis/teaching_assistant_assistant/util/TestDataGenerator.java @@ -0,0 +1,47 @@ +package nl.andrewlalis.teaching_assistant_assistant.util; + +import java.util.ArrayList; +import java.util.List; +import java.util.Random; + +/** + * Generates random objects for testing. + * @param The class of objects this generator produces. + */ +public abstract class TestDataGenerator { + + private Random random; + private long seed; + + public TestDataGenerator() { + this.random = new Random(0); + } + + public TestDataGenerator(long seed) { + this.seed = seed; + this.random = new Random(seed); + } + + public List generateList(int count) { + List list = new ArrayList<>(count); + for (int i = 0; i < count; i++) { + list.add(this.generate()); + } + return list; + } + + public abstract T generate(); + + protected C getRandomObjectFromArray(C[] array) { + return array[this.random.nextInt(array.length)]; + } + + protected Random getRandom() { + return this.random; + } + + protected long getSeed() { + return this.seed; + } + +} diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 2027ba2..bb2d8eb 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -1 +1,7 @@ -spring.jpa.hibernate.ddl-auto=create-drop +spring.jpa.hibernate.ddl-auto=create +#spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL57Dialect + +#spring.jpa.properties.hibernate.show_sql=true +#spring.jpa.properties.hibernate.use_sql_comments=true +#spring.jpa.properties.hibernate.format_sql=true +#spring.jpa.properties.hibernate.type=trace diff --git a/src/main/resources/templates/courses/create.html b/src/main/resources/templates/courses/create.html new file mode 100644 index 0000000..566549b --- /dev/null +++ b/src/main/resources/templates/courses/create.html @@ -0,0 +1,10 @@ + + + + + Title + + + + + \ No newline at end of file diff --git a/src/main/resources/templates/courses/created.html b/src/main/resources/templates/courses/created.html new file mode 100644 index 0000000..3f33f5e --- /dev/null +++ b/src/main/resources/templates/courses/created.html @@ -0,0 +1,14 @@ + + + + + Title + + + +

+ Object created. +

+ + + \ No newline at end of file diff --git a/src/main/resources/templates/courses/entity.html b/src/main/resources/templates/courses/entity.html index 02ffef1..9b3229f 100644 --- a/src/main/resources/templates/courses/entity.html +++ b/src/main/resources/templates/courses/entity.html @@ -8,9 +8,24 @@

-

-

Created on:

-

Id:

+

+

Created on:

+

Id:

+
+

Teaching Assistant Groups ():

+ + + + + +
+

Student Groups ():

+ + + + + +