From 3168e1b0d8b78c98cd8b0cb8213089c194b614e4 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Thu, 29 Jun 2023 16:56:10 +0200 Subject: [PATCH] Make sure that the update of a process / execution variable returns the same scope as fetching a variable When a variable is updated for a process instance no scope is returned, and when one is updated for an execution the relevant scope is returned. This is handled by the `constructRestVariable` which is overridden in the process variable resources and explicitly uses `null` --- .../api/runtime/CaseInstanceVariableResourceTest.java | 10 +++++++--- .../runtime/process/BaseExecutionVariableResource.java | 5 +---- .../runtime/ProcessInstanceVariableResourceTest.java | 4 ++++ 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/modules/flowable-cmmn-rest/src/test/java/org/flowable/cmmn/rest/service/api/runtime/CaseInstanceVariableResourceTest.java b/modules/flowable-cmmn-rest/src/test/java/org/flowable/cmmn/rest/service/api/runtime/CaseInstanceVariableResourceTest.java index b412aeac82c..5c2c2f806cb 100644 --- a/modules/flowable-cmmn-rest/src/test/java/org/flowable/cmmn/rest/service/api/runtime/CaseInstanceVariableResourceTest.java +++ b/modules/flowable-cmmn-rest/src/test/java/org/flowable/cmmn/rest/service/api/runtime/CaseInstanceVariableResourceTest.java @@ -249,7 +249,7 @@ public void testDeleteProcessVariable() throws Exception { * PUT cmmn-runtime/case-instances/{caseInstanceId}/variables/{variableName} */ @CmmnDeployment(resources = { "org/flowable/cmmn/rest/service/api/repository/oneHumanTaskCase.cmmn" }) - public void testUpdateProcessVariable() throws Exception { + public void testUpdateCaseVariable() throws Exception { CaseInstance caseInstance = runtimeService.createCaseInstanceBuilder().caseDefinitionKey("oneHumanTaskCase") .variables(Collections.singletonMap("overlappingVariable", (Object) "processValue")).start(); runtimeService.setVariable(caseInstance.getId(), "myVar", "value"); @@ -271,6 +271,7 @@ public void testUpdateProcessVariable() throws Exception { assertThatJson(responseNode) .when(Option.IGNORING_EXTRA_FIELDS) .isEqualTo("{" + + " scope: 'global'," + " value: 'updatedValue'" + "}"); @@ -288,7 +289,7 @@ public void testUpdateProcessVariable() throws Exception { } @CmmnDeployment(resources = { "org/flowable/cmmn/rest/service/api/repository/oneHumanTaskCase.cmmn" }) - public void testUpdateInstantProcessVariable() throws Exception { + public void testUpdateInstantCaseVariable() throws Exception { Instant initial = Instant.parse("2019-12-03T12:32:45.583345Z"); Instant tenDaysLater = initial.plus(10, ChronoUnit.DAYS); @@ -316,6 +317,7 @@ public void testUpdateInstantProcessVariable() throws Exception { assertThatJson(responseNode) .when(Option.IGNORING_EXTRA_FIELDS) .isEqualTo("{" + + " scope: 'global'," + " value: '2019-12-13T12:32:45.583Z'" + "}"); } @@ -348,12 +350,13 @@ public void testUpdateLocalDateCaseVariable() throws Exception { assertThatJson(responseNode) .when(Option.IGNORING_EXTRA_FIELDS) .isEqualTo("{" + + " scope: 'global'," + " value: '2020-01-28'" + "}"); } @CmmnDeployment(resources = { "org/flowable/cmmn/rest/service/api/repository/oneHumanTaskCase.cmmn" }) - public void testUpdateLocalDateTimeProcessVariable() throws Exception { + public void testUpdateLocalDateTimeCaseVariable() throws Exception { LocalDateTime initial = LocalDateTime.parse("2020-01-18T12:32:45"); LocalDateTime tenDaysLater = initial.plusDays(10); @@ -380,6 +383,7 @@ public void testUpdateLocalDateTimeProcessVariable() throws Exception { assertThatJson(responseNode) .when(Option.IGNORING_EXTRA_FIELDS) .isEqualTo("{" + + " scope: 'global'," + " value: '2020-01-28T12:32:45'" + "}"); } diff --git a/modules/flowable-rest/src/main/java/org/flowable/rest/service/api/runtime/process/BaseExecutionVariableResource.java b/modules/flowable-rest/src/main/java/org/flowable/rest/service/api/runtime/process/BaseExecutionVariableResource.java index 9b54c456f9e..27f769cd80e 100644 --- a/modules/flowable-rest/src/main/java/org/flowable/rest/service/api/runtime/process/BaseExecutionVariableResource.java +++ b/modules/flowable-rest/src/main/java/org/flowable/rest/service/api/runtime/process/BaseExecutionVariableResource.java @@ -196,10 +196,7 @@ protected RestVariable setSimpleVariable(RestVariable restVariable, Execution ex Object actualVariableValue = restResponseFactory.getVariableValue(restVariable); setVariable(execution, restVariable.getName(), actualVariableValue, scope, isNew); - RestVariable variable = getVariableFromRequestWithoutAccessCheck(execution, restVariable.getName(), scope, false); - // We are setting the scope because the fetched variable does not always have it - variable.setVariableScope(scope); - return variable; + return getVariableFromRequestWithoutAccessCheck(execution, restVariable.getName(), scope, false); } protected void setVariable(Execution execution, String name, Object value, RestVariableScope scope, boolean isNew) { diff --git a/modules/flowable-rest/src/test/java/org/flowable/rest/service/api/runtime/ProcessInstanceVariableResourceTest.java b/modules/flowable-rest/src/test/java/org/flowable/rest/service/api/runtime/ProcessInstanceVariableResourceTest.java index a5c20d44291..f4265ec0ca2 100644 --- a/modules/flowable-rest/src/test/java/org/flowable/rest/service/api/runtime/ProcessInstanceVariableResourceTest.java +++ b/modules/flowable-rest/src/test/java/org/flowable/rest/service/api/runtime/ProcessInstanceVariableResourceTest.java @@ -297,6 +297,7 @@ public void testUpdateProcessVariable() throws Exception { assertThatJson(responseNode) .when(Option.IGNORING_EXTRA_FIELDS) .isEqualTo("{" + + "scope: null," + "value: 'updatedValue'" + "}"); @@ -342,6 +343,7 @@ public void testUpdateInstantProcessVariable() throws Exception { assertThatJson(responseNode) .when(Option.IGNORING_EXTRA_FIELDS) .isEqualTo("{" + + " scope: null," + " value: '2019-12-13T12:32:45.583Z'" + "}"); } @@ -374,6 +376,7 @@ public void testUpdateLocalDateProcessVariable() throws Exception { assertThatJson(responseNode) .when(Option.IGNORING_EXTRA_FIELDS) .isEqualTo("{" + + " scope: null," + " value: '2020-01-28'" + "}"); } @@ -407,6 +410,7 @@ public void testUpdateLocalDateTimeProcessVariable() throws Exception { assertThatJson(responseNode) .when(Option.IGNORING_EXTRA_FIELDS) .isEqualTo("{" + + " scope: null," + " value: '2020-01-28T12:32:45'" + "}"); }