Search in sources :

Example 46 with FeedbackResponseAttributes

use of teammates.common.datatransfer.attributes.FeedbackResponseAttributes in project teammates by TEAMMATES.

the class FeedbackResponsesDbTest method testTimestamp.

@Test
public void testTimestamp() throws InvalidParametersException, EntityAlreadyExistsException, EntityDoesNotExistException {
    ______TS("success : created");
    FeedbackResponseAttributes fra = getNewFeedbackResponseAttributes();
    // remove possibly conflicting entity from the database
    frDb.deleteEntity(fra);
    frDb.createEntity(fra);
    verifyPresentInDatastore(fra);
    String feedbackQuestionId = fra.feedbackQuestionId;
    String giverEmail = fra.giver;
    String recipientEmail = fra.recipient;
    FeedbackResponseAttributes feedbackResponse = frDb.getFeedbackResponse(feedbackQuestionId, giverEmail, recipientEmail);
    // Assert dates are now.
    AssertHelper.assertInstantIsNow(feedbackResponse.getCreatedAt());
    AssertHelper.assertInstantIsNow(feedbackResponse.getUpdatedAt());
    ______TS("success : update lastUpdated");
    String newRecipientEmail = "new-email@tmt.com";
    feedbackResponse.recipient = newRecipientEmail;
    frDb.updateFeedbackResponse(feedbackResponse);
    FeedbackResponseAttributes updatedFr = frDb.getFeedbackResponse(feedbackQuestionId, giverEmail, newRecipientEmail);
    // Assert lastUpdate has changed, and is now.
    assertFalse(feedbackResponse.getUpdatedAt().equals(updatedFr.getUpdatedAt()));
    AssertHelper.assertInstantIsNow(updatedFr.getUpdatedAt());
    ______TS("success : keep lastUpdated");
    String newRecipientEmailTwo = "new-email-two@tmt.com";
    feedbackResponse.recipient = newRecipientEmailTwo;
    frDb.updateFeedbackResponse(feedbackResponse, true);
    FeedbackResponseAttributes updatedFrTwo = frDb.getFeedbackResponse(feedbackQuestionId, giverEmail, newRecipientEmailTwo);
    // Assert lastUpdate has NOT changed.
    assertEquals(updatedFr.getUpdatedAt(), updatedFrTwo.getUpdatedAt());
}
Also used : FeedbackResponseAttributes(teammates.common.datatransfer.attributes.FeedbackResponseAttributes) Test(org.testng.annotations.Test)

Example 47 with FeedbackResponseAttributes

use of teammates.common.datatransfer.attributes.FeedbackResponseAttributes in project teammates by TEAMMATES.

the class FeedbackResponsesDbTest method testGetFeedbackResponses.

@Test
public void testGetFeedbackResponses() {
    ______TS("standard success case");
    FeedbackResponseAttributes expected = getResponseAttributes("response1ForQ1S1C1");
    FeedbackResponseAttributes actual = frDb.getFeedbackResponse(expected.feedbackQuestionId, expected.giver, expected.recipient);
    assertEquals(expected.toString(), actual.toString());
    ______TS("non-existent response");
    assertNull(frDb.getFeedbackResponse(expected.feedbackQuestionId, "student1InCourse1@gmail.tmt", "student3InCourse1@gmail.tmt"));
    ______TS("null fqId");
    try {
        frDb.getFeedbackResponse(null, "student1InCourse1@gmail.tmt", "student1InCourse1@gmail.tmt");
        signalFailureToDetectException();
    } catch (AssertionError e) {
        AssertHelper.assertContains(Const.StatusCodes.DBLEVEL_NULL_INPUT, e.getLocalizedMessage());
    }
    ______TS("null giverEmail");
    try {
        frDb.getFeedbackResponse(expected.feedbackQuestionId, null, "student1InCourse1@gmail.tmt");
        signalFailureToDetectException();
    } catch (AssertionError e) {
        AssertHelper.assertContains(Const.StatusCodes.DBLEVEL_NULL_INPUT, e.getLocalizedMessage());
    }
    ______TS("null receiverEmail");
    try {
        frDb.getFeedbackResponse(expected.feedbackQuestionId, "student1InCourse1@gmail.tmt", null);
        signalFailureToDetectException();
    } catch (AssertionError e) {
        AssertHelper.assertContains(Const.StatusCodes.DBLEVEL_NULL_INPUT, e.getLocalizedMessage());
    }
    ______TS("get by id");
    // Id from first success case
    actual = frDb.getFeedbackResponse(actual.getId());
    assertEquals(expected.toString(), actual.toString());
    ______TS("get non-existent response by id");
    actual = frDb.getFeedbackResponse("non-existent id");
    assertNull(actual);
}
Also used : FeedbackResponseAttributes(teammates.common.datatransfer.attributes.FeedbackResponseAttributes) Test(org.testng.annotations.Test)

