Skip to content

Add ability to dynamically search for comments #3028

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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 @@ -19,6 +19,7 @@
import java.util.Map;
import java.util.Set;

import org.flowable.engine.task.CommentQuery;
import org.flowable.task.api.TaskCompletionBuilder;
import org.flowable.common.engine.api.FlowableException;
import org.flowable.common.engine.api.FlowableObjectNotFoundException;
Expand Down Expand Up @@ -816,6 +817,11 @@ void completeTaskWithForm(String taskId, String formDefinitionId, String outcome
/** The comments related to the given process instance. */
List<Comment> getProcessInstanceComments(String processInstanceId, String type);

/**
* Returns a new {@link CommentQuery} that can be used to dynamically query comments.
*/
CommentQuery createCommentQuery();

/**
* Add a new attachment to a task and/or a process instance and use an input stream to provide the content
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
/* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.flowable.engine.impl;

import java.io.Serializable;
import java.util.Collection;
import java.util.Date;
import java.util.List;

import org.flowable.common.engine.api.FlowableIllegalArgumentException;
import org.flowable.common.engine.impl.interceptor.CommandContext;
import org.flowable.common.engine.impl.interceptor.CommandExecutor;
import org.flowable.common.engine.impl.query.AbstractQuery;
import org.flowable.engine.impl.cfg.ProcessEngineConfigurationImpl;
import org.flowable.engine.task.Comment;
import org.flowable.engine.task.CommentQuery;

/**
* @author David Lamas
*/
public class CommentQueryImpl extends AbstractQuery<CommentQuery, Comment> implements CommentQuery, Serializable {
private ProcessEngineConfigurationImpl processEngineConfiguration;

private String commentId;
private String taskId;
private String processInstanceId;
private String type;
private String createdBy;
private Collection<String> createdByOneOf;
private Date createdBefore;
private Date createdAfter;
private Date createdOn;

public CommentQueryImpl() {
}

public CommentQueryImpl(CommandExecutor commandExecutor, ProcessEngineConfigurationImpl processEngineConfiguration) {
super(commandExecutor);
this.processEngineConfiguration = processEngineConfiguration;
}

public CommentQueryImpl(CommandContext commandContext, ProcessEngineConfigurationImpl processEngineConfiguration) {
super(commandContext);
this.processEngineConfiguration = processEngineConfiguration;
}

@Override
public CommentQuery commentId(String commentId) {
this.commentId = commentId;
return this;
}

@Override
public CommentQuery taskId(String taskId) {
this.taskId = taskId;
return this;
}

@Override
public CommentQuery processInstanceId(String processInstanceId) {
this.processInstanceId = processInstanceId;
return this;
}

@Override
public CommentQuery type(String type) {
this.type = type;
return this;
}

@Override
public CommentQuery createdBy(String userId) {
if (userId != null) {
if (createdByOneOf != null) {
throw new FlowableIllegalArgumentException("Invalid query usage: cannot set both createdBy and createdByOneOf");
}
}
this.createdBy = userId;
return this;
}

@Override
public CommentQuery createdByOneOf(Collection<String> userIds) {
if (userIds != null) {
if (userIds.isEmpty()) {
throw new FlowableIllegalArgumentException("User id list cannot be empty");
}

if (createdBy != null) {
throw new FlowableIllegalArgumentException("Invalid query usage: cannot set both createdBy and createdByOneOf");
}
}

this.createdByOneOf = userIds;
return this;
}

@Override
public CommentQuery createdBefore(Date beforeTime) {
this.createdBefore = beforeTime;
return this;
}

@Override
public CommentQuery createdAfter(Date afterTime) {
this.createdAfter = afterTime;
return this;
}

@Override
public CommentQuery createdOn(Date createTime) {
this.createdOn = createTime;
return this;
}

@Override
public CommentQuery orderByCreateTime() {
return orderBy(CommentQueryProperty.TIME);
}

@Override
public CommentQuery orderByUser() {
return orderBy(CommentQueryProperty.USER_ID);
}

@Override
public CommentQuery orderByType() {
return orderBy(CommentQueryProperty.TYPE);
}

@Override
public CommentQuery orderByTaskId() {
return orderBy(CommentQueryProperty.TASK_ID);
}

@Override
public CommentQuery orderByProcessInstanceId() {
return orderBy(CommentQueryProperty.PROCESS_INSTANCE_ID);
}

@Override
public long executeCount(CommandContext commandContext) {
return processEngineConfiguration.getCommentEntityManager().findCommentCountByQueryCriteria(this);
}

@Override
public List<Comment> executeList(CommandContext commandContext) {
return processEngineConfiguration.getCommentEntityManager().findCommentsByQueryCriteria(this);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.flowable.engine.impl;

import java.util.HashMap;
import java.util.Map;

import org.flowable.common.engine.api.query.QueryProperty;

/**
* Contains the possible properties which can be used in a {@link org.flowable.engine.task.CommentQuery}.
*
* @author David Lamas
*/
public class CommentQueryProperty implements QueryProperty {
private static final long serialVersionUID = 1L;

private static final Map<String, CommentQueryProperty> properties = new HashMap<>();

public static final CommentQueryProperty ID = new CommentQueryProperty("RES.ID_");
public static final CommentQueryProperty TIME = new CommentQueryProperty("RES.TIME_");
public static final CommentQueryProperty USER_ID = new CommentQueryProperty("RES.USER_ID_");
public static final CommentQueryProperty TYPE = new CommentQueryProperty("RES.TYPE_");
public static final CommentQueryProperty TASK_ID = new CommentQueryProperty("RES.TASK_ID_");
public static final CommentQueryProperty PROCESS_INSTANCE_ID = new CommentQueryProperty("RES.PROC_INST_ID_");

private String name;

public CommentQueryProperty(String name) {
this.name = name;
properties.put(name, this);
}

@Override
public String getName() {
return name;
}

public static CommentQueryProperty findByName(String propertyName) {
return properties.get(propertyName);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
import org.flowable.engine.runtime.DataObject;
import org.flowable.engine.task.Attachment;
import org.flowable.engine.task.Comment;
import org.flowable.engine.task.CommentQuery;
import org.flowable.engine.task.Event;
import org.flowable.form.api.FormInfo;
import org.flowable.identitylink.api.IdentityLink;
Expand Down Expand Up @@ -460,6 +461,11 @@ public List<Comment> getProcessInstanceComments(String processInstanceId, String
return commandExecutor.execute(new GetProcessInstanceCommentsCmd(processInstanceId, type));
}

@Override
public CommentQuery createCommentQuery() {
return new CommentQueryImpl(getCommandExecutor(), getConfiguration());
}

@Override
public Attachment createAttachment(String attachmentType, String taskId, String processInstanceId, String attachmentName, String attachmentDescription, InputStream content) {
return commandExecutor.execute(new CreateAttachmentCmd(attachmentType, taskId, processInstanceId, attachmentName, attachmentDescription, content, null));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import java.util.List;

import org.flowable.common.engine.impl.persistence.entity.EntityManager;
import org.flowable.engine.impl.CommentQueryImpl;
import org.flowable.engine.task.Comment;
import org.flowable.engine.task.Event;

Expand Down Expand Up @@ -45,4 +46,8 @@ public interface CommentEntityManager extends EntityManager<CommentEntity> {

Event findEvent(String commentId);

List<Comment> findCommentsByQueryCriteria(CommentQueryImpl query);

long findCommentCountByQueryCriteria(CommentQueryImpl query);

}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import org.flowable.common.engine.api.delegate.event.FlowableEngineEventType;
import org.flowable.engine.delegate.event.impl.FlowableEventBuilder;
import org.flowable.engine.impl.cfg.ProcessEngineConfigurationImpl;
import org.flowable.engine.impl.CommentQueryImpl;
import org.flowable.engine.impl.history.HistoryManager;
import org.flowable.engine.impl.persistence.entity.data.CommentDataManager;
import org.flowable.engine.task.Comment;
Expand Down Expand Up @@ -176,6 +177,16 @@ public void delete(CommentEntity commentEntity) {
}
}

@Override
public List<Comment> findCommentsByQueryCriteria(CommentQueryImpl query) {
return dataManager.findCommentsByQueryCriteria(query);
}

@Override
public long findCommentCountByQueryCriteria(CommentQueryImpl query) {
return dataManager.findCommentCountByQueryCriteria(query);
}

protected void checkHistoryEnabled() {
if (!getHistoryManager().isHistoryEnabled()) {
throw new FlowableException("In order to use comments, history should be enabled");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import java.util.List;

import org.flowable.common.engine.impl.persistence.entity.data.DataManager;
import org.flowable.engine.impl.CommentQueryImpl;
import org.flowable.engine.impl.persistence.entity.CommentEntity;
import org.flowable.engine.task.Comment;
import org.flowable.engine.task.Event;
Expand Down Expand Up @@ -46,4 +47,8 @@ public interface CommentDataManager extends DataManager<CommentEntity> {

Event findEvent(String commentId);

List<Comment> findCommentsByQueryCriteria(CommentQueryImpl commentQuery);

long findCommentCountByQueryCriteria(CommentQueryImpl commentQuery);

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import java.util.Map;

import org.flowable.engine.impl.cfg.ProcessEngineConfigurationImpl;
import org.flowable.engine.impl.CommentQueryImpl;
import org.flowable.engine.impl.persistence.entity.CommentEntity;
import org.flowable.engine.impl.persistence.entity.CommentEntityImpl;
import org.flowable.engine.impl.persistence.entity.data.AbstractProcessDataManager;
Expand Down Expand Up @@ -111,4 +112,14 @@ public Event findEvent(String commentId) {
return findById(commentId);
}

@Override
public List<Comment> findCommentsByQueryCriteria(CommentQueryImpl commentQuery) {
final String query = "selectCommentByQueryCriteria";
return getDbSqlSession().selectList(query, commentQuery);
}

@Override
public long findCommentCountByQueryCriteria(CommentQueryImpl commentQuery) {
return (Long) getDbSqlSession().selectOne("selectCommentCountByQueryCriteria", commentQuery);
}
}
Loading