Skip to content

Commit

Permalink
[#12048] Remove null default section (#13040)
Browse files Browse the repository at this point in the history
* Add changes

* Add missing

---------

Co-authored-by: Nicolas <[email protected]>
Co-authored-by: Wilson Kurniawan <[email protected]>
  • Loading branch information
3 people authored May 12, 2024
1 parent 1ea04f4 commit 06bfafd
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 10 deletions.
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

0 comments on commit 06bfafd

Please sign in to comment.