use of teammates.common.datatransfer.attributes.FeedbackResponseCommentAttributes in project teammates by TEAMMATES.
the class InstructorFeedbackResponseCommentEditAction method execute.
@Override
protected ActionResult execute() throws EntityDoesNotExistException {
String courseId = getRequestParamValue(Const.ParamsNames.COURSE_ID);
Assumption.assertPostParamNotNull(Const.ParamsNames.COURSE_ID, courseId);
String feedbackSessionName = getRequestParamValue(Const.ParamsNames.FEEDBACK_SESSION_NAME);
Assumption.assertPostParamNotNull(Const.ParamsNames.FEEDBACK_SESSION_NAME, feedbackSessionName);
String feedbackResponseId = getRequestParamValue(Const.ParamsNames.FEEDBACK_RESPONSE_ID);
Assumption.assertPostParamNotNull(Const.ParamsNames.FEEDBACK_RESPONSE_ID, feedbackResponseId);
String feedbackResponseCommentId = getRequestParamValue(Const.ParamsNames.FEEDBACK_RESPONSE_COMMENT_ID);
Assumption.assertPostParamNotNull(Const.ParamsNames.FEEDBACK_RESPONSE_COMMENT_ID, feedbackResponseCommentId);
InstructorAttributes instructor = logic.getInstructorForGoogleId(courseId, account.googleId);
FeedbackSessionAttributes session = logic.getFeedbackSession(feedbackSessionName, courseId);
FeedbackResponseAttributes response = logic.getFeedbackResponse(feedbackResponseId);
Assumption.assertNotNull(response);
FeedbackResponseCommentAttributes frc = logic.getFeedbackResponseComment(Long.parseLong(feedbackResponseCommentId));
Assumption.assertNotNull("FeedbackResponseComment should not be null", frc);
verifyAccessibleForInstructorToFeedbackResponseComment(feedbackResponseCommentId, instructor, session, response);
InstructorFeedbackResponseCommentAjaxPageData data = new InstructorFeedbackResponseCommentAjaxPageData(account, sessionToken);
// Edit comment text
String commentText = getRequestParamValue(Const.ParamsNames.FEEDBACK_RESPONSE_COMMENT_TEXT);
Assumption.assertPostParamNotNull(Const.ParamsNames.FEEDBACK_RESPONSE_COMMENT_TEXT, commentText);
if (commentText.trim().isEmpty()) {
data.errorMessage = Const.StatusMessages.FEEDBACK_RESPONSE_COMMENT_EMPTY;
data.isError = true;
return createAjaxResult(data);
}
FeedbackResponseCommentAttributes feedbackResponseComment = FeedbackResponseCommentAttributes.builder(courseId, feedbackSessionName, instructor.email, new Text(commentText)).withCreatedAt(Instant.now()).withGiverSection(response.giverSection).withReceiverSection(response.recipientSection).build();
feedbackResponseComment.setId(Long.parseLong(feedbackResponseCommentId));
// Edit visibility settings
String showCommentTo = getRequestParamValue(Const.ParamsNames.RESPONSE_COMMENTS_SHOWCOMMENTSTO);
String showGiverNameTo = getRequestParamValue(Const.ParamsNames.RESPONSE_COMMENTS_SHOWGIVERTO);
feedbackResponseComment.showCommentTo = new ArrayList<>();
if (showCommentTo != null && !showCommentTo.isEmpty()) {
String[] showCommentToArray = showCommentTo.split(",");
for (String viewer : showCommentToArray) {
feedbackResponseComment.showCommentTo.add(FeedbackParticipantType.valueOf(viewer.trim()));
}
}
feedbackResponseComment.showGiverNameTo = new ArrayList<>();
if (showGiverNameTo != null && !showGiverNameTo.isEmpty()) {
String[] showGiverNameToArray = showGiverNameTo.split(",");
for (String viewer : showGiverNameToArray) {
feedbackResponseComment.showGiverNameTo.add(FeedbackParticipantType.valueOf(viewer.trim()));
}
}
FeedbackResponseCommentAttributes updatedComment = null;
try {
updatedComment = logic.updateFeedbackResponseComment(feedbackResponseComment);
// TODO: move putDocument to task queue
logic.putDocument(updatedComment);
} catch (InvalidParametersException e) {
setStatusForException(e);
data.errorMessage = e.getMessage();
data.isError = true;
}
if (!data.isError) {
statusToAdmin += "InstructorFeedbackResponseCommentEditAction:<br>" + "Editing feedback response comment: " + feedbackResponseComment.getId() + "<br>" + "in course/feedback session: " + feedbackResponseComment.courseId + "/" + feedbackResponseComment.feedbackSessionName + "<br>" + "by: " + feedbackResponseComment.giverEmail + "<br>" + "comment text: " + feedbackResponseComment.commentText.getValue();
String commentGiverName = logic.getInstructorForEmail(courseId, frc.giverEmail).name;
String commentEditorName = instructor.name;
// createdAt and lastEditedAt fields in updatedComment as well as sessionTimeZone
// are required to generate timestamps in editedCommentDetails
data.comment = updatedComment;
data.sessionTimeZone = session.getTimeZone();
data.editedCommentDetails = data.createEditedCommentDetails(commentGiverName, commentEditorName);
}
return createAjaxResult(data);
}
use of teammates.common.datatransfer.attributes.FeedbackResponseCommentAttributes in project teammates by TEAMMATES.
the class FeedbackSessionsLogic method getFeedbackSessionResultsForUserInSectionByQuestions.
/* Get the feedback results for user in a section iterated by questions */
private FeedbackSessionResultsBundle getFeedbackSessionResultsForUserInSectionByQuestions(String feedbackSessionName, String courseId, String userEmail, UserRole role, String section, CourseRoster roster) throws EntityDoesNotExistException {
FeedbackSessionAttributes session = fsDb.getFeedbackSession(courseId, feedbackSessionName);
if (session == null) {
throw new EntityDoesNotExistException(ERROR_NON_EXISTENT_FS_VIEW + courseId + "/" + feedbackSessionName);
}
// create empty data containers to store results
List<FeedbackResponseAttributes> responses = new ArrayList<>();
Map<String, FeedbackQuestionAttributes> relevantQuestions = new HashMap<>();
Map<String, String> emailNameTable = new HashMap<>();
Map<String, String> emailLastNameTable = new HashMap<>();
Map<String, String> emailTeamNameTable = new HashMap<>();
Map<String, Set<String>> sectionTeamNameTable = new HashMap<>();
Map<String, boolean[]> visibilityTable = new HashMap<>();
Map<String, List<FeedbackResponseCommentAttributes>> responseComments = new HashMap<>();
FeedbackSessionResponseStatus responseStatus = new FeedbackSessionResponseStatus();
boolean isPrivateSessionNotCreatedByThisUser = session.isPrivateSession() && !session.isCreator(userEmail);
if (isPrivateSessionNotCreatedByThisUser) {
// return empty result set
return new FeedbackSessionResultsBundle(session, responses, relevantQuestions, emailNameTable, emailLastNameTable, emailTeamNameTable, sectionTeamNameTable, visibilityTable, responseStatus, roster, responseComments);
}
List<FeedbackQuestionAttributes> allQuestions = fqLogic.getFeedbackQuestionsForSession(feedbackSessionName, courseId);
Map<String, FeedbackResponseAttributes> relevantResponse = new HashMap<>();
for (FeedbackQuestionAttributes question : allQuestions) {
List<FeedbackResponseAttributes> responsesForThisQn;
boolean isPrivateSessionCreatedByThisUser = session.isCreator(userEmail) && session.isPrivateSession();
if (isPrivateSessionCreatedByThisUser) {
responsesForThisQn = frLogic.getFeedbackResponsesForQuestion(question.getId());
} else {
responsesForThisQn = frLogic.getViewableFeedbackResponsesForQuestionInSection(question, userEmail, role, section);
}
boolean hasResponses = !responsesForThisQn.isEmpty();
if (hasResponses) {
relevantQuestions.put(question.getId(), question);
responses.addAll(responsesForThisQn);
for (FeedbackResponseAttributes response : responsesForThisQn) {
relevantResponse.put(response.getId(), response);
addEmailNamePairsToTable(emailNameTable, response, question, roster);
addEmailLastNamePairsToTable(emailLastNameTable, response, question, roster);
addEmailTeamNamePairsToTable(emailTeamNameTable, response, question, roster);
addVisibilityToTable(visibilityTable, question, response, userEmail, role, roster);
}
}
}
StudentAttributes student = null;
Set<String> studentsEmailInTeam = new HashSet<>();
if (isStudent(role)) {
student = studentsLogic.getStudentForEmail(courseId, userEmail);
List<StudentAttributes> studentsInTeam = studentsLogic.getStudentsForTeam(student.team, courseId);
for (StudentAttributes teammates : studentsInTeam) {
studentsEmailInTeam.add(teammates.email);
}
}
List<FeedbackResponseCommentAttributes> allResponseComments = frcLogic.getFeedbackResponseCommentForSession(courseId, feedbackSessionName);
for (FeedbackResponseCommentAttributes frc : allResponseComments) {
FeedbackResponseAttributes relatedResponse = relevantResponse.get(frc.feedbackResponseId);
FeedbackQuestionAttributes relatedQuestion = relevantQuestions.get(frc.feedbackQuestionId);
boolean isVisibleResponseComment = frcLogic.isResponseCommentVisibleForUser(userEmail, role, student, studentsEmailInTeam, relatedResponse, relatedQuestion, frc);
if (isVisibleResponseComment) {
if (!frcLogic.isNameVisibleToUser(frc, relatedResponse, userEmail, roster)) {
frc.giverEmail = Const.DISPLAYED_NAME_FOR_ANONYMOUS_PARTICIPANT;
}
if (responseComments.get(frc.feedbackResponseId) == null) {
responseComments.put(frc.feedbackResponseId, new ArrayList<FeedbackResponseCommentAttributes>());
}
responseComments.get(frc.feedbackResponseId).add(frc);
}
}
for (List<FeedbackResponseCommentAttributes> responseCommentList : responseComments.values()) {
sortByCreatedDate(responseCommentList);
}
addSectionTeamNamesToTable(sectionTeamNameTable, roster, courseId, userEmail, role, feedbackSessionName, section);
return new FeedbackSessionResultsBundle(session, responses, relevantQuestions, emailNameTable, emailLastNameTable, emailTeamNameTable, sectionTeamNameTable, visibilityTable, responseStatus, roster, responseComments);
}
use of teammates.common.datatransfer.attributes.FeedbackResponseCommentAttributes 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.attributes.FeedbackResponseCommentAttributes in project teammates by TEAMMATES.
the class FeedbackResponseCommentsDb method putDocuments.
/*
* Batch creates or updates search documents for the given comments
*/
public void putDocuments(List<FeedbackResponseCommentAttributes> comments) {
List<SearchDocument> frcSearchDocuments = new ArrayList<>();
for (FeedbackResponseCommentAttributes comment : comments) {
frcSearchDocuments.add(new FeedbackResponseCommentSearchDocument(comment));
}
putDocuments(Const.SearchIndex.FEEDBACK_RESPONSE_COMMENT, frcSearchDocuments);
}
use of teammates.common.datatransfer.attributes.FeedbackResponseCommentAttributes in project teammates by TEAMMATES.
the class InstructorSearchPageData method createFeedbackResponseCommentRows.
private List<FeedbackResponseCommentRow> createFeedbackResponseCommentRows(FeedbackResponseAttributes responseEntry, FeedbackResponseCommentSearchResultBundle frcSearchResultBundle) {
List<FeedbackResponseCommentRow> rows = new ArrayList<>();
List<FeedbackResponseCommentAttributes> frcList = frcSearchResultBundle.comments.get(responseEntry.getId());
for (FeedbackResponseCommentAttributes frc : frcList) {
String frCommentGiver = frcSearchResultBundle.commentGiverTable.get(frc.getId().toString());
if (!Const.DISPLAYED_NAME_FOR_ANONYMOUS_PARTICIPANT.equals(frCommentGiver)) {
frCommentGiver = frc.giverEmail;
}
ZoneId sessionTimeZone = frcSearchResultBundle.sessions.get(responseEntry.feedbackSessionName).getTimeZone();
FeedbackResponseCommentRow frcDiv = new FeedbackResponseCommentRow(frc, frCommentGiver, frcSearchResultBundle.instructorEmailNameTable, sessionTimeZone);
rows.add(frcDiv);
}
return rows;
}
Aggregations