org.activiti.engine.impl.persistence.entity.ProcessDefinitionEntity Java Examples

The following examples show how to use org.activiti.engine.impl.persistence.entity.ProcessDefinitionEntity. 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: SetProcessDefinitionVersionCmd.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
protected void validateAndSwitchVersionOfExecution(CommandContext commandContext, ExecutionEntity execution, ProcessDefinitionEntity newProcessDefinition) {
    // check that the new process definition version contains the current activity
    if (execution.getActivity() != null && !newProcessDefinition.contains(execution.getActivity())) {
        throw new ActivitiException(
                "The new process definition " +
                        "(key = '" + newProcessDefinition.getKey() + "') " +
                        "does not contain the current activity " +
                        "(id = '" + execution.getActivity().getId() + "') " +
                        "of the process instance " +
                        "(id = '" + processInstanceId + "').");
    }

    // switch the process instance to the new process definition version
    execution.setProcessDefinition(newProcessDefinition);

    // and change possible existing tasks (as the process definition id is stored there too)
    List<TaskEntity> tasks = commandContext.getTaskEntityManager().findTasksByExecutionId(execution.getId());
    for (TaskEntity taskEntity : tasks) {
        taskEntity.setProcessDefinitionId(newProcessDefinition.getId());
        commandContext.getHistoryManager().recordTaskProcessDefinitionChange(taskEntity.getId(), newProcessDefinition.getId());
    }
}
 
Example #2
Source File: BpmnDeployer.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
protected void addTimerDeclarations(ProcessDefinitionEntity processDefinition, List<TimerJobEntity> timers) {
    List<TimerDeclarationImpl> timerDeclarations = (List<TimerDeclarationImpl>) processDefinition.getProperty(BpmnParse.PROPERTYNAME_START_TIMER);
    if (timerDeclarations != null) {
        for (TimerDeclarationImpl timerDeclaration : timerDeclarations) {
            TimerJobEntity timer = timerDeclaration.prepareTimerEntity(null);
            if (timer != null) {
                timer.setProcessDefinitionId(processDefinition.getId());

                // Inherit timer (if applicable)
                if (processDefinition.getTenantId() != null) {
                    timer.setTenantId(processDefinition.getTenantId());
                }
                timers.add(timer);
            }
        }
    }
}
 
Example #3
Source File: AbstractSetProcessDefinitionStateCmd.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
protected void createTimerForDelayedExecution(CommandContext commandContext, List<ProcessDefinitionEntity> processDefinitions) {
    for (ProcessDefinitionEntity processDefinition : processDefinitions) {
        TimerJobEntity timer = new TimerJobEntity();
        timer.setJobType(Job.JOB_TYPE_TIMER);
        timer.setRevision(1);
        timer.setProcessDefinitionId(processDefinition.getId());

        // Inherit tenant identifier (if applicable)
        if (processDefinition.getTenantId() != null) {
            timer.setTenantId(processDefinition.getTenantId());
        }

        timer.setDuedate(executionDate);
        timer.setJobHandlerType(getDelayedExecutionJobHandlerType());
        timer.setJobHandlerConfiguration(TimerChangeProcessDefinitionSuspensionStateJobHandler.createJobHandlerConfiguration(includeProcessInstances));
        commandContext.getJobEntityManager().schedule(timer);
    }
}
 
Example #4
Source File: AutoCompleteFirstTaskListener.java    From lemon with Apache License 2.0 6 votes vote down vote up
/**
 * 获得第一个节点.
 */
public PvmActivity findFirstActivity(String processDefinitionId) {
    ProcessDefinitionEntity processDefinitionEntity = Context
            .getProcessEngineConfiguration().getProcessDefinitionCache()
            .get(processDefinitionId);

    ActivityImpl startActivity = processDefinitionEntity.getInitial();

    if (startActivity.getOutgoingTransitions().size() != 1) {
        throw new IllegalStateException(
                "start activity outgoing transitions cannot more than 1, now is : "
                        + startActivity.getOutgoingTransitions().size());
    }

    PvmTransition pvmTransition = startActivity.getOutgoingTransitions()
            .get(0);
    PvmActivity targetActivity = pvmTransition.getDestination();

    if (!"userTask".equals(targetActivity.getProperty("type"))) {
        logger.debug("first activity is not userTask, just skip");

        return null;
    }

    return targetActivity;
}
 
