Search in sources :

Example 76 with InvalidParametersException

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

the class InstructorsDb method updateInstructorByGoogleId.

/**
 * Updates the instructor. Cannot modify Course ID or google id.
 */
public void updateInstructorByGoogleId(InstructorAttributes instructorAttributesToUpdate) throws InvalidParametersException, EntityDoesNotExistException {
    Assumption.assertNotNull(Const.StatusCodes.DBLEVEL_NULL_INPUT, instructorAttributesToUpdate);
    if (!instructorAttributesToUpdate.isValid()) {
        throw new InvalidParametersException(instructorAttributesToUpdate.getInvalidityInfo());
    }
    instructorAttributesToUpdate.sanitizeForSaving();
    Instructor instructorToUpdate = getInstructorEntityForGoogleId(instructorAttributesToUpdate.courseId, instructorAttributesToUpdate.googleId);
    if (instructorToUpdate == null) {
        throw new EntityDoesNotExistException(ERROR_UPDATE_NON_EXISTENT_ACCOUNT + instructorAttributesToUpdate.googleId + ThreadHelper.getCurrentThreadStack());
    }
    instructorToUpdate.setName(instructorAttributesToUpdate.name);
    instructorToUpdate.setEmail(instructorAttributesToUpdate.email);
    instructorToUpdate.setIsArchived(instructorAttributesToUpdate.isArchived);
    instructorToUpdate.setRole(instructorAttributesToUpdate.role);
    instructorToUpdate.setIsDisplayedToStudents(instructorAttributesToUpdate.isDisplayedToStudents);
    instructorToUpdate.setDisplayedName(instructorAttributesToUpdate.displayedName);
    instructorToUpdate.setInstructorPrivilegeAsText(instructorAttributesToUpdate.getTextFromInstructorPrivileges());
    // TODO: make courseId+email the non-modifiable values
    putDocument(makeAttributes(instructorToUpdate));
    saveEntity(instructorToUpdate, instructorAttributesToUpdate);
}
Also used : Instructor(teammates.storage.entity.Instructor) InvalidParametersException(teammates.common.exception.InvalidParametersException) EntityDoesNotExistException(teammates.common.exception.EntityDoesNotExistException)

Example 77 with InvalidParametersException

use of teammates.common.exception.InvalidParametersException 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 78 with InvalidParametersException

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

the class StudentsLogic method resetStudentGoogleId.

public void resetStudentGoogleId(String originalEmail, String courseId, boolean hasDocument) throws EntityDoesNotExistException, InvalidParametersException {
    // Edit student uses KeepOriginal policy, where unchanged fields are set
    // as null. Hence, we can't do isValid() for student here.
    // After updateWithExistingRecordWithGoogleIdReset method called,
    // the student should be valid
    studentsDb.verifyStudentExists(courseId, originalEmail);
    StudentAttributes originalStudent = getStudentForEmail(courseId, originalEmail);
    originalStudent.googleId = null;
    if (!originalStudent.isValid()) {
        throw new InvalidParametersException(originalStudent.getInvalidityInfo());
    }
    studentsDb.updateStudent(originalStudent.course, originalEmail, originalStudent.name, originalStudent.team, originalStudent.section, originalStudent.email, originalStudent.googleId, originalStudent.comments, hasDocument, false);
}
Also used : InvalidParametersException(teammates.common.exception.InvalidParametersException) StudentAttributes(teammates.common.datatransfer.attributes.StudentAttributes)

Example 79 with InvalidParametersException

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

the class StudentsLogic method updateStudentCascadeWithSubmissionAdjustmentScheduled.

