Java Code Examples for org.flowable.engine.repository.ProcessDefinition#getDeploymentId()

The following examples show how to use org.flowable.engine.repository.ProcessDefinition#getDeploymentId() . 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: GetDeploymentProcessDiagramCmd.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
@Override
public InputStream execute(CommandContext commandContext) {
    ProcessDefinition processDefinition = commandContext
            .getProcessEngineConfiguration()
            .getDeploymentManager()
            .findDeployedProcessDefinitionById(processDefinitionId);
    String deploymentId = processDefinition.getDeploymentId();
    String resourceName = processDefinition.getDiagramResourceName();
    if (resourceName == null) {
        LOGGER.info("Resource name is null! No process diagram stream exists.");
        return null;
    } else {
        InputStream processDiagramStream = new GetDeploymentResourceCmd(deploymentId, resourceName)
                .execute(commandContext);
        return processDiagramStream;
    }
}
 
Example 2
Source File: DeploymentManager.java    From flowable-engine 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 3
Source File: DeploymentManager.java    From flowable-engine 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) {
        if (Flowable5Util.isFlowable5ProcessDefinition(processDefinition, processEngineConfiguration)) {
            return Flowable5Util.getFlowable5CompatibilityHandler().resolveProcessDefinition(processDefinition);
        }

        DeploymentEntity deployment = deploymentEntityManager.findById(deploymentId);
        deployment.setNew(false);
        deploy(deployment, null);
        cachedProcessDefinition = processDefinitionCache.get(processDefinitionId);

        if (cachedProcessDefinition == null) {
            throw new FlowableException("deployment '" + deploymentId + "' didn't put process definition '" + processDefinitionId + "' in the cache");
        }
    }
    return cachedProcessDefinition;
}
 
Example 4
Source File: GetDeploymentProcessModelCmd.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@Override
public InputStream execute(CommandContext commandContext) {
    ProcessDefinition processDefinition = CommandContextUtil.getProcessEngineConfiguration(commandContext).getDeploymentManager().findDeployedProcessDefinitionById(processDefinitionId);
    String deploymentId = processDefinition.getDeploymentId();
    String resourceName = processDefinition.getResourceName();
    InputStream processModelStream = new GetDeploymentResourceCmd(deploymentId, resourceName).execute(commandContext);
    return processModelStream;
}
 
Example 5
Source File: FlowableBpmnProcessManager.java    From syncope with Apache License 2.0 5 votes vote down vote up
protected Model getModel(final ProcessDefinition procDef) {
    try {
        Model model = engine.getRepositoryService().createModelQuery().
                deploymentId(procDef.getDeploymentId()).singleResult();
        if (model == null) {
            throw new NotFoundException("Could not find Model for deployment " + procDef.getDeploymentId());
        }
        return model;
    } catch (Exception e) {
        throw new WorkflowException("While accessing process " + procDef.getKey(), e);
    }
}
 
Example 6
Source File: GetDeploymentProcessModelCmd.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@Override
public InputStream execute(CommandContext commandContext) {
    ProcessDefinition processDefinition = commandContext
            .getProcessEngineConfiguration()
            .getDeploymentManager()
            .findDeployedProcessDefinitionById(processDefinitionId);
    String deploymentId = processDefinition.getDeploymentId();
    String resourceName = processDefinition.getResourceName();
    InputStream processModelStream = new GetDeploymentResourceCmd(deploymentId, resourceName)
            .execute(commandContext);
    return processModelStream;
}
 
Example 7
Source File: DeploymentManager.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
public BpmnModel getBpmnModelById(String processDefinitionId) {
    if (processDefinitionId == null) {
        throw new ActivitiIllegalArgumentException("Invalid process definition id : null");
    }

    // first try the cache
    BpmnModel bpmnModel = bpmnModelCache.get(processDefinitionId);

    if (bpmnModel == null) {
        ProcessDefinition processDefinition = findDeployedProcessDefinitionById(processDefinitionId);
        if (processDefinition == null) {
            throw new ActivitiObjectNotFoundException("no deployed process definition found with id '" + processDefinitionId + "'", ProcessDefinition.class);
        }

        // Fetch the resource
        String resourceName = processDefinition.getResourceName();
        ResourceEntity resource = Context.getCommandContext().getResourceEntityManager()
                .findResourceByDeploymentIdAndResourceName(processDefinition.getDeploymentId(), resourceName);
        if (resource == null) {
            if (Context.getCommandContext().getDeploymentEntityManager().findDeploymentById(processDefinition.getDeploymentId()) == null) {
                throw new ActivitiObjectNotFoundException("deployment for process definition does not exist: "
                        + processDefinition.getDeploymentId(), Deployment.class);
            } else {
                throw new ActivitiObjectNotFoundException("no resource found with name '" + resourceName
                        + "' in deployment '" + processDefinition.getDeploymentId() + "'", InputStream.class);
            }
        }

        // Convert the bpmn 2.0 xml to a bpmn model
        BpmnXMLConverter bpmnXMLConverter = new BpmnXMLConverter();
        bpmnModel = bpmnXMLConverter.convertToBpmnModel(new BytesStreamSource(resource.getBytes()), false, false);
        bpmnModelCache.add(processDefinition.getId(), bpmnModel);
    }
    return bpmnModel;
}
 