Example #5
Source File: ProcessDefinitionsImpl.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public ProcessDefinition getProcessDefinition(String definitionId)
{
    ProcessDefinitionQuery query = activitiProcessEngine
            .getRepositoryService()
            .createProcessDefinitionQuery()
            .processDefinitionId(definitionId);
    
    if (tenantService.isEnabled() && deployWorkflowsInTenant) 
    {
        query.processDefinitionKeyLike("@" + TenantUtil.getCurrentDomain() + "@%");
    }
    
    org.activiti.engine.repository.ProcessDefinition processDefinition = query.singleResult();
    
    if (processDefinition == null) 
    {
        throw new EntityNotFoundException(definitionId); 
    }

    ProcessDefinition deploymentRest = createProcessDefinitionRest((ProcessDefinitionEntity) processDefinition);
    return deploymentRest;
}
 
Example #6
Source File: ResourceNameUtil.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
/**
 * Finds the name of a resource for the diagram for a process definition.  Assumes that the
 * process definition's key and (BPMN) resource name are already set.
 *
 * <p>It will first look for an image resource which matches the process specifically, before
 * resorting to an image resource which matches the BPMN 2.0 xml file resource.
 *
 * <p>Example: if the deployment contains a BPMN 2.0 xml resource called 'abc.bpmn20.xml'
 * containing only one process with key 'myProcess', then this method will look for an image resources
 * called'abc.myProcess.png' (or .jpg, or .gif, etc.) or 'abc.png' if the previous one wasn't
 * found.
 *
 * <p>Example 2: if the deployment contains a BPMN 2.0 xml resource called 'abc.bpmn20.xml'
 * containing three processes (with keys a, b and c), then this method will first look for an image resource
 * called 'abc.a.png' before looking for 'abc.png' (likewise for b and c). Note that if abc.a.png,
 * abc.b.png and abc.c.png don't exist, all processes will have the same image: abc.png.
 *
 * @return name of an existing resource, or null if no matching image resource is found in the resources.
 */
public static String getProcessDiagramResourceNameFromDeployment(
    ProcessDefinitionEntity processDefinition, Map<String, ResourceEntity> resources) {
  
  if (StringUtils.isEmpty(processDefinition.getResourceName())) {
    throw new IllegalStateException("Provided process definition must have its resource name set.");
  }
  
  String bpmnResourceBase = stripBpmnFileSuffix(processDefinition.getResourceName());
  String key = processDefinition.getKey();
  
  for (String diagramSuffix : DIAGRAM_SUFFIXES) {
    String possibleName = bpmnResourceBase + key + "." + diagramSuffix;
    if (resources.containsKey(possibleName)) {
      return possibleName;
    }
    
    possibleName = bpmnResourceBase + diagramSuffix;
    if (resources.containsKey(possibleName)) {
      return possibleName;
    }
  }
  
  return null;
}
 
Example #7
Source File: GetStartFormCmd.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
@Override
public StartFormData execute(CommandContext commandContext) {
    ProcessDefinitionEntity processDefinition = (ProcessDefinitionEntity) commandContext
            .getProcessEngineConfiguration()
            .getDeploymentManager()
            .findDeployedProcessDefinitionById(processDefinitionId);
    if (processDefinition == null) {
        throw new ActivitiObjectNotFoundException("No process definition found for id '" + processDefinitionId + "'", ProcessDefinition.class);
    }

    StartFormHandler startFormHandler = processDefinition.getStartFormHandler();
    if (startFormHandler == null) {
        throw new ActivitiException("No startFormHandler defined in process '" + processDefinitionId + "'");
    }

    return startFormHandler.createStartFormData(processDefinition);
}
 
