org.camunda.bpm.engine.impl.interceptor.CommandContext Java Examples
The following examples show how to use
org.camunda.bpm.engine.impl.interceptor.CommandContext.
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: CompetingVariableFetchingAndDeletionTest.java From camunda-bpm-platform with Apache License 2.0 | 6 votes |
public Void execute(CommandContext commandContext) { ExecutionEntity execution = commandContext.getExecutionManager() .findExecutionById(executionId); // fetch the variable instance but not the value (make sure the byte array is lazily fetched) VariableInstanceEntity varInstance = (VariableInstanceEntity) execution.getVariableInstanceLocal(varName); String byteArrayValueId = varInstance.getByteArrayValueId(); assertNotNull("Byte array id is expected to be not null", byteArrayValueId); CachedDbEntity cachedByteArray = commandContext.getDbEntityManager().getDbEntityCache() .getCachedEntity(ByteArrayEntity.class, byteArrayValueId); assertNull("Byte array is expected to be not fetched yet / lazily fetched.", cachedByteArray); monitor.sync(); // now trigger the fetching of the byte array Object value = varInstance.getValue(); assertNull("Expecting the value to be null (deleted)", value); return null; }
Example #2
Source File: GetDeploymentDmnModelInstanceCmd.java From camunda-bpm-platform with Apache License 2.0 | 6 votes |
public DmnModelInstance execute(CommandContext commandContext) { ensureNotNull("decisionDefinitionId", decisionDefinitionId); DeploymentCache deploymentCache = Context.getProcessEngineConfiguration().getDeploymentCache(); DecisionDefinitionEntity decisionDefinition = deploymentCache.findDeployedDecisionDefinitionById(decisionDefinitionId); for(CommandChecker checker : commandContext.getProcessEngineConfiguration().getCommandCheckers()) { checker.checkReadDecisionDefinition(decisionDefinition); } DmnModelInstance modelInstance = deploymentCache.findDmnModelInstanceForDecisionDefinition(decisionDefinitionId); ensureNotNull(DmnModelInstanceNotFoundException.class, "No DMN model instance found for decision definition id " + decisionDefinitionId, "modelInstance", modelInstance); return modelInstance; }
Example #3
Source File: JobQueryTest.java From camunda-bpm-platform with Apache License 2.0 | 6 votes |
private void deleteJobInDatabase() { CommandExecutor commandExecutor = processEngineConfiguration.getCommandExecutorTxRequired(); commandExecutor.execute(new Command<Void>() { public Void execute(CommandContext commandContext) { timerEntity.delete(); commandContext.getHistoricJobLogManager().deleteHistoricJobLogByJobId(timerEntity.getId()); List<HistoricIncident> historicIncidents = Context .getProcessEngineConfiguration() .getHistoryService() .createHistoricIncidentQuery() .list(); for (HistoricIncident historicIncident : historicIncidents) { commandContext .getDbEntityManager() .delete((DbEntity) historicIncident); } return null; } }); }
Example #4
Source File: AbstractRestartProcessInstanceCmd.java From camunda-bpm-platform with Apache License 2.0 | 6 votes |
protected void writeUserOperationLog(CommandContext commandContext, ProcessDefinition processDefinition, int numInstances, boolean async) { List<PropertyChange> propertyChanges = new ArrayList<PropertyChange>(); propertyChanges.add(new PropertyChange("nrOfInstances", null, numInstances)); propertyChanges.add(new PropertyChange("async", null, async)); commandContext.getOperationLogManager() .logProcessInstanceOperation(UserOperationLogEntry.OPERATION_TYPE_RESTART_PROCESS_INSTANCE, null, processDefinition.getId(), processDefinition.getKey(), propertyChanges); }
Example #5
Source File: ConcurrentHistoryCleanupReconfigureTest.java From camunda-bpm-platform with Apache License 2.0 | 6 votes |
protected void clearDatabase() { deleteHistoryCleanupJobs(); processEngineConfiguration.getCommandExecutorTxRequired().execute(new Command<Void>() { public Void execute(CommandContext commandContext) { commandContext.getMeterLogManager() .deleteAll(); commandContext.getHistoricJobLogManager() .deleteHistoricJobLogsByHandlerType("history-cleanup"); return null; } }); }
Example #6
Source File: GroupAuthorizationTest.java From camunda-bpm-platform with Apache License 2.0 | 6 votes |
public void testCheckAuthorizationWithUserWithoutGroups() { processEngineConfiguration.getCommandExecutorTxRequired().execute(new Command<Void>() { public Void execute(CommandContext commandContext) { AuthorizationManager authorizationManager = spyOnSession(commandContext, AuthorizationManager.class); DbEntityManager dbEntityManager = spyOnSession(commandContext, DbEntityManager.class); authorizationService.isUserAuthorized(testUserId, null, Permissions.READ, Resources.TASK); verify(authorizationManager, atLeastOnce()).filterAuthenticatedGroupIds(eq((List<String>) null)); ArgumentCaptor<AuthorizationCheck> authorizationCheckArgument = ArgumentCaptor.forClass(AuthorizationCheck.class); verify(dbEntityManager).selectBoolean(eq("isUserAuthorizedForResource"), authorizationCheckArgument.capture()); AuthorizationCheck authorizationCheck = authorizationCheckArgument.getValue(); assertTrue(authorizationCheck.getAuthGroupIds().isEmpty()); return null; } }); }
Example #7
Source File: ManagementServiceTest.java From camunda-bpm-platform with Apache License 2.0 | 6 votes |
protected void deleteJobAndIncidents(final Job job) { final List<HistoricIncident> incidents = historyService.createHistoricIncidentQuery() .incidentType(Incident.FAILED_JOB_HANDLER_TYPE).list(); CommandExecutor commandExecutor = processEngineConfiguration.getCommandExecutorTxRequired(); commandExecutor.execute(new Command<Void>() { @Override public Void execute(CommandContext commandContext) { ((JobEntity) job).delete(); HistoricIncidentManager historicIncidentManager = commandContext.getHistoricIncidentManager(); for (HistoricIncident incident : incidents) { HistoricIncidentEntity incidentEntity = (HistoricIncidentEntity) incident; historicIncidentManager.delete(incidentEntity); } commandContext.getHistoricJobLogManager().deleteHistoricJobLogByJobId(job.getId()); return null; } }); }
Example #8
Source File: DecisionDefinitionEntity.java From camunda-bpm-platform with Apache License 2.0 | 6 votes |
/** * Returns the cached version if exists; does not update the entity from the database in that case */ protected DecisionDefinitionEntity loadDecisionDefinition(String decisionDefinitionId) { ProcessEngineConfigurationImpl configuration = Context.getProcessEngineConfiguration(); DeploymentCache deploymentCache = configuration.getDeploymentCache(); DecisionDefinitionEntity decisionDefinition = deploymentCache.findDecisionDefinitionFromCache(decisionDefinitionId); if (decisionDefinition == null) { CommandContext commandContext = Context.getCommandContext(); DecisionDefinitionManager decisionDefinitionManager = commandContext.getDecisionDefinitionManager(); decisionDefinition = decisionDefinitionManager.findDecisionDefinitionById(decisionDefinitionId); if (decisionDefinition != null) { decisionDefinition = deploymentCache.resolveDecisionDefinition(decisionDefinition); } } return decisionDefinition; }
Example #9
Source File: DefaultCorrelationHandler.java From camunda-bpm-platform with Apache License 2.0 | 6 votes |
protected List<CorrelationHandlerResult> correlateStartMessageByEventSubscription(CommandContext commandContext, String messageName, CorrelationSet correlationSet) { List<CorrelationHandlerResult> results = new ArrayList<CorrelationHandlerResult>(); DeploymentCache deploymentCache = commandContext.getProcessEngineConfiguration().getDeploymentCache(); List<EventSubscriptionEntity> messageEventSubscriptions = findMessageStartEventSubscriptions(commandContext, messageName, correlationSet); for (EventSubscriptionEntity messageEventSubscription : messageEventSubscriptions) { if (messageEventSubscription.getConfiguration() != null) { String processDefinitionId = messageEventSubscription.getConfiguration(); ProcessDefinitionEntity processDefinition = deploymentCache.findDeployedProcessDefinitionById(processDefinitionId); // only an active process definition will be returned if (processDefinition != null && !processDefinition.isSuspended()) { CorrelationHandlerResult result = CorrelationHandlerResult.matchedProcessDefinition(processDefinition, messageEventSubscription.getActivityId()); results.add(result); } else { LOG.couldNotFindProcessDefinitionForEventSubscription(messageEventSubscription, processDefinitionId); } } } return results; }
Example #10
Source File: CompetingMessageCorrelationTest.java From camunda-bpm-platform with Apache License 2.0 | 6 votes |
@Override public Void execute(CommandContext commandContext) { monitor.sync(); // thread will block here until makeContinue() is called form main thread MessageCorrelationBuilderImpl correlationBuilder = new MessageCorrelationBuilderImpl(commandContext, messageName); if (processInstanceId != null) { correlationBuilder.processInstanceId(processInstanceId); } if (exclusive) { correlationBuilder.correlateExclusively(); } else { correlationBuilder.correlate(); } monitor.sync(); // thread will block here until waitUntilDone() is called form main thread return null; }
Example #11
Source File: DeleteHistoricDecisionInstancesJobHandler.java From camunda-bpm-platform with Apache License 2.0 | 6 votes |
@Override public void execute(BatchJobConfiguration configuration, ExecutionEntity execution, CommandContext commandContext, String tenantId) { ByteArrayEntity configurationEntity = commandContext .getDbEntityManager() .selectById(ByteArrayEntity.class, configuration.getConfigurationByteArrayId()); BatchConfiguration batchConfiguration = readConfiguration(configurationEntity.getBytes()); boolean initialLegacyRestrictions = commandContext.isRestrictUserOperationLogToAuthenticatedUsers(); commandContext.disableUserOperationLog(); commandContext.setRestrictUserOperationLogToAuthenticatedUsers(true); try { commandContext.getProcessEngineConfiguration() .getHistoryService() .deleteHistoricDecisionInstancesBulk(batchConfiguration.getIds()); } finally { commandContext.enableUserOperationLog(); commandContext.setRestrictUserOperationLogToAuthenticatedUsers(initialLegacyRestrictions); } commandContext.getByteArrayManager().delete(configurationEntity); }
Example #12
Source File: DeleteUserPictureCmd.java From camunda-bpm-platform with Apache License 2.0 | 6 votes |
public Void execute(CommandContext commandContext) { ensureNotNull("UserId", userId); IdentityInfoEntity infoEntity = commandContext.getIdentityInfoManager() .findUserInfoByUserIdAndKey(userId, "picture"); if(infoEntity != null) { String byteArrayId = infoEntity.getValue(); if(byteArrayId != null) { commandContext.getByteArrayManager() .deleteByteArrayById(byteArrayId); } commandContext.getIdentityInfoManager() .delete(infoEntity); } return null; }
Example #13
Source File: DeleteHistoricProcessInstancesJobHandler.java From camunda-bpm-platform with Apache License 2.0 | 6 votes |
@Override public void execute(BatchJobConfiguration configuration, ExecutionEntity execution, CommandContext commandContext, String tenantId) { ByteArrayEntity configurationEntity = commandContext .getDbEntityManager() .selectById(ByteArrayEntity.class, configuration.getConfigurationByteArrayId()); BatchConfiguration batchConfiguration = readConfiguration(configurationEntity.getBytes()); boolean initialLegacyRestrictions = commandContext.isRestrictUserOperationLogToAuthenticatedUsers(); commandContext.disableUserOperationLog(); commandContext.setRestrictUserOperationLogToAuthenticatedUsers(true); try { HistoryService historyService = commandContext.getProcessEngineConfiguration().getHistoryService(); if(batchConfiguration.isFailIfNotExists()) { historyService.deleteHistoricProcessInstances(batchConfiguration.getIds()); }else { historyService.deleteHistoricProcessInstancesIfExists(batchConfiguration.getIds()); } } finally { commandContext.enableUserOperationLog(); commandContext.setRestrictUserOperationLogToAuthenticatedUsers(initialLegacyRestrictions); } commandContext.getByteArrayManager().delete(configurationEntity); }
Example #14
Source File: GetStartFormVariablesCmd.java From camunda-bpm-platform with Apache License 2.0 | 6 votes |
public VariableMap execute(final CommandContext commandContext) { StartFormData startFormData = commandContext.runWithoutAuthorization(new Callable<StartFormData>() { public StartFormData call() throws Exception { return new GetStartFormCmd(resourceId).execute(commandContext); } }); ProcessDefinition definition = startFormData.getProcessDefinition(); checkGetStartFormVariables((ProcessDefinitionEntity) definition, commandContext); VariableMap result = new VariableMapImpl(); for (FormField formField : startFormData.getFormFields()) { if(formVariableNames == null || formVariableNames.contains(formField.getId())) { result.put(formField.getId(), createVariable(formField, null)); } } return result; }
Example #15
Source File: UnlockJobCmd.java From camunda-bpm-platform with Apache License 2.0 | 6 votes |
public Void execute(CommandContext commandContext) { JobEntity job = getJob(); if (Context.getJobExecutorContext() == null) { EnsureUtil.ensureNotNull("Job with id " + jobId + " does not exist", "job", job); } else if (Context.getJobExecutorContext() != null && job == null) { // CAM-1842 // Job was acquired but does not exist anymore. This is not a problem. // It usually means that the job has been deleted after it was acquired which can happen if the // the activity instance corresponding to the job is cancelled. LOG.debugAcquiredJobNotFound(jobId); return null; } job.unlock(); return null; }
Example #16
Source File: TaskQueryImpl.java From camunda-bpm-platform with Apache License 2.0 | 6 votes |
@Override public List<Task> executeList(CommandContext commandContext, Page page) { ensureOrExpressionsEvaluated(); ensureVariablesInitialized(); checkQueryOk(); resetCachedCandidateGroups(); //check if candidateGroup and candidateGroups intersect if (getCandidateGroup() != null && getCandidateGroupsInternal() != null && getCandidateGroups().isEmpty()) { return Collections.emptyList(); } List<Task> taskList = commandContext .getTaskManager() .findTasksByQueryCriteria(this); if (initializeFormKeys) { for (Task task : taskList) { // initialize the form keys of the tasks ((TaskEntity) task).initializeFormKey(); } } return taskList; }
Example #17
Source File: CompetingHistoryCleanupAcquisitionTest.java From camunda-bpm-platform with Apache License 2.0 | 6 votes |
protected void clearDatabase() { deleteHistoryCleanupJobs(); processEngineConfiguration.getCommandExecutorTxRequired().execute(new Command<Void>() { public Void execute(CommandContext commandContext) { commandContext.getMeterLogManager() .deleteAll(); commandContext.getHistoricJobLogManager() .deleteHistoricJobLogsByHandlerType("history-cleanup"); return null; } }); }
Example #18
Source File: AcquireJobCmdUnitTest.java From camunda-bpm-platform with Apache License 2.0 | 6 votes |
@Before public void initCommand() { JobExecutor jobExecutor = mock(JobExecutor.class); when(jobExecutor.getMaxJobsPerAcquisition()).thenReturn(3); when(jobExecutor.getLockOwner()).thenReturn("test"); when(jobExecutor.getLockTimeInMillis()).thenReturn(5 * 60 * 1000); acquireJobsCmd = new AcquireJobsCmd(jobExecutor); commandContext = mock(CommandContext.class); DbEntityManager dbEntityManager = mock(DbEntityManager.class); when(commandContext.getDbEntityManager()).thenReturn(dbEntityManager); jobManager = mock(JobManager.class); when(commandContext.getJobManager()).thenReturn(jobManager); }
Example #19
Source File: MultiTenancyCommandTenantCheckTest.java From camunda-bpm-platform with Apache License 2.0 | 6 votes |
@Test public void disableAndEnableTenantCheckForCommand() { processEngineConfiguration.getCommandExecutorTxRequired().execute(new Command<Void>() { @Override public Void execute(CommandContext commandContext) { commandContext.disableTenantCheck(); assertThat(commandContext.getTenantManager().isTenantCheckEnabled(), is(false)); commandContext.enableTenantCheck(); assertThat(commandContext.getTenantManager().isTenantCheckEnabled(), is(true)); return null; } }); }
Example #20
Source File: HistoricBatchManager.java From camunda-bpm-platform with Apache License 2.0 | 6 votes |
public void addRemovalTimeById(String id, Date removalTime) { CommandContext commandContext = Context.getCommandContext(); commandContext.getHistoricIncidentManager() .addRemovalTimeToHistoricIncidentsByBatchId(id, removalTime); commandContext.getHistoricJobLogManager() .addRemovalTimeToJobLogByBatchId(id, removalTime); Map<String, Object> parameters = new HashMap<>(); parameters.put("id", id); parameters.put("removalTime", removalTime); getDbEntityManager() .updatePreserveOrder(HistoricBatchEntity.class, "updateHistoricBatchRemovalTimeById", parameters); }
Example #21
Source File: CaseInstanceQueryImpl.java From camunda-bpm-platform with Apache License 2.0 | 5 votes |
public List<CaseInstance> executeList(CommandContext commandContext, Page page) { checkQueryOk(); ensureVariablesInitialized(); return commandContext .getCaseExecutionManager() .findCaseInstanceByQueryCriteria(this, page); }
Example #22
Source File: DeleteHistoricProcessInstancesBatchCmd.java From camunda-bpm-platform with Apache License 2.0 | 5 votes |
@Override public Batch execute(CommandContext commandContext) { BatchElementConfiguration elementConfiguration = collectHistoricProcessInstanceIds(commandContext); ensureNotEmpty(BadUserRequestException.class, "historicProcessInstanceIds", elementConfiguration.getIds()); return new BatchBuilder(commandContext) .type(Batch.TYPE_HISTORIC_PROCESS_INSTANCE_DELETION) .config(getConfiguration(elementConfiguration)) .permission(BatchPermissions.CREATE_BATCH_DELETE_FINISHED_PROCESS_INSTANCES) .operationLogHandler(this::writeUserOperationLog) .build(); }
Example #23
Source File: AbstractExecuteFilterCmd.java From camunda-bpm-platform with Apache License 2.0 | 5 votes |
protected Query<?, ?> getFilterQuery(CommandContext commandContext) { Filter filter = getFilter(commandContext); Query<?, ?> query = filter.getQuery(); if (query instanceof TaskQuery) { ((TaskQuery) query).initializeFormKeys(); } return query; }
Example #24
Source File: ProcessDiagramParseTest.java From camunda-bpm-platform with Apache License 2.0 | 5 votes |
@Test public void testXxeParsingIsDisabled() { processEngineConfiguration.setEnableXxeProcessing(false); try { final InputStream bpmnXmlStream = new FileInputStream( resourcePath + ".bpmn20.xml"); final InputStream imageStream = new FileInputStream( resourcePath + ".png"); assertNotNull(bpmnXmlStream); // when we run this in the ProcessEngine context engineRule.getProcessEngineConfiguration() .getCommandExecutorTxRequired() .execute(new Command<DiagramLayout>() { @Override public DiagramLayout execute(CommandContext commandContext) { return new ProcessDiagramLayoutFactory().getProcessDiagramLayout(bpmnXmlStream, imageStream); } }); fail("The test model contains a DOCTYPE declaration! The test should fail."); } catch (FileNotFoundException ex) { fail("The test BPMN model file is missing. " + ex.getMessage()); } catch (Exception e) { // then assertThat(e.getMessage(), containsString("Error while parsing BPMN model")); assertThat(e.getCause().getMessage(), containsString("http://apache.org/xml/features/disallow-doctype-decl")); } }
Example #25
Source File: AbstractMigrationCmd.java From camunda-bpm-platform with Apache License 2.0 | 5 votes |
protected ProcessDefinitionEntity resolveTargetProcessDefinition(CommandContext commandContext) { String targetProcessDefinitionId = executionBuilder.getMigrationPlan() .getTargetProcessDefinitionId(); ProcessDefinitionEntity sourceProcessDefinition = getProcessDefinition(commandContext, targetProcessDefinitionId); EnsureUtil.ensureNotNull("sourceProcessDefinition", sourceProcessDefinition); return sourceProcessDefinition; }
Example #26
Source File: HistoryLevelSetupCommand.java From camunda-bpm-platform with Apache License 2.0 | 5 votes |
public static void dbCreateHistoryLevel(CommandContext commandContext) { ProcessEngineConfigurationImpl processEngineConfiguration = Context.getProcessEngineConfiguration(); HistoryLevel configuredHistoryLevel = processEngineConfiguration.getHistoryLevel(); PropertyEntity property = new PropertyEntity("historyLevel", Integer.toString(configuredHistoryLevel.getId())); commandContext.getSession(DbEntityManager.class).insert(property); LOG.creatingHistoryLevelPropertyInDatabase(configuredHistoryLevel); }
Example #27
Source File: AbstractRemovalTimeTest.java From camunda-bpm-platform with Apache License 2.0 | 5 votes |
protected void clearAttachment(final Attachment attachment) { CommandExecutor commandExecutor = engineRule.getProcessEngineConfiguration().getCommandExecutorTxRequired(); commandExecutor.execute(new Command<Object>() { public Object execute(CommandContext commandContext) { commandContext.getAttachmentManager().delete((AttachmentEntity) attachment); return null; } }); }
Example #28
Source File: DeploymentQueryImpl.java From camunda-bpm-platform with Apache License 2.0 | 5 votes |
@Override public long executeCount(CommandContext commandContext) { checkQueryOk(); return commandContext .getDeploymentManager() .findDeploymentCountByQueryCriteria(this); }
Example #29
Source File: DeleteGroupIdentityLinkCmd.java From camunda-bpm-platform with Apache License 2.0 | 5 votes |
@Override public Void execute(CommandContext commandContext) { super.execute(commandContext); PropertyChange propertyChange = new PropertyChange(type, null, groupId); commandContext.getOperationLogManager() .logLinkOperation(UserOperationLogEntry.OPERATION_TYPE_DELETE_GROUP_LINK, task, propertyChange); return null; }
Example #30
Source File: MigrateProcessInstanceCmd.java From camunda-bpm-platform with Apache License 2.0 | 5 votes |
public Void migrateProcessInstance(CommandContext commandContext, String processInstanceId, MigrationPlan migrationPlan, ProcessDefinitionEntity targetProcessDefinition) { ensureNotNull(BadUserRequestException.class, "Process instance id cannot be null", "process instance id", processInstanceId); final ExecutionEntity processInstance = commandContext.getExecutionManager() .findExecutionById(processInstanceId); ensureProcessInstanceExist(processInstanceId, processInstance); ensureOperationAllowed(commandContext, processInstance, targetProcessDefinition); ensureSameProcessDefinition(processInstance, migrationPlan.getSourceProcessDefinitionId()); MigratingProcessInstanceValidationReportImpl processInstanceReport = new MigratingProcessInstanceValidationReportImpl(); // Initialize migration: match migration instructions to activity instances and collect required entities ProcessEngineImpl processEngine = commandContext.getProcessEngineConfiguration() .getProcessEngine(); MigratingInstanceParser migratingInstanceParser = new MigratingInstanceParser(processEngine); final MigratingProcessInstance migratingProcessInstance = migratingInstanceParser.parse(processInstanceId, migrationPlan, processInstanceReport); validateInstructions(commandContext, migratingProcessInstance, processInstanceReport); if (processInstanceReport.hasFailures()) { throw LOGGER.failingMigratingProcessInstanceValidation(processInstanceReport); } executeInContext(() -> deleteUnmappedActivityInstances(migratingProcessInstance), migratingProcessInstance.getSourceDefinition()); executeInContext(() -> migrateProcessInstance(migratingProcessInstance), migratingProcessInstance.getTargetDefinition()); return null; }