Fixed the generator and relations in the teaching assistant team.

This commit is contained in:
Andrew Lalis 2019-04-11 17:36:05 +02:00 committed by andrewlalis
parent 00ec719238
commit 433702f437
5 changed files with 33 additions and 43 deletions

View File

@ -2,14 +2,16 @@ 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.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.model.repositories.PersonRepository;
import nl.andrewlalis.teaching_assistant_assistant.model.repositories.TeamRepository;
import nl.andrewlalis.teaching_assistant_assistant.util.CourseGenerator; 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 java.util.List;
@SpringBootApplication @SpringBootApplication
public class TeachingAssistantAssistantApplication implements CommandLineRunner { public class TeachingAssistantAssistantApplication implements CommandLineRunner {
@ -31,15 +33,10 @@ public class TeachingAssistantAssistantApplication implements CommandLineRunner
System.out.println("Running startup..."); System.out.println("Running startup...");
// Generate some example courses. // Generate some example courses.
CourseGenerator courseGenerator = new CourseGenerator(0, 3, 2, 10, 3, this.courseRepository, teamRepository, personRepository); CourseGenerator courseGenerator = new CourseGenerator(0, 3, 2, 10, 3);
Course c1 = courseGenerator.generate(); List<Course> courses = courseGenerator.generateList(100);
Course c2 = courseGenerator.generate(); this.courseRepository.saveAll(courses);
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());

View File

@ -8,29 +8,14 @@ import javax.persistence.Entity;
@Entity @Entity
public class TeachingAssistant extends Person { public class TeachingAssistant extends Person {
// /**
// * The list of all feedback given by a teaching assistant.
// */
// @OneToMany
// @JoinColumn(name = "teaching_assistant_id")
// private List<SectionGrade> sectionGrades;
/** /**
* Default constructor for JPA. * Default constructor for JPA.
*/ */
protected TeachingAssistant() { protected TeachingAssistant() {
// this.sectionGrades = new ArrayList<>();
} }
public TeachingAssistant(String firstName, String lastName, String emailAddress) { public TeachingAssistant(String firstName, String lastName, String emailAddress) {
super(firstName, lastName, emailAddress); super(firstName, lastName, emailAddress);
} }
// public List<SectionGrade> getSectionGrades() {
// return this.sectionGrades;
// }
//
// public void setSectionGrades(List<SectionGrade> newSectionGrades) {
// this.sectionGrades = newSectionGrades;
// }
} }

View File

@ -1,10 +1,14 @@
package nl.andrewlalis.teaching_assistant_assistant.model.people.teams; package nl.andrewlalis.teaching_assistant_assistant.model.people.teams;
import nl.andrewlalis.teaching_assistant_assistant.model.assignments.grades.SectionGrade;
import nl.andrewlalis.teaching_assistant_assistant.model.people.TeachingAssistant; import nl.andrewlalis.teaching_assistant_assistant.model.people.TeachingAssistant;
import nl.andrewlalis.teaching_assistant_assistant.model.people.TeachingAssistantRole; import nl.andrewlalis.teaching_assistant_assistant.model.people.TeachingAssistantRole;
import javax.persistence.Column; import javax.persistence.Column;
import javax.persistence.Entity; import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.OneToMany;
import java.util.List;
/** /**
* A group of teaching assistants. * A group of teaching assistants.
@ -12,9 +16,18 @@ import javax.persistence.Entity;
@Entity @Entity
public class TeachingAssistantTeam extends Team<TeachingAssistant> { public class TeachingAssistantTeam extends Team<TeachingAssistant> {
/**
* The role that this teaching assistant team plays.
*/
@Column @Column
private TeachingAssistantRole role; private TeachingAssistantRole role;
@OneToMany
@JoinColumn(
name = "teaching_assistant_team_id"
)
private List<SectionGrade> sectionGrades;
/** /**
* Default constructor for JPA. * Default constructor for JPA.
*/ */

View File

@ -5,13 +5,13 @@ 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.TeachingAssistant;
import nl.andrewlalis.teaching_assistant_assistant.model.people.teams.StudentTeam; 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.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.ArrayList;
import java.util.List; import java.util.List;
/**
* Generator for a full course with TA and student teams, and all other course information.
*/
public class CourseGenerator extends TestDataGenerator<Course> { public class CourseGenerator extends TestDataGenerator<Course> {
private static final String[] COURSE_NAMES = { private static final String[] COURSE_NAMES = {
@ -35,33 +35,24 @@ public class CourseGenerator extends TestDataGenerator<Course> {
private int teachingAssistantGroupCount = 10; private int teachingAssistantGroupCount = 10;
private int teachingAssistantGroupSize = 2; private int teachingAssistantGroupSize = 2;
private CourseRepository courseRepository; public CourseGenerator() {
private TeamRepository teamRepository;
private PersonRepository personRepository;
public CourseGenerator(CourseRepository courseRepository, TeamRepository teamRepository, PersonRepository personRepository) {
super(0); 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) { public CourseGenerator(long seed, int studentGroupSize, int teachingAssistantGroupSize, int studentGroupCount, int teachingAssistantGroupCount) {
super(seed); super(seed);
this.studentGroupSize = studentGroupSize; this.studentGroupSize = studentGroupSize;
this.teachingAssistantGroupSize = teachingAssistantGroupSize; this.teachingAssistantGroupSize = teachingAssistantGroupSize;
this.studentGroupCount = studentGroupCount; this.studentGroupCount = studentGroupCount;
this.teachingAssistantGroupCount = teachingAssistantGroupCount; this.teachingAssistantGroupCount = teachingAssistantGroupCount;
this.courseRepository = courseRepository;
this.teamRepository = teamRepository;
this.personRepository = personRepository;
} }
@Override @Override
public Course generate() { public Course generate() {
Course course = new Course(this.getRandomObjectFromArray(COURSE_NAMES), Integer.toString(this.getRandom().nextInt(1000))); Course course = new Course(
this.getRandomObjectFromArray(COURSE_NAMES) + this.getRandomInteger(0, 999),
Integer.toString(this.getRandomInteger(0, 1000000))
);
List<StudentTeam> studentTeams = this.generateStudentTeams(); List<StudentTeam> studentTeams = this.generateStudentTeams();
List<TeachingAssistantTeam> teachingAssistantTeams = this.generateTeachingAssistantTeams(); List<TeachingAssistantTeam> teachingAssistantTeams = this.generateTeachingAssistantTeams();
for (StudentTeam team : studentTeams) { for (StudentTeam team : studentTeams) {

View File

@ -36,6 +36,10 @@ public abstract class TestDataGenerator<T> {
return array[this.random.nextInt(array.length)]; return array[this.random.nextInt(array.length)];
} }
protected int getRandomInteger(int lower, int upper) {
return this.random.nextInt(upper + lower) - lower;
}
protected Random getRandom() { protected Random getRandom() {
return this.random; return this.random;
} }