From 08b12cfff68f6116482a85b307c2877fc798aa9e Mon Sep 17 00:00:00 2001 From: Earle Nietzel Date: Thu, 22 Feb 2018 14:11:30 -0500 Subject: [PATCH] SAK-33938 Assignments previous grade and resubmission improvement (#5334) --- .../assignment/tool/AssignmentAction.java | 128 +++++++++--------- ...signments_instructor_grading_submission.vm | 6 +- 2 files changed, 68 insertions(+), 66 deletions(-) diff --git a/assignment/tool/src/java/org/sakaiproject/assignment/tool/AssignmentAction.java b/assignment/tool/src/java/org/sakaiproject/assignment/tool/AssignmentAction.java index 5304eb2b875d..50c041f4fcc1 100644 --- a/assignment/tool/src/java/org/sakaiproject/assignment/tool/AssignmentAction.java +++ b/assignment/tool/src/java/org/sakaiproject/assignment/tool/AssignmentAction.java @@ -27,6 +27,8 @@ import java.nio.file.StandardCopyOption; import java.text.*; import java.time.*; +import java.time.format.DateTimeFormatter; +import java.time.format.FormatStyle; import java.time.temporal.ChronoField; import java.time.temporal.ChronoUnit; import java.util.*; @@ -3100,8 +3102,8 @@ protected String build_instructor_grade_submission_context(VelocityPortlet portl boolean addGradeDraftAlert = false; // assignment - String assignmentId = (String) state.getAttribute(GRADE_SUBMISSION_ASSIGNMENT_ID); - Assignment a = getAssignment(assignmentId, "build_instructor_grade_submission_context", state); + String assignmentRef = (String) state.getAttribute(GRADE_SUBMISSION_ASSIGNMENT_ID); + Assignment a = getAssignment(assignmentRef, "build_instructor_grade_submission_context", state); if (a != null) { context.put("assignment", a); context.put("assignmentReference", AssignmentReferenceReckoner.reckoner().assignment(a).reckon().getReference()); @@ -3128,13 +3130,12 @@ protected String build_instructor_grade_submission_context(VelocityPortlet portl context.put("assignmentAttachmentReferences", attachmentReferences); } - String submissionId = ""; + String submissionRef = (String) state.getAttribute(GRADE_SUBMISSION_SUBMISSION_ID); // assignment submission - AssignmentSubmission s = getSubmission((String) state.getAttribute(GRADE_SUBMISSION_SUBMISSION_ID), "build_instructor_grade_submission_context", state); + AssignmentSubmission s = getSubmission(submissionRef, "build_instructor_grade_submission_context", state); if (s != null) { - submissionId = s.getId(); context.put("submission", s); - context.put("submissionReference", AssignmentReferenceReckoner.reckoner().submission(s).reckon().getReference()); + context.put("submissionReference", submissionRef); Map users = s.getSubmitters().stream().map(u -> { try { @@ -3169,18 +3170,18 @@ protected String build_instructor_grade_submission_context(VelocityPortlet portl } Map p = s.getProperties(); - if (p.get(ResourceProperties.PROP_SUBMISSION_PREVIOUS_FEEDBACK_TEXT) != null) { + if (StringUtils.isNotBlank(p.get(ResourceProperties.PROP_SUBMISSION_PREVIOUS_FEEDBACK_TEXT))) { context.put("prevFeedbackText", p.get(ResourceProperties.PROP_SUBMISSION_PREVIOUS_FEEDBACK_TEXT)); } - - if (p.get(ResourceProperties.PROP_SUBMISSION_PREVIOUS_FEEDBACK_COMMENT) != null) { + if (StringUtils.isNotBlank(p.get(ResourceProperties.PROP_SUBMISSION_PREVIOUS_FEEDBACK_COMMENT))) { context.put("prevFeedbackComment", p.get(ResourceProperties.PROP_SUBMISSION_PREVIOUS_FEEDBACK_COMMENT)); } - - if (p.get(PROP_SUBMISSION_PREVIOUS_FEEDBACK_ATTACHMENTS) != null) { + if (StringUtils.isNotBlank(p.get(PROP_SUBMISSION_PREVIOUS_FEEDBACK_ATTACHMENTS))) { context.put("prevFeedbackAttachments", getPrevFeedbackAttachments(p)); } - + if (StringUtils.isNotBlank(p.get(ResourceProperties.PROP_SUBMISSION_SCALED_PREVIOUS_GRADES))) { + context.put("NamePropSubmissionScaledPreviousGrades", ResourceProperties.PROP_SUBMISSION_SCALED_PREVIOUS_GRADES); + } // put the re-submission info into context putTimePropertiesInContext(context, state, "Resubmit", ALLOW_RESUBMIT_CLOSEMONTH, ALLOW_RESUBMIT_CLOSEDAY, ALLOW_RESUBMIT_CLOSEYEAR, ALLOW_RESUBMIT_CLOSEHOUR, ALLOW_RESUBMIT_CLOSEMIN); @@ -3291,7 +3292,7 @@ protected String build_instructor_grade_submission_context(VelocityPortlet portl resetNavOptions(); if (userSubmissions != null) { for (int index = 0; index < userSubmissions.size(); index++) { - if (((SubmitterSubmission) userSubmissions.get(index)).getSubmission().getId().equals(submissionId)) { + if (((SubmitterSubmission) userSubmissions.get(index)).getSubmission().getId().equals(s.getId())) { // Determine next/previous boolean goPT = false; boolean goNT = false; @@ -5770,7 +5771,7 @@ private void grade_submission_option(RunData data, String gradeOption) { String sReference = AssignmentReferenceReckoner.reckoner().submission(submission).reckon().getReference(); // save a timestamp for this grading process - properties.put(AssignmentConstants.PROP_LAST_GRADED_DATE, Instant.now().toString()); + properties.put(AssignmentConstants.PROP_LAST_GRADED_DATE, DateTimeFormatter.ofLocalizedDateTime(FormatStyle.LONG).withZone(ZoneId.systemDefault()).format(Instant.now())); try { assignmentService.updateSubmission(submission); @@ -5969,12 +5970,11 @@ private void post_save_submission(RunData data, boolean post) { checkSubmissionTextAttachmentInput(data, state, a, text); } if ((state.getAttribute(STATE_MESSAGE) == null) && (a != null)) { - AssignmentSubmission submission = null; + AssignmentSubmission submission; + if (a.getIsGroup()) { - submission = getSubmission(aReference, - (original_group_id == null ? group_id : original_group_id), - "post_save_submission", - state); + String g = StringUtils.isNotBlank(original_group_id) ? original_group_id : group_id; + submission = getSubmission(aReference, g, "post_save_submission", state); } else { submission = getSubmission(aReference, u, "post_save_submission", state); } @@ -5982,24 +5982,21 @@ private void post_save_submission(RunData data, boolean post) { if (submission != null) { // the submission already exists, change the text and honor pledge value, post it Map properties = submission.getProperties(); - /** - * SAK-22150 We will need to know later if there was a previous submission time. DH - */ + boolean isPreviousSubmissionTime = true; - if (submission.getDateSubmitted() == null || "".equals(submission.getDateSubmitted()) || !submission.getSubmitted()) { + if (submission.getDateSubmitted() == null || !submission.getSubmitted()) { isPreviousSubmissionTime = false; } if (a.getIsGroup()) { - if (original_group_id != null && !original_group_id.equals(group_id)) { + if (StringUtils.isNotBlank(original_group_id) && !StringUtils.equals(original_group_id, group_id)) { // changing group id so we need to check if a submission has already been made for that group AssignmentSubmission submissioncheck = getSubmission(aReference, group_id, "post_save_submission", state); if (submissioncheck != null) { addAlert(state, rb.getString("group.already.submitted")); - log.warn(this + ":post_save_submission " + group_id + " has already submitted " + submissioncheck.getId() + "!"); + log.warn("The group {} has already submitted {}!", group_id, submissioncheck.getId()); } } - // TODO sets the submitter id as the group.... submission.setGroupId(group_id); } @@ -6023,14 +6020,13 @@ private void post_save_submission(RunData data, boolean post) { // for resubmissions // when resubmit, keep the Returned flag on till the instructor grade again. - Instant now = Instant.now(); - // need this to handle feedback and comments, which we have to do even if ungraded // get the previous graded date String prevGradedDate = properties.get(AssignmentConstants.PROP_LAST_GRADED_DATE); - if (prevGradedDate == null && submission.getDateModified() != null) { + if (StringUtils.isBlank(prevGradedDate) && submission.getDateModified() != null) { // since this is a newly added property, if no value is set, get the default as the submission last modified date - prevGradedDate = submission.getDateModified().toString(); + // this date is shown in the UI so we format the date and time using the system zone vs the users for consistency + prevGradedDate = DateTimeFormatter.ofLocalizedDateTime(FormatStyle.LONG).withZone(ZoneId.systemDefault()).format(submission.getDateModified()); properties.put(AssignmentConstants.PROP_LAST_GRADED_DATE, prevGradedDate); } @@ -6038,11 +6034,10 @@ private void post_save_submission(RunData data, boolean post) { // add the current grade into previous grade histroy String previousGrades = properties.get(ResourceProperties.PROP_SUBMISSION_SCALED_PREVIOUS_GRADES); - if (previousGrades == null) { + if (StringUtils.isBlank(previousGrades)) { previousGrades = properties.get(ResourceProperties.PROP_SUBMISSION_PREVIOUS_GRADES); - if (previousGrades != null) { - Assignment.GradeType typeOfGrade = a.getTypeOfGrade(); - if (typeOfGrade == SCORE_GRADE_TYPE) { + if (StringUtils.isNotBlank(previousGrades)) { + if (a.getTypeOfGrade() == SCORE_GRADE_TYPE) { // point grade assignment type // some old unscaled grades, need to scale the number and remove the old property String[] grades = StringUtils.split(previousGrades, " "); @@ -6050,8 +6045,7 @@ private void post_save_submission(RunData data, boolean post) { String decSeparator = formattedText.getDecimalSeparator(); - for (int jj = 0; jj < grades.length; jj++) { - String grade = grades[jj]; + for (String grade : grades) { if (!grade.contains(decSeparator)) { // show the grade with decimal point grade = grade.concat(decSeparator).concat("0"); @@ -6075,7 +6069,7 @@ private void post_save_submission(RunData data, boolean post) { // clear the current grade and make the submission ungraded submission.setGraded(false); submission.setGradedBy(null); - submission.setGrade(""); + submission.setGrade(null); submission.setGradeReleased(false); } @@ -6088,26 +6082,20 @@ private void post_save_submission(RunData data, boolean post) { if (StringUtils.isNotBlank(submission.getFeedbackText())) { // keep the history of assignment feed back text - String feedbackTextHistory = properties.get(ResourceProperties.PROP_SUBMISSION_PREVIOUS_FEEDBACK_TEXT) != null - ? properties.get(ResourceProperties.PROP_SUBMISSION_PREVIOUS_FEEDBACK_TEXT) - : ""; + String feedbackTextHistory = StringUtils.trimToEmpty(properties.get(ResourceProperties.PROP_SUBMISSION_PREVIOUS_FEEDBACK_TEXT)); feedbackTextHistory = "

" + prevGradedDate + "

" + "
" + submission.getFeedbackText() + "
" + feedbackTextHistory; properties.put(ResourceProperties.PROP_SUBMISSION_PREVIOUS_FEEDBACK_TEXT, feedbackTextHistory); } - if (StringUtils.trimToNull(submission.getFeedbackComment()) != null) { + if (StringUtils.isNotBlank(submission.getFeedbackComment())) { // keep the history of assignment feed back comment - String feedbackCommentHistory = properties.get(ResourceProperties.PROP_SUBMISSION_PREVIOUS_FEEDBACK_COMMENT) != null - ? properties.get(ResourceProperties.PROP_SUBMISSION_PREVIOUS_FEEDBACK_COMMENT) - : ""; + String feedbackCommentHistory = StringUtils.trimToEmpty(properties.get(ResourceProperties.PROP_SUBMISSION_PREVIOUS_FEEDBACK_COMMENT)); feedbackCommentHistory = "

" + prevGradedDate + "

" + "
" + submission.getFeedbackComment() + "
" + feedbackCommentHistory; properties.put(ResourceProperties.PROP_SUBMISSION_PREVIOUS_FEEDBACK_COMMENT, feedbackCommentHistory); } // keep the history of assignment feed back comment - String feedbackAttachmentHistory = properties.get(PROP_SUBMISSION_PREVIOUS_FEEDBACK_ATTACHMENTS) != null - ? properties.get(PROP_SUBMISSION_PREVIOUS_FEEDBACK_ATTACHMENTS) - : ""; + String feedbackAttachmentHistory = StringUtils.trimToEmpty(properties.get(PROP_SUBMISSION_PREVIOUS_FEEDBACK_ATTACHMENTS)); Set feedbackAttachments = submission.getFeedbackAttachments(); // use comma as separator for attachments feedbackAttachmentHistory = StringUtils.join(feedbackAttachments, ",") + feedbackAttachmentHistory; @@ -6115,8 +6103,8 @@ private void post_save_submission(RunData data, boolean post) { properties.put(PROP_SUBMISSION_PREVIOUS_FEEDBACK_ATTACHMENTS, feedbackAttachmentHistory); // reset the previous grading context - submission.setFeedbackText(""); - submission.setFeedbackComment(""); + submission.setFeedbackText(null); + submission.setFeedbackComment(null); submission.getFeedbackAttachments().clear(); // SAK-26322 @@ -6129,17 +6117,11 @@ private void post_save_submission(RunData data, boolean post) { // add attachments List attachments = (List) state.getAttribute(ATTACHMENTS); - Set submittedAttachments = submission.getAttachments(); if (attachments != null) { - if (a.getTypeOfSubmission() == Assignment.SubmissionType.TEXT_ONLY_ASSIGNMENT_SUBMISSION) { - //inline only doesn't accept attachments - submittedAttachments.clear(); - } else { - - // clear the old attachments first - submittedAttachments.clear(); + Set submittedAttachments = submission.getAttachments(); + submittedAttachments.clear(); + if (a.getTypeOfSubmission() != Assignment.SubmissionType.TEXT_ONLY_ASSIGNMENT_SUBMISSION) { - // add each new attachment if (submitter != null) { properties.put(AssignmentConstants.SUBMITTER_USER_ID, submitter.getId()); state.setAttribute(STATE_SUBMITTER, u.getId()); @@ -6182,8 +6164,8 @@ private void post_save_submission(RunData data, boolean post) { logEntry += u.getDisplayName() + " (" + u.getEid() + ") " + subOrDraft; } }*/ -// TODO submissionLog -// submission.addSubmissionLogEntry( logEntry ); + // TODO submissionLog + // submission.addSubmissionLogEntry( logEntry ); try { assignmentService.updateSubmission(submission); } catch (PermissionException e) { @@ -6194,7 +6176,7 @@ private void post_save_submission(RunData data, boolean post) { // new submission try { // if assignment is a group submission... send group id and not user id - String submitterId = null; + String submitterId; if (a.getIsGroup()) { submitterId = group_id; } else { @@ -6202,10 +6184,30 @@ private void post_save_submission(RunData data, boolean post) { } submission = assignmentService.addSubmission(a.getId(), submitterId); if (submission != null) { - log.debug("NEW SUBMISSION:submitter: {}", submission.getSubmitters().toArray(new AssignmentSubmissionSubmitter[]{})[0].getSubmitter()); + log.debug("NEW SUBMISSION:submitter: {}", submission.getSubmitters()); + Set submitters = submission.getSubmitters(); if (a.getIsGroup()) { - submission.setGroupId(group_id); log.debug("NEW SUBMISSION: group: {}", group_id); + try { + Site site = siteService.getSite(a.getContext()); + Group group = site.getGroup(group_id); + submission.setGroupId(group.getId()); + for (Member member : group.getMembers()) { + AssignmentSubmissionSubmitter ass = new AssignmentSubmissionSubmitter(); + String userId = member.getUserId(); + ass.setSubmitter(userId); + if (StringUtils.equals(submitter.getId(), userId)) ass.setSubmittee(true); + submitters.add(ass); + } + } catch (IdUnusedException e) { + log.warn("could not access the site {}, {}", a.getContext(), e.getMessage()); + } + } else { + AssignmentSubmissionSubmitter ass = new AssignmentSubmissionSubmitter(); + String userId = u.getId(); + ass.setSubmitter(userId); + if (StringUtils.equals(submitter.getId(), userId)) ass.setSubmittee(true); + submitters.add(ass); } submission.setUserSubmission(true); submission.setSubmittedText(text); diff --git a/assignment/tool/src/webapp/vm/assignment/chef_assignments_instructor_grading_submission.vm b/assignment/tool/src/webapp/vm/assignment/chef_assignments_instructor_grading_submission.vm index 66e824649812..ae7584fdb48f 100644 --- a/assignment/tool/src/webapp/vm/assignment/chef_assignments_instructor_grading_submission.vm +++ b/assignment/tool/src/webapp/vm/assignment/chef_assignments_instructor_grading_submission.vm @@ -673,8 +673,8 @@ #end ## the previous grades - #set ($previousGrades = $submission.Properties.get($submission.Properties.getNamePropSubmissionScaledPreviousGrades())) - #if ($!previousGrades && $!previousGrades.length() != 0 ) + #set ($previousGrades = $submission.Properties.get($NamePropSubmissionScaledPreviousGrades)) + #if ($previousGrades && $previousGrades.length() > 0 )

expand collapse @@ -707,7 +707,7 @@ #if ($!prevFeedbackComment)

expand - collapse + collapse $tlang.getString("gradingsub.prefee2")