Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,10 @@ public interface CommentHandler extends GenericDAO<Comment, Long> {

int countCommentsWithSubs(long taskId);

/**
* @param taskId Task Technical identifier
* @return null if no comments else last created comment on task
*/
Comment getLastComment(long taskId);

}
11 changes: 10 additions & 1 deletion services/src/main/java/org/exoplatform/task/dao/TaskHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -108,5 +108,14 @@ public interface TaskHandler extends GenericDAO<Task, Long> {
* @return a list of task IDs
*/
List<Long> getAllIds(int offset, int limit);
}

/**
* Find tasks switch last update date computed from Task Logs and Task
* Comments after applying the {@link TaskQuery} filtering
*
* @param query {@link TaskQuery}
* @return {@link List} of corresponding Tasks
*/
ListAccess<Task> findLastUpdatedTasks(TaskQuery query);

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/
package org.exoplatform.task.dao.jpa;

import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections4.CollectionUtils;

import org.exoplatform.commons.api.persistence.ExoTransactional;
import org.exoplatform.commons.utils.ListAccess;
Expand Down Expand Up @@ -70,6 +70,18 @@ public ListAccess<Comment> findComments(long taskId) {
return new JPAQueryListAccess<Comment>(Comment.class, count, query);
}

@Override
public Comment getLastComment(long taskId) {
TypedQuery<Comment> query = getEntityManager().createNamedQuery("Comment.findLastCommentOfTask", Comment.class);
query.setParameter("taskId", taskId);
List<Comment> result = query.getResultList();
if (CollectionUtils.isEmpty(result)) {
return null;
} else {
return result.get(0);
}
}

@Override
@ExoTransactional
public List<Comment> getSubComments(List<Comment> comments) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import jakarta.persistence.Tuple;
import jakarta.persistence.TypedQuery;
import jakarta.persistence.criteria.CriteriaBuilder;
import jakarta.persistence.criteria.CriteriaBuilder.Case;
import jakarta.persistence.criteria.CriteriaQuery;
import jakarta.persistence.criteria.Expression;
import jakarta.persistence.criteria.Join;
Expand All @@ -31,10 +32,12 @@
import jakarta.persistence.criteria.Predicate;
import jakarta.persistence.criteria.Root;
import jakarta.persistence.criteria.Selection;
import jakarta.persistence.criteria.Subquery;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
Expand All @@ -46,6 +49,9 @@
import org.exoplatform.task.dao.condition.AggregateCondition;
import org.exoplatform.task.dao.condition.Condition;
import org.exoplatform.task.dao.condition.SingleCondition;
import org.exoplatform.task.domain.ChangeLog;
import org.exoplatform.task.domain.Comment;
import org.exoplatform.task.domain.Task;

