Java Code Examples for org.activiti.engine.repository.ProcessDefinition#getId()

The following examples show how to use org.activiti.engine.repository.ProcessDefinition#getId() . 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: AbstractProcessDefinitionResource.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
protected FormDefinition getStartForm(ProcessDefinition processDefinition) {
  FormDefinition formDefinition = null;
  BpmnModel bpmnModel = repositoryService.getBpmnModel(processDefinition.getId());
  Process process = bpmnModel.getProcessById(processDefinition.getKey());
  FlowElement startElement = process.getInitialFlowElement();
  if (startElement instanceof StartEvent) {
    StartEvent startEvent = (StartEvent) startElement;
    if (StringUtils.isNotEmpty(startEvent.getFormKey())) {
      formDefinition = formRepositoryService.getFormDefinitionByKeyAndParentDeploymentId(startEvent.getFormKey(), 
          processDefinition.getDeploymentId(), processDefinition.getTenantId());
    }
  }

  if (formDefinition == null) {
    // Definition found, but no form attached
    throw new NotFoundException("Process definition does not have a form defined: " + processDefinition.getId());
  }

  return formDefinition;
}
 
Example 2
Source File: DeploymentManager.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
/**
 * Resolving the process definition will fetch the BPMN 2.0, parse it and store the {@link BpmnModel} in memory.
 */
public ProcessDefinitionCacheEntry resolveProcessDefinition(ProcessDefinition processDefinition) {
  String processDefinitionId = processDefinition.getId();
  String deploymentId = processDefinition.getDeploymentId();

  ProcessDefinitionCacheEntry cachedProcessDefinition = processDefinitionCache.get(processDefinitionId);

  if (cachedProcessDefinition == null) {
    CommandContext commandContext = Context.getCommandContext();
    if (commandContext.getProcessEngineConfiguration().isActiviti5CompatibilityEnabled() && 
        Activiti5Util.isActiviti5ProcessDefinition(Context.getCommandContext(), processDefinition)) {
      
      return Activiti5Util.getActiviti5CompatibilityHandler().resolveProcessDefinition(processDefinition);
    }
    
    DeploymentEntity deployment = deploymentEntityManager.findById(deploymentId);
    deployment.setNew(false);
    deploy(deployment, null);
    cachedProcessDefinition = processDefinitionCache.get(processDefinitionId);

    if (cachedProcessDefinition == null) {
      throw new ActivitiException("deployment '" + deploymentId + "' didn't put process definition '" + processDefinitionId + "' in the cache");
    }
  }
  return cachedProcessDefinition;
}
 
Example 3
Source File: ActivitiTypeConverter.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Convert a {@link ProcessDefinition} into a {@link WorkflowDefinition}.
 * @param definition ProcessDefinition
 * @return WorkflowDefinition
 */
public WorkflowDefinition convert(ProcessDefinition definition)
{
    if(definition==null)
        return null;
    
    String defId = definition.getId();
    String defName = definition.getKey();
    int version = definition.getVersion();
    String defaultTitle = definition.getName();
    
    String startTaskName = null;
    StartFormData startFormData = getStartFormData(defId, defName);
    if(startFormData != null) 
    {
        startTaskName = startFormData.getFormKey();
    }
    
    ReadOnlyProcessDefinition def = activitiUtil.getDeployedProcessDefinition(defId);
    PvmActivity startEvent = def.getInitial();
    WorkflowTaskDefinition startTask = getTaskDefinition(startEvent, startTaskName, definition.getKey(), true);
    
    return factory.createDefinition(defId,
                defName, version, defaultTitle,
                null, startTask);
}
 
