Skip to content

Commit

Permalink
Merge pull request sakaiproject#940 from ern/SAK-29517
Browse files Browse the repository at this point in the history
SAK-29517 fix comments not being sent to gb for linked/associated assignments
  • Loading branch information
jonespm committed Aug 6, 2015
2 parents 07f3472 + 74fdc87 commit 226b95c
Showing 1 changed file with 22 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4926,9 +4926,8 @@ protected boolean isGradebookDefined()
boolean rv = false;
try
{
GradebookService g = (GradebookService) ComponentManager
.get("org.sakaiproject.service.gradebook.GradebookService");
String gradebookUid = ToolManager.getInstance().getCurrentPlacement().getContext();
GradebookService g = (GradebookService) ComponentManager.get("org.sakaiproject.service.gradebook.GradebookService");
String gradebookUid = ToolManager.getCurrentPlacement().getContext();
if (g.isGradebookDefined(gradebookUid) && (g.currentUserHasEditPerm(gradebookUid) || g.currentUserHasGradingPerm(gradebookUid)))
{
rv = true;
Expand Down Expand Up @@ -5043,7 +5042,7 @@ protected void integrateGradebook (SessionState state, String assignmentRef, Str
GradebookService g = (GradebookService) ComponentManager.get("org.sakaiproject.service.gradebook.GradebookService");
GradebookExternalAssessmentService gExternal = (GradebookExternalAssessmentService) ComponentManager.get("org.sakaiproject.service.gradebook.GradebookExternalAssessmentService");

String gradebookUid = ToolManager.getInstance().getCurrentPlacement().getContext();
String gradebookUid = ToolManager.getCurrentPlacement().getContext();
if (g.isGradebookDefined(gradebookUid) && g.currentUserHasGradingPerm(gradebookUid))
{
boolean isExternalAssignmentDefined=gExternal.isExternalAssignmentDefined(gradebookUid, assignmentRef);
Expand Down Expand Up @@ -5073,19 +5072,8 @@ protected void integrateGradebook (SessionState state, String assignmentRef, Str
addAlert(state, rb.getFormattedMessage("addtogradebook.nonUniqueTitle", new Object[]{"\"" + newAssignment_title + "\""}));
M_log.warn(this + ":integrateGradebook " + e.getMessage());
}
catch (ConflictingExternalIdException e)
{
// this shouldn't happen, as we have already checked for assignment reference before. Log the error
M_log.warn(this + ":integrateGradebook " + e.getMessage());
}
catch (GradebookNotFoundException e)
{
// this shouldn't happen, as we have checked for gradebook existence before
M_log.warn(this + ":integrateGradebook " + e.getMessage());
}
catch (Exception e)
{
// ignore
M_log.warn(this + ":integrateGradebook " + e.getMessage());
}
}
Expand Down Expand Up @@ -5116,11 +5104,13 @@ else if ("remove".equals(addUpdateRemoveAssignment))
if (updateRemoveSubmission != null)
{
Assignment a = getAssignment(assignmentRef, "integrateGradebook", state);

if (a != null)
{
String propAddToGradebook = a.getProperties().getProperty(NEW_ASSIGNMENT_ADD_TO_GRADEBOOK);
if ("update".equals(updateRemoveSubmission)
&& (StringUtils.equals( propAddToGradebook, AssignmentService.GRADEBOOK_INTEGRATION_ADD) || StringUtils.equals( propAddToGradebook, AssignmentService.GRADEBOOK_INTEGRATION_ASSOCIATE))
&& (StringUtils.equals( propAddToGradebook, AssignmentService.GRADEBOOK_INTEGRATION_ADD)
|| StringUtils.equals( propAddToGradebook, AssignmentService.GRADEBOOK_INTEGRATION_ASSOCIATE))
&& a.getContent().getTypeOfGrade() == Assignment.SCORE_GRADE_TYPE)
{
if (submissionRef == null)
Expand All @@ -5147,7 +5137,7 @@ else if ("remove".equals(addUpdateRemoveAssignment))
for (int i=0; submitters != null && i < submitters.length; i++) {
String submitterId = submitters[i].getId();
String gradeStringToUse = (a.isGroup() && aSubmission.getGradeForUser(submitterId) != null)
? displayGrade(state,aSubmission.getGradeForUser(submitterId), a.getContent().getFactor()): grade;
? displayGrade(state,aSubmission.getGradeForUser(submitterId), a.getContent().getFactor()): grade;
sm.put(submitterId, gradeStringToUse);
cm.put(submitterId, commentString);
}
Expand All @@ -5167,14 +5157,17 @@ else if ("remove".equals(addUpdateRemoveAssignment))
}
else if (isAssignmentDefined)
{
Long associateGradebookAssignmentId = g.getAssignment(gradebookUid, associateGradebookAssignment).getId();
// the associated assignment is internal one, update records one by one
for (Map.Entry<String, String> entry : sm.entrySet())
{
String submitterId = (String) entry.getKey();
String grade = StringUtils.trimToNull(displayGrade(state, (String) sm.get(submitterId), a.getContent().getFactor()));
if (grade != null)
{
g.setAssignmentScoreString(gradebookUid, associateGradebookAssignment, submitterId, grade, "");
g.setAssignmentScoreString(gradebookUid, associateGradebookAssignmentId, submitterId, grade, "");
String comment = StringUtils.isNotEmpty(cm.get(submitterId)) ? cm.get(submitterId) : "";
g.setAssignmentScoreComment(gradebookUid, associateGradebookAssignmentId, submitterId, comment);
}
}
}
Expand All @@ -5196,31 +5189,36 @@ else if (isExternalAssignmentDefined)
User[] submitters = aSubmission.getSubmitters();
String gradeString = displayGrade(state, StringUtils.trimToNull(aSubmission.getGrade(false)), factor);
for (int i=0; submitters != null && i < submitters.length; i++) {
String gradeStringToUse = (a.isGroup() && aSubmission.getGradeForUser(submitters[i].getId()) != null)
? displayGrade(state,aSubmission.getGradeForUser(submitters[i].getId()), factor): gradeString;
String gradeStringToUse = (a.isGroup() && aSubmission.getGradeForUser(submitters[i].getId()) != null)
? displayGrade(state,aSubmission.getGradeForUser(submitters[i].getId()), factor): gradeString;
//Gradebook only supports plaintext strings
String commentString = FormattedText.convertFormattedTextToPlaintext(aSubmission.getFeedbackComment());
if (associateGradebookAssignment != null)
{
if (gExternal.isExternalAssignmentDefined(gradebookUid, associateGradebookAssignment))
{
// the associated assignment is externally maintained
gExternal.updateExternalAssessmentScore(gradebookUid, associateGradebookAssignment, submitters[i].getId(),
(gradeStringToUse != null && aSubmission.getGradeReleased()) ? gradeStringToUse : "");
//Gradebook only supports plaintext strings
String commentString = FormattedText.convertFormattedTextToPlaintext(aSubmission.getFeedbackComment());
gExternal.updateExternalAssessmentComment(gradebookUid, associateGradebookAssignment, submitters[i].getId(),
(commentString != null && aSubmission.getGradeReleased()) ? commentString : "");
}
else if (g.isAssignmentDefined(gradebookUid, associateGradebookAssignment))
{
Long associateGradebookAssignmentId = g.getAssignment(gradebookUid, associateGradebookAssignment).getId();
// the associated assignment is internal one, update records
g.setAssignmentScoreString(gradebookUid, associateGradebookAssignment, submitters[i].getId(),
g.setAssignmentScoreString(gradebookUid, associateGradebookAssignmentId, submitters[i].getId(),
(gradeStringToUse != null && aSubmission.getGradeReleased()) ? gradeStringToUse : "", "");
g.setAssignmentScoreComment(gradebookUid, associateGradebookAssignmentId, submitters[i].getId(),
(commentString != null && aSubmission.getGradeReleased()) ? commentString : "");
}
}
else
{
gExternal.updateExternalAssessmentScore(gradebookUid, assignmentRef, submitters[i].getId(),
(gradeStringToUse != null && aSubmission.getGradeReleased()) ? gradeStringToUse : "");
gExternal.updateExternalAssessmentComment(gradebookUid, assignmentRef, submitters[i].getId(),
(commentString != null && aSubmission.getGradeReleased()) ? commentString : "");
}
}
}
Expand Down Expand Up @@ -8802,7 +8800,7 @@ private void initIntegrateWithGradebook(SessionState state, String siteId, Strin
if (gradebookExists)
{
GradebookService g = (GradebookService) ComponentManager.get("org.sakaiproject.service.gradebook.GradebookService");
String gradebookUid = ToolManager.getInstance().getCurrentPlacement().getContext();
String gradebookUid = ToolManager.getCurrentPlacement().getContext();

String aReference = a.getReference();
String addUpdateRemoveAssignment = "remove";
Expand Down

0 comments on commit 226b95c

Please sign in to comment.