Example 48 with FeedbackResponseAttributes

use of teammates.common.datatransfer.attributes.FeedbackResponseAttributes in project teammates by TEAMMATES.

the class BackDoorTest method testDeletion.

@Test
public void testDeletion() {
    // ----------deleting Instructor entities-------------------------
    InstructorAttributes instructor1OfCourse1 = dataBundle.instructors.get("instructor2OfCourse2");
    verifyPresentInDatastore(instructor1OfCourse1);
    String status = BackDoor.deleteInstructor(instructor1OfCourse1.courseId, instructor1OfCourse1.email);
    assertEquals(Const.StatusCodes.BACKDOOR_STATUS_SUCCESS, status);
    verifyAbsentInDatastore(instructor1OfCourse1);
    // try to delete again: should indicate as success because delete fails silently.
    status = BackDoor.deleteInstructor(instructor1OfCourse1.email, instructor1OfCourse1.courseId);
    assertEquals(Const.StatusCodes.BACKDOOR_STATUS_SUCCESS, status);
    // ----------deleting Feedback Response entities-------------------------
    FeedbackQuestionAttributes fq = dataBundle.feedbackQuestions.get("qn2InSession1InCourse1");
    FeedbackResponseAttributes fr = dataBundle.feedbackResponses.get("response1ForQ2S1C1");
    fq = BackDoor.getFeedbackQuestion(fq.courseId, fq.feedbackSessionName, fq.questionNumber);
    fr = BackDoor.getFeedbackResponse(fq.getId(), fr.giver, fr.recipient);
    verifyPresentInDatastore(fr);
    status = BackDoor.deleteFeedbackResponse(fq.getId(), fr.giver, fr.recipient);
    assertEquals(Const.StatusCodes.BACKDOOR_STATUS_SUCCESS, status);
    verifyAbsentInDatastore(fr);
    // ----------deleting Feedback Question entities-------------------------
    fq = dataBundle.feedbackQuestions.get("qn5InSession1InCourse1");
    verifyPresentInDatastore(fq);
    status = BackDoor.deleteFeedbackQuestion(fq.getId());
    assertEquals(Const.StatusCodes.BACKDOOR_STATUS_SUCCESS, status);
    verifyAbsentInDatastore(fq);
    // ----------deleting Course entities-------------------------
    // #COURSE 2
    CourseAttributes course2 = dataBundle.courses.get("typicalCourse2");
    verifyPresentInDatastore(course2);
    status = BackDoor.deleteCourse(course2.getId());
    assertEquals(Const.StatusCodes.BACKDOOR_STATUS_SUCCESS, status);
    verifyAbsentInDatastore(course2);
    // check if related student entities are also deleted
    StudentAttributes student2InCourse2 = dataBundle.students.get("student2InCourse2");
    verifyAbsentInDatastore(student2InCourse2);
    // #COURSE 1
    CourseAttributes course1 = dataBundle.courses.get("typicalCourse1");
    verifyPresentInDatastore(course1);
    status = BackDoor.deleteCourse(course1.getId());
    assertEquals(Const.StatusCodes.BACKDOOR_STATUS_SUCCESS, status);
    verifyAbsentInDatastore(course1);
    // check if related student entities are also deleted
    StudentAttributes student1InCourse1 = dataBundle.students.get("student1InCourse1");
    verifyAbsentInDatastore(student1InCourse1);
    // #COURSE NO EVALS
    CourseAttributes courseNoEvals = dataBundle.courses.get("courseNoEvals");
    verifyPresentInDatastore(courseNoEvals);
    status = BackDoor.deleteCourse(courseNoEvals.getId());
    assertEquals(Const.StatusCodes.BACKDOOR_STATUS_SUCCESS, status);
    verifyAbsentInDatastore(courseNoEvals);
// ----------deleting Feedback Session entities-------------------------
// TODO: do proper deletion test
}
Also used : FeedbackResponseAttributes(teammates.common.datatransfer.attributes.FeedbackResponseAttributes) FeedbackQuestionAttributes(teammates.common.datatransfer.attributes.FeedbackQuestionAttributes) StudentAttributes(teammates.common.datatransfer.attributes.StudentAttributes) InstructorAttributes(teammates.common.datatransfer.attributes.InstructorAttributes) CourseAttributes(teammates.common.datatransfer.attributes.CourseAttributes) Test(org.testng.annotations.Test)

