From f10aa6c74d86732f53a65b337c16ba1b47469502 Mon Sep 17 00:00:00 2001 From: Valentin Zickner <3200232+vzickner@users.noreply.github.com> Date: Fri, 12 Apr 2024 09:11:27 +0200 Subject: [PATCH] add pre- and post upgrade expressions to migration builder (#3871) --- .../CaseInstanceMigrationBuilderImpl.java | 2 ++ .../migration/CaseInstanceMigrationTest.java | 29 +++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/modules/flowable-cmmn-engine/src/main/java/org/flowable/cmmn/engine/impl/migration/CaseInstanceMigrationBuilderImpl.java b/modules/flowable-cmmn-engine/src/main/java/org/flowable/cmmn/engine/impl/migration/CaseInstanceMigrationBuilderImpl.java index 64356b4245b..ebec190a8eb 100644 --- a/modules/flowable-cmmn-engine/src/main/java/org/flowable/cmmn/engine/impl/migration/CaseInstanceMigrationBuilderImpl.java +++ b/modules/flowable-cmmn-engine/src/main/java/org/flowable/cmmn/engine/impl/migration/CaseInstanceMigrationBuilderImpl.java @@ -52,6 +52,8 @@ public CaseInstanceMigrationBuilder fromCaseInstanceMigrationDocument(CaseInstan this.caseInstanceMigrationDocumentDocumentBuilder.addWaitingForRepetitionPlanItemDefinitionMappings(caseInstanceMigrationDocument.getWaitingForRepetitionPlanItemDefinitionMappings()); this.caseInstanceMigrationDocumentDocumentBuilder.addRemoveWaitingForRepetitionPlanItemDefinitionMappings(caseInstanceMigrationDocument.getRemoveWaitingForRepetitionPlanItemDefinitionMappings()); this.caseInstanceMigrationDocumentDocumentBuilder.addCaseInstanceVariables(caseInstanceMigrationDocument.getCaseInstanceVariables()); + this.caseInstanceMigrationDocumentDocumentBuilder.preUpgradeExpression(caseInstanceMigrationDocument.getPreUpgradeExpression()); + this.caseInstanceMigrationDocumentDocumentBuilder.postUpgradeExpression(caseInstanceMigrationDocument.getPostUpgradeExpression()); return this; } diff --git a/modules/flowable-cmmn-engine/src/test/java/org/flowable/cmmn/test/migration/CaseInstanceMigrationTest.java b/modules/flowable-cmmn-engine/src/test/java/org/flowable/cmmn/test/migration/CaseInstanceMigrationTest.java index 63142feb604..bf5839d9101 100644 --- a/modules/flowable-cmmn-engine/src/test/java/org/flowable/cmmn/test/migration/CaseInstanceMigrationTest.java +++ b/modules/flowable-cmmn-engine/src/test/java/org/flowable/cmmn/test/migration/CaseInstanceMigrationTest.java @@ -13,6 +13,7 @@ package org.flowable.cmmn.test.migration; +import static net.javacrumbs.jsonunit.assertj.JsonAssertions.assertThatJson; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.flowable.cmmn.converter.CmmnXmlConstants.ELEMENT_STAGE; @@ -27,6 +28,7 @@ import org.flowable.cmmn.api.history.HistoricMilestoneInstance; import org.flowable.cmmn.api.history.HistoricPlanItemInstance; 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.PlanItemDefinitionMappingBuilder; @@ -38,6 +40,7 @@ import org.flowable.cmmn.api.runtime.PlanItemInstance; import org.flowable.cmmn.api.runtime.PlanItemInstanceState; import org.flowable.cmmn.api.runtime.UserEventListenerInstance; +import org.flowable.cmmn.engine.impl.migration.CaseInstanceMigrationDocumentConverter; import org.flowable.cmmn.engine.impl.persistence.entity.SentryPartInstanceEntity; import org.flowable.cmmn.engine.test.impl.CmmnHistoryTestHelper; import org.flowable.common.engine.api.FlowableException; @@ -5847,6 +5850,32 @@ void withCaseTaskWhichWillBeTerminated() { assertThat(subcaseInstances).isEqualTo(0); } + @Test + void testCaseInstanceMigrationDocument() { + String documentAsJson = this.cmmnMigrationService.createCaseInstanceMigrationBuilder() + .addTerminatePlanItemDefinitionMapping( + PlanItemDefinitionMappingBuilder.createTerminatePlanItemDefinitionMappingFor("terminateId", "${terminateCondition}")) + .addMoveToAvailablePlanItemDefinitionMapping( + PlanItemDefinitionMappingBuilder.createMoveToAvailablePlanItemDefinitionMappingFor("availableId", "${availableCondition}")) + .addWaitingForRepetitionPlanItemDefinitionMapping( + PlanItemDefinitionMappingBuilder.createWaitingForRepetitionPlanItemDefinitionMappingFor("repetitionId", "${repetitionCondition}")) + .removeWaitingForRepetitionPlanItemDefinitionMapping( + PlanItemDefinitionMappingBuilder.createRemoveWaitingForRepetitionPlanItemDefinitionMappingFor("removeRepetitionId", + "${removeRepetitionCondition}")) + .addActivatePlanItemDefinitionMapping( + PlanItemDefinitionMappingBuilder.createActivatePlanItemDefinitionMappingFor("activateId", "${activateCondition}")) + .withPreUpgradeExpression("${preExpression}") + .withPostUpgradeExpression("${postExpression}") + .getCaseInstanceMigrationDocument() + .asJsonString(); + CaseInstanceMigrationDocument caseInstanceMigrationDocumentFromString = CaseInstanceMigrationDocumentConverter.convertFromJson(documentAsJson); + String documentAsJsonConverted = this.cmmnMigrationService.createCaseInstanceMigrationBuilderFromCaseInstanceMigrationDocument( + caseInstanceMigrationDocumentFromString) + .getCaseInstanceMigrationDocument() + .asJsonString(); + assertThatJson(documentAsJsonConverted).isEqualTo(documentAsJson); + } + protected class CustomTenantProvider implements DefaultTenantProvider { @Override