Example 4
Source File: ProcessDefinitionImageResource.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
@ApiOperation(value = "Get a process definition image", tags = {"Process Definitions"})
@ApiResponses(value = {
    @ApiResponse(code = 200, message = "Indicates request was successful and the process-definitions are returned"),
    @ApiResponse(code = 404, message = "Indicates the requested process definition was not found.")
})
@RequestMapping(value = "/repository/process-definitions/{processDefinitionId}/image", method = RequestMethod.GET)
public ResponseEntity<byte[]> getModelResource(@ApiParam(name = "processDefinitionId") @PathVariable String processDefinitionId) {
  ProcessDefinition processDefinition = getProcessDefinitionFromRequest(processDefinitionId);
  InputStream imageStream = repositoryService.getProcessDiagram(processDefinition.getId());

  if (imageStream != null) {
    HttpHeaders responseHeaders = new HttpHeaders();
    responseHeaders.set("Content-Type", "image/png");
    try {
      return new ResponseEntity<byte[]>(IOUtils.toByteArray(imageStream), responseHeaders, HttpStatus.OK);
    } catch (Exception e) {
      throw new ActivitiException("Error reading image stream", e);
    }
  } else {
    throw new ActivitiIllegalArgumentException("Process definition with id '" + processDefinition.getId() + "' has no image.");
  }
}
 
Example 5
Source File: DeploymentManager.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
public ProcessDefinitionCacheEntry resolveProcessDefinition(ProcessDefinition processDefinition) {
  String processDefinitionId = processDefinition.getId();
  String deploymentId = processDefinition.getDeploymentId();
  ProcessDefinitionCacheEntry cachedProcessDefinition = processDefinitionCache.get(processDefinitionId);
  if (cachedProcessDefinition==null) {
    DeploymentEntity deployment = Context
      .getCommandContext()
      .getDeploymentEntityManager()
      .findDeploymentById(deploymentId);
    deployment.setNew(false);
    deploy(deployment, null);
    cachedProcessDefinition = processDefinitionCache.get(processDefinitionId);
    
    if (cachedProcessDefinition==null) {
      throw new ActivitiException("deployment '"+deploymentId+"' didn't put process definition '"+processDefinitionId+"' in the cache");
    }
  }
  return cachedProcessDefinition;
}
 
Example 6
Source File: IsActiviti5ProcessDefinitionCmd.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
public Boolean execute(CommandContext commandContext) {
  if (!commandContext.getProcessEngineConfiguration().isActiviti5CompatibilityEnabled()) {
    return false;
  }
  
  ProcessDefinition processDefinition = commandContext.getProcessEngineConfiguration()
      .getDeploymentManager()
      .findDeployedProcessDefinitionById(processDefinitionId);
  
  if (processDefinition.getEngineVersion() != null) {
    if (Activiti5CompatibilityHandler.ACTIVITI_5_ENGINE_TAG.equals(processDefinition.getEngineVersion())) {
      if (commandContext.getProcessEngineConfiguration().isActiviti5CompatibilityEnabled()) {
        return true;
      }
    } else {
      throw new ActivitiException("Invalid 'engine' for process definition " + processDefinition.getId() + " : " + processDefinition.getEngineVersion());
    }
  }
  return false;
}
 
Example 7
Source File: AbstractActivitiTestCase.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
/**
 * Creates and deploys the one task process. See {@link #createOneTaskTestProcess()}.
 * 
 * @return The process definition id (NOT the process definition key) of deployed one task process.
 */
public String deployOneTaskTestProcess() {
  BpmnModel bpmnModel = createOneTaskTestProcess();
  Deployment deployment = repositoryService.createDeployment().addBpmnModel("oneTasktest.bpmn20.xml", bpmnModel).deploy();

  deploymentIdsForAutoCleanup.add(deployment.getId()); // For auto-cleanup

  ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().deploymentId(deployment.getId()).singleResult();
  return processDefinition.getId();
}
 
Example 8
Source File: TaskFormsTest.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
@Deployment(resources = { 
  "org/activiti5/examples/taskforms/VacationRequest_deprecated_forms.bpmn20.xml", 
  "org/activiti5/examples/taskforms/approve.form", 
  "org/activiti5/examples/taskforms/request.form", 
  "org/activiti5/examples/taskforms/adjustRequest.form" })
