Java Code Examples for org.activiti.engine.delegate.DelegateExecution#getVariables()

The following examples show how to use org.activiti.engine.delegate.DelegateExecution#getVariables() . 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: LogVariables.java    From herd with Apache License 2.0 6 votes vote down vote up
@Override
public void executeImpl(DelegateExecution execution) throws Exception
{
    // Get the REGEX parameter value.
    String regexValue = activitiHelper.getExpressionVariableAsString(regex, execution);

    // Loop through all process variables.
    Map<String, Object> variableMap = execution.getVariables();
    for (Map.Entry<String, Object> variableEntry : variableMap.entrySet())
    {
        // If a REGEX wasn't specified or if the variable key matches the REGEX, log the variable. Otherwise, skip it.
        if (StringUtils.isBlank(regexValue) || variableEntry.getKey().matches(regexValue))
        {
            LOGGER.info("{} Process Variable {}=\"{}\"", activitiHelper.getProcessIdentifyingInformation(execution), variableEntry.getKey(),
                variableEntry.getValue());
        }
    }
}
 
Example 2
Source File: ShopperDelegate.java    From Spring-MVC-Blueprints with MIT License 6 votes vote down vote up
@Override
public void execute(DelegateExecution exec) throws Exception {
	
	// Retrieve all objects from the @Controller containing the processes
	variables = exec.getVariables();
	System.out.println("Executed process with key "
			+ "" + exec.getProcessBusinessKey() 
			+ " with process definition ID: "
			+ "" + exec.getProcessDefinitionId()
			+ " with process instance ID: "
			+ "" + exec.getProcessInstanceId()
			+ " with current task name: "
			+ "" + exec.getCurrentActivityName()
			+ "");
			
}
 
Example 3
Source File: ResetPasswordServiceImpl.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public void sendResetPasswordConfirmationEmail(DelegateExecution execution, String fallbackEmailTemplatePath, String emailSubject)
{
    Map<String, Object> variables = execution.getVariables();
    final String userName = (String) variables.get(WorkflowModelResetPassword.WF_PROP_USERNAME_ACTIVITI);
    final String userEmail = (String) variables.get(WorkflowModelResetPassword.WF_PROP_USER_EMAIL_ACTIVITI);
    final String clientName = (String) variables.get(WorkflowModelResetPassword.WF_PROP_CLIENT_NAME_ACTIVITI);

    // Now notify the user
    final ClientApp clientApp = getClientAppConfig(clientName);
    Map<String, Serializable> emailTemplateModel = Collections.singletonMap(FTL_USER_NAME, userName);

    final String templatePath = emailHelper.getEmailTemplate(clientName,
                getConfirmResetPasswordEmailTemplate(clientApp),
                fallbackEmailTemplatePath);

    ResetPasswordEmailDetails emailRequest = new ResetPasswordEmailDetails()
                .setUserName(userName)
                .setUserEmail(userEmail)
                .setTemplatePath(templatePath)
                .setTemplateAssetsUrl(clientApp.getTemplateAssetsUrl())
                .setEmailSubject(emailSubject)
                .setTemplateModel(emailTemplateModel);

    sendEmail(emailRequest);
}
 
Example 4
Source File: DelegateExecutionScriptBase.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
protected Map<String, Object> getInputMap(DelegateExecution execution, String runAsUser) 
{
    HashMap<String, Object> scriptModel = new HashMap<String, Object>(1);
    
    // Add current logged-in user and it's user home
    ActivitiScriptNode personNode = getPersonNode(runAsUser);
    if (personNode != null)
    {
        ServiceRegistry registry = getServiceRegistry();
        scriptModel.put(PERSON_BINDING_NAME, personNode);
        NodeRef userHomeNode = (NodeRef) registry.getNodeService().getProperty(personNode.getNodeRef(), ContentModel.PROP_HOMEFOLDER);
        if (userHomeNode != null)
        {
            scriptModel.put(USERHOME_BINDING_NAME, new ActivitiScriptNode(userHomeNode, registry));
        }
    }
    
    // Add activiti-specific objects
    scriptModel.put(EXECUTION_BINDING_NAME, execution);

    // Add all workflow variables to model
    Map<String, Object> variables = execution.getVariables();
    
    for (Entry<String, Object> varEntry : variables.entrySet())
    {
        scriptModel.put(varEntry.getKey(), varEntry.getValue());
    }
    
    return scriptModel;
}
 
