Search in sources :

Example 6 with WorkflowDefinitionConversion

use of org.activiti.workflow.simple.converter.WorkflowDefinitionConversion in project Activiti by Activiti.

the class WorkflowDefinitionConversionTest method testTaskListenerForIncomingProperties.

@Test
public void testTaskListenerForIncomingProperties() throws Exception {
    WorkflowDefinition definition = new WorkflowDefinition();
    definition.setId("process");
    HumanStepDefinition humanStep = new HumanStepDefinition();
    humanStep.setId("step1");
    FormDefinition form = new FormDefinition();
    form.setFormKey("myform");
    humanStep.setForm(form);
    definition.addStep(humanStep);
    WorkflowDefinitionConversion conversion = conversionFactory.createWorkflowDefinitionConversion(definition);
    conversion.convert();
    Process process = conversion.getProcess();
    assertNotNull(process);
    boolean listenerFound = false;
    for (FlowElement flowElement : process.getFlowElements()) {
        if (flowElement instanceof UserTask) {
            UserTask task = (UserTask) flowElement;
            assertNotNull(task.getTaskListeners());
            assertEquals(1L, task.getTaskListeners().size());
            assertEquals("create", task.getTaskListeners().get(0).getEvent());
            listenerFound = true;
        }
    }
    assertTrue(listenerFound);
}
Also used : WorkflowDefinitionConversion(org.activiti.workflow.simple.converter.WorkflowDefinitionConversion) HumanStepDefinition(org.activiti.workflow.simple.definition.HumanStepDefinition) FlowElement(org.activiti.bpmn.model.FlowElement) UserTask(org.activiti.bpmn.model.UserTask) WorkflowDefinition(org.activiti.workflow.simple.definition.WorkflowDefinition) Process(org.activiti.bpmn.model.Process) FormDefinition(org.activiti.workflow.simple.definition.form.FormDefinition) Test(org.junit.Test)

Example 7 with WorkflowDefinitionConversion

use of org.activiti.workflow.simple.converter.WorkflowDefinitionConversion in project Activiti by Activiti.

the class WorkflowDefinitionConversionTest method testGeneratedWorkflowDefinitionId.

/**
	 * Check if all required artifacts are created when converting an empty workflow-definition.
	 */
@Test
public void testGeneratedWorkflowDefinitionId() {
    WorkflowDefinition definition = new WorkflowDefinition();
    WorkflowDefinitionConversion conversion = conversionFactory.createWorkflowDefinitionConversion(definition);
    conversion.convert();
    BpmnModel bpmnModel = conversion.getBpmnModel();
    assertNotNull(bpmnModel);
    Process process = bpmnModel.getMainProcess();
    assertNotNull(process);
    String generatedProcessId = process.getId();
    assertNotNull(generatedProcessId);
}
Also used : WorkflowDefinitionConversion(org.activiti.workflow.simple.converter.WorkflowDefinitionConversion) WorkflowDefinition(org.activiti.workflow.simple.definition.WorkflowDefinition) Process(org.activiti.bpmn.model.Process) BpmnModel(org.activiti.bpmn.model.BpmnModel) Test(org.junit.Test)

Example 8 with WorkflowDefinitionConversion

use of org.activiti.workflow.simple.converter.WorkflowDefinitionConversion in project Activiti by Activiti.

the class SimpleWorkflowResource method createWorkflow.

@RequestMapping(value = "/simple-workflow", method = RequestMethod.POST, produces = "application/json")
public SimpleWorkflowSuccessResponse createWorkflow(@RequestBody String json) {
    // Convert json to simple workflow definition
    SimpleWorkflowJsonConverter jsonConverter = new SimpleWorkflowJsonConverter();
    WorkflowDefinition workflowDefinition = jsonConverter.readWorkflowDefinition(json.getBytes());
    WorkflowDefinitionConversionFactory conversionFactory = new WorkflowDefinitionConversionFactory();
    WorkflowDefinitionConversion conversion = conversionFactory.createWorkflowDefinitionConversion(workflowDefinition);
    conversion.convert();
    // Deploy process
    BpmnModel bpmnModel = conversion.getBpmnModel();
    Deployment deployment = repositoryService.createDeployment().addBpmnModel(bpmnModel.getProcesses().get(0).getName() + ".bpmn20.xml", bpmnModel).deploy();
    // Fetch process definition id
    ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().deploymentId(deployment.getId()).singleResult();
    return new SimpleWorkflowSuccessResponse(processDefinition.getId());
}
Also used : WorkflowDefinitionConversion(org.activiti.workflow.simple.converter.WorkflowDefinitionConversion) WorkflowDefinitionConversionFactory(org.activiti.workflow.simple.converter.WorkflowDefinitionConversionFactory) WorkflowDefinition(org.activiti.workflow.simple.definition.WorkflowDefinition) Deployment(org.activiti.engine.repository.Deployment) SimpleWorkflowJsonConverter(org.activiti.workflow.simple.converter.json.SimpleWorkflowJsonConverter) ProcessDefinition(org.activiti.engine.repository.ProcessDefinition) BpmnModel(org.activiti.bpmn.model.BpmnModel) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 9 with WorkflowDefinitionConversion

