Search in sources :

Example 31 with WorkflowDefinition

use of org.activiti.workflow.simple.definition.WorkflowDefinition in project Activiti by Activiti.

the class EditorProcessDefinitionDetailPanel method exportModel.

protected void exportModel() {
    final FileResource stream = new FileResource(new File(""), ExplorerApp.get()) {

        private static final long serialVersionUID = 1L;

        @Override
        public DownloadStream getStream() {
            DownloadStream ds = null;
            try {
                byte[] bpmnBytes = null;
                String filename = null;
                if (SimpleTableEditorConstants.TABLE_EDITOR_CATEGORY.equals(modelData.getCategory())) {
                    WorkflowDefinition workflowDefinition = ExplorerApp.get().getSimpleWorkflowJsonConverter().readWorkflowDefinition(repositoryService.getModelEditorSource(modelData.getId()));
                    filename = workflowDefinition.getName();
                    WorkflowDefinitionConversion conversion = ExplorerApp.get().getWorkflowDefinitionConversionFactory().createWorkflowDefinitionConversion(workflowDefinition);
                    bpmnBytes = conversion.getBpmn20Xml().getBytes("utf-8");
                } else {
                    JsonNode editorNode = new ObjectMapper().readTree(repositoryService.getModelEditorSource(modelData.getId()));
                    BpmnJsonConverter jsonConverter = new BpmnJsonConverter();
                    BpmnModel model = jsonConverter.convertToBpmnModel(editorNode);
                    filename = model.getMainProcess().getId() + ".bpmn20.xml";
                    bpmnBytes = new BpmnXMLConverter().convertToXML(model);
                }
                ByteArrayInputStream in = new ByteArrayInputStream(bpmnBytes);
                ds = new DownloadStream(in, "application/xml", filename);
                // Need a file download POPUP
                ds.setParameter("Content-Disposition", "attachment; filename=" + filename);
            } catch (Exception e) {
                LOGGER.error("failed to export model to BPMN XML", e);
                ExplorerApp.get().getNotificationManager().showErrorNotification(Messages.PROCESS_TOXML_FAILED, e);
            }
            return ds;
        }
    };
    stream.setCacheTime(0);
    ExplorerApp.get().getMainWindow().open(stream);
}
Also used : FileResource(com.vaadin.terminal.FileResource) WorkflowDefinition(org.activiti.workflow.simple.definition.WorkflowDefinition) JsonNode(com.fasterxml.jackson.databind.JsonNode) UnsupportedEncodingException(java.io.UnsupportedEncodingException) BpmnModel(org.activiti.bpmn.model.BpmnModel) BpmnXMLConverter(org.activiti.bpmn.converter.BpmnXMLConverter) WorkflowDefinitionConversion(org.activiti.workflow.simple.converter.WorkflowDefinitionConversion) ByteArrayInputStream(java.io.ByteArrayInputStream) File(java.io.File) DownloadStream(com.vaadin.terminal.DownloadStream) BpmnJsonConverter(org.activiti.editor.language.json.converter.BpmnJsonConverter) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 32 with WorkflowDefinition

use of org.activiti.workflow.simple.definition.WorkflowDefinition in project Activiti by Activiti.

the class EditorProcessDefinitionDetailPanel method deploySimpleTableEditorModel.

protected void deploySimpleTableEditorModel(final byte[] model) {
    final DeployModelPopupWindow deployModelPopupWindow = new DeployModelPopupWindow(modelData);
    deployModelPopupWindow.getDeployButton().addListener(new ClickListener() {

        private static final long serialVersionUID = 1L;

        public void buttonClick(ClickEvent event) {
            // Convert to simple workflow definition
            WorkflowDefinition workflowDefinition = ExplorerApp.get().getSimpleWorkflowJsonConverter().readWorkflowDefinition(model);
            // Update model name
            modelData.setName(deployModelPopupWindow.getProcessName());
            workflowDefinition.setName(deployModelPopupWindow.getProcessName());
            WorkflowDefinitionConversion conversion = ExplorerApp.get().getWorkflowDefinitionConversionFactory().createWorkflowDefinitionConversion(workflowDefinition);
            conversion.convert();
            // Deploy to database
            byte[] bpmnBytes = null;
            try {
                bpmnBytes = conversion.getBpmn20Xml().getBytes("utf-8");
                String processName = modelData.getName() + ".bpmn20.xml";
                Deployment deployment = repositoryService.createDeployment().name(modelData.getName()).addString(processName, new String(bpmnBytes)).deploy();
                // Generate reports
                if (deployModelPopupWindow.isGenerateReports()) {
                    ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().deploymentId(deployment.getId()).singleResult();
                    ReportingUtil.generateTaskDurationReport(processDefinition.getId());
                }
                // Close popup and show new deployment
                deployModelPopupWindow.closePopupWindow();
                ExplorerApp.get().getViewManager().showDeploymentPage(deployment.getId());
            } catch (UnsupportedEncodingException e) {
                ExplorerApp.get().getNotificationManager().showErrorNotification(Messages.PROCESS_TOXML_FAILED, e);
                deployModelPopupWindow.closePopupWindow();
            }
        }
    });
    deployModelPopupWindow.showPopupWindow();
}
Also used : WorkflowDefinitionConversion(org.activiti.workflow.simple.converter.WorkflowDefinitionConversion) ClickEvent(com.vaadin.ui.Button.ClickEvent) WorkflowDefinition(org.activiti.workflow.simple.definition.WorkflowDefinition) Deployment(org.activiti.engine.repository.Deployment) UnsupportedEncodingException(java.io.UnsupportedEncodingException) ProcessDefinition(org.activiti.engine.repository.ProcessDefinition) ClickListener(com.vaadin.ui.Button.ClickListener) ImportModelClickListener(org.activiti.explorer.ui.process.listener.ImportModelClickListener) NewModelClickListener(org.activiti.explorer.ui.process.listener.NewModelClickListener) EditModelClickListener(org.activiti.explorer.ui.process.listener.EditModelClickListener)

Aggregations

WorkflowDefinition (org.activiti.workflow.simple.definition.WorkflowDefinition)32 Test (org.junit.Test)24 WorkflowDefinitionConversion (org.activiti.workflow.simple.converter.WorkflowDefinitionConversion)16 HumanStepDefinition (org.activiti.workflow.simple.definition.HumanStepDefinition)10 Task (org.activiti.engine.task.Task)7 FormDefinition (org.activiti.workflow.simple.definition.form.FormDefinition)7 ByteArrayOutputStream (java.io.ByteArrayOutputStream)6 TaskService (org.activiti.engine.TaskService)6 OutputStreamWriter (java.io.OutputStreamWriter)5 Process (org.activiti.bpmn.model.Process)5 Writer (java.io.Writer)4 BpmnModel (org.activiti.bpmn.model.BpmnModel)4 FlowElement (org.activiti.bpmn.model.FlowElement)4 M2Model (org.activiti.workflow.simple.alfresco.model.M2Model)4 ListStepDefinition (org.activiti.workflow.simple.definition.ListStepDefinition)4 RepositoryService (org.activiti.engine.RepositoryService)3 ProcessInstance (org.activiti.engine.runtime.ProcessInstance)3 M2Type (org.activiti.workflow.simple.alfresco.model.M2Type)3 ListConditionStepDefinition (org.activiti.workflow.simple.definition.ListConditionStepDefinition)3 StepDefinition (org.activiti.workflow.simple.definition.StepDefinition)3