Search in sources :

Example 1 with CourseStudent

use of teammates.storage.entity.CourseStudent in project teammates by TEAMMATES.

the class StudentsDb method getStudentForGoogleId.

/**
 * Preconditions:
 * <br> * All parameters are non-null.
 * @return null if no such student is found.
 */
public StudentAttributes getStudentForGoogleId(String courseId, String googleId) {
    Assumption.assertNotNull(Const.StatusCodes.DBLEVEL_NULL_INPUT, googleId);
    Assumption.assertNotNull(Const.StatusCodes.DBLEVEL_NULL_INPUT, courseId);
    CourseStudent student = load().filter("courseId =", courseId).filter("googleId =", googleId).first().now();
    return makeAttributesOrNull(student);
}
Also used : CourseStudent(teammates.storage.entity.CourseStudent)

Example 2 with CourseStudent

use of teammates.storage.entity.CourseStudent in project teammates by TEAMMATES.

the class StudentsDb method deleteStudentsCascadeDocuments.

private void deleteStudentsCascadeDocuments(List<CourseStudent> students) {
    List<StudentAttributes> studentsAttributes = new ArrayList<>();
    for (CourseStudent student : students) {
        StudentAttributes studentAttributes = makeAttributes(student);
        studentsAttributes.add(studentAttributes);
        deleteDocument(studentAttributes);
    }
    deleteEntitiesDirect(students, studentsAttributes);
}
Also used : CourseStudent(teammates.storage.entity.CourseStudent) ArrayList(java.util.ArrayList) StudentAttributes(teammates.common.datatransfer.attributes.StudentAttributes)

Example 3 with CourseStudent

use of teammates.storage.entity.CourseStudent in project teammates by TEAMMATES.

the class StudentAttributesTest method testStudentBuilder.

