Search in sources :

Example 6 with EntityDoesNotExistException

use of teammates.common.exception.EntityDoesNotExistException in project teammates by TEAMMATES.

the class AccountsLogic method joinCourseForStudent.

public void joinCourseForStudent(String registrationKey, String googleId) throws JoinCourseException, InvalidParametersException {
    verifyStudentJoinCourseRequest(registrationKey, googleId);
    StudentAttributes student = studentsLogic.getStudentForRegistrationKey(registrationKey);
    // register the student
    student.googleId = googleId;
    try {
        studentsLogic.updateStudentCascade(student.email, student);
    } catch (EntityDoesNotExistException e) {
        Assumption.fail("Student disappered while trying to register " + TeammatesException.toStringWithStackTrace(e));
    }
    if (accountsDb.getAccount(googleId) == null) {
        createStudentAccount(student);
    }
}
Also used : StudentAttributes(teammates.common.datatransfer.attributes.StudentAttributes) EntityDoesNotExistException(teammates.common.exception.EntityDoesNotExistException)

Example 7 with EntityDoesNotExistException

use of teammates.common.exception.EntityDoesNotExistException in project teammates by TEAMMATES.

the class CoursesLogic method getTeamsForCourse.

/**
 * Returns Teams for a particular courseId.<br>
 * <b>Note:</b><br>
 * This method does not returns any Loner information presently,<br>
 * Loner information must be returned as we decide to support loners<br>in future.
 */
public List<TeamDetailsBundle> getTeamsForCourse(String courseId) throws EntityDoesNotExistException {
    if (getCourse(courseId) == null) {
        throw new EntityDoesNotExistException("The course " + courseId + " does not exist");
    }
    List<StudentAttributes> students = studentsLogic.getStudentsForCourse(courseId);
    StudentAttributes.sortByTeamName(students);
    List<TeamDetailsBundle> teams = new ArrayList<>();
    TeamDetailsBundle team = null;
    for (int i = 0; i < students.size(); i++) {
        StudentAttributes s = students.get(i);
        // first student of first team
        if (team == null) {
            team = new TeamDetailsBundle();
            team.name = s.team;
            team.students.add(s);
        } else if (s.team.equals(team.name)) {
            // student in the same team as the previous student
            team.students.add(s);
        } else {
            // first student of subsequent teams (not the first team)
            teams.add(team);
            team = new TeamDetailsBundle();
            team.name = s.team;
            team.students.add(s);
        }
        // if last iteration
        if (i == students.size() - 1) {
            teams.add(team);
        }
    }
    return teams;
}
Also used : TeamDetailsBundle(teammates.common.datatransfer.TeamDetailsBundle) ArrayList(java.util.ArrayList) StudentAttributes(teammates.common.datatransfer.attributes.StudentAttributes) EntityDoesNotExistException(teammates.common.exception.EntityDoesNotExistException)

Example 8 with EntityDoesNotExistException

use of teammates.common.exception.EntityDoesNotExistException in project teammates by TEAMMATES.

the class GenerateFeedbackReport method doOperation.

@Override
protected void doOperation() {
    Logic logic = new Logic();
    try {
        String fileContent = logic.getFeedbackSessionResultSummaryAsCsv("CourseID", "Session Name", "instructor@email.com", true, true, null);
        writeToFile("result.csv", fileContent);
    } catch (EntityDoesNotExistException | ExceedingRangeException e) {
        e.printStackTrace();
    }
}
Also used : ExceedingRangeException(teammates.common.exception.ExceedingRangeException) Logic(teammates.logic.api.Logic) EntityDoesNotExistException(teammates.common.exception.EntityDoesNotExistException)

Example 9 with EntityDoesNotExistException

use of teammates.common.exception.EntityDoesNotExistException in project teammates by TEAMMATES.

the class CoursesLogicTest method testGetCoursesForStudentAccount.

private void testGetCoursesForStudentAccount() throws Exception {
    ______TS("student having two courses");
    StudentAttributes studentInTwoCourses = dataBundle.students.get("student2InCourse1");
    List<CourseAttributes> courseList = coursesLogic.getCoursesForStudentAccount(studentInTwoCourses.googleId);
    CourseAttributes.sortById(courseList);
    assertEquals(2, courseList.size());
    CourseAttributes course1 = dataBundle.courses.get("typicalCourse1");
    CourseAttributes course2 = dataBundle.courses.get("typicalCourse2");
    List<CourseAttributes> courses = new ArrayList<>();
    courses.add(course1);
    courses.add(course2);
    CourseAttributes.sortById(courses);
    assertEquals(courses.get(0).getId(), courseList.get(0).getId());
    assertEquals(courses.get(0).getName(), courseList.get(0).getName());
    assertEquals(courses.get(1).getId(), courseList.get(1).getId());
    assertEquals(courses.get(1).getName(), courseList.get(1).getName());
    ______TS("student having one course");
    StudentAttributes studentInOneCourse = dataBundle.students.get("student1InCourse1");
    courseList = coursesLogic.getCoursesForStudentAccount(studentInOneCourse.googleId);
    assertEquals(1, courseList.size());
    course1 = dataBundle.courses.get("typicalCourse1");
    assertEquals(course1.getId(), courseList.get(0).getId());
    assertEquals(course1.getName(), courseList.get(0).getName());
    // Student having zero courses is not applicable
    ______TS("non-existent student");
    try {
        coursesLogic.getCoursesForStudentAccount("non-existent-student");
        signalFailureToDetectException();
    } catch (EntityDoesNotExistException e) {
        AssertHelper.assertContains("does not exist", e.getMessage());
    }
    ______TS("null parameter");
    try {
        coursesLogic.getCoursesForStudentAccount(null);
        signalFailureToDetectException();
    } catch (AssertionError e) {
        assertEquals(Const.StatusCodes.DBLEVEL_NULL_INPUT, e.getMessage());
    }
}
Also used : ArrayList(java.util.ArrayList) StudentAttributes(teammates.common.datatransfer.attributes.StudentAttributes) CourseAttributes(teammates.common.datatransfer.attributes.CourseAttributes) EntityDoesNotExistException(teammates.common.exception.EntityDoesNotExistException)