public void testTaskFormsWithVacationRequestProcess() {

  // Get start form
  String procDefId = repositoryService.createProcessDefinitionQuery().singleResult().getId();
  Object startForm = formService.getRenderedStartForm(procDefId);
  assertNotNull(startForm);
  
  ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().singleResult();
  String processDefinitionId = processDefinition.getId();
  assertEquals("org/activiti5/examples/taskforms/request.form", formService.getStartFormData(processDefinitionId).getFormKey());

  // Define variables that would be filled in through the form
  Map<String, String> formProperties = new HashMap<String, String>();
  formProperties.put("employeeName", "kermit");
  formProperties.put("numberOfDays", "4");
  formProperties.put("vacationMotivation", "I'm tired");
  formService.submitStartFormData(procDefId, formProperties);

  // Management should now have a task assigned to them
  Task task = taskService.createTaskQuery().taskCandidateGroup("management").singleResult();
  assertEquals("Vacation request by kermit", task.getDescription());
  Object taskForm = formService.getRenderedTaskForm(task.getId());
  assertNotNull(taskForm);

  // Rejecting the task should put the process back to first task
  taskService.complete(task.getId(), CollectionUtil.singletonMap("vacationApproved", "false"));
  task = taskService.createTaskQuery().singleResult();
  assertEquals("Adjust vacation request", task.getName());
}
 
Example 9
Source File: AbstractActivitiTestCase.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
public String deployTwoTasksTestProcess() {
	BpmnModel bpmnModel = createTwoTasksTestProcess();
	Deployment deployment = repositoryService.createDeployment()
			.addBpmnModel("twoTasksTestProcess.bpmn20.xml", bpmnModel).deploy();
	
	deploymentIdsForAutoCleanup.add(deployment.getId()); // For auto-cleanup

	ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery()
			.deploymentId(deployment.getId()).singleResult();
	return processDefinition.getId(); 
}
 
Example 10
Source File: FlowableProcessController.java    From hsweb-framework with Apache License 2.0 5 votes vote down vote up
@PostMapping("/start/key/{defineKey}")
@ApiOperation("提交表单数据并根据流程定义key启动流程")
@Authorize(merge = false)
public ResponseMessage<String> startProcessByKey(@PathVariable String defineKey,
                                                 @RequestBody Map<String, Object> data,
                                                 Authentication authentication) {
    ProcessDefinition definition = repositoryService.createProcessDefinitionQuery()
            .processDefinitionKey(defineKey)
            .active()
            .latestVersion()
            .singleResult();

    if (null == definition) {
        throw new NotFoundException("流程[" + defineKey + "]不存在");
    }
    //判断权限
    processConfigurationService.getProcessConfiguration(definition.getId())
            .assertCanStartProcess(authentication.getUser().getId(), definition);

    String id = definition.getId();

    ProcessInstance instance = bpmProcessService.startProcessInstance(StartProcessRequest.builder()
            .creatorId(authentication.getUser().getId())
            .creatorName(authentication.getUser().getName())
            .formData(data)
            .processDefineId(id)
            .build());


    return ResponseMessage.ok(instance.getId());
}
 
Example 11
Source File: ProcessDefinitionResource.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
protected ProcessDefinitionResponse suspendProcessDefinition(ProcessDefinition processDefinition, boolean suspendInstances, Date date) {

    if (repositoryService.isProcessDefinitionSuspended(processDefinition.getId())) {
      throw new ActivitiConflictException("Process definition with id '" + processDefinition.getId() + " ' is already suspended");
    }
    repositoryService.suspendProcessDefinitionById(processDefinition.getId(), suspendInstances, date);

    ProcessDefinitionResponse response = restResponseFactory.createProcessDefinitionResponse(processDefinition);

    // No need to re-fetch the ProcessDefinition, just alter the suspended
    // state of the result-object
    response.setSuspended(true);
    return response;
  }
 
Example 12
Source File: ProcessDefinitionResource.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
protected ProcessDefinitionResponse activateProcessDefinition(ProcessDefinition processDefinition, boolean suspendInstances, Date date) {

    if (!repositoryService.isProcessDefinitionSuspended(processDefinition.getId())) {
      throw new ActivitiConflictException("Process definition with id '" + processDefinition.getId() + " ' is already active");
    }
    repositoryService.activateProcessDefinitionById(processDefinition.getId(), suspendInstances, date);

    ProcessDefinitionResponse response = restResponseFactory.createProcessDefinitionResponse(processDefinition);

    // No need to re-fetch the ProcessDefinition, just alter the suspended
    // state of the result-object
    response.setSuspended(false);
    return response;
  }
 
