-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Task api enhancement to include attachment and comments fields. #4306
base: master
Are you sure you want to change the base?
Changes from all commits
d744faa
e9bd295
7f9ba41
998f8a2
5fd4d3c
d3b33d7
76a428d
3ea772d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
yanavasileva marked this conversation as resolved.
Show resolved
Hide resolved
|
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -18,6 +18,7 @@ | |||
|
||||
import java.util.Date; | ||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty; | ||||
import org.camunda.bpm.engine.BadUserRequestException; | ||||
import org.camunda.bpm.engine.form.CamundaFormRef; | ||||
import org.camunda.bpm.engine.rest.dto.converter.DelegationStateConverter; | ||||
|
@@ -49,7 +50,9 @@ public class TaskDto { | |||
private String formKey; | ||||
private CamundaFormRef camundaFormRef; | ||||
private String tenantId; | ||||
|
||||
@JsonProperty("attachment") | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ❌ For consistency, let's remove the annotation:
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was reluctant to add this, I am facing an weird issue where hasAttachment is translated to attachments instead of attachment in the json response, hence decided to add. Let me know your thoughts. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I saw this. I will try to see from where it's coming. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can also try to debug it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I figured it , jackson considers the setter method to decide the boolean var name. |
||||
private boolean hasAttachment; | ||||
private boolean hasComment; | ||||
public String getId() { | ||||
return id; | ||||
} | ||||
|
@@ -194,6 +197,20 @@ public void setTenantId(String tenantId) { | |||
this.tenantId = tenantId; | ||||
} | ||||
|
||||
public boolean getAttachments() { | ||||
return hasAttachment; | ||||
} | ||||
public void setAttachments(boolean hasAttachment) { | ||||
this.hasAttachment = hasAttachment; | ||||
} | ||||
|
||||
public boolean getComment() { | ||||
return hasComment; | ||||
} | ||||
|
||||
public void setComments(boolean hasComment) { | ||||
this.hasComment = hasComment; | ||||
} | ||||
public static TaskDto fromEntity(Task task) { | ||||
TaskDto dto = new TaskDto(); | ||||
dto.id = task.getId(); | ||||
|
@@ -221,6 +238,8 @@ public static TaskDto fromEntity(Task task) { | |||
dto.caseInstanceId = task.getCaseInstanceId(); | ||||
dto.suspended = task.isSuspended(); | ||||
dto.tenantId = task.getTenantId(); | ||||
dto.hasAttachment = task.hasAttachment(); | ||||
dto.hasComment = task.hasComment(); | ||||
|
||||
try { | ||||
dto.formKey = task.getFormKey(); | ||||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -44,6 +44,7 @@ | |||||
import org.camunda.bpm.engine.task.Task; | ||||||
import org.camunda.bpm.engine.task.TaskQuery; | ||||||
import org.camunda.bpm.engine.variable.type.ValueType; | ||||||
import org.camunda.bpm.engine.impl.history.HistoryLevel; | ||||||
|
||||||
/** | ||||||
* @author Joram Barrez | ||||||
|
@@ -175,6 +176,7 @@ public class TaskQueryImpl extends AbstractQuery<TaskQuery, Task> implements Tas | |||||
// or query ///////////////////////////// | ||||||
protected List<TaskQueryImpl> queries = new ArrayList<>(Arrays.asList(this)); | ||||||
protected boolean isOrQueryActive = false; | ||||||
protected boolean withCommentAttachmentInfo = false; | ||||||
|
||||||
public TaskQueryImpl() { | ||||||
} | ||||||
|
@@ -1088,6 +1090,12 @@ protected boolean hasExcludingConditions() { | |||||
|| CompareUtil.elementIsNotContainedInArray(processInstanceBusinessKey, processInstanceBusinessKeys); | ||||||
} | ||||||
|
||||||
@Override | ||||||
public TaskQuery withCommentAttachmentInfo() { | ||||||
this.withCommentAttachmentInfo = true; | ||||||
return this; | ||||||
} | ||||||
|
||||||
public List<String> getCandidateGroups() { | ||||||
if (cachedCandidateGroups != null) { | ||||||
return cachedCandidateGroups; | ||||||
|
@@ -1441,6 +1449,13 @@ public List<Task> executeList(CommandContext commandContext, Page page) { | |||||
} | ||||||
} | ||||||
|
||||||
if (withCommentAttachmentInfo && Context.getProcessEngineConfiguration().getHistoryLevel()!= HistoryLevel.HISTORY_LEVEL_NONE) { | ||||||
yanavasileva marked this conversation as resolved.
Show resolved
Hide resolved
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ❌ Use equals to compare:
Suggested change
|
||||||
for (Task task : taskList) { | ||||||
// verify attachment and comments exists for the task | ||||||
((TaskEntity) task).initializeAttachmentAndComments(); | ||||||
} | ||||||
} | ||||||
|
||||||
return taskList; | ||||||
} | ||||||
|
||||||
|
Original file line number | Diff line number | Diff line change | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -158,6 +158,8 @@ public class TaskEntity extends AbstractVariableScope implements Task, DelegateT | |||||||||||
protected boolean isFormKeyInitialized = false; | ||||||||||||
protected String formKey; | ||||||||||||
protected CamundaFormRef camundaFormRef; | ||||||||||||
protected boolean attachmentExists; | ||||||||||||
protected boolean commentExists; | ||||||||||||
|
||||||||||||
@SuppressWarnings({ "unchecked" }) | ||||||||||||
protected transient VariableStore<VariableInstanceEntity> variableStore | ||||||||||||
|
@@ -1451,6 +1453,10 @@ public void initializeFormKey() { | |||||||||||
} | ||||||||||||
} | ||||||||||||
} | ||||||||||||
public void initializeAttachmentAndComments(){ | ||||||||||||
this.attachmentExists = !getProcessEngine().getTaskService().getTaskAttachments(id).isEmpty(); | ||||||||||||
this.commentExists = !getProcessEngine().getTaskService().getTaskComments(id).isEmpty(); | ||||||||||||
Comment on lines
+1457
to
+1458
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ❌ Please re-use the command context instead of executing command (get attachment/comments) in the command (task query):
Suggested change
|
||||||||||||
} | ||||||||||||
yanavasileva marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||
|
||||||||||||
@Override | ||||||||||||
public String getFormKey() { | ||||||||||||
|
@@ -1758,7 +1764,14 @@ public void bpmnError(String errorCode, String errorMessage, Map<String, Object> | |||||||||||
throw ProcessEngineLogger.CMD_LOGGER.exceptionBpmnErrorPropagationFailed(errorCode, ex); | ||||||||||||
} | ||||||||||||
} | ||||||||||||
|
||||||||||||
@Override | ||||||||||||
public boolean hasAttachment() { | ||||||||||||
return attachmentExists; | ||||||||||||
} | ||||||||||||
@Override | ||||||||||||
public boolean hasComment() { | ||||||||||||
return commentExists; | ||||||||||||
} | ||||||||||||
public void escalation(String escalationCode, Map<String, Object> variables) { | ||||||||||||
ensureTaskActive(); | ||||||||||||
ActivityExecution activityExecution = getExecution(); | ||||||||||||
|
yanavasileva marked this conversation as resolved.
Show resolved
Hide resolved
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1104,4 +1104,9 @@ public interface TaskQuery extends Query<TaskQuery, Task> { | |
* this exception, {@link #or()} must be invoked first. | ||
*/ | ||
TaskQuery endOr(); | ||
|
||
/** | ||
* Evaluates existence of attachment and comments associated with the task, defaults to false. | ||
*/ | ||
Comment on lines
+1108
to
+1110
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ❌ Please add performance considerations to the javadoc. Adding the filter will do additional attachment and comments queries to the database, that might slow down the query in case of big size of the tables. |
||
TaskQuery withCommentAttachmentInfo(); | ||
yanavasileva marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
❌ Please add performance considerations to the description. Adding the filter will do additional attachment and comments queries to the database, that might slow down the query in case of big size of the tables.