Example #8
Source File: ActivitiTypeConverter.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Get the taskDefinition key based on the Activiti task definition id,
 * @param taskDefinitionKey String
 * @param processDefinitionId String
 * @return WorkflowTaskDefinition
 */
public WorkflowTaskDefinition getTaskDefinition(String taskDefinitionKey, String processDefinitionId)
{
	 ProcessDefinitionEntity procDef = (ProcessDefinitionEntity) activitiUtil.getDeployedProcessDefinition(processDefinitionId);
	 Collection<PvmActivity> userTasks = findUserTasks(procDef.getInitial());
	 
	 TaskDefinition taskDefinition = null;
	 for(PvmActivity activity : userTasks)
	 {
		 taskDefinition = procDef.getTaskDefinitions().get(activity.getId());
		 if(taskDefinitionKey.equals(taskDefinition.getKey()))
		 {
			 String formKey = getFormKey(taskDefinition);
			 WorkflowNode node = convert(activity);
			 return factory.createTaskDefinition(formKey, node, formKey, false);
		 }
	 }
	 
	 return null;
}
 
Example #9
Source File: StartEventParseHandler.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
protected void selectInitial(BpmnParse bpmnParse, ActivityImpl startEventActivity, StartEvent startEvent, ProcessDefinitionEntity processDefinition) {
    if (processDefinition.getInitial() == null) {
        processDefinition.setInitial(startEventActivity);
    } else {
        // validate that there is a single none start event / timer start event:
        if (!startEventActivity.getProperty("type").equals("messageStartEvent")
                && !startEventActivity.getProperty("type").equals("signalStartEvent")
                && !startEventActivity.getProperty("type").equals("startTimerEvent")) {
            String currentInitialType = (String) processDefinition.getInitial().getProperty("type");
            if (currentInitialType.equals("messageStartEvent")) {
                processDefinition.setInitial(startEventActivity);
            } else {
                throw new ActivitiException("multiple none start events or timer start events not supported on process definition");
            }
        }
    }
}
 
Example #10
Source File: RollbackTaskCmd.java    From lemon with Apache License 2.0 6 votes vote down vote up
/**
 * 查找回退的目的节点.
 */
public ActivityImpl findTargetActivity(CommandContext commandContext,
        TaskEntity taskEntity) {
    if (activityId == null) {
        String historyTaskId = this.findNearestUserTask(commandContext);
        HistoricTaskInstanceEntity historicTaskInstanceEntity = commandContext
                .getHistoricTaskInstanceEntityManager()
                .findHistoricTaskInstanceById(historyTaskId);
        this.activityId = historicTaskInstanceEntity.getTaskDefinitionKey();
    }

    String processDefinitionId = taskEntity.getProcessDefinitionId();
    ProcessDefinitionEntity processDefinitionEntity = new GetDeploymentProcessDefinitionCmd(
            processDefinitionId).execute(commandContext);

    return processDefinitionEntity.findActivity(activityId);
}
 
Example #11
Source File: ProcessInstanceHighlightsResource.java    From hsweb-framework with Apache License 2.0 6 votes vote down vote up
/**
 * getHighLightedFlows
 *
 * @param processDefinition
 * @param processInstanceId
 * @return
 */
private List<String> getHighLightedFlows(ProcessDefinitionEntity processDefinition, String processInstanceId) {

    List<String> highLightedFlows = new ArrayList<String>();

    List<HistoricActivityInstance> historicActivityInstances = historyService.createHistoricActivityInstanceQuery()
            .processInstanceId(processInstanceId)
            //order by startime asc is not correct. use default order is correct.
            //.orderByHistoricActivityInstanceStartTime().asc()/*.orderByActivityId().asc()*/
            .list();

    LinkedList<HistoricActivityInstance> hisActInstList = new LinkedList<HistoricActivityInstance>();
    hisActInstList.addAll(historicActivityInstances);

    getHighlightedFlows(processDefinition.getActivities(), hisActInstList, highLightedFlows);

    return highLightedFlows;
}
 
