Java Code Examples for org.camunda.bpm.engine.impl.persistence.entity.ProcessDefinitionEntity#findActivity()

The following examples show how to use org.camunda.bpm.engine.impl.persistence.entity.ProcessDefinitionEntity#findActivity() . 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: DebugSessionImpl.java    From camunda-bpm-workbench with GNU Affero General Public License v3.0 6 votes vote down vote up
public Script getScript(String processDefinitionId, String activityId) {
  ProcessDefinitionEntity processDefinition =
    (ProcessDefinitionEntity) getProcessEngine().getRepositoryService().getProcessDefinition(processDefinitionId);

  ActivityImpl activity = processDefinition.findActivity(activityId);

  ActivityBehavior activityBehavior = activity.getActivityBehavior();

  if (activityBehavior instanceof ScriptTaskActivityBehavior) {
    Script script = new Script();
    ExecutableScript taskScript = ((ScriptTaskActivityBehavior) activityBehavior).getScript();

    if (!(taskScript instanceof SourceExecutableScript)) {
      throw new DebuggerException("Encountered non-source script");
    }

    SourceExecutableScript sourceScript = (SourceExecutableScript) taskScript;

    script.setScript(sourceScript.getScriptSource());
    script.setScriptingLanguage(sourceScript.getLanguage());

    return script;
  } else {
    throw new DebuggerException("Activity " + activityId + " is no script task");
  }
}
 
Example 2
Source File: DebugSessionImpl.java    From camunda-bpm-workbench with GNU Affero General Public License v3.0 6 votes vote down vote up
public void updateScript(String processDefinitionId, String activityId, Script script) {
  ProcessDefinitionEntity processDefinition =
    (ProcessDefinitionEntity) getProcessEngine().getRepositoryService().getProcessDefinition(processDefinitionId);

  ActivityImpl activity = processDefinition.findActivity(activityId);

  ActivityBehavior activityBehavior = activity.getActivityBehavior();

  if (activityBehavior instanceof ScriptTaskActivityBehavior) {
    SourceExecutableScript taskScript = (SourceExecutableScript) ((ScriptTaskActivityBehavior) activityBehavior).getScript();
    taskScript.setScriptSource(script.getScript());
    // TODO set script language here
  } else {
    throw new DebuggerException("Activity " + activityId + " is no script task");
  }
}
 
Example 3
Source File: SignalEventHandler.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
protected void handleStartEvent(EventSubscriptionEntity eventSubscription, Map<String, Object> payload, String businessKey, CommandContext commandContext) {
  String processDefinitionId = eventSubscription.getConfiguration();
  ensureNotNull("Configuration of signal start event subscription '" + eventSubscription.getId() + "' contains no process definition id.",
      processDefinitionId);

  DeploymentCache deploymentCache = Context.getProcessEngineConfiguration().getDeploymentCache();
  ProcessDefinitionEntity processDefinition = deploymentCache.findDeployedProcessDefinitionById(processDefinitionId);
  if (processDefinition == null || processDefinition.isSuspended()) {
    // ignore event subscription
    LOG.debugIgnoringEventSubscription(eventSubscription, processDefinitionId);
  } else {
    ActivityImpl signalStartEvent = processDefinition.findActivity(eventSubscription.getActivityId());
    PvmProcessInstance processInstance = processDefinition.createProcessInstance(businessKey, signalStartEvent);
    processInstance.start(payload);
  }
}
 
Example 4
Source File: DefaultJobRetryCmd.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
protected ActivityImpl getCurrentActivity(CommandContext commandContext, JobEntity job) {
  String type = job.getJobHandlerType();
  ActivityImpl activity = null;

  if (SUPPORTED_TYPES.contains(type)) {
    DeploymentCache deploymentCache = Context.getProcessEngineConfiguration().getDeploymentCache();
    ProcessDefinitionEntity processDefinitionEntity =
        deploymentCache.findDeployedProcessDefinitionById(job.getProcessDefinitionId());
    activity = processDefinitionEntity.findActivity(job.getActivityId());

  } else {
    // noop, because activity type is not supported
  }

  return activity;
}
 
Example 5
Source File: LegacyBehavior.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
/**
 * When deploying an async job definition for an activity wrapped in an miBody, set the activity id to the
 * miBody except the wrapped activity is marked as async.
 *
 * Background: in <= 7.2 async job definitions were created for the inner activity, although the
 * semantics are that they are executed before the miBody is entered
 */
public static void migrateMultiInstanceJobDefinitions(ProcessDefinitionEntity processDefinition, List<JobDefinitionEntity> jobDefinitions) {
  for (JobDefinitionEntity jobDefinition : jobDefinitions) {

    String activityId = jobDefinition.getActivityId();
    if (activityId != null) {
      ActivityImpl activity = processDefinition.findActivity(jobDefinition.getActivityId());

      if (!isAsync(activity) && isActivityWrappedInMultiInstanceBody(activity) && isAsyncJobDefinition(jobDefinition)) {
        jobDefinition.setActivityId(activity.getFlowScope().getId());
      }
    }
  }
}
 
Example 6
Source File: EvaluateStartConditionCmd.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
protected ProcessInstance instantiateProcess(CommandContext commandContext, ConditionHandlerResult result) {
  ProcessDefinitionEntity processDefinitionEntity = result.getProcessDefinition();

  ActivityImpl startEvent = processDefinitionEntity.findActivity(result.getActivity().getActivityId());
  ExecutionEntity processInstance = processDefinitionEntity.createProcessInstance(builder.getBusinessKey(), startEvent);
  processInstance.start(builder.getVariables());

  return processInstance;
}
 