@Test
public void testStudentBuilder() throws Exception {
    String courseId = "anyCourseId";
    StudentAttributes invalidStudent;
    CourseStudent expected;
    StudentAttributes studentUnderTest;
    ______TS("Typical case: contains white space");
    expected = generateTypicalStudentObject();
    studentUnderTest = StudentAttributes.builder("courseId1", "   name 1   ", "   email@email.com  ").withSection("  sect 1 ").withComments("  comment 1  ").withTeam("  team 1   ").build();
    verifyStudentContent(expected, (CourseStudent) studentUnderTest.toEntity());
    ______TS("Typical case: contains google id");
    expected = generateTypicalStudentObject();
    studentUnderTest = StudentAttributes.builder("courseId1", "name 1", "email@email.com").withGoogleId("googleId.1").withSection("section 1").withComments("comment 1").withTeam("team 1").build();
    verifyStudentContentIncludingId(expected, (CourseStudent) studentUnderTest.toEntity());
    ______TS("Typical case: initialize from entity");
    expected = generateTypicalStudentObject();
    studentUnderTest = StudentAttributes.valueOf(expected);
    verifyStudentContentIncludingId(expected, (CourseStudent) studentUnderTest.toEntity());
    ______TS("Failure case: empty course id");
    invalidStudent = StudentAttributes.builder("", "name", "e@e.com").withSection("section").withComments("c").withTeam("team").build();
    assertFalse(invalidStudent.isValid());
    assertEquals(getPopulatedEmptyStringErrorMessage(FieldValidator.COURSE_ID_ERROR_MESSAGE_EMPTY_STRING, FieldValidator.COURSE_ID_FIELD_NAME, FieldValidator.COURSE_ID_MAX_LENGTH), invalidStudent.getInvalidityInfo().get(0));
    ______TS("Failure case: invalid course id");
    invalidStudent = StudentAttributes.builder("Course Id with space", "name", "e@e.com").withSection("section").withComments("c").withTeam("team").build();
    assertFalse(invalidStudent.isValid());
    assertEquals(getPopulatedErrorMessage(FieldValidator.COURSE_ID_ERROR_MESSAGE, invalidStudent.course, FieldValidator.COURSE_ID_FIELD_NAME, FieldValidator.REASON_INCORRECT_FORMAT, FieldValidator.COURSE_ID_MAX_LENGTH), invalidStudent.getInvalidityInfo().get(0));
    ______TS("Failure case: empty name");
    invalidStudent = StudentAttributes.builder(courseId, "", "e@e.com").withSection("sect").withComments("c").withTeam("t1").build();
    assertFalse(invalidStudent.isValid());
    assertEquals(invalidStudent.getInvalidityInfo().get(0), getPopulatedEmptyStringErrorMessage(FieldValidator.SIZE_CAPPED_NON_EMPTY_STRING_ERROR_MESSAGE_EMPTY_STRING, FieldValidator.PERSON_NAME_FIELD_NAME, FieldValidator.PERSON_NAME_MAX_LENGTH));
    ______TS("Failure case: empty email");
    invalidStudent = StudentAttributes.builder(courseId, "n", "").withSection("sect").withComments("c").withTeam("t1").build();
    assertFalse(invalidStudent.isValid());
    assertEquals(getPopulatedEmptyStringErrorMessage(FieldValidator.EMAIL_ERROR_MESSAGE_EMPTY_STRING, FieldValidator.EMAIL_FIELD_NAME, FieldValidator.EMAIL_MAX_LENGTH), invalidStudent.getInvalidityInfo().get(0));
    ______TS("Failure case: section name too long");
    String longSectionName = StringHelperExtension.generateStringOfLength(FieldValidator.SECTION_NAME_MAX_LENGTH + 1);
    invalidStudent = StudentAttributes.builder(courseId, "", "e@e.com").withSection(longSectionName).withComments("c").withTeam("t1").build();
    assertFalse(invalidStudent.isValid());
    assertEquals(getPopulatedErrorMessage(FieldValidator.SIZE_CAPPED_NON_EMPTY_STRING_ERROR_MESSAGE, longSectionName, FieldValidator.SECTION_NAME_FIELD_NAME, FieldValidator.REASON_TOO_LONG, FieldValidator.SECTION_NAME_MAX_LENGTH), invalidStudent.getInvalidityInfo().get(0));
    ______TS("Failure case: team name too long");
    String longTeamName = StringHelperExtension.generateStringOfLength(FieldValidator.TEAM_NAME_MAX_LENGTH + 1);
    invalidStudent = StudentAttributes.builder(courseId, "", "e@e.com").withSection("sect").withComments("c").withTeam(longTeamName).build();
    assertFalse(invalidStudent.isValid());
    assertEquals(getPopulatedErrorMessage(FieldValidator.SIZE_CAPPED_NON_EMPTY_STRING_ERROR_MESSAGE, longTeamName, FieldValidator.TEAM_NAME_FIELD_NAME, FieldValidator.REASON_TOO_LONG, FieldValidator.TEAM_NAME_MAX_LENGTH), invalidStudent.getInvalidityInfo().get(0));
    ______TS("Failure case: student name too long");
    String longStudentName = StringHelperExtension.generateStringOfLength(FieldValidator.PERSON_NAME_MAX_LENGTH + 1);
    invalidStudent = StudentAttributes.builder(courseId, longStudentName, "e@e.com").withSection("sect").withComments("c").withTeam("t1").build();
    assertFalse(invalidStudent.isValid());
    assertEquals(getPopulatedErrorMessage(FieldValidator.SIZE_CAPPED_NON_EMPTY_STRING_ERROR_MESSAGE, longStudentName, FieldValidator.PERSON_NAME_FIELD_NAME, FieldValidator.REASON_TOO_LONG, FieldValidator.PERSON_NAME_MAX_LENGTH), invalidStudent.getInvalidityInfo().get(0));
    ______TS("Failure case: invalid email");
    invalidStudent = StudentAttributes.builder(courseId, "name", "ee.com").withSection("sect").withComments("c").withTeam("t1").build();
    assertFalse(invalidStudent.isValid());
    assertEquals(getPopulatedErrorMessage(FieldValidator.EMAIL_ERROR_MESSAGE, "ee.com", FieldValidator.EMAIL_FIELD_NAME, FieldValidator.REASON_INCORRECT_FORMAT, FieldValidator.EMAIL_MAX_LENGTH), invalidStudent.getInvalidityInfo().get(0));
    ______TS("Failure case: comment too long");
    String longComment = StringHelperExtension.generateStringOfLength(FieldValidator.STUDENT_ROLE_COMMENTS_MAX_LENGTH + 1);
    invalidStudent = StudentAttributes.builder(courseId, "name", "e@e.com").withSection("sect").withComments(longComment).withTeam("t1").build();
    assertFalse(invalidStudent.isValid());
    assertEquals(getPopulatedErrorMessage(FieldValidator.SIZE_CAPPED_POSSIBLY_EMPTY_STRING_ERROR_MESSAGE, longComment, FieldValidator.STUDENT_ROLE_COMMENTS_FIELD_NAME, FieldValidator.REASON_TOO_LONG, FieldValidator.STUDENT_ROLE_COMMENTS_MAX_LENGTH), invalidStudent.getInvalidityInfo().get(0));
// Other invalid parameters cases are omitted because they are already
// unit-tested in validate*() methods in Common.java
}
Also used : CourseStudent(teammates.storage.entity.CourseStudent) StudentAttributes(teammates.common.datatransfer.attributes.StudentAttributes) Test(org.testng.annotations.Test)

Example 4 with CourseStudent

use of teammates.storage.entity.CourseStudent in project teammates by TEAMMATES.

the class StudentAttributesTest method testValueOf.