Example #12
Source File: BpmnDeploymentHelper.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
/**
 * Updates all timers and events for the process definition.  This removes obsolete message and signal
 * subscriptions and timers, and adds new ones.
 */
public void updateTimersAndEvents(ProcessDefinitionEntity processDefinition, 
    ProcessDefinitionEntity previousProcessDefinition, ParsedDeployment parsedDeployment) {
  
  Process process = parsedDeployment.getProcessModelForProcessDefinition(processDefinition);
  BpmnModel bpmnModel = parsedDeployment.getBpmnModelForProcessDefinition(processDefinition);

  eventSubscriptionManager.removeObsoleteMessageEventSubscriptions(previousProcessDefinition);
  eventSubscriptionManager.addMessageEventSubscriptions(processDefinition, process, bpmnModel);

  eventSubscriptionManager.removeObsoleteSignalEventSubScription(previousProcessDefinition);
  eventSubscriptionManager.addSignalEventSubscriptions(Context.getCommandContext(), processDefinition, process, bpmnModel);

  timerManager.removeObsoleteTimers(processDefinition);
  timerManager.scheduleTimers(processDefinition, process);
}
 
Example #13
Source File: EventSubscriptionManager.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
protected void addMessageEventSubscriptions(ProcessDefinitionEntity processDefinition, Process process, BpmnModel bpmnModel) {
  if (CollectionUtil.isNotEmpty(process.getFlowElements())) {
    for (FlowElement element : process.getFlowElements()) {
      if (element instanceof StartEvent) {
        StartEvent startEvent = (StartEvent) element;
        if (CollectionUtil.isNotEmpty(startEvent.getEventDefinitions())) {
          EventDefinition eventDefinition = startEvent.getEventDefinitions().get(0);
          if (eventDefinition instanceof MessageEventDefinition) {
            MessageEventDefinition messageEventDefinition = (MessageEventDefinition) eventDefinition;
            insertMessageEvent(messageEventDefinition, startEvent, processDefinition, bpmnModel);
          }
        }
      } 
    }
  }
}
 
Example #14
Source File: AutoCompleteFirstTaskEventListener.java    From lemon with Apache License 2.0 6 votes vote down vote up
/**
 * 获得第一个节点.
 */
public PvmActivity findFirstActivity(String processDefinitionId) {
    ProcessDefinitionEntity processDefinitionEntity = Context
            .getProcessEngineConfiguration().getProcessDefinitionCache()
            .get(processDefinitionId);

    ActivityImpl startActivity = processDefinitionEntity.getInitial();

    if (startActivity.getOutgoingTransitions().size() != 1) {
        throw new IllegalStateException(
                "start activity outgoing transitions cannot more than 1, now is : "
                        + startActivity.getOutgoingTransitions().size());
    }

    PvmTransition pvmTransition = startActivity.getOutgoingTransitions()
            .get(0);
    PvmActivity targetActivity = pvmTransition.getDestination();

    if (!"userTask".equals(targetActivity.getProperty("type"))) {
        logger.debug("first activity is not userTask, just skip");

        return null;
    }

    return targetActivity;
}
 
Example #15
Source File: TimerManager.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
protected void removeObsoleteTimers(ProcessDefinitionEntity processDefinition) {
  List<TimerJobEntity> jobsToDelete = null;

  if (processDefinition.getTenantId() != null && !ProcessEngineConfiguration.NO_TENANT_ID.equals(processDefinition.getTenantId())) {
    jobsToDelete = Context.getCommandContext().getTimerJobEntityManager().findJobsByTypeAndProcessDefinitionKeyAndTenantId(
        TimerStartEventJobHandler.TYPE, processDefinition.getKey(), processDefinition.getTenantId());
  } else {
    jobsToDelete = Context.getCommandContext().getTimerJobEntityManager()
        .findJobsByTypeAndProcessDefinitionKeyNoTenantId(TimerStartEventJobHandler.TYPE, processDefinition.getKey());
  }

  if (jobsToDelete != null) {
    for (TimerJobEntity job :jobsToDelete) {
      new CancelJobsCmd(job.getId()).execute(Context.getCommandContext());
    }
  }
}
 