Example 8
Source File: BusinessRuleTaskActivityBehavior.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@Override
public void execute(DelegateExecution execution) {
    ProcessDefinition processDefinition = ProcessDefinitionUtil.getProcessDefinition(execution.getProcessDefinitionId());
    String deploymentId = processDefinition.getDeploymentId();

    KieBase knowledgeBase = RulesHelper.findKnowledgeBaseByDeploymentId(deploymentId);
    KieSession ksession = knowledgeBase.newKieSession();

    if (variablesInputExpressions != null) {
        Iterator<Expression> itVariable = variablesInputExpressions.iterator();
        while (itVariable.hasNext()) {
            Expression variable = itVariable.next();
            ksession.insert(variable.getValue(execution));
        }
    }

    if (!rulesExpressions.isEmpty()) {
        RulesAgendaFilter filter = new RulesAgendaFilter();
        Iterator<Expression> itRuleNames = rulesExpressions.iterator();
        while (itRuleNames.hasNext()) {
            Expression ruleName = itRuleNames.next();
            filter.addSuffic(ruleName.getValue(execution).toString());
        }
        filter.setAccept(!exclude);
        ksession.fireAllRules(filter);

    } else {
        ksession.fireAllRules();
    }

    Collection<? extends Object> ruleOutputObjects = ksession.getObjects();
    if (ruleOutputObjects != null && !ruleOutputObjects.isEmpty()) {
        Collection<Object> outputVariables = new ArrayList<>(ruleOutputObjects);
        execution.setVariable(resultVariable, outputVariables);
    }
    ksession.dispose();
    leave(execution);
}
 
Example 9
Source File: GetDeploymentProcessDiagramCmd.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@Override
public InputStream execute(CommandContext commandContext) {
    ProcessDefinition processDefinition = CommandContextUtil.getProcessEngineConfiguration(commandContext).getDeploymentManager().findDeployedProcessDefinitionById(processDefinitionId);
    String deploymentId = processDefinition.getDeploymentId();
    String resourceName = processDefinition.getDiagramResourceName();
    if (resourceName == null) {
        LOGGER.info("Resource name is null! No process diagram stream exists.");
        return null;
    } else {
        InputStream processDiagramStream = new GetDeploymentResourceCmd(deploymentId, resourceName).execute(commandContext);
        return processDiagramStream;
    }
}
 
Example 10
Source File: ProcessDefinitionUtil.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
public static String getDefinitionDeploymentId(ProcessDefinition processDefinition, ProcessEngineConfigurationImpl processEngineConfiguration) {
    if (processDefinition != null) {
        DeploymentManager deploymentManager = processEngineConfiguration.getDeploymentManager();
        DeploymentEntity processDeployment = deploymentManager.getDeploymentEntityManager().findById(processDefinition.getDeploymentId());
        if (StringUtils.isEmpty(processDeployment.getParentDeploymentId())) {
            return processDefinition.getDeploymentId();
        }
        return processDeployment.getParentDeploymentId();
    }

    return null;
}
 
Example 11
Source File: ProcessInstanceRepresentation.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
protected void mapProcessDefinition(ProcessDefinition processDefinition) {
    if (processDefinition != null) {
        this.processDefinitionName = processDefinition.getName();
        this.processDefinitionDescription = processDefinition.getDescription();
        this.processDefinitionKey = processDefinition.getKey();
        this.processDefinitionCategory = processDefinition.getCategory();
        this.processDefinitionVersion = processDefinition.getVersion();
        this.processDefinitionDeploymentId = processDefinition.getDeploymentId();
    }
}
 
Example 12
Source File: ProcessDefinitionRepresentation.java    From flowable-engine 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 13
Source File: TaskRepresentation.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
public TaskRepresentation(TaskInfo taskInfo, ProcessDefinition processDefinition) {
    initializeTaskDetails(taskInfo);

    if (processDefinition != null) {
        this.processDefinitionName = processDefinition.getName();
        this.processDefinitionDescription = processDefinition.getDescription();
        this.processDefinitionKey = processDefinition.getKey();
        this.processDefinitionCategory = processDefinition.getCategory();
        this.processDefinitionVersion = processDefinition.getVersion();
        this.processDefinitionDeploymentId = processDefinition.getDeploymentId();
    }
}
 
