Search in sources :

Example 6 with EntityAlreadyExistsException

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

the class InstructorCourseInstructorAddAction method execute.

@Override
protected ActionResult execute() {
    String courseId = getRequestParamValue(Const.ParamsNames.COURSE_ID);
    Assumption.assertPostParamNotNull(Const.ParamsNames.COURSE_ID, courseId);
    String instructorName = getRequestParamValue(Const.ParamsNames.INSTRUCTOR_NAME);
    Assumption.assertPostParamNotNull(Const.ParamsNames.INSTRUCTOR_NAME, instructorName);
    String instructorEmail = getRequestParamValue(Const.ParamsNames.INSTRUCTOR_EMAIL);
    Assumption.assertPostParamNotNull(Const.ParamsNames.INSTRUCTOR_EMAIL, instructorEmail);
    InstructorAttributes instructor = logic.getInstructorForGoogleId(courseId, account.googleId);
    gateKeeper.verifyAccessible(instructor, logic.getCourse(courseId), Const.ParamsNames.INSTRUCTOR_PERMISSION_MODIFY_INSTRUCTOR);
    InstructorAttributes instructorToAdd = extractCompleteInstructor(courseId, instructorName, instructorEmail);
    /* Process adding the instructor and setup status to be shown to user and admin */
    try {
        logic.createInstructor(instructorToAdd);
        taskQueuer.scheduleCourseRegistrationInviteToInstructor(loggedInUser.googleId, instructorEmail, courseId);
        statusToUser.add(new StatusMessage(String.format(Const.StatusMessages.COURSE_INSTRUCTOR_ADDED, instructorName, instructorEmail), StatusMessageColor.SUCCESS));
        statusToAdmin = "New instructor (<span class=\"bold\"> " + instructorEmail + "</span>)" + " for Course <span class=\"bold\">[" + courseId + "]</span> created.<br>";
    } catch (EntityAlreadyExistsException e) {
        setStatusForException(e, Const.StatusMessages.COURSE_INSTRUCTOR_EXISTS);
    } catch (InvalidParametersException e) {
        setStatusForException(e);
    }
    RedirectResult redirectResult = createRedirectResult(Const.ActionURIs.INSTRUCTOR_COURSE_EDIT_PAGE);
    redirectResult.addResponseParam(Const.ParamsNames.COURSE_ID, courseId);
    return redirectResult;
}
Also used : EntityAlreadyExistsException(teammates.common.exception.EntityAlreadyExistsException) InvalidParametersException(teammates.common.exception.InvalidParametersException) InstructorAttributes(teammates.common.datatransfer.attributes.InstructorAttributes) StatusMessage(teammates.common.util.StatusMessage)

Example 7 with EntityAlreadyExistsException

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

the class FeedbackSessionsLogicTest method testCreateAndDeleteFeedbackSession.

private void testCreateAndDeleteFeedbackSession() throws InvalidParametersException, EntityAlreadyExistsException {
    ______TS("test create");
    FeedbackSessionAttributes fs = getNewFeedbackSession();
    fsLogic.createFeedbackSession(fs);
    verifyPresentInDatastore(fs);
    ______TS("test create with invalid session name");
    fs.setFeedbackSessionName("test & test");
    try {
        fsLogic.createFeedbackSession(fs);
        signalFailureToDetectException();
    } catch (Exception e) {
        assertEquals("The provided feedback session name is not acceptable to TEAMMATES " + "as it cannot contain the following special html characters in brackets: " + "(&lt; &gt; &quot; &#x2f; &#39; &amp;)", e.getMessage());
    }
    fs.setFeedbackSessionName("test %| test");
    try {
        fsLogic.createFeedbackSession(fs);
        signalFailureToDetectException();
    } catch (Exception e) {
        assertEquals("\"test %| test\" is not acceptable to TEAMMATES as a/an feedback session name " + "because it contains invalid characters. A/An feedback session name " + "must start with an alphanumeric character, and cannot contain " + "any vertical bar (|) or percent sign (%).", e.getMessage());
    }
    ______TS("test delete");
    fs = getNewFeedbackSession();
    // Create a question under the session to test for cascading during delete.
    FeedbackQuestionAttributes fq = new FeedbackQuestionAttributes();
    fq.feedbackSessionName = fs.getFeedbackSessionName();
    fq.courseId = fs.getCourseId();
    fq.questionNumber = 1;
    fq.creatorEmail = fs.getCreatorEmail();
    fq.numberOfEntitiesToGiveFeedbackTo = Const.MAX_POSSIBLE_RECIPIENTS;
    fq.giverType = FeedbackParticipantType.STUDENTS;
    fq.recipientType = FeedbackParticipantType.TEAMS;
    fq.questionMetaData = new Text("question to be deleted through cascade");
    fq.questionType = FeedbackQuestionType.TEXT;
    fq.showResponsesTo = new ArrayList<>();
    fq.showRecipientNameTo = new ArrayList<>();
    fq.showGiverNameTo = new ArrayList<>();
    fqLogic.createFeedbackQuestion(fq);
    fsLogic.deleteFeedbackSessionCascade(fs.getFeedbackSessionName(), fs.getCourseId());
    verifyAbsentInDatastore(fs);
    verifyAbsentInDatastore(fq);
}
Also used : FeedbackSessionAttributes(teammates.common.datatransfer.attributes.FeedbackSessionAttributes) FeedbackQuestionAttributes(teammates.common.datatransfer.attributes.FeedbackQuestionAttributes) Text(com.google.appengine.api.datastore.Text) EntityDoesNotExistException(teammates.common.exception.EntityDoesNotExistException) InvalidParametersException(teammates.common.exception.InvalidParametersException) EntityAlreadyExistsException(teammates.common.exception.EntityAlreadyExistsException)

