Fixed the generator and relations in the teaching assistant team.
This commit is contained in:
parent
00ec719238
commit
433702f437
|
@ -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.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.TeamRepository;
|
||||
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 java.util.List;
|
||||
|
||||
@SpringBootApplication
|
||||
public class TeachingAssistantAssistantApplication implements CommandLineRunner {
|
||||
|
||||
|
@ -31,15 +33,10 @@ public class TeachingAssistantAssistantApplication implements CommandLineRunner
|
|||
System.out.println("Running startup...");
|
||||
|
||||
// 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();
|
||||
Course c2 = courseGenerator.generate();
|
||||
|
||||
this.courseRepository.save(c1);
|
||||
System.out.println(c1.toString());
|
||||
this.courseRepository.save(c2);
|
||||
System.out.println(c2.toString());
|
||||
List<Course> courses = courseGenerator.generateList(100);
|
||||
this.courseRepository.saveAll(courses);
|
||||
|
||||
System.out.println("Course count: " + courseRepository.count());
|
||||
|
||||
|
|
|
@ -8,29 +8,14 @@ import javax.persistence.Entity;
|
|||
@Entity
|
||||
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.
|
||||
*/
|
||||
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;
|
||||
// }
|
||||
}
|
||||
|
|
|
@ -1,10 +1,14 @@
|
|||
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.TeachingAssistantRole;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.JoinColumn;
|
||||
import javax.persistence.OneToMany;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* A group of teaching assistants.
|
||||
|
@ -12,9 +16,18 @@ import javax.persistence.Entity;
|
|||
@Entity
|
||||
public class TeachingAssistantTeam extends Team<TeachingAssistant> {
|
||||
|
||||
/**
|
||||
* The role that this teaching assistant team plays.
|
||||
*/
|
||||
@Column
|
||||
private TeachingAssistantRole role;
|
||||
|
||||
@OneToMany
|
||||
@JoinColumn(
|
||||
name = "teaching_assistant_team_id"
|
||||
)
|
||||
private List<SectionGrade> sectionGrades;
|
||||
|
||||
/**
|
||||
* Default constructor for JPA.
|
||||
*/
|
||||
|
|
|
@ -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.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;
|
||||
|
||||
/**
|
||||
* Generator for a full course with TA and student teams, and all other course information.
|
||||
*/
|
||||
public class CourseGenerator extends TestDataGenerator<Course> {
|
||||
|
||||
private static final String[] COURSE_NAMES = {
|
||||
|
@ -35,33 +35,24 @@ public class CourseGenerator extends TestDataGenerator<Course> {
|
|||
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) {
|
||||
public CourseGenerator() {
|
||||
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);
|
||||
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)));
|
||||
Course course = new Course(
|
||||
this.getRandomObjectFromArray(COURSE_NAMES) + this.getRandomInteger(0, 999),
|
||||
Integer.toString(this.getRandomInteger(0, 1000000))
|
||||
);
|
||||
List<StudentTeam> studentTeams = this.generateStudentTeams();
|
||||
List<TeachingAssistantTeam> teachingAssistantTeams = this.generateTeachingAssistantTeams();
|
||||
for (StudentTeam team : studentTeams) {
|
||||
|
|
|
@ -36,6 +36,10 @@ public abstract class TestDataGenerator<T> {
|
|||
return array[this.random.nextInt(array.length)];
|
||||
}
|
||||
|
||||
protected int getRandomInteger(int lower, int upper) {
|
||||
return this.random.nextInt(upper + lower) - lower;
|
||||
}
|
||||
|
||||
protected Random getRandom() {
|
||||
return this.random;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue