Search in sources :

Example 6 with MigrationInstruction

use of org.camunda.bpm.engine.migration.MigrationInstruction in project camunda-bpm-platform by camunda.

the class CreateMigrationPlanCmd method wrapMigrationInstructions.

protected ValidatingMigrationInstructions wrapMigrationInstructions(MigrationPlan migrationPlan, ProcessDefinitionImpl sourceProcessDefinition, ProcessDefinitionImpl targetProcessDefinition, MigrationPlanValidationReportImpl planReport) {
    ValidatingMigrationInstructions validatingMigrationInstructions = new ValidatingMigrationInstructions();
    for (MigrationInstruction migrationInstruction : migrationPlan.getInstructions()) {
        MigrationInstructionValidationReportImpl instructionReport = new MigrationInstructionValidationReportImpl(migrationInstruction);
        String sourceActivityId = migrationInstruction.getSourceActivityId();
        String targetActivityId = migrationInstruction.getTargetActivityId();
        if (sourceActivityId != null && targetActivityId != null) {
            ActivityImpl sourceActivity = sourceProcessDefinition.findActivity(sourceActivityId);
            ActivityImpl targetActivity = targetProcessDefinition.findActivity(migrationInstruction.getTargetActivityId());
            if (sourceActivity != null && targetActivity != null) {
                validatingMigrationInstructions.addInstruction(new ValidatingMigrationInstructionImpl(sourceActivity, targetActivity, migrationInstruction.isUpdateEventTrigger()));
            } else {
                if (sourceActivity == null) {
                    instructionReport.addFailure("Source activity '" + sourceActivityId + "' does not exist");
                }
                if (targetActivity == null) {
                    instructionReport.addFailure("Target activity '" + targetActivityId + "' does not exist");
                }
            }
        } else {
            if (sourceActivityId == null) {
                instructionReport.addFailure("Source activity id is null");
            }
            if (targetActivityId == null) {
                instructionReport.addFailure("Target activity id is null");
            }
        }
        if (instructionReport.hasFailures()) {
            planReport.addInstructionReport(instructionReport);
        }
    }
    return validatingMigrationInstructions;
}
Also used : MigrationInstructionValidationReportImpl(org.camunda.bpm.engine.impl.migration.validation.instruction.MigrationInstructionValidationReportImpl) ActivityImpl(org.camunda.bpm.engine.impl.pvm.process.ActivityImpl) MigrationInstruction(org.camunda.bpm.engine.migration.MigrationInstruction) ValidatingMigrationInstruction(org.camunda.bpm.engine.impl.migration.validation.instruction.ValidatingMigrationInstruction) ValidatingMigrationInstructionImpl(org.camunda.bpm.engine.impl.migration.validation.instruction.ValidatingMigrationInstructionImpl) ValidatingMigrationInstructions(org.camunda.bpm.engine.impl.migration.validation.instruction.ValidatingMigrationInstructions)

Example 7 with MigrationInstruction

use of org.camunda.bpm.engine.migration.MigrationInstruction in project camunda-bpm-platform by camunda.

the class MigrationExternalTaskTest method testProcessDefinitionWithIdField.

@Test
@Deployment(resources = { "org/camunda/bpm/engine/test/api/externaltask/ExternalTaskWithoutIdTest.bpmn" })
public void testProcessDefinitionWithIdField() {
    // given
    ProcessDefinition sourceProcessDefinition = testHelper.deploy("org/camunda/bpm/engine/test/api/externaltask/ExternalTaskWithIdTest.bpmn").getDeployedProcessDefinitions().get(0);
    ProcessDefinition targetProcessDefinition = testHelper.deploy("org/camunda/bpm/engine/test/api/externaltask/ExternalTaskWithIdTest.bpmn").getDeployedProcessDefinitions().get(0);
    // external task is not mapped to new external task
    MigrationPlan migrationPlan = rule.getRuntimeService().createMigrationPlan(sourceProcessDefinition.getId(), targetProcessDefinition.getId()).mapEqualActivities().build();
    List<MigrationInstruction> instructions = migrationPlan.getInstructions();
    assertEquals(2, instructions.size());
}
Also used : MigrationInstruction(org.camunda.bpm.engine.migration.MigrationInstruction) MigrationPlan(org.camunda.bpm.engine.migration.MigrationPlan) ProcessDefinition(org.camunda.bpm.engine.repository.ProcessDefinition) Test(org.junit.Test) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 8 with MigrationInstruction

use of org.camunda.bpm.engine.migration.MigrationInstruction in project camunda-bpm-platform by camunda.

the class ActivityInstanceHandler method handle.

