Skip to content

Commit

Permalink
Update getters and setters and fix lint
Browse files Browse the repository at this point in the history
  • Loading branch information
domlimm committed Mar 31, 2024
1 parent 424b2ab commit a096fea
Show file tree
Hide file tree
Showing 20 changed files with 95 additions and 68 deletions.
2 changes: 1 addition & 1 deletion src/main/java/teammates/sqllogic/core/CoursesLogic.java
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ public static void sortById(List<Course> courses) {

/**
* Gets the course associated with a feedback response comment.
*
*
* @param id The identifier of a feedback response comment.
* @return A course.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@
import teammates.common.exception.EntityDoesNotExistException;
import teammates.common.exception.InvalidParametersException;
import teammates.storage.sqlapi.FeedbackResponseCommentsDb;
import teammates.storage.sqlentity.Course;
import teammates.storage.sqlentity.FeedbackQuestion;
import teammates.storage.sqlentity.FeedbackResponse;
import teammates.storage.sqlentity.FeedbackResponseComment;
import teammates.storage.sqlentity.Student;
import teammates.storage.sqlentity.Course;
import teammates.storage.sqlentity.User;
import teammates.ui.request.FeedbackResponseCommentUpdateRequest;

Expand Down Expand Up @@ -125,7 +125,7 @@ public FeedbackResponseComment updateFeedbackResponseComment(Long frcId,
if (comment == null) {
throw new EntityDoesNotExistException("Trying to update a feedback response comment that does not exist.");
}

Course course = coursesLogic.getCourseForFeedbackResponseCommentId(frcId);
User lastEditor = usersLogic.getUserByEmail(course.getId(), updaterEmail);
comment.setCommentText(updateRequest.getCommentText());
Expand Down Expand Up @@ -222,19 +222,19 @@ private boolean checkIsVisibleToUserTeam(Student student, Set<String> studentsEm
&& relatedQuestion.getRecipientType() == FeedbackParticipantType.TEAMS
&& checkIsResponseCommentVisibleTo(relatedQuestion, relatedComment,
FeedbackParticipantType.RECEIVER)
&& response.getRecipient().equals(student.getTeamName());
&& response.getRecipient().getTeam().getName().equals(student.getTeamName());

boolean isUserInResponseGiverTeamAndRelatedResponseCommentVisibleToGiversTeamMembers =
(relatedQuestion.getGiverType() == FeedbackParticipantType.TEAMS
|| checkIsResponseCommentVisibleTo(relatedQuestion, relatedComment,
FeedbackParticipantType.OWN_TEAM_MEMBERS))
&& (studentsEmailInTeam.contains(response.getGiver())
|| isUserStudent && student.getTeamName().equals(response.getGiver()));
&& (studentsEmailInTeam.contains(response.getGiver().getEmail())
|| isUserStudent && student.getTeamName().equals(response.getGiver().getTeam().getName()));

boolean isUserInResponseRecipientTeamAndRelatedResponseCommentVisibleToRecipientsTeamMembers =
checkIsResponseCommentVisibleTo(relatedQuestion, relatedComment,
FeedbackParticipantType.RECEIVER_TEAM_MEMBERS)
&& studentsEmailInTeam.contains(response.getRecipient());
&& studentsEmailInTeam.contains(response.getRecipient().getEmail());

return isUserInResponseRecipientTeamAndRelatedResponseCommentVisibleToRecipients
|| isUserInResponseGiverTeamAndRelatedResponseCommentVisibleToGiversTeamMembers
Expand All @@ -250,13 +250,14 @@ isUserInstructor && checkIsResponseCommentVisibleTo(relatedQuestion, relatedComm
FeedbackParticipantType.INSTRUCTORS);

boolean isUserResponseRecipientAndRelatedResponseCommentVisibleToRecipients =
response.getRecipient().equals(userEmail) && checkIsResponseCommentVisibleTo(relatedQuestion,
response.getRecipient().getEmail().equals(userEmail)
&& checkIsResponseCommentVisibleTo(relatedQuestion,
relatedComment, FeedbackParticipantType.RECEIVER);

boolean isUserResponseGiverAndRelatedResponseCommentVisibleToGivers =
response.getGiver().equals(userEmail) && isVisibleToGiver;
response.getGiver().getEmail().equals(userEmail) && isVisibleToGiver;

boolean isUserRelatedResponseCommentGiver = relatedComment.getGiver().equals(userEmail);
boolean isUserRelatedResponseCommentGiver = relatedComment.getGiver().getEmail().equals(userEmail);

boolean isUserStudentAndRelatedResponseCommentVisibleToStudents =
isUserStudent && checkIsResponseCommentVisibleTo(relatedQuestion,
Expand Down Expand Up @@ -290,7 +291,7 @@ public boolean checkIsNameVisibleToUser(FeedbackResponseComment comment, Feedbac
}

//comment giver can always see
if (userEmail.equals(comment.getGiver())) {
if (userEmail.equals(comment.getGiver().getEmail())) {
return true;
}

Expand All @@ -300,12 +301,12 @@ public boolean checkIsNameVisibleToUser(FeedbackResponseComment comment, Feedbac
private boolean checkIsFeedbackParticipantNameVisibleToUser(FeedbackResponse response,
String userEmail, SqlCourseRoster roster, List<FeedbackParticipantType> showNameTo) {
String responseGiverTeam = "giverTeam";
if (roster.getStudentForEmail(response.getGiver()) != null) {
responseGiverTeam = roster.getStudentForEmail(response.getGiver()).getTeamName();
if (roster.getStudentForEmail(response.getGiver().getEmail()) != null) {
responseGiverTeam = roster.getStudentForEmail(response.getGiver().getEmail()).getTeamName();
}
String responseRecipientTeam = "recipientTeam";
if (roster.getStudentForEmail(response.getRecipient()) != null) {
responseRecipientTeam = roster.getStudentForEmail(response.getRecipient()).getTeamName();
if (roster.getStudentForEmail(response.getRecipient().getEmail()) != null) {
responseRecipientTeam = roster.getStudentForEmail(response.getRecipient().getEmail()).getTeamName();
}
String currentUserTeam = "currentUserTeam";
if (roster.getStudentForEmail(userEmail) != null) {
Expand All @@ -324,7 +325,7 @@ private boolean checkIsFeedbackParticipantNameVisibleToUser(FeedbackResponse res
}
break;
case RECEIVER:
if (userEmail.equals(response.getRecipient())) {
if (userEmail.equals(response.getRecipient().getEmail())) {
return true;
}
break;
Expand All @@ -339,7 +340,7 @@ private boolean checkIsFeedbackParticipantNameVisibleToUser(FeedbackResponse res
}
break;
case GIVER:
if (userEmail.equals(response.getGiver())) {
if (userEmail.equals(response.getGiver().getEmail())) {
return true;
}
break;
Expand Down
44 changes: 24 additions & 20 deletions src/main/java/teammates/sqllogic/core/FeedbackResponsesLogic.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@
import teammates.storage.sqlentity.Section;
import teammates.storage.sqlentity.Student;
import teammates.storage.sqlentity.Team;
import teammates.storage.sqlentity.responses.FeedbackMissingResponse;
import teammates.storage.sqlentity.User;
import teammates.storage.sqlentity.responses.FeedbackMissingResponse;
import teammates.storage.sqlentity.responses.FeedbackRankRecipientsResponse;

/**
Expand Down Expand Up @@ -284,7 +284,7 @@ public void deleteFeedbackResponsesForCourseCascade(String courseId, String enti

/**
* Gets all responses given by a user for a course.
*
*
* @param courseId the identifier of a course.
* @param giver the email of the giver.
*/
Expand All @@ -300,7 +300,7 @@ public List<FeedbackResponse> getFeedbackResponsesFromGiverForCourse(

/**
* Gets all responses received by a user for a course.
*
*
* @param courseId the identifier of a course.
* @param recipient the email of the recipient.
*/
Expand Down Expand Up @@ -813,10 +813,12 @@ private List<FeedbackResponse> buildMissingResponses(
for (FeedbackResponse existingResponse : existingResponses) {
Map<String, Set<String>> currGiverRecipientMap =
questionCompleteGiverRecipientMap.get(existingResponse.getFeedbackQuestion());
if (!currGiverRecipientMap.containsKey(existingResponse.getGiver())) {
if (!currGiverRecipientMap.containsKey(existingResponse.getGiver().getEmail())) {
continue;
}
currGiverRecipientMap.get(existingResponse.getGiver()).remove(existingResponse.getRecipient());
currGiverRecipientMap
.get(existingResponse.getGiver().getEmail())
.remove(existingResponse.getRecipient().getEmail());
}

List<FeedbackResponse> missingResponses = new ArrayList<>();
Expand All @@ -842,10 +844,12 @@ private List<FeedbackResponse> buildMissingResponses(
continue;
}

User giver = usersLogic.getUserByEmail(correspondingQuestion.getCourseId(), giverIdentifier);
User recipient = usersLogic.getUserByEmail(correspondingQuestion.getCourseId(), recipientIdentifier);
FeedbackResponse missingResponse = new FeedbackMissingResponse(
correspondingQuestion,
giverIdentifier, giverInfo.getSectionName(),
recipientIdentifier, recipientInfo.getSectionName());
giver, giverInfo.getSectionName(),
recipient, recipientInfo.getSectionName());

// check visibility of the missing response
boolean isVisibleResponse = isResponseVisibleForUser(
Expand Down Expand Up @@ -886,11 +890,11 @@ public boolean isNameVisibleToUser(
// Early return if user is giver
if (question.getGiverType() == FeedbackParticipantType.TEAMS) {
// if response is given by team, then anyone in the team can see the response
if (roster.isStudentInTeam(userEmail, response.getGiver())) {
if (roster.isStudentInTeam(userEmail, response.getGiver().getEmail())) {
return true;
}
} else {
if (response.getGiver().equals(userEmail)) {
if (response.getGiver().getEmail().equals(userEmail)) {
return true;
}
}
Expand All @@ -915,33 +919,33 @@ private boolean isFeedbackParticipantNameVisibleToUser(
case OWN_TEAM_MEMBERS:
case OWN_TEAM_MEMBERS_INCLUDING_SELF:
// Refers to Giver's Team Members
if (roster.isStudentsInSameTeam(response.getGiver(), userEmail)) {
if (roster.isStudentsInSameTeam(response.getGiver().getEmail(), userEmail)) {
return true;
}
break;
case RECEIVER:
// Response to team
if (question.getRecipientType().isTeam()) {
if (roster.isStudentInTeam(userEmail, response.getRecipient())) {
if (roster.isStudentInTeam(userEmail, response.getRecipient().getEmail())) {
// this is a team name
return true;
}
break;
// Response to individual
} else if (response.getRecipient().equals(userEmail)) {
} else if (response.getRecipient().getEmail().equals(userEmail)) {
return true;
} else {
break;
}
case RECEIVER_TEAM_MEMBERS:
// Response to team; recipient = teamName
if (question.getRecipientType().isTeam()) {
if (roster.isStudentInTeam(userEmail, response.getRecipient())) {
if (roster.isStudentInTeam(userEmail, response.getRecipient().getEmail())) {
// this is a team name
return true;
}
break;
} else if (roster.isStudentsInSameTeam(response.getRecipient(), userEmail)) {
} else if (roster.isStudentsInSameTeam(response.getRecipient().getEmail(), userEmail)) {
// Response to individual
return true;
}
Expand All @@ -967,26 +971,26 @@ private boolean isResponseVisibleForUser(

boolean isVisibleResponse = false;
if (isInstructor && relatedQuestion.isResponseVisibleTo(FeedbackParticipantType.INSTRUCTORS)
|| response.getRecipient().equals(userEmail)
|| response.getRecipient().getEmail().equals(userEmail)
&& relatedQuestion.isResponseVisibleTo(FeedbackParticipantType.RECEIVER)
|| response.getGiver().equals(userEmail)
|| response.getGiver().getEmail().equals(userEmail)
|| !isInstructor && relatedQuestion.isResponseVisibleTo(FeedbackParticipantType.STUDENTS)) {
isVisibleResponse = true;
} else if (studentsEmailInTeam != null && !isInstructor) {
if ((relatedQuestion.getRecipientType() == FeedbackParticipantType.TEAMS
|| relatedQuestion.getRecipientType() == FeedbackParticipantType.TEAMS_IN_SAME_SECTION
|| relatedQuestion.getRecipientType() == FeedbackParticipantType.TEAMS_EXCLUDING_SELF)
&& relatedQuestion.isResponseVisibleTo(FeedbackParticipantType.RECEIVER)
&& response.getRecipient().equals(student.getTeamName())) {
&& response.getRecipient().getEmail().equals(student.getTeamName())) {
isVisibleResponse = true;
} else if (relatedQuestion.getGiverType() == FeedbackParticipantType.TEAMS
&& response.getGiver().equals(student.getTeamName())) {
&& response.getGiver().getEmail().equals(student.getTeamName())) {
isVisibleResponse = true;
} else if (relatedQuestion.isResponseVisibleTo(FeedbackParticipantType.OWN_TEAM_MEMBERS)
&& studentsEmailInTeam.contains(response.getGiver())) {
&& studentsEmailInTeam.contains(response.getGiver().getEmail())) {
isVisibleResponse = true;
} else if (relatedQuestion.isResponseVisibleTo(FeedbackParticipantType.RECEIVER_TEAM_MEMBERS)
&& studentsEmailInTeam.contains(response.getRecipient())) {
&& studentsEmailInTeam.contains(response.getRecipient().getEmail())) {
isVisibleResponse = true;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/teammates/storage/sqlapi/CoursesDb.java
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ public Team getTeamByName(UUID sectionId, String teamName) {

/**
* Gets the course associated with a feedback response comment.
*
*
* @param id The identifier of a feedback response comment.
* @return A course.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ public List<FeedbackResponse> getResponsesForQuestion(UUID questionId) {

/**
* Checks whether a user has responses in a session.
*
*
* @param giver the email of the giver.
* @param feedbackSessionName the name of the feedback session.
* @param courseId the identifier of the course.
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/teammates/storage/sqlapi/UsersDb.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import teammates.storage.sqlsearch.InstructorSearchManager;
import teammates.storage.sqlsearch.SearchManagerFactory;
import teammates.storage.sqlsearch.StudentSearchManager;

import jakarta.persistence.TypedQuery;
import jakarta.persistence.criteria.CriteriaBuilder;
import jakarta.persistence.criteria.CriteriaQuery;
Expand Down Expand Up @@ -671,6 +672,9 @@ public void checkBeforeUpdateStudent(Student student)
}
}

/**
* Gets a User by course id and email.
*/
public User getUserByEmail(String courseId, String email) {
assert courseId != null;
assert email != null;
Expand Down
1 change: 1 addition & 0 deletions src/main/java/teammates/storage/sqlentity/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

import teammates.common.util.SanitizationHelper;
import teammates.common.util.StringHelper;

import jakarta.persistence.CascadeType;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import teammates.storage.sqlentity.FeedbackResponse;
import teammates.storage.sqlentity.Section;
import teammates.storage.sqlentity.User;

import jakarta.persistence.Column;
import jakarta.persistence.Convert;
import jakarta.persistence.Converter;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import teammates.storage.sqlentity.FeedbackResponse;
import teammates.storage.sqlentity.Section;
import teammates.storage.sqlentity.User;

import jakarta.persistence.Column;
import jakarta.persistence.Convert;
import jakarta.persistence.Converter;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import teammates.storage.sqlentity.FeedbackResponse;
import teammates.storage.sqlentity.Section;
import teammates.storage.sqlentity.User;

import jakarta.persistence.Column;
import jakarta.persistence.Convert;
import jakarta.persistence.Converter;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import teammates.common.datatransfer.questions.FeedbackTextResponseDetails;
import teammates.common.util.Const;
import teammates.storage.sqlentity.FeedbackQuestion;
import teammates.storage.sqlentity.User;

/**
* Represents a missing response.
Expand All @@ -17,8 +18,8 @@ protected FeedbackMissingResponse() {
}

public FeedbackMissingResponse(
FeedbackQuestion feedbackQuestion, String giver,
String giverSectionName, String recipient, String recipientSectionName
FeedbackQuestion feedbackQuestion, User giver,
String giverSectionName, User recipient, String recipientSectionName
) {
super(feedbackQuestion, giver, null, recipient, null, new FeedbackTextResponseDetails(Const.MISSING_RESPONSE_TEXT));
this.giverSectionName = giverSectionName;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import teammates.storage.sqlentity.FeedbackResponse;
import teammates.storage.sqlentity.Section;
import teammates.storage.sqlentity.User;

import jakarta.persistence.Column;
import jakarta.persistence.Convert;
import jakarta.persistence.Converter;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import teammates.storage.sqlentity.FeedbackResponse;
import teammates.storage.sqlentity.Section;
import teammates.storage.sqlentity.User;

import jakarta.persistence.Column;
import jakarta.persistence.Convert;
import jakarta.persistence.Converter;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import teammates.storage.sqlentity.FeedbackResponse;
import teammates.storage.sqlentity.Section;
import teammates.storage.sqlentity.User;

import jakarta.persistence.Column;
import jakarta.persistence.Convert;
import jakarta.persistence.Converter;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import teammates.storage.sqlentity.FeedbackResponse;
import teammates.storage.sqlentity.Section;
import teammates.storage.sqlentity.User;

import jakarta.persistence.Column;
import jakarta.persistence.Convert;
import jakarta.persistence.Converter;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import teammates.storage.sqlentity.FeedbackResponse;
import teammates.storage.sqlentity.Section;
import teammates.storage.sqlentity.User;

import jakarta.persistence.Column;
import jakarta.persistence.Convert;
import jakarta.persistence.Converter;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import teammates.storage.sqlentity.FeedbackResponse;
import teammates.storage.sqlentity.Section;
import teammates.storage.sqlentity.User;

import jakarta.persistence.Column;
import jakarta.persistence.Convert;
import jakarta.persistence.Converter;
Expand Down
Loading

0 comments on commit a096fea

Please sign in to comment.