Search in sources :

Example 6 with CourseStudent

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

the class StudentsDb method deleteStudent.

public void deleteStudent(String courseId, String email, boolean hasDocument) {
    Assumption.assertNotNull(Const.StatusCodes.DBLEVEL_NULL_INPUT, courseId);
    Assumption.assertNotNull(Const.StatusCodes.DBLEVEL_NULL_INPUT, email);
    if (hasDocument) {
        CourseStudent courseStudentToDelete = getCourseStudentEntityForEmail(courseId, email);
        if (courseStudentToDelete != null) {
            StudentAttributes courseStudentToDeleteAttributes = makeAttributes(courseStudentToDelete);
            deleteDocument(courseStudentToDeleteAttributes);
            deleteEntityDirect(courseStudentToDelete, courseStudentToDeleteAttributes);
        }
    } else {
        ofy().delete().keys(getCourseStudentForEmailQuery(courseId, email).keys()).now();
    }
}
Also used : CourseStudent(teammates.storage.entity.CourseStudent) StudentAttributes(teammates.common.datatransfer.attributes.StudentAttributes)

Example 7 with CourseStudent

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

the class StudentsDb method getCourseStudentEntityForRegistrationKey.

private CourseStudent getCourseStudentEntityForRegistrationKey(String registrationKey) {
    List<CourseStudent> studentList = load().filter("registrationKey =", registrationKey).list();
    // If registration key detected is not unique, something is wrong
    if (studentList.size() > 1) {
        StringBuilder duplicatedStudentsUniqueIds = new StringBuilder();
        for (CourseStudent s : studentList) {
            duplicatedStudentsUniqueIds.append(s.getUniqueId() + '\n');
        }
        log.severe("Duplicate registration keys detected for: \n" + duplicatedStudentsUniqueIds);
    }
    if (studentList.isEmpty()) {
        return null;
    }
    return studentList.get(0);
}
Also used : CourseStudent(teammates.storage.entity.CourseStudent)

Example 8 with CourseStudent

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

the class StudentsDb method recreateStudentWithNewEmail.

@SuppressWarnings("PMD.PreserveStackTrace")
private void recreateStudentWithNewEmail(CourseStudent newCourseStudent, String lastName, CourseStudent courseStudent, boolean hasDocument, boolean keepUpdateTimestamp, String courseId, String email) throws InvalidParametersException {
    newCourseStudent.setLastName(lastName);
    newCourseStudent.setCreatedAt(courseStudent.getCreatedAt());
    if (keepUpdateTimestamp) {
        newCourseStudent.setLastUpdate(courseStudent.getUpdatedAt());
    }
    StudentAttributes newCourseStudentAttributes = makeAttributes(newCourseStudent);
    try {
        createStudent(newCourseStudentAttributes, hasDocument);
    } catch (EntityAlreadyExistsException e) {
        CourseStudent existingStudent = getEntity(newCourseStudentAttributes);
        String error = ERROR_UPDATE_EMAIL_ALREADY_USED + existingStudent.getName() + "/" + existingStudent.getEmail();
        throw new InvalidParametersException(error);
    }
    deleteStudent(courseId, email);
}
Also used : EntityAlreadyExistsException(teammates.common.exception.EntityAlreadyExistsException) CourseStudent(teammates.storage.entity.CourseStudent) InvalidParametersException(teammates.common.exception.InvalidParametersException) StudentAttributes(teammates.common.datatransfer.attributes.StudentAttributes)

Example 9 with CourseStudent

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

the class StudentsDb method updateStudent.

public void updateStudent(String courseId, String email, String newName, String newTeamName, String newSectionName, String newEmail, String newGoogleId, String newComments, boolean hasDocument, boolean keepUpdateTimestamp) throws InvalidParametersException, EntityDoesNotExistException {
    Assumption.assertNotNull(Const.StatusCodes.DBLEVEL_NULL_INPUT, courseId);
    Assumption.assertNotNull(Const.StatusCodes.DBLEVEL_NULL_INPUT, email);
    verifyStudentExists(courseId, email);
    // Update CourseStudent if it exists.
    CourseStudent courseStudent = getCourseStudentEntityForEmail(courseId, email);
    if (courseStudent != null) {
        boolean isEmailChanged = !email.equals(newEmail);
        String lastName = StringHelper.splitName(newName)[1];
        if (isEmailChanged) {
            CourseStudent newCourseStudent = new CourseStudent(newEmail, newName, newGoogleId, newComments, courseId, newTeamName, newSectionName);
            recreateStudentWithNewEmail(newCourseStudent, lastName, courseStudent, hasDocument, keepUpdateTimestamp, courseId, email);
        } else {
            updateStudentDetails(newName, newTeamName, newSectionName, newGoogleId, newComments, hasDocument, keepUpdateTimestamp, courseStudent, lastName);
        }
    }
}
Also used : CourseStudent(teammates.storage.entity.CourseStudent)

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