Search in sources :

Example 1 with ExternalTaskEntity

use of org.camunda.bpm.engine.impl.persistence.entity.ExternalTaskEntity in project camunda-bpm-platform by camunda.

the class FetchExternalTasksCmd method execute.

@Override
public List<LockedExternalTask> execute(CommandContext commandContext) {
    validateInput();
    for (TopicFetchInstruction instruction : fetchInstructions.values()) {
        instruction.ensureVariablesInitialized();
    }
    List<ExternalTaskEntity> externalTasks = commandContext.getExternalTaskManager().selectExternalTasksForTopics(fetchInstructions.values(), filterByBusinessKey, maxResults, usePriority);
    final List<LockedExternalTask> result = new ArrayList<LockedExternalTask>();
    for (ExternalTaskEntity entity : externalTasks) {
        TopicFetchInstruction fetchInstruction = fetchInstructions.get(entity.getTopicName());
        entity.lock(workerId, fetchInstruction.getLockDuration());
        LockedExternalTaskImpl resultTask = LockedExternalTaskImpl.fromEntity(entity, fetchInstruction.getVariablesToFetch(), fetchInstruction.isDeserializeVariables());
        result.add(resultTask);
    }
    filterOnOptimisticLockingFailure(commandContext, result);
    return result;
}
Also used : ExternalTaskEntity(org.camunda.bpm.engine.impl.persistence.entity.ExternalTaskEntity) LockedExternalTaskImpl(org.camunda.bpm.engine.impl.externaltask.LockedExternalTaskImpl) TopicFetchInstruction(org.camunda.bpm.engine.impl.externaltask.TopicFetchInstruction) LockedExternalTask(org.camunda.bpm.engine.externaltask.LockedExternalTask)

Example 2 with ExternalTaskEntity

use of org.camunda.bpm.engine.impl.persistence.entity.ExternalTaskEntity in project camunda-bpm-platform by camunda.

the class ExternalTaskActivityBehavior method onParseMigratingInstance.

@Override
public void onParseMigratingInstance(MigratingInstanceParseContext parseContext, MigratingActivityInstance migratingInstance) {
    ExecutionEntity execution = migratingInstance.resolveRepresentativeExecution();
    for (ExternalTaskEntity task : execution.getExternalTasks()) {
        MigratingExternalTaskInstance migratingTask = new MigratingExternalTaskInstance(task, migratingInstance);
        migratingInstance.addMigratingDependentInstance(migratingTask);
        parseContext.consume(task);
        parseContext.submit(migratingTask);
    }
}
Also used : ExternalTaskEntity(org.camunda.bpm.engine.impl.persistence.entity.ExternalTaskEntity) ExecutionEntity(org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity) MigratingExternalTaskInstance(org.camunda.bpm.engine.impl.migration.instance.MigratingExternalTaskInstance)

Example 3 with ExternalTaskEntity

use of org.camunda.bpm.engine.impl.persistence.entity.ExternalTaskEntity in project camunda-bpm-platform by camunda.

the class GetExternalTaskErrorDetailsCmd method execute.

public String execute(CommandContext commandContext) {
    ensureNotNull("externalTaskId", externalTaskId);
    ExternalTaskEntity externalTask = commandContext.getExternalTaskManager().findExternalTaskById(externalTaskId);
    ensureNotNull("No external task found with id " + externalTaskId, "externalTask", externalTask);
    for (CommandChecker checker : commandContext.getProcessEngineConfiguration().getCommandCheckers()) {
        checker.checkReadProcessInstance(externalTask.getProcessInstanceId());
    }
    return externalTask.getErrorDetails();
}
Also used : ExternalTaskEntity(org.camunda.bpm.engine.impl.persistence.entity.ExternalTaskEntity) CommandChecker(org.camunda.bpm.engine.impl.cfg.CommandChecker)

Example 4 with ExternalTaskEntity

use of org.camunda.bpm.engine.impl.persistence.entity.ExternalTaskEntity in project camunda-bpm-platform by camunda.

the class MigratingInstanceParser method parse.

