Added basic sample data generation.

This commit is contained in:
Andrew Lalis 2019-04-10 17:24:00 +02:00 committed by andrewlalis
parent 61de43d7d8
commit 00ec719238
31 changed files with 736 additions and 190 deletions

View File

@ -25,7 +25,7 @@ More specifically, the following data will be stored in this application:
* Attendance for labs / tutorial sessions * Attendance for labs / tutorial sessions
#### Coordination #### 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: More specifically, this application will take care of the following tasks:

View File

@ -1,14 +1,14 @@
package nl.andrewlalis.teaching_assistant_assistant; package nl.andrewlalis.teaching_assistant_assistant;
import nl.andrewlalis.teaching_assistant_assistant.model.Course; 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.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.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner; import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication; import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.data.repository.CrudRepository;
@SpringBootApplication @SpringBootApplication
public class TeachingAssistantAssistantApplication implements CommandLineRunner { public class TeachingAssistantAssistantApplication implements CommandLineRunner {
@ -16,6 +16,12 @@ public class TeachingAssistantAssistantApplication implements CommandLineRunner
@Autowired @Autowired
CourseRepository courseRepository; CourseRepository courseRepository;
@Autowired
TeamRepository teamRepository;
@Autowired
PersonRepository personRepository;
public static void main(String[] args) { public static void main(String[] args) {
SpringApplication.run(TeachingAssistantAssistantApplication.class, args); SpringApplication.run(TeachingAssistantAssistantApplication.class, args);
} }
@ -23,11 +29,19 @@ public class TeachingAssistantAssistantApplication implements CommandLineRunner
@Override @Override
public void run(String... args) throws Exception { public void run(String... args) throws Exception {
System.out.println("Running startup..."); System.out.println("Running startup...");
courseRepository.save(new Course("Intro to Information Systems", "INF-1"));
courseRepository.save(new Course("Program Correctness", "PC-002")); // Generate some example courses.
System.out.println("Saved two 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()); System.out.println("Course count: " + courseRepository.count());
StudentGroup sg = new StudentGroup();
sg.addMember(new Student("Andrew", "Lalis", "andrewlalisofficial@gmail.com"));
} }
} }

View File

@ -25,7 +25,7 @@ public class DataSourceConfig {
public DataSource getDataSource() { public DataSource getDataSource() {
return DataSourceBuilder return DataSourceBuilder
.create() .create()
.url("jdbc:mysql://" + DB_HOST + '/' + DB_NAME) .url("jdbc:h2:~/" + DB_NAME)
.username(USERNAME) .username(USERNAME)
.password(PASSWORD) .password(PASSWORD)
.build(); .build();

View File

@ -1,10 +1,16 @@
package nl.andrewlalis.teaching_assistant_assistant.controllers; 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 nl.andrewlalis.teaching_assistant_assistant.model.repositories.CourseRepository;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
import org.springframework.ui.Model; import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping; 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 @Controller
public class Courses { public class Courses {
@ -20,4 +26,14 @@ public class Courses {
return "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";
}
} }

View File

@ -21,7 +21,10 @@ public class Entity {
@GetMapping("/courses/{id}") @GetMapping("/courses/{id}")
public String get(@PathVariable Long id, Model model) { public String get(@PathVariable Long id, Model model) {
Optional<Course> courseOptional = this.courseRepository.findById(id); Optional<Course> 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"; return "courses/entity";
} }

View File

@ -1,10 +1,11 @@
package nl.andrewlalis.teaching_assistant_assistant.model; package nl.andrewlalis.teaching_assistant_assistant.model;
import nl.andrewlalis.teaching_assistant_assistant.model.assignments.Assignment; 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.teams.StudentTeam;
import nl.andrewlalis.teaching_assistant_assistant.model.people.TeachingAssistant; import nl.andrewlalis.teaching_assistant_assistant.model.people.teams.TeachingAssistantTeam;
import javax.persistence.*; import javax.persistence.*;
import java.util.ArrayList;
import java.util.List; import java.util.List;
/** /**
@ -28,43 +29,42 @@ public class Course extends BasicEntity {
@Column(unique = true, nullable = false) @Column(unique = true, nullable = false)
private String code; 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<Student> 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<TeachingAssistant> teachingAssistants;
/** /**
* The list of assignments this course contains. * The list of assignments this course contains.
*/ */
@OneToMany( @OneToMany(
fetch = FetchType.LAZY, orphanRemoval = true,
orphanRemoval = true cascade = CascadeType.ALL
) )
@JoinColumn(name = "course_id") @JoinColumn(name = "course_id")
private List<Assignment> assignments; private List<Assignment> assignments;
/**
* The list of student teams in this course.
*/
@OneToMany(
orphanRemoval = true,
cascade = CascadeType.ALL
)
private List<StudentTeam> studentTeams;
/**
* The list of teaching assistant teams that belong to this course.
*/
@OneToMany(
orphanRemoval = true,
cascade = CascadeType.ALL
)
private List<TeachingAssistantTeam> teachingAssistantTeams;
/** /**
* Default constructor for JPA. * 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. * Constructs a new Course object.
@ -72,10 +72,19 @@ public class Course extends BasicEntity {
* @param code The course's unique code. * @param code The course's unique code.
*/ */
public Course(String name, String code) { public Course(String name, String code) {
this(); // Initialize all array lists first.
this.name = name; this.name = name;
this.code = code; this.code = code;
} }
public void addStudentGroup(StudentTeam group) {
this.studentTeams.add(group);
}
public void addTeachingAssistantGroup(TeachingAssistantTeam group) {
this.teachingAssistantTeams.add(group);
}
/* /*
Getters and Setters Getters and Setters
*/ */
@ -88,15 +97,29 @@ public class Course extends BasicEntity {
return code; return code;
} }
public List<TeachingAssistant> getTeachingAssistants() {
return teachingAssistants;
}
public List<Student> getStudents() {
return students;
}
public List<Assignment> getAssignments() { public List<Assignment> getAssignments() {
return assignments; return assignments;
} }
public List<StudentTeam> getStudentTeams() {
return studentTeams;
}
public List<TeachingAssistantTeam> 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();
}
} }

View File

@ -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.BasicEntity;
import nl.andrewlalis.teaching_assistant_assistant.model.assignments.Assignment; import nl.andrewlalis.teaching_assistant_assistant.model.assignments.Assignment;
import nl.andrewlalis.teaching_assistant_assistant.model.people.teams.StudentTeam;
import javax.persistence.*; import javax.persistence.*;
import java.util.List; import java.util.List;
@ -21,6 +22,15 @@ public class AssignmentGrade extends BasicEntity {
) )
private Assignment assignment; 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. * 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") @JoinColumn(name = "assignment_grade_id")
private List<SectionGrade> sectionGrades; private List<SectionGrade> sectionGrades;
/**
* Default constructor for JPA
*/
protected AssignmentGrade() {}
public float getTotalGrade() {
float sum = 0.0f;
for (SectionGrade grade : this.sectionGrades) {
sum += grade.getGrade();
}
return sum;
}
} }

