Skip to content

Commit

Permalink
Create FeedbackResponse and FeedbackResponseComment entities (#12135)
Browse files Browse the repository at this point in the history
  • Loading branch information
cedricongjh authored and samuelfangjw committed Apr 8, 2023
1 parent 453899e commit e7bb996
Show file tree
Hide file tree
Showing 8 changed files with 542 additions and 8 deletions.
9 changes: 8 additions & 1 deletion src/main/java/teammates/common/util/HibernateUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
import teammates.storage.sqlentity.Course;
import teammates.storage.sqlentity.DeadlineExtension;
import teammates.storage.sqlentity.FeedbackQuestion;
import teammates.storage.sqlentity.FeedbackResponse;
import teammates.storage.sqlentity.FeedbackResponseComment;
import teammates.storage.sqlentity.FeedbackSession;
import teammates.storage.sqlentity.Instructor;
import teammates.storage.sqlentity.Notification;
Expand All @@ -26,6 +28,7 @@
import teammates.storage.sqlentity.User;
import teammates.storage.sqlentity.questions.FeedbackNumericalScaleQuestion;
import teammates.storage.sqlentity.questions.FeedbackTextQuestion;
import teammates.storage.sqlentity.responses.FeedbackTextResponse;

/**
* Utility class for Hibernate related methods.
Expand All @@ -49,7 +52,11 @@ public final class HibernateUtil {
FeedbackQuestion.class,
FeedbackNumericalScaleQuestion.class,
FeedbackTextQuestion.class,
DeadlineExtension.class);
DeadlineExtension.class,
FeedbackResponse.class,
FeedbackTextResponse.class,
FeedbackNumericalScaleQuestion.class,
FeedbackResponseComment.class);

private HibernateUtil() {
// Utility class
Expand Down
19 changes: 19 additions & 0 deletions src/main/java/teammates/storage/sqlentity/BaseEntity.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import com.google.common.reflect.TypeToken;

import teammates.common.datatransfer.FeedbackParticipantType;
import teammates.common.util.JsonUtils;

import jakarta.persistence.AttributeConverter;
Expand Down Expand Up @@ -100,4 +101,22 @@ public T convertToEntityAttribute(String dbData) {
return JsonUtils.fromJson(dbData, new TypeToken<T>(){}.getType());
}
}

/**
* Attribute converter between FeedbackParticipantType and JSON.
*/
@Converter
public static class FeedbackParticipantTypeConverter
extends JsonConverter<FeedbackParticipantType> {

}

/**
* Attribute converter between a list of FeedbackParticipantTypes and JSON.
*/
@Converter
public static class FeedbackParticipantTypeListConverter
extends JsonConverter<List<FeedbackParticipantType>> {

}
}
19 changes: 12 additions & 7 deletions src/main/java/teammates/storage/sqlentity/FeedbackQuestion.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

import jakarta.persistence.Column;
import jakarta.persistence.Convert;
import jakarta.persistence.Converter;
import jakarta.persistence.Entity;
import jakarta.persistence.EnumType;
import jakarta.persistence.Enumerated;
Expand All @@ -24,6 +23,7 @@
import jakarta.persistence.InheritanceType;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.OneToMany;
import jakarta.persistence.Table;