Example 13
Source File: AbstractActivitiTestCase.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
public String deployTwoTasksTestProcess() {
  BpmnModel bpmnModel = createTwoTasksTestProcess();
  Deployment deployment = repositoryService.createDeployment().addBpmnModel("twoTasksTestProcess.bpmn20.xml", bpmnModel).deploy();

  deploymentIdsForAutoCleanup.add(deployment.getId()); // For auto-cleanup

  ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().deploymentId(deployment.getId()).singleResult();
  return processDefinition.getId();
}
 
Example 14
Source File: ProcessInstanceHelper.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
protected ProcessInstance createAndStartProcessInstance(ProcessDefinition processDefinition,
    String businessKey, String processInstanceName,
    Map<String, Object> variables, Map<String, Object> transientVariables, boolean startProcessInstance) {

  CommandContext commandContext = Context.getCommandContext(); // Todo: ideally, context should be passed here
  if (Activiti5Util.isActiviti5ProcessDefinition(commandContext, processDefinition)) {
    Activiti5CompatibilityHandler activiti5CompatibilityHandler = Activiti5Util.getActiviti5CompatibilityHandler();
    return activiti5CompatibilityHandler.startProcessInstance(processDefinition.getKey(), processDefinition.getId(),
        variables, businessKey, processDefinition.getTenantId(), processInstanceName);
  }

  // Do not start process a process instance if the process definition is suspended
  if (ProcessDefinitionUtil.isProcessDefinitionSuspended(processDefinition.getId())) {
    throw new ActivitiException("Cannot start process instance. Process definition " + processDefinition.getName() + " (id = " + processDefinition.getId() + ") is suspended");
  }

  // Get model from cache
  Process process = ProcessDefinitionUtil.getProcess(processDefinition.getId());
  if (process == null) {
    throw new ActivitiException("Cannot start process instance. Process model " + processDefinition.getName() + " (id = " + processDefinition.getId() + ") could not be found");
  }

  FlowElement initialFlowElement = process.getInitialFlowElement();
  if (initialFlowElement == null) {
    throw new ActivitiException("No start element found for process definition " + processDefinition.getId());
  }

  return createAndStartProcessInstanceWithInitialFlowElement(processDefinition, businessKey,
      processInstanceName, initialFlowElement, process, variables, transientVariables, startProcessInstance);
}
 
Example 15
Source File: ProcessDefinitionRepresentation.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
public ProcessDefinitionRepresentation(ProcessDefinition processDefinition) {
    this.id = processDefinition.getId();
    this.name = processDefinition.getName();
    this.description = processDefinition.getDescription();
    this.key = processDefinition.getKey();
    this.category = processDefinition.getCategory();
    this.version = processDefinition.getVersion();
    this.deploymentId = processDefinition.getDeploymentId();
    this.tenantId = processDefinition.getTenantId();
    this.hasStartForm = processDefinition.hasStartFormKey();
}
 
Example 16
Source File: ModelDeployer.java    From lemon with Apache License 2.0 4 votes vote down vote up
public void processBusiness(ProcessDefinition processDefinition) {
    String processDefinitionId = processDefinition.getId();
    List<HumanTaskDefinition> humanTaskDefinitions = humanTaskConnector
            .findHumanTaskDefinitions(processDefinitionId);
    ModelInfo modelInfo = modelInfoManager.findUniqueBy("code",
            processDefinitionId);

    if (modelInfo == null) {
        modelInfo = new ModelInfo();
        modelInfo.setCode(processDefinitionId);
        modelInfo.setName(processDefinition.getName());
        modelInfo.setTenantId(processDefinition.getTenantId());
        modelInfoManager.save(modelInfo);
    }

    Map<String, FormField> formFieldMap = new HashMap<String, FormField>();

    for (HumanTaskDefinition humanTaskDefinition : humanTaskDefinitions) {
        try {
            com.mossle.spi.humantask.FormDTO formDto = taskDefinitionConnector
                    .findForm(humanTaskDefinition.getKey(),
                            processDefinitionId);

            if (formDto == null) {
                continue;
            }

            String formKey = formDto.getKey();
            this.processForm(processDefinitionId, formKey,
                    modelInfo.getTenantId(), formFieldMap);
        } catch (IOException ex) {
            logger.error(ex.getMessage(), ex);
        }
    }

    for (FormField formField : formFieldMap.values()) {
        String hql = "from ModelField where name=? and modelInfo=?";
        ModelField modelField = modelFieldManager.findUnique(hql,
                formField.getName(), modelInfo);

        if (modelField != null) {
            continue;
        }

        modelField = new ModelField();
        modelField.setModelInfo(modelInfo);
        modelField.setCode(formField.getName());
        modelField.setType(formField.getType());
        modelField.setName(formField.getLabel());
        modelField.setSearchable("true");
        modelField.setDisplayable("true");
        modelField.setViewForm("true");
        modelField.setViewList("true");
        modelField.setTenantId(modelInfo.getTenantId());
        modelFieldManager.save(modelField);
    }
}
 