View File

@ -1,7 +1,7 @@
package nl.andrewlalis.teaching_assistant_assistant.model.assignments.grades; package nl.andrewlalis.teaching_assistant_assistant.model.assignments.grades;
import nl.andrewlalis.teaching_assistant_assistant.model.BasicEntity; 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.*; import javax.persistence.*;
@ -12,13 +12,13 @@ import javax.persistence.*;
public class SectionGrade extends BasicEntity { public class SectionGrade extends BasicEntity {
/** /**
* The teaching assistant responsible for giving this grade. * The teaching assistant team responsible for giving this grade.
*/ */
@ManyToOne( @ManyToOne(
fetch = FetchType.LAZY, fetch = FetchType.LAZY,
optional = false optional = false
) )
private TeachingAssistant teachingAssistant; private TeachingAssistantTeam teachingAssistantTeam;
/** /**
* The overall grade to which this section grade belongs. * The overall grade to which this section grade belongs.
@ -43,11 +43,19 @@ public class SectionGrade extends BasicEntity {
@Column @Column
private float grade; 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.grade = grade;
this.feedback = feedback; this.feedback = feedback;
this.teachingAssistant = teachingAssistant; this.teachingAssistantTeam = teachingAssistantTeam;
this.assignmentGrade = assignmentGrade; this.assignmentGrade = assignmentGrade;
} }
public float getGrade() {
return grade;
}
} }

View File

@ -1,14 +1,17 @@
package nl.andrewlalis.teaching_assistant_assistant.model.people; package nl.andrewlalis.teaching_assistant_assistant.model.people;
import nl.andrewlalis.teaching_assistant_assistant.model.BasicEntity; 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 javax.persistence.*;
import java.util.ArrayList;
import java.util.List;
/** /**
* Represents any person (teaching assistant, student, or other) that exists in this application. * Represents any person (teaching assistant, student, or other) that exists in this application.
*/ */
@Entity @Entity
@Table(name = "people")
@Inheritance( @Inheritance(
strategy = InheritanceType.JOINED strategy = InheritanceType.JOINED
) )
@ -23,15 +26,21 @@ public abstract class Person extends BasicEntity {
@Column @Column
private String emailAddress; 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<Team> teams;
/** /**
* Default constructor for JPA. * Default constructor for JPA.
*/ */
protected Person () {} protected Person () {
this.teams = new ArrayList<>();
}
/** /**
* Constructs a new Person. * Constructs a new Person.
@ -40,11 +49,16 @@ public abstract class Person extends BasicEntity {
* @param emailAddress The person's email address. * @param emailAddress The person's email address.
*/ */
public Person(String firstName, String lastName, String emailAddress) { public Person(String firstName, String lastName, String emailAddress) {
this();
this.firstName = firstName; this.firstName = firstName;
this.lastName = lastName; this.lastName = lastName;
this.emailAddress = emailAddress; this.emailAddress = emailAddress;
} }
public void assignToTeam(Team team) {
this.teams.add(team);
}
/* /*
Getters and Setters Getters and Setters
*/ */
@ -61,7 +75,8 @@ public abstract class Person extends BasicEntity {
return this.emailAddress; return this.emailAddress;
} }
public Group<?> getGroup() { @Override
return this.group; public String toString() {
return this.getFirstName() + ' ' + this.getLastName() + '[' + this.getId() + ']';
} }
} }