public MigratingProcessInstance parse(String processInstanceId, MigrationPlan migrationPlan, MigratingProcessInstanceValidationReportImpl processInstanceReport) {
    CommandContext commandContext = Context.getCommandContext();
    List<EventSubscriptionEntity> eventSubscriptions = fetchEventSubscriptions(commandContext, processInstanceId);
    List<ExecutionEntity> executions = fetchExecutions(commandContext, processInstanceId);
    List<ExternalTaskEntity> externalTasks = fetchExternalTasks(commandContext, processInstanceId);
    List<IncidentEntity> incidents = fetchIncidents(commandContext, processInstanceId);
    List<JobEntity> jobs = fetchJobs(commandContext, processInstanceId);
    List<TaskEntity> tasks = fetchTasks(commandContext, processInstanceId);
    List<VariableInstanceEntity> variables = fetchVariables(commandContext, processInstanceId);
    ExecutionEntity processInstance = commandContext.getExecutionManager().findExecutionById(processInstanceId);
    processInstance.restoreProcessInstance(executions, eventSubscriptions, variables, tasks, jobs, incidents, externalTasks);
    ProcessDefinitionEntity targetProcessDefinition = Context.getProcessEngineConfiguration().getDeploymentCache().findDeployedProcessDefinitionById(migrationPlan.getTargetProcessDefinitionId());
    List<JobDefinitionEntity> targetJobDefinitions = fetchJobDefinitions(commandContext, targetProcessDefinition.getId());
    final MigratingInstanceParseContext parseContext = new MigratingInstanceParseContext(this, migrationPlan, processInstance, targetProcessDefinition).eventSubscriptions(eventSubscriptions).externalTasks(externalTasks).incidents(incidents).jobs(jobs).tasks(tasks).targetJobDefinitions(targetJobDefinitions).variables(variables);
    ActivityInstance activityInstance = engine.getRuntimeService().getActivityInstance(processInstanceId);
    ActivityInstanceWalker activityInstanceWalker = new ActivityInstanceWalker(activityInstance);
    activityInstanceWalker.addPreVisitor(new TreeVisitor<ActivityInstance>() {

        @Override
        public void visit(ActivityInstance obj) {
            activityInstanceHandler.handle(parseContext, obj);
        }
    });
    activityInstanceWalker.walkWhile();
    CompensationEventSubscriptionWalker compensateSubscriptionsWalker = new CompensationEventSubscriptionWalker(parseContext.getMigratingActivityInstances());
    compensateSubscriptionsWalker.addPreVisitor(new TreeVisitor<EventSubscriptionEntity>() {

        @Override
        public void visit(EventSubscriptionEntity obj) {
            compensationInstanceHandler.handle(parseContext, obj);
        }
    });
    compensateSubscriptionsWalker.walkWhile();
    for (IncidentEntity incidentEntity : incidents) {
        incidentHandler.handle(parseContext, incidentEntity);
    }
    parseContext.validateNoEntitiesLeft(processInstanceReport);
    return parseContext.getMigratingProcessInstance();
}
Also used : ExternalTaskEntity(org.camunda.bpm.engine.impl.persistence.entity.ExternalTaskEntity) TaskEntity(org.camunda.bpm.engine.impl.persistence.entity.TaskEntity) CommandContext(org.camunda.bpm.engine.impl.interceptor.CommandContext) MigratingActivityInstance(org.camunda.bpm.engine.impl.migration.instance.MigratingActivityInstance) ActivityInstance(org.camunda.bpm.engine.runtime.ActivityInstance) VariableInstanceEntity(org.camunda.bpm.engine.impl.persistence.entity.VariableInstanceEntity) JobDefinitionEntity(org.camunda.bpm.engine.impl.persistence.entity.JobDefinitionEntity) ExecutionEntity(org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity) EventSubscriptionEntity(org.camunda.bpm.engine.impl.persistence.entity.EventSubscriptionEntity) IncidentEntity(org.camunda.bpm.engine.impl.persistence.entity.IncidentEntity) ExternalTaskEntity(org.camunda.bpm.engine.impl.persistence.entity.ExternalTaskEntity) JobEntity(org.camunda.bpm.engine.impl.persistence.entity.JobEntity) ProcessDefinitionEntity(org.camunda.bpm.engine.impl.persistence.entity.ProcessDefinitionEntity)

Example 5 with ExternalTaskEntity

use of org.camunda.bpm.engine.impl.persistence.entity.ExternalTaskEntity in project camunda-bpm-platform by camunda.

the class HandleExternalTaskCmd method execute.

@Override
public Void execute(CommandContext commandContext) {
    validateInput();
    ExternalTaskEntity externalTask = commandContext.getExternalTaskManager().findExternalTaskById(externalTaskId);
    EnsureUtil.ensureNotNull(NotFoundException.class, "Cannot find external task with id " + externalTaskId, "externalTask", externalTask);
    if (!workerId.equals(externalTask.getWorkerId())) {
        throw new BadUserRequestException(getErrorMessageOnWrongWorkerAccess() + "'. It is locked by worker '" + externalTask.getWorkerId() + "'.");
    }
    for (CommandChecker checker : commandContext.getProcessEngineConfiguration().getCommandCheckers()) {
        checker.checkUpdateProcessInstanceById(externalTask.getProcessInstanceId());
    }
    execute(externalTask);
    return null;
}
Also used : ExternalTaskEntity(org.camunda.bpm.engine.impl.persistence.entity.ExternalTaskEntity) BadUserRequestException(org.camunda.bpm.engine.BadUserRequestException) CommandChecker(org.camunda.bpm.engine.impl.cfg.CommandChecker)

Aggregations

ExternalTaskEntity (org.camunda.bpm.engine.impl.persistence.entity.ExternalTaskEntity)6 CommandChecker (org.camunda.bpm.engine.impl.cfg.CommandChecker)3 ExecutionEntity (org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity)2 BadUserRequestException (org.camunda.bpm.engine.BadUserRequestException)1 LockedExternalTask (org.camunda.bpm.engine.externaltask.LockedExternalTask)1 LockedExternalTaskImpl (org.camunda.bpm.engine.impl.externaltask.LockedExternalTaskImpl)1 TopicFetchInstruction (org.camunda.bpm.engine.impl.externaltask.TopicFetchInstruction)1 CommandContext (org.camunda.bpm.engine.impl.interceptor.CommandContext)1 MigratingActivityInstance (org.camunda.bpm.engine.impl.migration.instance.MigratingActivityInstance)1 MigratingExternalTaskInstance (org.camunda.bpm.engine.impl.migration.instance.MigratingExternalTaskInstance)1 EventSubscriptionEntity (org.camunda.bpm.engine.impl.persistence.entity.EventSubscriptionEntity)1 IncidentEntity (org.camunda.bpm.engine.impl.persistence.entity.IncidentEntity)1 JobDefinitionEntity (org.camunda.bpm.engine.impl.persistence.entity.JobDefinitionEntity)1 JobEntity (org.camunda.bpm.engine.impl.persistence.entity.JobEntity)1 ProcessDefinitionEntity (org.camunda.bpm.engine.impl.persistence.entity.ProcessDefinitionEntity)1 TaskEntity (org.camunda.bpm.engine.impl.persistence.entity.TaskEntity)1 VariableInstanceEntity (org.camunda.bpm.engine.impl.persistence.entity.VariableInstanceEntity)1 ActivityInstance (org.camunda.bpm.engine.runtime.ActivityInstance)1