Example 17
Source File: ProcessInstanceHelper.java    From activiti6-boot2 with Apache License 2.0 4 votes vote down vote up
public ProcessInstance createAndStartProcessInstanceByMessage(ProcessDefinition processDefinition, String messageName,
    Map<String, Object> variables, Map<String, Object> transientVariables) {

  CommandContext commandContext = Context.getCommandContext();
  if (processDefinition.getEngineVersion() != null) {
    if (Activiti5CompatibilityHandler.ACTIVITI_5_ENGINE_TAG.equals(processDefinition.getEngineVersion())) {
      Activiti5CompatibilityHandler activiti5CompatibilityHandler = commandContext.getProcessEngineConfiguration().getActiviti5CompatibilityHandler();

      if (activiti5CompatibilityHandler == null) {
        throw new ActivitiException("Found Activiti 5 process definition, but no compatibility handler on the classpath");
      }

      return activiti5CompatibilityHandler.startProcessInstanceByMessage(messageName, variables, null, processDefinition.getTenantId());

    } else {
      throw new ActivitiException("Invalid 'engine' for process definition " + processDefinition.getId() + " : " + processDefinition.getEngineVersion());
    }
  }

  // Do not start process a process instance if the process definition is suspended
  if (ProcessDefinitionUtil.isProcessDefinitionSuspended(processDefinition.getId())) {
    throw new ActivitiException("Cannot start process instance. Process definition " + processDefinition.getName() + " (id = " + processDefinition.getId() + ") is suspended");
  }

  // Get model from cache
  Process process = ProcessDefinitionUtil.getProcess(processDefinition.getId());
  if (process == null) {
    throw new ActivitiException("Cannot start process instance. Process model " + processDefinition.getName() + " (id = " + processDefinition.getId() + ") could not be found");
  }

  FlowElement initialFlowElement = null;
  for (FlowElement flowElement : process.getFlowElements()) {
    if (flowElement instanceof StartEvent) {
      StartEvent startEvent = (StartEvent) flowElement;
      if (CollectionUtil.isNotEmpty(startEvent.getEventDefinitions()) && startEvent.getEventDefinitions().get(0) instanceof MessageEventDefinition) {

        MessageEventDefinition messageEventDefinition = (MessageEventDefinition) startEvent.getEventDefinitions().get(0);
        if (messageEventDefinition.getMessageRef().equals(messageName)) {
          initialFlowElement = flowElement;
          break;
        }
      }
    }
  }
  if (initialFlowElement == null) {
    throw new ActivitiException("No message start event found for process definition " + processDefinition.getId() + " and message name " + messageName);
  }

  return createAndStartProcessInstanceWithInitialFlowElement(processDefinition, null, null, initialFlowElement, process, variables, transientVariables, true);
}
 
Example 18
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;
       
     }
     
 }
 