@Override
public void handle(MigratingInstanceParseContext parseContext, ActivityInstance element) {
    MigratingActivityInstance migratingInstance = null;
    MigrationInstruction applyingInstruction = parseContext.getInstructionFor(element.getActivityId());
    ScopeImpl sourceScope = null;
    ScopeImpl targetScope = null;
    ExecutionEntity representativeExecution = parseContext.getMapping().getExecution(element);
    if (element.getId().equals(element.getProcessInstanceId())) {
        sourceScope = parseContext.getSourceProcessDefinition();
        targetScope = parseContext.getTargetProcessDefinition();
    } else {
        sourceScope = parseContext.getSourceProcessDefinition().findActivity(element.getActivityId());
        if (applyingInstruction != null) {
            String activityId = applyingInstruction.getTargetActivityId();
            targetScope = parseContext.getTargetProcessDefinition().findActivity(activityId);
        }
    }
    migratingInstance = parseContext.getMigratingProcessInstance().addActivityInstance(applyingInstruction, element, sourceScope, targetScope, representativeExecution);
    MigratingActivityInstance parentInstance = parseContext.getMigratingActivityInstanceById(element.getParentActivityInstanceId());
    if (parentInstance != null) {
        migratingInstance.setParent(parentInstance);
    }
    CoreActivityBehavior<?> sourceActivityBehavior = sourceScope.getActivityBehavior();
    if (sourceActivityBehavior instanceof MigrationObserverBehavior) {
        ((MigrationObserverBehavior) sourceActivityBehavior).onParseMigratingInstance(parseContext, migratingInstance);
    }
    parseContext.submit(migratingInstance);
    parseTransitionInstances(parseContext, migratingInstance);
    parseDependentInstances(parseContext, migratingInstance);
}
Also used : ExecutionEntity(org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity) MigrationInstruction(org.camunda.bpm.engine.migration.MigrationInstruction) MigrationObserverBehavior(org.camunda.bpm.engine.impl.pvm.delegate.MigrationObserverBehavior) MigratingActivityInstance(org.camunda.bpm.engine.impl.migration.instance.MigratingActivityInstance) ScopeImpl(org.camunda.bpm.engine.impl.pvm.process.ScopeImpl)

Example 9 with MigrationInstruction

use of org.camunda.bpm.engine.migration.MigrationInstruction in project camunda-bpm-platform by camunda.

the class CompensationInstanceHandler method createMigratingEventScopeInstance.

protected MigratingProcessElementInstance createMigratingEventScopeInstance(MigratingInstanceParseContext parseContext, EventSubscriptionEntity element) {
    ActivityImpl compensatingActivity = parseContext.getSourceProcessDefinition().findActivity(element.getActivityId());
    MigrationInstruction migrationInstruction = getMigrationInstruction(parseContext, compensatingActivity);
    ActivityImpl eventSubscriptionTargetScope = null;
    if (migrationInstruction != null) {
        if (compensatingActivity.isCompensationHandler()) {
            ActivityImpl targetEventScope = (ActivityImpl) parseContext.getTargetActivity(migrationInstruction).getEventScope();
            eventSubscriptionTargetScope = targetEventScope.findCompensationHandler();
        } else {
            eventSubscriptionTargetScope = parseContext.getTargetActivity(migrationInstruction);
        }
    }
    ExecutionEntity eventScopeExecution = CompensationUtil.getCompensatingExecution(element);
    MigrationInstruction eventScopeInstruction = parseContext.findSingleMigrationInstruction(eventScopeExecution.getActivityId());
    ActivityImpl targetScope = parseContext.getTargetActivity(eventScopeInstruction);
    MigratingEventScopeInstance migratingCompensationInstance = parseContext.getMigratingProcessInstance().addEventScopeInstance(eventScopeInstruction, eventScopeExecution, eventScopeExecution.getActivity(), targetScope, migrationInstruction, element, compensatingActivity, eventSubscriptionTargetScope);
    parseContext.consume(element);
    parseContext.submit(migratingCompensationInstance);
    parseDependentEntities(parseContext, migratingCompensationInstance);
    return migratingCompensationInstance;
}
Also used : ActivityImpl(org.camunda.bpm.engine.impl.pvm.process.ActivityImpl) ExecutionEntity(org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity) MigrationInstruction(org.camunda.bpm.engine.migration.MigrationInstruction) MigratingEventScopeInstance(org.camunda.bpm.engine.impl.migration.instance.MigratingEventScopeInstance)

Example 10 with MigrationInstruction

use of org.camunda.bpm.engine.migration.MigrationInstruction in project camunda-bpm-platform by camunda.