@Test
public void testValueOf() {
    CourseStudent originalStudent = new CourseStudent("email@email.com", "name 1", "googleId.1", "comment 1", "courseId1", "team 1", "sect 1");
    StudentAttributes copyStudent = StudentAttributes.valueOf(originalStudent);
    assertEquals(originalStudent.getCourseId(), copyStudent.course);
    assertEquals(originalStudent.getName(), copyStudent.name);
    assertEquals(originalStudent.getEmail(), copyStudent.email);
    assertEquals(originalStudent.getGoogleId(), copyStudent.googleId);
    assertEquals(originalStudent.getComments(), copyStudent.comments);
    assertEquals(originalStudent.getRegistrationKey(), copyStudent.key);
    assertEquals(originalStudent.getLastName(), copyStudent.lastName);
    assertEquals(originalStudent.getSectionName(), copyStudent.section);
    assertEquals(originalStudent.getTeamName(), copyStudent.team);
    assertEquals(originalStudent.getCreatedAt(), copyStudent.getCreatedAt());
    assertEquals(originalStudent.getUpdatedAt(), copyStudent.getUpdatedAt());
}
Also used : CourseStudent(teammates.storage.entity.CourseStudent) StudentAttributes(teammates.common.datatransfer.attributes.StudentAttributes) Test(org.testng.annotations.Test)

Example 5 with CourseStudent

use of teammates.storage.entity.CourseStudent in project teammates by TEAMMATES.

the class StatisticsPerInstitute method generateStatsPerInstitute.

private StatsBundle generateStatsPerInstitute(List<CourseStudent> allStudents, List<Instructor> allInstructors, List<Account> allAccounts) {
    Map<String, Map<Integer, Set<String>>> institutes = new HashMap<>();
    Set<String> allInstructorEmailSet = new HashSet<>();
    Set<String> allStudentEmailSet = new HashSet<>();
    int studentEmailCounter = 0;
    int instructorEmailCounter = 0;
    for (Instructor instructor : allInstructors) {
        if (isTestingInstructorData(instructor, allAccounts) || instructor.getEmail() == null) {
            continue;
        }
        String institute = getInstituteForInstructor(instructor, allAccounts);
        if (!institutes.containsKey(institute)) {
            institutes.put(institute, new HashMap<Integer, Set<String>>());
            institutes.get(institute).put(INSTRUCTOR_INDEX, new HashSet<String>());
            institutes.get(institute).put(STUDENT_INDEX, new HashSet<String>());
        }
        institutes.get(institute).get(INSTRUCTOR_INDEX).add(instructor.getEmail().toLowerCase());
        allInstructorEmailSet.add(instructor.getEmail().toLowerCase());
        instructorEmailCounter++;
        updateProgressIndicator();
    }
    for (CourseStudent student : allStudents) {
        if (isTestingStudentData(student, allInstructors, allAccounts) || student.getEmail() == null) {
            continue;
        }
        String institute = getInstituteForStudent(student, allInstructors, allAccounts);
        if (!institutes.containsKey(institute)) {
            institutes.put(institute, new HashMap<Integer, Set<String>>());
            institutes.get(institute).put(INSTRUCTOR_INDEX, new HashSet<String>());
            institutes.get(institute).put(STUDENT_INDEX, new HashSet<String>());
        }
        institutes.get(institute).get(STUDENT_INDEX).add(student.getEmail().toLowerCase());
        allStudentEmailSet.add(student.getEmail().toLowerCase());
        studentEmailCounter++;
        updateProgressIndicator();
    }
    List<InstituteStats> statList = convertToList(institutes);
    sortByTotalStudentsDescending(statList);
    StatsBundle statsBundle = new StatsBundle();
    statsBundle.instituteStatsList = statList;
    statsBundle.numOfAllInstructorEmail = instructorEmailCounter;
    statsBundle.numOfAllStudentEmails = studentEmailCounter;
    statsBundle.numOfUniqueInstructorEmails = allInstructorEmailSet.size();
    statsBundle.numOfUniqueStudentEmails = allStudentEmailSet.size();
    return statsBundle;
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) HashMap(java.util.HashMap) Instructor(teammates.storage.entity.Instructor) CourseStudent(teammates.storage.entity.CourseStudent) Map(java.util.Map) HashMap(java.util.HashMap) HashSet(java.util.HashSet)

Aggregations

CourseStudent (teammates.storage.entity.CourseStudent)9 StudentAttributes (teammates.common.datatransfer.attributes.StudentAttributes)5 Test (org.testng.annotations.Test)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 Set (java.util.Set)1 EntityAlreadyExistsException (teammates.common.exception.EntityAlreadyExistsException)1 InvalidParametersException (teammates.common.exception.InvalidParametersException)1 Instructor (teammates.storage.entity.Instructor)1