Example 5
Source File: CancelNominatedInviteDelegate.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void execute(DelegateExecution execution) throws Exception
{
    Map<String, Object> executionVariables = execution.getVariables();
    String currentInviteId = ActivitiConstants.ENGINE_ID + "$" + execution.getProcessInstanceId();

    // Get the invitee user name and site short name variables off the execution context
    String invitee = (String) executionVariables.get(wfVarInviteeUserName);
    String siteName = (String) executionVariables.get(wfVarResourceName);
    String inviteId = (String) executionVariables.get(wfVarWorkflowInstanceId);

    invitationService.cancelInvitation(siteName, invitee, inviteId, currentInviteId);
}
 
Example 6
Source File: AcceptNominatedInviteDelegate.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void execute(DelegateExecution execution) throws Exception
{
    Map<String, Object> executionVariables = execution.getVariables();
    String invitee = (String) executionVariables.get(WorkflowModelNominatedInvitation.wfVarInviteeUserName);
    String siteName = (String) executionVariables.get(WorkflowModelNominatedInvitation.wfVarResourceName);
    String inviter = (String) executionVariables.get(WorkflowModelNominatedInvitation.wfVarInviterUserName);
    String role = (String) executionVariables.get(WorkflowModelNominatedInvitation.wfVarRole);

    invitationService.acceptNominatedInvitation(siteName, invitee, role, inviter);
}
 
Example 7
Source File: SendNominatedInviteAddDirectDelegate.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void execute(DelegateExecution execution) throws Exception
{
    String invitationId = ActivitiConstants.ENGINE_ID + "$" + execution.getProcessInstanceId();
    Map<String, Object> variables = execution.getVariables();
    invitationService.sendNominatedInvitation(invitationId, EMAIL_TEMPLATE_XPATH, EMAIL_SUBJECT_KEY, variables);
}
 
Example 8
Source File: SendNominatedInviteDelegate.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void execute(DelegateExecution execution) throws Exception
{
    String invitationId = ActivitiConstants.ENGINE_ID + "$" + execution.getProcessInstanceId();
    Map<String, Object> variables = execution.getVariables();
    invitationService.sendNominatedInvitation(invitationId, EMAIL_TEMPLATE_XPATH, EMAIL_SUBJECT_KEY, variables);
}
 
Example 9
Source File: RejectModeratedInviteDelegate.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void execute(DelegateExecution execution) throws Exception
{
    Map<String, Object> vars = execution.getVariables();
    String siteName = (String) vars.get(WorkflowModelModeratedInvitation.wfVarResourceName);
    String invitee = (String) vars.get(WorkflowModelModeratedInvitation.wfVarInviteeUserName);
    String role = (String) vars.get(WorkflowModelModeratedInvitation.wfVarInviteeRole);
    String reviewer = (String) vars.get(WorkflowModelModeratedInvitation.wfVarReviewer);
    String resourceType = (String) vars.get(WorkflowModelModeratedInvitation.wfVarResourceType);
    String reviewComments = (String) vars.get(WorkflowModelModeratedInvitation.wfVarReviewComments);
    
    invitationService.rejectModeratedInvitation(siteName, invitee, role, reviewer, resourceType, reviewComments);
}
 
Example 10
Source File: SendModeratedInviteDelegate.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void execute(DelegateExecution execution) throws Exception
{
    String invitationId = ActivitiConstants.ENGINE_ID + "$" + execution.getProcessInstanceId();
    Map<String, Object> variables = execution.getVariables();
    invitationService.sendModeratedInvitation(invitationId, emailTemplatePath, EMAIL_SUBJECT_KEY, variables);
}
 
Example 11
Source File: ApproveModeratedInviteDelegate.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void execute(DelegateExecution execution) throws Exception
{
    Map<String, Object> variables = execution.getVariables();
    String siteName = (String) variables.get(WorkflowModelModeratedInvitation.wfVarResourceName);
    String invitee = (String) variables.get(WorkflowModelModeratedInvitation.wfVarInviteeUserName);
    String role = (String) variables.get(WorkflowModelModeratedInvitation.wfVarInviteeRole);
    String reviewer = (String) variables.get(WorkflowModelModeratedInvitation.wfVarReviewer);

    invitationService.approveModeratedInvitation(siteName, invitee, role, reviewer);
}
 
