Skip to content

Commit

Permalink
Add support for plan item id mapping for case instance migration
Browse files Browse the repository at this point in the history
  • Loading branch information
tijsrademakers committed Sep 6, 2023
1 parent 687d8a3 commit a07632a
Show file tree
Hide file tree
Showing 27 changed files with 1,162 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,26 @@ public interface CaseInstanceMigrationBuilder {
* @see WaitingForRepetitionPlanItemDefinitionMapping
*/
CaseInstanceMigrationBuilder removeWaitingForRepetitionPlanItemDefinitionMapping(RemoveWaitingForRepetitionPlanItemDefinitionMapping mapping);

/**
* Adds a mapping for a plan item id to new plan item id. This should not be needed in general, but there are cases where the plan item can have a new plan item id
* between different versions, and that's why this option is added.
*
* @param mapping Mapping from an existing plan item id to a new plan item id
* @return Returns the builder
* @see ChangePlanItemIdMapping
*/
CaseInstanceMigrationBuilder addChangePlanItemIdMapping(ChangePlanItemIdMapping mapping);

/**
* Adds a mapping for a plan item definition id to a new plan item definition id to change the plan item id. This should not be needed in general,
* but there are cases where the plan item can have a new plan item id between different versions, and that's why this option is added.
*
* @param mapping Mapping from an existing plan item definition id to a new plan item definition id to change the plan item id
* @return Returns the builder
* @see ChangePlanItemIdWithDefinitionIdMapping
*/
CaseInstanceMigrationBuilder addChangePlanItemIdWithDefinitionIdMapping(ChangePlanItemIdWithDefinitionIdMapping mapping);

/**
* Specifies a case instance variable that will also be available during the case migration
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ public interface CaseInstanceMigrationDocument {
List<WaitingForRepetitionPlanItemDefinitionMapping> getWaitingForRepetitionPlanItemDefinitionMappings();

List<RemoveWaitingForRepetitionPlanItemDefinitionMapping> getRemoveWaitingForRepetitionPlanItemDefinitionMappings();

List<ChangePlanItemIdMapping> getChangePlanItemIdMappings();

List<ChangePlanItemIdWithDefinitionIdMapping> getChangePlanItemIdWithDefinitionIdMappings();

Map<String, Map<String, Object>> getPlanItemLocalVariables();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ public interface CaseInstanceMigrationDocumentBuilder {

CaseInstanceMigrationDocumentBuilder addRemoveWaitingForRepetitionPlanItemDefinitionMapping(RemoveWaitingForRepetitionPlanItemDefinitionMapping planItemDefinitionMapping);

CaseInstanceMigrationDocumentBuilder addChangePlanItemIdMapping(ChangePlanItemIdMapping mapping);

CaseInstanceMigrationDocumentBuilder addChangePlanItemIdWithDefinitionIdMapping(ChangePlanItemIdWithDefinitionIdMapping mapping);

CaseInstanceMigrationDocumentBuilder addCaseInstanceVariable(String variableName, Object variableValue);

CaseInstanceMigrationDocumentBuilder addCaseInstanceVariables(Map<String, Object> caseInstanceVariables);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.flowable.cmmn.api.migration;

public class ChangePlanItemIdMapping {

protected String existingPlanItemId;
protected String newPlanItemId;

public ChangePlanItemIdMapping(String existingPlanItemId, String newPlanItemId) {
this.existingPlanItemId = existingPlanItemId;
this.newPlanItemId = newPlanItemId;
}

public String getExistingPlanItemId() {
return existingPlanItemId;
}

public void setExistingPlanItemId(String existingPlanItemId) {
this.existingPlanItemId = existingPlanItemId;
}

public String getNewPlanItemId() {
return newPlanItemId;
}

public void setNewPlanItemId(String newPlanItemId) {
this.newPlanItemId = newPlanItemId;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.flowable.cmmn.api.migration;

public class ChangePlanItemIdWithDefinitionIdMapping {

protected String existingPlanItemDefinitionId;
protected String newPlanItemDefinitionId;

public ChangePlanItemIdWithDefinitionIdMapping(String existingPlanItemDefinitionId, String newPlanItemDefinitionId) {
this.existingPlanItemDefinitionId = existingPlanItemDefinitionId;
this.newPlanItemDefinitionId = newPlanItemDefinitionId;
}

public String getExistingPlanItemDefinitionId() {
return existingPlanItemDefinitionId;
}

public void setExistingPlanItemDefinitionId(String existingPlanItemDefinitionId) {
this.existingPlanItemDefinitionId = existingPlanItemDefinitionId;
}

public String getNewPlanItemDefinitionId() {
return newPlanItemDefinitionId;
}

public void setNewPlanItemDefinitionId(String newPlanItemDefinitionId) {
this.newPlanItemDefinitionId = newPlanItemDefinitionId;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,30 @@ public interface ChangePlanItemStateBuilder {
*/
ChangePlanItemStateBuilder removeWaitingForRepetitionPlanItemDefinitionIds(List<String> planItemDefinitionIds);

/**
* Add plan item id mapping. This should not be needed in general, but there are cases where the existing plan item id
* is different from the new plan item id, and for this reason this option is provided.
*/
ChangePlanItemStateBuilder changePlanItemId(String existingPlanItemId, String newPlanItemId);

/**
* Add plan item id mapping. This should not be needed in general, but there are cases where the existing plan item id
* is different from the new plan item id, and for this reason this option is provided.
*/
ChangePlanItemStateBuilder changePlanItemIds(Map<String, String> changePlanItemIdMap);

/**
* Add plan item id mapping with definition id. This should not be needed in general, but there are cases where the existing plan item id
* is different from the new plan item id, and for this reason this option is provided.
*/
ChangePlanItemStateBuilder changePlanItemIdWithDefinitionId(String existingPlanItemDefinitionId, String newPlanItemDefinitionId);

/**
* Add plan item id mapping with definition id. This should not be needed in general, but there are cases where the existing plan item id
* is different from the new plan item id, and for this reason this option is provided.
*/
ChangePlanItemStateBuilder changePlanItemIdsWithDefinitionId(Map<String, String> changePlanItemIdWithDefinitionIdMap);

/**
* Set the case variable that should be set as part of the change plan item state action.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,7 @@ public void recordPlanItemInstanceUpdated(PlanItemInstanceEntity planItemInstanc
HistoricPlanItemInstanceEntity historicPlanItemInstanceEntity = historicPlanItemInstanceEntityManager.findById(planItemInstanceEntity.getId());
if (historicPlanItemInstanceEntity != null) {
historicPlanItemInstanceEntity.setFormKey(planItemInstanceEntity.getFormKey());
historicPlanItemInstanceEntity.setElementId(planItemInstanceEntity.getElementId());
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
import org.flowable.cmmn.api.migration.CaseInstanceMigrationBuilder;
import org.flowable.cmmn.api.migration.CaseInstanceMigrationDocument;
import org.flowable.cmmn.api.migration.CaseInstanceMigrationValidationResult;
import org.flowable.cmmn.api.migration.ChangePlanItemIdMapping;
import org.flowable.cmmn.api.migration.ChangePlanItemIdWithDefinitionIdMapping;
import org.flowable.cmmn.api.migration.MoveToAvailablePlanItemDefinitionMapping;
import org.flowable.cmmn.api.migration.RemoveWaitingForRepetitionPlanItemDefinitionMapping;
import org.flowable.cmmn.api.migration.TerminatePlanItemDefinitionMapping;
Expand Down Expand Up @@ -107,6 +109,18 @@ public CaseInstanceMigrationBuilder removeWaitingForRepetitionPlanItemDefinition
this.caseInstanceMigrationDocumentDocumentBuilder.addRemoveWaitingForRepetitionPlanItemDefinitionMapping(mapping);
return this;
}

@Override
public CaseInstanceMigrationBuilder addChangePlanItemIdMapping(ChangePlanItemIdMapping mapping) {
this.caseInstanceMigrationDocumentDocumentBuilder.addChangePlanItemIdMapping(mapping);
return this;
}

@Override
public CaseInstanceMigrationBuilder addChangePlanItemIdWithDefinitionIdMapping(ChangePlanItemIdWithDefinitionIdMapping mapping) {
this.caseInstanceMigrationDocumentDocumentBuilder.addChangePlanItemIdWithDefinitionIdMapping(mapping);
return this;
}

@Override
public CaseInstanceMigrationBuilder withCaseInstanceVariable(String variableName, Object variableValue) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
import org.flowable.cmmn.api.migration.ActivatePlanItemDefinitionMapping;
import org.flowable.cmmn.api.migration.CaseInstanceMigrationDocument;
import org.flowable.cmmn.api.migration.CaseInstanceMigrationDocumentBuilder;
import org.flowable.cmmn.api.migration.ChangePlanItemIdMapping;
import org.flowable.cmmn.api.migration.ChangePlanItemIdWithDefinitionIdMapping;
import org.flowable.cmmn.api.migration.MoveToAvailablePlanItemDefinitionMapping;
import org.flowable.cmmn.api.migration.RemoveWaitingForRepetitionPlanItemDefinitionMapping;
import org.flowable.cmmn.api.migration.TerminatePlanItemDefinitionMapping;
Expand All @@ -40,6 +42,8 @@ public class CaseInstanceMigrationDocumentBuilderImpl implements CaseInstanceMig
protected List<MoveToAvailablePlanItemDefinitionMapping> moveToAvailablePlanItemDefinitionMappings = new ArrayList<>();
protected List<WaitingForRepetitionPlanItemDefinitionMapping> waitingForRepetitionPlanItemDefinitionMappings = new ArrayList<>();
protected List<RemoveWaitingForRepetitionPlanItemDefinitionMapping> removeWaitingForRepetitionPlanItemDefinitionMappings = new ArrayList<>();
protected List<ChangePlanItemIdMapping> changePlanItemIdMappings = new ArrayList<>();
protected List<ChangePlanItemIdWithDefinitionIdMapping> changePlanItemIdWithDefinitionIdMappings = new ArrayList<>();
protected Map<String, Object> caseInstanceVariables = new HashMap<>();

@Override
Expand Down Expand Up @@ -120,6 +124,18 @@ public CaseInstanceMigrationDocumentBuilder addRemoveWaitingForRepetitionPlanIte
this.removeWaitingForRepetitionPlanItemDefinitionMappings.add(planItemDefinitionMapping);
return this;
}

@Override
public CaseInstanceMigrationDocumentBuilder addChangePlanItemIdMapping(ChangePlanItemIdMapping mapping) {
this.changePlanItemIdMappings.add(mapping);
return this;
}

@Override
public CaseInstanceMigrationDocumentBuilder addChangePlanItemIdWithDefinitionIdMapping(ChangePlanItemIdWithDefinitionIdMapping mapping) {
this.changePlanItemIdWithDefinitionIdMappings.add(mapping);
return this;
}

@Override
public CaseInstanceMigrationDocumentBuilder addCaseInstanceVariable(String variableName, Object variableValue) {
Expand All @@ -143,6 +159,8 @@ public CaseInstanceMigrationDocument build() {
caseInstanceMigrationDocument.setMoveToAvailablePlanItemDefinitionMappings(this.moveToAvailablePlanItemDefinitionMappings);
caseInstanceMigrationDocument.setWaitingForRepetitionPlanItemDefinitionMappings(this.waitingForRepetitionPlanItemDefinitionMappings);
caseInstanceMigrationDocument.setRemoveWaitingForRepetitionPlanItemDefinitionMappings(this.removeWaitingForRepetitionPlanItemDefinitionMappings);
caseInstanceMigrationDocument.setChangePlanItemIdMappings(this.changePlanItemIdMappings);
caseInstanceMigrationDocument.setChangePlanItemIdWithDefinitionIdMappings(this.changePlanItemIdWithDefinitionIdMappings);
caseInstanceMigrationDocument.setCaseInstanceVariables(this.caseInstanceVariables);
return caseInstanceMigrationDocument;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,19 @@ public interface CaseInstanceMigrationDocumentConstants {
String TO_CASE_DEFINITION_TENANT_ID_JSON_PROPERTY = "toCaseDefinitionTenantId";

String PLAN_ITEM_DEFINITION_ID_JSON_PROPERTY = "planItemDefinitionId";
String EXISTING_PLAN_ITEM_ID_JSON_PROPERTY = "existingPlanItemId";
String NEW_PLAN_ITEM_ID_JSON_PROPERTY = "newPlanItemId";
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 ACTIVATE_PLAN_ITEM_DEFINITIONS_JSON_SECTION = "activatePlanItemDefinitions";
String TERMINATE_PLAN_ITEM_DEFINITIONS_JSON_SECTION = "terminatePlanItemDefinitions";
String MOVE_TO_AVAILABLE_PLAN_ITEM_DEFINITIONS_JSON_SECTION = "moveToAvailablePlanItemDefinitions";
String WAITING_FOR_REPETITION_PLAN_ITEM_DEFINITIONS_JSON_SECTION = "waitingForRepetitionPlanItemDefinitions";
String REMOVE_WAITING_FOR_REPETITION_PLAN_ITEM_DEFINITIONS_JSON_SECTION = "removeWaitingForRepetitionPlanItemDefinitions";
String CHANGE_PLAN_ITEM_IDS_JSON_SECTION = "changePlanItemIds";
String CHANGE_PLAN_ITEM_IDS_WITH_DEFINITION_ID_JSON_SECTION = "changePlanItemIdsWithDefinitionId";
String LOCAL_VARIABLES_JSON_SECTION = "localVariables";
String CASE_INSTANCE_VARIABLES_JSON_SECTION = "caseInstanceVariables";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@

import org.flowable.cmmn.api.migration.ActivatePlanItemDefinitionMapping;
import org.flowable.cmmn.api.migration.CaseInstanceMigrationDocument;
import org.flowable.cmmn.api.migration.ChangePlanItemIdMapping;
import org.flowable.cmmn.api.migration.ChangePlanItemIdWithDefinitionIdMapping;
import org.flowable.cmmn.api.migration.MoveToAvailablePlanItemDefinitionMapping;
import org.flowable.cmmn.api.migration.RemoveWaitingForRepetitionPlanItemDefinitionMapping;
import org.flowable.cmmn.api.migration.TerminatePlanItemDefinitionMapping;
Expand Down Expand Up @@ -87,7 +89,17 @@ public static JsonNode convertToJson(CaseInstanceMigrationDocument caseInstanceM
if (removeWaitingForRepetitionMappingNodes != null && !removeWaitingForRepetitionMappingNodes.isNull()) {
documentNode.set(REMOVE_WAITING_FOR_REPETITION_PLAN_ITEM_DEFINITIONS_JSON_SECTION, removeWaitingForRepetitionMappingNodes);
}


ArrayNode changePlanItemIdMappingNodes = convertToJsonChangePlanItemIdMappings(caseInstanceMigrationDocument.getChangePlanItemIdMappings());
if (changePlanItemIdMappingNodes != null && !changePlanItemIdMappingNodes.isNull()) {
documentNode.set(CHANGE_PLAN_ITEM_IDS_JSON_SECTION, changePlanItemIdMappingNodes);
}

ArrayNode changePlanItemIdWithDefinitionIdMappingNodes = convertToJsonChangePlanItemIdWithDefinitionIdMappings(caseInstanceMigrationDocument.getChangePlanItemIdWithDefinitionIdMappings());
if (changePlanItemIdWithDefinitionIdMappingNodes != null && !changePlanItemIdWithDefinitionIdMappingNodes.isNull()) {
documentNode.set(CHANGE_PLAN_ITEM_IDS_WITH_DEFINITION_ID_JSON_SECTION, changePlanItemIdWithDefinitionIdMappingNodes);
}

JsonNode caseInstanceVariablesNode = convertToJsonCaseInstanceVariables(caseInstanceMigrationDocument, objectMapper);
if (caseInstanceVariablesNode != null && !caseInstanceVariablesNode.isNull()) {
documentNode.set(CASE_INSTANCE_VARIABLES_JSON_SECTION, caseInstanceVariablesNode);
Expand Down Expand Up @@ -166,6 +178,32 @@ protected static ArrayNode convertToJsonRemoveWaitingForRepetitionPlanItemDefini

return mappingsArray;
}

protected static ArrayNode convertToJsonChangePlanItemIdMappings(List<ChangePlanItemIdMapping> planItemIdMappings) {
ArrayNode mappingsArray = objectMapper.createArrayNode();

for (ChangePlanItemIdMapping mapping : planItemIdMappings) {
ObjectNode mappingNode = objectMapper.createObjectNode();
mappingNode.put(EXISTING_PLAN_ITEM_ID_JSON_PROPERTY, mapping.getExistingPlanItemId());
mappingNode.put(NEW_PLAN_ITEM_ID_JSON_PROPERTY, mapping.getNewPlanItemId());
mappingsArray.add(mappingNode);
}

return mappingsArray;
}

protected static ArrayNode convertToJsonChangePlanItemIdWithDefinitionIdMappings(List<ChangePlanItemIdWithDefinitionIdMapping> definitionIdMappings) {
ArrayNode mappingsArray = objectMapper.createArrayNode();

for (ChangePlanItemIdWithDefinitionIdMapping mapping : definitionIdMappings) {
ObjectNode mappingNode = objectMapper.createObjectNode();
mappingNode.put(EXISTING_PLAN_ITEM_DEFINITION_ID_JSON_PROPERTY, mapping.getExistingPlanItemDefinitionId());
mappingNode.put(NEW_PLAN_ITEM_DEFINITION_ID_JSON_PROPERTY, mapping.getNewPlanItemDefinitionId());
mappingsArray.add(mappingNode);
}

return mappingsArray;
}

public static CaseInstanceMigrationDocument convertFromJson(String jsonCaseInstanceMigrationDocument) {

Expand Down Expand Up @@ -228,6 +266,26 @@ public static CaseInstanceMigrationDocument convertFromJson(String jsonCaseInsta
documentBuilder.addRemoveWaitingForRepetitionPlanItemDefinitionMapping(removeWaitingForRepetitionDefinitionMapping);
}
}

JsonNode changePlanItemIdMappingNodes = rootNode.get(CHANGE_PLAN_ITEM_IDS_JSON_SECTION);
if (changePlanItemIdMappingNodes != null) {
for (JsonNode mappingNode : changePlanItemIdMappingNodes) {
String existingPlanItemId = getJsonProperty(EXISTING_PLAN_ITEM_ID_JSON_PROPERTY, mappingNode);
String newPlanItemId = getJsonProperty(NEW_PLAN_ITEM_ID_JSON_PROPERTY, mappingNode);
ChangePlanItemIdMapping changePlanItemIdMapping = new ChangePlanItemIdMapping(existingPlanItemId, newPlanItemId);
documentBuilder.addChangePlanItemIdMapping(changePlanItemIdMapping);
}
}

JsonNode changePlanItemIdWithDefinitionIdMappingNodes = rootNode.get(CHANGE_PLAN_ITEM_IDS_WITH_DEFINITION_ID_JSON_SECTION);
if (changePlanItemIdWithDefinitionIdMappingNodes != null) {
for (JsonNode mappingNode : changePlanItemIdWithDefinitionIdMappingNodes) {
String existingPlanItemDefinitionId = getJsonProperty(EXISTING_PLAN_ITEM_DEFINITION_ID_JSON_PROPERTY, mappingNode);
String newPlanItemDefinitionId = getJsonProperty(NEW_PLAN_ITEM_DEFINITION_ID_JSON_PROPERTY, mappingNode);
ChangePlanItemIdWithDefinitionIdMapping changePlanItemIdWithDefinitionIdMapping = new ChangePlanItemIdWithDefinitionIdMapping(existingPlanItemDefinitionId, newPlanItemDefinitionId);
documentBuilder.addChangePlanItemIdWithDefinitionIdMapping(changePlanItemIdWithDefinitionIdMapping);
}
}

JsonNode caseInstanceVariablesNode = rootNode.get(CASE_INSTANCE_VARIABLES_JSON_SECTION);
if (caseInstanceVariablesNode != null) {
Expand Down
Loading

0 comments on commit a07632a

Please sign in to comment.