Skip to content

Commit

Permalink
Merge pull request sakaiproject#1726 from payten/1389-categorized-sor…
Browse files Browse the repository at this point in the history
…t-order

1389: Refactor categorized sort order to use DB column instead of site properties XML
  • Loading branch information
steveswinsburg committed Feb 21, 2016
2 parents 0327c5d + aa0d817 commit 407d94a
Show file tree
Hide file tree
Showing 26 changed files with 665 additions and 313 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@ public class Assignment implements Serializable, Comparable<Assignment> {
//Needed for transfer
private boolean categoryExtraCredit;
private Integer sortOrder;
private Integer categorizedSortOrder;
private Long categoryId;
private Integer categoryOrder;


public Assignment() {
Expand Down Expand Up @@ -233,6 +235,14 @@ public Long getCategoryId() {
public void setCategoryId(Long categoryId) {
this.categoryId = categoryId;
}

public Integer getCategoryOrder() {
return categoryOrder;
}

public void setCategoryOrder(Integer categoryOrder) {
this.categoryOrder = categoryOrder;
}

@Override
public int compareTo(Assignment o) {
Expand All @@ -246,4 +256,11 @@ public String toString() {
return ToStringBuilder.reflectionToString(this, ToStringStyle.MULTI_LINE_STYLE);
}

public Integer getCategorizedSortOrder() {
return categorizedSortOrder;
}

public void setCategorizedSortOrder(Integer categorizedSortOrder) {
this.categorizedSortOrder = categorizedSortOrder;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
package org.sakaiproject.service.gradebook.shared;

import java.io.Serializable;
import java.util.Comparator;
import java.util.List;

import org.apache.commons.lang.builder.ToStringBuilder;
Expand All @@ -44,7 +45,10 @@ public class CategoryDefinition implements Serializable {
private Integer dropHighest;
private Integer keepHighest;
private Boolean extraCredit;
private Integer categoryOrder;

public static Comparator<CategoryDefinition> orderComparator;

private List<Assignment> assignmentList;

public CategoryDefinition() {
Expand Down Expand Up @@ -159,9 +163,35 @@ public Boolean isExtraCredit() {
public void setExtraCredit(Boolean extraCredit) {
this.extraCredit = extraCredit;
}

public Integer getCategoryOrder() {
return categoryOrder;
}

public void setCategoryOrder(Integer categoryOrder) {
this.categoryOrder = categoryOrder;
}

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

static {
orderComparator = new Comparator<CategoryDefinition>() {
@Override
public int compare(final CategoryDefinition c1, final CategoryDefinition c2) {
if (c1.getCategoryOrder() == null && c2.getCategoryOrder() == null) {
return c1.getName().compareTo(c2.getName());
}
if(c1.getCategoryOrder() == null) {
return -1;
}
if(c2.getCategoryOrder() == null) {
return 1;
}
return c1.getCategoryOrder().compareTo(c2.getCategoryOrder());
}
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,21 @@ public boolean isAssignmentDefined(String gradebookUid, String assignmentTitle)
*/
public List<Assignment> getViewableAssignmentsForCurrentUser(String gradebookUid);

/**
*
* @param gradebookUid
* @return list of gb items that the current user is authorized to view
* sorted by the provided SortType.
* If user has gradeAll permission, returns all gb items.
* If user has gradeSection perm with no grader permissions,
* returns all gb items.
* If user has gradeSection with grader perms, returns only the items that
* the current user is authorized to view or grade.
* If user does not have grading privileges but does have viewOwnGrades perm,
* will return all released gb items.
*/
public List<Assignment> getViewableAssignmentsForCurrentUser(String gradebookUid, SortType sortBy);

/**
*
* @param gradebookUid
Expand Down Expand Up @@ -830,4 +845,13 @@ public void finalizeGrades(String gradebookUid)
* @param grade the new course grade
*/
void updateCourseGradeForStudent(String gradebookUid, String studentUuid, String grade);

/**
* Updates the categorized order of an assignment
* @param gradebookUid uuid of the gradebook
* @param categoryId id of the category
* @param assignmentId id of the assignment
* @param order new position of the assignment
*/
void updateAssignmentCategorizedOrder(final String gradebookUid, final Long categoryId, final Long assignmentId, Integer order);
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,6 @@ public enum SortType {
SORT_BY_RELEASED,
SORT_BY_COUNTED,
SORT_BY_EDITOR,
SORT_BY_CATEGORY,
SORT_BY_SORTING; //default
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@

<property name="removed" column="REMOVED" type="boolean" />

<property name="sortOrder" column="SORT_ORDER" type="java.lang.Integer" />
<property name="sortOrder" column="SORT_ORDER" type="java.lang.Integer" />

<property name="categorizedSortOrder" column="CATEGORIZED_SORT_ORDER" type="java.lang.Integer" />

<subclass name="org.sakaiproject.tool.gradebook.Assignment" extends="org.sakaiproject.tool.gradebook.GradableObject" discriminator-value="1">
<property name="pointsPossible" column="POINTS_POSSIBLE" type="double" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ public class Assignment extends GradableObject {
public static Comparator releasedComparator;
public static Comparator countedComparator;
public static Comparator gradeEditorComparator;
public static Comparator categoryComparator;

private Double pointsPossible;
private Date dueDate;
Expand Down Expand Up @@ -230,6 +231,63 @@ public String toString() {
return "Assignment.gradeEditorComparator";
}
};

categoryComparator = new Comparator() {
public int compare(Object o1, Object o2) {
if(log.isDebugEnabled()) log.debug("Comparing assignment + " + o1 + " to " + o2 + " by category ordering");
Assignment one = (Assignment)o1;
Assignment two = (Assignment)o2;

// if categories are null
if (one.getCategory() == null && two.getCategory() == null) {
// sort by assignment sort order
return one.getSortOrder().compareTo(two.getSortOrder());
} else if (one.getCategory() == null) {
return 1;
} else if (two.getCategory() == null) {
return -1;
}

// if in the same category, sort by their categorized sort order
if (one.getCategory().equals(two.getCategory())) {
// handles null orders by putting them at the end of the list
if (one.getCategorizedSortOrder() == null) {
return 1;
} else if (two.getCategorizedSortOrder() == null) {
return -1;
}
return Integer.compare(one.getCategorizedSortOrder(), two.getCategorizedSortOrder());

// otherwise, sort by their category order
} else {
// check if category has a order (not required)
if (one.getCategory().getCategoryOrder() == null && two.getCategory().getCategoryOrder() == null) {
// both orders are null.. so order by A-Z
if (one.getCategory().getName() == null && two.getCategory().getName() == null) {
// both names are null so order by id
return one.getCategory().getId().compareTo(two.getCategory().getId());
} else if (one.getCategory().getName() == null) {
return 1;
} else if (two.getCategory().getName() == null) {
return -1;
} else {
return one.getCategory().getName().compareTo(two.getCategory().getName());
}
} else if (one.getCategory().getCategoryOrder() == null) {
return 1;
} else if (two.getCategory().getCategoryOrder() == null) {
return -1;
} else {
return one.getCategory().getCategoryOrder().compareTo(two.getCategory().getCategoryOrder());
}
}
}

@Override
public String toString() {
return "Assignment.categoryComparator";
}
};
}

public Assignment(Gradebook gradebook, String name, Double pointsPossible, Date dueDate) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public abstract class GradableObject implements Serializable {
protected Gradebook gradebook;
protected String name;
protected Integer sortOrder;
protected Integer categorizedSortOrder;

protected Double mean; // not persisted; not used in all contexts (in Overview & Assignment Grading,
// not in Roster or Student View)
Expand Down Expand Up @@ -341,6 +342,14 @@ public void setSortOrder(Integer sortOrder) {
this.sortOrder = sortOrder;
}

public Integer getCategorizedSortOrder() {
return categorizedSortOrder;
}

public void setCategorizedSortOrder(Integer value) {
this.categorizedSortOrder = value;
}

}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,12 @@ public void postEvent(String message,String objectReference){
eventTrackingService.postEvent(message,objectReference);
}

public Long createCategory(final Long gradebookId, final String name, final Double weight, final Integer drop_lowest, final Integer dropHighest, final Integer keepHighest, final Boolean is_extra_credit)

public Long createCategory(final Long gradebookId, final String name, final Double weight, final Integer drop_lowest, final Integer dropHighest, final Integer keepHighest, final Boolean is_extra_credit) {
return createCategory(gradebookId, name, weight, drop_lowest, dropHighest, keepHighest, is_extra_credit, null);
}

public Long createCategory(final Long gradebookId, final String name, final Double weight, final Integer drop_lowest, final Integer dropHighest, final Integer keepHighest, final Boolean is_extra_credit, final Integer categoryOrder)
throws ConflictingCategoryNameException, StaleObjectModificationException {
HibernateCallback hc = new HibernateCallback() {
public Object doInHibernate(Session session) throws HibernateException {
Expand Down Expand Up @@ -503,6 +508,7 @@ public Object doInHibernate(Session session) throws HibernateException {
//ca.setItemValue(itemValue);
ca.setRemoved(false);
ca.setExtraCredit(is_extra_credit);
ca.setCategoryOrder(categoryOrder);

Long id = (Long)session.save(ca);

Expand Down
Loading

0 comments on commit 407d94a

Please sign in to comment.