use of teammates.common.datatransfer.attributes.FeedbackResponseCommentAttributes in project teammates by TEAMMATES.
the class BackDoorLogic method putDocuments.
/**
* Creates document for entities that have document, i.e. searchable.
* @return status of the request in the form 'status meassage'+'additional
* info (if any)' e.g., "[BACKEND_STATUS_SUCCESS]" e.g.,
* "[BACKEND_STATUS_FAILURE]NullPointerException at ..."
*/
public String putDocuments(DataBundle dataBundle) {
// query the entity in db first to get the actual data and create document for actual entity
Map<String, StudentAttributes> students = dataBundle.students;
for (StudentAttributes student : students.values()) {
StudentAttributes studentInDb = studentsDb.getStudentForEmail(student.course, student.email);
studentsDb.putDocument(studentInDb);
}
Map<String, InstructorAttributes> instructors = dataBundle.instructors;
for (InstructorAttributes instructor : instructors.values()) {
InstructorAttributes instructorInDb = instructorsDb.getInstructorForEmail(instructor.courseId, instructor.email);
instructorsDb.putDocument(instructorInDb);
}
Map<String, FeedbackResponseCommentAttributes> responseComments = dataBundle.feedbackResponseComments;
for (FeedbackResponseCommentAttributes responseComment : responseComments.values()) {
FeedbackResponseCommentAttributes fcInDb = fcDb.getFeedbackResponseComment(responseComment.courseId, responseComment.createdAt, responseComment.giverEmail);
fcDb.putDocument(fcInDb);
}
return Const.StatusCodes.BACKDOOR_STATUS_SUCCESS;
}
use of teammates.common.datatransfer.attributes.FeedbackResponseCommentAttributes in project teammates by TEAMMATES.
the class DataMigrationForFeedbackResponseCommentSearchDocument method postAction.
/**
* {@inheritDoc}
*/
@Override
protected void postAction() {
if (isPreview()) {
return;
}
LoopHelper loopHelper = new LoopHelper(BATCH_SIZE, "documents processed.");
List<Document> documentsToUpdate = new ArrayList<>();
for (FeedbackResponseCommentAttributes comment : commentsToMigrate) {
loopHelper.recordLoop();
documentsToUpdate.add(new FeedbackResponseCommentSearchDocument(comment).build());
if (documentsToUpdate.size() == BATCH_SIZE) {
updateAndClearDocuments(documentsToUpdate);
}
}
updateAndClearDocuments(documentsToUpdate);
}
use of teammates.common.datatransfer.attributes.FeedbackResponseCommentAttributes in project teammates by TEAMMATES.
the class FeedbackResponseCommentsLogicTest method restoreFrCommentFromDataBundle.
private FeedbackResponseCommentAttributes restoreFrCommentFromDataBundle(String existingFrCommentInDataBundle) {
FeedbackResponseCommentAttributes existingFrComment = dataBundle.feedbackResponseComments.get(existingFrCommentInDataBundle);
FeedbackResponseCommentAttributes frComment = FeedbackResponseCommentAttributes.builder(existingFrComment.courseId, existingFrComment.feedbackSessionName, existingFrComment.giverEmail, existingFrComment.commentText).withFeedbackQuestionId(existingFrComment.feedbackQuestionId).withFeedbackResponseId(existingFrComment.feedbackResponseId).withCreatedAt(existingFrComment.createdAt).build();
restoreFrCommentIdFromExistingOne(frComment, existingFrComment);
return frComment;
}
use of teammates.common.datatransfer.attributes.FeedbackResponseCommentAttributes in project teammates by TEAMMATES.
the class FeedbackResponseCommentsLogicTest method testUpdateFeedbackResponseComment.
@Test
public void testUpdateFeedbackResponseComment() throws Exception {
FeedbackResponseCommentAttributes frComment = restoreFrCommentFromDataBundle("comment1FromT1C1ToR1Q1S1C1");
______TS("fail: invalid params");
frComment.courseId = "invalid course name";
String expectedError = "\"" + frComment.courseId + "\" is not acceptable to TEAMMATES as a/an course ID " + "because it is not in the correct format. A course ID can contain letters, " + "numbers, fullstops, hyphens, underscores, and dollar signs. It cannot be longer " + "than 40 characters, cannot be empty and cannot contain spaces.";
verifyExceptionThrownWhenUpdateFrComment(frComment, expectedError);
frComment = restoreFrCommentFromDataBundle("comment1FromT1C1ToR1Q1S1C1");
______TS("typical success case");
frComment.commentText = new Text("Updated feedback response comment");
frcLogic.updateFeedbackResponseComment(frComment);
verifyPresentInDatastore(frComment);
List<FeedbackResponseCommentAttributes> actualFrComments = frcLogic.getFeedbackResponseCommentForSession(frComment.courseId, frComment.feedbackSessionName);
FeedbackResponseCommentAttributes actualFrComment = null;
for (int i = 0; i < actualFrComments.size(); i++) {
if (actualFrComments.get(i).commentText.equals(frComment.commentText)) {
actualFrComment = actualFrComments.get(i);
break;
}
}
assertNotNull(actualFrComment);
______TS("typical success case update feedback response comment giver email");
String oldEmail = frComment.giverEmail;
String updatedEmail = "newEmail@gmail.tmt";
frcLogic.updateFeedbackResponseCommentsEmails(frComment.courseId, oldEmail, updatedEmail);
actualFrComment = frcLogic.getFeedbackResponseComment(frComment.feedbackResponseId, updatedEmail, frComment.createdAt);
assertEquals(frComment.courseId, actualFrComment.courseId);
assertEquals(updatedEmail, actualFrComment.giverEmail);
assertEquals(updatedEmail, actualFrComment.lastEditorEmail);
assertEquals(frComment.feedbackSessionName, actualFrComment.feedbackSessionName);
// reset email
frcLogic.updateFeedbackResponseCommentsEmails(frComment.courseId, updatedEmail, oldEmail);
______TS("typical success case update feedback response comment feedbackResponseId");
String oldId = frComment.feedbackResponseId;
String updatedId = "newResponseId";
frcLogic.updateFeedbackResponseCommentsForChangingResponseId(oldId, updatedId);
actualFrComment = frcLogic.getFeedbackResponseComment(updatedId, frComment.giverEmail, frComment.createdAt);
assertEquals(frComment.courseId, actualFrComment.courseId);
assertEquals(updatedId, actualFrComment.feedbackResponseId);
assertEquals(frComment.feedbackSessionName, actualFrComment.feedbackSessionName);
// reset id
frcLogic.updateFeedbackResponseCommentsForChangingResponseId(updatedId, oldId);
}
use of teammates.common.datatransfer.attributes.FeedbackResponseCommentAttributes in project teammates by TEAMMATES.
the class FeedbackResponseCommentsLogicTest method testGetFeedbackResponseComments.
@Test
public void testGetFeedbackResponseComments() {
FeedbackResponseCommentAttributes frComment = restoreFrCommentFromDataBundle("comment1FromT1C1ToR1Q1S1C1");
List<FeedbackResponseCommentAttributes> expectedFrComments = new ArrayList<>();
______TS("fail: invalid parameters");
frComment.courseId = "invalid course id";
frComment.giverEmail = "invalid giver email";
verifyNullFromGetFrCommentForSession(frComment);
verifyNullFromGetFrComment(frComment);
frComment = restoreFrCommentFromDataBundle("comment1FromT1C1ToR1Q1S1C1");
______TS("Typical successful case");
List<FeedbackResponseCommentAttributes> actualFrComments = frcLogic.getFeedbackResponseCommentForSession(frComment.courseId, frComment.feedbackSessionName);
FeedbackResponseCommentAttributes actualFrComment = actualFrComments.get(0);
assertEquals(frComment.courseId, actualFrComment.courseId);
assertEquals(frComment.giverEmail, actualFrComment.giverEmail);
assertEquals(frComment.feedbackSessionName, actualFrComment.feedbackSessionName);
______TS("Typical successful case by feedback response comment details");
actualFrComment = frcLogic.getFeedbackResponseComment(frComment.feedbackResponseId, frComment.giverEmail, frComment.createdAt);
assertEquals(frComment.courseId, actualFrComment.courseId);
assertEquals(frComment.giverEmail, actualFrComment.giverEmail);
assertEquals(frComment.feedbackSessionName, actualFrComment.feedbackSessionName);
______TS("Typical successful case by feedback response id");
actualFrComments = frcLogic.getFeedbackResponseCommentForResponse(frComment.feedbackResponseId);
actualFrComment = actualFrComments.get(0);
assertEquals(frComment.courseId, actualFrComment.courseId);
assertEquals(frComment.giverEmail, actualFrComment.giverEmail);
assertEquals(frComment.feedbackSessionName, actualFrComment.feedbackSessionName);
______TS("Typical successful case by feedback response comment id");
actualFrComment = frcLogic.getFeedbackResponseComment(frComment.getId());
assertEquals(frComment.courseId, actualFrComment.courseId);
assertEquals(frComment.giverEmail, actualFrComment.giverEmail);
assertEquals(frComment.feedbackSessionName, actualFrComment.feedbackSessionName);
______TS("Typical successful case for giver");
actualFrComments = frcLogic.getFeedbackResponseCommentsForGiver(frComment.courseId, frComment.giverEmail);
FeedbackResponseCommentAttributes tempFrComment = restoreFrCommentFromDataBundle("comment1FromT1C1ToR1Q1S1C1");
expectedFrComments.add(tempFrComment);
tempFrComment = restoreFrCommentFromDataBundle("comment1FromT1C1ToR1Q2S1C1");
expectedFrComments.add(tempFrComment);
tempFrComment = restoreFrCommentFromDataBundle("comment1FromT1C1ToR1Q3S1C1");
expectedFrComments.add(tempFrComment);
assertEquals(expectedFrComments.size(), actualFrComments.size());
for (int i = 0; i < expectedFrComments.size(); i++) {
assertEquals(expectedFrComments.get(i).courseId, actualFrComments.get(i).courseId);
assertEquals(expectedFrComments.get(i).giverEmail, actualFrComments.get(i).giverEmail);
assertEquals(expectedFrComments.get(i).feedbackSessionName, actualFrComments.get(i).feedbackSessionName);
}
}
Aggregations