Example 49 with FeedbackResponseAttributes

use of teammates.common.datatransfer.attributes.FeedbackResponseAttributes in project teammates by TEAMMATES.

the class InstructorFeedbackResultsPageData method buildResponsePanels.

private List<InstructorFeedbackResultsResponsePanel> buildResponsePanels(final String additionalInfoId, int primaryParticipantIndex, int secondaryRecipientIndex, List<FeedbackResponseAttributes> giverResponses) {
    List<InstructorFeedbackResultsResponsePanel> responsePanels = new ArrayList<>();
    for (int responseIndex = 0; responseIndex < giverResponses.size(); responseIndex++) {
        FeedbackResponseAttributes response = giverResponses.get(responseIndex);
        String questionId = response.feedbackQuestionId;
        FeedbackQuestionAttributes question = bundle.questions.get(questionId);
        String questionText = bundle.getQuestionText(questionId);
        int giverIndex = viewType.isPrimaryGroupingOfGiverType() ? primaryParticipantIndex : secondaryRecipientIndex;
        int recipientIndex = viewType.isPrimaryGroupingOfGiverType() ? secondaryRecipientIndex : primaryParticipantIndex;
        String additionalInfoText = questionToDetailsMap.get(question).getQuestionAdditionalInfoHtml(question.getQuestionNumber(), String.format(additionalInfoId, giverIndex, recipientIndex));
        String displayableResponse = bundle.getResponseAnswerHtml(response, question);
        String giverName = bundle.getNameForEmail(response.giver);
        String recipientName = bundle.getNameForEmail(response.recipient);
        String giverTeam = bundle.getTeamNameForEmail(response.giver);
        String recipientTeam = bundle.getTeamNameForEmail(response.recipient);
        giverName = bundle.appendTeamNameToName(giverName, giverTeam);
        recipientName = bundle.appendTeamNameToName(recipientName, recipientTeam);
        List<FeedbackResponseCommentRow> comments = buildResponseComments(giverName, recipientName, question, response);
        boolean isAllowedToSubmitSessionsInBothSection = instructor.isAllowedForPrivilege(response.giverSection, response.feedbackSessionName, Const.ParamsNames.INSTRUCTOR_PERMISSION_SUBMIT_SESSION_IN_SECTIONS) && instructor.isAllowedForPrivilege(response.recipientSection, response.feedbackSessionName, Const.ParamsNames.INSTRUCTOR_PERMISSION_SUBMIT_SESSION_IN_SECTIONS);
        boolean isCommentsOnResponsesAllowed = question.getQuestionDetails().isCommentsOnResponsesAllowed();
        Matcher matcher = sectionIdPattern.matcher(additionalInfoId);
        if (matcher.find()) {
            sectionId = Integer.parseInt(matcher.group(1));
        }
        InstructorFeedbackResultsResponsePanel responsePanel = new InstructorFeedbackResultsResponsePanel(question, response, questionText, sectionId, additionalInfoText, null, displayableResponse, comments, isAllowedToSubmitSessionsInBothSection, isCommentsOnResponsesAllowed);
        responsePanel.setCommentsIndexes(recipientIndex, giverIndex, responseIndex + 1);
        if (isCommentsOnResponsesAllowed) {
            Map<FeedbackParticipantType, Boolean> responseVisibilityMap = getResponseVisibilityMap(question);
            FeedbackResponseCommentRow frcForAdding = buildFeedbackResponseCommentAddForm(question, response, responseVisibilityMap, giverName, recipientName);
            responsePanel.setFrcForAdding(frcForAdding);
        }
        responsePanels.add(responsePanel);
    }
    return responsePanels;
}
Also used : InstructorFeedbackResultsResponsePanel(teammates.ui.template.InstructorFeedbackResultsResponsePanel) Matcher(java.util.regex.Matcher) ArrayList(java.util.ArrayList) FeedbackParticipantType(teammates.common.datatransfer.FeedbackParticipantType) FeedbackResponseAttributes(teammates.common.datatransfer.attributes.FeedbackResponseAttributes) FeedbackQuestionAttributes(teammates.common.datatransfer.attributes.FeedbackQuestionAttributes) FeedbackResponseCommentRow(teammates.ui.template.FeedbackResponseCommentRow)

