Search in sources :

Example 36 with BpmnModel

use of org.activiti.bpmn.model.BpmnModel in project tutorials-java by Artister.

the class ModelController method deployUploadedFile.

@ApiOperation(value = "上传一个已有模型")
@RequestMapping(value = "/uploadFile", method = RequestMethod.POST)
public void deployUploadedFile(@RequestParam("uploadfile") MultipartFile uploadfile) {
    InputStreamReader in = null;
    try {
        try {
            boolean validFile = false;
            String fileName = uploadfile.getOriginalFilename();
            if (fileName.endsWith(".bpmn20.xml") || fileName.endsWith(".bpmn")) {
                validFile = true;
                XMLInputFactory xif = XmlUtil.createSafeXmlInputFactory();
                in = new InputStreamReader(new ByteArrayInputStream(uploadfile.getBytes()), "UTF-8");
                XMLStreamReader xtr = xif.createXMLStreamReader(in);
                BpmnModel bpmnModel = new BpmnXMLConverter().convertToBpmnModel(xtr);
                if (bpmnModel.getMainProcess() == null || bpmnModel.getMainProcess().getId() == null) {
                    // notificationManager.showErrorNotification(Messages.MODEL_IMPORT_FAILED,
                    // i18nManager.getMessage(Messages.MODEL_IMPORT_INVALID_BPMN_EXPLANATION));
                    System.out.println("err1");
                } else {
                    if (bpmnModel.getLocationMap().isEmpty()) {
                        // notificationManager.showErrorNotification(Messages.MODEL_IMPORT_INVALID_BPMNDI,
                        // i18nManager.getMessage(Messages.MODEL_IMPORT_INVALID_BPMNDI_EXPLANATION));
                        System.out.println("err2");
                    } else {
                        String processName = null;
                        if (StringUtils.isNotEmpty(bpmnModel.getMainProcess().getName())) {
                            processName = bpmnModel.getMainProcess().getName();
                        } else {
                            processName = bpmnModel.getMainProcess().getId();
                        }
                        Model modelData;
                        modelData = repositoryService.newModel();
                        ObjectNode modelObjectNode = new ObjectMapper().createObjectNode();
                        modelObjectNode.put(ModelDataJsonConstants.MODEL_NAME, processName);
                        modelObjectNode.put(ModelDataJsonConstants.MODEL_REVISION, 1);
                        modelData.setMetaInfo(modelObjectNode.toString());
                        modelData.setName(processName);
                        repositoryService.saveModel(modelData);
                        BpmnJsonConverter jsonConverter = new BpmnJsonConverter();
                        ObjectNode editorNode = jsonConverter.convertToJson(bpmnModel);
                        repositoryService.addModelEditorSource(modelData.getId(), editorNode.toString().getBytes("utf-8"));
                    }
                }
            } else {
                // notificationManager.showErrorNotification(Messages.MODEL_IMPORT_INVALID_FILE,
                // i18nManager.getMessage(Messages.MODEL_IMPORT_INVALID_FILE_EXPLANATION));
                System.out.println("err3");
            }
        } catch (Exception e) {
            String errorMsg = e.getMessage().replace(System.getProperty("line.separator"), "<br/>");
            // notificationManager.showErrorNotification(Messages.MODEL_IMPORT_FAILED, errorMsg);
            System.out.println("err4");
        }
    } finally {
        if (in != null) {
            try {
                in.close();
            } catch (IOException e) {
                // notificationManager.showErrorNotification("Server-side error", e.getMessage());
                System.out.println("err5");
            }
        }
    }
}
Also used : XMLStreamReader(javax.xml.stream.XMLStreamReader) InputStreamReader(java.io.InputStreamReader) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) IOException(java.io.IOException) IOException(java.io.IOException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) BpmnModel(org.activiti.bpmn.model.BpmnModel) BpmnXMLConverter(org.activiti.bpmn.converter.BpmnXMLConverter) ByteArrayInputStream(java.io.ByteArrayInputStream) Model(org.activiti.engine.repository.Model) BpmnModel(org.activiti.bpmn.model.BpmnModel) BpmnJsonConverter(org.activiti.editor.language.json.converter.BpmnJsonConverter) XMLInputFactory(javax.xml.stream.XMLInputFactory) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) ApiOperation(io.swagger.annotations.ApiOperation)

Example 37 with BpmnModel

use of org.activiti.bpmn.model.BpmnModel in project Activiti by Activiti.

the class CustomExtensionsConverterTest method convertXMLToModel.

@Test
public void convertXMLToModel() throws Exception {
    BpmnModel bpmnModel = readXMLFile();
    validateModel(bpmnModel);
}
Also used : BpmnModel(org.activiti.bpmn.model.BpmnModel) Test(org.junit.jupiter.api.Test)

Example 38 with BpmnModel

use of org.activiti.bpmn.model.BpmnModel in project Activiti by Activiti.

the class EndEventConverterTest method convertXMLToModel.

@Test
public void convertXMLToModel() throws Exception {
    BpmnModel bpmnModel = readXMLFile();
    validateModel(bpmnModel);
}
Also used : BpmnModel(org.activiti.bpmn.model.BpmnModel) Test(org.junit.jupiter.api.Test)

Example 39 with BpmnModel

use of org.activiti.bpmn.model.BpmnModel in project Activiti by Activiti.

the class EndEventConverterTest method convertModelToXML.

@Test
public void convertModelToXML() throws Exception {
    BpmnModel bpmnModel = readXMLFile();
    validateModel(exportAndReadXMLFile(bpmnModel));
}
Also used : BpmnModel(org.activiti.bpmn.model.BpmnModel) Test(org.junit.jupiter.api.Test)

Example 40 with BpmnModel

use of org.activiti.bpmn.model.BpmnModel in project Activiti by Activiti.

the class FormPropertiesConverterTest method convertJsonToModel.

@Test
public void convertJsonToModel() throws Exception {
    BpmnModel bpmnModel = readXMLFile();
    validateModel(bpmnModel);
}
Also used : BpmnModel(org.activiti.bpmn.model.BpmnModel) Test(org.junit.jupiter.api.Test)

Aggregations

BpmnModel (org.activiti.bpmn.model.BpmnModel)265 Test (org.junit.jupiter.api.Test)123 Test (org.junit.Test)57 Process (org.activiti.bpmn.model.Process)26 BpmnXMLConverter (org.activiti.bpmn.converter.BpmnXMLConverter)22 InputStream (java.io.InputStream)19 StartEvent (org.activiti.bpmn.model.StartEvent)17 SequenceFlow (org.activiti.bpmn.model.SequenceFlow)16 ArrayList (java.util.ArrayList)14 FlowElement (org.activiti.bpmn.model.FlowElement)13 ServiceTask (org.activiti.bpmn.model.ServiceTask)13 ProcessDefinition (org.activiti.engine.repository.ProcessDefinition)12 EndEvent (org.activiti.bpmn.model.EndEvent)11 ValidationError (org.activiti.validation.ValidationError)11 ByteArrayInputStream (java.io.ByteArrayInputStream)10 SubProcess (org.activiti.bpmn.model.SubProcess)10 JsonNode (com.fasterxml.jackson.databind.JsonNode)9 Deployment (org.activiti.engine.repository.Deployment)9 ProcessInstance (org.activiti.engine.runtime.ProcessInstance)9 ProcessDiagramGenerator (org.activiti.image.ProcessDiagramGenerator)9