Example #16
Source File: TraceProcessController.java    From activiti-in-action-codes with Apache License 2.0 6 votes vote down vote up
/**
 * 读取流程资源
 */
@RequestMapping(value = "trace/data/auto/{executionId}")
public void readResource(@PathVariable("executionId") String executionId, HttpServletResponse response)
        throws Exception {
    ProcessInstance processInstance = runtimeService.createProcessInstanceQuery().processInstanceId(executionId).singleResult();
    BpmnModel bpmnModel = repositoryService.getBpmnModel(processInstance.getProcessDefinitionId());
    ProcessDefinitionEntity processDefinition = (ProcessDefinitionEntity) repositoryService.createProcessDefinitionQuery().processDefinitionId(processInstance.getProcessDefinitionId()).singleResult();
    List<String> activeActivityIds = runtimeService.getActiveActivityIds(executionId);
    ProcessDiagramGenerator diagramGenerator = processEngineConfiguration.getProcessDiagramGenerator();
    List<String> highLightedFlows = getHighLightedFlows(processDefinition, processInstance.getId());
    InputStream imageStream =diagramGenerator.generateDiagram(bpmnModel, "png", activeActivityIds, highLightedFlows);

    // 输出资源内容到相应对象
    byte[] b = new byte[1024];
    int len;
    while ((len = imageStream.read(b, 0, 1024)) != -1) {
        response.getOutputStream().write(b, 0, len);
    }
}
 
Example #17
Source File: BpmnDeploymentHelper.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
/**
 * Gets the most recent persisted process definition that matches this one for tenant and key.
 * If none is found, returns null.  This method assumes that the tenant and key are properly
 * set on the process definition entity.
 */
public ProcessDefinitionEntity getMostRecentVersionOfProcessDefinition(ProcessDefinitionEntity processDefinition) {
  String key = processDefinition.getKey();
  String tenantId = processDefinition.getTenantId();
  ProcessDefinitionEntityManager processDefinitionManager 
    = Context.getCommandContext().getProcessEngineConfiguration().getProcessDefinitionEntityManager();

  ProcessDefinitionEntity existingDefinition = null;

  if (tenantId != null && !tenantId.equals(ProcessEngineConfiguration.NO_TENANT_ID)) {
    existingDefinition = processDefinitionManager.findLatestProcessDefinitionByKeyAndTenantId(key, tenantId);
  } else {
    existingDefinition = processDefinitionManager.findLatestProcessDefinitionByKey(key);
  }

  return existingDefinition;
}
 
Example #18
Source File: AbstractProcessInstanceQueryResource.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
protected List<ProcessInstanceRepresentation> convertInstanceList(List<HistoricProcessInstance> instances) {
  List<ProcessInstanceRepresentation> result = new ArrayList<ProcessInstanceRepresentation>();
  if (CollectionUtils.isNotEmpty(instances)) {

    for (HistoricProcessInstance processInstance : instances) {
      User userRep = null;
      if (processInstance.getStartUserId() != null) {
        CachedUser user = userCache.getUser(processInstance.getStartUserId());
        if (user != null && user.getUser() != null) {
          userRep = user.getUser();
        }
      }

      ProcessDefinitionEntity procDef = (ProcessDefinitionEntity) repositoryService.getProcessDefinition(processInstance.getProcessDefinitionId());
      ProcessInstanceRepresentation instanceRepresentation = new ProcessInstanceRepresentation(processInstance, procDef, procDef.isGraphicalNotationDefined(), userRep);
      result.add(instanceRepresentation);
    }

  }
  return result;
}
 
Example #19
Source File: CachingAndArtifactsManager.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
/**
 * Ensures that the process definition is cached in the appropriate places, including the
 * deployment's collection of deployed artifacts and the deployment manager's cache, as well
 * as caching any ProcessDefinitionInfos.
 */