Example 19
Source File: ActProcessService.java    From Shop-for-JavaWeb with MIT License 4 votes vote down vote up
/**
	 * 部署流程 - 保存
	 * @param file
	 * @return
	 */
	@Transactional(readOnly = false)
	public String deploy(String exportDir, String category, MultipartFile file) {

		String message = "";
		
		String fileName = file.getOriginalFilename();
		
		try {
			InputStream fileInputStream = file.getInputStream();
			Deployment deployment = null;
			String extension = FilenameUtils.getExtension(fileName);
			if (extension.equals("zip") || extension.equals("bar")) {
				ZipInputStream zip = new ZipInputStream(fileInputStream);
				deployment = repositoryService.createDeployment().addZipInputStream(zip).deploy();
			} else if (extension.equals("png")) {
				deployment = repositoryService.createDeployment().addInputStream(fileName, fileInputStream).deploy();
			} else if (fileName.indexOf("bpmn20.xml") != -1) {
				deployment = repositoryService.createDeployment().addInputStream(fileName, fileInputStream).deploy();
			} else if (extension.equals("bpmn")) { // bpmn扩展名特殊处理,转换为bpmn20.xml
				String baseName = FilenameUtils.getBaseName(fileName); 
				deployment = repositoryService.createDeployment().addInputStream(baseName + ".bpmn20.xml", fileInputStream).deploy();
			} else {
				message = "不支持的文件类型:" + extension;
			}
			
			List<ProcessDefinition> list = repositoryService.createProcessDefinitionQuery().deploymentId(deployment.getId()).list();

			// 设置流程分类
			for (ProcessDefinition processDefinition : list) {
//					ActUtils.exportDiagramToFile(repositoryService, processDefinition, exportDir);
				repositoryService.setProcessDefinitionCategory(processDefinition.getId(), category);
				message += "部署成功,流程ID=" + processDefinition.getId() + "<br/>";
			}
			
			if (list.size() == 0){
				message = "部署失败,没有流程。";
			}
			
		} catch (Exception e) {
			throw new ActivitiException("部署失败!", e);
		}
		return message;
	}
 
Example 20
Source File: StartProcessInstanceCmd.java    From activiti6-boot2 with Apache License 2.0 4 votes vote down vote up
public ProcessInstance execute(CommandContext commandContext) {
  DeploymentManager deploymentManager = commandContext
    .getProcessEngineConfiguration()
    .getDeploymentManager();
  
  // Find the process definition
  ProcessDefinition processDefinition = null;
  if (processDefinitionId!=null) {
    processDefinition = deploymentManager.findDeployedProcessDefinitionById(processDefinitionId);
    if (processDefinition == null) {
      throw new ActivitiObjectNotFoundException("No process definition found for id = '" + processDefinitionId + "'", ProcessDefinition.class);
    }
  } else if (processDefinitionKey != null && (tenantId == null || ProcessEngineConfiguration.NO_TENANT_ID.equals(tenantId))){
    processDefinition = deploymentManager.findDeployedLatestProcessDefinitionByKey(processDefinitionKey);
    if (processDefinition == null) {
      throw new ActivitiObjectNotFoundException("No process definition found for key '" + processDefinitionKey +"'", ProcessDefinition.class);
    }
  } else if (processDefinitionKey != null && tenantId != null && !ProcessEngineConfiguration.NO_TENANT_ID.equals(tenantId)) {
  	 processDefinition = deploymentManager.findDeployedLatestProcessDefinitionByKeyAndTenantId(processDefinitionKey, tenantId);
     if (processDefinition == null) {
       throw new ActivitiObjectNotFoundException("No process definition found for key '" + processDefinitionKey +"' for tenant identifier " + tenantId, ProcessDefinition.class);
     }
  } else {
    throw new ActivitiIllegalArgumentException("processDefinitionKey and processDefinitionId are null");
  }
  
  // Do not start process 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");
  }

  // Start the process instance
  ExecutionEntity processInstance = ((ProcessDefinitionEntity) processDefinition).createProcessInstance(businessKey);

  // now set the variables passed into the start command
  initializeVariables(processInstance);

  // now set processInstance name
  if (processInstanceName != null) {
    processInstance.setName(processInstanceName);
    commandContext.getHistoryManager().recordProcessInstanceNameChange(processInstance.getId(), processInstanceName);
  }
  
  processInstance.start();
  
  return processInstance;
}