Example 10 with EntityDoesNotExistException

use of teammates.common.exception.EntityDoesNotExistException in project teammates by TEAMMATES.

the class CoursesLogicTest method testGetCourseSummary.

private void testGetCourseSummary() throws Exception {
    ______TS("typical case");
    CourseAttributes course = dataBundle.courses.get("typicalCourse1");
    CourseDetailsBundle courseSummary = coursesLogic.getCourseSummary(course.getId());
    assertEquals(course.getId(), courseSummary.course.getId());
    assertEquals(course.getName(), courseSummary.course.getName());
    assertEquals(2, courseSummary.stats.teamsTotal);
    assertEquals(5, courseSummary.stats.studentsTotal);
    assertEquals(0, courseSummary.stats.unregisteredTotal);
    assertEquals(1, courseSummary.sections.get(0).teams.size());
    assertEquals("Team 1.1</td></div>'\"", courseSummary.sections.get(0).teams.get(0).name);
    ______TS("course without students");
    StudentProfileAttributes spa = StudentProfileAttributes.builder("instructor1").build();
    AccountsLogic.inst().createAccount(AccountAttributes.builder().withGoogleId("instructor1").withName("Instructor 1").withEmail("instructor@email.tmt").withInstitute("TEAMMATES Test Institute 1").withIsInstructor(true).withStudentProfileAttributes(spa).build());
    coursesLogic.createCourseAndInstructor("instructor1", "course1", "course 1", "Asia/Singapore");
    courseSummary = coursesLogic.getCourseSummary("course1");
    assertEquals("course1", courseSummary.course.getId());
    assertEquals("course 1", courseSummary.course.getName());
    assertEquals("Asia/Singapore", courseSummary.course.getTimeZone().getId());
    assertEquals(0, courseSummary.stats.teamsTotal);
    assertEquals(0, courseSummary.stats.studentsTotal);
    assertEquals(0, courseSummary.stats.unregisteredTotal);
    assertEquals(0, courseSummary.sections.size());
    coursesLogic.deleteCourseCascade("course1");
    accountsDb.deleteAccount("instructor1");
    ______TS("non-existent");
    try {
        coursesLogic.getCourseSummary("non-existent-course");
        signalFailureToDetectException();
    } catch (EntityDoesNotExistException e) {
        AssertHelper.assertContains("The course does not exist:", e.getMessage());
    }
    ______TS("null parameter");
    try {
        coursesLogic.getCourseSummary((CourseAttributes) null);
        signalFailureToDetectException();
    } catch (AssertionError e) {
        assertEquals(Const.StatusCodes.DBLEVEL_NULL_INPUT, e.getMessage());
    }
    try {
        coursesLogic.getCourseSummary((String) null);
        signalFailureToDetectException();
    } catch (AssertionError e) {
        assertEquals(Const.StatusCodes.DBLEVEL_NULL_INPUT, e.getMessage());
    }
}
Also used : CourseDetailsBundle(teammates.common.datatransfer.CourseDetailsBundle) StudentProfileAttributes(teammates.common.datatransfer.attributes.StudentProfileAttributes) CourseAttributes(teammates.common.datatransfer.attributes.CourseAttributes) EntityDoesNotExistException(teammates.common.exception.EntityDoesNotExistException)

Aggregations

EntityDoesNotExistException (teammates.common.exception.EntityDoesNotExistException)107 InvalidParametersException (teammates.common.exception.InvalidParametersException)35 FeedbackSessionAttributes (teammates.common.datatransfer.attributes.FeedbackSessionAttributes)29 StudentAttributes (teammates.common.datatransfer.attributes.StudentAttributes)26 InstructorAttributes (teammates.common.datatransfer.attributes.InstructorAttributes)24 ArrayList (java.util.ArrayList)21 FeedbackQuestionAttributes (teammates.common.datatransfer.attributes.FeedbackQuestionAttributes)17 CourseAttributes (teammates.common.datatransfer.attributes.CourseAttributes)15 List (java.util.List)10 FeedbackResponseAttributes (teammates.common.datatransfer.attributes.FeedbackResponseAttributes)10 HashMap (java.util.HashMap)9 Test (org.testng.annotations.Test)9 FeedbackSession (teammates.storage.entity.FeedbackSession)9 CourseDetailsBundle (teammates.common.datatransfer.CourseDetailsBundle)8 StatusMessage (teammates.common.util.StatusMessage)8 StudentProfileAttributes (teammates.common.datatransfer.attributes.StudentProfileAttributes)7 Text (com.google.appengine.api.datastore.Text)6 TeamDetailsBundle (teammates.common.datatransfer.TeamDetailsBundle)6 VoidWork (com.googlecode.objectify.VoidWork)4 HashSet (java.util.HashSet)4