Skip to content

Commit

Permalink
Add support for migrating historic case instances
Browse files Browse the repository at this point in the history
  • Loading branch information
tijsrademakers committed Aug 24, 2023
1 parent cd6ca22 commit bc5c13e
Show file tree
Hide file tree
Showing 23 changed files with 1,691 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,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.HistoricCaseInstanceMigrationBuilder;
import org.flowable.cmmn.api.migration.HistoricCaseInstanceMigrationDocument;

/**
* Service to manager case instance migrations.
Expand All @@ -29,6 +31,10 @@ public interface CmmnMigrationService {
CaseInstanceMigrationBuilder createCaseInstanceMigrationBuilder();

CaseInstanceMigrationBuilder createCaseInstanceMigrationBuilderFromCaseInstanceMigrationDocument(CaseInstanceMigrationDocument document);

HistoricCaseInstanceMigrationBuilder createHistoricCaseInstanceMigrationBuilder();

HistoricCaseInstanceMigrationBuilder createHistoricCaseInstanceMigrationBuilderFromHistoricCaseInstanceMigrationDocument(HistoricCaseInstanceMigrationDocument document);

CaseInstanceMigrationValidationResult validateMigrationForCaseInstance(String caseInstanceId, CaseInstanceMigrationDocument caseInstanceMigrationDocument);

Expand All @@ -37,14 +43,24 @@ public interface CmmnMigrationService {
CaseInstanceMigrationValidationResult validateMigrationForCaseInstancesOfCaseDefinition(String caseDefinitionKey, int caseDefinitionVersion, String caseDefinitionTenantId, CaseInstanceMigrationDocument caseInstanceMigrationDocument);

void migrateCaseInstance(String caseInstanceId, CaseInstanceMigrationDocument caseInstanceMigrationDocument);

void migrateHistoricCaseInstance(String caseInstanceId, HistoricCaseInstanceMigrationDocument historicCaseInstanceMigrationDocument);

void migrateCaseInstancesOfCaseDefinition(String caseDefinitionId, CaseInstanceMigrationDocument caseInstanceMigrationDocument);

void migrateHistoricCaseInstancesOfCaseDefinition(String caseDefinitionId, HistoricCaseInstanceMigrationDocument historicCaseInstanceMigrationDocument);

void migrateCaseInstancesOfCaseDefinition(String caseDefinitionKey, int caseDefinitionVersion, String caseDefinitionTenantId, CaseInstanceMigrationDocument caseInstanceMigrationDocument);

void migrateHistoricCaseInstancesOfCaseDefinition(String caseDefinitionKey, int caseDefinitionVersion, String caseDefinitionTenantId, HistoricCaseInstanceMigrationDocument historicCaseInstanceMigrationDocument);

Batch batchMigrateCaseInstancesOfCaseDefinition(String caseDefinitionId, CaseInstanceMigrationDocument caseInstanceMigrationDocument);

Batch batchMigrateHistoricCaseInstancesOfCaseDefinition(String caseDefinitionId, HistoricCaseInstanceMigrationDocument historicCaseInstanceMigrationDocument);

Batch batchMigrateCaseInstancesOfCaseDefinition(String caseDefinitionKey, int caseDefinitionVersion, String caseDefinitionTenantId, CaseInstanceMigrationDocument caseInstanceMigrationDocument);

Batch batchMigrateHistoricCaseInstancesOfCaseDefinition(String caseDefinitionKey, int caseDefinitionVersion, String caseDefinitionTenantId, HistoricCaseInstanceMigrationDocument historicCaseInstanceMigrationDocument);

CaseInstanceBatchMigrationResult getResultsOfBatchCaseInstanceMigration(String migrationBatchId);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,14 @@
*/
package org.flowable.cmmn.api.migration;

import org.flowable.cmmn.api.history.HistoricCaseInstance;
import org.flowable.cmmn.api.repository.CaseDefinition;
import org.flowable.cmmn.api.runtime.CaseInstance;

