Java Code Examples for org.camunda.bpm.engine.impl.context.Context#getCurrentProcessApplication()

The following examples show how to use org.camunda.bpm.engine.impl.context.Context#getCurrentProcessApplication() . 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: ProcessApplicationEventListenerDelegate.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
protected void notifyExecutionListener(DelegateExecution execution) throws Exception {
  ProcessApplicationReference processApp = Context.getCurrentProcessApplication();
  try {
    ProcessApplicationInterface processApplication = processApp.getProcessApplication();
    ExecutionListener executionListener = processApplication.getExecutionListener();
    if(executionListener != null) {
      executionListener.notify(execution);

    } else {
      LOG.paDoesNotProvideExecutionListener(processApp.getName());

    }
  } catch (ProcessApplicationUnavailableException e) {
    // Process Application unavailable => ignore silently
    LOG.cannotInvokeListenerPaUnavailable(processApp.getName(), e);
  }
}
 
Example 2
Source File: ProcessApplicationEventListenerDelegate.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
protected void notifyTaskListener(DelegateTask task) throws Exception {
  ProcessApplicationReference processApp = Context.getCurrentProcessApplication();
  try {
    ProcessApplicationInterface processApplication = processApp.getProcessApplication();
    TaskListener taskListener = processApplication.getTaskListener();
    if(taskListener != null) {
      taskListener.notify(task);

    } else {
      LOG.paDoesNotProvideTaskListener(processApp.getName());

    }
  } catch (ProcessApplicationUnavailableException e) {
    // Process Application unavailable => ignore silently
    LOG.cannotInvokeListenerPaUnavailable(processApp.getName(), e);
  }
}
 
Example 3
Source File: ProcessDataContext.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
/**
 * Start a new section that keeps track of the pushed properties.
 *
 * If logging context properties are defined, the MDC is updated as well. This
 * also includes clearing the MDC for the first section that is pushed for the
 * logging context so that only the current properties will be present in the
 * MDC (might be less than previously present in the MDC). The previous
 * logging context needs to be reset in the MDC when this one is closed. This
 * can be achieved by using {@link #updateMdc(String)} with the previous
 * logging context.
 *
 * @param execution
 *          the execution to retrieve the context data from
 *
 * @return <code>true</code> if the section contains any updates and therefore
 *         should be popped later by {@link #popSection()}
 */
public boolean pushSection(ExecutionEntity execution) {
  if (handleMdc && propertyValues.isEmpty()) {
    clearMdc();
  }
  startNewSection = true;
  addToStack(execution.getActivityId(), PROPERTY_ACTIVITY_ID, mdcPropertyActivityId != null);
  addToStack(execution.getProcessDefinitionId(), mdcPropertyDefinitionId);
  addToStack(execution.getProcessInstanceId(), mdcPropertyInstanceId);
  addToStack(execution.getTenantId(), mdcPropertyTenantId);

  if (isNotBlank(mdcPropertyApplicationName)) {
    ProcessApplicationReference currentPa = Context.getCurrentProcessApplication();
    if (currentPa != null) {
      addToStack(currentPa.getName(), mdcPropertyApplicationName);
    }
  }

  if (isNotBlank(mdcPropertyBusinessKey)) {
    addToStack(execution.getBusinessKey(), mdcPropertyBusinessKey);
  }

  return !startNewSection;
}
 
Example 4
Source File: ScriptingEngines.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
/**
 * Loads the given script engine by language name. Will throw an exception if no script engine can be loaded for the given language name.
 *
 * @param language the name of the script language to lookup an implementation for
 * @return the script engine
 * @throws ProcessEngineException if no such engine can be found.
 */
public ScriptEngine getScriptEngineForLanguage(String language) {

  if (language != null) {
    language = language.toLowerCase();
  }

  ProcessApplicationReference pa = Context.getCurrentProcessApplication();
  ProcessEngineConfigurationImpl config = Context.getProcessEngineConfiguration();

  ScriptEngine engine = null;
  if (config.isEnableFetchScriptEngineFromProcessApplication()) {
    if(pa != null) {
      engine = getPaScriptEngine(language, pa);
    }
  }

  if(engine == null) {
    engine = getGlobalScriptEngine(language);
  }

  return engine;
}
 