View File

@ -1,12 +1,6 @@
package nl.andrewlalis.teaching_assistant_assistant.model.people; package nl.andrewlalis.teaching_assistant_assistant.model.people;
import nl.andrewlalis.teaching_assistant_assistant.model.Course;
import javax.persistence.Entity; 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. * Represents a student, or someone enrolled and submitting assignments for a course.
@ -14,17 +8,6 @@ import java.util.List;
@Entity @Entity
public class Student extends Person { 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<Course> courses;
/** /**
* Default constructor for JPA. * Default constructor for JPA.
*/ */

View File

@ -1,10 +1,6 @@
package nl.andrewlalis.teaching_assistant_assistant.model.people; package nl.andrewlalis.teaching_assistant_assistant.model.people;
import nl.andrewlalis.teaching_assistant_assistant.model.Course; import javax.persistence.Entity;
import nl.andrewlalis.teaching_assistant_assistant.model.assignments.grades.SectionGrade;
import javax.persistence.*;
import java.util.List;
/** /**
* Represents a teaching assistant of a course, or in other words, a grader and administrator. * Represents a teaching assistant of a course, or in other words, a grader and administrator.
@ -12,30 +8,29 @@ import java.util.List;
@Entity @Entity
public class TeachingAssistant extends Person { public class TeachingAssistant extends Person {
/** // /**
* The list of courses which this teaching assistant is a member of. // * The list of all feedback given by a teaching assistant.
*/ // */
@ManyToMany // @OneToMany
@JoinTable( // @JoinColumn(name = "teaching_assistant_id")
name = "course_teaching_assistant", // private List<SectionGrade> sectionGrades;
joinColumns = @JoinColumn(name = "teaching_assistant_id"),
inverseJoinColumns = @JoinColumn(name = "course_id")
)
private List<Course> courses;
/**
* The list of all feedback given by a teaching assistant.
*/
@OneToMany
@JoinColumn(name = "teaching_assistant_id")
private List<SectionGrade> sectionGrades;
@Column
private TeachingAssistantRole role;
/** /**
* Default constructor for JPA. * 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<SectionGrade> getSectionGrades() {
// return this.sectionGrades;
// }
//
// public void setSectionGrades(List<SectionGrade> newSectionGrades) {
// this.sectionGrades = newSectionGrades;
// }
} }

View File

@ -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 <P> The type of members this group contains.
*/
@MappedSuperclass
public abstract class Group<P extends Person> extends BasicEntity {
/**
* The list of members in this group.
*/
@OneToMany(
fetch = FetchType.EAGER,
orphanRemoval = true
)
protected List<P> 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<P> getMembers() {
return this.members;
}
}

View File

@ -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<Student> {
/**
* Default constructor for JPA.
*/
public StudentGroup() {}
}

View File

@ -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<TeachingAssistant> {
/**
* Default constructor for JPA.
*/
public TeachingAssistantGroup() {}
}

View File

@ -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<Student> {
/**
* The list of assignment grades which this student group has received.
*/
@OneToMany(
fetch = FetchType.LAZY
)
private List<AssignmentGrade> assignmentGrades;
/**
* Default constructor for JPA.
*/
public StudentTeam() {}
@Override
public void addMember(Student person) {
this.getMembers().add(person);
}
}

View File

@ -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<TeachingAssistant> {
@Column
private TeachingAssistantRole role;
/**
* Default constructor for JPA.
*/
public TeachingAssistantTeam() {}
@Override
public void addMember(TeachingAssistant person) {
this.getMembers().add(person);
}
}

View File

@ -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 <P> The type of members this group contains.
*/
@Entity
@Inheritance(
strategy = InheritanceType.JOINED
)
public abstract class Team<P extends Person> 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<P> 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<P> 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<P> 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();
}
}

