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

[#12048] Remove null default section #13040

Merged
merged 5 commits into from
May 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 0 additions & 3 deletions src/main/java/teammates/common/util/Const.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
import java.time.Duration;
import java.time.Instant;

import teammates.storage.sqlentity.Section;

/**
* Stores constants that are widely used across classes.
* this class contains several nested classes, each containing a specific
Expand All @@ -27,7 +25,6 @@ public final class Const {
public static final int SECTION_SIZE_LIMIT = 100;

public static final String DEFAULT_SECTION = "None";
public static final Section DEFAULT_SQL_SECTION = null;

public static final String UNKNOWN_INSTITUTION = "Unknown Institution";

Expand Down
9 changes: 9 additions & 0 deletions src/main/java/teammates/sqllogic/api/Logic.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import teammates.common.exception.InvalidParametersException;
import teammates.common.exception.SearchServiceException;
import teammates.common.exception.StudentUpdateException;
import teammates.common.util.Const;
import teammates.sqllogic.core.AccountRequestsLogic;
import teammates.sqllogic.core.AccountsLogic;
import teammates.sqllogic.core.CoursesLogic;
Expand Down Expand Up @@ -1089,6 +1090,14 @@ public List<Student> getStudentsByTeamName(String teamName, String courseId) {
return usersLogic.getStudentsForTeam(teamName, courseId);
}

/**
* Returns the default SQL section.
* If it does not exist, create and return it.
*/
public Section getDefaultSectionOrCreate(String courseId) {
return getSectionOrCreate(courseId, Const.DEFAULT_SECTION);
}

/**
* Gets a team by associated {@code courseId} and {@code sectionName}.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -434,35 +434,35 @@ Section getRecipientSection(
switch (giverType) {
case INSTRUCTORS:
case SELF:
return Const.DEFAULT_SQL_SECTION;
return sqlLogic.getDefaultSectionOrCreate(courseId);
case TEAMS:
case TEAMS_IN_SAME_SECTION:
Section section = sqlLogic.getSectionByCourseIdAndTeam(courseId, recipientIdentifier);
return section == null ? Const.DEFAULT_SQL_SECTION : section;
return section == null ? sqlLogic.getDefaultSectionOrCreate(courseId) : section;
case STUDENTS:
case STUDENTS_IN_SAME_SECTION:
Student student = sqlLogic.getStudentForEmail(courseId, recipientIdentifier);
return student == null ? Const.DEFAULT_SQL_SECTION : student.getSection();
return student == null ? sqlLogic.getDefaultSectionOrCreate(courseId) : student.getSection();
default:
assert false : "Invalid giver type " + giverType + " for recipient type " + recipientType;
return null;
}
case INSTRUCTORS:
case NONE:
return Const.DEFAULT_SQL_SECTION;
return sqlLogic.getDefaultSectionOrCreate(courseId);
case TEAMS:
case TEAMS_EXCLUDING_SELF:
case TEAMS_IN_SAME_SECTION:
case OWN_TEAM:
Section section = sqlLogic.getSectionByCourseIdAndTeam(courseId, recipientIdentifier);
return section == null ? Const.DEFAULT_SQL_SECTION : section;
return section == null ? sqlLogic.getDefaultSectionOrCreate(courseId) : section;
case STUDENTS:
case STUDENTS_EXCLUDING_SELF:
case STUDENTS_IN_SAME_SECTION:
case OWN_TEAM_MEMBERS:
case OWN_TEAM_MEMBERS_INCLUDING_SELF:
Student student = sqlLogic.getStudentForEmail(courseId, recipientIdentifier);
return student == null ? Const.DEFAULT_SQL_SECTION : student.getSection();
return student == null ? sqlLogic.getDefaultSectionOrCreate(courseId) : student.getSection();
default:
assert false : "Unknown recipient type " + recipientType;
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ public JsonResult execute() throws InvalidHttpRequestBodyException, InvalidOpera
case INSTRUCTOR_SUBMISSION:
Instructor instructor = getSqlInstructorOfCourseFromRequest(feedbackQuestion.getCourseId());
giverIdentifier = instructor.getEmail();
giverSection = Const.DEFAULT_SQL_SECTION;
giverSection = sqlLogic.getDefaultSectionOrCreate(courseId);
existingResponses = sqlLogic.getFeedbackResponsesFromInstructorForQuestion(feedbackQuestion, instructor);
recipientsOfTheQuestion = sqlLogic.getRecipientsOfQuestion(feedbackQuestion, instructor, null);
sqlLogic.populateFieldsToGenerateInQuestion(feedbackQuestion,
Expand Down