-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Feature/git issue #4487 fetch task variables feature #4754
base: master
Are you sure you want to change the base?
Changes from 1 commit
ce9e0f6
c210094
97f1254
efcbc73
a686db9
149e3aa
cd15246
4c12656
11de7ad
5625e6f
d75434f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,7 @@ | |
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.stream.Collectors; | ||
import javax.ws.rs.core.MediaType; | ||
import javax.ws.rs.core.Request; | ||
|
@@ -34,6 +35,8 @@ | |
import org.camunda.bpm.engine.rest.dto.task.TaskDto; | ||
import org.camunda.bpm.engine.rest.dto.task.TaskQueryDto; | ||
import org.camunda.bpm.engine.rest.dto.task.TaskWithAttachmentAndCommentDto; | ||
import org.camunda.bpm.engine.rest.dto.task.TaskWithVariablesDto; | ||
import org.camunda.bpm.engine.rest.dto.VariableValueDto; | ||
import org.camunda.bpm.engine.rest.exception.InvalidRequestException; | ||
import org.camunda.bpm.engine.rest.hal.Hal; | ||
import org.camunda.bpm.engine.rest.hal.task.HalTaskList; | ||
|
@@ -44,6 +47,7 @@ | |
import org.camunda.bpm.engine.rest.util.QueryUtil; | ||
import org.camunda.bpm.engine.task.Task; | ||
import org.camunda.bpm.engine.task.TaskQuery; | ||
import org.camunda.bpm.engine.variable.VariableMap; | ||
|
||
public class TaskRestServiceImpl extends AbstractRestProcessEngineAware implements TaskRestService { | ||
|
||
|
@@ -96,8 +100,19 @@ public List<TaskDto> queryTasks(TaskQueryDto queryDto, Integer firstResult, | |
TaskQuery query = queryDto.toQuery(engine); | ||
|
||
List<Task> matchingTasks = executeTaskQuery(firstResult, maxResults, query); | ||
|
||
List<TaskDto> tasks = new ArrayList<TaskDto>(); | ||
|
||
if ((Boolean.TRUE.equals(queryDto.getWithTaskVariablesInReturn()) || Boolean.TRUE.equals( | ||
queryDto.getWithTaskLocalVariablesInReturn())) && Boolean.TRUE.equals( | ||
queryDto.getWithCommentAttachmentInfo())) { | ||
return getVariablesForTasks(engine, matchingTasks, Boolean.TRUE.equals(queryDto.getWithTaskVariablesInReturn()), | ||
true); | ||
} | ||
if (Boolean.TRUE.equals(queryDto.getWithTaskVariablesInReturn()) || Boolean.TRUE.equals( | ||
queryDto.getWithTaskLocalVariablesInReturn())) { | ||
return getVariablesForTasks(engine, matchingTasks, Boolean.TRUE.equals(queryDto.getWithTaskVariablesInReturn()), | ||
false); | ||
} | ||
if (Boolean.TRUE.equals(queryDto.getWithCommentAttachmentInfo())) { | ||
tasks = matchingTasks.stream().map(TaskWithAttachmentAndCommentDto::fromEntity).collect(Collectors.toList()); | ||
} | ||
|
@@ -163,4 +178,27 @@ public void createTask(TaskDto taskDto) { | |
public TaskReportResource getTaskReportResource() { | ||
return new TaskReportResourceImpl(getProcessEngine()); | ||
} | ||
|
||
private List<TaskDto> getVariablesForTasks(ProcessEngine engine, | ||
List<Task> matchingTasks, | ||
boolean withTaskVariablesInReturn, | ||
boolean withCommentAndAttachments) { | ||
TaskService taskService = engine.getTaskService(); | ||
List<TaskDto> tasks = new ArrayList<TaskDto>(); | ||
for (Task task : matchingTasks) { | ||
VariableMap taskVariables; | ||
if (withTaskVariablesInReturn) { | ||
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. This loop can introduce 2 extra DB query per task instance. One to get Variables and one for the Comments. 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. Hi @venetrius , Here one call is being made for each task in the loop - either taskVars or taskLocalVars. The comments and attachment info is already obtained and just used to populate the DTO accordingly. Please 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. @venetrius , I understand that there is a DB call made to get the comment and attachment info additional to getAllTask, while getting the list of tasks (matchingTasks). I understand in the above loop, one additional call is being made to get either taskVariables or taskLocalVariables to be added to the response. OpenAPI documentation is updated with exercising caution while using the comment/attachment request. Do you think its apt to add another cautionary note in the documentation for the variablesInReturn query as well? Please provide your thoughts and direction on how to proceed further. |
||
taskVariables = taskService.getVariablesTyped(task.getId(), true); | ||
} else { | ||
taskVariables = taskService.getVariablesLocalTyped(task.getId(), true); | ||
} | ||
Map<String, VariableValueDto> taskVariablesDto = VariableValueDto.fromMap(taskVariables); | ||
if (withCommentAndAttachments) { | ||
tasks.add(TaskWithAttachmentAndCommentDto.fromEntity(task, taskVariablesDto)); | ||
} else { | ||
tasks.add(TaskWithVariablesDto.fromEntity(task, taskVariablesDto)); | ||
} | ||
} | ||
return tasks; | ||
} | ||
} |
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.
Line 104 - 115 seems unececcerly complicated. I think this would mean the same:
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.
@venetrius I agree with your comments. Ill push the updates shortly.
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.
I have pushed the changes. Can you please take a look?