Skip to content

Commit 18db156

Browse files
Add support for updating more task properties when doing case and process instance migration
1 parent b1312f3 commit 18db156

28 files changed

Lines changed: 1673 additions & 244 deletions

File tree

modules/flowable-cmmn-api/src/main/java/org/flowable/cmmn/api/migration/ActivatePlanItemDefinitionMapping.java

Lines changed: 87 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,24 @@
1313
package org.flowable.cmmn.api.migration;
1414

1515
import java.util.LinkedHashMap;
16+
import java.util.List;
1617
import java.util.Map;
1718

1819
public class ActivatePlanItemDefinitionMapping extends PlanItemDefinitionMapping {
1920

21+
protected String newName;
2022
protected String newAssignee;
23+
protected String newOwner;
24+
protected String newFormKey;
25+
protected String newDueDate;
26+
protected String newPriority;
27+
protected String newCategory;
28+
protected List<String> newCandidateUsers;
29+
protected List<String> newCandidateGroups;
2130
protected Map<String, Object> withLocalVariables = new LinkedHashMap<>();
2231

23-
public ActivatePlanItemDefinitionMapping(String planItemDefinitionId, String newAssignee, Map<String, Object> withLocalVariables) {
32+
public ActivatePlanItemDefinitionMapping(String planItemDefinitionId, Map<String, Object> withLocalVariables) {
2433
super(planItemDefinitionId);
25-
this.newAssignee = newAssignee;
2634
this.withLocalVariables = withLocalVariables;
2735
}
2836

@@ -34,25 +42,98 @@ public ActivatePlanItemDefinitionMapping(String planItemDefinitionId, String con
3442
super(planItemDefinitionId, condition);
3543
}
3644

37-
public ActivatePlanItemDefinitionMapping(String planItemDefinitionId, String newAssignee, String condition, Map<String, Object> withLocalVariables) {
45+
public ActivatePlanItemDefinitionMapping(String planItemDefinitionId, String condition, Map<String, Object> withLocalVariables) {
3846
super(planItemDefinitionId, condition);
39-
this.newAssignee = newAssignee;
4047
this.withLocalVariables = withLocalVariables;
4148
}
4249

50+
public String getNewName() {
51+
return newName;
52+
}
53+
54+
public ActivatePlanItemDefinitionMapping withNewName(String newName) {
55+
this.newName = newName;
56+
return this;
57+
}
58+
4359
public String getNewAssignee() {
4460
return newAssignee;
4561
}
4662

47-
public void setNewAssignee(String newAssignee) {
63+
public ActivatePlanItemDefinitionMapping withNewAssignee(String newAssignee) {
4864
this.newAssignee = newAssignee;
65+
return this;
66+
}
67+
68+
public String getNewOwner() {
69+
return newOwner;
70+
}
71+
72+
public ActivatePlanItemDefinitionMapping withNewOwner(String newOwner) {
73+
this.newOwner = newOwner;
74+
return this;
75+
}
76+
77+
public String getNewFormKey() {
78+
return newFormKey;
79+
}
80+
81+
public ActivatePlanItemDefinitionMapping withNewFormKey(String newFormKey) {
82+
this.newFormKey = newFormKey;
83+
return this;
84+
}
85+
86+
public String getNewDueDate() {
87+
return newDueDate;
88+
}
89+
90+
public ActivatePlanItemDefinitionMapping withNewDueDate(String newDueDate) {
91+
this.newDueDate = newDueDate;
92+
return this;
93+
}
94+
95+
public String getNewPriority() {
96+
return newPriority;
97+
}
98+
99+
public ActivatePlanItemDefinitionMapping withNewPriority(String newPriority) {
100+
this.newPriority = newPriority;
101+
return this;
102+
}
103+
104+
public String getNewCategory() {
105+
return newCategory;
106+
}
107+
108+
public ActivatePlanItemDefinitionMapping withNewCategory(String newCategory) {
109+
this.newCategory = newCategory;
110+
return this;
111+
}
112+
113+
public List<String> getNewCandidateUsers() {
114+
return newCandidateUsers;
115+
}
116+
117+
public ActivatePlanItemDefinitionMapping withNewCandidateUsers(List<String> newCandidateUsers) {
118+
this.newCandidateUsers = newCandidateUsers;
119+
return this;
120+
}
121+
122+
public List<String> getNewCandidateGroups() {
123+
return newCandidateGroups;
124+
}
125+
126+
public ActivatePlanItemDefinitionMapping withNewCandidateGroups(List<String> newCandidateGroups) {
127+
this.newCandidateGroups = newCandidateGroups;
128+
return this;
49129
}
50130

51131
public Map<String, Object> getWithLocalVariables() {
52132
return withLocalVariables;
53133
}
54134

55-
public void setWithLocalVariables(Map<String, Object> withLocalVariables) {
135+
public ActivatePlanItemDefinitionMapping withLocalVariables(Map<String, Object> withLocalVariables) {
56136
this.withLocalVariables = withLocalVariables;
137+
return this;
57138
}
58139
}

modules/flowable-cmmn-api/src/main/java/org/flowable/cmmn/api/migration/PlanItemDefinitionMappingBuilder.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,8 @@ public static ActivatePlanItemDefinitionMapping createActivatePlanItemDefinition
2424
return new ActivatePlanItemDefinitionMapping(planItemDefinitionId);
2525
}
2626

27-
public static ActivatePlanItemDefinitionMapping createActivatePlanItemDefinitionMappingFor(String planItemDefinitionId,
28-
String newAssignee, Map<String, Object> withLocalVariables) {
29-
30-
return new ActivatePlanItemDefinitionMapping(planItemDefinitionId, newAssignee, withLocalVariables);
27+
public static ActivatePlanItemDefinitionMapping createActivatePlanItemDefinitionMappingFor(String planItemDefinitionId, Map<String, Object> withLocalVariables) {
28+
return new ActivatePlanItemDefinitionMapping(planItemDefinitionId, withLocalVariables);
3129
}
3230

3331
public static ActivatePlanItemDefinitionMapping createActivatePlanItemDefinitionMappingFor(String planItemDefinitionId, String condition) {

modules/flowable-cmmn-engine/src/main/java/org/flowable/cmmn/engine/impl/behavior/impl/HumanTaskActivityBehavior.java

Lines changed: 94 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -113,14 +113,14 @@ public void execute(CommandContext commandContext, PlanItemInstanceEntity planIt
113113
cmmnEngineConfiguration.getCreateHumanTaskInterceptor().beforeCreateHumanTask(beforeContext);
114114
}
115115

116-
handleTaskName(planItemInstanceEntity, expressionManager, taskEntity, beforeContext);
116+
handleTaskName(planItemInstanceEntity, expressionManager, taskEntity, beforeContext, migrationContext);
117117
handleTaskDescription(planItemInstanceEntity, expressionManager, taskEntity, beforeContext);
118118
handleAssignee(planItemInstanceEntity, taskService, expressionManager, taskEntity, planItemInstanceEntityManager, beforeContext, migrationContext);
119-
handleOwner(planItemInstanceEntity, taskService, expressionManager, taskEntity, beforeContext);
120-
handlePriority(planItemInstanceEntity, expressionManager, taskEntity, beforeContext);
121-
handleFormKey(planItemInstanceEntity, expressionManager, taskEntity, beforeContext);
122-
handleDueDate(commandContext, planItemInstanceEntity, expressionManager, taskEntity, beforeContext);
123-
handleCategory(planItemInstanceEntity, expressionManager, taskEntity, beforeContext);
119+
handleOwner(planItemInstanceEntity, taskService, expressionManager, taskEntity, beforeContext, migrationContext);
120+
handlePriority(planItemInstanceEntity, expressionManager, taskEntity, beforeContext, migrationContext);
121+
handleFormKey(planItemInstanceEntity, expressionManager, taskEntity, beforeContext, migrationContext);
122+
handleDueDate(commandContext, planItemInstanceEntity, expressionManager, taskEntity, beforeContext, migrationContext);
123+
handleCategory(planItemInstanceEntity, expressionManager, taskEntity, beforeContext, migrationContext);
124124

125125
TaskHelper.insertTask(taskEntity, true, cmmnEngineConfiguration);
126126

@@ -143,8 +143,8 @@ public void execute(CommandContext commandContext, PlanItemInstanceEntity planIt
143143
}
144144
}
145145

146-
handleCandidateUsers(commandContext, planItemInstanceEntity, expressionManager, taskEntity, beforeContext);
147-
handleCandidateGroups(commandContext, planItemInstanceEntity, expressionManager, taskEntity, beforeContext);
146+
handleCandidateUsers(commandContext, planItemInstanceEntity, expressionManager, taskEntity, beforeContext, migrationContext);
147+
handleCandidateGroups(commandContext, planItemInstanceEntity, expressionManager, taskEntity, beforeContext, migrationContext);
148148
handleTaskIdVariableStorage(planItemInstanceEntity, humanTask, expressionManager, taskEntity);
149149

150150
planItemInstanceEntity.setReferenceId(taskEntity.getId());
@@ -178,10 +178,18 @@ public void execute(CommandContext commandContext, PlanItemInstanceEntity planIt
178178
}
179179

180180
protected void handleTaskName(PlanItemInstanceEntity planItemInstanceEntity, ExpressionManager expressionManager,
181-
TaskEntity taskEntity, CreateHumanTaskBeforeContext beforeContext) {
181+
TaskEntity taskEntity, CreateHumanTaskBeforeContext beforeContext, MigrationContext migrationContext) {
182+
183+
String nameStringValue = null;
184+
if (migrationContext != null && migrationContext.getName() != null) {
185+
nameStringValue = migrationContext.getName();
186+
187+
} else if (StringUtils.isNotEmpty(beforeContext.getName())) {
188+
nameStringValue = beforeContext.getName();
189+
}
182190

183-
if (StringUtils.isNotEmpty(beforeContext.getName())) {
184-
Object name = expressionManager.createExpression(beforeContext.getName()).getValue(planItemInstanceEntity);
191+
if (StringUtils.isNotEmpty(nameStringValue)) {
192+
Object name = expressionManager.createExpression(nameStringValue).getValue(planItemInstanceEntity);
185193
if (name != null) {
186194
if (name instanceof String) {
187195
taskEntity.setName((String) name);
@@ -232,10 +240,18 @@ protected void handleAssignee(PlanItemInstanceEntity planItemInstanceEntity, Tas
232240
}
233241

234242
protected void handleOwner(PlanItemInstanceEntity planItemInstanceEntity, TaskService taskService,
235-
ExpressionManager expressionManager, TaskEntity taskEntity, CreateHumanTaskBeforeContext beforeContext) {
243+
ExpressionManager expressionManager, TaskEntity taskEntity, CreateHumanTaskBeforeContext beforeContext, MigrationContext migrationContext) {
244+
245+
String ownerStringValue = null;
246+
if (migrationContext != null && migrationContext.getOwner() != null) {
247+
ownerStringValue = migrationContext.getOwner();
248+
249+
} else if (StringUtils.isNotEmpty(beforeContext.getOwner())) {
250+
ownerStringValue = beforeContext.getOwner();
251+
}
236252

237-
if (StringUtils.isNotEmpty(beforeContext.getOwner())) {
238-
Object ownerExpressionValue = expressionManager.createExpression(beforeContext.getOwner()).getValue(planItemInstanceEntity);
253+
if (StringUtils.isNotEmpty(ownerStringValue)) {
254+
Object ownerExpressionValue = expressionManager.createExpression(ownerStringValue).getValue(planItemInstanceEntity);
239255
String ownerValue = null;
240256
if (ownerExpressionValue != null) {
241257
ownerValue = ownerExpressionValue.toString();
@@ -246,10 +262,18 @@ protected void handleOwner(PlanItemInstanceEntity planItemInstanceEntity, TaskSe
246262
}
247263

248264
protected void handlePriority(PlanItemInstanceEntity planItemInstanceEntity, ExpressionManager expressionManager,
249-
TaskEntity taskEntity, CreateHumanTaskBeforeContext beforeContext) {
265+
TaskEntity taskEntity, CreateHumanTaskBeforeContext beforeContext, MigrationContext migrationContext) {
266+
267+
String priorityStringValue = null;
268+
if (migrationContext != null && migrationContext.getPriority() != null) {
269+
priorityStringValue = migrationContext.getPriority();
270+
271+
} else if (StringUtils.isNotEmpty(beforeContext.getPriority())) {
272+
priorityStringValue = beforeContext.getPriority();
273+
}
250274

251-
if (StringUtils.isNotEmpty(beforeContext.getPriority())) {
252-
Object priority = expressionManager.createExpression(beforeContext.getPriority()).getValue(planItemInstanceEntity);
275+
if (StringUtils.isNotEmpty(priorityStringValue)) {
276+
Object priority = expressionManager.createExpression(priorityStringValue).getValue(planItemInstanceEntity);
253277
if (priority != null) {
254278
if (priority instanceof String) {
255279
try {
@@ -267,10 +291,18 @@ protected void handlePriority(PlanItemInstanceEntity planItemInstanceEntity, Exp
267291
}
268292

269293
protected void handleFormKey(PlanItemInstanceEntity planItemInstanceEntity, ExpressionManager expressionManager,
270-
TaskEntity taskEntity, CreateHumanTaskBeforeContext beforeContext) {
294+
TaskEntity taskEntity, CreateHumanTaskBeforeContext beforeContext, MigrationContext migrationContext) {
271295

272-
if (StringUtils.isNotEmpty(beforeContext.getFormKey())) {
273-
Object formKey = expressionManager.createExpression(beforeContext.getFormKey()).getValue(planItemInstanceEntity);
296+
String formKeyStringValue = null;
297+
if (migrationContext != null && migrationContext.getFormKey() != null) {
298+
formKeyStringValue = migrationContext.getFormKey();
299+
300+
} else if (StringUtils.isNotEmpty(beforeContext.getFormKey())) {
301+
formKeyStringValue = beforeContext.getFormKey();
302+
}
303+
304+
if (StringUtils.isNotEmpty(formKeyStringValue)) {
305+
Object formKey = expressionManager.createExpression(formKeyStringValue).getValue(planItemInstanceEntity);
274306
if (formKey != null) {
275307
if (formKey instanceof String) {
276308
taskEntity.setFormKey((String) formKey);
@@ -282,10 +314,18 @@ protected void handleFormKey(PlanItemInstanceEntity planItemInstanceEntity, Expr
282314
}
283315

284316
protected void handleDueDate(CommandContext commandContext, PlanItemInstanceEntity planItemInstanceEntity,
285-
ExpressionManager expressionManager, TaskEntity taskEntity, CreateHumanTaskBeforeContext beforeContext) {
317+
ExpressionManager expressionManager, TaskEntity taskEntity, CreateHumanTaskBeforeContext beforeContext, MigrationContext migrationContext) {
286318

287-
if (StringUtils.isNotEmpty(beforeContext.getDueDate())) {
288-
Object dueDate = expressionManager.createExpression(beforeContext.getDueDate()).getValue(planItemInstanceEntity);
319+
String dueDateStringValue = null;
320+
if (migrationContext != null && migrationContext.getDueDate() != null) {
321+
dueDateStringValue = migrationContext.getDueDate();
322+
323+
} else if (StringUtils.isNotEmpty(beforeContext.getDueDate())) {
324+
dueDateStringValue = beforeContext.getDueDate();
325+
}
326+
327+
if (StringUtils.isNotEmpty(dueDateStringValue)) {
328+
Object dueDate = expressionManager.createExpression(dueDateStringValue).getValue(planItemInstanceEntity);
289329
if (dueDate != null) {
290330
if (dueDate instanceof Date) {
291331
taskEntity.setDueDate((Date) dueDate);
@@ -313,10 +353,18 @@ protected void handleDueDate(CommandContext commandContext, PlanItemInstanceEnti
313353
}
314354

315355
protected void handleCategory(PlanItemInstanceEntity planItemInstanceEntity, ExpressionManager expressionManager,
316-
TaskEntity taskEntity, CreateHumanTaskBeforeContext beforeContext) {
356+
TaskEntity taskEntity, CreateHumanTaskBeforeContext beforeContext, MigrationContext migrationContext) {
317357

318-
if (StringUtils.isNotEmpty(beforeContext.getCategory())) {
319-
final Object category = expressionManager.createExpression(beforeContext.getCategory()).getValue(planItemInstanceEntity);
358+
String categoryStringValue = null;
359+
if (migrationContext != null && migrationContext.getCategory() != null) {
360+
categoryStringValue = migrationContext.getCategory();
361+
362+
} else if (StringUtils.isNotEmpty(beforeContext.getCategory())) {
363+
categoryStringValue = beforeContext.getCategory();
364+
}
365+
366+
if (StringUtils.isNotEmpty(categoryStringValue)) {
367+
final Object category = expressionManager.createExpression(categoryStringValue).getValue(planItemInstanceEntity);
320368
if (category != null) {
321369
if (category instanceof String) {
322370
taskEntity.setCategory((String) category);
@@ -329,10 +377,18 @@ protected void handleCategory(PlanItemInstanceEntity planItemInstanceEntity, Exp
329377

330378
@SuppressWarnings({ "unchecked", "rawtypes" })
331379
protected void handleCandidateUsers(CommandContext commandContext, PlanItemInstanceEntity planItemInstanceEntity,
332-
ExpressionManager expressionManager, TaskEntity taskEntity, CreateHumanTaskBeforeContext beforeContext) {
380+
ExpressionManager expressionManager, TaskEntity taskEntity, CreateHumanTaskBeforeContext beforeContext, MigrationContext migrationContext) {
333381

334382
CmmnEngineConfiguration cmmnEngineConfiguration = CommandContextUtil.getCmmnEngineConfiguration(commandContext);
335-
List<String> candidateUsers = beforeContext.getCandidateUsers();
383+
384+
List<String> candidateUsers = null;
385+
if (migrationContext != null && migrationContext.getCandidateUsers() != null) {
386+
candidateUsers = migrationContext.getCandidateUsers();
387+
388+
} else if (beforeContext.getCandidateUsers() != null) {
389+
candidateUsers = beforeContext.getCandidateUsers();
390+
}
391+
336392
if (candidateUsers != null && !candidateUsers.isEmpty()) {
337393
List<IdentityLinkEntity> allIdentityLinkEntities = new ArrayList<>();
338394
for (String candidateUser : candidateUsers) {
@@ -360,10 +416,18 @@ protected void handleCandidateUsers(CommandContext commandContext, PlanItemInsta
360416

361417
@SuppressWarnings({ "unchecked", "rawtypes" })
362418
protected void handleCandidateGroups(CommandContext commandContext, PlanItemInstanceEntity planItemInstanceEntity,
363-
ExpressionManager expressionManager, TaskEntity taskEntity, CreateHumanTaskBeforeContext beforeContext) {
419+
ExpressionManager expressionManager, TaskEntity taskEntity, CreateHumanTaskBeforeContext beforeContext, MigrationContext migrationContext) {
364420

365421
CmmnEngineConfiguration cmmnEngineConfiguration = CommandContextUtil.getCmmnEngineConfiguration(commandContext);
366-
List<String> candidateGroups = beforeContext.getCandidateGroups();
422+
423+
List<String> candidateGroups = null;
424+
if (migrationContext != null && migrationContext.getCandidateGroups() != null) {
425+
candidateGroups = migrationContext.getCandidateGroups();
426+
427+
} else if (beforeContext.getCandidateGroups() != null) {
428+
candidateGroups = beforeContext.getCandidateGroups();
429+
}
430+
367431
if (candidateGroups != null && !candidateGroups.isEmpty()) {
368432
List<IdentityLinkEntity> allIdentityLinkEntities = new ArrayList<>();
369433
for (String candidateGroup : candidateGroups) {

modules/flowable-cmmn-engine/src/main/java/org/flowable/cmmn/engine/impl/migration/CaseInstanceMigrationDocumentConstants.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,15 @@ public interface CaseInstanceMigrationDocumentConstants {
2929
String NEW_PLAN_ITEM_ID_JSON_PROPERTY = "newPlanItemId";
3030
String EXISTING_PLAN_ITEM_DEFINITION_ID_JSON_PROPERTY = "existingPlanItemDefinitionId";
3131
String NEW_PLAN_ITEM_DEFINITION_ID_JSON_PROPERTY = "newPlanItemDefinitionId";
32+
String NEW_NAME_JSON_PROPERTY = "newName";
33+
String NEW_DUE_DATE_JSON_PROPERTY = "newDueDate";
34+
String NEW_PRIORITY_JSON_PROPERTY = "newPriority";
35+
String NEW_CATEGORY_JSON_PROPERTY = "newCategory";
36+
String NEW_FORM_KEY_JSON_PROPERTY = "newFormKey";
3237
String NEW_ASSIGNEE_JSON_PROPERTY = "newAssignee";
38+
String NEW_OWNER_JSON_PROPERTY = "newOwner";
39+
String NEW_CANDIDATE_USERS_JSON_PROPERTY = "newCandidateUsers";
40+
String NEW_CANDIDATE_GROUPS_JSON_PROPERTY = "newCandidateGroups";
3341
String CONDITION_JSON_PROPERTY = "condition";
3442

3543
String ACTIVATE_PLAN_ITEM_DEFINITIONS_JSON_SECTION = "activatePlanItemDefinitions";

0 commit comments

Comments
 (0)