use of org.activiti.workflow.simple.converter.WorkflowDefinitionConversion in project Activiti by Activiti.

the class SimpleTableEditor method save.

protected void save() {
    WorkflowDefinition workflowDefinition = createWorkflow();
    final ProcessEngineImpl defaultProcessEngine = (ProcessEngineImpl) ProcessEngines.getDefaultProcessEngine();
    RepositoryService repositoryService = defaultProcessEngine.getRepositoryService();
    ProcessEngineConfiguration processEngineConfiguration = defaultProcessEngine.getProcessEngineConfiguration();
    ProcessDiagramGenerator diagramGenerator = processEngineConfiguration.getProcessDiagramGenerator();
    Model model = null;
    if (modelId == null) {
        // new process
        model = repositoryService.newModel();
    } else {
        // update existing process
        model = repositoryService.getModel(modelId);
    }
    model.setName(workflowDefinition.getName());
    model.setCategory(SimpleTableEditorConstants.TABLE_EDITOR_CATEGORY);
    repositoryService.saveModel(model);
    // Store model entity
    WorkflowDefinitionConversion conversion = ExplorerApp.get().getWorkflowDefinitionConversionFactory().createWorkflowDefinitionConversion(workflowDefinition);
    conversion.convert();
    try {
        // Write JSON to byte-array and set as editor-source
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        ExplorerApp.get().getSimpleWorkflowJsonConverter().writeWorkflowDefinition(workflowDefinition, new OutputStreamWriter(baos));
        repositoryService.addModelEditorSource(model.getId(), baos.toByteArray());
        // Store process image
        // TODO: we should really allow the service to take an inputstream as input. Now we load it into memory ...
        repositoryService.addModelEditorSourceExtra(model.getId(), IOUtils.toByteArray(diagramGenerator.generateDiagram(conversion.getBpmnModel(), "png", processEngineConfiguration.getActivityFontName(), processEngineConfiguration.getLabelFontName(), processEngineConfiguration.getAnnotationFontName(), processEngineConfiguration.getClassLoader())));
    } catch (IOException e) {
        logger.warn("Could not generate process image. Image is not stored and will not be shown.", e);
    }
    ExplorerApp.get().getViewManager().showEditorProcessDefinitionPage(model.getId());
}
Also used : WorkflowDefinitionConversion(org.activiti.workflow.simple.converter.WorkflowDefinitionConversion) ProcessEngineConfiguration(org.activiti.engine.ProcessEngineConfiguration) ProcessDiagramGenerator(org.activiti.image.ProcessDiagramGenerator) Model(org.activiti.engine.repository.Model) WorkflowDefinition(org.activiti.workflow.simple.definition.WorkflowDefinition) OutputStreamWriter(java.io.OutputStreamWriter) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) ProcessEngineImpl(org.activiti.engine.impl.ProcessEngineImpl) RepositoryService(org.activiti.engine.RepositoryService)

Example 10 with WorkflowDefinitionConversion

use of org.activiti.workflow.simple.converter.WorkflowDefinitionConversion in project Activiti by Activiti.

the class EditModelClickListener method showSelectEditorPopupWindow.