public abstract class CommonJPADAO<E, K extends Serializable> extends GenericDAOJPAImpl<E, K> {

Expand Down Expand Up @@ -116,17 +122,45 @@ public Class<?> loadClass(String name) throws ClassNotFoundException {
List<OrderBy> orderby = query.getOrderBy();
if(orderby != null && !orderby.isEmpty()) {
List<Order> orders = new ArrayList<>(orderby.size());
for(OrderBy orderBy : orderby) {
Expression<?> p = root.get(orderBy.getFieldName());
for (OrderBy orderBy : orderby) {
Order order;
if (orderBy.isAscending()) {
if (orderBy.getFieldName().equals("lastTaskActivity")) {
Subquery<Date> maxCommentSq = q.subquery(Date.class);
Root<Comment> c = maxCommentSq.from(Comment.class);

maxCommentSq.select(cb.greatest(c.<Date> get("createdTime")));
maxCommentSq.where(cb.equal(c.get("task"), root));

Subquery<Date> maxLogSq = q.subquery(Date.class);
Root<ChangeLog> l = maxLogSq.from(ChangeLog.class);

maxLogSq.select(cb.greatest(l.<Date> get("createdTime")));
maxLogSq.where(cb.equal(l.get("task"), root));

Expression<Date> taskCreated = root.get("createdTime");
Expression<Date> maxCommentTime = cb.coalesce(maxCommentSq.getSelection(), taskCreated);
Expression<Date> maxLogTime = cb.coalesce(maxLogSq.getSelection(), taskCreated);

Case<Date> tmpSelectCase = cb.selectCase();
Expression<Date> tmpMax = tmpSelectCase.when(cb.greaterThan(taskCreated, maxCommentTime), taskCreated)
.otherwise(maxCommentTime);

tmpSelectCase = cb.selectCase();
Expression<Date> lastActivity = tmpSelectCase.when(cb.greaterThan(tmpMax, maxLogTime), tmpMax)
.otherwise(maxLogTime);

selections.add(lastActivity);

order = orderBy.isAscending() ? cb.asc(lastActivity) : cb.desc(lastActivity);
} else if (orderBy.isAscending()) {
Expression<?> p = root.get(orderBy.getFieldName());
// NULL value should be at last when order by
Expression<?> nullCase = cb.selectCase().when(p.isNull(), 1).otherwise(0);
selections.add(nullCase);
orders.add(cb.asc(nullCase));

order = cb.asc(p);
} else {
Expression<?> p = root.get(orderBy.getFieldName());
order = cb.desc(p);
}
orders.add(order);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,12 @@ public ListAccess<Task> findTasks(TaskQuery query) {
return findEntities(query, Task.class);
}

@Override
public ListAccess<Task> findLastUpdatedTasks(TaskQuery query) {
query.setOrderBy(List.of(new OrderBy("lastTaskActivity", false)));
return findEntities(query, Task.class);
}

@Override
public <T> List<T> selectTaskField(TaskQuery query, String fieldName) {
EntityManager em = getEntityManager();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
*/
package org.exoplatform.task.domain;

import java.util.Calendar;
import java.util.Date;

import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
Expand All @@ -28,6 +31,8 @@
import jakarta.persistence.NamedQuery;
import jakarta.persistence.SequenceGenerator;
import jakarta.persistence.Table;
import jakarta.persistence.Temporal;
import jakarta.persistence.TemporalType;
import lombok.Data;

@Entity(name = "TaskChangeLog")
Expand Down Expand Up @@ -58,12 +63,13 @@ public class ChangeLog implements Comparable<ChangeLog> {

private String target;

@Column(name="CREATED_TIME")
private long createdTime = System.currentTimeMillis();
@Temporal(TemporalType.TIMESTAMP)
@Column(name = "CREATED_TIME")
private Date createdTime = Calendar.getInstance().getTime();

@Override
public int compareTo(ChangeLog o) {
return (int)(getCreatedTime() - o.getCreatedTime());
return getCreatedTime().compareTo(o.getCreatedTime());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
package org.exoplatform.task.domain;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.HashSet;
import java.util.List;
Expand Down Expand Up @@ -52,6 +53,8 @@
query = "SELECT count(c) FROM TaskComment c WHERE c.task.id = :taskId")
@NamedQuery(name = "Comment.findCommentsOfTask",
query = "SELECT c FROM TaskComment c WHERE c.task.id = :taskId AND c.parentComment IS NULL ORDER BY c.createdTime DESC")
@NamedQuery(name = "Comment.findLastCommentOfTask",
query = "SELECT c FROM TaskComment c WHERE c.task.id = :taskId ORDER BY c.createdTime DESC")
@NamedQuery(name = "Comment.findSubCommentsOfComments",
query = "SELECT c FROM TaskComment c WHERE c.parentComment IN (:comments) ORDER BY c.createdTime ASC")
@NamedQuery(name = "Comment.deleteCommentOfTask",
Expand All @@ -78,7 +81,7 @@ public class Comment {

@Temporal(TemporalType.TIMESTAMP)
@Column(name = "CREATED_TIME")
private Date createdTime;
private Date createdTime = Calendar.getInstance().getTime();

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "TASK_ID")
Expand Down
3 changes: 2 additions & 1 deletion services/src/main/java/org/exoplatform/task/domain/Task.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
package org.exoplatform.task.domain;

import java.io.Serializable;
import java.util.Calendar;
import java.util.Date;
import java.util.HashSet;
import java.util.List;
Expand Down Expand Up @@ -206,7 +207,7 @@ public class Task implements Serializable {

@Temporal(TemporalType.TIMESTAMP)
@Column(name = "CREATED_TIME")
private Date createdTime;
private Date createdTime = Calendar.getInstance().getTime();

@Temporal(TemporalType.TIMESTAMP)
@Column(name = "START_DATE")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ public ChangeLogEntry(ChangeLog changeLog,UserService userService) {

this.targetFullName = userService.loadUser(changeLog.getTarget()).getDisplayName();

this.createdTime = changeLog.getCreatedTime();
}
this.createdTime = changeLog.getCreatedTime() == null ? 0 : changeLog.getCreatedTime().getTime();
}

public long getId() {
return id;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,10 @@ public interface CommentService {
* @return {@link Integer}
*/
int countCommentsWithSubs(long taskId);

/**
* @param taskId Task identifier
* @return null if no comments else last created comment on task
*/
CommentDto getLastComment(long taskId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -192,4 +192,15 @@ public interface TaskService {
* @return a list of task IDs
*/
public List<TaskDto> findTasks(TaskSearchFilter taskFilter);

/**
* Find tasks switch last update date computed from Task Logs and Task
* Comments after applying the {@link TaskQuery} filtering
*
* @param query {@link TaskQuery}
* @param offset result offset
* @param limit result limit
* @return {@link List} of corresponding Tasks
*/
List<TaskDto> findLastUpdatedTasks(TaskQuery query, int offset, int limit);
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import org.exoplatform.task.exception.EntityNotFoundException;
import org.exoplatform.task.service.CommentService;
import org.exoplatform.task.storage.CommentStorage;
import org.exoplatform.task.util.StorageUtil;

public class CommentServiceImpl implements CommentService {
private static final Log LOG = ExoLogger.getExoLogger(CommentServiceImpl.class);
Expand Down Expand Up @@ -71,6 +72,11 @@ public int countComments(long taskId) {
return commentStorage.countComments(taskId);
}

@Override
public CommentDto getLastComment(long taskId) {
return commentStorage.getLastComment(taskId);
}

@Override
public List<CommentDto> loadSubComments(List<CommentDto> listComments) {
if (listComments == null || listComments.isEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,11 @@ public List<TaskDto> findTasks(TaskQuery query, int offset, int limit) throws Ex
return taskStorage.findTasks(query, offset, limit);
}

@Override
public List<TaskDto> findLastUpdatedTasks(TaskQuery query, int offset, int limit) {
return taskStorage.findLastUpdatedTasks(query, offset, limit);
}

@Override
public int countTasks(TaskQuery query) throws Exception {
return taskStorage.countTasks(query);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,10 @@ public interface CommentStorage {
*/
int countCommentsWithSubs(long taskId);

/**
* @param taskId Task identifier
* @return null if no comments else last created comment on task
*/
CommentDto getLastComment(long taskId);

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,9 @@
*/
package org.exoplatform.task.storage;

import org.exoplatform.commons.utils.ListAccess;
import org.exoplatform.task.dao.OrderBy;
import org.exoplatform.task.dao.TaskQuery;
import org.exoplatform.task.domain.ChangeLog;
import org.exoplatform.task.domain.Status;
import org.exoplatform.task.domain.Task;
import org.exoplatform.task.dto.ChangeLogEntry;
import org.exoplatform.task.dto.LabelDto;
import org.exoplatform.task.dto.TaskDto;
Expand Down Expand Up @@ -175,4 +172,15 @@ List<TaskDto> findTasksByLabel(LabelDto label,
* @return {@link List} of {@link TaskDto}
*/
List<TaskDto> findTasks(TaskSearchFilter filter);

/**
* Find tasks switch last update date computed from Task Logs and Task
* Comments after applying the {@link TaskQuery} filtering
*
* @param query {@link TaskQuery}
* @param offset result offset
* @param limit result limit
* @return {@link List} of corresponding Tasks
*/
List<TaskDto> findLastUpdatedTasks(TaskQuery query, int offset, int limit);
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@ public CommentDto getComment(long commentId) {
return StorageUtil.commentToDto(daoHandler.getCommentHandler().find(commentId),projectStorage);
}

@Override
public CommentDto getLastComment(long taskId) {
return StorageUtil.commentToDto(daoHandler.getCommentHandler().getLastComment(taskId), projectStorage);
}

@Override
public List<CommentDto> getCommentsWithSubs(long taskId, int offset, int limit) {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,19 @@ public List<TaskDto> findByUser(String user) {

@Override
public List<TaskDto> findTasks(TaskQuery query, int offset, int limit) throws Exception {
List<Task> taskEntities = Arrays.asList(daoHandler.getTaskHandler().findTasks(query).load(offset, limit));
return taskEntities.stream().map((Task taskEntity) -> StorageUtil.taskToDto(taskEntity,projectStorage)).collect(Collectors.toList());
List<Task> taskEntities = Arrays.asList(daoHandler.getTaskHandler().findTasks(query).load(offset, limit));
return taskEntities.stream()
.map((Task taskEntity) -> StorageUtil.taskToDto(taskEntity, projectStorage))
.collect(Collectors.toList());
}

@Override
@SneakyThrows
public List<TaskDto> findLastUpdatedTasks(TaskQuery query, int offset, int limit) {
List<Task> taskEntities = Arrays.asList(daoHandler.getTaskHandler().findLastUpdatedTasks(query).load(offset, limit));
return taskEntities.stream()
.map((Task taskEntity) -> StorageUtil.taskToDto(taskEntity, projectStorage))
.toList();
}

public int countTasks(TaskQuery query) throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import org.exoplatform.task.storage.ProjectStorage;

import java.util.Arrays;
import java.util.Date;
import java.util.HashSet;
import java.util.List;
import java.util.Objects;
Expand All @@ -52,7 +53,7 @@ public static ChangeLog changeLogToEntity(ChangeLogEntry changeLogEntry, UserSer
changeLog.setTask(changeLogEntry.getTask());
changeLog.setAuthor(changeLogEntry.getAuthor());
changeLog.setActionName(changeLogEntry.getActionName());
changeLog.setCreatedTime(changeLogEntry.getCreatedTime());
changeLog.setCreatedTime(new Date(changeLogEntry.getCreatedTime()));
changeLog.setTarget(changeLogEntry.getTarget());
return changeLog;
}
Expand All @@ -63,7 +64,7 @@ public static ChangeLogEntry changeLogToDto(ChangeLog changeLog, UserService use
changeLogEntry.setTask(changeLog.getTask());
changeLogEntry.setAuthor(changeLog.getAuthor());
changeLogEntry.setActionName(changeLog.getActionName());
changeLogEntry.setCreatedTime(changeLog.getCreatedTime());
changeLogEntry.setCreatedTime(changeLog.getCreatedTime() == null ? 0 : changeLog.getCreatedTime().getTime());
changeLogEntry.setTarget(changeLog.getTarget());
changeLogEntry.setAuthorFullName(userService.loadUser(changeLog.getAuthor()).getDisplayName());
changeLogEntry.setAuthorAvatarUrl(userService.loadUser(changeLog.getAuthor()).getAvatar());
Expand Down
Loading