Example 8 with EntityAlreadyExistsException

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

the class FeedbackResponsesLogic method recreateResponse.

private void recreateResponse(FeedbackResponseAttributes newResponse, FeedbackResponseAttributes oldResponse) throws InvalidParametersException, EntityAlreadyExistsException, EntityDoesNotExistException {
    try {
        newResponse.setId(null);
        FeedbackResponse createdResponseEntity = frDb.createEntity(newResponse);
        frDb.deleteEntity(oldResponse);
        frcLogic.updateFeedbackResponseCommentsForChangingResponseId(oldResponse.getId(), createdResponseEntity.getId());
    } catch (EntityAlreadyExistsException e) {
        log.warning("Trying to update an existing response to one that already exists.");
        throw e;
    }
}
Also used : EntityAlreadyExistsException(teammates.common.exception.EntityAlreadyExistsException) FeedbackResponse(teammates.storage.entity.FeedbackResponse)

Example 9 with EntityAlreadyExistsException

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

the class FeedbackSessionsLogicTest method testCopyFeedbackSession.

private void testCopyFeedbackSession() throws Exception {
    ______TS("Test copy");
    FeedbackSessionAttributes session1InCourse1 = dataBundle.feedbackSessions.get("session1InCourse1");
    InstructorAttributes instructor2OfCourse1 = dataBundle.instructors.get("instructor2OfCourse1");
    CourseAttributes typicalCourse2 = dataBundle.courses.get("typicalCourse2");
    FeedbackSessionAttributes copiedSession = fsLogic.copyFeedbackSession("Copied Session", typicalCourse2.getId(), session1InCourse1.getFeedbackSessionName(), session1InCourse1.getCourseId(), instructor2OfCourse1.email);
    verifyPresentInDatastore(copiedSession);
    assertEquals("Copied Session", copiedSession.getFeedbackSessionName());
    assertEquals(typicalCourse2.getId(), copiedSession.getCourseId());
    List<FeedbackQuestionAttributes> questions1 = fqLogic.getFeedbackQuestionsForSession(session1InCourse1.getFeedbackSessionName(), session1InCourse1.getCourseId());
    List<FeedbackQuestionAttributes> questions2 = fqLogic.getFeedbackQuestionsForSession(copiedSession.getFeedbackSessionName(), copiedSession.getCourseId());
    assertEquals(questions1.size(), questions2.size());
    for (int i = 0; i < questions1.size(); i++) {
        FeedbackQuestionAttributes question1 = questions1.get(i);
        FeedbackQuestionDetails questionDetails1 = question1.getQuestionDetails();
        FeedbackQuestionAttributes question2 = questions2.get(i);
        FeedbackQuestionDetails questionDetails2 = question2.getQuestionDetails();
        assertEquals(questionDetails1.getQuestionText(), questionDetails2.getQuestionText());
        assertEquals(question1.giverType, question2.giverType);
        assertEquals(question1.recipientType, question2.recipientType);
        assertEquals(question1.questionType, question2.questionType);
        assertEquals(question1.numberOfEntitiesToGiveFeedbackTo, question2.numberOfEntitiesToGiveFeedbackTo);
    }
    assertEquals(0, copiedSession.getRespondingInstructorList().size());
    assertEquals(0, copiedSession.getRespondingStudentList().size());
    ______TS("Failure case: duplicate session");
    try {
        fsLogic.copyFeedbackSession(session1InCourse1.getFeedbackSessionName(), session1InCourse1.getCourseId(), session1InCourse1.getFeedbackSessionName(), session1InCourse1.getCourseId(), instructor2OfCourse1.email);
        signalFailureToDetectException();
    } catch (EntityAlreadyExistsException e) {
        ignoreExpectedException();
    }
    fsLogic.deleteFeedbackSessionCascade(copiedSession.getFeedbackSessionName(), copiedSession.getCourseId());
}
Also used : FeedbackSessionAttributes(teammates.common.datatransfer.attributes.FeedbackSessionAttributes) FeedbackQuestionDetails(teammates.common.datatransfer.questions.FeedbackQuestionDetails) EntityAlreadyExistsException(teammates.common.exception.EntityAlreadyExistsException) FeedbackQuestionAttributes(teammates.common.datatransfer.attributes.FeedbackQuestionAttributes) InstructorAttributes(teammates.common.datatransfer.attributes.InstructorAttributes) CourseAttributes(teammates.common.datatransfer.attributes.CourseAttributes)