public void updateStudentCascadeWithSubmissionAdjustmentScheduled(String originalEmail, StudentAttributes student, boolean hasDocument) throws EntityDoesNotExistException, InvalidParametersException {
    // Edit student uses KeepOriginal policy, where unchanged fields are set
    // as null. Hence, we can't do isValid() for student here.
    // After updateWithReferenceToExistingStudentRecord method called,
    // the student should be valid
    // here is like a db access that can be avoided if we really want to optimize the code
    studentsDb.verifyStudentExists(student.course, originalEmail);
    StudentAttributes originalStudent = getStudentForEmail(student.course, originalEmail);
    // prepare new student
    student.updateWithExistingRecord(originalStudent);
    if (!student.isValid()) {
        throw new InvalidParametersException(student.getInvalidityInfo());
    }
    studentsDb.updateStudent(student.course, originalEmail, student.name, student.team, student.section, student.email, student.googleId, student.comments, hasDocument, false);
    // cascade email change, if any
    if (!originalEmail.equals(student.email)) {
        frLogic.updateFeedbackResponsesForChangingEmail(student.course, originalEmail, student.email);
        fsLogic.updateRespondentsForStudent(originalEmail, student.email, student.course);
    }
}
Also used : InvalidParametersException(teammates.common.exception.InvalidParametersException) StudentAttributes(teammates.common.datatransfer.attributes.StudentAttributes)

Example 80 with InvalidParametersException

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

the class AdminEmailsDb method updateAdminEmail.

public void updateAdminEmail(AdminEmailAttributes ae) throws InvalidParametersException, EntityDoesNotExistException {
    if (!ae.isValid()) {
        throw new InvalidParametersException(ae.getInvalidityInfo());
    }
    AdminEmail adminEmailToUpdate = getAdminEmailEntity(ae.emailId);
    if (adminEmailToUpdate == null) {
        throw new EntityDoesNotExistException(ERROR_UPDATE_NON_EXISTENT_ACCOUNT + ae.getSubject() + "/" + ae.getSendDate() + ThreadHelper.getCurrentThreadStack());
    }
    ae.sanitizeForSaving();
    adminEmailToUpdate.setContent(ae.content);
    adminEmailToUpdate.setAddressReceiver(ae.addressReceiver);
    adminEmailToUpdate.setGroupReceiver(ae.groupReceiver);
    adminEmailToUpdate.setSubject(ae.subject);
    adminEmailToUpdate.setIsInTrashBin(ae.isInTrashBin);
    adminEmailToUpdate.setSendDate(ae.sendDate);
    saveEntity(adminEmailToUpdate, ae);
}
Also used : InvalidParametersException(teammates.common.exception.InvalidParametersException) AdminEmail(teammates.storage.entity.AdminEmail) EntityDoesNotExistException(teammates.common.exception.EntityDoesNotExistException)

Aggregations

InvalidParametersException (teammates.common.exception.InvalidParametersException)83 EntityDoesNotExistException (teammates.common.exception.EntityDoesNotExistException)37 InstructorAttributes (teammates.common.datatransfer.attributes.InstructorAttributes)24 StatusMessage (teammates.common.util.StatusMessage)21 Test (org.testng.annotations.Test)19 EntityAlreadyExistsException (teammates.common.exception.EntityAlreadyExistsException)19 FeedbackSessionAttributes (teammates.common.datatransfer.attributes.FeedbackSessionAttributes)13 StudentAttributes (teammates.common.datatransfer.attributes.StudentAttributes)12 CourseAttributes (teammates.common.datatransfer.attributes.CourseAttributes)9 FeedbackSession (teammates.storage.entity.FeedbackSession)9 Text (com.google.appengine.api.datastore.Text)8 FeedbackQuestionAttributes (teammates.common.datatransfer.attributes.FeedbackQuestionAttributes)8 AccountAttributes (teammates.common.datatransfer.attributes.AccountAttributes)6 FeedbackResponseAttributes (teammates.common.datatransfer.attributes.FeedbackResponseAttributes)6 ArrayList (java.util.ArrayList)5 InstructorPrivileges (teammates.common.datatransfer.InstructorPrivileges)5 VoidWork (com.googlecode.objectify.VoidWork)4 StudentProfileAttributes (teammates.common.datatransfer.attributes.StudentProfileAttributes)4 PageData (teammates.ui.pagedata.PageData)4 FeedbackResponseCommentAttributes (teammates.common.datatransfer.attributes.FeedbackResponseCommentAttributes)3