Skip to content

Commit

Permalink
add condition attribute for case migration mappings (flowable#3855)
Browse files Browse the repository at this point in the history
* add condition attribute for case migration mappings

* implement plan item instance level condition evaluation for terminate and wait_for_repetition case instance migration

* implement plan item instance level condition evaluation for remove wait_for_repetition case instance migration

* implement plan item instance level condition evaluation for activate plan item definition during case instance migration

* implement plan item instance level condition evaluation for move to available during case instance migration
  • Loading branch information
vzickner authored Apr 4, 2024
1 parent 411d645 commit ab035a5
Show file tree
Hide file tree
Showing 24 changed files with 1,394 additions and 51 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,16 @@ public ActivatePlanItemDefinitionMapping(String planItemDefinitionId) {
super(planItemDefinitionId);
}

public ActivatePlanItemDefinitionMapping(String planItemDefinitionId, String condition) {
super(planItemDefinitionId, condition);
}

public ActivatePlanItemDefinitionMapping(String planItemDefinitionId, String newAssignee, String condition, Map<String, Object> withLocalVariables) {
super(planItemDefinitionId, condition);
this.newAssignee = newAssignee;
this.withLocalVariables = withLocalVariables;
}

public String getNewAssignee() {
return newAssignee;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ public MoveToAvailablePlanItemDefinitionMapping(String planItemDefinitionId, Map
this.withLocalVariables = withLocalVariables;
}

public MoveToAvailablePlanItemDefinitionMapping(String planItemDefinitionId, String condition) {
super(planItemDefinitionId, condition);
}

public Map<String, Object> getWithLocalVariables() {
return withLocalVariables;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,30 @@
public abstract class PlanItemDefinitionMapping {

protected String planItemDefinitionId;
protected String condition;

public PlanItemDefinitionMapping(String planItemDefinitionId) {
this.planItemDefinitionId = planItemDefinitionId;
}

public PlanItemDefinitionMapping(String planItemDefinitionId, String condition) {
this.planItemDefinitionId = planItemDefinitionId;
this.condition = condition;
}

public String getPlanItemDefinitionId() {
return planItemDefinitionId;
}

public void setPlanItemDefinitionId(String planItemDefinitionId) {
this.planItemDefinitionId = planItemDefinitionId;
}

public String getCondition() {
return condition;
}

public void setCondition(String condition) {
this.condition = condition;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,27 @@ public static ActivatePlanItemDefinitionMapping createActivatePlanItemDefinition

return new ActivatePlanItemDefinitionMapping(planItemDefinitionId, newAssignee, withLocalVariables);
}


public static ActivatePlanItemDefinitionMapping createActivatePlanItemDefinitionMappingFor(String planItemDefinitionId, String condition) {
return new ActivatePlanItemDefinitionMapping(planItemDefinitionId, condition);
}

public static TerminatePlanItemDefinitionMapping createTerminatePlanItemDefinitionMappingFor(String planItemDefinitionId) {
return new TerminatePlanItemDefinitionMapping(planItemDefinitionId);
}


public static TerminatePlanItemDefinitionMapping createTerminatePlanItemDefinitionMappingFor(String planItemDefinitionId, String condition) {
return new TerminatePlanItemDefinitionMapping(planItemDefinitionId, condition);
}

public static MoveToAvailablePlanItemDefinitionMapping createMoveToAvailablePlanItemDefinitionMappingFor(String planItemDefinitionId) {
return new MoveToAvailablePlanItemDefinitionMapping(planItemDefinitionId);
}


public static MoveToAvailablePlanItemDefinitionMapping createMoveToAvailablePlanItemDefinitionMappingFor(String planItemDefinitionId, String condition) {
return new MoveToAvailablePlanItemDefinitionMapping(planItemDefinitionId, condition);
}

public static MoveToAvailablePlanItemDefinitionMapping createMoveToAvailablePlanItemDefinitionMappingFor(
String planItemDefinitionId, Map<String, Object> withLocalVariables) {

Expand All @@ -47,8 +59,16 @@ public static MoveToAvailablePlanItemDefinitionMapping createMoveToAvailablePlan
public static WaitingForRepetitionPlanItemDefinitionMapping createWaitingForRepetitionPlanItemDefinitionMappingFor(String planItemDefinitionId) {
return new WaitingForRepetitionPlanItemDefinitionMapping(planItemDefinitionId);
}


public static WaitingForRepetitionPlanItemDefinitionMapping createWaitingForRepetitionPlanItemDefinitionMappingFor(String planItemDefinitionId, String condition) {
return new WaitingForRepetitionPlanItemDefinitionMapping(planItemDefinitionId, condition);
}

public static RemoveWaitingForRepetitionPlanItemDefinitionMapping createRemoveWaitingForRepetitionPlanItemDefinitionMappingFor(String planItemDefinitionId) {
return new RemoveWaitingForRepetitionPlanItemDefinitionMapping(planItemDefinitionId);
}

public static RemoveWaitingForRepetitionPlanItemDefinitionMapping createRemoveWaitingForRepetitionPlanItemDefinitionMappingFor(String planItemDefinitionId, String condition) {
return new RemoveWaitingForRepetitionPlanItemDefinitionMapping(planItemDefinitionId, condition);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,8 @@ public class RemoveWaitingForRepetitionPlanItemDefinitionMapping extends PlanIte
public RemoveWaitingForRepetitionPlanItemDefinitionMapping(String planItemDefinitionId) {
super(planItemDefinitionId);
}

public RemoveWaitingForRepetitionPlanItemDefinitionMapping(String planItemDefinitionId, String condition) {
super(planItemDefinitionId, condition);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,8 @@ public class TerminatePlanItemDefinitionMapping extends PlanItemDefinitionMappin
public TerminatePlanItemDefinitionMapping(String planItemDefinitionId) {
super(planItemDefinitionId);
}

public TerminatePlanItemDefinitionMapping(String planItemDefinitionId, String condition) {
super(planItemDefinitionId, condition);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,8 @@ public class WaitingForRepetitionPlanItemDefinitionMapping extends PlanItemDefin
public WaitingForRepetitionPlanItemDefinitionMapping(String planItemDefinitionId) {
super(planItemDefinitionId);
}

public WaitingForRepetitionPlanItemDefinitionMapping(String planItemDefinitionId, String condition) {
super(planItemDefinitionId, condition);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@

import org.flowable.cmmn.api.migration.ActivatePlanItemDefinitionMapping;
import org.flowable.cmmn.api.migration.MoveToAvailablePlanItemDefinitionMapping;
import org.flowable.cmmn.api.migration.RemoveWaitingForRepetitionPlanItemDefinitionMapping;
import org.flowable.cmmn.api.migration.TerminatePlanItemDefinitionMapping;
import org.flowable.cmmn.api.migration.WaitingForRepetitionPlanItemDefinitionMapping;
import org.flowable.common.engine.api.FlowableException;
import org.flowable.common.engine.api.FlowableObjectNotFoundException;

Expand Down Expand Up @@ -73,7 +76,12 @@ public interface ChangePlanItemStateBuilder {
* Terminate a plan item by definition id without terminating another plan item instance.
*/
ChangePlanItemStateBuilder terminatePlanItemDefinitionId(String planItemDefinitionId);


/**
* Terminate a plan item by definition mapping without terminating another plan item instance.
*/
ChangePlanItemStateBuilder terminatePlanItemDefinition(TerminatePlanItemDefinitionMapping planItemDefinition);

/**
* Terminate multiple plan items by definition id without terminating another plan item instance.
*/
Expand All @@ -84,6 +92,11 @@ public interface ChangePlanItemStateBuilder {
*/
ChangePlanItemStateBuilder addWaitingForRepetitionPlanItemDefinitionId(String planItemDefinitionId);

/**
* Add waiting for repetition to a plan item by definition mapping.
*/
ChangePlanItemStateBuilder addWaitingForRepetitionPlanItemDefinition(WaitingForRepetitionPlanItemDefinitionMapping planItemDefinitionMapping);

/**
* Add multiple waiting for repetitions to a plan item by definition id.
*/
Expand All @@ -94,6 +107,11 @@ public interface ChangePlanItemStateBuilder {
*/
ChangePlanItemStateBuilder removeWaitingForRepetitionPlanItemDefinitionId(String planItemDefinitionId);

/**
* Remove waiting for repetition from a plan item by definition.
*/
ChangePlanItemStateBuilder removeWaitingForRepetitionPlanItemDefinition(RemoveWaitingForRepetitionPlanItemDefinitionMapping planItemDefinitionId);

/**
* Remove multiple waiting for repetitions from a plan item by definition id.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ public int count() {
return planItemInstances.size();
}

public boolean exists() {
return count() > 0;
}

protected void ensurePlanItemInstanceInitialized() {
if (planItemInstances == null) {
planItemInstances = collectAllChildPlanItemInstances(caseInstanceEntity);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public interface CaseInstanceMigrationDocumentConstants {
String EXISTING_PLAN_ITEM_DEFINITION_ID_JSON_PROPERTY = "existingPlanItemDefinitionId";
String NEW_PLAN_ITEM_DEFINITION_ID_JSON_PROPERTY = "newPlanItemDefinitionId";
String NEW_ASSIGNEE_JSON_PROPERTY = "newAssignee";
String CONDITION_JSON_PROPERTY = "condition";

String ACTIVATE_PLAN_ITEM_DEFINITIONS_JSON_SECTION = "activatePlanItemDefinitions";
String TERMINATE_PLAN_ITEM_DEFINITIONS_JSON_SECTION = "terminatePlanItemDefinitions";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ protected static ArrayNode convertToJsonActivatePlanItemDefinitionMappings(List<
ObjectNode mappingNode = objectMapper.createObjectNode();
mappingNode.put(PLAN_ITEM_DEFINITION_ID_JSON_PROPERTY, mapping.getPlanItemDefinitionId());
mappingNode.put(NEW_ASSIGNEE_JSON_PROPERTY, mapping.getNewAssignee());
mappingNode.put(CONDITION_JSON_PROPERTY, mapping.getCondition());
mappingsArray.add(mappingNode);
}

Expand All @@ -145,6 +146,7 @@ protected static ArrayNode convertToJsonTerminatePlanItemDefinitionMappings(List
for (TerminatePlanItemDefinitionMapping mapping : planItemDefinitionMappings) {
ObjectNode mappingNode = objectMapper.createObjectNode();
mappingNode.put(PLAN_ITEM_DEFINITION_ID_JSON_PROPERTY, mapping.getPlanItemDefinitionId());
mappingNode.put(CONDITION_JSON_PROPERTY, mapping.getCondition());
mappingsArray.add(mappingNode);
}

Expand All @@ -157,6 +159,7 @@ protected static ArrayNode convertToJsonMoveToAvailablePlanItemDefinitionMapping
for (MoveToAvailablePlanItemDefinitionMapping mapping : planItemDefinitionMappings) {
ObjectNode mappingNode = objectMapper.createObjectNode();
mappingNode.put(PLAN_ITEM_DEFINITION_ID_JSON_PROPERTY, mapping.getPlanItemDefinitionId());
mappingNode.put(CONDITION_JSON_PROPERTY, mapping.getCondition());
mappingsArray.add(mappingNode);
}

Expand All @@ -169,6 +172,7 @@ protected static ArrayNode convertToJsonWaitingForRepetitionPlanItemDefinitionMa
for (WaitingForRepetitionPlanItemDefinitionMapping mapping : planItemDefinitionMappings) {
ObjectNode mappingNode = objectMapper.createObjectNode();
mappingNode.put(PLAN_ITEM_DEFINITION_ID_JSON_PROPERTY, mapping.getPlanItemDefinitionId());
mappingNode.put(CONDITION_JSON_PROPERTY, mapping.getCondition());
mappingsArray.add(mappingNode);
}

Expand All @@ -181,6 +185,7 @@ protected static ArrayNode convertToJsonRemoveWaitingForRepetitionPlanItemDefini
for (RemoveWaitingForRepetitionPlanItemDefinitionMapping mapping : planItemDefinitionMappings) {
ObjectNode mappingNode = objectMapper.createObjectNode();
mappingNode.put(PLAN_ITEM_DEFINITION_ID_JSON_PROPERTY, mapping.getPlanItemDefinitionId());
mappingNode.put(CONDITION_JSON_PROPERTY, mapping.getCondition());
mappingsArray.add(mappingNode);
}

Expand Down Expand Up @@ -234,6 +239,8 @@ public static CaseInstanceMigrationDocument convertFromJson(String jsonCaseInsta
ActivatePlanItemDefinitionMapping activateDefinitionMapping = new ActivatePlanItemDefinitionMapping(planItemDefinitionId);
String newAssginee = getJsonProperty(NEW_ASSIGNEE_JSON_PROPERTY, mappingNode);
activateDefinitionMapping.setNewAssignee(newAssginee);
String condition = getJsonProperty(CONDITION_JSON_PROPERTY, mappingNode);
activateDefinitionMapping.setCondition(condition);

documentBuilder.addActivatePlanItemDefinitionMapping(activateDefinitionMapping);
}
Expand All @@ -244,6 +251,8 @@ public static CaseInstanceMigrationDocument convertFromJson(String jsonCaseInsta
for (JsonNode mappingNode : terminateMappingNodes) {
String planItemDefinitionId = getJsonProperty(PLAN_ITEM_DEFINITION_ID_JSON_PROPERTY, mappingNode);
TerminatePlanItemDefinitionMapping terminateDefinitionMapping = new TerminatePlanItemDefinitionMapping(planItemDefinitionId);
String condition = getJsonProperty(CONDITION_JSON_PROPERTY, mappingNode);
terminateDefinitionMapping.setCondition(condition);
documentBuilder.addTerminatePlanItemDefinitionMapping(terminateDefinitionMapping);
}
}
Expand All @@ -253,6 +262,8 @@ public static CaseInstanceMigrationDocument convertFromJson(String jsonCaseInsta
for (JsonNode mappingNode : moveToAvailableMappingNodes) {
String planItemDefinitionId = getJsonProperty(PLAN_ITEM_DEFINITION_ID_JSON_PROPERTY, mappingNode);
MoveToAvailablePlanItemDefinitionMapping moveToAvailableDefinitionMapping = new MoveToAvailablePlanItemDefinitionMapping(planItemDefinitionId);
String condition = getJsonProperty(CONDITION_JSON_PROPERTY, mappingNode);
moveToAvailableDefinitionMapping.setCondition(condition);
documentBuilder.addMoveToAvailablePlanItemDefinitionMapping(moveToAvailableDefinitionMapping);
}
}
Expand All @@ -262,6 +273,8 @@ public static CaseInstanceMigrationDocument convertFromJson(String jsonCaseInsta
for (JsonNode mappingNode : waitingForRepetitionMappingNodes) {
String planItemDefinitionId = getJsonProperty(PLAN_ITEM_DEFINITION_ID_JSON_PROPERTY, mappingNode);
WaitingForRepetitionPlanItemDefinitionMapping waitingForRepetitionDefinitionMapping = new WaitingForRepetitionPlanItemDefinitionMapping(planItemDefinitionId);
String condition = getJsonProperty(CONDITION_JSON_PROPERTY, mappingNode);
waitingForRepetitionDefinitionMapping.setCondition(condition);
documentBuilder.addWaitingForRepetitionPlanItemDefinitionMapping(waitingForRepetitionDefinitionMapping);
}
}
Expand All @@ -271,6 +284,8 @@ public static CaseInstanceMigrationDocument convertFromJson(String jsonCaseInsta
for (JsonNode mappingNode : removeWaitingForRepetitionMappingNodes) {
String planItemDefinitionId = getJsonProperty(PLAN_ITEM_DEFINITION_ID_JSON_PROPERTY, mappingNode);
RemoveWaitingForRepetitionPlanItemDefinitionMapping removeWaitingForRepetitionDefinitionMapping = new RemoveWaitingForRepetitionPlanItemDefinitionMapping(planItemDefinitionId);
String condition = getJsonProperty(CONDITION_JSON_PROPERTY, mappingNode);
removeWaitingForRepetitionDefinitionMapping.setCondition(condition);
documentBuilder.addRemoveWaitingForRepetitionPlanItemDefinitionMapping(removeWaitingForRepetitionDefinitionMapping);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@
package org.flowable.cmmn.engine.impl.migration;

import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;

import org.flowable.batch.api.Batch;
import org.flowable.batch.api.BatchPart;
Expand Down Expand Up @@ -302,7 +304,7 @@ protected void doMigrateCaseInstance(CaseInstanceEntity caseInstance, CaseDefini
cmmnEngineConfiguration.getExpressionManager().createExpression(document.getPostUpgradeExpression()).getValue(caseInstance);
}
}

protected void doMigrateHistoricCaseInstance(HistoricCaseInstanceEntity historicCaseInstance, CaseDefinition caseDefinitionToMigrateTo, HistoricCaseInstanceMigrationDocument document, CommandContext commandContext) {
LOGGER.debug("Start migration of historic case instance with Id:'{}' to case definition identified by {}", historicCaseInstance.getId(), printCaseDefinitionIdentifierMessage(document));

Expand Down Expand Up @@ -367,19 +369,19 @@ protected ChangePlanItemStateBuilderImpl prepareChangeStateBuilder(CaseInstance
}

for (TerminatePlanItemDefinitionMapping planItemDefinitionMapping : document.getTerminatePlanItemDefinitionMappings()) {
changePlanItemStateBuilder.terminatePlanItemDefinitionId(planItemDefinitionMapping.getPlanItemDefinitionId());
changePlanItemStateBuilder.terminatePlanItemDefinition(planItemDefinitionMapping);
}

for (MoveToAvailablePlanItemDefinitionMapping planItemDefinitionMapping : document.getMoveToAvailablePlanItemDefinitionMappings()) {
changePlanItemStateBuilder.changeToAvailableStateByPlanItemDefinition(planItemDefinitionMapping);
}

for (WaitingForRepetitionPlanItemDefinitionMapping planItemDefinitionMapping : document.getWaitingForRepetitionPlanItemDefinitionMappings()) {
changePlanItemStateBuilder.addWaitingForRepetitionPlanItemDefinitionId(planItemDefinitionMapping.getPlanItemDefinitionId());
changePlanItemStateBuilder.addWaitingForRepetitionPlanItemDefinition(planItemDefinitionMapping);
}

for (RemoveWaitingForRepetitionPlanItemDefinitionMapping planItemDefinitionMapping : document.getRemoveWaitingForRepetitionPlanItemDefinitionMappings()) {
changePlanItemStateBuilder.removeWaitingForRepetitionPlanItemDefinitionId(planItemDefinitionMapping.getPlanItemDefinitionId());
changePlanItemStateBuilder.removeWaitingForRepetitionPlanItemDefinition(planItemDefinitionMapping);
}

for (ChangePlanItemIdMapping changePlanItemIdMapping : document.getChangePlanItemIdMappings()) {
Expand Down
Loading

0 comments on commit ab035a5

Please sign in to comment.