View File

@ -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, Long> {
Person findByFirstNameAndLastName(String firstName, String lastName);
}

View File

@ -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<Team, Long> {
}

View File

@ -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<Course> {
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<StudentTeam> studentTeams = this.generateStudentTeams();
List<TeachingAssistantTeam> 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<StudentTeam> generateStudentTeams() {
StudentGenerator studentGenerator = new StudentGenerator(this.getSeed());
List<StudentTeam> teams = new ArrayList<>(this.studentGroupCount);
for (int i = 0; i < this.studentGroupCount; i++) {
StudentTeam team = new StudentTeam();
List<Student> students = studentGenerator.generateList(this.studentGroupSize);
for (Student s : students) {
s.assignToTeam(team);
team.addMember(s);
}
teams.add(team);
}
return teams;
}
private List<TeachingAssistantTeam> generateTeachingAssistantTeams() {
TeachingAssistantGenerator teachingAssistantGenerator = new TeachingAssistantGenerator(this.getSeed() + 1);
List<TeachingAssistantTeam> teams = new ArrayList<>(this.teachingAssistantGroupCount);
for (int i = 0; i < this.teachingAssistantGroupCount; i++) {
TeachingAssistantTeam team = new TeachingAssistantTeam();
List<TeachingAssistant> teachingAssistants = teachingAssistantGenerator.generateList(this.teachingAssistantGroupSize);
for (TeachingAssistant t : teachingAssistants) {
t.assignToTeam(team);
team.addMember(t);
}
teams.add(team);
}
return teams;
}
}

