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

The following examples show how to use org.activiti.engine.delegate.DelegateExecution#getVariable() . 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 Project: activiti6-boot2   File: While.java    License: Apache License 2.0 6 votes vote down vote up
public void execute(DelegateExecution execution) {
  ActivityExecution activityExecution = (ActivityExecution) execution;
  PvmTransition more = activityExecution.getActivity().findOutgoingTransition("more");
  PvmTransition done = activityExecution.getActivity().findOutgoingTransition("done");
  
  Integer value = (Integer) execution.getVariable(variableName);

  if (value==null) {
    execution.setVariable(variableName, from);
    activityExecution.take(more);
    
  } else {
    value = value+1;
    
    if (value<to) {
      execution.setVariable(variableName, value);
      activityExecution.take(more);
      
    } else {
      activityExecution.take(done);
    }
  }
}
 
Example 2
Source Project: oneops   File: CMSClient.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Check dpmt.
 *
 * @param exec the exec
 * @throws GeneralSecurityException the general security exception
 */
public void checkDpmt(DelegateExecution exec) throws GeneralSecurityException {
    CmsDeployment dpmt = (CmsDeployment) exec.getVariable(DPMT);
    try {
        //CmsDeployment cmsDpmt = retryTemplate.execute(retryContext -> restTemplate.getForObject(serviceUrl + "dj/simple/deployments/{deploymentId}", CmsDeployment.class, dpmt.getDeploymentId()));
    	CmsDeployment cmsDpmt = cmsDpmtProcessor.getDeployment(dpmt.getDeploymentId());
    	if (cmsDpmt == null) {
    		throw new DJException(CmsError.DJ_NO_DEPLOYMENT_WITH_GIVEN_ID_ERROR,"Cant get deployment with id = " + dpmt.getDeploymentId());
    	}
        exec.setVariable(DPMT, cmsDpmt);
    } catch (CmsBaseException e) {
        logger.error("CmsBaseException on check deployment state : dpmtId=" + dpmt.getDeploymentId(), e);
        logger.error(e.getMessage());
        String descr = dpmt.getDescription();
        if (descr == null) {
            descr = "";
        }
        descr += "\n Can not check deployment state for dpmtId : " + dpmt.getDeploymentId() + ";\n " + e.getMessage();
        dpmt.setDeploymentState(FAILED);
        dpmt.setDescription(descr);
        exec.setVariable(DPMT, dpmt);
    }
}
 
Example 3
/**
 * Checks a valid Fully Authenticated User is set.
 * If none is set then attempts to set the workflow owner
 * @param execution the execution
 * @return <code>true</code> if the Fully Authenticated User was changed, otherwise <code>false</code>.
 */
private boolean checkFullyAuthenticatedUser(final DelegateExecution execution) 
{
    if (AuthenticationUtil.getFullyAuthenticatedUser() == null)
    {
        NamespaceService namespaceService = getServiceRegistry().getNamespaceService();
        WorkflowQNameConverter qNameConverter = new WorkflowQNameConverter(namespaceService);
        String ownerVariableName = qNameConverter.mapQNameToName(ContentModel.PROP_OWNER);
        
        String userName = (String) execution.getVariable(ownerVariableName);
        if (userName != null)
        {
            AuthenticationUtil.setFullyAuthenticatedUser(userName);
            return true;
        }
    }
    return false;
}
 
Example 4
@Override
public void execute(DelegateExecution execution) {
  Object throwException = execution.getVariable(execution.getCurrentActivityId());

  if (throwException != null && (boolean) throwException) {
    throw new ActivitiException("throwException was true");
  }

  if (injectedVar != null && injectedVar.getValue(execution) != null) {
    execution.setVariable("injectedExecutionVariable", injectedVar.getValue(execution));
  }
}
 
Example 5
Source Project: activiti6-boot2   File: Decision.java    License: Apache License 2.0 5 votes vote down vote up
public void execute(DelegateExecution execution) {
  PvmTransition transition;
  ActivityExecution activityExecution = (ActivityExecution) execution;
  String creditRating = (String) execution.getVariable("creditRating");
  if (creditRating.equals("AAA+")) {
    transition = activityExecution.getActivity().findOutgoingTransition("wow");
  } else if (creditRating.equals("Aaa-")) {
    transition = activityExecution.getActivity().findOutgoingTransition("nice");
  } else {
    transition = activityExecution.getActivity().findOutgoingTransition("default");
  }

  activityExecution.take(transition);
}
 