public interface CaseInstanceMigrationCallback {

void caseInstanceMigrated(CaseInstance caseInstance, CaseDefinition caseDefToMigrateTo, CaseInstanceMigrationDocument document);

void historicCaseInstanceMigrated(HistoricCaseInstance caseInstance, CaseDefinition caseDefToMigrateTo, HistoricCaseInstanceMigrationDocument document);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
/* 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;

import org.flowable.batch.api.Batch;

public interface HistoricCaseInstanceMigrationBuilder {

/**
* Creates a HistoricCaseInstanceMigrationBuilder using the values of a HistoricCaseInstanceMigrationDocument
*
* @param historicCaseInstanceMigrationDocument Migration document with pre-filled case information
* @return Returns the builder
* @see HistoricCaseInstanceMigrationDocument
*/
HistoricCaseInstanceMigrationBuilder fromHistoricCaseInstanceMigrationDocument(HistoricCaseInstanceMigrationDocument caseInstanceMigrationDocument);

/**
* Specifies the case definition to migrate to, using the case definition id
*
* @param caseDefinitionId ID of the case definition to migrate to
* @return Returns the builder
* @see org.flowable.cmmn.api.repository.CaseDefinition
*/
HistoricCaseInstanceMigrationBuilder migrateToCaseDefinition(String caseDefinitionId);

/**
* Specifies the case definition to migrate to, identified by its key and version
*
* @param caseDefinitionKey Key of the case definition to migrate to
* @param caseDefinitionVersion Version of the case to migrate to
* @return Returns the builder
* @see org.flowable.cmmn.api.repository.CaseDefinition
*/
HistoricCaseInstanceMigrationBuilder migrateToCaseDefinition(String caseDefinitionKey, int caseDefinitionVersion);

/**
* Specifies the case definition to migrate to, identified by its key and version and tenantId
*
* @param caseDefinitionKey Key of the case definition to migrate to
* @param caseDefinitionVersion Version of the case to migrate to
* @param caseDefinitionTenantId Tenant id of the case definition, must be part of the same tenant
* @return Returns the builder
* @see org.flowable.cmmn.api.repository.CaseDefinition
*/
HistoricCaseInstanceMigrationBuilder migrateToCaseDefinition(String caseDefinitionKey, int caseDefinitionVersion, String caseDefinitionTenantId);

/**
* Specifies the tenantId of the case definition to migrate to
*
* @param caseDefinitionTenantId Tenant id of the case definition, must be part of the same tenant
* @return Returns the builder
*/
HistoricCaseInstanceMigrationBuilder withMigrateToCaseDefinitionTenantId(String caseDefinitionTenantId);

/**
* Builds a HistoricCaseInstanceMigrationDocument
*
* @return Returns the builder
* @see HistoricCaseInstanceMigrationDocument
*/
HistoricCaseInstanceMigrationDocument getHistoricCaseInstanceMigrationDocument();

/**
* Starts the case instance migration for a case identified with the submitted caseInstanceId
*
* @param caseInstanceId
*/
void migrate(String caseInstanceId);

/**
* Asynchronously starts the case instance migration for each case instances of a given case definition identified by the case definition id.
*
* @param caseDefinitionId
*/
void migrateHistoricCaseInstances(String caseDefinitionId);

/**
* Starts the case instance migration for all case instances of a given case definition identified by the case definition id.
*
* @param caseDefinitionId
*/
Batch batchMigrateHistoricCaseInstances(String caseDefinitionId);

/**
* Starts the case instance migration for all case instances of a given case definition identified by the case definition key and version (optional tenantId).
*
* @param caseDefinitionKey
* @param caseDefinitionVersion
* @param caseDefinitionTenantId
*/
void migrateHistoricCaseInstances(String caseDefinitionKey, int caseDefinitionVersion, String caseDefinitionTenantId);

/**
* Asynchronously starts the case instance migration for each case instances of a given case definition identified by the case definition key and version (optional tenantId).
*
* @param caseDefinitionKey
* @param caseDefinitionVersion
* @param caseDefinitionTenantId
* @return an id of the created batch entity
*/
Batch batchMigrateHistoricCaseInstances(String caseDefinitionKey, int caseDefinitionVersion, String caseDefinitionTenantId);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/* 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 interface HistoricCaseInstanceMigrationDocument {

String getMigrateToCaseDefinitionId();

String getMigrateToCaseDefinitionKey();

Integer getMigrateToCaseDefinitionVersion();

String getMigrateToCaseDefinitionTenantId();

String asJsonString();

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/* 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 interface HistoricCaseInstanceMigrationDocumentBuilder {

HistoricCaseInstanceMigrationDocumentBuilder setCaseDefinitionToMigrateTo(String caseDefinitionId);

HistoricCaseInstanceMigrationDocumentBuilder setCaseDefinitionToMigrateTo(String caseDefinitionKey, Integer caseDefinitionVersion);

HistoricCaseInstanceMigrationDocumentBuilder setTenantId(String caseDefinitionTenantId);

HistoricCaseInstanceMigrationDocument build();

}
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@
import org.flowable.cmmn.engine.impl.job.CaseInstanceMigrationStatusJobHandler;
import org.flowable.cmmn.engine.impl.job.CmmnHistoryCleanupJobHandler;
import org.flowable.cmmn.engine.impl.job.ExternalWorkerTaskCompleteJobHandler;
import org.flowable.cmmn.engine.impl.job.HistoricCaseInstanceMigrationJobHandler;
import org.flowable.cmmn.engine.impl.job.TriggerTimerEventJobHandler;
import org.flowable.cmmn.engine.impl.listener.CmmnListenerFactory;
import org.flowable.cmmn.engine.impl.listener.CmmnListenerNotificationHelper;
Expand Down Expand Up @@ -1645,6 +1646,7 @@ public void initJobHandlers() {
jobHandlers.put(ExternalWorkerTaskCompleteJobHandler.TYPE, new ExternalWorkerTaskCompleteJobHandler(this));
addJobHandler(new CaseInstanceMigrationJobHandler());
addJobHandler(new CaseInstanceMigrationStatusJobHandler());
addJobHandler(new HistoricCaseInstanceMigrationJobHandler());
addJobHandler(new ComputeDeleteHistoricCaseInstanceIdsJobHandler());
addJobHandler(new ComputeDeleteHistoricCaseInstanceStatusJobHandler());
addJobHandler(new DeleteHistoricCaseInstanceIdsJobHandler());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/* 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.engine.impl.cmd;

import org.flowable.batch.api.Batch;
import org.flowable.cmmn.api.migration.HistoricCaseInstanceMigrationDocument;
import org.flowable.cmmn.engine.CmmnEngineConfiguration;
import org.flowable.cmmn.engine.impl.migration.CaseInstanceMigrationManager;
import org.flowable.common.engine.api.FlowableException;
import org.flowable.common.engine.impl.interceptor.Command;
import org.flowable.common.engine.impl.interceptor.CommandContext;

public class HistoricCaseInstanceMigrationBatchCmd implements Command<Batch> {

protected CmmnEngineConfiguration cmmnEngineConfiguration;

protected String caseDefinitionId;
protected String caseDefinitionKey;
protected int caseDefinitionVersion;
protected String caseDefinitionTenantId;
protected HistoricCaseInstanceMigrationDocument historicCaseInstanceMigrationDocument;

public HistoricCaseInstanceMigrationBatchCmd(HistoricCaseInstanceMigrationDocument historicCaseInstanceMigrationDocument, String caseDefinitionId,
CmmnEngineConfiguration cmmnEngineConfiguration) {

if (caseDefinitionId == null) {
throw new FlowableException("Must specify a case definition id to migrate");
}
if (historicCaseInstanceMigrationDocument == null) {
throw new FlowableException("Must specify a historic case instance migration document to migrate");
}
this.caseDefinitionId = caseDefinitionId;
this.historicCaseInstanceMigrationDocument = historicCaseInstanceMigrationDocument;
this.cmmnEngineConfiguration = cmmnEngineConfiguration;
}

public HistoricCaseInstanceMigrationBatchCmd(String caseDefinitionKey, int caseDefinitionVersion, String caseDefinitionTenantId,
HistoricCaseInstanceMigrationDocument historicCaseInstanceMigrationDocument, CmmnEngineConfiguration cmmnEngineConfiguration) {

if (caseDefinitionKey == null) {
throw new FlowableException("Must specify a case definition id to migrate");
}
if (caseDefinitionTenantId == null) {
throw new FlowableException("Must specify a case definition tenant id to migrate");
}
if (historicCaseInstanceMigrationDocument == null) {
throw new FlowableException("Must specify a historic case instance migration document to migrate");
}
this.caseDefinitionKey = caseDefinitionKey;
this.caseDefinitionVersion = caseDefinitionVersion;
this.caseDefinitionTenantId = caseDefinitionTenantId;
this.historicCaseInstanceMigrationDocument = historicCaseInstanceMigrationDocument;
this.cmmnEngineConfiguration = cmmnEngineConfiguration;
}

@Override
public Batch execute(CommandContext commandContext) {
CaseInstanceMigrationManager migrationManager = cmmnEngineConfiguration.getCaseInstanceMigrationManager();

if (caseDefinitionId != null) {
return migrationManager.batchMigrateHistoricCaseInstancesOfCaseDefinition(caseDefinitionId, historicCaseInstanceMigrationDocument, commandContext);
} else if (caseDefinitionKey != null && caseDefinitionVersion >= 0) {
return migrationManager.batchMigrateHistoricCaseInstancesOfCaseDefinition(caseDefinitionKey, caseDefinitionVersion, caseDefinitionTenantId,
historicCaseInstanceMigrationDocument, commandContext);
} else {
throw new FlowableException("Cannot migrate historic case instances, not enough information");
}
}
}
Loading

0 comments on commit bc5c13e

Please sign in to comment.