Search in sources :

Example 6 with FeedbackResponseCommentAttributes

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;
}
Also used : FeedbackResponseCommentAttributes(teammates.common.datatransfer.attributes.FeedbackResponseCommentAttributes) StudentAttributes(teammates.common.datatransfer.attributes.StudentAttributes) InstructorAttributes(teammates.common.datatransfer.attributes.InstructorAttributes)

Example 7 with FeedbackResponseCommentAttributes

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);
}
Also used : FeedbackResponseCommentSearchDocument(teammates.storage.search.FeedbackResponseCommentSearchDocument) FeedbackResponseCommentAttributes(teammates.common.datatransfer.attributes.FeedbackResponseCommentAttributes) LoopHelper(teammates.client.scripts.util.LoopHelper) ArrayList(java.util.ArrayList) Document(com.google.appengine.api.search.Document) FeedbackResponseCommentSearchDocument(teammates.storage.search.FeedbackResponseCommentSearchDocument)

Example 8 with FeedbackResponseCommentAttributes

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;
}
Also used : FeedbackResponseCommentAttributes(teammates.common.datatransfer.attributes.FeedbackResponseCommentAttributes)

Example 9 with FeedbackResponseCommentAttributes

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);
}
Also used : FeedbackResponseCommentAttributes(teammates.common.datatransfer.attributes.FeedbackResponseCommentAttributes) Text(com.google.appengine.api.datastore.Text) Test(org.testng.annotations.Test)

Example 10 with FeedbackResponseCommentAttributes

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);
    }
}
Also used : FeedbackResponseCommentAttributes(teammates.common.datatransfer.attributes.FeedbackResponseCommentAttributes) ArrayList(java.util.ArrayList) Test(org.testng.annotations.Test)

Aggregations

FeedbackResponseCommentAttributes (teammates.common.datatransfer.attributes.FeedbackResponseCommentAttributes)46 FeedbackResponseAttributes (teammates.common.datatransfer.attributes.FeedbackResponseAttributes)15 Test (org.testng.annotations.Test)13 Text (com.google.appengine.api.datastore.Text)12 ArrayList (java.util.ArrayList)12 FeedbackQuestionAttributes (teammates.common.datatransfer.attributes.FeedbackQuestionAttributes)9 FeedbackSessionAttributes (teammates.common.datatransfer.attributes.FeedbackSessionAttributes)9 InstructorAttributes (teammates.common.datatransfer.attributes.InstructorAttributes)9 StudentAttributes (teammates.common.datatransfer.attributes.StudentAttributes)6 FeedbackResponseCommentsDb (teammates.storage.api.FeedbackResponseCommentsDb)6 FeedbackQuestionsDb (teammates.storage.api.FeedbackQuestionsDb)5 FeedbackResponsesDb (teammates.storage.api.FeedbackResponsesDb)5 InstructorFeedbackResponseCommentAjaxPageData (teammates.ui.pagedata.InstructorFeedbackResponseCommentAjaxPageData)4 FeedbackResponseCommentRow (teammates.ui.template.FeedbackResponseCommentRow)4 InvalidParametersException (teammates.common.exception.InvalidParametersException)3 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 List (java.util.List)2 FeedbackResponseCommentSearchResultBundle (teammates.common.datatransfer.FeedbackResponseCommentSearchResultBundle)2 FeedbackSessionResultsBundle (teammates.common.datatransfer.FeedbackSessionResultsBundle)2