Skip to content

Commit

Permalink
SAK-29890 Fix the bug by removing duplicates when getting the list of…
Browse files Browse the repository at this point in the history
… assignments for a user.
  • Loading branch information
steveswinsburg committed Sep 14, 2015
1 parent 2a9c13c commit 7372419
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 5 deletions.
7 changes: 7 additions & 0 deletions edu-services/gradebook-service/api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,11 @@
<properties>
<deploy.target>shared</deploy.target>
</properties>

<dependencies>
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,13 @@
import java.io.Serializable;
import java.util.Date;

import org.apache.commons.lang.builder.CompareToBuilder;

/**
* JavaBean to hold data associated with a Gradebook assignment.
* The Course Grade is not considered an assignment.
*/
public class Assignment implements Serializable {
public class Assignment implements Serializable, Comparable<Assignment> {
private static final long serialVersionUID = 1L;

private String name;
Expand Down Expand Up @@ -229,5 +231,12 @@ public Long getCategoryId() {
public void setCategoryId(Long categoryId) {
this.categoryId = categoryId;
}

@Override
public int compareTo(Assignment o) {
return new CompareToBuilder()
.append(this.id, o.id)
.toComparison();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@
import java.util.Map.Entry;
import java.util.Set;
import java.util.HashSet;
import java.util.SortedSet;
import java.util.TreeSet;

import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
Expand Down Expand Up @@ -1308,7 +1310,7 @@ public List<org.sakaiproject.service.gradebook.shared.Assignment> getViewableAss
throws GradebookNotFoundException {

List<Assignment> viewableAssignments = new ArrayList<>();
List<org.sakaiproject.service.gradebook.shared.Assignment> assignmentsToReturn = new ArrayList<>();
SortedSet<org.sakaiproject.service.gradebook.shared.Assignment> assignmentsToReturn = new TreeSet<>();

Gradebook gradebook = getGradebook(gradebookUid);

Expand All @@ -1325,12 +1327,12 @@ public List<org.sakaiproject.service.gradebook.shared.Assignment> getViewableAss
// if this gradebook has categories enabled, we need to check for category-specific restrictions

if (gradebook.getCategory_type() == GradebookService.CATEGORY_TYPE_NO_CATEGORY) {
assignmentsToReturn = getAssignments(gradebookUid);
assignmentsToReturn.addAll(getAssignments(gradebookUid));
} else {

String userUid = getUserUid();
if (getGradebookPermissionService().getPermissionForUserForAllAssignment(gradebook.getId(), userUid)) {
assignmentsToReturn = getAssignments(gradebookUid);
assignmentsToReturn.addAll(getAssignments(gradebookUid));
}

// categories are enabled, so we need to check the category restrictions
Expand Down Expand Up @@ -1381,7 +1383,7 @@ public List<org.sakaiproject.service.gradebook.shared.Assignment> getViewableAss
}
}

return assignmentsToReturn;
return new ArrayList<>(assignmentsToReturn);

}

Expand Down

0 comments on commit 7372419

Please sign in to comment.