Skip to content

Commit

Permalink
feat(engine+rest): set variables on process instance migration
Browse files Browse the repository at this point in the history
* Available for synchronous and asynchronous execution
* When a batch is created, the variables are intermediately stored in the `ACT_RU_VARIABLE` table
* Set variables into the process instances' scope
* Variables are validated when configuring the migration plan
  * A `MigrationVariableValidationReport` contains the validation result
* Refactors the prevention of user operation logs in job handlers
* Removes `CoreLogger#missingVariableInstanceException` since it is unused
* Adds REST API
* Adds Open API (CAM-13448, camunda#1443)

related to CAM-13410, closes camunda#1442
  • Loading branch information
tasso94 authored May 6, 2021
1 parent dba53ae commit 459ddf9
Show file tree
Hide file tree
Showing 64 changed files with 2,624 additions and 265 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@

* `transient`: Indicates whether the variable should be transient or
not. See [documentation](${docsUrl}/user-guide/process-engine/variables#transient-variables) for more informations.
(Not applicable for `decision-definition` and ` /process-instance/variables-async` endpoints)"
(Not applicable for `decision-definition`, ` /process-instance/variables-async`, and `/migration/executeAsync` endpoints)"
/>





</@lib.dto>
</#macro>
</#macro>
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
desc = "A migration instruction JSON object."
/>

<@lib.property
<@lib.property
name = "failures"
type = "array"
itemType = "string"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,15 @@
dto = "MigrationInstructionDto"
desc = "A list of migration instructions which map equal activities. Each
migration instruction is a JSON object with the following properties:"
/>

<@lib.property
name = "variables"
type = "object"
additionalProperties = true
dto = "VariableValueDto"
desc = "A map of variables which will be set into the process instances' scope.
Each key is a variable name and each value a JSON variable value object."
last = true
/>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,17 @@
type = "boolean"
desc = "A boolean flag indicating whether instructions between events should be configured
to update the event triggers."
last = true
/>

<@lib.property
name = "variables"
type = "object"
additionalProperties = true
dto = "VariableValueDto"
desc = "A map of variables which will be set into the process instances' scope.
Each key is a variable name and each value a JSON variable value object."
last = true
/>

</@lib.dto>
</#macro>
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,16 @@
dto = "MigrationInstructionValidationReportDto"
desc = "The list of instruction validation reports. If no validation
errors are detected it is an empty list."
/>

<@lib.property
name = "variableReports"
type = "object"
additionalProperties = true
dto = "MigrationVariableValidationReportDto"
desc = "A map of variable reports.
Each key is a variable name and each value a JSON object consisting of the variable's type, value,
value info object and a list of failures."
last = true
/>

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<#macro dto_macro docsUrl="">
<@lib.dto extends="VariableValueDto">

<@lib.property
name = "failures"
type = "array"
itemType = "string"
desc = "A list of variable validation report messages."
last = true
/>

</@lib.dto>
</#macro>
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,17 @@
],
"updateEventTrigger": true
}
]
],
"variables": {
"foo": {
"type": "Object",
"value": "[5,9]",
"valueInfo": {
"objectTypeName": "java.util.ArrayList",
"serializationDataFormat": "application/json"
}
}
}
},
"processInstanceIds": [
"aProcessInstance",
Expand All @@ -63,6 +73,13 @@
desc = "Request successful. This method returns no content."
/>

<@lib.response
code = "400"
dto = "ExceptionDto"
desc = "Invalid variable value, for example if the value could not be parsed to an Integer value or the passed variable type is not supported.
See the [Introduction](${docsUrl}/reference/rest/overview/#error-handling) for the error response format."
/>

<@lib.response
code = "400"
dto = "ExceptionDto"
Expand All @@ -72,7 +89,7 @@
`MigrationPlanValidationException` is returned.
* The provided migration plan is not valid for a specific process
instance it is applied to, so an exception of type
`MigrationInstructionInstanceValidationException` is returned.
`MigratingProcessInstanceValidationException` is returned.
* In case additional parameters of the request are unexpected, an
exception of type `InvalidRequestException` is returned.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,17 @@
],
"updateEventTrigger": true
}
]
],
"variables": {
"foo": {
"type": "Object",
"value": "[5,9]",
"valueInfo": {
"objectTypeName": "java.util.ArrayList",
"serializationDataFormat": "application/json"
}
}
}
},
"processInstanceIds": [
"aProcessInstance",
Expand Down Expand Up @@ -79,6 +89,13 @@
}']
/>

<@lib.response
code = "400"
dto = "ExceptionDto"
desc = "Invalid variable value, for example if the value could not be parsed to an Integer value or the passed variable type is not supported.
See the [Introduction](${docsUrl}/reference/rest/overview/#error-handling) for the error response format."
/>

<@lib.response
code = "400"
dto = "ExceptionDto"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,17 @@
"value": {
"sourceProcessDefinitionId": "aProcessDefinitionId1",
"targetProcessDefinitionId": "aProcessDefinitionId2",
"updateEventTriggers": true
"updateEventTriggers": true,
"variables": {
"foo": {
"type": "Object",
"value": "[5,6]",
"valueInfo": {
"objectTypeName": "java.util.ArrayList",
"serializationDataFormat": "application/json"
}
}
}
}
}']
/>
Expand Down Expand Up @@ -55,11 +65,28 @@
],
"updateEventTrigger": true
}
]
],
"variables": {
"foo": {
"type": "Object",
"value": "[5,6]",
"valueInfo": {
"objectTypeName": "java.util.ArrayList",
"serializationDataFormat": "application/json"
}
}
}
}
}']
/>