Example 6
@Override
public void notify(DelegateExecution execution) {
	Integer loopCounter = (Integer) execution.getVariable(LOOP_COUNTER_KEY);
	if (loopCounter != null) {
		countWithLoopCounter.incrementAndGet();
	} else{
		countWithoutLoopCounter.incrementAndGet();
	}
}
 
Example 7
public void notify(DelegateExecution execution) {
  String persistentVar1 = (String) execution.getVariable("persistentVar1");
  
  Object unusedTransientVar = execution.getVariable("unusedTransientVar");
  if (unusedTransientVar != null) {
    throw new RuntimeException("Unused transient var should have been deleted");
  }
  
  String secondTransientVar = (String) execution.getVariable("secondTransientVar");
  Number thirdTransientVar = (Number) execution.getTransientVariable("thirdTransientVar");
  
  String combinedVar = persistentVar1 + secondTransientVar + thirdTransientVar.intValue();
  execution.setVariable("combinedVar", combinedVar);
}
 
Example 8
/***
 * @param execution - the request to execute on
 * @throws Exception - if the revocation fails
 */
public void execute(DelegateExecution execution) throws Exception{
    Job job = managementService.createJobQuery().processInstanceId(execution.getProcessInstanceId()).singleResult();
    AccessRequest accessRequest = (AccessRequest)execution.getVariable("accessRequest");
    try {
        AWSEnvironment awsEnvironment = new AWSEnvironment(accessRequest.getAccount(), accessRequest.getRegion(), accessRequest.getAccountSdlc());
        logger.info("Revoking access for Users, Attempts remaining: " + job.getRetries());
        for(User user : accessRequest.getUsers()){
            for(UserRole role : accessRequest.getRoles()) {
                AWSRdsDatabase database = accessRequest.getAwsRdsInstances().get(0);
                // if the db was actually an aurora global cluster then we should re-fetch the primary cluster
                // as that could have changed
                if(database.getDatabaseType() != null && database.getDatabaseType() == DatabaseType.AURORA_GLOBAL){
                    logger.info("Re-fetching the Primary Cluster for this global cluster since it could have changed over time.");
                    DBCluster primaryCluster = rdsLookupService.getPrimaryClusterForGlobalCluster(awsEnvironment, database.getName()).get();
                    database.setEndpoint(String.format("%s:%s", primaryCluster.getEndpoint(), primaryCluster.getPort()));
                }
                databaseConnectionService.revokeAccess(database, awsEnvironment, RoleType.valueOf(role.getRole().toUpperCase()), user.getUserId());
            }
        }

    }catch(Exception e){
        if(job.getRetries() - 1 == 0){
            logger.error("Maximum attempt limit reached. Notify Ops team for manual removal");
            emailServiceWrapper.notifyOps(accessRequest);
            emailServiceWrapper.notifyAdminsOfFailure(accessRequest,e);
        }else{
            throw e;
        }
    }
}
 
Example 9
protected Object resolveCollection(DelegateExecution execution) {
  Object collection = null;
  if (collectionExpression != null) {
    collection = collectionExpression.getValue(execution);

  } else if (collectionVariable != null) {
    collection = execution.getVariable(collectionVariable);
  }
  return collection;
}
 
Example 10
public void execute(DelegateExecution execution) {
  Integer executionsBeforeError = (Integer) execution.getVariable("executionsBeforeError");
  Integer executions = (Integer) execution.getVariable("executions");
  if (executions == null) {
    executions = 0;
  }
  executions++;
  if (executionsBeforeError == null || executionsBeforeError < executions) {
    throw new BpmnError("23", "This is a business fault, which can be caught by a BPMN Error Event.");
  } else {
    execution.setVariable("executions", executions);
  }
}
 
Example 11
@Override
public void evaluate(DelegateExecution execution) {
  MessageInstance message = (MessageInstance) execution.getVariable(WebServiceActivityBehavior.CURRENT_MESSAGE);
  if (message.getStructureInstance() instanceof FieldBaseStructureInstance) {
    FieldBaseStructureInstance structure = (FieldBaseStructureInstance) message.getStructureInstance();
    execution.setVariable(this.getTarget(), structure.getFieldValue(this.getSource()));
  }
}
 