Example 14
Source File: ProcessDefinitionXmlResource.java    From plumdo-work with Apache License 2.0 5 votes vote down vote up
@GetMapping(value = "/process-definitions/{processDefinitionId}/xml", name = "获取流程定义XML")
public ResponseEntity<byte[]> getProcessDefinitionXml(@PathVariable String processDefinitionId) {
    ProcessDefinition processDefinition = getProcessDefinitionFromRequest(processDefinitionId);
    String deploymentId = processDefinition.getDeploymentId();
    String resourceId = processDefinition.getResourceName();
    if (deploymentId == null) {
        exceptionFactory.throwObjectNotFound(ErrorConstant.DEFINITION_DEPLOY_NOT_FOUND, processDefinitionId);
    }
    if (resourceId == null) {
        exceptionFactory.throwObjectNotFound(ErrorConstant.DEFINITION_RESOURCE_NOT_FOUND, processDefinitionId);
    }

    Deployment deployment = repositoryService.createDeploymentQuery().deploymentId(deploymentId).singleResult();
    if (deployment == null) {
        exceptionFactory.throwObjectNotFound(ErrorConstant.DEPLOY_NOT_FOUND, deploymentId);
    }

    List<String> resourceList = repositoryService.getDeploymentResourceNames(deploymentId);
    if (ObjectUtils.isEmpty(resourceList) || !resourceList.contains(resourceId)) {
        exceptionFactory.throwObjectNotFound(ErrorConstant.DEPLOY_RESOURCE_NOT_FOUND, deploymentId, resourceId);
    }
    InputStream resourceStream = repositoryService.getResourceAsStream(deploymentId, resourceId);
    HttpHeaders responseHeaders = new HttpHeaders();
    responseHeaders.setContentType(MediaType.TEXT_XML);
    try {
        return new ResponseEntity<>(IOUtils.toByteArray(resourceStream), responseHeaders, HttpStatus.OK);
    } catch (Exception e) {
        logger.error("获取流程定义XML信息异常", e);
        exceptionFactory.throwDefinedException(ErrorConstant.DEFINITION_XML_READ_ERROR, e.getMessage());
    }
    return null;

}
 
Example 15
Source File: ProcessDefinitionResource.java    From plumdo-work with Apache License 2.0 5 votes vote down vote up
@DeleteMapping(value = "/process-definitions/{processDefinitionId}", name = "流程定义删除")
@ResponseStatus(value = HttpStatus.NO_CONTENT)
@Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
public void deleteProcessDefinition(@PathVariable String processDefinitionId, @RequestParam(value = "cascade", required = false, defaultValue = "false") Boolean cascade) {
    ProcessDefinition processDefinition = getProcessDefinitionFromRequest(processDefinitionId);

    if (processDefinition.getDeploymentId() == null) {
        exceptionFactory.throwObjectNotFound(ErrorConstant.DEFINITION_DEPLOY_NOT_FOUND, processDefinitionId);
    }

    if (cascade) {
        List<Job> jobs = managementService.createTimerJobQuery().processDefinitionId(processDefinitionId).list();
        for (Job job : jobs) {
            managementService.deleteTimerJob(job.getId());
        }
        repositoryService.deleteDeployment(processDefinition.getDeploymentId(), true);
    } else {
        long processCount = runtimeService.createProcessInstanceQuery().processDefinitionId(processDefinitionId).count();
        if (processCount > 0) {
            exceptionFactory.throwForbidden(ErrorConstant.DEFINITION_HAVE_INSTANCE, processDefinitionId);
        }

        long jobCount = managementService.createTimerJobQuery().processDefinitionId(processDefinitionId).count();
        if (jobCount > 0) {
            exceptionFactory.throwForbidden(ErrorConstant.DEFINITION_HAVE_TIME_JOB, processDefinitionId);
        }
        repositoryService.deleteDeployment(processDefinition.getDeploymentId());
    }
}
 