Example 12
Source File: CamelBehavior.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
protected Exchange createExchange(DelegateExecution activityExecution, ActivitiEndpoint endpoint) {
  Exchange ex = endpoint.createExchange();
  ex.setProperty(ActivitiProducer.PROCESS_ID_PROPERTY, activityExecution.getProcessInstanceId());
  ex.setProperty(ActivitiProducer.EXECUTION_ID_PROPERTY, activityExecution.getId());
  Map<String, Object> variables = activityExecution.getVariables();
  updateTargetVariables(endpoint);
  copyVariables(variables, ex, endpoint);
  return ex;
}
 
Example 13
Source File: ResetPasswordServiceImpl.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void sendResetPasswordEmail(DelegateExecution execution, String fallbackEmailTemplatePath, String emailSubject)
{
    Map<String, Object> variables = execution.getVariables();
    final String userName = (String) variables.get(WorkflowModelResetPassword.WF_PROP_USERNAME_ACTIVITI);
    final String toEmail = (String) variables.get(WorkflowModelResetPassword.WF_PROP_USER_EMAIL_ACTIVITI);
    final String clientName = (String) variables.get(WorkflowModelResetPassword.WF_PROP_CLIENT_NAME_ACTIVITI);
    final String key = (String) variables.get(WorkflowModelResetPassword.WF_PROP_KEY_ACTIVITI);
    final String id = execution.getProcessInstanceId();

    final ClientApp clientApp = getClientAppConfig(clientName);
    Map<String, Serializable> emailTemplateModel = Collections.singletonMap(FTL_RESET_PASSWORD_URL,
                createResetPasswordUrl(clientApp, id, key));

    final String templatePath = emailHelper.getEmailTemplate(clientName,
                getResetPasswordEmailTemplate(clientApp),
                fallbackEmailTemplatePath);

    ResetPasswordEmailDetails emailRequest = new ResetPasswordEmailDetails()
                .setUserName(userName)
                .setUserEmail(toEmail)
                .setTemplatePath(templatePath)
                .setTemplateAssetsUrl(clientApp.getTemplateAssetsUrl())
                .setEmailSubject(emailSubject)
                .setTemplateModel(emailTemplateModel);

    sendEmail(emailRequest);
}
 
Example 14
Source File: VariablesTest.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
public void execute(DelegateExecution execution) {
	Map<String, Object> vars = execution.getVariables(Arrays.asList("testVar1", "testVar2", "testVar3"), false);
	
	String testVar1 = (String) vars.get("testVar1");
	String testVar2 = (String) vars.get("testVar2");
	String testVar3 = (String) vars.get("testVar3");
	
	execution.setVariable("testVar1", testVar1 + "-CHANGED", false);
	execution.setVariable("testVar2", testVar2 + "-CHANGED", false);
	execution.setVariable("testVar3", testVar3 + "-CHANGED", false);
	
	execution.setVariableLocal("localVar", "localValue", false);
}
 
Example 15
Source File: VariablesTest.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
public void execute(DelegateExecution execution) {
  Map<String, Object> vars = execution.getVariables(Arrays.asList("testVar1", "testVar2", "testVar3"), false);

  String testVar1 = (String) vars.get("testVar1");
  String testVar2 = (String) vars.get("testVar2");
  String testVar3 = (String) vars.get("testVar3");

  execution.setVariable("testVar1", testVar1 + "-CHANGED", false);
  execution.setVariable("testVar2", testVar2 + "-CHANGED", false);
  execution.setVariable("testVar3", testVar3 + "-CHANGED", false);

  execution.setVariableLocal("localVar", "localValue", false);
}
 
Example 16
Source File: TransientVariablesTest.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
public void execute(DelegateExecution execution) {
  Map<String, Object> vars = execution.getVariables();
  List<String> varNames = new ArrayList<String>(vars.keySet());
  Collections.sort(varNames);
  
  StringBuilder strb = new StringBuilder();
  for (String varName : varNames) {
    strb.append(vars.get(varName));
  }
  
  execution.setVariable("result", strb.toString());
}
 
