Skip to content

Commit a6ce53e

Browse files
Fix potential issues when retrieving variables with unresolvable variable values (#4299)
* Fix potential issues when retrieving variables with unresolvable variable values A variable whose value cannot be resolved (e.g. a serialized value that can no longer be deserialized, or a custom variable type that fails to load its value) failed every read that returned variables, like the variable instance queries, the queries including variables and the variable REST endpoints. - The (historic) variable instance queries and the queries including variables return such a variable with a null value instead of failing, and mark it as having an unresolvable value (HasUnresolvableValue on the runtime and historic variable entities), so reading its value again returns null instead of failing again. - getVariable(s) of the RuntimeService, CmmnRuntimeService, TaskService and CmmnTaskService still fail for such a variable, as do variable access during process / case execution and case reactivation. - The variable REST endpoints read the variable instances and resolve their values when the REST response is created, so such a variable is returned with a null value and a valueUnresolvable marker (only present when true) instead of failing the whole response. * Resolve variable values in the REST layer instead of marking unresolvable variable entities The variable entities are no longer changed: HasUnresolvableValue and VariableValueUtil are removed and the (historic) variable instance queries and service getters fail again for a variable whose value cannot be resolved. - The queries that include variables get an include*Variables(..., boolean excludeVariableInitialization) overload (case, historic case, process, historic process, plan item, historic plan item and task queries). The variable values are then not resolved while the query result is mapped, but only when they are read. - The REST query endpoints include the variables without initializing them and create the response in the same command as the query. The REST response factories create the REST variables from the variable instances and mark a variable whose value cannot be resolved with valueUnresolvable, without a value. - The REST type of such a variable is determined from the variable type by the REST variable converters (RestVariableConverter#isVariableTypeSupported), falling back to the binary or serializable type. * Return a server error for the binary data of a variable whose value cannot be resolved - The variable data endpoints resolve the value of the requested variable strictly again, so a variable whose value cannot be resolved results in a server error instead of a REST variable without a value. - The historic process instance and historic task instance variable data endpoints include the variables without initializing them and only resolve the value of the requested variable, so another variable whose value cannot be resolved no longer fails the request. - An unresolvable variable value is logged once at warn level, the base variable resources use a logger for the concrete resource class.
1 parent d149602 commit a6ce53e

61 files changed

Lines changed: 2549 additions & 261 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎modules/flowable-cmmn-api/src/main/java/org/flowable/cmmn/api/history/HistoricCaseInstanceQuery.java‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,20 @@ public interface HistoricCaseInstanceQuery extends Query<HistoricCaseInstanceQue
197197
*/
198198
HistoricCaseInstanceQuery includeCaseVariables(Collection<String> variableNames);
199199

200+
/**
201+
* Include historic case variables in the historic case query result.
202+
* When {@code excludeVariableInitialization} is true the variable values are not resolved by the query, a value is only resolved when it is read.
203+
* A variable whose value cannot be resolved then does not fail the query. The flag applies to all the variables included by the query.
204+
*/
205+
HistoricCaseInstanceQuery includeCaseVariables(boolean excludeVariableInitialization);
206+
207+
/**
208+
* Include the historic case variables with the given names into the query result.
209+
* When {@code excludeVariableInitialization} is true the variable values are not resolved by the query, a value is only resolved when it is read.
210+
* A variable whose value cannot be resolved then does not fail the query. The flag applies to all the variables included by the query.
211+
*/
212+
HistoricCaseInstanceQuery includeCaseVariables(Collection<String> variableNames, boolean excludeVariableInitialization);
213+
200214
/**
201215
* Only select historic case instances that are defined by a case definition with the given deployment identifier.
202216
*/

‎modules/flowable-cmmn-api/src/main/java/org/flowable/cmmn/api/history/HistoricPlanItemInstanceQuery.java‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,13 @@ public interface HistoricPlanItemInstanceQuery extends Query<HistoricPlanItemIns
9696

9797
HistoricPlanItemInstanceQuery includeLocalVariables();
9898

99+
/**
100+
* Include local plan item instance variables in the query result.
101+
* When {@code excludeVariableInitialization} is true the variable values are not resolved by the query, a value is only resolved when it is read.
102+
* A variable whose value cannot be resolved then does not fail the query. The flag applies to all the variables included by the query.
103+
*/
104+
HistoricPlanItemInstanceQuery includeLocalVariables(boolean excludeVariableInitialization);
105+
99106
/**
100107
* Begin an OR statement. Make sure you invoke the endOr method at the end of your OR statement.
101108
* OR statements cannot be nested: calling or() again before endOr() throws an exception. Sequential

‎modules/flowable-cmmn-api/src/main/java/org/flowable/cmmn/api/runtime/CaseInstanceQuery.java‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,20 @@ public interface CaseInstanceQuery extends Query<CaseInstanceQuery, CaseInstance
249249
*/
250250
CaseInstanceQuery includeCaseVariables(Collection<String> variableNames);
251251

252+
/**
253+
* Includes case variables into the query result.
254+
* When {@code excludeVariableInitialization} is true the variable values are not resolved by the query, a value is only resolved when it is read.
255+
* A variable whose value cannot be resolved then does not fail the query. The flag applies to all the variables included by the query.
256+
*/
257+
CaseInstanceQuery includeCaseVariables(boolean excludeVariableInitialization);
258+
259+
/**
260+
* Include the case variables with the given names into the query result.
261+
* When {@code excludeVariableInitialization} is true the variable values are not resolved by the query, a value is only resolved when it is read.
262+
* A variable whose value cannot be resolved then does not fail the query. The flag applies to all the variables included by the query.
263+
*/
264+
CaseInstanceQuery includeCaseVariables(Collection<String> variableNames, boolean excludeVariableInitialization);
265+
252266
/**
253267
* Begin an OR statement. Make sure you invoke the endOr method at the end of your OR statement.
254268
*/

‎modules/flowable-cmmn-api/src/main/java/org/flowable/cmmn/api/runtime/PlanItemInstanceQuery.java‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,13 @@ public interface PlanItemInstanceQuery extends Query<PlanItemInstanceQuery, Plan
405405
*/
406406
PlanItemInstanceQuery includeLocalVariables();
407407

408+
/**
409+
* Include local plan item instance variables in the query result.
410+
* When {@code excludeVariableInitialization} is true the variable values are not resolved by the query, a value is only resolved when it is read.
411+
* A variable whose value cannot be resolved then does not fail the query. The flag applies to all the variables included by the query.
412+
*/
413+
PlanItemInstanceQuery includeLocalVariables(boolean excludeVariableInitialization);
414+
408415
/**
409416
* Localize plan item name to specified locale.
410417
*/

‎modules/flowable-cmmn-engine/src/main/java/org/flowable/cmmn/engine/impl/history/HistoricCaseInstanceQueryImpl.java‎

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
import org.flowable.common.engine.impl.persistence.cache.EntityCache;
4242
import org.flowable.variable.service.impl.AbstractVariableQueryImpl;
4343
import org.flowable.variable.service.impl.persistence.entity.HistoricVariableInstanceEntity;
44+
import org.flowable.variable.service.impl.persistence.entity.VariableInitializingList;
4445

4546
/**
4647
* @author Joram Barrez
@@ -114,6 +115,7 @@ public class HistoricCaseInstanceQueryImpl extends AbstractVariableQueryImpl<His
114115
protected boolean withoutTenantId;
115116
protected boolean includeCaseVariables;
116117
protected Collection<String> variableNamesToInclude;
118+
protected boolean excludeVariableInitialization;
117119
protected String activePlanItemDefinitionId;
118120
protected Set<String> activePlanItemDefinitionIds;
119121
protected String involvedUser;
@@ -940,11 +942,14 @@ public List<HistoricCaseInstance> executeList(CommandContext commandContext) {
940942
results = cmmnEngineConfiguration.getHistoricCaseInstanceEntityManager().findIdsByCriteria(this);
941943

942944
} else if (includeCaseVariables) {
943-
results = cmmnEngineConfiguration.getHistoricCaseInstanceEntityManager().findWithVariablesByQueryCriteria(this);
945+
results = VariableInitializingList.executeQueryIncludingVariables(commandContext, excludeVariableInitialization, () -> {
946+
List<HistoricCaseInstance> caseInstances = cmmnEngineConfiguration.getHistoricCaseInstanceEntityManager().findWithVariablesByQueryCriteria(this);
944947

945-
if (caseInstanceId != null) {
946-
addCachedVariableForQueryById(commandContext, results);
947-
}
948+
if (caseInstanceId != null) {
949+
addCachedVariableForQueryById(commandContext, caseInstances);
950+
}
951+
return caseInstances;
952+
});
948953

949954
} else {
950955
results = cmmnEngineConfiguration.getHistoricCaseInstanceEntityManager().findByCriteria(this);
@@ -1050,6 +1055,20 @@ public HistoricCaseInstanceQuery includeCaseVariables(Collection<String> variabl
10501055
return this;
10511056
}
10521057

1058+
@Override
1059+
public HistoricCaseInstanceQuery includeCaseVariables(boolean excludeVariableInitialization) {
1060+
includeCaseVariables();
1061+
this.excludeVariableInitialization = excludeVariableInitialization;
1062+
return this;
1063+
}
1064+
1065+
@Override
1066+
public HistoricCaseInstanceQuery includeCaseVariables(Collection<String> variableNames, boolean excludeVariableInitialization) {
1067+
includeCaseVariables(variableNames);
1068+
this.excludeVariableInitialization = excludeVariableInitialization;
1069+
return this;
1070+
}
1071+
10531072
@Override
10541073
public HistoricCaseInstanceQuery activePlanItemDefinitionId(String planItemDefinitionId) {
10551074
if (planItemDefinitionId == null) {
@@ -1555,6 +1574,10 @@ public Collection<String> getVariableNamesToInclude() {
15551574
return variableNamesToInclude;
15561575
}
15571576

1577+
public boolean isExcludeVariableInitialization() {
1578+
return excludeVariableInitialization;
1579+
}
1580+
15581581
public List<HistoricCaseInstanceQueryImpl> getOrQueryObjects() {
15591582
return orQueryObjects;
15601583
}

‎modules/flowable-cmmn-engine/src/main/java/org/flowable/cmmn/engine/impl/history/HistoricPlanItemInstanceQueryImpl.java‎

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import org.flowable.common.engine.impl.interceptor.CommandContext;
2929
import org.flowable.common.engine.impl.interceptor.CommandExecutor;
3030
import org.flowable.common.engine.impl.query.AbstractQuery;
31+
import org.flowable.variable.service.impl.persistence.entity.VariableInitializingList;
3132

3233
/**
3334
* @author Dennis Federico
@@ -99,6 +100,7 @@ public class HistoricPlanItemInstanceQueryImpl extends AbstractQuery<HistoricPla
99100
protected String locale;
100101
protected boolean withLocalizationFallback;
101102
protected boolean includeLocalVariables;
103+
protected boolean excludeVariableInitialization;
102104

103105
protected List<HistoricPlanItemInstanceQueryImpl> orQueryObjects = new ArrayList<>();
104106
protected HistoricPlanItemInstanceQueryImpl currentOrQueryObject;
@@ -740,6 +742,13 @@ public HistoricPlanItemInstanceQuery includeLocalVariables() {
740742
return this;
741743
}
742744

745+
@Override
746+
public HistoricPlanItemInstanceQuery includeLocalVariables(boolean excludeVariableInitialization) {
747+
includeLocalVariables();
748+
this.excludeVariableInitialization = excludeVariableInitialization;
749+
return this;
750+
}
751+
743752

744753
@Override
745754
public HistoricPlanItemInstanceQuery orderByCreateTime() {
@@ -842,7 +851,8 @@ public long executeCount(CommandContext commandContext) {
842851
public List<HistoricPlanItemInstance> executeList(CommandContext commandContext) {
843852
List<HistoricPlanItemInstance> historicPlanItems;
844853
if (includeLocalVariables){
845-
historicPlanItems = CommandContextUtil.getHistoricPlanItemInstanceEntityManager(commandContext).findWithVariablesByCriteria(this);
854+
historicPlanItems = VariableInitializingList.executeQueryIncludingVariables(commandContext, excludeVariableInitialization,
855+
() -> CommandContextUtil.getHistoricPlanItemInstanceEntityManager(commandContext).findWithVariablesByCriteria(this));
846856
} else {
847857
historicPlanItems =CommandContextUtil.getHistoricPlanItemInstanceEntityManager(commandContext).findByCriteria(this);
848858
}
@@ -1032,6 +1042,10 @@ public boolean isIncludeLocalVariables() {
10321042
return includeLocalVariables;
10331043
}
10341044

1045+
public boolean isExcludeVariableInitialization() {
1046+
return excludeVariableInitialization;
1047+
}
1048+
10351049
public List<List<String>> getSafeInvolvedGroups() {
10361050
return safeInvolvedGroups;
10371051
}

‎modules/flowable-cmmn-engine/src/main/java/org/flowable/cmmn/engine/impl/runtime/CaseInstanceQueryImpl.java‎

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import org.flowable.common.engine.impl.interceptor.CommandContext;
3333
import org.flowable.common.engine.impl.interceptor.CommandExecutor;
3434
import org.flowable.variable.service.impl.AbstractVariableQueryImpl;
35+
import org.flowable.variable.service.impl.persistence.entity.VariableInitializingList;
3536

3637
/**
3738
* @author Joram Barrez
@@ -99,6 +100,7 @@ public class CaseInstanceQueryImpl extends AbstractVariableQueryImpl<CaseInstanc
99100
protected boolean withoutTenantId;
100101
protected boolean includeCaseVariables;
101102
protected Collection<String> variableNamesToInclude;
103+
protected boolean excludeVariableInitialization;
102104
protected String activePlanItemDefinitionId;
103105
protected Set<String> activePlanItemDefinitionIds;
104106
protected String involvedUser;
@@ -1073,6 +1075,20 @@ public CaseInstanceQuery includeCaseVariables(Collection<String> variableNames)
10731075
return this;
10741076
}
10751077

1078+
@Override
1079+
public CaseInstanceQuery includeCaseVariables(boolean excludeVariableInitialization) {
1080+
includeCaseVariables();
1081+
this.excludeVariableInitialization = excludeVariableInitialization;
1082+
return this;
1083+
}
1084+
1085+
@Override
1086+
public CaseInstanceQuery includeCaseVariables(Collection<String> variableNames, boolean excludeVariableInitialization) {
1087+
includeCaseVariables(variableNames);
1088+
this.excludeVariableInitialization = excludeVariableInitialization;
1089+
return this;
1090+
}
1091+
10761092
@Override
10771093
public CaseInstanceQuery locale(String locale) {
10781094
this.locale = locale;
@@ -1106,7 +1122,8 @@ public List<CaseInstance> executeList(CommandContext commandContext) {
11061122
if (returnIdsOnly) {
11071123
caseInstances = cmmnEngineConfiguration.getCaseInstanceEntityManager().findIdsByCriteria(this);
11081124
} else if (this.isIncludeCaseVariables()) {
1109-
caseInstances = cmmnEngineConfiguration.getCaseInstanceEntityManager().findWithVariablesByCriteria(this);
1125+
caseInstances = VariableInitializingList.executeQueryIncludingVariables(commandContext, excludeVariableInitialization,
1126+
() -> cmmnEngineConfiguration.getCaseInstanceEntityManager().findWithVariablesByCriteria(this));
11101127
} else {
11111128
caseInstances = cmmnEngineConfiguration.getCaseInstanceEntityManager().findByCriteria(this);
11121129
}
@@ -1383,6 +1400,10 @@ public Collection<String> getVariableNamesToInclude() {
13831400
return variableNamesToInclude;
13841401
}
13851402

1403+
public boolean isExcludeVariableInitialization() {
1404+
return excludeVariableInitialization;
1405+
}
1406+
13861407
public boolean isNeedsCaseDefinitionOuterJoin() {
13871408
if (isNeedsPaging()) {
13881409
if (AbstractEngineConfiguration.DATABASE_TYPE_ORACLE.equals(databaseType)

‎modules/flowable-cmmn-engine/src/main/java/org/flowable/cmmn/engine/impl/runtime/PlanItemInstanceQueryImpl.java‎

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import org.flowable.common.engine.impl.interceptor.CommandContext;
2929
import org.flowable.common.engine.impl.interceptor.CommandExecutor;
3030
import org.flowable.variable.service.impl.AbstractVariableQueryImpl;
31+
import org.flowable.variable.service.impl.persistence.entity.VariableInitializingList;
3132

3233
/**
3334
* @author Joram Barrez
@@ -99,6 +100,7 @@ public class PlanItemInstanceQueryImpl extends AbstractVariableQueryImpl<PlanIte
99100
protected String locale;
100101
protected boolean withLocalizationFallback;
101102
protected boolean includeLocalVariables;
103+
protected boolean excludeVariableInitialization;
102104

103105
protected List<PlanItemInstanceQueryImpl> orQueryObjects = new ArrayList<>();
104106
protected PlanItemInstanceQueryImpl currentOrQueryObject;
@@ -1183,6 +1185,13 @@ public PlanItemInstanceQuery includeLocalVariables() {
11831185
return this;
11841186
}
11851187

1188+
@Override
1189+
public PlanItemInstanceQuery includeLocalVariables(boolean excludeVariableInitialization) {
1190+
includeLocalVariables();
1191+
this.excludeVariableInitialization = excludeVariableInitialization;
1192+
return this;
1193+
}
1194+
11861195
@Override
11871196
public PlanItemInstanceQuery locale(String locale) {
11881197
this.locale = locale;
@@ -1206,7 +1215,8 @@ public List<PlanItemInstance> executeList(CommandContext commandContext) {
12061215
ensureVariablesInitialized();
12071216
List<PlanItemInstance> planItems = null;
12081217
if (includeLocalVariables) {
1209-
planItems = cmmnEngineConfiguration.getPlanItemInstanceEntityManager().findWithVariablesByCriteria(this);
1218+
planItems = VariableInitializingList.executeQueryIncludingVariables(commandContext, excludeVariableInitialization,
1219+
() -> cmmnEngineConfiguration.getPlanItemInstanceEntityManager().findWithVariablesByCriteria(this));
12101220

12111221
} else {
12121222
planItems = cmmnEngineConfiguration.getPlanItemInstanceEntityManager().findByCriteria(this);
@@ -1415,6 +1425,11 @@ public boolean isWithoutTenantId() {
14151425
public boolean isIncludeLocalVariables() {
14161426
return includeLocalVariables;
14171427
}
1428+
1429+
public boolean isExcludeVariableInitialization() {
1430+
return excludeVariableInitialization;
1431+
}
1432+
14181433
public List<List<String>> getSafeInvolvedGroups() {
14191434
return safeInvolvedGroups;
14201435
}

0 commit comments

Comments
 (0)