Example 7
Source File: SignalEventReceivedCmd.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
private void startProcessInstances(List<EventSubscriptionEntity> startSignalEventSubscriptions, Map<String, ProcessDefinitionEntity> processDefinitions) {
  for (EventSubscriptionEntity signalStartEventSubscription : startSignalEventSubscriptions) {
    ProcessDefinitionEntity processDefinition = processDefinitions.get(signalStartEventSubscription.getId());
    if (processDefinition != null) {

      ActivityImpl signalStartEvent = processDefinition.findActivity(signalStartEventSubscription.getActivityId());
      PvmProcessInstance processInstance = processDefinition.createProcessInstanceForInitial(signalStartEvent);
      processInstance.start(builder.getVariables());
    }
  }
}
 
Example 8
Source File: SetProcessDefinitionVersionCmd.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
protected void validateAndSwitchVersionOfExecution(CommandContext commandContext, ExecutionEntity execution, ProcessDefinitionEntity newProcessDefinition) {
  // check that the new process definition version contains the current activity
  if (execution.getActivity() != null) {
    String activityId = execution.getActivity().getId();
    PvmActivity newActivity = newProcessDefinition.findActivity(activityId);

    if (newActivity == null) {
      throw new ProcessEngineException(
        "The new process definition " +
        "(key = '" + newProcessDefinition.getKey() + "') " +
        "does not contain the current activity " +
        "(id = '" + activityId + "') " +
        "of the process instance " +
        "(id = '" + processInstanceId + "').");
      }

      // clear cached activity so that outgoing transitions are refreshed
      execution.setActivity(newActivity);
    }

  // switch the process instance to the new process definition version
  execution.setProcessDefinition(newProcessDefinition);

  // and change possible existing tasks (as the process definition id is stored there too)
  List<TaskEntity> tasks = commandContext.getTaskManager().findTasksByExecutionId(execution.getId());
  for (TaskEntity taskEntity : tasks) {
    taskEntity.setProcessDefinitionId(newProcessDefinition.getId());
  }
}
 
Example 9
Source File: BpmnParseTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Deployment
@Test
public void testParseNamespaceInConditionExpressionType() {
  CommandExecutor commandExecutor = processEngineConfiguration.getCommandExecutorTxRequired();
  ProcessDefinitionEntity processDefinitionEntity = commandExecutor.execute(new Command<ProcessDefinitionEntity>() {
    @Override
    public ProcessDefinitionEntity execute(CommandContext commandContext) {
      return Context.getProcessEngineConfiguration().getDeploymentCache().findDeployedLatestProcessDefinitionByKey("resolvableNamespacesProcess");
    }
  });

  // Test that the process definition has been deployed
  assertNotNull(processDefinitionEntity);
  PvmActivity activity = processDefinitionEntity.findActivity("ExclusiveGateway_1");
  assertNotNull(activity);

  // Test that the conditions has been resolved
  for (PvmTransition transition : activity.getOutgoingTransitions()) {
    if (transition.getDestination().getId().equals("Task_2")) {
      assertTrue(transition.getProperty("conditionText").equals("#{approved}"));
    } else if (transition.getDestination().getId().equals("Task_3")) {
      assertTrue(transition.getProperty("conditionText").equals("#{!approved}"));
    } else {
      fail("Something went wrong");
    }

  }
}
 
Example 10
Source File: BpmnParseTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
protected ActivityImpl findActivityInDeployedProcessDefinition(String activityId) {
  ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().singleResult();
  assertNotNull(processDefinition);

  ProcessDefinitionEntity cachedProcessDefinition = processEngineConfiguration.getDeploymentCache()
                                                      .getProcessDefinitionCache()
                                                      .get(processDefinition.getId());
  return cachedProcessDefinition.findActivity(activityId);
}
 
Example 11
Source File: FoxFailedJobParseListenerTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
protected ActivityImpl findActivity(ProcessInstance pi, String activityId) {

    ProcessInstanceWithVariablesImpl entity = (ProcessInstanceWithVariablesImpl) pi;
    ProcessDefinitionEntity processDefEntity = entity.getExecutionEntity().getProcessDefinition();

    assertNotNull(processDefEntity);
    ActivityImpl activity = processDefEntity.findActivity(activityId);
    assertNotNull(activity);
    return activity;
  }
 
Example 12
Source File: AbstractCorrelateMessageCmd.java    From camunda-bpm-platform with Apache License 2.0 4 votes vote down vote up
protected ProcessInstance instantiateProcess(CommandContext commandContext, CorrelationHandlerResult correlationResult) {
  ProcessDefinitionEntity processDefinitionEntity = correlationResult.getProcessDefinitionEntity();

  ActivityImpl messageStartEvent = processDefinitionEntity.findActivity(correlationResult.getStartEventActivityId());
  ExecutionEntity processInstance = processDefinitionEntity.createProcessInstance(builder.getBusinessKey(), messageStartEvent);

  if (variablesEnabled) {
    variablesListener = new ExecutionVariableSnapshotObserver(processInstance, false, deserializeVariableValues);
  }

  VariableMap startVariables = resolveStartVariables();

  processInstance.start(startVariables);

  return processInstance;
}