Skip to content

Commit

Permalink
Merge branch 'release'
Browse files Browse the repository at this point in the history
# Conflicts:
#	src/main/java/teammates/common/datatransfer/attributes/InstructorAttributes.java
  • Loading branch information
wkurniawan07 committed Aug 3, 2021
2 parents c3def1a + 837960d commit 8a97db6
Show file tree
Hide file tree
Showing 11 changed files with 293 additions and 118 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package teammates.client.scripts;

import java.io.IOException;

import com.googlecode.objectify.cmd.Query;

import teammates.common.datatransfer.attributes.FeedbackQuestionAttributes;
import teammates.common.datatransfer.questions.FeedbackConstantSumDistributePointsType;
import teammates.common.datatransfer.questions.FeedbackConstantSumQuestionDetails;
import teammates.common.datatransfer.questions.FeedbackQuestionType;
import teammates.storage.entity.FeedbackQuestion;

/**
* Script to set distributePointsFor to DISTRIBUTE_ALL_UNEVENLY if forceUnevenDistribution is true.
*
* <p>See issue #8577.
*/
public class DataMigrationForConstSumForceUnevenDistribution extends
DataMigrationEntitiesBaseScript<FeedbackQuestion> {

public static void main(String[] args) throws IOException {
new DataMigrationForConstSumForceUnevenDistribution().doOperationRemotely();
}

@Override
protected Query<FeedbackQuestion> getFilterQuery() {
return ofy().load().type(FeedbackQuestion.class)
.filter("questionType =", FeedbackQuestionType.CONSTSUM.name());
}

@Override
protected boolean isPreview() {
return true;
}

@Override
protected boolean isMigrationNeeded(FeedbackQuestion question) {
FeedbackQuestionAttributes fqa = FeedbackQuestionAttributes.valueOf(question);
FeedbackConstantSumQuestionDetails fcsqd = (FeedbackConstantSumQuestionDetails) fqa.getQuestionDetails();

return fcsqd.isForceUnevenDistribution()
&& FeedbackConstantSumDistributePointsType.NONE.getDisplayedOption().equals(fcsqd.getDistributePointsFor());
}

@Override
protected void migrateEntity(FeedbackQuestion question) {
FeedbackQuestionAttributes fqa = FeedbackQuestionAttributes.valueOf(question);
FeedbackConstantSumQuestionDetails fcsqd = (FeedbackConstantSumQuestionDetails) fqa.getQuestionDetails();

fcsqd.setDistributePointsFor(
FeedbackConstantSumDistributePointsType.DISTRIBUTE_ALL_UNEVENLY.getDisplayedOption());

fqa.setQuestionDetails(fcsqd);

saveEntityDeferred(question);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package teammates.client.scripts;

import java.io.IOException;

import com.googlecode.objectify.cmd.Query;

import teammates.common.datatransfer.FeedbackParticipantType;
import teammates.storage.entity.FeedbackResponseComment;

/**
* Script to set commentGiverType as INSTRUCTOR in all comments by instructor.
*
* <p>See issue #9083</p>
*/
public class DataMigrationForNullCommentGiverType extends
DataMigrationEntitiesBaseScript<FeedbackResponseComment> {

public static void main(String[] args) throws IOException {
new DataMigrationForNullCommentGiverType().doOperationRemotely();
}

@Override
protected Query<FeedbackResponseComment> getFilterQuery() {
return ofy().load().type(FeedbackResponseComment.class)
.filter("commentGiverType =", null);
}

@Override
protected boolean isPreview() {
return true;
}

@Override
protected boolean isMigrationNeeded(FeedbackResponseComment comment) {
return comment.getCommentGiverType() == null;
}

@Override
protected void migrateEntity(FeedbackResponseComment comment) {
comment.setCommentGiverType(FeedbackParticipantType.INSTRUCTORS);
comment.setIsCommentFromFeedbackParticipant(false);

saveEntityDeferred(comment);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package teammates.client.scripts;

import java.io.IOException;

import com.googlecode.objectify.cmd.Query;

import teammates.storage.entity.CourseStudent;

/**
* Script to remove google ID of {@link CourseStudent} if it is fake google ID.
*/
public class DataMigrationForSampleGoogleIdInStudentAttributes
extends DataMigrationEntitiesBaseScript<CourseStudent> {

public static void main(String[] args) throws IOException {
DataMigrationForSampleGoogleIdInStudentAttributes migrator =
new DataMigrationForSampleGoogleIdInStudentAttributes();
migrator.doOperationRemotely();
}

@Override
protected Query<CourseStudent> getFilterQuery() {
String sampleGoogleId = "alice.b.tmms.sampleData";
// Uncomment the google ID to be removed as necessary
// sampleGoogleId = "benny.c.tmms.sampleData";
// sampleGoogleId = "charlie.d.tmms.sampleData";
// sampleGoogleId = "danny.e.tmms.sampleData";
// sampleGoogleId = "emma.f.tmms.sampleData";
// sampleGoogleId = "francis.g.tmms.sampleData";
// sampleGoogleId = "gene.h.tmms.sampleData";
// sampleGoogleId = "teammates.demo.instructor";

return ofy().load().type(CourseStudent.class)
.filter("googleId =", sampleGoogleId);
}

@Override
protected boolean isPreview() {
return true;
}

@Override
protected boolean isMigrationNeeded(CourseStudent student) throws Exception {
return true;
}

@Override
protected void migrateEntity(CourseStudent student) throws Exception {
student.setGoogleId("");

saveEntityDeferred(student);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package teammates.client.scripts;

import java.io.IOException;

import com.googlecode.objectify.cmd.Query;

import teammates.common.datatransfer.attributes.FeedbackQuestionAttributes;
import teammates.common.datatransfer.questions.FeedbackQuestionType;
import teammates.common.datatransfer.questions.FeedbackTextQuestionDetails;
import teammates.storage.entity.FeedbackQuestion;

/**
* Script to set recommendedLength as null in all text questions whose recommendedLength is 0.
*
* <p>See issue #10677</p>
*/
public class DataMigrationForTextQuestionRecommendedLength extends
DataMigrationEntitiesBaseScript<FeedbackQuestion> {

public static void main(String[] args) throws IOException {
new DataMigrationForTextQuestionRecommendedLength().doOperationRemotely();
}

@Override
protected Query<FeedbackQuestion> getFilterQuery() {
return ofy().load().type(FeedbackQuestion.class)
.filter("questionType =", FeedbackQuestionType.TEXT.name());
}

@Override
protected boolean isPreview() {
return true;
}

@Override
protected boolean isMigrationNeeded(FeedbackQuestion question) {
FeedbackQuestionAttributes fqa = FeedbackQuestionAttributes.valueOf(question);
FeedbackTextQuestionDetails ftqd = (FeedbackTextQuestionDetails) fqa.getQuestionDetails();
return ftqd.getRecommendedLength() != null && ftqd.getRecommendedLength() == 0;
}

@Override
protected void migrateEntity(FeedbackQuestion question) {
FeedbackQuestionAttributes fqa = FeedbackQuestionAttributes.valueOf(question);
FeedbackTextQuestionDetails ftqd = (FeedbackTextQuestionDetails) fqa.getQuestionDetails();
ftqd.setRecommendedLength(null);

fqa.setQuestionDetails(ftqd);

saveEntityDeferred(fqa.toEntity());
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package teammates.common.datatransfer.attributes;

import java.time.Instant;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
Expand Down Expand Up @@ -27,6 +28,8 @@ public class InstructorAttributes extends EntityAttributes<Instructor> {
private boolean isDisplayedToStudents;
private InstructorPrivileges privileges;
private transient String key;
private transient Instant createdAt;
private transient Instant updatedAt;

private InstructorAttributes(String courseId, String email) {
this.courseId = courseId;
Expand All @@ -37,6 +40,9 @@ private InstructorAttributes(String courseId, String email) {
this.isArchived = false;
this.isDisplayedToStudents = true;
this.privileges = new InstructorPrivileges(Const.InstructorPermissionRoleNames.INSTRUCTOR_PERMISSION_ROLE_COOWNER);

this.createdAt = Const.TIME_REPRESENTS_DEFAULT_TIMESTAMP;
this.updatedAt = Const.TIME_REPRESENTS_DEFAULT_TIMESTAMP;
}

/**
Expand Down Expand Up @@ -72,6 +78,12 @@ public static InstructorAttributes valueOf(Instructor instructor) {
instructorAttributes.privileges =
JsonUtils.fromJson(instructor.getInstructorPrivilegesAsText(), InstructorPrivileges.class);
}
if (instructor.getCreatedAt() != null) {
instructorAttributes.createdAt = instructor.getCreatedAt();
}
if (instructor.getUpdatedAt() != null) {
instructorAttributes.updatedAt = instructor.getUpdatedAt();
}

return instructorAttributes;
}
Expand All @@ -89,6 +101,8 @@ public InstructorAttributes getCopy() {
instructorAttributes.isArchived = isArchived;
instructorAttributes.isDisplayedToStudents = isDisplayedToStudents;
instructorAttributes.privileges = privileges;
instructorAttributes.createdAt = createdAt;
instructorAttributes.updatedAt = updatedAt;

return instructorAttributes;
}
Expand Down Expand Up @@ -318,6 +332,22 @@ public void setRole(String role) {
this.role = role;
}

public Instant getCreatedAt() {
return createdAt;
}

public Instant getUpdatedAt() {
return updatedAt;
}

public void setCreatedAt(Instant createdAt) {
this.createdAt = createdAt;
}

public void setUpdatedAt(Instant updatedAt) {
this.updatedAt = updatedAt;
}

/**
* Updates with {@link UpdateOptionsWithEmail}.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ public enum FeedbackQuestionType {

CONSTSUM(FeedbackConstantSumQuestionDetails.class, FeedbackConstantSumResponseDetails.class),

// TODO: dummy enum, need to migrate CONSTSUM to either CONSTSUM_OPTIONS or CONSTSUM_RECIPIENTS
// In the back-end, only CONSTSUM and not its branched versions is recognized as a valid question type.
// The branching here is done to make it simpler for the front-end to render the right items.
CONSTSUM_OPTIONS(FeedbackConstantSumQuestionDetails.class, FeedbackConstantSumResponseDetails.class),
CONSTSUM_RECIPIENTS(FeedbackConstantSumQuestionDetails.class, FeedbackConstantSumResponseDetails.class),

Expand Down
39 changes: 39 additions & 0 deletions src/main/java/teammates/storage/entity/Instructor.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
package teammates.storage.entity;

import java.security.SecureRandom;
import java.time.Instant;

import com.googlecode.objectify.annotation.Entity;
import com.googlecode.objectify.annotation.Id;
import com.googlecode.objectify.annotation.Index;
import com.googlecode.objectify.annotation.OnSave;
import com.googlecode.objectify.annotation.Translate;
import com.googlecode.objectify.annotation.Unindex;

/**
Expand Down Expand Up @@ -54,6 +57,12 @@ public class Instructor extends BaseEntity {
@Unindex
private String instructorPrivilegesAsText;

@Translate(InstantTranslatorFactory.class)
private Instant createdAt;

@Translate(InstantTranslatorFactory.class)
private Instant updatedAt;

@SuppressWarnings("unused")
private Instructor() {
// required by Objectify
Expand All @@ -74,6 +83,7 @@ public Instructor(String instructorGoogleId, String courseId, boolean isArchived
// setId should be called after setting email and courseId
this.setUniqueId(generateId(this.getEmail(), this.getCourseId()));
this.setRegistrationKey(generateRegistrationKey());
this.setCreatedAt(Instant.now());
}

/**
Expand Down Expand Up @@ -208,4 +218,33 @@ public String getInstructorPrivilegesAsText() {
public void setInstructorPrivilegeAsText(String instructorPrivilegesAsText) {
this.instructorPrivilegesAsText = instructorPrivilegesAsText;
}

public Instant getCreatedAt() {
return createdAt;
}

/**
* Sets the createdAt timestamp.
*/
public void setCreatedAt(Instant created) {
this.createdAt = created;
setLastUpdate(created);
}

public Instant getUpdatedAt() {
return updatedAt;
}

public void setLastUpdate(Instant updatedAt) {
this.updatedAt = updatedAt;
}

/**
* Updates the updatedAt timestamp when saving.
*/
@OnSave
public void updateLastUpdateTimestamp() {
this.setLastUpdate(Instant.now());
}

}
3 changes: 0 additions & 3 deletions src/main/java/teammates/ui/output/FeedbackQuestionData.java
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,6 @@ public FeedbackQuestionData(FeedbackQuestionAttributes feedbackQuestionAttribute
}

if (this.questionType == FeedbackQuestionType.CONSTSUM) {
// TODO: remove the abstraction after migration
// need to migrate CONSTSUM to either CONSTSUM_OPTIONS or CONSTSUM_RECIPIENTS
// correct to either CONSTSUM_OPTIONS or CONSTSUM_RECIPIENTS
FeedbackConstantSumQuestionDetails constantSumQuestionDetails =
(FeedbackConstantSumQuestionDetails) this.questionDetails;
this.questionType = constantSumQuestionDetails.isDistributeToRecipients()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ public FeedbackQuestionDetails getQuestionDetails() {
FeedbackQuestionDetails details =
JsonUtils.fromJson(JsonUtils.toCompactJson(questionDetails), questionType.getQuestionDetailsClass());
details.setQuestionText(questionBrief);
// TODO remove this after migrate CONSTSUM to either CONSTSUM_OPTIONS or CONSTSUM_RECIPIENTS
if (questionType == FeedbackQuestionType.CONSTSUM_OPTIONS
|| questionType == FeedbackQuestionType.CONSTSUM_RECIPIENTS) {
details.setQuestionType(FeedbackQuestionType.CONSTSUM);
Expand Down
Loading

0 comments on commit 8a97db6

Please sign in to comment.