Example 50 with FeedbackResponseAttributes

use of teammates.common.datatransfer.attributes.FeedbackResponseAttributes in project teammates by TEAMMATES.

the class InstructorFeedbackResultsPageData method buildResponseRowsForQuestion.

/**
 * Builds response rows for a given question. This not only builds response rows for existing responses, but includes
 * the missing responses between pairs of givers and recipients.
 * @param responses  existing responses for the question
 */
private List<InstructorFeedbackResultsResponseRow> buildResponseRowsForQuestion(FeedbackQuestionAttributes question, List<FeedbackResponseAttributes> responses) {
    List<InstructorFeedbackResultsResponseRow> responseRows = new ArrayList<>();
    List<String> possibleGiversWithoutResponses = bundle.getPossibleGivers(question);
    List<String> possibleReceiversWithoutResponsesForGiver = new ArrayList<>();
    String prevGiver = "";
    int responseRecipientIndex = 0;
    int responseGiverIndex = 0;
    int userIndex = 0;
    Map<String, Integer> userIndexesForComments = new HashMap<String, Integer>();
    for (FeedbackResponseAttributes response : responses) {
        if (!bundle.isGiverVisible(response) || !bundle.isRecipientVisible(response)) {
            possibleGiversWithoutResponses.clear();
            possibleReceiversWithoutResponsesForGiver.clear();
        }
        // keep track of possible givers who did not give a response
        removeParticipantIdentifierFromList(possibleGiversWithoutResponses, response.giver);
        boolean isNewGiver = !prevGiver.equals(response.giver);
        if (isNewGiver) {
            if (isMissingResponsesShown) {
                responseRows.addAll(buildMissingResponseRowsBetweenGiverAndPossibleRecipients(question, possibleReceiversWithoutResponsesForGiver, prevGiver, bundle.getNameForEmail(prevGiver), bundle.getTeamNameForEmail(prevGiver)));
            }
            String giverIdentifier = response.giver;
            possibleReceiversWithoutResponsesForGiver = bundle.getPossibleRecipients(question, giverIdentifier);
        }
        // keep track of possible recipients without a response from the current giver
        removeParticipantIdentifierFromList(possibleReceiversWithoutResponsesForGiver, response.recipient);
        prevGiver = response.giver;
        InstructorFeedbackResultsModerationButton moderationButton = buildModerationButtonForExistingResponse(question, response);
        InstructorFeedbackResultsResponseRow responseRow = new InstructorFeedbackResultsResponseRow(bundle.getGiverNameForResponse(response), bundle.getTeamNameForEmail(response.giver), bundle.getRecipientNameForResponse(response), bundle.getTeamNameForEmail(response.recipient), bundle.getResponseAnswerHtml(response, question), moderationButton);
        configureResponseRow(prevGiver, response.recipient, responseRow);
        String giverName = bundle.getNameForEmail(response.giver);
        String recipientName = bundle.getNameForEmail(response.recipient);
        String giverTeam = bundle.getTeamNameForEmail(response.giver);
        String recipientTeam = bundle.getTeamNameForEmail(response.recipient);
        giverName = bundle.appendTeamNameToName(giverName, giverTeam);
        recipientName = bundle.appendTeamNameToName(recipientName, recipientTeam);
        List<FeedbackResponseCommentRow> comments = buildResponseComments(giverName, recipientName, question, response);
        if (!comments.isEmpty()) {
            responseRow.setCommentsOnResponses(comments);
        }
        Map<FeedbackParticipantType, Boolean> responseVisibilityMap = getResponseVisibilityMap(question);
        boolean isCommentsOnResponsesAllowed = question.getQuestionDetails().isCommentsOnResponsesAllowed();
        if (isCommentsOnResponsesAllowed) {
            FeedbackResponseCommentRow addCommentForm = buildFeedbackResponseCommentAddForm(question, response, responseVisibilityMap, giverName, recipientName);
            responseRow.setAddCommentButton(addCommentForm);
            if (userIndexesForComments.get(response.giver) == null) {
                userIndex = generateIndexForUser(response.giver, userIndex, userIndexesForComments);
            }
            responseGiverIndex = userIndexesForComments.get(response.giver);
            if (userIndexesForComments.get(response.recipient) == null) {
                userIndex = generateIndexForUser(response.recipient, userIndex, userIndexesForComments);
            }
            responseRecipientIndex = userIndexesForComments.get(response.recipient);
            responseRow.setResponseRecipientIndex(responseRecipientIndex);
            responseRow.setResponseGiverIndex(responseGiverIndex);
            responseRow.setCommentsOnResponsesAllowed(isCommentsOnResponsesAllowed);
        }
        responseRows.add(responseRow);
    }
    if (!responses.isEmpty()) {
        responseRows.addAll(getRemainingMissingResponseRows(question, possibleGiversWithoutResponses, possibleReceiversWithoutResponsesForGiver, prevGiver));
    }
    return responseRows;
}
Also used : InstructorFeedbackResultsResponseRow(teammates.ui.template.InstructorFeedbackResultsResponseRow) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ArrayList(java.util.ArrayList) FeedbackParticipantType(teammates.common.datatransfer.FeedbackParticipantType) FeedbackResponseAttributes(teammates.common.datatransfer.attributes.FeedbackResponseAttributes) FeedbackResponseCommentRow(teammates.ui.template.FeedbackResponseCommentRow) InstructorFeedbackResultsModerationButton(teammates.ui.template.InstructorFeedbackResultsModerationButton)

