Skip to content

Commit

Permalink
chore(engine): adjust return type of complete task
Browse files Browse the repository at this point in the history
and submit form with variables in return

Related to CAM-9398
  • Loading branch information
yanavasileva committed Mar 21, 2019
1 parent a529d00 commit b9af348
Show file tree
Hide file tree
Showing 10 changed files with 45 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -98,14 +98,15 @@ public Response complete(CompleteTaskDto dto) {
try {
VariableMap variables = VariableValueDto.toMap(dto.getVariables(), engine, objectMapper);
if (dto.isWithVariablesInReturn()) {
Map<String, Object> taskVariables = taskService.completeWithVariablesInReturn(taskId, variables);
VariableMap taskVariables = taskService.completeWithVariablesInReturn(taskId, variables);
return Response
.ok(taskVariables)
.type(MediaType.APPLICATION_JSON)
.build();
} else {
taskService.complete(taskId, variables);
return Response.noContent().build();
}
taskService.complete(taskId, variables);
return Response.noContent().build();

} catch (RestException e) {
String errorMessage = String.format("Cannot complete task %s: %s", taskId, e.getMessage());
Expand All @@ -130,14 +131,15 @@ public Response submit(CompleteTaskDto dto) {
try {
VariableMap variables = VariableValueDto.toMap(dto.getVariables(), engine, objectMapper);
if (dto.isWithVariablesInReturn()) {
Map<String, Object> taskVariables = formService.submitTaskFormWithVariablesInReturn(taskId, variables);
VariableMap taskVariables = formService.submitTaskFormWithVariablesInReturn(taskId, variables);
return Response
.ok(taskVariables)
.type(MediaType.APPLICATION_JSON)
.build();
} else {
formService.submitTaskForm(taskId, variables);
return Response.noContent().build();
}
formService.submitTaskForm(taskId, variables);
return Response.noContent().build();

} catch (RestException e) {
String errorMessage = String.format("Cannot submit task form %s: %s", taskId, e.getMessage());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@
import org.camunda.bpm.engine.task.Task;
import org.camunda.bpm.engine.task.TaskQuery;
import org.camunda.bpm.engine.variable.VariableMap;
import org.camunda.bpm.engine.variable.Variables;
import org.camunda.bpm.engine.variable.value.FileValue;
import org.fest.assertions.Assertions;
import org.junit.Assert;
Expand Down Expand Up @@ -693,14 +694,27 @@ public void testSubmitForm() {

@Test
public void testSubmitFormWithVariablesInReturn() {
String mockVar = "mockVar";
String mockVarVal = "mockVarVal";
VariableMap mockMap = Variables.putValue(mockVar, mockVarVal);
when(formServiceMock.submitTaskFormWithVariablesInReturn(EXAMPLE_TASK_ID, null)).thenReturn(mockMap);

Map<String, Object> queryParameters = new HashMap<String, Object>();
queryParameters.put("withVariablesInReturn", true);

given().pathParam("id", EXAMPLE_TASK_ID).contentType(POST_JSON_CONTENT_TYPE).body(queryParameters).header("accept", MediaType.APPLICATION_JSON).expect()
.statusCode(Status.OK.getStatusCode()).when().post(SUBMIT_FORM_URL);
given()
.pathParam("id", EXAMPLE_TASK_ID)
.contentType(POST_JSON_CONTENT_TYPE)
.body(queryParameters)
.header("accept", MediaType.APPLICATION_JSON)
.expect()
.statusCode(Status.OK.getStatusCode())
.body(mockVar, equalTo(mockVarVal))
.when().post(SUBMIT_FORM_URL);

verify(formServiceMock).submitTaskFormWithVariablesInReturn(EXAMPLE_TASK_ID, null);
}

@Test
public void testSubmitFormWithParameters() {
Map<String, Object> variables = VariablesBuilder.create()
Expand Down Expand Up @@ -1542,13 +1556,12 @@ public void testCompleteWithParameters() {

verify(taskServiceMock).complete(eq(EXAMPLE_TASK_ID), argThat(new EqualsMap(expectedVariables)));
}

@Test
public void testCompleteTaskWithVariablesInReturn() {
String mockVar = "mockVar";
String mockVarVal = "mockVarVal";
Map<String, Object> mockMap = new HashMap<String, Object>();
mockMap.put(mockVar, mockVarVal);
VariableMap mockMap = Variables.putValue(mockVar, mockVarVal);
when(taskServiceMock.completeWithVariablesInReturn(EXAMPLE_TASK_ID, null)).thenReturn(mockMap);

Map<String, Object> json = new HashMap<String, Object>();
Expand All @@ -1565,7 +1578,7 @@ public void testCompleteTaskWithVariablesInReturn() {
.when()
.post(COMPLETE_TASK_URL);

verify(taskServiceMock).completeWithVariablesInReturn(EXAMPLE_TASK_ID, null);
verify(taskServiceMock).completeWithVariablesInReturn(EXAMPLE_TASK_ID, null);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ public interface FormService {
* If the user has no {@link Permissions#UPDATE} permission on {@link Resources#TASK}
* or no {@link Permissions#UPDATE_TASK} permission on {@link Resources#PROCESS_DEFINITION}.
*/
Map<String, Object> submitTaskFormWithVariablesInReturn(String taskId, Map<String, Object> properties);
VariableMap submitTaskFormWithVariablesInReturn(String taskId, Map<String, Object> properties);

/**
* Retrieves a list of all variables for rendering a start from. The method takes into account
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ public interface TaskService {
* or no {@link Permissions#UPDATE_TASK} permission on {@link Resources#PROCESS_DEFINITION}
* (if the task is part of a running process instance).
*/
Map<String, Object> completeWithVariablesInReturn(String taskId, Map<String, Object> variables);
VariableMap completeWithVariablesInReturn(String taskId, Map<String, Object> variables);

/**
* Changes the assignee of the given task to the given userId.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public void submitTaskForm(String taskId, Map<String, Object> properties) {
commandExecutor.execute(new SubmitTaskFormCmd(taskId, properties));
}

public Map<String, Object> submitTaskFormWithVariablesInReturn(String taskId, Map<String, Object> properties) {
public VariableMap submitTaskFormWithVariablesInReturn(String taskId, Map<String, Object> properties) {
return commandExecutor.execute(new SubmitTaskFormCmd(taskId, properties));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ public void complete(String taskId, Map<String, Object> variables) {
commandExecutor.execute(new CompleteTaskCmd(taskId, variables));
}

public Map<String, Object> completeWithVariablesInReturn(String taskId, Map<String, Object> variables) {
public VariableMap completeWithVariablesInReturn(String taskId, Map<String, Object> variables) {
return commandExecutor.execute(new CompleteTaskCmd(taskId, variables));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,12 @@
import org.camunda.bpm.engine.impl.persistence.entity.ExecutionVariableSnapshotObserver;
import org.camunda.bpm.engine.impl.persistence.entity.TaskEntity;
import org.camunda.bpm.engine.impl.persistence.entity.TaskManager;
import org.camunda.bpm.engine.variable.VariableMap;

/**
* @author Joram Barrez
*/
public class CompleteTaskCmd implements Command<Map<String, Object>>, Serializable {
public class CompleteTaskCmd implements Command<VariableMap>, Serializable {

private static final long serialVersionUID = 1L;

Expand All @@ -43,7 +44,7 @@ public CompleteTaskCmd(String taskId, Map<String, Object> variables) {
this.variables = variables;
}

public Map<String, Object> execute(CommandContext commandContext) {
public VariableMap execute(CommandContext commandContext) {
ensureNotNull("taskId", taskId);

TaskManager taskManager = commandContext.getTaskManager();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
* @author Tom Baeyens
* @author Joram Barrez
*/
public class SubmitTaskFormCmd implements Command<Map<String, Object>>, Serializable {
public class SubmitTaskFormCmd implements Command<VariableMap>, Serializable {

private static final long serialVersionUID = 1L;

Expand All @@ -51,7 +51,7 @@ public SubmitTaskFormCmd(String taskId, Map<String, Object> properties) {
this.properties = Variables.fromMap(properties);
}

public Map<String, Object> execute(CommandContext commandContext) {
public VariableMap execute(CommandContext commandContext) {
ensureNotNull("taskId", taskId);
TaskManager taskManager = commandContext.getTaskManager();
TaskEntity task = taskManager.findTaskById(taskId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -979,7 +979,7 @@ public void testSubmitTaskFormWithObjectVariables() {

@Deployment(resources = { "org/camunda/bpm/engine/test/api/task/TaskServiceTest.testCompleteTaskWithVariablesInReturn.bpmn20.xml" })
@Test
public void testCompleteTaskWithVariablesInReturn() {
public void testSubmitTaskFormWithVariablesInReturn() {
String processVarName = "processVar";
String processVarValue = "processVarValue";

Expand All @@ -998,10 +998,12 @@ public void testCompleteTaskWithVariablesInReturn() {
additionalVariables.put(taskVarName, taskVarValue);

// After completion of firstUserTask a script Task sets 'x' = 5
Map<String, Object> vars = formService.submitTaskFormWithVariablesInReturn(firstUserTask.getId(), additionalVariables);
VariableMap vars = formService.submitTaskFormWithVariablesInReturn(firstUserTask.getId(), additionalVariables);
assertEquals(3, vars.size());
assertEquals(5, vars.get("x"));
assertEquals(ValueType.INTEGER, vars.getValueTyped("x").getType());
assertEquals(processVarValue, vars.get(processVarName));
assertEquals(ValueType.STRING, vars.getValueTyped(processVarName).getType());
assertEquals(taskVarValue, vars.get(taskVarName));

additionalVariables = new HashMap<String, Object>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
import org.camunda.bpm.engine.test.util.ProvidedProcessEngineRule;
import org.camunda.bpm.engine.variable.VariableMap;
import org.camunda.bpm.engine.variable.Variables;
import org.camunda.bpm.engine.variable.type.ValueType;
import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
Expand Down Expand Up @@ -795,11 +796,14 @@ public void testCompleteTaskWithVariablesInReturn() {
additionalVariables.put(taskVarName, taskVarValue);

// After completion of firstUserTask a script Task sets 'x' = 5
Map<String, Object> vars = taskService.completeWithVariablesInReturn(firstUserTask.getId(), additionalVariables);
VariableMap vars = taskService.completeWithVariablesInReturn(firstUserTask.getId(), additionalVariables);

assertEquals(3, vars.size());
assertEquals(5, vars.get("x"));
assertEquals(ValueType.INTEGER, vars.getValueTyped("x").getType());
assertEquals(processVarValue, vars.get(processVarName));
assertEquals(taskVarValue, vars.get(taskVarName));
assertEquals(ValueType.STRING, vars.getValueTyped(taskVarName).getType());

additionalVariables = new HashMap<String, Object>();
additionalVariables.put("x", 7);
Expand Down

0 comments on commit b9af348

Please sign in to comment.