From a11fb25b2d88987ba51b1d6feadb0ad7393b82a6 Mon Sep 17 00:00:00 2001 From: Isabelle Robin Date: Mon, 3 Feb 2020 16:25:12 -0500 Subject: [PATCH] Use only id autogenerated --- .../com/crecerjuntos/model/Achievement.java | 34 ++++++++--------- .../java/com/crecerjuntos/model/Student.java | 38 +++++++------------ .../services/AchievementServiceTest.java | 1 - .../services/StudentServiceTest.java | 2 +- .../crecerjuntos/services/TestServices.java | 2 +- .../front/util/LoginServices.java | 3 +- .../front/util/ProgressServices.java | 4 -- 7 files changed, 32 insertions(+), 52 deletions(-) diff --git a/back/src/main/java/com/crecerjuntos/model/Achievement.java b/back/src/main/java/com/crecerjuntos/model/Achievement.java index ad0b43b..43f8d2b 100644 --- a/back/src/main/java/com/crecerjuntos/model/Achievement.java +++ b/back/src/main/java/com/crecerjuntos/model/Achievement.java @@ -27,46 +27,44 @@ public int hashCode() { /** Unique, private & generated id */ @Id @GeneratedValue(strategy = GenerationType.AUTO) - private final Long id; + private Long id; @ManyToOne @JoinColumn(name = "student_id", nullable = false) - private final Student student; + private Student student; /** Session id */ - private final String sessionId; + private String sessionId; /** Timestamp of the achievement */ - private final Date timestamp; + private Date timestamp; /** Name of the current exercise */ @Column(nullable = false) - private final String exercise; + private String exercise; /** Level of the current exercise, default : 1 */ @Column(columnDefinition = "integer default 1") - private final int level; + private int level; /** Progression should be between 0 and 100 */ - private final double progress; + private double progress; /** Score, should be between 0 and 100 */ - private final int score; + private int score; public Achievement() { - this(0L, new Student(), "0", Date.valueOf(LocalDate.now()), "No exercise", 0, 0, 0); + this(new Student(), "0", Date.valueOf(LocalDate.now()), "No exercise", 0, 0, 0); } public Achievement( - final Long id, - final Student student, - final String sessionId, - final Date timestamp, - final String exercise, - final int level, - final double progress, - final int score) { - this.id = id; + Student student, + String sessionId, + Date timestamp, + String exercise, + int level, + double progress, + int score) { this.student = student; this.sessionId = sessionId; this.timestamp = timestamp; diff --git a/back/src/main/java/com/crecerjuntos/model/Student.java b/back/src/main/java/com/crecerjuntos/model/Student.java index 2ab24c7..e784049 100644 --- a/back/src/main/java/com/crecerjuntos/model/Student.java +++ b/back/src/main/java/com/crecerjuntos/model/Student.java @@ -11,70 +11,58 @@ public class Student implements BaseEntity { public static final String DEFAULT_NAME = "Anonymous"; public static final String DEFAULT_MAIL = "anonymous@gmail.com"; public static final Student DEFAULT = - new Student(1L, DEFAULT_NAME, DEFAULT_MAIL, "", Section.DEFAULT); + new Student(DEFAULT_NAME, DEFAULT_MAIL, "", Section.DEFAULT); /** Private generated id */ @Id @GeneratedValue(strategy = GenerationType.AUTO) - private final Long id; + private Long id; /** Public first name */ @Column(nullable = false) - private final String name; + private String name; /** Email address */ @Column(unique = true, nullable = false) - private final String mail; + private String mail; /** Password */ @Column(nullable = false) - private final String password; + private String password; /** Id of the associated section */ @Enumerated(EnumType.STRING) - private final Section section; + private Section section; public Student() { - this(0L, DEFAULT_NAME, Section.DEFAULT); + this(DEFAULT_NAME, DEFAULT_MAIL, "", Section.DEFAULT); } public Student( - final Long id, - final String name, - final String mail, - final String password, - final Section section) { - this.id = id; + String name, + String mail, + String password, + Section section) { this.name = name; this.mail = mail; this.password = password; this.section = section; } - public Student(final Long id, final String name, final Section section) { - this.id = id; + public Student(final String name, final Section section) { this.name = name; this.mail = DEFAULT_MAIL; this.password = null; this.section = section; } - public Student(final Long id, final String name) { - this.id = id; + public Student(final String name) { this.name = name; this.mail = DEFAULT_MAIL; this.password = null; this.section = Section.DEFAULT; } - public Student(final Long id) { - this.id = id; - this.name = DEFAULT_NAME; - this.mail = DEFAULT_MAIL; - this.password = null; - this.section = Section.DEFAULT; - } - @Override public boolean equals(Object o) { if (this == o) return true; diff --git a/back/src/test/java/com/crecerjuntos/services/AchievementServiceTest.java b/back/src/test/java/com/crecerjuntos/services/AchievementServiceTest.java index 78f8aa6..f7803b9 100644 --- a/back/src/test/java/com/crecerjuntos/services/AchievementServiceTest.java +++ b/back/src/test/java/com/crecerjuntos/services/AchievementServiceTest.java @@ -19,7 +19,6 @@ public void create() throws Exception{ double progress = TestServices.random.nextInt(100); Achievement achievement = new Achievement( - TestServices.random.nextLong(), student, "session", date, diff --git a/back/src/test/java/com/crecerjuntos/services/StudentServiceTest.java b/back/src/test/java/com/crecerjuntos/services/StudentServiceTest.java index 4f29807..4fb9fd8 100644 --- a/back/src/test/java/com/crecerjuntos/services/StudentServiceTest.java +++ b/back/src/test/java/com/crecerjuntos/services/StudentServiceTest.java @@ -32,7 +32,7 @@ public void setUp() { studentService = new StudentService(studentRepository); // Add a test student in repository - Student testStudent = new Student(1234L, "Pedro test", Section.DEFAULT); + Student testStudent = new Student("Pedro test", Section.DEFAULT); List studentList = new ArrayList<>(); studentList.add(testStudent); diff --git a/back/src/test/java/com/crecerjuntos/services/TestServices.java b/back/src/test/java/com/crecerjuntos/services/TestServices.java index aead209..56abee1 100644 --- a/back/src/test/java/com/crecerjuntos/services/TestServices.java +++ b/back/src/test/java/com/crecerjuntos/services/TestServices.java @@ -19,7 +19,7 @@ public class TestServices { public static final Student generateTestStudent() throws Exception{ String mail = "student.test" + UUID.randomUUID() + "@gmail.com"; Student student = - new Student(random.nextLong(), "Test Student", mail, "password", Section.DEFAULT); + new Student("Test Student", mail, "password", Section.DEFAULT); authoringServices.add(student); return studentAccess.byMail(mail); } diff --git a/front/src/main/java/com/crecerjuntos/front/util/LoginServices.java b/front/src/main/java/com/crecerjuntos/front/util/LoginServices.java index 521955e..d9c7c62 100644 --- a/front/src/main/java/com/crecerjuntos/front/util/LoginServices.java +++ b/front/src/main/java/com/crecerjuntos/front/util/LoginServices.java @@ -25,8 +25,7 @@ public static Student create( String mail, final String username, final String password, final String section) throws DataBaseException { // Create student - long id = random.nextLong(); - Student student = new Student(id, username, mail, password, Section.fromString(section)); + Student student = new Student(username, mail, password, Section.fromString(section)); // Register new student in database logger.info("Create Student User {}", student); diff --git a/front/src/main/java/com/crecerjuntos/front/util/ProgressServices.java b/front/src/main/java/com/crecerjuntos/front/util/ProgressServices.java index 2173114..b4dc511 100644 --- a/front/src/main/java/com/crecerjuntos/front/util/ProgressServices.java +++ b/front/src/main/java/com/crecerjuntos/front/util/ProgressServices.java @@ -25,12 +25,10 @@ public class ProgressServices { private static final IAchievementAccess achievementAccess = new AchievementService(); public static void start(final Exercise exercise, final int level) throws DataBaseException { - long id = random.nextLong(); VaadinSession session = UI.getCurrent().getSession(); Student student = LoginServices.getStudent(); Achievement achievement = new Achievement( - id, student, session.getSession().getId(), new java.sql.Date(Calendar.getInstance().getTime().getTime()), @@ -44,12 +42,10 @@ public static void start(final Exercise exercise, final int level) throws DataBa } public static void end(final Exercise exercise, final int level, final int score) throws DataBaseException{ - long id = random.nextLong(); VaadinSession session = UI.getCurrent().getSession(); Student student = LoginServices.getStudent(); Achievement achievement = new Achievement( - id, student, session.getSession().getId(), new java.sql.Date(Calendar.getInstance().getTime().getTime()),