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

Create FeedbackResponse and FeedbackResponseComment entities #12135

Merged
Show file tree
Hide file tree
Changes from 2 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
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>> {

}
}

185 changes: 185 additions & 0 deletions src/main/java/teammates/storage/sqlentity/FeedbackResponse.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,185 @@
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.OneToOne;
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;

@OneToOne
@JoinColumn(name = "giverSectionId")
private Section giverSection;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not a OneToOne relationship. Multiple responses can have the same giverSection.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

right, changed to ManyToOne


@Column(nullable = false)
private String receiver;

@OneToOne
@JoinColumn(name = "receiverSectionId")
private Section receiverSection;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed!


@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() {
/*
* The old FeedbackResponse checks invalidity info for courseId and sessionName,
* which do not exist on this new entity.
*/
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/*
* The old FeedbackResponse checks invalidity info for courseId and sessionName,
* which do not exist on this new entity.
*/

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed

return new ArrayList<>();
}

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

@Override
public int hashCode() {
// FeedbackQuestion ID uniquely identifies a Feedback Response.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// FeedbackQuestion ID uniquely identifies a Feedback Response.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed!

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