Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#12048] V9: Cleanup and refactor #12090

Merged
merged 6 commits into from
Feb 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 4 additions & 16 deletions src/it/java/teammates/it/storage/sqlapi/CoursesDbIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,7 @@ public class CoursesDbIT extends BaseTestCaseWithSqlDatabaseAccess {
public void testCreateCourse() throws Exception {
______TS("Create course, does not exists, succeeds");

Course course = new Course.CourseBuilder("course-id")
.withName("course-name")
.withInstitute("teammates")
.build();
Course course = new Course("course-id", "course-name", null, "teammates");

coursesDb.createCourse(course);

Expand All @@ -31,10 +28,7 @@ public void testCreateCourse() throws Exception {

______TS("Create course, already exists, execption thrown");

Course identicalCourse = new Course.CourseBuilder("course-id")
.withName("course-name")
.withInstitute("teammates")
.build();
Course identicalCourse = new Course("course-id", "course-name", null, "teammates");
assertNotSame(course, identicalCourse);

assertThrows(EntityAlreadyExistsException.class, () -> coursesDb.createCourse(identicalCourse));
Expand All @@ -44,10 +38,7 @@ public void testCreateCourse() throws Exception {
public void testUpdateCourse() throws Exception {
______TS("Update course, does not exists, exception thrown");

Course course = new Course.CourseBuilder("course-id")
.withName("course-name")
.withInstitute("teammates")
.build();
Course course = new Course("course-id", "course-name", null, "teammates");

assertThrows(EntityDoesNotExistException.class, () -> coursesDb.updateCourse(course));

Expand All @@ -63,10 +54,7 @@ public void testUpdateCourse() throws Exception {
______TS("Update detached course, already exists, update successful");

// same id, different name
Course detachedCourse = new Course.CourseBuilder("course-id")
.withName("course")
.withInstitute("teammates")
.build();
Course detachedCourse = new Course("course-id", "different-name", null, "teammates");

coursesDb.updateCourse(detachedCourse);
verifyEquals(course, detachedCourse);
Expand Down
15 changes: 7 additions & 8 deletions src/it/java/teammates/it/storage/sqlapi/NotificationDbIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,13 @@ public class NotificationDbIT extends BaseTestCaseWithSqlDatabaseAccess {
@Test
public void testCreateNotification() throws EntityAlreadyExistsException, InvalidParametersException {
______TS("success: create notification that does not exist");
Notification newNotification = new Notification.NotificationBuilder()
.withStartTime(Instant.parse("2011-01-01T00:00:00Z"))
.withEndTime(Instant.parse("2099-01-01T00:00:00Z"))
.withStyle(NotificationStyle.DANGER)
.withTargetUser(NotificationTargetUser.GENERAL)
.withTitle("A deprecation note")
.withMessage("<p>Deprecation happens in three minutes</p>")
.build();
Notification newNotification = new Notification(
Instant.parse("2011-01-01T00:00:00Z"),
Instant.parse("2099-01-01T00:00:00Z"),
NotificationStyle.DANGER,
NotificationTargetUser.GENERAL,
"A deprecation note",
"<p>Deprecation happens in three minutes</p>");

notificationsDb.createNotification(newNotification);

Expand Down
2 changes: 0 additions & 2 deletions src/main/java/teammates/storage/sqlapi/CoursesDb.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ public Course getCourse(String courseId) {
public Course createCourse(Course course) throws InvalidParametersException, EntityAlreadyExistsException {
assert course != null;

course.sanitizeForSaving();
if (!course.isValid()) {
throw new InvalidParametersException(course.getInvalidityInfo());
}
Expand All @@ -59,7 +58,6 @@ public Course createCourse(Course course) throws InvalidParametersException, Ent
public Course updateCourse(Course course) throws InvalidParametersException, EntityDoesNotExistException {
assert course != null;

course.sanitizeForSaving();
if (!course.isValid()) {
throw new InvalidParametersException(course.getInvalidityInfo());
}
Expand Down
11 changes: 5 additions & 6 deletions src/main/java/teammates/storage/sqlapi/FeedbackSessionsDb.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public static FeedbackSessionsDb inst() {
*
* @return null if not found or soft-deleted.
*/
public FeedbackSession getFeedbackSession(Long fsId) {
public FeedbackSession getFeedbackSession(Integer fsId) {
assert fsId != null;

FeedbackSession fs = HibernateUtil.getSessionFactory().getCurrentSession().get(FeedbackSession.class, fsId);
Expand All @@ -47,7 +47,7 @@ public FeedbackSession getFeedbackSession(Long fsId) {
*
* @return null if not found or not soft-deleted.
*/
public FeedbackSession getSoftDeletedFeedbackSession(Long fsId) {
public FeedbackSession getSoftDeletedFeedbackSession(Integer fsId) {
assert fsId != null;

FeedbackSession fs = HibernateUtil.getSessionFactory().getCurrentSession().get(FeedbackSession.class, fsId);
Expand All @@ -71,7 +71,6 @@ public FeedbackSession updateFeedbackSession(FeedbackSession feedbackSession)
throws InvalidParametersException, EntityDoesNotExistException {
assert feedbackSession != null;

feedbackSession.sanitizeForSaving();
if (!feedbackSession.isValid()) {
throw new InvalidParametersException(feedbackSession.getInvalidityInfo());
}
Expand All @@ -88,7 +87,7 @@ public FeedbackSession updateFeedbackSession(FeedbackSession feedbackSession)
*
* @return Soft-deletion time of the feedback session.
*/
public Instant softDeleteFeedbackSession(Long fsId)
public Instant softDeleteFeedbackSession(Integer fsId)
throws EntityDoesNotExistException {
assert fsId != null;

Expand All @@ -105,7 +104,7 @@ public Instant softDeleteFeedbackSession(Long fsId)
/**
* Restores a specific soft deleted feedback session.
*/
public void restoreDeletedFeedbackSession(Long fsId)
public void restoreDeletedFeedbackSession(Integer fsId)
throws EntityDoesNotExistException {
assert fsId != null;

Expand All @@ -121,7 +120,7 @@ public void restoreDeletedFeedbackSession(Long fsId)
/**
* Deletes a feedback session.
*/
public void deleteFeedbackSession(Long fsId) {
public void deleteFeedbackSession(Integer fsId) {
assert fsId != null;

FeedbackSession fs = getFeedbackSession(fsId);
Expand Down
3 changes: 0 additions & 3 deletions src/main/java/teammates/storage/sqlapi/NotificationsDb.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ public Notification createNotification(Notification notification)
throws InvalidParametersException, EntityAlreadyExistsException {
assert notification != null;

notification.sanitizeForSaving();
if (!notification.isValid()) {
throw new InvalidParametersException(notification.getInvalidityInfo());
}
Expand All @@ -57,8 +56,6 @@ public Notification updateNotification(Notification notification)
throws InvalidParametersException, EntityDoesNotExistException {
assert notification != null;

notification.sanitizeForSaving();

if (!notification.isValid()) {
throw new InvalidParametersException(notification.getInvalidityInfo());
}
Expand Down
32 changes: 11 additions & 21 deletions src/main/java/teammates/storage/sqlentity/Account.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
public class Account extends BaseEntity {
@Id
@GeneratedValue
private Long id;
private Integer id;
samuelfangjw marked this conversation as resolved.
Show resolved Hide resolved

@Column(nullable = false)
private String googleId;
Expand All @@ -53,17 +53,17 @@ protected Account() {
}

public Account(String googleId, String name, String email) {
this.googleId = googleId;
this.name = name;
this.email = email;
this.setGoogleId(googleId);
this.setName(name);
this.setEmail(email);
this.readNotifications = new ArrayList<>();
}

public Long getId() {
public Integer getId() {
return id;
}

public void setId(Long id) {
public void setId(Integer id) {
this.id = id;
}

Expand All @@ -72,23 +72,23 @@ public String getGoogleId() {
}

public void setGoogleId(String googleId) {
this.googleId = googleId;
this.googleId = SanitizationHelper.sanitizeGoogleId(googleId);
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
this.name = SanitizationHelper.sanitizeName(name);
}

public String getEmail() {
return email;
}

public void setEmail(String email) {
this.email = email;
this.email = SanitizationHelper.sanitizeEmail(email);
}

public List<ReadNotification> getReadNotifications() {
Expand Down Expand Up @@ -126,13 +126,6 @@ public List<String> getInvalidityInfo() {
return errors;
}

@Override
public void sanitizeForSaving() {
this.googleId = SanitizationHelper.sanitizeGoogleId(googleId);
this.name = SanitizationHelper.sanitizeName(name);
this.email = SanitizationHelper.sanitizeEmail(email);
}

@Override
public boolean equals(Object other) {
if (other == null) {
Expand All @@ -141,18 +134,15 @@ public boolean equals(Object other) {
return true;
} else if (this.getClass() == other.getClass()) {
Account otherAccount = (Account) other;
return Objects.equals(this.email, otherAccount.email)
&& Objects.equals(this.name, otherAccount.name)
&& Objects.equals(this.googleId, otherAccount.googleId)
&& Objects.equals(this.id, otherAccount.id);
return Objects.equals(this.googleId, otherAccount.googleId);
} else {
return false;
}
}

@Override
public int hashCode() {
return this.getId().hashCode();
return this.getGoogleId().hashCode();
}

@Override
Expand Down
5 changes: 0 additions & 5 deletions src/main/java/teammates/storage/sqlentity/BaseEntity.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,6 @@ public abstract class BaseEntity {
// instantiate as child classes
}

/**
* Perform any sanitization that needs to be done before saving.
*/
public abstract void sanitizeForSaving();

/**
* Returns a {@code List} of strings, one string for each attribute whose
* value is invalid, or an empty {@code List} if all attributes are valid.
Expand Down
Loading