Example 12
Source Project: activiti6-boot2   File: FailingDelegate.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void execute(DelegateExecution execution) {
  Boolean fail = (Boolean) execution.getVariable("fail");

  if (fail == null || fail) {
      throw new ActivitiException(EXCEPTION_MESSAGE);
  }

}
 
Example 13
public void notify(DelegateExecution execution) {
	
	Integer loopCounter = (Integer) execution.getVariable("loopCounter");
	if (loopCounter != null) {
	
   Integer counter = (Integer) execution.getVariable("executionListenerCounter");
   if (counter == null) {
     counter = 0;
   }
   execution.setVariable("executionListenerCounter", ++counter);
   
	}
}
 
Example 14
Source Project: oneops   File: CMSClient.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Gets the work orders.
 *
 * @param exec the exec
 * @return the work orders
 * @throws GeneralSecurityException the general security exception
 */
public void getWorkOrderIds(DelegateExecution exec) {
    CmsDeployment dpmt = (CmsDeployment) exec.getVariable(DPMT);
    Integer execOrder = (Integer) exec.getVariable(CmsConstants.EXEC_ORDER);
    long startTime = System.currentTimeMillis();
    try {
        // if not - resubmit them, this is not normal situation but sometimes activiti completes subprocess
        // without calling final step, not sure how or why
        List<CmsWorkOrderSimple> recList = null;
        boolean pendingList = false;
        recList = cmsWoProvider.getWorkOrderIdsSimple(dpmt.getDeploymentId(), "inprogress", execOrder, this.stepWoLimit);
        if (recList.size() == 0) {
          pendingList= true;
        	recList = cmsWoProvider.getWorkOrderIdsSimple(dpmt.getDeploymentId(), "pending", execOrder, this.stepWoLimit);
        }
        logger.info(dpmt.getDeploymentId()+"-"+execOrder +" Got workOrderIds size: " + recList.size()
            + " took " +(System.currentTimeMillis()-startTime) +"ms pendingList "+ pendingList );
        exec.setVariable("dpmtrecs", recList);
    } catch (CmsBaseException e) {
        logger.error(dpmt.getDeploymentId()+"-"+execOrder +" CmsException :", e);
        String descr = dpmt.getDescription();
        if (descr == null) {
            descr = "";
        }
        descr += "\n Can not get workorderIds for step #" + execOrder + ";\n " + e.getMessage();
        handleWoError2(exec, dpmt, descr);
    }
}
 
Example 15
Source Project: activiti6-boot2   File: VariablesTest.java    License: Apache License 2.0 4 votes vote down vote up
public void execute(DelegateExecution execution) {
	String value = (String) execution.getVariable("testVar2");
	String localVarValue = (String) execution.getVariableLocal("localValue");
	execution.setVariableLocal("testVar2", value + localVarValue);
}
 
Example 16
Source Project: activiti6-boot2   File: VariablesTest.java    License: Apache License 2.0 4 votes vote down vote up
public void execute(DelegateExecution execution) {
  String var = (String) execution.getVariable("testVar", false);
  execution.setVariable("testVar", var + " 1 2 3");
}
 
Example 17
protected Expression getExpression(DelegateExecution execution, Expression var) {
  String variable = (String) execution.getVariable(var.getExpressionText());
  return Context.getProcessEngineConfiguration().getExpressionManager().createExpression(variable);
}
 
Example 18
Source Project: activiti6-boot2   File: ToUppercase.java    License: Apache License 2.0 4 votes vote down vote up
public void execute(DelegateExecution execution) {
  String var = (String) execution.getVariable(VARIABLE_NAME);
  var = var.toUpperCase();
  execution.setVariable(VARIABLE_NAME, var);
}
 
Example 19
Source Project: activiti6-boot2   File: CustomFlowBean.java    License: Apache License 2.0 4 votes vote down vote up
public boolean executeLogic(String flowId, DelegateExecution execution) {
  Object conditionsObject = execution.getVariable(flowId + "_activiti_conditions");
  return conditionsObject != null;
}
 
Example 20
Source Project: activiti6-boot2   File: ToUppercase.java    License: Apache License 2.0 4 votes vote down vote up
public void execute(DelegateExecution execution) {
  String var = (String) execution.getVariable(VARIABLE_NAME);
  var = var.toUpperCase();
  execution.setVariable(VARIABLE_NAME, var);
}