public void updateCachingAndArtifacts(ParsedDeployment parsedDeployment) {
  CommandContext commandContext = Context.getCommandContext();
  final ProcessEngineConfigurationImpl processEngineConfiguration = Context.getProcessEngineConfiguration();
  DeploymentCache<ProcessDefinitionCacheEntry> processDefinitionCache 
    = processEngineConfiguration.getDeploymentManager().getProcessDefinitionCache();
  DeploymentEntity deployment = parsedDeployment.getDeployment();

  for (ProcessDefinitionEntity processDefinition : parsedDeployment.getAllProcessDefinitions()) {
    BpmnModel bpmnModel = parsedDeployment.getBpmnModelForProcessDefinition(processDefinition);
    Process process = parsedDeployment.getProcessModelForProcessDefinition(processDefinition);
    ProcessDefinitionCacheEntry cacheEntry = new ProcessDefinitionCacheEntry(processDefinition, bpmnModel, process);
    processDefinitionCache.add(processDefinition.getId(), cacheEntry);
    addDefinitionInfoToCache(processDefinition, processEngineConfiguration, commandContext);
  
    // Add to deployment for further usage
    deployment.addDeployedArtifact(processDefinition);
  }
}
 
Example #20
Source File: TraceProcessController.java    From activiti-in-action-codes with Apache License 2.0 6 votes vote down vote up
/**
 * 读取流程资源
 */
@RequestMapping(value = "trace/data/auto/{executionId}")
public void readResource(@PathVariable("executionId") String executionId, HttpServletResponse response)
        throws Exception {
    ProcessInstance processInstance = runtimeService.createProcessInstanceQuery().processInstanceId(executionId).singleResult();
    BpmnModel bpmnModel = repositoryService.getBpmnModel(processInstance.getProcessDefinitionId());
    ProcessDefinitionEntity processDefinition = (ProcessDefinitionEntity) repositoryService.createProcessDefinitionQuery().processDefinitionId(processInstance.getProcessDefinitionId()).singleResult();
    List<String> activeActivityIds = runtimeService.getActiveActivityIds(executionId);
    ProcessDiagramGenerator diagramGenerator = processEngineConfiguration.getProcessDiagramGenerator();
    List<String> highLightedFlows = getHighLightedFlows(processDefinition, processInstance.getId());
    InputStream imageStream =diagramGenerator.generateDiagram(bpmnModel, "png", activeActivityIds, highLightedFlows);

    // 输出资源内容到相应对象
    byte[] b = new byte[1024];
    int len;
    while ((len = imageStream.read(b, 0, 1024)) != -1) {
        response.getOutputStream().write(b, 0, len);
    }
}
 
Example #21
Source File: RollbackCmd.java    From lemon with Apache License 2.0 6 votes vote down vote up
public void initSource() {
    // source task
    this.jumpInfo.setSourceTaskId(this.taskId);

    TaskEntity sourceTask = Context.getCommandContext()
            .getTaskEntityManager().findTaskById(this.taskId);
    this.jumpInfo.setSourceTask(sourceTask);

    ProcessDefinitionEntity processDefinitionEntity = Context
            .getProcessEngineConfiguration()
            .getDeploymentManager()
            .findDeployedProcessDefinitionById(
                    sourceTask.getProcessDefinitionId());
    // source activity
    this.jumpInfo.setSourceActivityId(sourceTask.getTaskDefinitionKey());
    this.jumpInfo.setSourceActivity(processDefinitionEntity
            .findActivity(this.jumpInfo.getSourceActivityId()));

    HistoricTaskInstanceEntity sourceHistoryTask = Context
            .getCommandContext().getHistoricTaskInstanceEntityManager()
            .findHistoricTaskInstanceById(this.jumpInfo.getSourceTaskId());
}
 
Example #22
Source File: ActivitiInternalProcessConnector.java    From lemon with Apache License 2.0 5 votes vote down vote up
/**
 * 获得开始事件id.
 */
