Search in sources :

Example 6 with Instructor

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

the class InstructorsDb method deleteInstructor.

/**
 * Deletes the instructor specified by courseId and email.
 */
public void deleteInstructor(String courseId, String email) {
    Assumption.assertNotNull(Const.StatusCodes.DBLEVEL_NULL_INPUT, email);
    Assumption.assertNotNull(Const.StatusCodes.DBLEVEL_NULL_INPUT, courseId);
    Instructor instructorToDelete = getInstructorEntityForEmail(courseId, email);
    if (instructorToDelete == null) {
        return;
    }
    InstructorAttributes instructorToDeleteAttributes = makeAttributes(instructorToDelete);
    deleteDocument(instructorToDeleteAttributes);
    deleteEntityDirect(instructorToDelete, instructorToDeleteAttributes);
    Instructor instructorCheck = getInstructorEntityForEmail(courseId, email);
    if (instructorCheck != null) {
        putDocument(makeAttributes(instructorCheck));
    }
// TODO: reuse the method in the parent class instead
}
Also used : Instructor(teammates.storage.entity.Instructor) InstructorAttributes(teammates.common.datatransfer.attributes.InstructorAttributes)

Example 7 with Instructor

use of teammates.storage.entity.Instructor 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)

Aggregations

Instructor (teammates.storage.entity.Instructor)7 InstructorAttributes (teammates.common.datatransfer.attributes.InstructorAttributes)4 InvalidParametersException (teammates.common.exception.InvalidParametersException)3 Test (org.testng.annotations.Test)2 InstructorPrivileges (teammates.common.datatransfer.InstructorPrivileges)2 EntityDoesNotExistException (teammates.common.exception.EntityDoesNotExistException)2 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 Set (java.util.Set)1 CourseStudent (teammates.storage.entity.CourseStudent)1