View File

@ -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<P extends Person> extends TestDataGenerator<P> {
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);
}
}

View File

@ -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<Student> {
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));
}
}

View File

@ -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<StudentTeam, Student> {
public StudentTeamGenerator(long seed, int groupSize, boolean groupSizeVariable) {
super(seed, groupSize, groupSizeVariable);
}
@Override
protected StudentTeam getNewTeam() {
return new StudentTeam();
}
@Override
protected PersonGenerator<Student> getPersonGenerator(long seed) {
return new StudentGenerator(seed);
}
}

View File

@ -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<TeachingAssistant> {
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));
}
}

View File

@ -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<TeachingAssistantTeam, TeachingAssistant> {
public TeachingAssistantTeamGenerator(long seed, int groupSize, boolean groupSizeVariable) {
super(seed, groupSize, groupSizeVariable);
}
@Override
protected TeachingAssistantTeam getNewTeam() {
return new TeachingAssistantTeam();
}
@Override
protected PersonGenerator<TeachingAssistant> getPersonGenerator(long seed) {
return new TeachingAssistantGenerator(seed);
}
}

View File

@ -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<T extends Team, P extends Person> extends TestDataGenerator<T> {
private int groupSize;
private boolean groupSizeVariable = false;
private PersonGenerator<P> 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<P> getPersonGenerator(long seed);
@Override
public T generate() {
T team = this.getNewTeam();
List<P> members = new ArrayList<>(this.groupSize);
for (int i = 0; i < this.groupSize; i++) {
members.add(this.personGenerator.generate());
}
//team.addMembers(members);
return team;
}
}

View File

@ -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 <T> The class of objects this generator produces.
*/
public abstract class TestDataGenerator<T> {
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<T> generateList(int count) {
List<T> list = new ArrayList<>(count);
for (int i = 0; i < count; i++) {
list.add(this.generate());
}
return list;
}
public abstract T generate();
protected <C> C getRandomObjectFromArray(C[] array) {
return array[this.random.nextInt(array.length)];
}
protected Random getRandom() {
return this.random;
}
protected long getSeed() {
return this.seed;
}
}

View File

@ -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

View File

@ -0,0 +1,10 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
</body>
</html>

View File

@ -0,0 +1,14 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<h1>
Object created.
</h1>
</body>
</html>

View File

@ -8,9 +8,24 @@
<div id="content"> <div id="content">
<h1 th:text="${course.getName()}"></h1> <h1 th:text="${course.getName()}"></h1>
<h3 th:text="${course.getCode()}"></h3> <h2 th:text="${course.getCode()}"></h2>
<h3>Created on: <span th:text="${course.getCreatedOn()}"></span></h3> <h2>Created on: <span th:text="${course.getCreatedOn()}"></span></h2>
<h3>Id: <span th:text="${course.getId()}"></span></h3> <h2>Id: <span th:text="${course.getId()}"></span></h2>
<hr>
<h3>Teaching Assistant Groups (<span th:text="${course.getTeachingAssistantTeams().size()}"></span>):</h3>
<table>
<tr th:each="teachingAssistantTeam: ${course.getTeachingAssistantTeams()}">
<td th:text="${teachingAssistantTeam.getId()}"></td>
<td th:text="${teachingAssistantTeam.toString()}"></td>
</tr>
</table>
<h3>Student Groups (<span th:text="${course.getStudentTeams().size()}"></span>):</h3>
<table>
<tr th:each="studentTeam: ${course.getStudentTeams()}">
<td th:text="${studentTeam.getId()}"></td>
<td th:text="${studentTeam.toString()}"></td>
</tr>
</table>
</div> </div>
<div id="sidebar"> <div id="sidebar">