Java Code Examples for org.flowable.engine.impl.util.CommandContextUtil#getProcessEngineConfiguration()
The following examples show how to use
org.flowable.engine.impl.util.CommandContextUtil#getProcessEngineConfiguration() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TimerActivateProcessDefinitionHandler.java From flowable-engine with Apache License 2.0 | 6 votes |
@Override public void execute(JobEntity job, String configuration, VariableScope variableScope, CommandContext commandContext) { ProcessEngineConfigurationImpl processEngineConfiguration = CommandContextUtil.getProcessEngineConfiguration(commandContext); boolean activateProcessInstances = false; try { JsonNode configNode = processEngineConfiguration.getObjectMapper().readTree(configuration); activateProcessInstances = getIncludeProcessInstances(configNode); } catch (Exception e) { throw new FlowableException("Error reading json value " + configuration, e); } String processDefinitionId = job.getProcessDefinitionId(); ActivateProcessDefinitionCmd activateProcessDefinitionCmd = new ActivateProcessDefinitionCmd(processDefinitionId, null, activateProcessInstances, null, job.getTenantId()); activateProcessDefinitionCmd.execute(commandContext); }
Example 2
Source File: TerminateEndEventActivityBehavior.java From flowable-engine with Apache License 2.0 | 6 votes |
protected void endAllHistoricActivities(String processInstanceId, String deleteReason) { if (!CommandContextUtil.getProcessEngineConfiguration().getHistoryLevel().isAtLeast(HistoryLevel.ACTIVITY)) { return; } List<HistoricActivityInstanceEntity> historicActivityInstances = CommandContextUtil.getHistoricActivityInstanceEntityManager() .findUnfinishedHistoricActivityInstancesByProcessInstanceId(processInstanceId); Clock clock = CommandContextUtil.getProcessEngineConfiguration().getClock(); for (HistoricActivityInstanceEntity historicActivityInstance : historicActivityInstances) { historicActivityInstance.markEnded(deleteReason, clock.getCurrentTime()); // Fire event ProcessEngineConfigurationImpl config = CommandContextUtil.getProcessEngineConfiguration(); FlowableEventDispatcher eventDispatcher = null; if (config != null) { eventDispatcher = config.getEventDispatcher(); } if (eventDispatcher != null && eventDispatcher.isEnabled()) { eventDispatcher.dispatchEvent( FlowableEventBuilder.createEntityEvent(FlowableEngineEventType.HISTORIC_ACTIVITY_INSTANCE_ENDED, historicActivityInstance)); } } }
Example 3
Source File: DeployCmd.java From flowable-engine with Apache License 2.0 | 6 votes |
@Override public Deployment execute(CommandContext commandContext) { // Backwards compatibility with v5 if (deploymentBuilder.getDeploymentProperties() != null && deploymentBuilder.getDeploymentProperties().containsKey(DeploymentProperties.DEPLOY_AS_FLOWABLE5_PROCESS_DEFINITION) && deploymentBuilder.getDeploymentProperties().get(DeploymentProperties.DEPLOY_AS_FLOWABLE5_PROCESS_DEFINITION).equals(Boolean.TRUE)) { ProcessEngineConfigurationImpl processEngineConfiguration = CommandContextUtil.getProcessEngineConfiguration(commandContext); if (processEngineConfiguration.isFlowable5CompatibilityEnabled() && processEngineConfiguration.getFlowable5CompatibilityHandler() != null) { return deployAsFlowable5ProcessDefinition(commandContext); } else { throw new FlowableException("Can't deploy a v5 deployment with no flowable 5 compatibility enabled or no compatibility handler on the classpath"); } } return executeDeploy(commandContext); }
Example 4
Source File: HistoricProcessInstanceQueryImpl.java From flowable-engine with Apache License 2.0 | 5 votes |
@Override public List<HistoricProcessInstance> executeList(CommandContext commandContext) { ensureVariablesInitialized(); List<HistoricProcessInstance> results = null; ProcessEngineConfigurationImpl processEngineConfiguration = CommandContextUtil.getProcessEngineConfiguration(commandContext); if (processEngineConfiguration.getHistoricProcessInstanceQueryInterceptor() != null) { processEngineConfiguration.getHistoricProcessInstanceQueryInterceptor().beforeHistoricProcessInstanceQueryExecute(this); } if (includeProcessVariables) { results = CommandContextUtil.getHistoricProcessInstanceEntityManager(commandContext).findHistoricProcessInstancesAndVariablesByQueryCriteria(this); if (processInstanceId != null) { addCachedVariableForQueryById(commandContext, results); } } else { results = CommandContextUtil.getHistoricProcessInstanceEntityManager(commandContext).findHistoricProcessInstancesByQueryCriteria(this); } if (processEngineConfiguration.getPerformanceSettings().isEnableLocalization() && processEngineConfiguration.getInternalProcessLocalizationManager() != null) { for (HistoricProcessInstance processInstance : results) { processEngineConfiguration.getInternalProcessLocalizationManager().localize(processInstance, locale, withLocalizationFallback); } } if (processEngineConfiguration.getHistoricProcessInstanceQueryInterceptor() != null) { processEngineConfiguration.getHistoricProcessInstanceQueryInterceptor().afterHistoricProcessInstanceQueryExecute(this, results); } return results; }
Example 5
Source File: SchemaOperationProcessEngineClose.java From flowable-engine with Apache License 2.0 | 5 votes |
@Override public Void execute(CommandContext commandContext) { ProcessEngineConfigurationImpl processEngineConfiguration = CommandContextUtil.getProcessEngineConfiguration(commandContext); if (processEngineConfiguration.isUsingRelationalDatabase()) { ((ProcessDbSchemaManager) processEngineConfiguration.getSchemaManager()).performSchemaOperationsProcessEngineClose(); } return null; }
Example 6
Source File: HandleHistoryCleanupTimerJobCmd.java From flowable-engine with Apache License 2.0 | 5 votes |
@Override public Object execute(CommandContext commandContext) { ProcessEngineConfigurationImpl processEngineConfiguration = CommandContextUtil.getProcessEngineConfiguration(commandContext); ManagementService managementService = processEngineConfiguration.getManagementService(); TimerJobService timerJobService = CommandContextUtil.getTimerJobService(commandContext); List<Job> cleanupJobs = managementService.createTimerJobQuery().handlerType(BpmnHistoryCleanupJobHandler.TYPE).list(); if (cleanupJobs.isEmpty()) { TimerJobEntity timerJob = timerJobService.createTimerJob(); timerJob.setJobType(JobEntity.JOB_TYPE_TIMER); timerJob.setRevision(1); timerJob.setJobHandlerType(BpmnHistoryCleanupJobHandler.TYPE); BusinessCalendar businessCalendar = processEngineConfiguration.getBusinessCalendarManager().getBusinessCalendar(CycleBusinessCalendar.NAME); timerJob.setDuedate(businessCalendar.resolveDuedate(processEngineConfiguration.getHistoryCleaningTimeCycleConfig())); timerJob.setRepeat(processEngineConfiguration.getHistoryCleaningTimeCycleConfig()); timerJobService.scheduleTimerJob(timerJob); } else { if (cleanupJobs.size() > 1) { for (int i = 1; i < cleanupJobs.size(); i++) { managementService.deleteTimerJob(cleanupJobs.get(i).getId()); } } } return null; }
Example 7
Source File: EscalationPropagation.java From flowable-engine with Apache License 2.0 | 5 votes |
protected static void executeEventHandler(Event event, ExecutionEntity parentExecution, ExecutionEntity currentExecution, String escalationCode, String escalationName) { ProcessEngineConfigurationImpl processEngineConfiguration = CommandContextUtil.getProcessEngineConfiguration(); FlowableEventDispatcher eventDispatcher = null; if (processEngineConfiguration != null) { eventDispatcher = processEngineConfiguration.getEventDispatcher(); } if (eventDispatcher != null && eventDispatcher.isEnabled()) { processEngineConfiguration.getEventDispatcher().dispatchEvent( FlowableEventBuilder.createEscalationEvent(FlowableEngineEventType.ACTIVITY_ESCALATION_RECEIVED, event.getId(), escalationCode, escalationName, parentExecution.getId(), parentExecution.getProcessInstanceId(), parentExecution.getProcessDefinitionId())); } if (event instanceof StartEvent) { ExecutionEntityManager executionEntityManager = CommandContextUtil.getExecutionEntityManager(); ExecutionEntity eventSubProcessExecution = executionEntityManager.createChildExecution(parentExecution); eventSubProcessExecution.setCurrentFlowElement(event.getSubProcess() != null ? event.getSubProcess() : event); CommandContextUtil.getAgenda().planContinueProcessOperation(eventSubProcessExecution); } else { ExecutionEntity boundaryExecution = null; List<? extends ExecutionEntity> childExecutions = parentExecution.getExecutions(); for (ExecutionEntity childExecution : childExecutions) { if (childExecution != null && childExecution.getActivityId() != null && childExecution.getActivityId().equals(event.getId())) { boundaryExecution = childExecution; } } CommandContextUtil.getAgenda().planTriggerExecutionOperation(boundaryExecution); } }
Example 8
Source File: ProcessInstanceQueryImpl.java From flowable-engine with Apache License 2.0 | 5 votes |
@Override public List<ProcessInstance> executeList(CommandContext commandContext) { ensureVariablesInitialized(); List<ProcessInstance> processInstances = null; ProcessEngineConfigurationImpl processEngineConfiguration = CommandContextUtil.getProcessEngineConfiguration(commandContext); if (processEngineConfiguration.getProcessInstanceQueryInterceptor() != null) { processEngineConfiguration.getProcessInstanceQueryInterceptor().beforeProcessInstanceQueryExecute(this); } if (includeProcessVariables) { processInstances = CommandContextUtil.getExecutionEntityManager(commandContext).findProcessInstanceAndVariablesByQueryCriteria(this); } else { processInstances = CommandContextUtil.getExecutionEntityManager(commandContext).findProcessInstanceByQueryCriteria(this); } if (processEngineConfiguration.getPerformanceSettings().isEnableLocalization() && processEngineConfiguration.getInternalProcessLocalizationManager() != null) { for (ProcessInstance processInstance : processInstances) { processEngineConfiguration.getInternalProcessLocalizationManager().localize(processInstance, locale, withLocalizationFallback); } } if (processEngineConfiguration.getProcessInstanceQueryInterceptor() != null) { processEngineConfiguration.getProcessInstanceQueryInterceptor().afterProcessInstanceQueryExecute(this, processInstances); } return processInstances; }
Example 9
Source File: ProcessInstanceQueryImpl.java From flowable-engine with Apache License 2.0 | 5 votes |
@Override public long executeCount(CommandContext commandContext) { ensureVariablesInitialized(); ProcessEngineConfigurationImpl processEngineConfiguration = CommandContextUtil.getProcessEngineConfiguration(commandContext); if (processEngineConfiguration.getProcessInstanceQueryInterceptor() != null) { processEngineConfiguration.getProcessInstanceQueryInterceptor().beforeProcessInstanceQueryExecute(this); } return CommandContextUtil.getExecutionEntityManager(commandContext).findProcessInstanceCountByQueryCriteria(this); }
Example 10
Source File: SkipExpressionUtil.java From flowable-engine with Apache License 2.0 | 5 votes |
protected static String resolveActiveSkipExpression(String skipExpression, String activityId, String processDefinitionId, CommandContext commandContext) { ProcessEngineConfigurationImpl processEngineConfiguration = CommandContextUtil.getProcessEngineConfiguration(commandContext); String activeTaskSkipExpression = null; if (processEngineConfiguration.isEnableProcessDefinitionInfoCache()) { ObjectNode taskElementProperties = BpmnOverrideContext.getBpmnOverrideElementProperties(activityId, processDefinitionId); activeTaskSkipExpression = DynamicPropertyUtil.getActiveValue(skipExpression, DynamicBpmnConstants.TASK_SKIP_EXPRESSION, taskElementProperties); } else { activeTaskSkipExpression = skipExpression; } return activeTaskSkipExpression; }
Example 11
Source File: ContinueProcessOperation.java From flowable-engine with Apache License 2.0 | 5 votes |
protected List<ExecutionEntity> createBoundaryEvents(List<BoundaryEvent> boundaryEvents, ExecutionEntity execution) { List<ExecutionEntity> boundaryEventExecutions = new ArrayList<>(boundaryEvents.size()); // The parent execution becomes a scope, and a child execution is created for each of the boundary events for (BoundaryEvent boundaryEvent : boundaryEvents) { if (!(boundaryEvent.getBehavior() instanceof BoundaryEventRegistryEventActivityBehavior)) { if (CollectionUtil.isEmpty(boundaryEvent.getEventDefinitions()) || (boundaryEvent.getEventDefinitions().get(0) instanceof CompensateEventDefinition)) { continue; } } // A Child execution of the current execution is created to represent the boundary event being active ExecutionEntity childExecutionEntity = CommandContextUtil.getExecutionEntityManager(commandContext).createChildExecution(execution); childExecutionEntity.setParentId(execution.getId()); childExecutionEntity.setCurrentFlowElement(boundaryEvent); childExecutionEntity.setScope(false); boundaryEventExecutions.add(childExecutionEntity); CommandContextUtil.getActivityInstanceEntityManager(commandContext).recordActivityStart(childExecutionEntity); ProcessEngineConfigurationImpl processEngineConfiguration = CommandContextUtil.getProcessEngineConfiguration(commandContext); if (processEngineConfiguration.isLoggingSessionEnabled()) { BpmnLoggingSessionUtil.addLoggingData(BpmnLoggingSessionUtil.getBoundaryCreateEventType(boundaryEvent), "Creating boundary event (" + BpmnLoggingSessionUtil.getBoundaryEventType(boundaryEvent) + ") for execution id " + childExecutionEntity.getId(), childExecutionEntity); } } return boundaryEventExecutions; }
Example 12
Source File: ContinueProcessOperation.java From flowable-engine with Apache License 2.0 | 5 votes |
protected void executeAsynchronous(FlowNode flowNode) { ProcessEngineConfigurationImpl processEngineConfiguration = CommandContextUtil.getProcessEngineConfiguration(commandContext); JobService jobService = CommandContextUtil.getJobService(commandContext); JobEntity job = jobService.createJob(); job.setExecutionId(execution.getId()); job.setProcessInstanceId(execution.getProcessInstanceId()); job.setProcessDefinitionId(execution.getProcessDefinitionId()); job.setElementId(flowNode.getId()); job.setElementName(flowNode.getName()); job.setJobHandlerType(AsyncContinuationJobHandler.TYPE); List<ExtensionElement> jobCategoryElements = flowNode.getExtensionElements().get("jobCategory"); if (jobCategoryElements != null && jobCategoryElements.size() > 0) { ExtensionElement jobCategoryElement = jobCategoryElements.get(0); if (StringUtils.isNotEmpty(jobCategoryElement.getElementText())) { Expression categoryExpression = processEngineConfiguration.getExpressionManager().createExpression(jobCategoryElement.getElementText()); Object categoryValue = categoryExpression.getValue(execution); if (categoryValue != null) { job.setCategory(categoryValue.toString()); } } } // Inherit tenant id (if applicable) if (execution.getTenantId() != null) { job.setTenantId(execution.getTenantId()); } execution.getJobs().add(job); jobService.createAsyncJob(job, flowNode.isExclusive()); jobService.scheduleAsyncJob(job); if (processEngineConfiguration.isLoggingSessionEnabled()) { BpmnLoggingSessionUtil.addAsyncActivityLoggingData("Created async job for " + flowNode.getId() + ", with job id " + job.getId(), LoggingSessionConstants.TYPE_SERVICE_TASK_ASYNC_JOB, job, flowNode, execution); } }
Example 13
Source File: ProcessDefinitionQueryImpl.java From flowable-engine with Apache License 2.0 | 5 votes |
@Override public List<ProcessDefinition> executeList(CommandContext commandContext) { ProcessEngineConfigurationImpl processEngineConfiguration = CommandContextUtil.getProcessEngineConfiguration(commandContext); List<ProcessDefinition> processDefinitions = CommandContextUtil.getProcessDefinitionEntityManager(commandContext).findProcessDefinitionsByQueryCriteria(this); if (processDefinitions != null && processEngineConfiguration.getPerformanceSettings().isEnableLocalization() && processEngineConfiguration.getInternalProcessDefinitionLocalizationManager() != null) { for (ProcessDefinition processDefinition : processDefinitions) { processEngineConfiguration.getInternalProcessDefinitionLocalizationManager().localize(processDefinition, locale, withLocalizationFallback); } } return processDefinitions; }
Example 14
Source File: DeployCmd.java From flowable-engine with Apache License 2.0 | 4 votes |
protected Deployment executeDeploy(CommandContext commandContext) { DeploymentEntity deployment = deploymentBuilder.getDeployment(); ProcessEngineConfigurationImpl processEngineConfiguration = CommandContextUtil.getProcessEngineConfiguration(commandContext); deployment.setDeploymentTime(processEngineConfiguration.getClock().getCurrentTime()); if (deploymentBuilder.isDuplicateFilterEnabled()) { List<Deployment> existingDeployments = new ArrayList<>(); if (deployment.getTenantId() == null || ProcessEngineConfiguration.NO_TENANT_ID.equals(deployment.getTenantId())) { List<Deployment> deploymentEntities = new DeploymentQueryImpl(processEngineConfiguration.getCommandExecutor()) .deploymentName(deployment.getName()) .orderByDeploymentTime().desc() .listPage(0, 1); if (!deploymentEntities.isEmpty()) { existingDeployments.add(deploymentEntities.get(0)); } } else { List<Deployment> deploymentList = processEngineConfiguration.getRepositoryService().createDeploymentQuery().deploymentName(deployment.getName()) .deploymentTenantId(deployment.getTenantId()).orderByDeploymentTime().desc().list(); if (!deploymentList.isEmpty()) { existingDeployments.addAll(deploymentList); } } DeploymentEntity existingDeployment = null; if (!existingDeployments.isEmpty()) { existingDeployment = (DeploymentEntity) existingDeployments.get(0); } if (existingDeployment != null && !deploymentsDiffer(deployment, existingDeployment)) { return existingDeployment; } } deployment.setNew(true); // Save the data CommandContextUtil.getDeploymentEntityManager(commandContext).insert(deployment); if (StringUtils.isEmpty(deployment.getParentDeploymentId())) { // If no parent deployment id is set then set the current ID as the parent // If something was deployed via this command than this deployment would // be a parent deployment to other potential child deployments deployment.setParentDeploymentId(deployment.getId()); } FlowableEventDispatcher eventDispatcher = processEngineConfiguration.getEventDispatcher(); if (eventDispatcher != null && eventDispatcher.isEnabled()) { eventDispatcher .dispatchEvent(FlowableEventBuilder.createEntityEvent(FlowableEngineEventType.ENTITY_CREATED, deployment)); } // Deployment settings Map<String, Object> deploymentSettings = new HashMap<>(); deploymentSettings.put(DeploymentSettings.IS_BPMN20_XSD_VALIDATION_ENABLED, deploymentBuilder.isBpmn20XsdValidationEnabled()); deploymentSettings.put(DeploymentSettings.IS_PROCESS_VALIDATION_ENABLED, deploymentBuilder.isProcessValidationEnabled()); // Actually deploy processEngineConfiguration.getDeploymentManager().deploy(deployment, deploymentSettings); if (deploymentBuilder.getProcessDefinitionsActivationDate() != null) { scheduleProcessDefinitionActivation(commandContext, deployment); } if (eventDispatcher != null && eventDispatcher.isEnabled()) { eventDispatcher .dispatchEvent(FlowableEventBuilder.createEntityEvent(FlowableEngineEventType.ENTITY_INITIALIZED, deployment)); } return deployment; }
Example 15
Source File: TestCacheTaskListener.java From flowable-engine with Apache License 2.0 | 4 votes |
@Override public void notify(DelegateTask delegateTask) { ProcessEngineConfigurationImpl processEngineConfiguration = CommandContextUtil.getProcessEngineConfiguration(); TaskService taskService = processEngineConfiguration.getTaskService(); Task task = taskService.createTaskQuery().taskId(delegateTask.getId()).singleResult(); if (task != null && task.getId().equals(delegateTask.getId())) { TASK_ID = task.getId(); } HistoryService historyService = processEngineConfiguration.getHistoryService(); HistoricTaskInstance historicTask = historyService.createHistoricTaskInstanceQuery().taskId(delegateTask.getId()).singleResult(); if (historicTask != null && historicTask.getId().equals(delegateTask.getId())) { HISTORIC_TASK_ID = historicTask.getId(); } delegateTask.setVariable("varFromTheListener", "valueFromTheListener"); delegateTask.setVariableLocal("localVar", "localValue"); // Used in CacheTaskTest#testTaskQueryWithIncludeVariables ProcessInstance processInstance = processEngineConfiguration.getRuntimeService().createProcessInstanceQuery() .processInstanceId(task.getProcessInstanceId()) .includeProcessVariables() .singleResult(); PROCESS_VARIABLES = processInstance.getProcessVariables(); HistoricProcessInstance historicProcessInstance = processEngineConfiguration.getHistoryService().createHistoricProcessInstanceQuery() .processInstanceId(task.getProcessInstanceId()) .includeProcessVariables() .singleResult(); HISTORIC_PROCESS_VARIABLES = historicProcessInstance.getProcessVariables(); // Used in CacheTaskTest#testTaskQueryWithIncludeVariables Task taskFromQuery = processEngineConfiguration.getTaskService().createTaskQuery() .taskId(delegateTask.getId()) .includeProcessVariables() .includeTaskLocalVariables() .singleResult(); TASK_PROCESS_VARIABLES = taskFromQuery.getProcessVariables(); TASK_LOCAL_VARIABLES = taskFromQuery.getTaskLocalVariables(); HistoricTaskInstance historicTaskFromQuery = processEngineConfiguration.getHistoryService().createHistoricTaskInstanceQuery() .taskId(delegateTask.getId()) .includeProcessVariables() .includeTaskLocalVariables() .singleResult(); HISTORIC_TASK_PROCESS_VARIABLES = historicTaskFromQuery.getProcessVariables(); HISTORIC_TASK_LOCAL_VARIABLES = historicTaskFromQuery.getTaskLocalVariables(); }
Example 16
Source File: ErrorPropagation.java From flowable-engine with Apache License 2.0 | 4 votes |
protected static void executeEventHandler(Event event, ExecutionEntity parentExecution, ExecutionEntity currentExecution, String errorId) { ProcessEngineConfigurationImpl processEngineConfiguration = CommandContextUtil.getProcessEngineConfiguration(); FlowableEventDispatcher eventDispatcher = null; if (processEngineConfiguration != null) { eventDispatcher = processEngineConfiguration.getEventDispatcher(); } if (eventDispatcher != null && eventDispatcher.isEnabled()) { BpmnModel bpmnModel = ProcessDefinitionUtil.getBpmnModel(parentExecution.getProcessDefinitionId()); if (bpmnModel != null) { String errorCode = bpmnModel.getErrors().get(errorId); if (errorCode == null) { errorCode = errorId; } processEngineConfiguration.getEventDispatcher().dispatchEvent( FlowableEventBuilder.createErrorEvent(FlowableEngineEventType.ACTIVITY_ERROR_RECEIVED, event.getId(), errorId, errorCode, parentExecution.getId(), parentExecution.getProcessInstanceId(), parentExecution.getProcessDefinitionId())); } } if (event instanceof StartEvent) { ExecutionEntityManager executionEntityManager = CommandContextUtil.getExecutionEntityManager(); if (parentExecution.isProcessInstanceType()) { executionEntityManager.deleteChildExecutions(parentExecution, null, true); } else if (!currentExecution.getParentId().equals(parentExecution.getId())) { CommandContextUtil.getAgenda().planDestroyScopeOperation(currentExecution); } else { executionEntityManager.deleteExecutionAndRelatedData(currentExecution, null, false); } ExecutionEntity eventSubProcessExecution = executionEntityManager.createChildExecution(parentExecution); if (event.getSubProcess() != null) { eventSubProcessExecution.setCurrentFlowElement(event.getSubProcess()); CommandContextUtil.getActivityInstanceEntityManager().recordActivityStart(eventSubProcessExecution); ExecutionEntity subProcessStartEventExecution = executionEntityManager.createChildExecution(eventSubProcessExecution); subProcessStartEventExecution.setCurrentFlowElement(event); CommandContextUtil.getAgenda().planContinueProcessOperation(subProcessStartEventExecution); } else { eventSubProcessExecution.setCurrentFlowElement(event); CommandContextUtil.getAgenda().planContinueProcessOperation(eventSubProcessExecution); } } else { ExecutionEntity boundaryExecution = null; List<? extends ExecutionEntity> childExecutions = parentExecution.getExecutions(); for (ExecutionEntity childExecution : childExecutions) { if (childExecution != null && childExecution.getActivityId() != null && childExecution.getActivityId().equals(event.getId())) { boundaryExecution = childExecution; } } CommandContextUtil.getAgenda().planTriggerExecutionOperation(boundaryExecution); } }
Example 17
Source File: ProcessInstanceMigrationManagerImpl.java From flowable-engine with Apache License 2.0 | 4 votes |
@Override public Batch batchMigrateProcessInstancesOfProcessDefinition(String sourceProcDefId, ProcessInstanceMigrationDocument document, CommandContext commandContext) { // Check of the target definition exists before submitting the batch ProcessDefinition targetProcessDefinition = resolveProcessDefinition(document, commandContext); ExecutionEntityManager executionEntityManager = CommandContextUtil.getExecutionEntityManager(commandContext); List<ProcessInstance> processInstances = executionEntityManager.findProcessInstanceByQueryCriteria( new ProcessInstanceQueryImpl().processDefinitionId(sourceProcDefId)); BatchService batchService = CommandContextUtil.getBatchService(commandContext); Batch batch = batchService.createBatchBuilder().batchType(Batch.PROCESS_MIGRATION_TYPE) .searchKey(sourceProcDefId) .searchKey2(targetProcessDefinition.getId()) .status(ProcessInstanceBatchMigrationResult.STATUS_IN_PROGRESS) .batchDocumentJson(document.asJsonString()) .create(); JobService jobService = CommandContextUtil.getJobService(commandContext); for (ProcessInstance processInstance : processInstances) { BatchPart batchPart = batchService.createBatchPart(batch, ProcessInstanceBatchMigrationResult.STATUS_WAITING, processInstance.getId(), null, ScopeTypes.BPMN); JobEntity job = jobService.createJob(); job.setJobHandlerType(ProcessInstanceMigrationJobHandler.TYPE); job.setProcessInstanceId(processInstance.getId()); job.setJobHandlerConfiguration(ProcessInstanceMigrationJobHandler.getHandlerCfgForBatchPartId(batchPart.getId())); jobService.createAsyncJob(job, false); jobService.scheduleAsyncJob(job); } if (!processInstances.isEmpty()) { TimerJobService timerJobService = CommandContextUtil.getTimerJobService(commandContext); TimerJobEntity timerJob = timerJobService.createTimerJob(); timerJob.setJobType(JobEntity.JOB_TYPE_TIMER); timerJob.setRevision(1); timerJob.setJobHandlerType(ProcessInstanceMigrationStatusJobHandler.TYPE); timerJob.setJobHandlerConfiguration(ProcessInstanceMigrationJobHandler.getHandlerCfgForBatchId(batch.getId())); ProcessEngineConfigurationImpl processEngineConfiguration = CommandContextUtil.getProcessEngineConfiguration(commandContext); BusinessCalendar businessCalendar = processEngineConfiguration.getBusinessCalendarManager().getBusinessCalendar(CycleBusinessCalendar.NAME); timerJob.setDuedate(businessCalendar.resolveDuedate(processEngineConfiguration.getBatchStatusTimeCycleConfig())); timerJob.setRepeat(processEngineConfiguration.getBatchStatusTimeCycleConfig()); timerJobService.scheduleTimerJob(timerJob); } return batch; }
Example 18
Source File: JobRetryCmd.java From flowable-engine with Apache License 2.0 | 4 votes |
@Override public Object execute(CommandContext commandContext) { JobService jobService = CommandContextUtil.getJobService(commandContext); TimerJobService timerJobService = CommandContextUtil.getTimerJobService(commandContext); JobEntity job = jobService.findJobById(jobId); if (job == null) { return null; } ProcessEngineConfiguration processEngineConfig = CommandContextUtil.getProcessEngineConfiguration(commandContext); ExecutionEntity executionEntity = fetchExecutionEntity(commandContext, job.getExecutionId()); FlowElement currentFlowElement = executionEntity != null ? executionEntity.getCurrentFlowElement() : null; if (executionEntity != null) { executionEntity.setActive(false); } String failedJobRetryTimeCycleValue = null; if (currentFlowElement instanceof ServiceTask) { failedJobRetryTimeCycleValue = ((ServiceTask) currentFlowElement).getFailedJobRetryTimeCycleValue(); } AbstractRuntimeJobEntity newJobEntity = null; if (currentFlowElement == null || failedJobRetryTimeCycleValue == null) { LOGGER.debug("activity or FailedJobRetryTimerCycleValue is null in job {}. Only decrementing retries.", jobId); if (job.getRetries() <= 1) { newJobEntity = jobService.moveJobToDeadLetterJob(job); } else { newJobEntity = timerJobService.moveJobToTimerJob(job); } newJobEntity.setRetries(job.getRetries() - 1); if (job.getDuedate() == null || JobEntity.JOB_TYPE_MESSAGE.equals(job.getJobType())) { // add wait time for failed async job newJobEntity.setDuedate(calculateDueDate(commandContext, processEngineConfig.getAsyncFailedJobWaitTime(), null)); } else { // add default wait time for failed job newJobEntity.setDuedate(calculateDueDate(commandContext, processEngineConfig.getDefaultFailedJobWaitTime(), job.getDuedate())); } } else { try { DurationHelper durationHelper = new DurationHelper(failedJobRetryTimeCycleValue, processEngineConfig.getClock()); int jobRetries = job.getRetries(); if (job.getExceptionMessage() == null) { // change default retries to the ones configured jobRetries = durationHelper.getTimes(); } if (jobRetries <= 1) { newJobEntity = jobService.moveJobToDeadLetterJob(job); } else { newJobEntity = timerJobService.moveJobToTimerJob(job); } newJobEntity.setDuedate(durationHelper.getDateAfter()); if (job.getExceptionMessage() == null) { // is it the first exception LOGGER.debug("Applying JobRetryStrategy '{}' the first time for job {} with {} retries", failedJobRetryTimeCycleValue, job.getId(), durationHelper.getTimes()); } else { LOGGER.debug("Decrementing retries of JobRetryStrategy '{}' for job {}", failedJobRetryTimeCycleValue, job.getId()); } newJobEntity.setRetries(jobRetries - 1); } catch (Exception e) { throw new FlowableException("failedJobRetryTimeCycle has wrong format:" + failedJobRetryTimeCycleValue, exception); } } if (exception != null) { newJobEntity.setExceptionMessage(exception.getMessage()); newJobEntity.setExceptionStacktrace(getExceptionStacktrace()); } // Dispatch both an update and a retry-decrement event FlowableEventDispatcher eventDispatcher = CommandContextUtil.getEventDispatcher(); if (eventDispatcher != null && eventDispatcher.isEnabled()) { eventDispatcher.dispatchEvent(FlowableEventBuilder.createEntityEvent(FlowableEngineEventType.ENTITY_UPDATED, newJobEntity)); eventDispatcher.dispatchEvent(FlowableEventBuilder.createEntityEvent(FlowableEngineEventType.JOB_RETRIES_DECREMENTED, newJobEntity)); } return null; }
Example 19
Source File: ProcessDbSchemaManager.java From flowable-engine with Apache License 2.0 | 4 votes |
protected ProcessEngineConfigurationImpl getProcessEngineConfiguration() { return CommandContextUtil.getProcessEngineConfiguration(); }
Example 20
Source File: HttpActivityBehaviorImpl.java From flowable-engine with Apache License 2.0 | 4 votes |
@Override public void execute(DelegateExecution execution) { String skipExpressionText = httpServiceTask.getSkipExpression(); CommandContext commandContext = CommandContextUtil.getCommandContext(); boolean isSkipExpressionEnabled = SkipExpressionUtil.isSkipExpressionEnabled(skipExpressionText, execution.getCurrentActivityId(), execution, commandContext); if (!isSkipExpressionEnabled || !SkipExpressionUtil.shouldSkipFlowElement(skipExpressionText, execution.getCurrentActivityId(), execution, commandContext)) { HttpRequest request = new HttpRequest(); try { request.setMethod(getStringFromField(requestMethod, execution)); request.setUrl(getStringFromField(requestUrl, execution)); request.setHeaders(getStringFromField(requestHeaders, execution)); request.setBody(getStringFromField(requestBody, execution)); request.setBodyEncoding(getStringFromField(requestBodyEncoding, execution)); request.setTimeout(getIntFromField(requestTimeout, execution)); request.setNoRedirects(getBooleanFromField(disallowRedirects, execution)); request.setIgnoreErrors(getBooleanFromField(ignoreException, execution)); request.setSaveRequest(getBooleanFromField(saveRequestVariables, execution)); request.setSaveResponse(getBooleanFromField(saveResponseParameters, execution)); request.setSaveResponseTransient(getBooleanFromField(saveResponseParametersTransient, execution)); request.setSaveResponseAsJson(getBooleanFromField(saveResponseVariableAsJson, execution)); request.setPrefix(getStringFromField(resultVariablePrefix, execution)); String failCodes = getStringFromField(failStatusCodes, execution); String handleCodes = getStringFromField(handleStatusCodes, execution); if (failCodes != null) { request.setFailCodes(getStringSetFromField(failCodes)); } if (handleCodes != null) { request.setHandleCodes(getStringSetFromField(handleCodes)); } if (request.getPrefix() == null) { request.setPrefix(execution.getCurrentFlowElement().getId()); } // Save request fields if (request.isSaveRequest()) { execution.setVariable(request.getPrefix() + "RequestMethod", request.getMethod()); execution.setVariable(request.getPrefix() + "RequestUrl", request.getUrl()); execution.setVariable(request.getPrefix() + "RequestHeaders", request.getHeaders()); execution.setVariable(request.getPrefix() + "RequestBody", request.getBody()); execution.setVariable(request.getPrefix() + "RequestBodyEncoding", request.getBodyEncoding()); execution.setVariable(request.getPrefix() + "RequestTimeout", request.getTimeout()); execution.setVariable(request.getPrefix() + "DisallowRedirects", request.isNoRedirects()); execution.setVariable(request.getPrefix() + "FailStatusCodes", failCodes); execution.setVariable(request.getPrefix() + "HandleStatusCodes", handleCodes); execution.setVariable(request.getPrefix() + "IgnoreException", request.isIgnoreErrors()); execution.setVariable(request.getPrefix() + "SaveRequestVariables", request.isSaveRequest()); execution.setVariable(request.getPrefix() + "SaveResponseParameters", request.isSaveResponse()); } } catch (Exception e) { if (e instanceof FlowableException) { throw (FlowableException) e; } else { throw new FlowableException(HTTP_TASK_REQUEST_FIELD_INVALID + " in execution " + execution.getId(), e); } } httpActivityExecutor.validate(request); ProcessEngineConfigurationImpl processEngineConfiguration = CommandContextUtil.getProcessEngineConfiguration(); HttpClientConfig httpClientConfig = CommandContextUtil.getProcessEngineConfiguration().getHttpClientConfig(); httpActivityExecutor.execute( request, execution, execution.getId(), createHttpRequestHandler(httpServiceTask.getHttpRequestHandler(), processEngineConfiguration), createHttpResponseHandler(httpServiceTask.getHttpResponseHandler(), processEngineConfiguration), getStringFromField(responseVariableName, execution), mapExceptions, httpClientConfig.getSocketTimeout(), httpClientConfig.getConnectTimeout(), httpClientConfig.getConnectionRequestTimeout()); } leave(execution); }