Search in sources :

Example 36 with EntityDoesNotExistException

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

the class StudentsLogic method enrollStudents.

private CourseEnrollmentResult enrollStudents(String enrollLines, String courseId, boolean hasDocument) throws EntityDoesNotExistException, EnrollException, InvalidParametersException, EntityAlreadyExistsException {
    if (!coursesLogic.isCoursePresent(courseId)) {
        throw new EntityDoesNotExistException("Course does not exist :" + courseId);
    }
    if (enrollLines.isEmpty()) {
        throw new EnrollException(Const.StatusMessages.ENROLL_LINE_EMPTY);
    }
    List<StudentAttributes> studentList = createStudents(enrollLines, courseId);
    ArrayList<StudentAttributes> returnList = new ArrayList<>();
    ArrayList<StudentEnrollDetails> enrollmentList = new ArrayList<>();
    verifyIsWithinSizeLimitPerEnrollment(studentList);
    validateSectionsAndTeams(studentList, courseId);
    // enroll all students
    for (StudentAttributes student : studentList) {
        StudentEnrollDetails enrollmentDetails;
        enrollmentDetails = enrollStudent(student, hasDocument);
        student.updateStatus = enrollmentDetails.updateStatus;
        enrollmentList.add(enrollmentDetails);
        returnList.add(student);
    }
    // add to return list students not included in the enroll list.
    List<StudentAttributes> studentsInCourse = getStudentsForCourse(courseId);
    for (StudentAttributes student : studentsInCourse) {
        if (!isInEnrollList(student, returnList)) {
            student.updateStatus = StudentUpdateStatus.NOT_IN_ENROLL_LIST;
            returnList.add(student);
        }
    }
    return new CourseEnrollmentResult(returnList, enrollmentList);
}
Also used : EnrollException(teammates.common.exception.EnrollException) CourseEnrollmentResult(teammates.common.datatransfer.CourseEnrollmentResult) ArrayList(java.util.ArrayList) StudentEnrollDetails(teammates.common.datatransfer.StudentEnrollDetails) StudentAttributes(teammates.common.datatransfer.attributes.StudentAttributes) EntityDoesNotExistException(teammates.common.exception.EntityDoesNotExistException)

Example 37 with EntityDoesNotExistException

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

the class AccountsDb method updateAccount.

/**
 * Preconditions:
 * <br> * {@code accountToAdd} is not null and has valid data.
 */
public void updateAccount(AccountAttributes a, boolean updateStudentProfile) throws InvalidParametersException, EntityDoesNotExistException {
    Assumption.assertNotNull(Const.StatusCodes.DBLEVEL_NULL_INPUT, a);
    if (!a.isValid()) {
        throw new InvalidParametersException(a.getInvalidityInfo());
    }
    Account accountToUpdate = getAccountEntity(a.googleId, updateStudentProfile);
    if (accountToUpdate == null) {
        throw new EntityDoesNotExistException(ERROR_UPDATE_NON_EXISTENT_ACCOUNT + a.googleId + ThreadHelper.getCurrentThreadStack());
    }
    a.sanitizeForSaving();
    accountToUpdate.setName(a.name);
    accountToUpdate.setEmail(a.email);
    accountToUpdate.setIsInstructor(a.isInstructor);
    accountToUpdate.setInstitute(a.institute);
    if (updateStudentProfile) {
        StudentProfile existingProfile = accountToUpdate.getStudentProfile();
        if (existingProfile == null) {
            existingProfile = new StudentProfile(a.studentProfile.googleId);
        }
        StudentProfileAttributes existingProfileAttributes = StudentProfileAttributes.valueOf(existingProfile);
        a.studentProfile.modifiedDate = existingProfileAttributes.modifiedDate;
        // this is to maintain integrity of the modified date.
        if (!existingProfileAttributes.toString().equals(a.studentProfile.toString())) {
            StudentProfile updatedProfile = a.studentProfile.toEntity();
            accountToUpdate.setStudentProfile(updatedProfile);
            profilesDb.saveEntity(updatedProfile);
        }
    }
    saveEntity(accountToUpdate, a);
}
Also used : StudentProfile(teammates.storage.entity.StudentProfile) Account(teammates.storage.entity.Account) InvalidParametersException(teammates.common.exception.InvalidParametersException) StudentProfileAttributes(teammates.common.datatransfer.attributes.StudentProfileAttributes) EntityDoesNotExistException(teammates.common.exception.EntityDoesNotExistException)

Example 38 with EntityDoesNotExistException

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

the class AdminEmailsDb method updateAdminEmailById.

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

Example 39 with EntityDoesNotExistException

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

the class FeedbackSessionsDb method clearStudentRespondents.

public void clearStudentRespondents(FeedbackSessionAttributes feedbackSession) throws InvalidParametersException, EntityDoesNotExistException {
    Assumption.assertNotNull(Const.StatusCodes.DBLEVEL_NULL_INPUT, feedbackSession);
    feedbackSession.sanitizeForSaving();
    if (!feedbackSession.isValid()) {
        throw new InvalidParametersException(feedbackSession.getInvalidityInfo());
    }
    FeedbackSession fs = getEntity(feedbackSession);
    if (fs == null) {
        throw new EntityDoesNotExistException(ERROR_UPDATE_NON_EXISTENT + feedbackSession.toString());
    }
    fs.getRespondingStudentList().clear();
    saveEntity(fs, feedbackSession);
}
Also used : FeedbackSession(teammates.storage.entity.FeedbackSession) InvalidParametersException(teammates.common.exception.InvalidParametersException) EntityDoesNotExistException(teammates.common.exception.EntityDoesNotExistException)

Example 40 with EntityDoesNotExistException

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

the class FeedbackSessionsDb method addInstructorRespondents.

// The objectify library does not support throwing checked exceptions inside transactions
@SuppressWarnings("PMD.AvoidThrowingRawExceptionTypes")
public void addInstructorRespondents(List<String> emails, FeedbackSessionAttributes feedbackSession) throws InvalidParametersException, EntityDoesNotExistException {
    Assumption.assertNotNull(Const.StatusCodes.DBLEVEL_NULL_INPUT, emails);
    Assumption.assertNotNull(Const.StatusCodes.DBLEVEL_NULL_INPUT, feedbackSession);
    feedbackSession.sanitizeForSaving();
    if (!feedbackSession.isValid()) {
        throw new InvalidParametersException(feedbackSession.getInvalidityInfo());
    }
    try {
        ofy().transact(new VoidWork() {

            @Override
            public void vrun() {
                FeedbackSession fs = getEntity(feedbackSession);
                if (fs == null) {
                    throw new RuntimeException(new EntityDoesNotExistException(ERROR_UPDATE_NON_EXISTENT + feedbackSession.toString()));
                }
                fs.getRespondingInstructorList().addAll(emails);
                saveEntity(fs, feedbackSession);
            }
        });
    } catch (RuntimeException e) {
        if (e.getCause() instanceof EntityDoesNotExistException) {
            throw (EntityDoesNotExistException) e.getCause();
        }
        throw e;
    }
}
Also used : FeedbackSession(teammates.storage.entity.FeedbackSession) VoidWork(com.googlecode.objectify.VoidWork) InvalidParametersException(teammates.common.exception.InvalidParametersException) 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