Skip to content

Commit

Permalink
SAK-45051 Add Gradebook items to Tasks widget (sakaiproject#10139)
Browse files Browse the repository at this point in the history
SAK-45051 Add Gradebook items to Tasks widget

SAK-45051 Add Gradebook items to Tasks widget

SAK-45051 Add Gradebook items to Tasks widget

SAK-45051 Add Gradebook items to Tasks widget

SAK-45051 Add Gradebook items to Tasks widget

SAK-45051 Add Gradebook items to Tasks widget
  • Loading branch information
ropemar authored Feb 1, 2022
1 parent 1c7fd22 commit e705248
Show file tree
Hide file tree
Showing 12 changed files with 188 additions and 8 deletions.
8 changes: 8 additions & 0 deletions edu-services/gradebook-service/api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@
</properties>

<dependencies>
<dependency>
<groupId>org.sakaiproject.kernel</groupId>
<artifactId>sakai-component-manager</artifactId>
</dependency>
<dependency>
<groupId>org.sakaiproject.kernel</groupId>
<artifactId>sakai-kernel-api</artifactId>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,13 +144,23 @@ public class Assignment implements Serializable, Comparable<Assignment> {
@Getter
@Setter
private Integer categorizedSortOrder;
@Getter
@Setter
private boolean createTask;

/**
* For editing. Not persisted.
*/
@Getter
@Setter
private boolean scaleGrades;
@Getter
@Setter
private String context;
@Getter
@Setter
private String gradebookId;


@Override
public int compareTo(final Assignment o) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
import java.util.Set;

import org.apache.commons.lang3.StringUtils;
import org.sakaiproject.entity.api.Entity;
import org.sakaiproject.entity.api.EntityProducer;

/**
* This is the externally exposed API of the gradebook application.
Expand All @@ -43,7 +45,7 @@
* <p>
* WARNING: For documentation of the deprecated methods, please see the service interfaces which own them.
*/
public interface GradebookService {
public interface GradebookService extends EntityProducer {
// Application service hooks.

// These have been deprecated in favour of the {@link GradingType} enum
Expand All @@ -57,6 +59,8 @@ public interface GradebookService {
public static final int CATEGORY_TYPE_NO_CATEGORY = 1;
public static final int CATEGORY_TYPE_ONLY_CATEGORY = 2;
public static final int CATEGORY_TYPE_WEIGHTED_CATEGORY = 3;
public static final String REFERENCE_ROOT = "/gbassignment";
public static final String SAKAI_GBASSIGNMENT = "sakai:gbassignment";

public static final String[] validLetterGrade = { "a+", "a", "a-", "b+", "b", "b-",
"c+", "c", "c-", "d+", "d", "d-", "f" };
Expand All @@ -73,7 +77,7 @@ public interface GradebookService {
public static final String enableLetterGradeString = "gradebook_enable_letter_grade";

public static final MathContext MATH_CONTEXT = new MathContext(10, RoundingMode.HALF_DOWN);

/**
* An enum for defining valid/invalid information for a points possible/relative weight value for a gradebook item. See
* {@link GradebookService#isPointsPossibleValid(String, Assignment, Double)} for usage
Expand Down Expand Up @@ -207,6 +211,17 @@ public List<Assignment> getAssignments(String gradebookUid, SortType sortBy)
public Assignment getAssignment(String gradebookUid, Long assignmentId)
throws AssessmentNotFoundException;

/**
* Get an assignment based on its id
*
* @param gradebookUid
* @param assignmentId
* @return the associated Assignment with the given assignmentId
* @throws AssessmentNotFoundException
*/
public Assignment getAssignmentByID(final Long gradeableObjectID)
throws AssessmentNotFoundException;

/**
* Get an assignment based on its name. This is provided for backward compatibility only.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,14 @@ protected GradebookAssignment getAssignmentWithoutStats(final String gradebookUi
.setParameter("gradebookuid", gradebookUid)
.uniqueResult();
}

protected GradebookAssignment getAssignmentById(final Long assignmentId) throws HibernateException {
return (GradebookAssignment) getSessionFactory().getCurrentSession()
.createCriteria(GradebookAssignment.class)
.add(Restrictions.eq("id", assignmentId))
.add(Restrictions.eq("removed", false))
.uniqueResult();
}

protected void updateAssignment(final GradebookAssignment assignment) throws ConflictingAssignmentNameException, HibernateException {
// Ensure that we don't have the assignment in the session, since
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;
Expand All @@ -49,6 +50,10 @@
import org.hibernate.query.Query;
import org.sakaiproject.authz.cover.SecurityService;
import org.sakaiproject.component.api.ServerConfigurationService;
import org.sakaiproject.entity.api.Entity;
import org.sakaiproject.entity.api.EntityManager;
import org.sakaiproject.entity.api.Reference;
import org.sakaiproject.exception.IdUnusedException;
import org.sakaiproject.hibernate.HibernateCriterionUtils;
import org.sakaiproject.rubrics.logic.RubricsService;
import org.sakaiproject.section.api.coursemanagement.CourseSection;
Expand Down Expand Up @@ -77,7 +82,10 @@
import org.sakaiproject.service.gradebook.shared.exception.UnmappableCourseGradeOverrideException;
import org.sakaiproject.site.api.Group;
import org.sakaiproject.site.api.Site;
import org.sakaiproject.site.api.SitePage;
import org.sakaiproject.site.api.SiteService;
import org.sakaiproject.site.api.ToolConfiguration;
import org.sakaiproject.tool.api.ToolManager;
import org.sakaiproject.tool.gradebook.AssignmentGradeRecord;
import org.sakaiproject.tool.gradebook.Category;
import org.sakaiproject.tool.gradebook.Comment;
Expand All @@ -91,6 +99,7 @@
import org.sakaiproject.tool.gradebook.LetterGradePercentMapping;
import org.sakaiproject.tool.gradebook.facades.Authz;
import org.sakaiproject.util.ResourceLoader;
import org.springframework.beans.factory.ObjectFactory;
import org.springframework.orm.hibernate5.HibernateCallback;
import org.springframework.orm.hibernate5.HibernateOptimisticLockingFailureException;

Expand All @@ -110,9 +119,18 @@ public class GradebookServiceHibernateImpl extends BaseHibernateManager implemen

@Setter
protected ServerConfigurationService serverConfigService;

@Setter private EntityManager entityManager;
@Setter private ToolManager toolManager;

@Getter @Setter
private RubricsService rubricsService;

public void init() {
// register as an entity producer
entityManager.registerEntityProducer(this, REFERENCE_ROOT);
}

@Override
public boolean isAssignmentDefined(final String gradebookUid, final String assignmentName) {
if (!isUserAbleToViewAssignments(gradebookUid)) {
Expand All @@ -129,6 +147,32 @@ public Object doInHibernate(final Session session) {
});
return (assignment != null);
}

@Override
public Optional<String> getEntityUrl(Reference ref, Entity.UrlType urlType) {
try {
Site site = siteService.getSite(ref.getContext());
ToolConfiguration fromTool = site.getToolForCommonId("sakai.gradebookng");
String entityUrl = null;
if (fromTool != null) {
entityUrl = String.format("%s/directtool/%s", serverConfigService.getPortalUrl(), fromTool.getId());
}
return Optional.of(entityUrl);
} catch (Exception e) {
log.error("ERROR getting gradebook assignment entity URL", e);
return Optional.empty();
}
}

@Override
public boolean parseEntityReference(String stringReference, Reference reference) {
if (StringUtils.startsWith(stringReference, REFERENCE_ROOT)) {
String[] parts = StringUtils.splitPreserveAllTokens(stringReference, Entity.SEPARATOR);
reference.set(SAKAI_GBASSIGNMENT, parts[2], parts[4], parts[3], parts[3]);
return true;
}
return false;
}

private boolean isUserAbleToViewAssignments(final String gradebookUid) {
final Authz authz = getAuthz();
Expand Down Expand Up @@ -199,6 +243,27 @@ public org.sakaiproject.service.gradebook.shared.Assignment getAssignment(final

return getAssignmentDefinition(assignment);
}

/**
* Method to retrieve Assignment by ID.
*
* @param gradeableObjectID
* @return
*/
public Assignment getAssignmentByID(final Long gradeableObjectID) throws AssessmentNotFoundException {
GradebookAssignment assignment = (GradebookAssignment) getHibernateTemplate().execute(new HibernateCallback() {
@Override
public Object doInHibernate(final Session session) throws HibernateException {
return getAssignmentById(gradeableObjectID);
}
});

if (assignment == null) {
throw new AssessmentNotFoundException("No gradebook item exists with gradable object id = " + gradeableObjectID);
}

return getAssignmentDefinition(assignment);
}

@Override
@Deprecated
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@

<bean id="org_sakaiproject_service_gradebook_GradebookServiceTarget"
class="org.sakaiproject.component.gradebook.GradebookServiceHibernateImpl"
name="org.sakaiproject.service.gradebook.GradebookServiceTarget">
name="org.sakaiproject.service.gradebook.GradebookServiceTarget"
init-method="init">
<property name="sessionFactory"><ref bean="org.sakaiproject.springframework.orm.hibernate.GlobalSessionFactory"/></property>
<property name="sectionAwareness">
<ref bean="org.sakaiproject.section.api.SectionAwareness" />
Expand All @@ -89,14 +90,15 @@
</property>
<property name="serverConfigService" ref="org.sakaiproject.component.api.ServerConfigurationService" />
<property name="rubricsService" ref="org.sakaiproject.rubrics.logic.RubricsService" />
<property name="entityManager" ref="org.sakaiproject.entity.api.EntityManager"/>
<property name="toolManager" ref="org.sakaiproject.tool.api.ToolManager" />
</bean>
<bean id="org_sakaiproject_service_gradebook_GradebookPermissionServiceTarget"
class="org.sakaiproject.component.gradebook.GradebookPermissionServiceImpl"
name="org.sakaiproject.service.gradebook.GradebookPermissionServiceTarget">
<property name="sessionFactory"><ref bean="org.sakaiproject.springframework.orm.hibernate.GlobalSessionFactory"/></property>
<property name="sectionAwareness"><ref bean="org.sakaiproject.section.api.SectionAwareness"/></property>
</bean>

</bean>

<bean id="gradebookServiceTemplate"
class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean"
Expand Down
1 change: 1 addition & 0 deletions gradebookng/bundle/src/main/bundle/gradebookng.properties
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ label.editgradeitem.due.help = Select a date
label.editgradeitem.category = Category
label.editgradeitem.release = Release item to students?
label.editgradeitem.include = Include item in course grade calculations?
label.editgradeitem.task = Create task in student dashboard?

#Rubrics
rubrics.dont_associate_label = Do not use a rubric to grade this assignment
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ label.editgradeitem.due.help=Seleccionar una fecha
label.editgradeitem.category=Categor\u00eda
label.editgradeitem.release=\u00bfPublicar este \u00edtem de calificaci\u00f3n al alumnado?
label.editgradeitem.include=\u00bfIncluir este \u00edtem en el c\u00e1lculo de la nota final?
label.editgradeitem.task =\u00bfCrear una tarea en el tablero del estudiante?

#Rubrics
rubrics.dont_associate_label=No utilizar r\u00fabricas para evaluar esta tarea
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import java.util.Set;
import java.util.TreeMap;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import lombok.Getter;
import lombok.Setter;
Expand All @@ -53,6 +54,7 @@
import org.sakaiproject.authz.api.SecurityService;
import org.sakaiproject.component.api.ServerConfigurationService;
import org.sakaiproject.component.cover.ComponentManager;
import org.sakaiproject.entity.api.Entity;
import org.sakaiproject.entity.api.ResourceProperties;
import org.sakaiproject.entity.api.ResourcePropertiesEdit;
import org.sakaiproject.coursemanagement.api.CourseManagementService;
Expand Down Expand Up @@ -101,6 +103,9 @@
import org.sakaiproject.site.api.Group;
import org.sakaiproject.site.api.Site;
import org.sakaiproject.site.api.SiteService;
import org.sakaiproject.tasks.api.Priorities;
import org.sakaiproject.tasks.api.Task;
import org.sakaiproject.tasks.api.TaskService;
import org.sakaiproject.time.api.UserTimeService;
import org.sakaiproject.tool.api.ToolManager;
import org.sakaiproject.tool.gradebook.Gradebook;
Expand Down Expand Up @@ -180,6 +185,10 @@ public class GradebookNgBusinessService {

@Setter
private UserTimeService userTimeService;

@Setter
private TaskService taskService;


public static final String GB_PREF_KEY = "GBNG-";
public static final String ASSIGNMENT_ORDER_PROP = "gbng_assignment_order";
Expand Down Expand Up @@ -1978,7 +1987,20 @@ public Long addAssignment(final Assignment assignment) {
Integer.MAX_VALUE);

EventHelper.postAddAssignmentEvent(gradebook, assignmentId, assignment, getUserRoleOrNone());


// Create the task
if (assignment.isCreateTask()) {
String reference = GradebookService.REFERENCE_ROOT + Entity.SEPARATOR + "a" + Entity.SEPARATOR + getCurrentSiteId() + Entity.SEPARATOR + assignmentId;
Task task = new Task();
task.setSiteId(getCurrentSiteId());
task.setReference(reference);
task.setSystem(true);
task.setDescription(assignment.getName());
task.setDue((assignment.getDueDate() == null) ? null : assignment.getDueDate().toInstant());
Set<String> users = new HashSet<>(this.getGradeableUsers());
taskService.createTask(task, users, Priorities.HIGH);
}

return assignmentId;

// TODO wrap this so we can catch any runtime exceptions
Expand Down Expand Up @@ -2221,7 +2243,29 @@ public void updateAssignment(final Assignment assignment) {
final Assignment original = this.getAssignment(assignment.getId());

this.gradebookService.updateAssignment(gradebook.getUid(), original.getId(), assignment);


// Update task
String reference = GradebookService.REFERENCE_ROOT + Entity.SEPARATOR + "a" + Entity.SEPARATOR + getCurrentSiteId() + Entity.SEPARATOR + original.getId();
Optional<Task> optTask = taskService.getTask(reference);
if (optTask.isPresent()) {
Task task = optTask.get();
task.setDescription(assignment.getName());
task.setDue((assignment.getDueDate() == null) ? null : assignment.getDueDate().toInstant());
taskService.saveTask(task);
} else {
// Create the task
if (assignment.isCreateTask()) {
Task task = new Task();
task.setSiteId(getCurrentSiteId());
task.setReference(reference);
task.setSystem(true);
task.setDescription(assignment.getName());
task.setDue((assignment.getDueDate() == null) ? null : assignment.getDueDate().toInstant());
Set<String> users = new HashSet<>(this.getGradeableUsers());
taskService.createTask(task, users, Priorities.HIGH);
}
}

EventHelper.postUpdateAssignmentEvent(gradebook, assignment, getUserRoleOrNone());

if (original.getCategoryId() != null && assignment.getCategoryId() != null
Expand Down Expand Up @@ -2591,6 +2635,10 @@ public void updateGradebookSettings(final GradebookInformation settings) {
*/
public void removeAssignment(final Long assignmentId) {

// Delete task
String reference = GradebookService.REFERENCE_ROOT + Entity.SEPARATOR + "a" + Entity.SEPARATOR + getCurrentSiteId() + Entity.SEPARATOR + assignmentId;
taskService.removeTaskByReference(reference);

rubricsService.deleteRubricAssociationsByItemIdPrefix(assignmentId.toString(), RubricsConstants.RBCS_TOOL_GRADEBOOKNG);
this.gradebookService.removeAssignment(assignmentId);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,16 @@
</div>
</div>
</div>
<div class="form-group form-group-sm" wicket:id="taskWrap">
<div class="col-xs-offset-3 col-xs-6">
<div class="checkbox">
<label>
<input wicket:id="createTask" type="checkbox" />
<span wicket:id="createTaskLabel"><wicket:message key="label.editgradeitem.task" /></span>
</label>
</div>
</div>
</div>

</wicket:panel>
</body>
Expand Down
Loading

0 comments on commit e705248

Please sign in to comment.