public String findInitialActivityId(String processDefinitionId) {
    GetDeploymentProcessDefinitionCmd getDeploymentProcessDefinitionCmd = new GetDeploymentProcessDefinitionCmd(
            processDefinitionId);
    ProcessDefinitionEntity processDefinition = processEngine
            .getManagementService().executeCommand(
                    getDeploymentProcessDefinitionCmd);

    return processDefinition.getInitial().getId();
}
 
Example #23
Source File: BpmnDeploymentHelper.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
/**
 * @param processDefinition
 */
public void addAuthorizationsForNewProcessDefinition(Process process, ProcessDefinitionEntity processDefinition) {
  CommandContext commandContext = Context.getCommandContext();
  
  addAuthorizationsFromIterator(commandContext, process.getCandidateStarterUsers(), processDefinition, ExpressionType.USER);
  addAuthorizationsFromIterator(commandContext, process.getCandidateStarterGroups(), processDefinition, ExpressionType.GROUP);
}
 
Example #24
Source File: ProcessExtensionServiceImpl.java    From activiti-demo with Apache License 2.0 5 votes vote down vote up
/**
 * 根据任务ID获取流程定义
 * @param taskId 任务ID
 * @return
 * @throws Exception
 */
public ProcessDefinitionEntity findProcessDefinitionEntityByTaskId(String taskId)throws Exception{

     ProcessDefinitionEntity processDefinition = (ProcessDefinitionEntity)((RepositoryServiceImpl) repositoryService).getDeployedProcessDefinition(findTaskById(taskId).getProcessDefinitionId());

     if(processDefinition == null){
         throw new Exception("流程定义未找到!");
     }
     return processDefinition;
}
 
Example #25
Source File: BpmResource.java    From lemon with Apache License 2.0 5 votes vote down vote up
private JsonNode getProcessDefinitionResponse(
        ProcessDefinitionEntity processDefinition) {
    ObjectMapper mapper = new ObjectMapper();
    ObjectNode pdrJSON = mapper.createObjectNode();
    pdrJSON.put("id", processDefinition.getId());
    pdrJSON.put("name", processDefinition.getName());
    pdrJSON.put("key", processDefinition.getKey());
    pdrJSON.put("version", processDefinition.getVersion());
    pdrJSON.put("deploymentId", processDefinition.getDeploymentId());
    pdrJSON.put("isGraphicNotationDefined",
            isGraphicNotationDefined(processDefinition));

    return pdrJSON;
}
 
Example #26
Source File: DefaultStartFormHandler.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@Override
public void parseConfiguration(List<FormProperty> formProperties, String formKey, DeploymentEntity deployment, ProcessDefinition processDefinition) {
    super.parseConfiguration(formProperties, formKey, deployment, processDefinition);
    if (StringUtils.isNotEmpty(formKey)) {
        ((ProcessDefinitionEntity) processDefinition).setStartFormKey(true);
    }
}
 
Example #27
Source File: BpmnDeploymentHelper.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
/**
 * Verifies that no two process definitions share the same key, to prevent database unique
 * index violation.
 * 
 * @throws ActivitiException if any two processes have the same key
 */
public void verifyProcessDefinitionsDoNotShareKeys(
    Collection<ProcessDefinitionEntity> processDefinitions) {
  Set<String> keySet = new LinkedHashSet<String>();
  for (ProcessDefinitionEntity processDefinition : processDefinitions) {
    if (keySet.contains(processDefinition.getKey())) {
      throw new ActivitiException(
          "The deployment contains process definitions with the same key (process id attribute), this is not allowed");
    }
    keySet.add(processDefinition.getKey());
  }
}
 
Example #28
Source File: RollbackTaskCmd.java    From lemon with Apache License 2.0 5 votes vote down vote up
/**
 * 获得历史节点对应的节点信息.
 */