Example 17
Source File: ListenerNotificationHelper.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
protected void planTransactionDependentTaskListener(DelegateExecution execution, TransactionDependentTaskListener taskListener, ActivitiListener activitiListener) {
  Map<String, Object> executionVariablesToUse = execution.getVariables();
  CustomPropertiesResolver customPropertiesResolver = createCustomPropertiesResolver(activitiListener);
  Map<String, Object> customPropertiesMapToUse = invokeCustomPropertiesResolver(execution, customPropertiesResolver);
  
  TransactionDependentTaskListenerExecutionScope scope = new TransactionDependentTaskListenerExecutionScope(
      execution.getProcessInstanceId(), execution.getId(), (Task) execution.getCurrentFlowElement(), executionVariablesToUse, customPropertiesMapToUse);
  addTransactionListener(activitiListener, new ExecuteTaskListenerTransactionListener(taskListener, scope));
}
 
Example 18
Source File: ListenerNotificationHelper.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
protected void planTransactionDependentExecutionListener(ListenerFactory listenerFactory, DelegateExecution execution, TransactionDependentExecutionListener executionListener, ActivitiListener activitiListener) {
  Map<String, Object> executionVariablesToUse = execution.getVariables();
  CustomPropertiesResolver customPropertiesResolver = createCustomPropertiesResolver(activitiListener);
  Map<String, Object> customPropertiesMapToUse = invokeCustomPropertiesResolver(execution, customPropertiesResolver);

  TransactionDependentExecutionListenerExecutionScope scope = new TransactionDependentExecutionListenerExecutionScope(
      execution.getProcessInstanceId(), execution.getId(), execution.getCurrentFlowElement(), executionVariablesToUse, customPropertiesMapToUse);
  
  addTransactionListener(activitiListener, new ExecuteExecutionListenerTransactionListener(executionListener, scope));
}
 
Example 19
Source File: CallActivityBehavior.java    From activiti6-boot2 with Apache License 2.0 4 votes vote down vote up
public void execute(DelegateExecution execution) {
   
String processDefinitonKey = this.processDefinitonKey;
   if (processDefinitionExpression != null) {
     processDefinitonKey = (String) processDefinitionExpression.getValue(execution);
   }

   DeploymentManager deploymentManager = Context.getProcessEngineConfiguration().getDeploymentManager();
   
   ProcessDefinition processDefinition = null;
   if (execution.getTenantId() == null || ProcessEngineConfiguration.NO_TENANT_ID.equals(execution.getTenantId())) {
   	processDefinition = deploymentManager.findDeployedLatestProcessDefinitionByKey(processDefinitonKey);
   } else {
   	processDefinition = deploymentManager.findDeployedLatestProcessDefinitionByKeyAndTenantId(processDefinitonKey, execution.getTenantId());
   }

   // Do not start a process instance if the process definition is suspended
   if (deploymentManager.isProcessDefinitionSuspended(processDefinition.getId())) {
     throw new ActivitiException("Cannot start process instance. Process definition "
         + processDefinition.getName() + " (id = " + processDefinition.getId() + ") is suspended");
   }
   
   ActivityExecution activityExecution = (ActivityExecution) execution;
   PvmProcessInstance subProcessInstance = activityExecution.createSubProcessInstance((ProcessDefinitionEntity) processDefinition);
   
   if (inheritVariables) {
     Map<String, Object> variables = execution.getVariables();
     for (Map.Entry<String, Object> entry : variables.entrySet()) {
       subProcessInstance.setVariable(entry.getKey(), entry.getValue());
     }
   }
   
   // copy process variables
   for (AbstractDataAssociation dataInputAssociation : dataInputAssociations) {
     Object value = null;
     if (dataInputAssociation.getSourceExpression()!=null) {
       value = dataInputAssociation.getSourceExpression().getValue(execution);
     }
     else {
       value = execution.getVariable(dataInputAssociation.getSource());
     }
     subProcessInstance.setVariable(dataInputAssociation.getTarget(), value);
   }
   
   try {
     subProcessInstance.start();
   } catch (RuntimeException e) {
       if (!ErrorPropagation.mapException(e, activityExecution, mapExceptions, true))
           throw e;
       
     }
     
 }