use of teammates.common.datatransfer.FeedbackResponseCommentSearchResultBundle in project teammates by TEAMMATES.
the class FeedbackResponseCommentSearchTest method allTests.
@Test
public void allTests() {
FeedbackResponseCommentsDb commentsDb = new FeedbackResponseCommentsDb();
FeedbackResponseCommentAttributes frc1I1Q1S1C1 = dataBundle.feedbackResponseComments.get("comment1FromT1C1ToR1Q1S1C1");
FeedbackResponseCommentAttributes frc1I1Q2S1C1 = dataBundle.feedbackResponseComments.get("comment1FromT1C1ToR1Q2S1C1");
FeedbackResponseCommentAttributes frc1I3Q1S1C2 = dataBundle.feedbackResponseComments.get("comment1FromT1C1ToR1Q1S1C2");
ArrayList<InstructorAttributes> instructors = new ArrayList<InstructorAttributes>();
______TS("success: search for comments; no results found as instructor doesn't have privileges");
instructors.add(dataBundle.instructors.get("helperOfCourse1"));
FeedbackResponseCommentSearchResultBundle bundle = commentsDb.search("\"self-feedback\"", instructors);
assertEquals(0, bundle.numberOfResults);
assertTrue(bundle.comments.isEmpty());
______TS("success: search for comments; query string does not match any comment");
instructors.clear();
instructors.add(dataBundle.instructors.get("instructor3OfCourse1"));
instructors.add(dataBundle.instructors.get("instructor3OfCourse2"));
bundle = commentsDb.search("non-existent", instructors);
assertEquals(0, bundle.numberOfResults);
assertTrue(bundle.comments.isEmpty());
______TS("success: search for comments; query string matches single comment");
bundle = commentsDb.search("\"Instructor 3 comment to instr1C2 response to student1C2\"", instructors);
verifySearchResults(bundle, frc1I3Q1S1C2);
______TS("success: search for comments in instructor's course; query string matches some comments");
bundle = commentsDb.search("\"self feedback\"", instructors);
verifySearchResults(bundle, frc1I1Q1S1C1, frc1I1Q2S1C1);
______TS("success: search for comments in instructor's course; confirms query string is case insensitive");
bundle = commentsDb.search("\"Instructor 1 COMMENT to student 1 self feedback Question 2\"", instructors);
verifySearchResults(bundle, frc1I1Q2S1C1);
______TS("success: search for comments using feedbackSessionName");
bundle = commentsDb.search("\"First feedback session\"", instructors);
verifySearchResults(bundle, frc1I1Q2S1C1, frc1I1Q1S1C1);
______TS("success: search for comments using Instructor's email");
bundle = commentsDb.search("instructor1@course1.tmt", instructors);
verifySearchResults(bundle, frc1I1Q2S1C1, frc1I1Q1S1C1);
______TS("success: search for comments using Student name");
bundle = commentsDb.search("\"student2 In Course1\"", instructors);
verifySearchResults(bundle, frc1I1Q2S1C1);
______TS("success: search for comments; confirms deleted comments are not included in results");
commentsDb.deleteDocument(frc1I3Q1S1C2);
bundle = commentsDb.search("\"Instructor 3 comment to instr1C2 response to student1C2\"", instructors);
verifySearchResults(bundle);
}
use of teammates.common.datatransfer.FeedbackResponseCommentSearchResultBundle in project teammates by TEAMMATES.
the class FeedbackResponseCommentSearchDocument method fromResults.
/**
* Produces a {@link FeedbackResponseCommentSearchResultBundle} from the {@code Results<ScoredDocument>} collection.
* The list of {@link InstructorAttributes} is used to filter out the search result.
*/
public static FeedbackResponseCommentSearchResultBundle fromResults(Results<ScoredDocument> results, List<InstructorAttributes> instructors) {
FeedbackResponseCommentSearchResultBundle bundle = new FeedbackResponseCommentSearchResultBundle();
if (results == null) {
return bundle;
}
// get instructor's information
bundle.instructorEmails = new HashSet<>();
Set<String> instructorCourseIdList = new HashSet<>();
for (InstructorAttributes ins : instructors) {
bundle.instructorEmails.add(ins.email);
instructorCourseIdList.add(ins.courseId);
}
Set<String> isAdded = new HashSet<>();
List<ScoredDocument> filteredResults = filterOutCourseId(results, instructors);
for (ScoredDocument doc : filteredResults) {
// get FeedbackResponseComment from results
FeedbackResponseCommentAttributes comment = JsonUtils.fromJson(doc.getOnlyField(Const.SearchDocumentField.FEEDBACK_RESPONSE_COMMENT_ATTRIBUTE).getText(), FeedbackResponseCommentAttributes.class);
if (frcDb.getFeedbackResponseComment(comment.getId()) == null) {
frcDb.deleteDocument(comment);
continue;
}
List<FeedbackResponseCommentAttributes> commentList = bundle.comments.get(comment.feedbackResponseId);
if (commentList == null) {
commentList = new ArrayList<>();
bundle.comments.put(comment.feedbackResponseId, commentList);
}
commentList.add(comment);
// get related response from results
FeedbackResponseAttributes response = JsonUtils.fromJson(doc.getOnlyField(Const.SearchDocumentField.FEEDBACK_RESPONSE_ATTRIBUTE).getText(), FeedbackResponseAttributes.class);
if (frDb.getFeedbackResponse(response.getId()) == null) {
frcDb.deleteDocument(comment);
continue;
}
List<FeedbackResponseAttributes> responseList = bundle.responses.get(response.feedbackQuestionId);
if (responseList == null) {
responseList = new ArrayList<>();
bundle.responses.put(response.feedbackQuestionId, responseList);
}
if (!isAdded.contains(response.getId())) {
isAdded.add(response.getId());
responseList.add(response);
}
// get related question from results
FeedbackQuestionAttributes question = JsonUtils.fromJson(doc.getOnlyField(Const.SearchDocumentField.FEEDBACK_QUESTION_ATTRIBUTE).getText(), FeedbackQuestionAttributes.class);
if (fqDb.getFeedbackQuestion(question.getId()) == null) {
frcDb.deleteDocument(comment);
continue;
}
List<FeedbackQuestionAttributes> questionList = bundle.questions.get(question.feedbackSessionName);
if (questionList == null) {
questionList = new ArrayList<>();
bundle.questions.put(question.feedbackSessionName, questionList);
}
if (!isAdded.contains(question.getId())) {
isAdded.add(question.getId());
questionList.add(question);
}
// get related session from results
FeedbackSessionAttributes session = JsonUtils.fromJson(doc.getOnlyField(Const.SearchDocumentField.FEEDBACK_SESSION_ATTRIBUTE).getText(), FeedbackSessionAttributes.class);
if (fsDb.getFeedbackSession(session.getCourseId(), session.getSessionName()) == null) {
frcDb.deleteDocument(comment);
continue;
}
if (!isAdded.contains(session.getFeedbackSessionName())) {
isAdded.add(session.getFeedbackSessionName());
bundle.sessions.put(session.getSessionName(), session);
}
// get giver and recipient names
String responseGiverName = StringHelper.extractContentFromQuotedString(doc.getOnlyField(Const.SearchDocumentField.FEEDBACK_RESPONSE_GIVER_NAME).getText());
bundle.responseGiverTable.put(response.getId(), getFilteredGiverName(bundle, instructorCourseIdList, response, responseGiverName));
String responseRecipientName = StringHelper.extractContentFromQuotedString(doc.getOnlyField(Const.SearchDocumentField.FEEDBACK_RESPONSE_RECEIVER_NAME).getText());
bundle.responseRecipientTable.put(response.getId(), getFilteredRecipientName(bundle, instructorCourseIdList, response, responseRecipientName));
String commentGiverName = StringHelper.extractContentFromQuotedString(doc.getOnlyField(Const.SearchDocumentField.FEEDBACK_RESPONSE_COMMENT_GIVER_NAME).getText());
bundle.commentGiverTable.put(comment.getId().toString(), getFilteredCommentGiverName(bundle, instructorCourseIdList, response, comment, commentGiverName));
bundle.instructorEmailNameTable.put(comment.giverEmail, commentGiverName);
boolean isLastEditorEmailInMap = !comment.lastEditorEmail.isEmpty() && bundle.instructorEmailNameTable.containsKey(comment.lastEditorEmail);
if (!isLastEditorEmailInMap) {
InstructorAttributes instructor = instructorsDb.getInstructorForEmail(response.courseId, comment.lastEditorEmail);
String commentLastEditorName = instructor.displayedName + " " + instructor.name;
bundle.instructorEmailNameTable.put(comment.lastEditorEmail, commentLastEditorName);
}
bundle.numberOfResults++;
}
for (List<FeedbackQuestionAttributes> questions : bundle.questions.values()) {
questions.sort(null);
}
for (List<FeedbackResponseAttributes> responses : bundle.responses.values()) {
FeedbackResponseAttributes.sortFeedbackResponses(responses);
}
for (List<FeedbackResponseCommentAttributes> responseComments : bundle.comments.values()) {
FeedbackResponseCommentAttributes.sortFeedbackResponseCommentsByCreationTime(responseComments);
}
bundle.numberOfResults = filterFeedbackResponseCommentResults(bundle, instructors, bundle.numberOfResults);
removeQuestionsAndResponsesWithoutComments(bundle);
return bundle;
}
use of teammates.common.datatransfer.FeedbackResponseCommentSearchResultBundle in project teammates by TEAMMATES.
the class InstructorSearchPageAction method execute.
@Override
protected ActionResult execute() {
gateKeeper.verifyInstructorPrivileges(account);
String searchKey = getRequestParamValue(Const.ParamsNames.SEARCH_KEY);
if (searchKey == null) {
searchKey = "";
}
int numberOfSearchOptions = 0;
boolean isSearchForStudents = getRequestParamAsBoolean(Const.ParamsNames.SEARCH_STUDENTS);
if (isSearchForStudents) {
numberOfSearchOptions++;
}
boolean isSearchFeedbackSessionData = getRequestParamAsBoolean(Const.ParamsNames.SEARCH_FEEDBACK_SESSION_DATA);
if (isSearchFeedbackSessionData) {
numberOfSearchOptions++;
}
FeedbackResponseCommentSearchResultBundle frCommentSearchResults = new FeedbackResponseCommentSearchResultBundle();
StudentSearchResultBundle studentSearchResults = new StudentSearchResultBundle();
int totalResultsSize = 0;
if (searchKey.isEmpty() || numberOfSearchOptions == 0) {
// display search tips and tutorials
statusToUser.add(new StatusMessage(Const.StatusMessages.INSTRUCTOR_SEARCH_TIPS, StatusMessageColor.INFO));
} else {
// Start searching
List<InstructorAttributes> instructors = logic.getInstructorsForGoogleId(account.googleId);
if (isSearchFeedbackSessionData) {
frCommentSearchResults = logic.searchFeedbackResponseComments(searchKey, instructors);
}
if (isSearchForStudents) {
studentSearchResults = logic.searchStudents(searchKey, instructors);
}
totalResultsSize = frCommentSearchResults.numberOfResults + studentSearchResults.numberOfResults;
Set<String> instructorEmails = new HashSet<>();
for (InstructorAttributes instructor : instructors) {
instructorEmails.add(instructor.email);
}
if (totalResultsSize == 0) {
statusToUser.add(new StatusMessage(Const.StatusMessages.INSTRUCTOR_SEARCH_NO_RESULTS, StatusMessageColor.WARNING));
}
}
InstructorSearchPageData data = new InstructorSearchPageData(account, sessionToken);
data.init(frCommentSearchResults, studentSearchResults, searchKey, isSearchFeedbackSessionData, isSearchForStudents);
return createShowPageResult(Const.ViewURIs.INSTRUCTOR_SEARCH, data);
}
Aggregations