Search in sources :

Example 11 with JobDefinitionEntity

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

the class BpmnDeployer method updateJobDeclarations.

protected void updateJobDeclarations(List<JobDeclaration<?, ?>> jobDeclarations, ProcessDefinitionEntity processDefinition, boolean isNewDeployment) {
    if (jobDeclarations == null || jobDeclarations.isEmpty()) {
        return;
    }
    final JobDefinitionManager jobDefinitionManager = getJobDefinitionManager();
    if (isNewDeployment) {
        // create new job definitions:
        for (JobDeclaration<?, ?> jobDeclaration : jobDeclarations) {
            createJobDefinition(processDefinition, jobDeclaration);
        }
    } else {
        // query all job definitions and update the declarations with their Ids
        List<JobDefinitionEntity> existingDefinitions = jobDefinitionManager.findByProcessDefinitionId(processDefinition.getId());
        LegacyBehavior.migrateMultiInstanceJobDefinitions(processDefinition, existingDefinitions);
        for (JobDeclaration<?, ?> jobDeclaration : jobDeclarations) {
            boolean jobDefinitionExists = false;
            for (JobDefinition jobDefinitionEntity : existingDefinitions) {
                // <!> Assumption: there can be only one job definition per activity and type
                if (jobDeclaration.getActivityId().equals(jobDefinitionEntity.getActivityId()) && jobDeclaration.getJobHandlerType().equals(jobDefinitionEntity.getJobType())) {
                    jobDeclaration.setJobDefinitionId(jobDefinitionEntity.getId());
                    jobDefinitionExists = true;
                    break;
                }
            }
            if (!jobDefinitionExists) {
                // not found: create new definition
                createJobDefinition(processDefinition, jobDeclaration);
            }
        }
    }
}
Also used : JobDefinitionEntity(org.camunda.bpm.engine.impl.persistence.entity.JobDefinitionEntity) JobDefinitionManager(org.camunda.bpm.engine.impl.persistence.entity.JobDefinitionManager) JobDefinition(org.camunda.bpm.engine.management.JobDefinition)

Example 12 with JobDefinitionEntity

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

the class BpmnDeployer method createJobDefinition.

protected void createJobDefinition(ProcessDefinition processDefinition, JobDeclaration<?, ?> jobDeclaration) {
    final JobDefinitionManager jobDefinitionManager = getJobDefinitionManager();
    JobDefinitionEntity jobDefinitionEntity = new JobDefinitionEntity(jobDeclaration);
    jobDefinitionEntity.setProcessDefinitionId(processDefinition.getId());
    jobDefinitionEntity.setProcessDefinitionKey(processDefinition.getKey());
    jobDefinitionEntity.setTenantId(processDefinition.getTenantId());
    jobDefinitionManager.insert(jobDefinitionEntity);
    jobDeclaration.setJobDefinitionId(jobDefinitionEntity.getId());
}
Also used : JobDefinitionEntity(org.camunda.bpm.engine.impl.persistence.entity.JobDefinitionEntity) JobDefinitionManager(org.camunda.bpm.engine.impl.persistence.entity.JobDefinitionManager)

Example 13 with JobDefinitionEntity

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

the class SetJobDefinitionPriorityCmd method execute.

public Void execute(CommandContext commandContext) {
    ensureNotNull(NotValidException.class, "jobDefinitionId", jobDefinitionId);
    JobDefinitionEntity jobDefinition = commandContext.getJobDefinitionManager().findById(jobDefinitionId);
    ensureNotNull(NotFoundException.class, "Job definition with id '" + jobDefinitionId + "' does not exist", "jobDefinition", jobDefinition);
    checkUpdateProcess(commandContext, jobDefinition);
    Long currentPriority = jobDefinition.getOverridingJobPriority();
    jobDefinition.setJobPriority(priority);
    UserOperationLogContext opLogContext = new UserOperationLogContext();
    createJobDefinitionOperationLogEntry(opLogContext, currentPriority, jobDefinition);
    if (cascade && priority != null) {
        commandContext.getJobManager().updateJobPriorityByDefinitionId(jobDefinitionId, priority);
        createCascadeJobsOperationLogEntry(opLogContext, jobDefinition);
    }
    commandContext.getOperationLogManager().logUserOperations(opLogContext);
    return null;
}
Also used : JobDefinitionEntity(org.camunda.bpm.engine.impl.persistence.entity.JobDefinitionEntity) UserOperationLogContext(org.camunda.bpm.engine.impl.oplog.UserOperationLogContext)

Example 14 with JobDefinitionEntity

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

the class TransitionInstanceJobHandler method handle.

