Search in sources :

Example 1 with Model

use of org.flowable.engine.repository.Model 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)

Example 2 with Model

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

the class ModelDeployResource method deployModel.

@RequestMapping(value = "/model/{modelId}/deploy", method = RequestMethod.POST, produces = "application/json", name = "模型部署")
@ResponseStatus(value = HttpStatus.CREATED)
@Transactional(propagation = Propagation.REQUIRED)
public ProcessDefinitionResponse deployModel(@PathVariable String modelId) {
    Model model = getModelFromRequest(modelId);
    Deployment deployment = managementService.executeCommand(new DeployModelCmd(model.getId()));
    ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().deploymentId(deployment.getId()).singleResult();
    return restResponseFactory.createProcessDefinitionResponse(processDefinition);
}
Also used : Model(org.flowable.engine.repository.Model) Deployment(org.flowable.engine.repository.Deployment) ProcessDefinition(org.flowable.engine.repository.ProcessDefinition) DeployModelCmd(com.plumdo.flow.cmd.DeployModelCmd) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) Transactional(org.springframework.transaction.annotation.Transactional)

Example 3 with Model

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

the class ModelResource method deleteModel.

@RequestMapping(value = "/model/{modelId}", method = RequestMethod.DELETE, name = "模型删除")
@ResponseStatus(value = HttpStatus.NO_CONTENT)
public void deleteModel(@PathVariable String modelId) {
    Model model = getModelFromRequest(modelId);
    repositoryService.deleteModel(model.getId());
}
Also used : Model(org.flowable.engine.repository.Model) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 4 with Model

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

the class ModelXmlResource method getModelXml.

@RequestMapping(value = "/model/{modelId}/xml", method = RequestMethod.GET, name = "获取模型XML")
public ResponseEntity<byte[]> getModelXml(@PathVariable String modelId) {
    Model model = getModelFromRequest(modelId);
    try {
        BpmnJsonConverter jsonConverter = new BpmnJsonConverter();
        JsonNode editorNode = new ObjectMapper().readTree(repositoryService.getModelEditorSource(model.getId()));
        BpmnModel bpmnModel = jsonConverter.convertToBpmnModel(editorNode);
        BpmnXMLConverter xmlConverter = new BpmnXMLConverter();
        byte[] bpmnBytes = xmlConverter.convertToXML(bpmnModel);
        ByteArrayInputStream in = new ByteArrayInputStream(bpmnBytes);
        HttpHeaders responseHeaders = new HttpHeaders();
        responseHeaders.setContentType(MediaType.TEXT_XML);
        return new ResponseEntity<byte[]>(IOUtils.toByteArray(in), responseHeaders, HttpStatus.OK);
    } catch (Exception e) {
        throw new FlowableException("Error converting resource stream", e);
    }
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) ResponseEntity(org.springframework.http.ResponseEntity) FlowableException(org.flowable.engine.common.api.FlowableException) ByteArrayInputStream(java.io.ByteArrayInputStream) Model(org.flowable.engine.repository.Model) BpmnModel(org.flowable.bpmn.model.BpmnModel) JsonNode(com.fasterxml.jackson.databind.JsonNode) BpmnJsonConverter(org.flowable.editor.language.json.converter.BpmnJsonConverter) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) FlowableException(org.flowable.engine.common.api.FlowableException) BpmnModel(org.flowable.bpmn.model.BpmnModel) BpmnXMLConverter(org.flowable.bpmn.converter.BpmnXMLConverter) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 5 with Model

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

the class ModelEditorResource method saveModel.

@RequestMapping(value = "/models/{modelId}/editor", method = { RequestMethod.POST }, name = "模型设计器保存模型")
@ResponseStatus(value = HttpStatus.OK)
@Transactional(propagation = Propagation.REQUIRED)
public void saveModel(@PathVariable String modelId, @RequestBody ModelEditorJsonRequest values) {
    try {
        Model model = getModelFromRequest(modelId);
        ObjectNode modelJson = (ObjectNode) objectMapper.readTree(model.getMetaInfo());
        modelJson.put(MODEL_NAME, values.getName());
        modelJson.put(MODEL_DESCRIPTION, values.getDescription());
        model.setMetaInfo(modelJson.toString());
        model.setName(values.getName());
        if (model.getDeploymentId() != null) {
            model.setDeploymentId(null);
        }
        if (values.isAddVersion()) {
            model.setVersion(model.getVersion() + 1);
        }
        repositoryService.saveModel(model);
        repositoryService.addModelEditorSource(model.getId(), values.getJson_xml().getBytes("utf-8"));
        ObjectNode modelNode = (ObjectNode) new ObjectMapper().readTree(values.getJson_xml().getBytes("utf-8"));
        BpmnModel bpmnModel = new BpmnJsonConverter().convertToBpmnModel(modelNode);
        ProcessDiagramGenerator diagramGenerator = processEngineConfiguration.getProcessDiagramGenerator();
        InputStream resource = diagramGenerator.generateDiagram(bpmnModel, "png", Collections.<String>emptyList(), Collections.<String>emptyList(), processEngineConfiguration.getActivityFontName(), processEngineConfiguration.getLabelFontName(), processEngineConfiguration.getAnnotationFontName(), processEngineConfiguration.getClassLoader(), 1.0);
        repositoryService.addModelEditorSourceExtra(model.getId(), IOUtils.toByteArray(resource));
    } catch (Exception e) {
        LOGGER.error("Error saving model", e);
        throw new FlowableException("Error saving model", e);
    }
}
Also used : FlowableException(org.flowable.engine.common.api.FlowableException) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) ProcessDiagramGenerator(org.flowable.image.ProcessDiagramGenerator) InputStream(java.io.InputStream) Model(org.flowable.engine.repository.Model) BpmnModel(org.flowable.bpmn.model.BpmnModel) BpmnJsonConverter(org.flowable.editor.language.json.converter.BpmnJsonConverter) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) FlowableException(org.flowable.engine.common.api.FlowableException) BpmnModel(org.flowable.bpmn.model.BpmnModel) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

Model (org.flowable.engine.repository.Model)11 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)10 FlowableException (org.flowable.engine.common.api.FlowableException)7 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)6 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)6 BpmnModel (org.flowable.bpmn.model.BpmnModel)6 ResponseStatus (org.springframework.web.bind.annotation.ResponseStatus)6 BpmnJsonConverter (org.flowable.editor.language.json.converter.BpmnJsonConverter)5 Transactional (org.springframework.transaction.annotation.Transactional)5 BpmnXMLConverter (org.flowable.bpmn.converter.BpmnXMLConverter)4 InputStream (java.io.InputStream)3 Deployment (org.flowable.engine.repository.Deployment)3 ProcessDefinition (org.flowable.engine.repository.ProcessDefinition)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 InputStreamReader (java.io.InputStreamReader)2 XMLInputFactory (javax.xml.stream.XMLInputFactory)2 XMLStreamReader (javax.xml.stream.XMLStreamReader)2 FlowableObjectNotFoundException (org.flowable.engine.common.api.FlowableObjectNotFoundException)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 DeployModelCmd (com.plumdo.flow.cmd.DeployModelCmd)1