Search in sources :

Example 1 with RepositoryService

use of org.flowable.engine.RepositoryService in project plumdo-work by wengwh.

the class DeployModelCmd method execute.

public Deployment execute(CommandContext commandContext) {
    Deployment deployment = null;
    RepositoryService repositoryService = commandContext.getProcessEngineConfiguration().getRepositoryService();
    Model model = repositoryService.getModel(modelId);
    if (model == null) {
        throw new FlowableObjectNotFoundException("Could not find a model with id '" + modelId + "'.", Model.class);
    }
    byte[] editorSource = commandContext.getModelEntityManager().findEditorSourceByModelId(modelId);
    if (editorSource == null) {
        throw new FlowableObjectNotFoundException("Model with id '" + modelId + "' does not have source available.", String.class);
    }
    try {
        DeploymentBuilder deploymentBuilder = repositoryService.createDeployment();
        ObjectNode modelNode = (ObjectNode) new ObjectMapper().readTree(editorSource);
        BpmnModel bpmnModel = new BpmnJsonConverter().convertToBpmnModel(modelNode);
        byte[] bpmnBytes = new BpmnXMLConverter().convertToXML(bpmnModel);
        String fileName = model.getId() + ".bpmn20.xml";
        ByteArrayInputStream bis = new ByteArrayInputStream(bpmnBytes);
        deploymentBuilder.addInputStream(fileName, bis);
        deploymentBuilder.name(fileName);
        // modelId设置为部署的分类字段作为后续关联的需要
        deploymentBuilder.category(model.getId());
        if (model.getTenantId() != null) {
            deploymentBuilder.tenantId(model.getTenantId());
        }
        deployment = deploymentBuilder.deploy();
        // 设置模型的部署ID
        model.setDeploymentId(deployment.getId());
    } catch (Exception e) {
        if (e instanceof FlowableException) {
            throw (FlowableException) e;
        }
        throw new FlowableException(e.getMessage(), e);
    }
    return deployment;
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) Deployment(org.flowable.engine.repository.Deployment) FlowableObjectNotFoundException(org.flowable.engine.common.api.FlowableObjectNotFoundException) FlowableException(org.flowable.engine.common.api.FlowableException) BpmnModel(org.flowable.bpmn.model.BpmnModel) BpmnXMLConverter(org.flowable.bpmn.converter.BpmnXMLConverter) FlowableObjectNotFoundException(org.flowable.engine.common.api.FlowableObjectNotFoundException) FlowableException(org.flowable.engine.common.api.FlowableException) ByteArrayInputStream(java.io.ByteArrayInputStream) Model(org.flowable.engine.repository.Model) BpmnModel(org.flowable.bpmn.model.BpmnModel) BpmnJsonConverter(org.flowable.editor.language.json.converter.BpmnJsonConverter) DeploymentBuilder(org.flowable.engine.repository.DeploymentBuilder) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) RepositoryService(org.flowable.engine.RepositoryService)

Aggregations

ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 BpmnXMLConverter (org.flowable.bpmn.converter.BpmnXMLConverter)1 BpmnModel (org.flowable.bpmn.model.BpmnModel)1 BpmnJsonConverter (org.flowable.editor.language.json.converter.BpmnJsonConverter)1 RepositoryService (org.flowable.engine.RepositoryService)1 FlowableException (org.flowable.engine.common.api.FlowableException)1 FlowableObjectNotFoundException (org.flowable.engine.common.api.FlowableObjectNotFoundException)1 Deployment (org.flowable.engine.repository.Deployment)1 DeploymentBuilder (org.flowable.engine.repository.DeploymentBuilder)1 Model (org.flowable.engine.repository.Model)1