@Override
public void handle(MigratingInstanceParseContext parseContext, MigratingTransitionInstance transitionInstance, List<JobEntity> elements) {
    for (JobEntity job : elements) {
        if (!isAsyncContinuation(job)) {
            continue;
        }
        ScopeImpl targetScope = transitionInstance.getTargetScope();
        if (targetScope != null) {
            JobDefinitionEntity targetJobDefinitionEntity = parseContext.getTargetJobDefinition(transitionInstance.getTargetScope().getId(), job.getJobHandlerType());
            MigratingAsyncJobInstance migratingJobInstance = new MigratingAsyncJobInstance(job, targetJobDefinitionEntity, transitionInstance.getTargetScope());
            transitionInstance.setDependentJobInstance(migratingJobInstance);
            parseContext.submit(migratingJobInstance);
        }
        parseContext.consume(job);
    }
}
Also used : JobEntity(org.camunda.bpm.engine.impl.persistence.entity.JobEntity) JobDefinitionEntity(org.camunda.bpm.engine.impl.persistence.entity.JobDefinitionEntity) MigratingAsyncJobInstance(org.camunda.bpm.engine.impl.migration.instance.MigratingAsyncJobInstance) ScopeImpl(org.camunda.bpm.engine.impl.pvm.process.ScopeImpl)

Example 15 with JobDefinitionEntity

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

the class AbstractSetJobDefinitionStateCmd method checkAuthorization.

@Override
protected void checkAuthorization(CommandContext commandContext) {
    for (CommandChecker checker : commandContext.getProcessEngineConfiguration().getCommandCheckers()) {
        if (jobDefinitionId != null) {
            JobDefinitionManager jobDefinitionManager = commandContext.getJobDefinitionManager();
            JobDefinitionEntity jobDefinition = jobDefinitionManager.findById(jobDefinitionId);
            if (jobDefinition != null && jobDefinition.getProcessDefinitionKey() != null) {
                String processDefinitionKey = jobDefinition.getProcessDefinitionKey();
                checker.checkUpdateProcessDefinitionByKey(processDefinitionKey);
                if (includeSubResources) {
                    checker.checkUpdateProcessInstanceByProcessDefinitionKey(processDefinitionKey);
                }
            }
        } else if (processDefinitionId != null) {
            checker.checkUpdateProcessDefinitionById(processDefinitionId);
            if (includeSubResources) {
                checker.checkUpdateProcessInstanceByProcessDefinitionId(processDefinitionId);
            }
        } else if (processDefinitionKey != null) {
            checker.checkUpdateProcessDefinitionByKey(processDefinitionKey);
            if (includeSubResources) {
                checker.checkUpdateProcessInstanceByProcessDefinitionKey(processDefinitionKey);
            }
        }
    }
}
Also used : JobDefinitionEntity(org.camunda.bpm.engine.impl.persistence.entity.JobDefinitionEntity) JobDefinitionManager(org.camunda.bpm.engine.impl.persistence.entity.JobDefinitionManager) CommandChecker(org.camunda.bpm.engine.impl.cfg.CommandChecker)

Aggregations

JobDefinitionEntity (org.camunda.bpm.engine.impl.persistence.entity.JobDefinitionEntity)16 JobDefinitionManager (org.camunda.bpm.engine.impl.persistence.entity.JobDefinitionManager)5 JobEntity (org.camunda.bpm.engine.impl.persistence.entity.JobEntity)5 CommandChecker (org.camunda.bpm.engine.impl.cfg.CommandChecker)3 ExecutionEntity (org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity)3 MigratingJobInstance (org.camunda.bpm.engine.impl.migration.instance.MigratingJobInstance)2 IncidentEntity (org.camunda.bpm.engine.impl.persistence.entity.IncidentEntity)2 ProcessDefinitionEntity (org.camunda.bpm.engine.impl.persistence.entity.ProcessDefinitionEntity)2 PropertyChange (org.camunda.bpm.engine.impl.persistence.entity.PropertyChange)2 ProcessEngineException (org.camunda.bpm.engine.ProcessEngineException)1 ProcessEngineConfigurationImpl (org.camunda.bpm.engine.impl.cfg.ProcessEngineConfigurationImpl)1 ParameterValueProvider (org.camunda.bpm.engine.impl.core.variable.mapping.value.ParameterValueProvider)1 HistoryLevel (org.camunda.bpm.engine.impl.history.HistoryLevel)1 HistoryEvent (org.camunda.bpm.engine.impl.history.event.HistoryEvent)1 HistoryEventProcessor (org.camunda.bpm.engine.impl.history.event.HistoryEventProcessor)1 HistoryEventProducer (org.camunda.bpm.engine.impl.history.producer.HistoryEventProducer)1 CommandContext (org.camunda.bpm.engine.impl.interceptor.CommandContext)1 TimerDeclarationImpl (org.camunda.bpm.engine.impl.jobexecutor.TimerDeclarationImpl)1 MigratingActivityInstance (org.camunda.bpm.engine.impl.migration.instance.MigratingActivityInstance)1 MigratingAsyncJobInstance (org.camunda.bpm.engine.impl.migration.instance.MigratingAsyncJobInstance)1