public ActivityImpl getActivity(
        HistoricActivityInstanceEntity historicActivityInstanceEntity) {
    ProcessDefinitionEntity processDefinitionEntity = new GetDeploymentProcessDefinitionCmd(
            historicActivityInstanceEntity.getProcessDefinitionId())
            .execute(Context.getCommandContext());

    return processDefinitionEntity
            .findActivity(historicActivityInstanceEntity.getActivityId());
}
 
Example #29
Source File: ProcessDefinitionDiagramHelper.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
/**
 * Generates a diagram resource for a ProcessDefinitionEntity and associated BpmnParse.  The
 * returned resource has not yet been persisted, nor attached to the ProcessDefinitionEntity.
 * This requires that the ProcessDefinitionEntity have its key and resource name already set.
 * 
 * The caller must determine whether creating a diagram for this process definition is appropriate or not,
 * for example see {@link #shouldCreateDiagram(ProcessDefinitionEntity, DeploymentEntity)}.
 */
public ResourceEntity createDiagramForProcessDefinition(ProcessDefinitionEntity processDefinition, BpmnParse bpmnParse) {
  
  if (StringUtils.isEmpty(processDefinition.getKey()) || StringUtils.isEmpty(processDefinition.getResourceName())) {
    throw new IllegalStateException("Provided process definition must have both key and resource name set.");
  }
  
  ResourceEntity resource = createResourceEntity();
  ProcessEngineConfiguration processEngineConfiguration = Context.getCommandContext().getProcessEngineConfiguration();
  try {
    byte[] diagramBytes = IoUtil.readInputStream(
        processEngineConfiguration.getProcessDiagramGenerator().generateDiagram(bpmnParse.getBpmnModel(), "png",
            processEngineConfiguration.getActivityFontName(),
            processEngineConfiguration.getLabelFontName(),
            processEngineConfiguration.getAnnotationFontName(),
            processEngineConfiguration.getClassLoader()), null);
      String diagramResourceName = ResourceNameUtil.getProcessDiagramResourceName(
          processDefinition.getResourceName(), processDefinition.getKey(), "png");
      
      resource.setName(diagramResourceName);
      resource.setBytes(diagramBytes);
      resource.setDeploymentId(processDefinition.getDeploymentId());

      // Mark the resource as 'generated'
      resource.setGenerated(true);
      
  } catch (Throwable t) { // if anything goes wrong, we don't store the image (the process will still be executable).
    log.warn("Error while generating process diagram, image will not be stored in repository", t);
    resource = null;
  }
  
  return resource;
}
 
Example #30
Source File: SignalEventHandler.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@Override
public void handleEvent(EventSubscriptionEntity eventSubscription, Object payload, CommandContext commandContext) {
    if (eventSubscription.getExecutionId() != null) {
        super.handleEvent(eventSubscription, payload, commandContext);
    } else if (eventSubscription.getProcessDefinitionId() != null) {
        // Start event
        String processDefinitionId = eventSubscription.getProcessDefinitionId();
        DeploymentManager deploymentCache = Context
                .getProcessEngineConfiguration()
                .getDeploymentManager();

        ProcessDefinitionEntity processDefinition = (ProcessDefinitionEntity) deploymentCache.findDeployedProcessDefinitionById(processDefinitionId);
        if (processDefinition == null) {
            throw new ActivitiObjectNotFoundException("No process definition found for id '" + processDefinitionId + "'", ProcessDefinition.class);
        }

        ActivityImpl startActivity = processDefinition.findActivity(eventSubscription.getActivityId());
        if (startActivity == null) {
            throw new ActivitiException("Could no handle signal: no start activity found with id " + eventSubscription.getActivityId());
        }
        ExecutionEntity processInstance = processDefinition.createProcessInstance(null, startActivity);
        if (processInstance == null) {
            throw new ActivitiException("Could not handle signal: no process instance started");
        }

        if (payload != null) {
            if (payload instanceof Map) {
                Map<String, Object> variables = (Map<String, Object>) payload;
                processInstance.setVariables(variables);
            }
        }

        processInstance.start();
    } else {
        throw new ActivitiException("Invalid signal handling: no execution nor process definition set");
    }
}