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;
}
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: " + "(< > " / ' &)", 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);
}
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;
}
}
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());
}
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());
}
}
Aggregations