Skip to content

Commit

Permalink
SAK-46436 Add ability for instructors to manually create Tasks that a…
Browse files Browse the repository at this point in the history
…ren't automatically added via tools
  • Loading branch information
ropemar authored and Miguel Pellicer committed Apr 13, 2022
1 parent e5440b8 commit e3d2644
Show file tree
Hide file tree
Showing 26 changed files with 610 additions and 64 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ public String pageIndex(Model model, HttpServletRequest request) {
String siteId = toolManager.getCurrentPlacement().getContext();
model.addAttribute("cdnQuery", PortalUtils.getCDNQuery());

model.addAttribute("userId", session.getUserId());
if (siteService.isUserSite(siteId)) {
model.addAttribute("userId", session.getUserId());
return "home_dashboard";
return "home_dashboard";
} else {
model.addAttribute("siteId", siteId);
model.addAttribute("sakaiHtmlHead", (String) request.getAttribute("sakai.html.head"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@
</head>
<body>
<div class="portletBody">
<sakai-course-dashboard th:site-id="${siteId}"></sakai-course-dashboard>
<sakai-course-dashboard th:site-id="${siteId}" th:user-id="${userId}"></sakai-course-dashboard>
</div>

</body>

</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package org.sakaiproject.tasks.api;

public enum AssignationType {
user, site, group
}
4 changes: 4 additions & 0 deletions kernel/api/src/main/java/org/sakaiproject/tasks/api/Task.java
Original file line number Diff line number Diff line change
Expand Up @@ -83,4 +83,8 @@ public class Task implements PersistableEntity<Long> {
@Column(name = "DUE")
@Type(type = "org.hibernate.type.InstantType")
private Instant due;

@Column(name = "TASK_OWNER", length = 99)
private String owner;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package org.sakaiproject.tasks.api;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Index;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;

import org.sakaiproject.springframework.data.PersistableEntity;

import lombok.Data;
import lombok.EqualsAndHashCode;

@Data
@Entity
@EqualsAndHashCode(onlyExplicitlyIncluded = true)
@Table(name = "TASKS_ASSIGNED", indexes = {
@Index(name = "IDX_TASKS_ASSIGNED", columnList = "TASK_ID")
})
public class TaskAssigned implements PersistableEntity<Long> {

@Id
@Column(name = "ID")
@GeneratedValue(strategy = GenerationType.AUTO, generator = "tasks_assigned_id_sequence")
@SequenceGenerator(name = "tasks_assigned_id_sequence", sequenceName = "TASKS_ASSIGNED_S")
@EqualsAndHashCode.Include
private Long id;

@ManyToOne
@JoinColumn(name = "TASK_ID", nullable = false)
private Task task;

@Column(name = "ASSIGNATION_TYPE", nullable = false)
@Enumerated(EnumType.STRING)
private AssignationType type;

@Column(name = "OBJECT_ID", length = 99, nullable = true)
private String objectId;

}
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,18 @@ public interface TaskService {

UserTask createSingleUserTask(UserTaskAdapterBean transfer);
UserTask saveUserTask(UserTaskAdapterBean transfer);
UserTask createUserTask(Task task, UserTaskAdapterBean transfer);
void removeUserTask(Long userTaskId);
Task createTask(Task task, Set<String> users, Integer priority);
Task saveTask(Task task);
Optional<Task> getTask(String reference);
List<UserTaskAdapterBean> getAllTasksForCurrentUser();
List<UserTaskAdapterBean> getAllTasksForCurrentUserOnSite(String siteId);
List<UserTask> getCurrentUserTasks(String userId);
void removeTask(Task task);
void removeTaskByReference(String reference);
void completeUserTaskByReference(String reference, List<String> userIds);
void assignTask(Task task, AssignationType type, String objectId);
void assignTask(Task task, AssignationType type, List<String> objectIds);
List<TaskAssigned> getTaskAssignments(Long taskId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,6 @@
@Data
public class UserTaskAdapterBean {

public static UserTaskAdapterBean from(UserTask userTask) {

UserTaskAdapterBean bean = new UserTaskAdapterBean();
BeanUtils.copyProperties(userTask, bean);
BeanUtils.copyProperties(userTask.getTask(), bean);
bean.setUserTaskId(userTask.getId());
bean.setTaskId(userTask.getTask().getId());
return bean;
}

private Long userTaskId;
private Long taskId;
private String userId;
Expand All @@ -47,6 +37,7 @@ public static UserTaskAdapterBean from(UserTask userTask) {
private String reference;
private Boolean system;
private Boolean complete;
private String owner;

@JsonSerialize(using = InstantToMillisJsonSerializer.class)
@JsonDeserialize(using = MillisToInstantJsonDeserializer.class)
Expand All @@ -60,4 +51,18 @@ public static UserTaskAdapterBean from(UserTask userTask) {
private String notes;
private String url;
private Boolean softDeleted;
private String assignationType;
private String[] selectedGroups;
private String taskAssignedTo;

public static UserTaskAdapterBean from(UserTask userTask) {

UserTaskAdapterBean bean = new UserTaskAdapterBean();
BeanUtils.copyProperties(userTask, bean);
BeanUtils.copyProperties(userTask.getTask(), bean);
bean.setUserTaskId(userTask.getId());
bean.setTaskId(userTask.getTask().getId());
return bean;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package org.sakaiproject.tasks.api.repository;

import java.util.List;

import org.sakaiproject.springframework.data.SpringCrudRepository;
import org.sakaiproject.tasks.api.Task;
import org.sakaiproject.tasks.api.TaskAssigned;

public interface TaskAssignedRepository extends SpringCrudRepository<TaskAssigned, Long>{

List<TaskAssigned> findByTaskId(Long taskId);
void deleteByTask(Task task);

}
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public interface UserTaskRepository extends SpringCrudRepository<UserTask, Long>

List<UserTask> findByTaskIdAndUserIdIn(Long taskId, List<String> userIds);
List<UserTask> findByUserId(String userId);
List<UserTask> findByUserIdAndSiteId(String userId, String siteId);
List<UserTask> findByUserIdAndTask_StartsLessThanEqual(String userId, Instant instant);
List<UserTask> findByTask_SiteId(String siteId);
void deleteByTask(Task task);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;

import java.util.Arrays;
import java.util.List;
import java.util.Observable;
import java.util.Observer;
Expand All @@ -39,10 +41,13 @@
import org.sakaiproject.event.api.Event;
import org.sakaiproject.event.api.EventTrackingService;
import org.sakaiproject.site.api.SiteService;
import org.sakaiproject.tasks.api.AssignationType;
import org.sakaiproject.tasks.api.Task;
import org.sakaiproject.tasks.api.TaskAssigned;
import org.sakaiproject.tasks.api.UserTask;
import org.sakaiproject.tasks.api.TaskService;
import org.sakaiproject.tasks.api.UserTaskAdapterBean;
import org.sakaiproject.tasks.api.repository.TaskAssignedRepository;
import org.sakaiproject.tasks.api.repository.TaskRepository;
import org.sakaiproject.tasks.api.repository.UserTaskRepository;
import org.sakaiproject.tool.api.SessionManager;
Expand All @@ -68,6 +73,7 @@ public class TaskServiceImpl implements TaskService, Observer {
@Autowired private SiteService siteService;
@Autowired private TaskRepository taskRepository;
@Autowired private UserTaskRepository userTaskRepository;
@Autowired private TaskAssignedRepository taskAssignedRepository;

@Setter private TransactionTemplate transactionTemplate;

Expand Down Expand Up @@ -201,6 +207,14 @@ public UserTask saveUserTask(UserTaskAdapterBean transfer) {
BeanUtils.copyProperties(transfer, userTask);
return userTaskRepository.save(userTask);
}

@Transactional
public UserTask createUserTask(Task task, UserTaskAdapterBean transfer) {
UserTask userTask = new UserTask();
userTask.setTask(task);
BeanUtils.copyProperties(transfer, userTask);
return userTaskRepository.save(userTask);
}

@Transactional
public void removeUserTask(Long userTaskId) {
Expand Down Expand Up @@ -231,6 +245,22 @@ public List<UserTaskAdapterBean> getAllTasksForCurrentUser() {
return bean;
}).collect(Collectors.toList());
}

public List<UserTaskAdapterBean> getAllTasksForCurrentUserOnSite(String siteId) {

String userId = sessionManager.getCurrentSessionUserId();

return userTaskRepository.findByUserIdAndSiteId(userId, siteId)
.stream()
.map(ut -> {
UserTaskAdapterBean bean = new UserTaskAdapterBean();
BeanUtils.copyProperties(ut, bean);
BeanUtils.copyProperties(ut.getTask(), bean);
bean.setUserTaskId(ut.getId());
bean.setTaskId(ut.getTask().getId());
return bean;
}).collect(Collectors.toList());
}

public List<UserTask> getCurrentUserTasks(String userId) {
return userTaskRepository.findByUserIdAndTask_StartsLessThanEqual(userId, Instant.now());
Expand All @@ -255,8 +285,29 @@ public void completeUserTaskByReference(String reference, List<String> userIds)

@Transactional
public void removeTask(Task task) {

taskAssignedRepository.deleteByTask(task);
userTaskRepository.deleteByTask(task);
taskRepository.delete(task);
}

@Transactional
public void assignTask(Task task, AssignationType type, String objectId) {
assignTask(task, type, Arrays.asList(objectId));
}

@Transactional
public void assignTask(Task task, AssignationType type, List<String> objectIds) {
for (String objectId : objectIds) {
TaskAssigned taskAssigned = new TaskAssigned();
taskAssigned.setTask(task);
taskAssigned.setType(type);
taskAssigned.setObjectId(objectId);
taskAssignedRepository.save(taskAssigned);
}
}

@Transactional
public List<TaskAssigned> getTaskAssignments(Long taskId) {
return taskAssignedRepository.findByTaskId(taskId);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package org.sakaiproject.tasks.impl.repository;

import java.util.List;

import org.hibernate.Session;
import org.sakaiproject.springframework.data.SpringCrudRepositoryImpl;
import org.sakaiproject.tasks.api.Task;
import org.sakaiproject.tasks.api.TaskAssigned;
import org.sakaiproject.tasks.api.repository.TaskAssignedRepository;

public class TaskAssignedRepositoryImpl extends SpringCrudRepositoryImpl<TaskAssigned, Long> implements TaskAssignedRepository {

@Override
public List<TaskAssigned> findByTaskId(Long taskId) {
Session session = sessionFactory.getCurrentSession();
return session.createQuery("select u from TaskAssigned u where task.id = :taskId")
.setParameter("taskId", taskId).list();
}

@Override
public void deleteByTask(Task task) {
Session session = sessionFactory.getCurrentSession();
session.createQuery("delete from TaskAssigned where task = :task")
.setParameter("task", task).executeUpdate();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,15 @@ public List<UserTask> findByUserId(String userId) {
return (List<UserTask>) session.createCriteria(UserTask.class)
.add(Restrictions.eq("userId", userId)).list();
}

public List<UserTask> findByUserIdAndSiteId(String userId, String siteId) {

Session session = sessionFactory.getCurrentSession();

return session.createQuery("select u from UserTask u where userId = :userId and task.siteId = :siteId")
.setParameter("userId", userId)
.setParameter("siteId", siteId).list();
}

public List<UserTask> findByUserIdAndTask_StartsLessThanEqual(String userId, Instant instant) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@
<property name="sessionFactory" ref="org.sakaiproject.springframework.orm.hibernate.GlobalSessionFactory"/>
</bean>

<bean id="org.sakaiproject.tasks.api.repository.TaskAssignedRepository"
class="org.sakaiproject.tasks.impl.repository.TaskAssignedRepositoryImpl">
<property name="sessionFactory" ref="org.sakaiproject.springframework.orm.hibernate.GlobalSessionFactory"/>
</bean>

<bean id="org.sakaiproject.tasks.api.TaskService"
class="org.sakaiproject.tasks.impl.TaskServiceImpl" init-method="init">

Expand All @@ -29,6 +34,7 @@
<list>
<value>org.sakaiproject.tasks.api.Task</value>
<value>org.sakaiproject.tasks.api.UserTask</value>
<value>org.sakaiproject.tasks.api.TaskAssigned</value>
</list>
</property>
</bean>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,14 @@
import org.sakaiproject.event.api.EventTrackingService;
import org.sakaiproject.site.api.SiteService;
import org.sakaiproject.tasks.api.Task;
import org.sakaiproject.tasks.api.TaskAssigned;
import org.sakaiproject.tasks.api.TaskService;
import org.sakaiproject.tasks.api.UserTask;
import org.sakaiproject.tasks.api.repository.TaskAssignedRepository;
import org.sakaiproject.tasks.api.repository.TaskRepository;
import org.sakaiproject.tasks.api.repository.UserTaskRepository;
import org.sakaiproject.tasks.impl.TaskServiceImpl;
import org.sakaiproject.tasks.impl.repository.TaskAssignedRepositoryImpl;
import org.sakaiproject.tasks.impl.repository.TaskRepositoryImpl;
import org.sakaiproject.tasks.impl.repository.UserTaskRepositoryImpl;
import org.sakaiproject.tool.api.SessionManager;
Expand Down Expand Up @@ -63,7 +66,7 @@ public class TaskServiceTestConfiguration {
@Bean(name = "org.sakaiproject.springframework.orm.hibernate.impl.AdditionalHibernateMappings.taskservice")
public AdditionalHibernateMappings hibernateMappings() {

Class[] annotatedClasses = new Class[] {Task.class, UserTask.class};
Class[] annotatedClasses = new Class[] {Task.class, UserTask.class, TaskAssigned.class};
AdditionalHibernateMappings mappings = new AdditionalHibernateMappingsImpl();
mappings.setAnnotatedClasses(annotatedClasses);
return mappings;
Expand Down Expand Up @@ -160,6 +163,12 @@ public UserTaskRepository userTaskRepository(SessionFactory sessionFactory) {
utr.setSessionFactory(sessionFactory);
return utr;
}


@Bean
public TaskAssignedRepository taskAssignedRepository(SessionFactory sessionFactory) {
TaskAssignedRepositoryImpl tar = new TaskAssignedRepositoryImpl();
tar.setSessionFactory(sessionFactory);
return tar;
}

}
Loading

0 comments on commit e3d2644

Please sign in to comment.