protected void showSelectEditorPopupWindow() {
    final PopupWindow selectEditorPopupWindow = new PopupWindow();
    selectEditorPopupWindow.setModal(true);
    selectEditorPopupWindow.setResizable(false);
    selectEditorPopupWindow.setWidth("350px");
    selectEditorPopupWindow.setHeight("250px");
    selectEditorPopupWindow.addStyleName(Reindeer.PANEL_LIGHT);
    selectEditorPopupWindow.center();
    final SelectEditorComponent selectEditorComponent = new SelectEditorComponent(false);
    selectEditorComponent.getModelerDescriptionLabel().setValue(ExplorerApp.get().getI18nManager().getMessage(Messages.PROCESS_EDITOR_CONVERSION_WARNING_MODELER));
    selectEditorComponent.getModelerDescriptionLabel().addStyleName(ExplorerLayout.STYLE_LABEL_RED);
    selectEditorComponent.preferTableDrivenEditor();
    selectEditorPopupWindow.getContent().addComponent(selectEditorComponent);
    selectEditorComponent.setEditorSelectedListener(new EditorSelectedListener() {

        public void editorSelectionChanged() {
            try {
                WorkflowDefinition workflowDefinition = loadWorkflowDefinition();
                // When using the modeler, the format must first be converted to the modeler json format
                if (selectEditorComponent.isModelerPreferred()) {
                    WorkflowDefinitionConversion conversion = ExplorerApp.get().getWorkflowDefinitionConversionFactory().createWorkflowDefinitionConversion(workflowDefinition);
                    conversion.convert();
                    RepositoryService repositoryService = ProcessEngines.getDefaultProcessEngine().getRepositoryService();
                    model.setCategory(null);
                    ObjectMapper objectMapper = new ObjectMapper();
                    ObjectNode metaInfoJson = objectMapper.createObjectNode();
                    metaInfoJson.put("name", model.getName());
                    model.setMetaInfo(metaInfoJson.toString());
                    repositoryService.saveModel(model);
                    BpmnJsonConverter bpmnJsonConverter = new BpmnJsonConverter();
                    ObjectNode json = bpmnJsonConverter.convertToJson(conversion.getBpmnModel());
                    repositoryService.addModelEditorSource(model.getId(), json.toString().getBytes("utf-8"));
                    // Show modeler
                    showModeler();
                } else {
                    // Load and show table editor
                    ExplorerApp.get().getViewManager().showSimpleTableProcessEditor(model.getId(), workflowDefinition);
                }
            } catch (Exception e) {
                LOGGER.error("Error showing editor", e);
                ExplorerApp.get().getNotificationManager().showErrorNotification(Messages.PROCESS_EDITOR_LOADING_ERROR, e);
            } finally {
                ExplorerApp.get().getMainWindow().removeWindow(selectEditorPopupWindow);
            }
        }
    });
    ExplorerApp.get().getViewManager().showPopupWindow(selectEditorPopupWindow);
}
Also used : WorkflowDefinitionConversion(org.activiti.workflow.simple.converter.WorkflowDefinitionConversion) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) PopupWindow(org.activiti.explorer.ui.custom.PopupWindow) SelectEditorComponent(org.activiti.editor.ui.SelectEditorComponent) EditorSelectedListener(org.activiti.editor.ui.SelectEditorComponent.EditorSelectedListener) WorkflowDefinition(org.activiti.workflow.simple.definition.WorkflowDefinition) BpmnJsonConverter(org.activiti.editor.language.json.converter.BpmnJsonConverter) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) RepositoryService(org.activiti.engine.RepositoryService)

Aggregations

WorkflowDefinitionConversion (org.activiti.workflow.simple.converter.WorkflowDefinitionConversion)18 WorkflowDefinition (org.activiti.workflow.simple.definition.WorkflowDefinition)16 Test (org.junit.Test)10 HumanStepDefinition (org.activiti.workflow.simple.definition.HumanStepDefinition)6 FormDefinition (org.activiti.workflow.simple.definition.form.FormDefinition)6 BpmnModel (org.activiti.bpmn.model.BpmnModel)4 FlowElement (org.activiti.bpmn.model.FlowElement)4 Process (org.activiti.bpmn.model.Process)4 M2Model (org.activiti.workflow.simple.alfresco.model.M2Model)4 RepositoryService (org.activiti.engine.RepositoryService)3 ProcessDefinition (org.activiti.engine.repository.ProcessDefinition)3 M2Type (org.activiti.workflow.simple.alfresco.model.M2Type)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 File (java.io.File)2 IOException (java.io.IOException)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 UserTask (org.activiti.bpmn.model.UserTask)2 BpmnJsonConverter (org.activiti.editor.language.json.converter.BpmnJsonConverter)2 ProcessEngineConfiguration (org.activiti.engine.ProcessEngineConfiguration)2