Example 10 with EntityAlreadyExistsException

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

the class InstructorsLogicTest method testAddInstructor.

private void testAddInstructor() throws Exception {
    ______TS("success: add an instructor");
    String courseId = "test-course";
    String name = "New Instructor";
    String email = "ILT.instr@email.tmt";
    String role = Const.InstructorPermissionRoleNames.INSTRUCTOR_PERMISSION_ROLE_COOWNER;
    String displayedName = InstructorAttributes.DEFAULT_DISPLAY_NAME;
    InstructorPrivileges privileges = new InstructorPrivileges(Const.InstructorPermissionRoleNames.INSTRUCTOR_PERMISSION_ROLE_COOWNER);
    InstructorAttributes instr = InstructorAttributes.builder(null, courseId, name, email).withRole(role).withDisplayedName(displayedName).withPrivileges(privileges).build();
    instructorsLogic.createInstructor(instr);
    verifyPresentInDatastore(instr);
    ______TS("failure: instructor already exists");
    try {
        instructorsLogic.createInstructor(instr);
        signalFailureToDetectException();
    } catch (EntityAlreadyExistsException e) {
        AssertHelper.assertContains("Trying to create a Instructor that exists", e.getMessage());
    }
    instructorsLogic.deleteInstructorCascade(instr.courseId, instr.email);
    ______TS("failure: invalid parameter");
    instr.email = "invalidEmail.tmt";
    String expectedError = "\"" + instr.email + "\" is not acceptable to TEAMMATES as a/an email " + "because it is not in the correct format. An email address contains " + "some text followed by one '@' sign followed by some more text. " + "It cannot be longer than 254 characters, cannot be empty and " + "cannot contain spaces.";
    try {
        instructorsLogic.createInstructor(instr);
        signalFailureToDetectException();
    } catch (InvalidParametersException e) {
        assertEquals(expectedError, e.getMessage());
    }
    ______TS("failure: null parameters");
    try {
        instructorsLogic.createInstructor(null);
        signalFailureToDetectException();
    } catch (AssertionError e) {
        AssertHelper.assertContains("Supplied parameter was null", e.getMessage());
    }
}
Also used : EntityAlreadyExistsException(teammates.common.exception.EntityAlreadyExistsException) InvalidParametersException(teammates.common.exception.InvalidParametersException) InstructorPrivileges(teammates.common.datatransfer.InstructorPrivileges) InstructorAttributes(teammates.common.datatransfer.attributes.InstructorAttributes)

Aggregations

EntityAlreadyExistsException (teammates.common.exception.EntityAlreadyExistsException)23 InvalidParametersException (teammates.common.exception.InvalidParametersException)19 InstructorAttributes (teammates.common.datatransfer.attributes.InstructorAttributes)10 Test (org.testng.annotations.Test)7 FeedbackSessionAttributes (teammates.common.datatransfer.attributes.FeedbackSessionAttributes)7 StatusMessage (teammates.common.util.StatusMessage)7 CourseAttributes (teammates.common.datatransfer.attributes.CourseAttributes)4 FeedbackResponseAttributes (teammates.common.datatransfer.attributes.FeedbackResponseAttributes)4 ArrayList (java.util.ArrayList)3 InstructorPrivileges (teammates.common.datatransfer.InstructorPrivileges)3 FeedbackQuestionAttributes (teammates.common.datatransfer.attributes.FeedbackQuestionAttributes)3 StudentAttributes (teammates.common.datatransfer.attributes.StudentAttributes)3 EntityDoesNotExistException (teammates.common.exception.EntityDoesNotExistException)3 Text (com.google.appengine.api.datastore.Text)2 List (java.util.List)2 EnrollException (teammates.common.exception.EnrollException)2 InstructorCourseEnrollPageData (teammates.ui.pagedata.InstructorCourseEnrollPageData)2 InstructorCourseEnrollResultPageData (teammates.ui.pagedata.InstructorCourseEnrollResultPageData)2 Comparator (java.util.Comparator)1 CourseEnrollmentResult (teammates.common.datatransfer.CourseEnrollmentResult)1