Skip to content

Commit

Permalink
[TEAMMATES#12048] Add isMigrated flag to course (TEAMMATES#12063)
Browse files Browse the repository at this point in the history
  • Loading branch information
daongochieu2810 authored and hhdqirui committed Feb 10, 2023
1 parent 84b2314 commit 8383d87
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,15 @@ public final class CourseAttributes extends EntityAttributes<Course> implements
private String timeZone;
private String id;
private String institute;
private boolean isMigrated;

private CourseAttributes(String courseId) {
this.id = courseId;
this.timeZone = Const.DEFAULT_TIME_ZONE;
this.institute = Const.UNKNOWN_INSTITUTION;
this.createdAt = Instant.now();
this.deletedAt = null;
this.isMigrated = false;
}

/**
Expand All @@ -60,6 +62,7 @@ public static CourseAttributes valueOf(Course course) {
courseAttributes.createdAt = course.getCreatedAt();
}
courseAttributes.deletedAt = course.getDeletedAt();
courseAttributes.isMigrated = course.isMigrated();

return courseAttributes;
}
Expand Down Expand Up @@ -115,6 +118,14 @@ public boolean isCourseDeleted() {
return this.deletedAt != null;
}

public boolean isMigrated() {
return isMigrated;
}

public void setMigrated(boolean migrated) {
isMigrated = migrated;
}

@Override
public List<String> getInvalidityInfo() {

Expand All @@ -131,13 +142,13 @@ public List<String> getInvalidityInfo() {

@Override
public Course toEntity() {
return new Course(getId(), getName(), getTimeZone(), getInstitute(), createdAt, deletedAt);
return new Course(getId(), getName(), getTimeZone(), getInstitute(), createdAt, deletedAt, isMigrated);
}

@Override
public String toString() {
return "[" + CourseAttributes.class.getSimpleName() + "] id: " + getId() + " name: " + getName()
+ " institute: " + getInstitute() + " timeZone: " + getTimeZone();
+ " institute: " + getInstitute() + " timeZone: " + getTimeZone() + " isMigrated: " + isMigrated();
}

@Override
Expand Down Expand Up @@ -189,6 +200,7 @@ public void update(UpdateOptions updateOptions) {
updateOptions.nameOption.ifPresent(s -> name = s);
updateOptions.timeZoneOption.ifPresent(s -> timeZone = s);
updateOptions.instituteOption.ifPresent(s -> institute = s);
updateOptions.migrateOption.ifPresent(s -> isMigrated = s);
}

/**
Expand Down Expand Up @@ -229,6 +241,7 @@ public static class UpdateOptions {
private UpdateOption<String> nameOption = UpdateOption.empty();
private UpdateOption<String> timeZoneOption = UpdateOption.empty();
private UpdateOption<String> instituteOption = UpdateOption.empty();
private UpdateOption<Boolean> migrateOption = UpdateOption.empty();

private UpdateOptions(String courseId) {
assert courseId != null;
Expand All @@ -247,6 +260,7 @@ public String toString() {
+ ", name = " + nameOption
+ ", timezone = " + timeZoneOption
+ ", institute = " + instituteOption
+ ", isMigrated = " + migrateOption
+ "]";
}

Expand Down Expand Up @@ -305,6 +319,11 @@ public B withInstitute(String institute) {
return thisBuilder;
}

public B withMigrate(boolean isMigrated) {
updateOptions.migrateOption = UpdateOption.of(isMigrated);
return thisBuilder;
}

public abstract T build();

}
Expand Down
13 changes: 12 additions & 1 deletion src/main/java/teammates/storage/entity/Course.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,15 @@ public class Course extends BaseEntity {

private String institute;

private boolean isMigrated;

@SuppressWarnings("unused")
private Course() {
// required by Objectify
}

public Course(String courseId, String courseName, String courseTimeZone, String institute,
Instant createdAt, Instant deletedAt) {
Instant createdAt, Instant deletedAt, boolean isMigrated) {
this.setUniqueId(courseId);
this.setName(courseName);
if (courseTimeZone == null) {
Expand All @@ -52,6 +54,7 @@ public Course(String courseId, String courseName, String courseTimeZone, String
this.setCreatedAt(createdAt);
}
this.setDeletedAt(deletedAt);
this.setMigrated(isMigrated);
}

public String getUniqueId() {
Expand Down Expand Up @@ -102,4 +105,12 @@ public void setInstitute(String institute) {
this.institute = institute;
}

public boolean isMigrated() {
return isMigrated;
}

public void setMigrated(boolean migrated) {
isMigrated = migrated;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class CourseAttributesTest extends BaseTestCase {
@Test
public void testValueOf_withTypicalData_shouldGenerateAttributesCorrectly() {
Instant typicalInstant = Instant.now();
Course course = new Course("testId", "testName", "UTC", "institute", typicalInstant, typicalInstant);
Course course = new Course("testId", "testName", "UTC", "institute", typicalInstant, typicalInstant, false);

CourseAttributes courseAttributes = CourseAttributes.valueOf(course);

Expand All @@ -34,7 +34,7 @@ public void testValueOf_withTypicalData_shouldGenerateAttributesCorrectly() {
@Test
public void testValueOf_withInvalidTimezoneStr_shouldFallbackToDefaultTimezone() {
Instant typicalInstant = Instant.now();
Course course = new Course("testId", "testName", "invalid", "institute", typicalInstant, typicalInstant);
Course course = new Course("testId", "testName", "invalid", "institute", typicalInstant, typicalInstant, false);

CourseAttributes courseAttributes = CourseAttributes.valueOf(course);

Expand All @@ -43,7 +43,7 @@ public void testValueOf_withInvalidTimezoneStr_shouldFallbackToDefaultTimezone()

@Test
public void testValueOf_withSomeFieldsPopulatedAsNull_shouldUseDefaultValues() {
Course course = new Course("testId", "testName", "UTC", "institute", null, null);
Course course = new Course("testId", "testName", "UTC", "institute", null, null, false);
course.setCreatedAt(null);
course.setDeletedAt(null);
assertNull(course.getCreatedAt());
Expand Down Expand Up @@ -153,7 +153,9 @@ public void testIsValid() {
@Test
public void testToString() {
CourseAttributes c = generateValidCourseAttributesObject();
assertEquals("[CourseAttributes] id: valid-id-$_abc name: valid-name institute: valid-institute timeZone: UTC",
assertEquals(
"[CourseAttributes] id: valid-id-$_abc name: valid-name institute: "
+ "valid-institute timeZone: UTC isMigrated: false",
c.toString());
}

Expand Down

0 comments on commit 8383d87

Please sign in to comment.