From b64414882556b71be041e79d11bbd0a164baab25 Mon Sep 17 00:00:00 2001 From: Steve Swinsburg Date: Thu, 1 Mar 2018 01:52:36 +1100 Subject: [PATCH] SAK-33964 Ensure every mapping in grading schema is added to dataset (#5350) * Remove unused code and cleanup other compiler warnings * Add rebel.xml to gitignore so that JRebel project config is not committed * SAK-33964 ensure the course grade dataset contains an entry for everything in the grading schema --- .../rest/GradebookNgEntityProvider.java | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/gradebookng/tool/src/java/org/sakaiproject/gradebookng/rest/GradebookNgEntityProvider.java b/gradebookng/tool/src/java/org/sakaiproject/gradebookng/rest/GradebookNgEntityProvider.java index e88399f2e4a2..b93cfe879a0d 100644 --- a/gradebookng/tool/src/java/org/sakaiproject/gradebookng/rest/GradebookNgEntityProvider.java +++ b/gradebookng/tool/src/java/org/sakaiproject/gradebookng/rest/GradebookNgEntityProvider.java @@ -238,7 +238,7 @@ public CourseGradeSummary getCourseGradeSummary(final EntityView view, final Map // get the course grades and re-map to summary. Also sorts the data so it is ready for the consumer to use final Map courseGrades = this.businessService.getCourseGrades(siteId, gradingSchema); - + return reMap(courseGrades, gradingSchema.keySet()); } @@ -329,7 +329,7 @@ private GbRole getUserRole(final String siteId) { /** * Re-map the course grades returned from the business service into our CourseGradeSummary object for returning on the REST API. - * + * * @param courseGrades map of student to course grade * @param gradingSchema the grading schema that has the order * @return @@ -339,15 +339,20 @@ private CourseGradeSummary reMap(final Map courseGrades, fi courseGrades.forEach((k,v) -> { summary.add(v.getDisplayGrade()); }); - + //sort the map based on the ordered schema - Map originalData = summary.getDataset(); - Map sortedData = new LinkedHashMap<>(); + final Map originalData = summary.getDataset(); + final Map sortedData = new LinkedHashMap<>(); order.forEach(o -> { - sortedData.put(o, originalData.get(o)); + // data set must contain everything in the grading schema + Integer value = originalData.get(o); + if (value == null) { + value = 0; + } + sortedData.put(o, value); }); summary.setDataset(sortedData); - + return summary; }