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;
}
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());
}
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);
}
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;
}
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());
}
}
Aggregations