Example 5
Source File: TypedValueField.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
protected static VariableSerializers getCurrentPaSerializers() {
  if (Context.getCurrentProcessApplication() != null) {
    ProcessApplicationReference processApplicationReference = Context.getCurrentProcessApplication();
    try {
      ProcessApplicationInterface processApplicationInterface = processApplicationReference.getProcessApplication();

      ProcessApplicationInterface rawPa = processApplicationInterface.getRawObject();
      if (rawPa instanceof AbstractProcessApplication) {
        return ((AbstractProcessApplication) rawPa).getVariableSerializers();
      }
      else {
        return null;
      }
    } catch (ProcessApplicationUnavailableException e) {
      throw LOG.cannotDeterminePaDataformats(e);
    }
  }
  else {
    return null;
  }
}
 
Example 6
Source File: ProcessApplicationBeanElResolverDelegate.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
protected ELResolver getElResolverDelegate() {

    ProcessApplicationReference processApplicationReference = Context.getCurrentProcessApplication();
    if(processApplicationReference != null) {

      try {
        ProcessApplicationInterface processApplication = processApplicationReference.getProcessApplication();
        return processApplication.getBeanElResolver();

      } catch (ProcessApplicationUnavailableException e) {
        throw new ProcessEngineException("Cannot access process application '"+processApplicationReference.getName()+"'", e);
      }

    } else {
      return new BeanELResolver();
    }

  }
 
Example 7
Source File: ProcessApplicationElResolverDelegate.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
protected ELResolver getElResolverDelegate() {

    ProcessApplicationReference processApplicationReference = Context.getCurrentProcessApplication();
    if(processApplicationReference != null) {

      try {
        ProcessApplicationInterface processApplication = processApplicationReference.getProcessApplication();
        return processApplication.getElResolver();

      } catch (ProcessApplicationUnavailableException e) {
        throw new ProcessEngineException("Cannot access process application '"+processApplicationReference.getName()+"'", e);
      }

    } else {
      return null;
    }

  }
 
Example 8
Source File: ScriptingEnvironment.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
protected Map<String, List<ExecutableScript>> getEnv(String language) {
  ProcessEngineConfigurationImpl config = Context.getProcessEngineConfiguration();
  ProcessApplicationReference processApplication = Context.getCurrentProcessApplication();

  Map<String, List<ExecutableScript>> result = null;
  if (config.isEnableFetchScriptEngineFromProcessApplication()) {
    if(processApplication != null) {
      result = getPaEnvScripts(processApplication);
    }
  }

  return result != null ? result : env;
}
 
Example 9
Source File: AtomicOperationInvocation.java    From camunda-bpm-platform with Apache License 2.0 4 votes vote down vote up
public void execute(BpmnStackTrace stackTrace, ProcessDataContext processDataContext) {

    if(operation != PvmAtomicOperation.ACTIVITY_START_CANCEL_SCOPE
       && operation != PvmAtomicOperation.ACTIVITY_START_INTERRUPT_SCOPE
       && operation != PvmAtomicOperation.ACTIVITY_START_CONCURRENT
       && operation != PvmAtomicOperation.DELETE_CASCADE) {
      // execution might be replaced in the meantime:
      ExecutionEntity replacedBy = execution.getReplacedBy();
      if(replacedBy != null) {
        execution = replacedBy;
      }
    }

    //execution was canceled for example via terminate end event
    if (execution.isCanceled() &&
         (operation == PvmAtomicOperation.TRANSITION_NOTIFY_LISTENER_END
         || operation == PvmAtomicOperation.ACTIVITY_NOTIFY_LISTENER_END)) {
      return;
    }

    // execution might have ended in the meanwhile
    if(execution.isEnded() &&
        (operation == PvmAtomicOperation.TRANSITION_NOTIFY_LISTENER_TAKE
        || operation == PvmAtomicOperation.ACTIVITY_START_CREATE_SCOPE)) {
      return;
    }

    ProcessApplicationReference currentPa = Context.getCurrentProcessApplication();
    if(currentPa != null) {
      applicationContextName = currentPa.getName();
    }
    activityId = execution.getActivityId();
    activityName = execution.getCurrentActivityName();
    stackTrace.add(this);


    boolean popProcessDataContextSection = processDataContext.pushSection(execution);

    try {
      Context.setExecutionContext(execution);
      if(!performAsync) {
        LOG.debugExecutingAtomicOperation(operation, execution);
        operation.execute(execution);
      }
      else {
        execution.scheduleAtomicOperationAsync(this);
      }
      if (popProcessDataContextSection) {
        processDataContext.popSection();
      }
    } finally {
      Context.removeExecutionContext();
    }
  }