From fe4502c50f77249c8421502f862624d4b79f1958 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Mon, 16 Sep 2024 23:19:06 +0200 Subject: [PATCH] Do not perform Cmmn Validation on already deployed models This aligns the CmmnDeployer with the BpmnDeployer --- .../engine/impl/deployer/CmmnDeployer.java | 9 +++-- .../cmmn/test/repository/DeploymentTest.java | 35 +++++++++++++++++++ 2 files changed, 41 insertions(+), 3 deletions(-) diff --git a/modules/flowable-cmmn-engine/src/main/java/org/flowable/cmmn/engine/impl/deployer/CmmnDeployer.java b/modules/flowable-cmmn-engine/src/main/java/org/flowable/cmmn/engine/impl/deployer/CmmnDeployer.java index 8acaae42066..6c537faf103 100644 --- a/modules/flowable-cmmn-engine/src/main/java/org/flowable/cmmn/engine/impl/deployer/CmmnDeployer.java +++ b/modules/flowable-cmmn-engine/src/main/java/org/flowable/cmmn/engine/impl/deployer/CmmnDeployer.java @@ -86,7 +86,7 @@ public void deploy(EngineDeployment deployment, Map deploymentSe for (EngineResource resource : deployment.getResources().values()) { if (isCmmnResource(resource.getName())) { LOGGER.debug("Processing CMMN resource {}", resource.getName()); - parseResult.merge(cmmnParser.parse(new CmmnParseContextImpl(resource))); + parseResult.merge(cmmnParser.parse(new CmmnParseContextImpl(resource, deployment.isNew()))); } } @@ -407,9 +407,11 @@ public void setUsePrefixId(boolean usePrefixId) { protected class CmmnParseContextImpl implements CmmnParseContext { protected final EngineResource resource; + protected final boolean newDeployment; - public CmmnParseContextImpl(EngineResource resource) { + public CmmnParseContextImpl(EngineResource resource, boolean newDeployment) { this.resource = resource; + this.newDeployment = newDeployment; } @Override @@ -434,7 +436,8 @@ public boolean validateXml() { @Override public boolean validateCmmnModel() { - return validateXml(); + // On redeploy, we assume it is validated at the first deploy + return newDeployment && validateXml(); } @Override diff --git a/modules/flowable-cmmn-engine/src/test/java/org/flowable/cmmn/test/repository/DeploymentTest.java b/modules/flowable-cmmn-engine/src/test/java/org/flowable/cmmn/test/repository/DeploymentTest.java index 79be64a6e93..68abfca2be5 100644 --- a/modules/flowable-cmmn-engine/src/test/java/org/flowable/cmmn/test/repository/DeploymentTest.java +++ b/modules/flowable-cmmn-engine/src/test/java/org/flowable/cmmn/test/repository/DeploymentTest.java @@ -26,6 +26,8 @@ import org.flowable.cmmn.engine.test.FlowableCmmnTestCase; import org.flowable.cmmn.model.CmmnModel; import org.flowable.cmmn.model.PlanItem; +import org.flowable.cmmn.validation.CaseValidator; +import org.flowable.cmmn.validation.CaseValidatorImpl; import org.flowable.common.engine.api.FlowableException; import org.flowable.common.engine.impl.persistence.deploy.DefaultDeploymentCache; import org.flowable.common.engine.impl.persistence.deploy.DeploymentCache; @@ -191,6 +193,39 @@ public void deployingCaseModelWithErrorsShouldFail() { assertThat(cmmnRepositoryService.createCaseDefinitionQuery().list()).isEmpty(); } + @Test + public void alreadyDeployedCaseModelWithErrorsShouldNotFail() { + CaseValidator originalValidator = cmmnEngineConfiguration.getCaseValidator(); + + try { + // We disable all the validations so we can test this + cmmnEngineConfiguration.setCaseValidator(new CaseValidatorImpl()); + + org.flowable.cmmn.api.repository.CmmnDeployment cmmnDeployment = cmmnRepositoryService.createDeployment() + .addClasspathResource("org/flowable/cmmn/test/repository/DeploymentTest.testCaseDefinitionWithErrors.cmmn") + .deploy(); + autoCleanupDeploymentIds.add(cmmnDeployment.getId()); + CaseDefinition caseDefinition = cmmnRepositoryService.createCaseDefinitionQuery() + .caseDefinitionKey("myCase") + .singleResult(); + assertThat(caseDefinition).isNotNull(); + + cmmnEngineConfiguration.setCaseValidator(originalValidator); + + // remove it from the cache to force parsing it again + cmmnEngineConfiguration.getDeploymentManager() + .getCaseDefinitionCache() + .clear(); + + CmmnModel cmmnModel = cmmnRepositoryService.getCmmnModel(caseDefinition.getId()); + + assertThat(cmmnModel).isNotNull(); + + } finally { + cmmnEngineConfiguration.setCaseValidator(originalValidator); + } + } + @Test public void deployingCaseModelWithWarningsShouldNotFail() { org.flowable.cmmn.api.repository.CmmnDeployment deployment = null;