本文整理匯總了Java中org.activiti.engine.runtime.ProcessInstance類的典型用法代碼示例。如果您正苦於以下問題:Java ProcessInstance類的具體用法?Java ProcessInstance怎麽用?Java ProcessInstance使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
ProcessInstance類屬於org.activiti.engine.runtime包,在下文中一共展示了ProcessInstance類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: startProcess
import org.activiti.engine.runtime.ProcessInstance; //導入依賴的package包/類
public ProcessInstance startProcess(String userId, String processDefinitionKey, Map<String, Object> variables) {
try {
engine.getIdentityService().setAuthenticatedUserId(userId);
// Get the last deployed version of the process and start a process instance
ProcessDefinitionQuery query = engine.getRepositoryService()
.createProcessDefinitionQuery()
.processDefinitionKey(processDefinitionKey)
.latestVersion();
String processDefinitionId = query.singleResult().getId();
ProcessInstance processInstance = engine.getRuntimeService().startProcessInstanceById(processDefinitionId, variables);
return processInstance;
} finally {
// After the setAuthenticatedUserId() method is invoked, all Activiti service methods
// executed within the current thread will have access to this userId. Just before
// leaving the method, the userId is set to null, preventing other services from using
// it unintentionally.
engine.getIdentityService().setAuthenticatedUserId(null);
}
}
示例2: getTaskForTimer
import org.activiti.engine.runtime.ProcessInstance; //導入依賴的package包/類
private WorkflowTask getTaskForTimer(Job job, ProcessInstance processInstance, Execution jobExecution)
{
if (job instanceof TimerEntity)
{
ReadOnlyProcessDefinition def = activitiUtil.getDeployedProcessDefinition(processInstance.getProcessDefinitionId());
List<String> activeActivityIds = runtimeService.getActiveActivityIds(jobExecution.getId());
if(activeActivityIds.size() == 1)
{
PvmActivity targetActivity = def.findActivity(activeActivityIds.get(0));
if(targetActivity != null)
{
// Only get tasks of active activity is a user-task
String activityType = (String) targetActivity.getProperty(ActivitiConstants.NODE_TYPE);
if(ActivitiConstants.USER_TASK_NODE_TYPE.equals(activityType))
{
Task task = taskService.createTaskQuery().executionId(job.getExecutionId()).singleResult();
return typeConverter.convert(task);
}
}
}
}
return null;
}
示例3: convert
import org.activiti.engine.runtime.ProcessInstance; //導入依賴的package包/類
public WorkflowPath convert(Execution execution, ProcessInstance instance)
{
if(execution == null)
return null;
boolean isActive = !execution.isEnded();
// Convert workflow and collect variables
Map<String, Object> workflowInstanceVariables = new HashMap<String, Object>();
WorkflowInstance wfInstance = convertAndSetVariables(instance, workflowInstanceVariables);
WorkflowNode node = null;
// Get active node on execution
List<String> nodeIds = runtimeService.getActiveActivityIds(execution.getId());
if (nodeIds != null && nodeIds.size() >= 1)
{
ReadOnlyProcessDefinition procDef = activitiUtil.getDeployedProcessDefinition(instance.getProcessDefinitionId());
PvmActivity activity = procDef.findActivity(nodeIds.get(0));
node = convert(activity);
}
return factory.createPath(execution.getId(), wfInstance, node, isActive);
}
示例4: buildCompletedPath
import org.activiti.engine.runtime.ProcessInstance; //導入依賴的package包/類
public WorkflowPath buildCompletedPath(String executionId, String processInstanceId)
{
WorkflowInstance wfInstance = null;
ProcessInstance processInstance = activitiUtil.getProcessInstance(processInstanceId);
if(processInstance != null)
{
wfInstance = convert(processInstance);
}
else
{
HistoricProcessInstance historicProcessInstance = activitiUtil.getHistoricProcessInstance(processInstanceId);
if(historicProcessInstance!= null)
wfInstance = convert(historicProcessInstance);
}
if(wfInstance == null)
{
// When workflow is cancelled or deleted, WorkflowPath should not be returned
return null;
}
WorkflowNode node = null;
return factory.createPath(executionId, wfInstance, node, false);
}
示例5: testGetWorkflowImage
import org.activiti.engine.runtime.ProcessInstance; //導入依賴的package包/類
@Test
public void testGetWorkflowImage()
{
WorkflowDefinition definitionWithoutImage = deployTestAdhocDefinition();
WorkflowDefinition definitionWithImage = deployTestDiagramDefinition();
// Start process-instance that shouldn't have an image
ProcessInstance processInstance = runtime.startProcessInstanceById(BPMEngineRegistry.getLocalId(definitionWithoutImage.getId()));
String worklfowId = BPMEngineRegistry.createGlobalId(ActivitiConstants.ENGINE_ID, processInstance.getId());
assertFalse(workflowEngine.hasWorkflowImage(worklfowId));
assertNull(workflowEngine.getWorkflowImage(worklfowId));
// Start process-instance that SHOULD have an image
ProcessInstance processInstanceWithImage = runtime.startProcessInstanceById(BPMEngineRegistry.getLocalId(definitionWithImage.getId()));
String worklfowWithImageId = BPMEngineRegistry.createGlobalId(ActivitiConstants.ENGINE_ID, processInstanceWithImage.getId());
assertTrue(workflowEngine.hasWorkflowImage(worklfowWithImageId));
assertNotNull(workflowEngine.getWorkflowImage(worklfowWithImageId));
}
示例6: create
import org.activiti.engine.runtime.ProcessInstance; //導入依賴的package包/類
@Override
public <S extends T> S create(S resource) {
checkFilter(resource, true);
String processDefinitionKey = resource.getProcessDefinitionKey();
String businessKey = resource.getBusinessKey();
String tenantId = resource.getTenantId();
Map<String, Object> variables = resourceMapper.mapToVariables(resource);
ProcessInstance processInstance =
runtimeService.startProcessInstanceByKeyAndTenantId(processDefinitionKey, businessKey, variables, tenantId);
applyUpdates(processInstance, resource);
return (S) findOne(processInstance.getId(), new QuerySpec(getResourceClass()));
}
示例7: save
import org.activiti.engine.runtime.ProcessInstance; //導入依賴的package包/類
@Override
public <S extends T> S save(S resource) {
checkFilter(resource, true);
ProcessInstance processInstance = runtimeService.createProcessInstanceQuery()
.processInstanceId(resource.getId())
.includeProcessVariables()
.singleResult();
if (processInstance == null) {
throw new ResourceNotFoundException(resource.getId());
}
checkFilter(processInstance, false);
checkActivate(processInstance, resource);
Map<String, Object> variables = resourceMapper.mapToVariables(resource);
runtimeService.setVariables(processInstance.getId(), variables);
applyUpdates(processInstance, resource);
return (S) findOne(processInstance.getId(), new QuerySpec(getResourceClass()));
}
示例8: checkProcessInstance
import org.activiti.engine.runtime.ProcessInstance; //導入依賴的package包/類
@Test
public void checkProcessInstance() {
Map<String, Object> variables = mapper.mapToVariables(processResource);
Assert.assertEquals(3, variables.size());
Assert.assertEquals("someString", variables.get("stringValue"));
Assert.assertEquals(13, variables.get("nestedBean.intValue"));
Assert.assertEquals(Boolean.TRUE, variables.get("booleanValue"));
TestProcess processCopy = new TestProcess();
mapper.mapFromVariables(processCopy, variables);
checkProcessResource(processCopy);
ProcessInstance processInstance = Mockito.mock(ProcessInstance.class);
Mockito.when(processInstance.getName()).thenReturn("someProcess");
Mockito.when(processInstance.getBusinessKey()).thenReturn("someBusinessKey");
Mockito.when(processInstance.getProcessVariables()).thenReturn(variables);
TestProcess processResourceCopy = mapper.mapToResource(TestProcess.class, processInstance);
checkProcessResource(processResourceCopy);
Assert.assertEquals("someProcess", processResourceCopy.getName());
Assert.assertEquals("someBusinessKey", processResourceCopy.getBusinessKey());
}
示例9: addProcessInstance
import org.activiti.engine.runtime.ProcessInstance; //導入依賴的package包/類
private ProcessInstance addProcessInstance() {
ScheduleApprovalValues newValues = new ScheduleApprovalValues();
newValues.setName("newName");
ScheduleApprovalProcessInstance resource = new ScheduleApprovalProcessInstance();
resource.setResourceType("schedules");
resource.setResourceId("12");
resource.setNewValues(newValues);
Map<String, Object> processVariables = resourceMapper.mapToVariables(resource);
runtimeService = processEngine.getRuntimeService();
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("scheduleChange",
"testBusinessKey", processVariables);
runtimeService.setProcessInstanceName(processInstance.getId(), "testName");
processInstance = runtimeService.createProcessInstanceQuery()
.processInstanceId(processInstance.getId())
.includeProcessVariables()
.singleResult();
return processInstance;
}
示例10: startProcess
import org.activiti.engine.runtime.ProcessInstance; //導入依賴的package包/類
public String startProcess(String userId, String businessKey,
String processDefinitionId, Map<String, Object> processParameters) {
// 先設置登錄用戶
IdentityService identityService = processEngine.getIdentityService();
identityService.setAuthenticatedUserId(userId);
ProcessInstance processInstance = processEngine.getRuntimeService()
.startProcessInstanceById(processDefinitionId, businessKey,
processParameters);
/*
* // {流程標題:title}-{發起人:startUser}-{發起時間:startTime} String processDefinitionName =
* processEngine.getRepositoryService() .createProcessDefinitionQuery()
* .processDefinitionId(processDefinitionId).singleResult() .getName(); String processInstanceName =
* processDefinitionName + "-" + userConnector.findById(userId).getDisplayName() + "-" + new
* SimpleDateFormat("yyyy-MM-dd HH:mm").format(new Date());
* processEngine.getRuntimeService().setProcessInstanceName( processInstance.getId(), processInstanceName);
*/
return processInstance.getId();
}
示例11: executeAsyncStep
import org.activiti.engine.runtime.ProcessInstance; //導入依賴的package包/類
@Override
protected StepPhase executeAsyncStep(ExecutionWrapper execution) throws Exception {
try {
String userId = StepsUtil.determineCurrentUser(execution.getContext(), getStepLogger());
int nextIterationIndex = getNextIterationIndex(execution);
execution.getContext().setVariable(getIterationVariableName(),
getIterationVariable(execution.getContext(), nextIterationIndex));
Map<String, Object> parentProcessVariables = execution.getContext().getVariables();
parentProcessVariables.put(Constants.VAR_PARENTPROCESS_ID, execution.getContext().getProcessInstanceId());
ProcessInstance subProcessInstance = actvitiFacade.startProcess(userId, getProcessDefinitionKey(), parentProcessVariables);
StepsUtil.setSubProcessId(execution.getContext(), subProcessInstance.getProcessInstanceId());
return StepPhase.POLL;
} catch (Exception e) {
getStepLogger().error(e, "Error starting sub-process");
throw new SLException(e);
}
}
示例12: test
import org.activiti.engine.runtime.ProcessInstance; //導入依賴的package包/類
/**
* Test.
*
* @return the string
*/
@RequestMapping(method=RequestMethod.GET, value="/resumeall")
@ResponseBody
public String test()
{
logger.info("Resuming crashed processes!!!");
List<ProcessInstance> processes = runtimeService.createProcessInstanceQuery().active().list();
for (ProcessInstance process : processes) {
ExecutionEntity exec = (ExecutionEntity)process;
if (exec.isActive() && exec.getActivityId().equals("ackStart")) {
exec.getId();
runtimeService.signal(exec.getId());
}
}
return "Resumed all processes";
}
示例13: setUp
import org.activiti.engine.runtime.ProcessInstance; //導入依賴的package包/類
@BeforeTest
public void setUp(){
RuntimeService rts = mock(RuntimeService.class);
List<ProcessInstance> processList = new ArrayList<ProcessInstance>();
ExecutionEntity executionEntity = new ExecutionEntity();
executionEntity.setActive(false);
processList.add(executionEntity);
ProcessInstanceQuery pQuery = mock(ProcessInstanceQuery.class);
when(pQuery.active()).thenReturn(pQuery);
when(pQuery.list()).thenReturn(processList);
when(rts.createProcessInstanceQuery()).thenReturn(pQuery);
this.servlet.setRuntimeService(rts);
this.servlet.setWoDispatcher(mock(WoDispatcher.class));
this.servlet.init();
}
示例14: deleteProcess
import org.activiti.engine.runtime.ProcessInstance; //導入依賴的package包/類
@Override
public void deleteProcess(String id)
{
validateIfUserAllowedToWorkWithProcess(id);
ProcessInstance processInstance = activitiProcessEngine.getRuntimeService()
.createProcessInstanceQuery()
.processInstanceId(id)
.singleResult();
if (processInstance == null)
{
throw new EntityNotFoundException(id);
}
activitiProcessEngine.getRuntimeService().deleteProcessInstance(id, "deleted through REST API call");
}
示例15: updateVariable
import org.activiti.engine.runtime.ProcessInstance; //導入依賴的package包/類
@Override
public Variable updateVariable(String processId, Variable variable)
{
validateIfUserAllowedToWorkWithProcess(processId);
ProcessInstance processInstance = activitiProcessEngine.getRuntimeService()
.createProcessInstanceQuery()
.processInstanceId(processId)
.singleResult();
if (processInstance == null)
{
throw new EntityNotFoundException(processId);
}
return updateVariableInProcess(processId, processInstance.getProcessDefinitionId(), variable);
}