/**
Expand All @@ -40,6 +40,9 @@ public abstract class FeedbackQuestion extends BaseEntity {
@JoinColumn(name = "sessionId")
private FeedbackSession feedbackSession;

@OneToMany(mappedBy = "feedbackQuestion")
private List<FeedbackResponse> feedbackResponses = new ArrayList<>();

@Column(nullable = false)
private Integer questionNumber;

Expand Down Expand Up @@ -137,6 +140,14 @@ public void setFeedbackSession(FeedbackSession feedbackSession) {
this.feedbackSession = feedbackSession;
}

public List<FeedbackResponse> getFeedbackResponses() {
return feedbackResponses;
}

public void setFeedbackResponses(List<FeedbackResponse> feedbackResponses) {
this.feedbackResponses = feedbackResponses;
}

public Integer getQuestionNumber() {
return questionNumber;
}
Expand Down Expand Up @@ -255,11 +266,5 @@ public boolean equals(Object other) {
return false;
}
}

@Converter
private static class FeedbackParticipantTypeListConverter
extends JsonConverter<List<FeedbackParticipantType>> {

}
}

179 changes: 179 additions & 0 deletions src/main/java/teammates/storage/sqlentity/FeedbackResponse.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,179 @@
package teammates.storage.sqlentity;

import java.time.Instant;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.UUID;

import org.hibernate.annotations.UpdateTimestamp;

import teammates.common.datatransfer.questions.FeedbackQuestionType;

import jakarta.persistence.Column;
import jakarta.persistence.Convert;
import jakarta.persistence.Entity;
import jakarta.persistence.Id;
import jakarta.persistence.Inheritance;
import jakarta.persistence.InheritanceType;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.OneToMany;
import jakarta.persistence.Table;

/**
* Represents a Feedback Response.
*/
@Entity
@Table(name = "FeedbackReponses")
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
public abstract class FeedbackResponse extends BaseEntity {
@Id
private UUID id;

@ManyToOne
@JoinColumn(name = "questionId")
private FeedbackQuestion feedbackQuestion;

@Column(nullable = false)
@Convert(converter = FeedbackParticipantTypeConverter.class)
private FeedbackQuestionType type;

@OneToMany(mappedBy = "feedbackResponse")
private List<FeedbackResponseComment> feedbackResponseComments = new ArrayList<>();

@Column(nullable = false)
private String giver;

@ManyToOne
@JoinColumn(name = "giverSectionId")
private Section giverSection;

@Column(nullable = false)
private String receiver;

@ManyToOne
@JoinColumn(name = "receiverSectionId")
private Section receiverSection;

@UpdateTimestamp
private Instant updatedAt;

protected FeedbackResponse() {
// required by Hibernate
}

public FeedbackResponse(
FeedbackQuestion feedbackQuestion, FeedbackQuestionType type, String giver,
Section giverSection, String receiver, Section receiverSection
) {
this.setFeedbackQuestion(feedbackQuestion);
this.setFeedbackQuestionType(type);
this.setGiver(giver);
this.setGiverSection(giverSection);
this.setReceiver(receiver);
this.setReceiverSection(receiverSection);
}

public UUID getId() {
return id;
}

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

public FeedbackQuestion getFeedbackQuestion() {
return feedbackQuestion;
}

public void setFeedbackQuestion(FeedbackQuestion feedbackQuestion) {
this.feedbackQuestion = feedbackQuestion;
}

public FeedbackQuestionType getFeedbackQuestionType() {
return type;
}

public void setFeedbackQuestionType(FeedbackQuestionType type) {
this.type = type;
}

public List<FeedbackResponseComment> getFeedbackResponseComments() {
return feedbackResponseComments;
}

public void setFeedbackResponseComments(List<FeedbackResponseComment> feedbackResponseComments) {
this.feedbackResponseComments = feedbackResponseComments;
}

public String getGiver() {
return giver;
}

public void setGiver(String giver) {
this.giver = giver;
}

public Section getGiverSection() {
return giverSection;
}

public void setGiverSection(Section giverSection) {
this.giverSection = giverSection;
}

public String getReceiver() {
return receiver;
}

public void setReceiver(String receiver) {
this.receiver = receiver;
}

public Section getReceiverSection() {
return receiverSection;
}

public void setReceiverSection(Section receiverSection) {
this.receiverSection = receiverSection;
}

public Instant getUpdatedAt() {
return updatedAt;
}

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

@Override
public List<String> getInvalidityInfo() {
return new ArrayList<>();
}

@Override
public String toString() {
return "FeedbackResponse [id=" + id + ", giver=" + giver + ", receiver=" + receiver
+ ", createdAt=" + getCreatedAt() + ", updatedAt=" + updatedAt + "]";
}

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

@Override
public boolean equals(Object other) {
if (other == null) {
return false;
} else if (this == other) {
return true;
} else if (this.getClass() == other.getClass()) {
FeedbackResponse otherResponse = (FeedbackResponse) other;
return Objects.equals(this.id, otherResponse.id);
} else {
return false;
}
}
}
Loading

0 comments on commit e7bb996

Please sign in to comment.