Aggregations

FeedbackResponseAttributes (teammates.common.datatransfer.attributes.FeedbackResponseAttributes)143 FeedbackQuestionAttributes (teammates.common.datatransfer.attributes.FeedbackQuestionAttributes)70 ArrayList (java.util.ArrayList)63 StudentAttributes (teammates.common.datatransfer.attributes.StudentAttributes)36 InstructorAttributes (teammates.common.datatransfer.attributes.InstructorAttributes)35 List (java.util.List)29 FeedbackSessionAttributes (teammates.common.datatransfer.attributes.FeedbackSessionAttributes)28 HashMap (java.util.HashMap)27 FeedbackResponseCommentAttributes (teammates.common.datatransfer.attributes.FeedbackResponseCommentAttributes)22 HashSet (java.util.HashSet)20 LinkedHashMap (java.util.LinkedHashMap)20 Map (java.util.Map)18 Test (org.testng.annotations.Test)18 FeedbackQuestionsDb (teammates.storage.api.FeedbackQuestionsDb)18 FeedbackResponsesDb (teammates.storage.api.FeedbackResponsesDb)18 Text (com.google.appengine.api.datastore.Text)15 Set (java.util.Set)11 EntityDoesNotExistException (teammates.common.exception.EntityDoesNotExistException)10 Comparator (java.util.Comparator)9 FeedbackParticipantType (teammates.common.datatransfer.FeedbackParticipantType)9