<@lib.response
code = "400"
dto = "ExceptionDto"
desc = "Invalid variable value, for example if the value could not be parsed to an Integer value or the passed variable type is not supported.
See the [Introduction](${docsUrl}/reference/rest/overview/#error-handling) for the error response format."
/>

<@lib.response
code = "400"
dto = "ExceptionDto"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,17 @@
],
"updateEventTrigger": true
}
]
],
"variables": {
"foo": {
"type": "Object",
"value": "...",
"valueInfo": {
"objectTypeName": "java.util.ArrayList",
"serializationDataFormat": "application/x-java-serialized-object"
}
}
}
}
}']
/>
Expand Down Expand Up @@ -83,11 +93,31 @@
"failure2"
]
}
]
],
"variableReports": {
"foo": {
"type": "Object",
"value": "...",
"valueInfo": {
"objectTypeName": "java.util.ArrayList",
"serializationDataFormat": "application/x-java-serialized-object"
},
"failures": [
"Cannot set variable with name foo. Java serialization format is prohibited"
]
}
}
}
}']
/>

<@lib.response
code = "400"
dto = "ExceptionDto"
desc = "Invalid variable value, for example if the value could not be parsed to an Integer value or the passed variable type is not supported.
See the [Introduction](${docsUrl}/reference/rest/overview/#error-handling) for the error response format."
/>

<@lib.response
code = "400"
dto = "ExceptionDto"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,23 @@

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import com.fasterxml.jackson.databind.ObjectMapper;
import org.camunda.bpm.engine.migration.MigrationPlanBuilder;
import org.camunda.bpm.engine.ProcessEngine;
import org.camunda.bpm.engine.migration.MigrationInstruction;
import org.camunda.bpm.engine.migration.MigrationInstructionBuilder;
import org.camunda.bpm.engine.migration.MigrationPlan;
import org.camunda.bpm.engine.rest.dto.VariableValueDto;
import org.camunda.bpm.engine.variable.VariableMap;

public class MigrationPlanDto {

protected String sourceProcessDefinitionId;
protected String targetProcessDefinitionId;
protected List<MigrationInstructionDto> instructions;
protected Map<String, VariableValueDto> variables;

public String getSourceProcessDefinitionId() {
return sourceProcessDefinitionId;
Expand All @@ -55,9 +60,22 @@ public void setInstructions(List<MigrationInstructionDto> instructions) {
this.instructions = instructions;
}

public Map<String, VariableValueDto> getVariables() {
return variables;
}

public void setVariables(Map<String, VariableValueDto> variables) {
this.variables = variables;
}

public static MigrationPlanDto from(MigrationPlan migrationPlan) {
MigrationPlanDto dto = new MigrationPlanDto();

VariableMap variables = migrationPlan.getVariables();
if (variables != null) {
dto.setVariables(VariableValueDto.fromMap(variables));
}

dto.setSourceProcessDefinitionId(migrationPlan.getSourceProcessDefinitionId());
dto.setTargetProcessDefinitionId(migrationPlan.getTargetProcessDefinitionId());

Expand All @@ -73,9 +91,18 @@ public static MigrationPlanDto from(MigrationPlan migrationPlan) {
return dto;
}

public static MigrationPlan toMigrationPlan(ProcessEngine processEngine, MigrationPlanDto migrationPlanDto) {
public static MigrationPlan toMigrationPlan(ProcessEngine processEngine,
ObjectMapper objectMapper,
MigrationPlanDto migrationPlanDto) {
MigrationPlanBuilder migrationPlanBuilder = processEngine.getRuntimeService().createMigrationPlan(migrationPlanDto.getSourceProcessDefinitionId(), migrationPlanDto.getTargetProcessDefinitionId());

Map<String, VariableValueDto> variableDtos = migrationPlanDto.getVariables();
if (variableDtos != null) {
Map<String, Object> variables =
VariableValueDto.toMap(variableDtos, processEngine, objectMapper);
migrationPlanBuilder.setVariables(variables);
}

if (migrationPlanDto.getInstructions() != null) {
for (MigrationInstructionDto migrationInstructionDto : migrationPlanDto.getInstructions()) {
MigrationInstructionBuilder migrationInstructionBuilder = migrationPlanBuilder.mapActivities(migrationInstructionDto.getSourceActivityIds().get(0), migrationInstructionDto.getTargetActivityIds().get(0));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@
*/
package org.camunda.bpm.engine.rest.dto.migration;

import org.camunda.bpm.engine.rest.dto.VariableValueDto;

import java.util.Map;

/**
* @author Thorben Lindhauer
*
Expand All @@ -25,6 +29,7 @@ public class MigrationPlanGenerationDto {
protected String sourceProcessDefinitionId;
protected String targetProcessDefinitionId;
protected boolean updateEventTriggers;
protected Map<String, VariableValueDto> variables;

public String getSourceProcessDefinitionId() {
return sourceProcessDefinitionId;
Expand All @@ -50,4 +55,12 @@ public void setUpdateEventTriggers(boolean updateEventTriggers) {
this.updateEventTriggers = updateEventTriggers;
}

public void setVariables(Map<String, VariableValueDto> variables) {
this.variables = variables;
}

public Map<String, VariableValueDto> getVariables() {
return variables;
}

}
Loading

0 comments on commit 459ddf9

Please sign in to comment.