Example 16
Source File: ProcessDefinitionGetModelResource.java    From plumdo-work with Apache License 2.0 4 votes vote down vote up
@RequestMapping(value = "/process-definitions/{processDefinitionId}/getModel", method = RequestMethod.GET, produces = "application/json", name = "流程定义获取对应模型")
public ModelResponse processDefinitionGetModel(@PathVariable String processDefinitionId) {
    ProcessDefinition processDefinition = getProcessDefinitionFromRequest(processDefinitionId);
    try {
        Deployment deployment = repositoryService.createDeploymentQuery().deploymentId(processDefinition.getDeploymentId()).singleResult();

        if (deployment == null) {
            throw new FlowableObjectNotFoundException("Could not find a process deployment with id '" + processDefinition.getDeploymentId() + "'.", Deployment.class);
        }
        Model modelData = null;

        if (deployment.getCategory() != null) {
            modelData = repositoryService.getModel(deployment.getCategory());
        }
        //如果不存在,创建对应模型
        if (modelData == null) {
            InputStream bpmnStream = repositoryService.getResourceAsStream(processDefinition.getDeploymentId(), processDefinition.getResourceName());
            XMLInputFactory xif = XMLInputFactory.newInstance();
            InputStreamReader in = new InputStreamReader(bpmnStream, "UTF-8");
            XMLStreamReader xtr = xif.createXMLStreamReader(in);
            BpmnModel bpmnModel = new BpmnXMLConverter().convertToBpmnModel(xtr);

            BpmnJsonConverter converter = new BpmnJsonConverter();
            ObjectNode modelNode = converter.convertToJson(bpmnModel);
            modelData = repositoryService.newModel();
            modelData.setKey(processDefinition.getKey());
            modelData.setName(processDefinition.getName());
            modelData.setCategory(processDefinition.getCategory());

            ObjectNode modelObjectNode = new ObjectMapper().createObjectNode();
            modelObjectNode.put(ModelDataJsonConstants.MODEL_NAME, processDefinition.getName());
            modelObjectNode.put(ModelDataJsonConstants.MODEL_REVISION, 1);
            modelObjectNode.put(ModelDataJsonConstants.MODEL_DESCRIPTION, processDefinition.getDescription());
            modelData.setMetaInfo(modelObjectNode.toString());

            repositoryService.saveModel(modelData);

            repositoryService.addModelEditorSource(modelData.getId(), modelNode.toString().getBytes("utf-8"));
            repositoryService.addModelEditorSourceExtra(modelData.getId(), IOUtils.toByteArray(managementService.executeCommand(new GetDeploymentProcessDiagramCmd(processDefinitionId))));

            repositoryService.setDeploymentCategory(processDefinition.getDeploymentId(), modelData.getId());
        }
        return restResponseFactory.createModelResponse(modelData);

    } catch (Exception e) {
        throw new FlowableException("Error  process-definition get model", e);
    }
}
 
Example 17
Source File: TenancyTest.java    From flowable-engine with Apache License 2.0 4 votes vote down vote up
@Test
public void testChangeDeploymentTenantId_withMergingTwoTenantsByDateOfdeployment_ensureDeploymentsOrderedCorrectly() {
    List<String> expectedOrderOfProcessDefinitionIds = new ArrayList<>();
    expectedOrderOfProcessDefinitionIds.add(deployOneTaskTestProcess());
    expectedOrderOfProcessDefinitionIds.add(deployOneTaskTestProcess());
    String processDefinitionIdWithTenant = deployTestProcessWithTestTenant("tenantA");
    expectedOrderOfProcessDefinitionIds.add(processDefinitionIdWithTenant);
    expectedOrderOfProcessDefinitionIds.add(deployOneTaskTestProcess());
    expectedOrderOfProcessDefinitionIds.add(deployOneTaskTestProcess());
    ProcessDefinition processDefinitionToBeMerged = this.repositoryService.createProcessDefinitionQuery()
            .processDefinitionId(processDefinitionIdWithTenant)
            .singleResult();
    String processDefinitionKey = processDefinitionToBeMerged.getKey();
    String deploymentId = processDefinitionToBeMerged.getDeploymentId();

    // Act
    repositoryService.changeDeploymentTenantId(deploymentId, "", MergeMode.BY_DATE);

    // Assert
    // Since we are using the "by-date" merge strategy, the version number of the original one should be matches
    List<ProcessDefinition> allDeployedProcessDefinitions = this.repositoryService.createProcessDefinitionQuery()
            .processDefinitionKey(processDefinitionKey)
            .processDefinitionWithoutTenantId()
            .orderByProcessDefinitionVersion()
            .asc()
            .list();
    assertThat(allDeployedProcessDefinitions).hasSize(5);
    assertThat(allDeployedProcessDefinitions)
            .extracting(ProcessDefinition::getId)
            .containsExactlyElementsOf(expectedOrderOfProcessDefinitionIds);
    assertThat(allDeployedProcessDefinitions)
            .extracting(ProcessDefinition::getVersion)
            .containsExactly(1, 2, 3, 4, 5);

    assertThat(this.repositoryService.createProcessDefinitionQuery()
            .processDefinitionTenantId("tenantA")
            .count()).isEqualTo(0);

    // Deploying another version should just up the version
    String processDefinitionIdNoTenant2 = deployOneTaskTestProcess();
    assertThat(repositoryService.createProcessDefinitionQuery()
            .processDefinitionId(processDefinitionIdNoTenant2)
            .singleResult()
            .getVersion())
            .isEqualTo(6);
}