Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/sakaiproject/sakai
Browse files Browse the repository at this point in the history
  • Loading branch information
steveswinsburg committed Jan 23, 2018
2 parents 7cfd765 + 686e37c commit 4191674
Show file tree
Hide file tree
Showing 8 changed files with 178 additions and 565 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,15 @@
package org.sakaiproject.service.gradebook.shared;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;
import java.util.TreeMap;

import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;

/**
* DTO to wrap the persistent GradeMapping
* DTO to wrap the persistent GradeMapping and provides utility methods for dealing with grade mappings
*/
public class GradeMappingDefinition implements Serializable {

Expand All @@ -32,49 +34,90 @@ public class GradeMappingDefinition implements Serializable {
private String name;
private Map<String, Double> gradeMap;
private Map<String, Double> defaultBottomPercents;
public GradeMappingDefinition(Long id, String name, Map<String,Double> gradeMap, Map<String, Double> defaultBottomPercents){

public GradeMappingDefinition(final Long id, final String name, final Map<String,Double> gradeMap, final Map<String, Double> defaultBottomPercents){
this.id = Long.toString(id);
this.name = name;
this.gradeMap = gradeMap;
this.defaultBottomPercents = defaultBottomPercents;
}

public String getId() {
return id;
return this.id;
}

public void setId(String id) {
public void setId(final String id) {
this.id = id;
}

public String getName() {
return name;
return this.name;
}

public void setName(String name) {
public void setName(final String name) {
this.name = name;
}

/**
* Get the current grade mappings
*
* @return
*/
public Map<String, Double> getGradeMap() {
return gradeMap;
return this.gradeMap;
}

public void setGradeMap(Map<String, Double> gradeMap) {
public void setGradeMap(final Map<String, Double> gradeMap) {
this.gradeMap = gradeMap;
}

/**
* Get the default grade mappings
*
* @return
*/
public Map<String, Double> getDefaultBottomPercents() {
return defaultBottomPercents;
return this.defaultBottomPercents;
}

public void setDefaultBottomPercents(Map<String, Double> defaultBottomPercents) {
public void setDefaultBottomPercents(final Map<String, Double> defaultBottomPercents) {
this.defaultBottomPercents = defaultBottomPercents;
}

@Override
public String toString() {
return ToStringBuilder.reflectionToString(this, ToStringStyle.MULTI_LINE_STYLE);
}


/**
* Handles the sorting of a grade mapping.
*
* Note that the output of this is a {@link TreeMap} which should be taken into consideration if performing element comparisons as the
* equals() implementation is different for TreeMaps vs HashMaps.
*
* @param gradeMap the grademap to be sorted
* @return {@link TreeMap} of sorted entries
*/
public static Map<String, Double> sortGradeMapping(final Map<String, Double> gradeMap) {

// we only ever order by bottom percents now
final DoubleComparator doubleComparator = new DoubleComparator(gradeMap);
final Map<String, Double> rval = new TreeMap<>(doubleComparator);
rval.putAll(gradeMap);

return rval;
}

/**
* Determines if the grade mapping is different to the defaults
*
* @return
*/
public boolean isModified() {
// TreeMap.equals uses compareTo for comparisons so cannot be used for equals in this case. Convert to HashMap.
final Map<String, Double> left = new HashMap<>(this.gradeMap);
final Map<String, Double> right = new HashMap<>(this.defaultBottomPercents);
return !left.equals(right);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public GradeMapping() {

public GradeMapping(final GradingScale gradingScale) {
setGradingScale(gradingScale);
this.gradeMap = new HashMap<String, Double>(gradingScale.getDefaultBottomPercents());
this.gradeMap = new HashMap<>(gradingScale.getDefaultBottomPercents());
}

public String getName() {
Expand All @@ -62,7 +62,7 @@ public String getName() {
* Sets the percentage values for this GradeMapping to their default values.
*/
public void setDefaultValues() {
this.gradeMap = new HashMap<String, Double>(getDefaultBottomPercents());
this.gradeMap = new HashMap<>(getDefaultBottomPercents());
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ public GradebookInformation getGradebookInformation(final String gradebookUid) {

//note that these are not the DEFAULT bottom percents but the configured ones per gradebook
Map<String, Double> gradeMap = selectedGradeMapping.getGradeMap();
gradeMap = GradeMapping.sortGradeMapping(gradeMap);
gradeMap = GradeMappingDefinition.sortGradeMapping(gradeMap);
rval.setSelectedGradingScaleBottomPercents(gradeMap);
rval.setGradeScale(selectedGradeMapping.getGradingScale().getName());
}
Expand Down Expand Up @@ -3344,7 +3344,7 @@ public Map<String, org.sakaiproject.service.gradebook.shared.CourseGrade> getCou
final List<CourseGradeRecord> gradeRecords = getPointsEarnedCourseGradeRecords(getCourseGrade(gradebook.getId()), userUuids);

// gradeMap MUST be sorted for the grade mapping to apply correctly
final Map<String, Double> sortedGradeMap = GradeMapping.sortGradeMapping(gradeMap);
final Map<String, Double> sortedGradeMap = GradeMappingDefinition.sortGradeMapping(gradeMap);

gradeRecords.forEach(gr -> {

Expand Down Expand Up @@ -3649,8 +3649,9 @@ private List<GradeMappingDefinition> getGradebookGradeMappings(final Set<GradeMa
final List<GradeMappingDefinition> rval = new ArrayList<>();

for(final GradeMapping mapping: gradeMappings) {
rval.add(new GradeMappingDefinition(mapping.getId(), mapping.getName(), mapping.getGradeMap(),
GradeMapping.sortGradeMapping(mapping.getDefaultBottomPercents())));
rval.add(new GradeMappingDefinition(mapping.getId(), mapping.getName(),
GradeMappingDefinition.sortGradeMapping(mapping.getGradeMap()),
GradeMappingDefinition.sortGradeMapping(mapping.getDefaultBottomPercents())));
}
return rval;

Expand Down
Loading

0 comments on commit 4191674

Please sign in to comment.