the class ActivityInstanceJobHandler method handle.

@Override
public void handle(MigratingInstanceParseContext parseContext, MigratingActivityInstance activityInstance, List<JobEntity> elements) {
    Map<String, TimerDeclarationImpl> timerDeclarationsInEventScope = getTimerDeclarationsByTriggeringActivity(activityInstance.getTargetScope());
    for (JobEntity job : elements) {
        if (!isTimerJob(job)) {
            // skip non timer jobs
            continue;
        }
        MigrationInstruction migrationInstruction = parseContext.findSingleMigrationInstruction(job.getActivityId());
        ActivityImpl targetActivity = parseContext.getTargetActivity(migrationInstruction);
        if (targetActivity != null && activityInstance.migratesTo(targetActivity.getEventScope())) {
            // the timer job is migrated
            JobDefinitionEntity targetJobDefinitionEntity = parseContext.getTargetJobDefinition(targetActivity.getActivityId(), job.getJobHandlerType());
            TimerDeclarationImpl targetTimerDeclaration = timerDeclarationsInEventScope.remove(targetActivity.getId());
            MigratingJobInstance migratingTimerJobInstance = new MigratingTimerJobInstance(job, targetJobDefinitionEntity, targetActivity, migrationInstruction.isUpdateEventTrigger(), targetTimerDeclaration);
            activityInstance.addMigratingDependentInstance(migratingTimerJobInstance);
            parseContext.submit(migratingTimerJobInstance);
        } else {
            // the timer job is removed
            MigratingJobInstance removingJobInstance = new MigratingTimerJobInstance(job);
            activityInstance.addRemovingDependentInstance(removingJobInstance);
            parseContext.submit(removingJobInstance);
        }
        parseContext.consume(job);
    }
    if (activityInstance.migrates()) {
        addEmergingTimerJobs(activityInstance, timerDeclarationsInEventScope.values());
    }
}
Also used : JobEntity(org.camunda.bpm.engine.impl.persistence.entity.JobEntity) TimerDeclarationImpl(org.camunda.bpm.engine.impl.jobexecutor.TimerDeclarationImpl) JobDefinitionEntity(org.camunda.bpm.engine.impl.persistence.entity.JobDefinitionEntity) ActivityImpl(org.camunda.bpm.engine.impl.pvm.process.ActivityImpl) MigrationInstruction(org.camunda.bpm.engine.migration.MigrationInstruction) MigratingJobInstance(org.camunda.bpm.engine.impl.migration.instance.MigratingJobInstance) MigratingTimerJobInstance(org.camunda.bpm.engine.impl.migration.instance.MigratingTimerJobInstance)

Aggregations

MigrationInstruction (org.camunda.bpm.engine.migration.MigrationInstruction)18 Test (org.junit.Test)6 ActivityImpl (org.camunda.bpm.engine.impl.pvm.process.ActivityImpl)5 Matchers.anyString (org.mockito.Matchers.anyString)4 ArrayList (java.util.ArrayList)3 ExecutionEntity (org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity)3 MigrationInstructionValidationReport (org.camunda.bpm.engine.migration.MigrationInstructionValidationReport)3 MigrationPlanValidationException (org.camunda.bpm.engine.migration.MigrationPlanValidationException)3 MigrationPlanValidationReport (org.camunda.bpm.engine.migration.MigrationPlanValidationReport)3 MigrationExecutionDtoBuilder (org.camunda.bpm.engine.rest.util.migration.MigrationExecutionDtoBuilder)3 MigratingActivityInstance (org.camunda.bpm.engine.impl.migration.instance.MigratingActivityInstance)2 ValidatingMigrationInstruction (org.camunda.bpm.engine.impl.migration.validation.instruction.ValidatingMigrationInstruction)2 JobEntity (org.camunda.bpm.engine.impl.persistence.entity.JobEntity)2 ScopeImpl (org.camunda.bpm.engine.impl.pvm.process.ScopeImpl)2 MigrationPlan (org.camunda.bpm.engine.migration.MigrationPlan)2 ProcessDefinition (org.camunda.bpm.engine.repository.ProcessDefinition)2 Deployment (org.camunda.bpm.engine.test.Deployment)2 EventSubscriptionDeclaration (org.camunda.bpm.engine.impl.bpmn.parser.EventSubscriptionDeclaration)1 TimerDeclarationImpl (org.camunda.bpm.engine.impl.jobexecutor.TimerDeclarationImpl)1 MigrationPlanImpl (org.camunda.bpm.engine.impl.migration.MigrationPlanImpl)1