Search in sources :

Example 16 with WorkflowDefinition

use of org.activiti.workflow.simple.definition.WorkflowDefinition 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)

Example 17 with WorkflowDefinition

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

the class WorkflowConversionTest method testMultipleConditionsInChoice.

@Test
public void testMultipleConditionsInChoice() throws Exception {
    TaskService taskService = activitiRule.getTaskService();
    WorkflowDefinition workflowDefinition = new WorkflowDefinition().name("testWorkflow").description("This is a test workflow").inChoice().inList().addCondition("test", "==", "'hello'").addCondition("test2", "==", "'world'").addHumanStep("first task", "kermit").endList().inList().addHumanStep("gonzo task", "gonzo").endList().endChoice();
    // Validate
    Map<String, Object> varMap = new HashMap<String, Object>();
    varMap.put("test", "hello");
    varMap.put("test2", "world");
    String definitionKey = convertAndDeploy(workflowDefinition);
    ProcessInstance instance = activitiRule.getRuntimeService().startProcessInstanceByKey(definitionKey, varMap);
    assertEquals(1, taskService.createTaskQuery().taskAssignee("kermit").count());
    assertEquals(0, taskService.createTaskQuery().taskAssignee("gonzo").count());
    Task task = taskService.createTaskQuery().singleResult();
    assertEquals("first task", task.getName());
    taskService.complete(task.getId());
    assertEquals(0, activitiRule.getRuntimeService().createProcessInstanceQuery().processInstanceId(instance.getId()).count());
    varMap = new HashMap<String, Object>();
    varMap.put("test", "world");
    varMap.put("test2", "world");
    instance = activitiRule.getRuntimeService().startProcessInstanceByKey(definitionKey, varMap);
    assertEquals(0, taskService.createTaskQuery().taskAssignee("kermit").count());
    assertEquals(1, taskService.createTaskQuery().taskAssignee("gonzo").count());
    task = taskService.createTaskQuery().singleResult();
    assertEquals("gonzo task", task.getName());
    taskService.complete(task.getId());
    assertEquals(0, activitiRule.getRuntimeService().createProcessInstanceQuery().processInstanceId(instance.getId()).count());
}
Also used : Task(org.activiti.engine.task.Task) HashMap(java.util.HashMap) TaskService(org.activiti.engine.TaskService) WorkflowDefinition(org.activiti.workflow.simple.definition.WorkflowDefinition) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) Test(org.junit.Test)

Example 18 with WorkflowDefinition

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

the class WorkflowConversionTest method testUserTasksWithOnlyAssignees.

@Test
public void testUserTasksWithOnlyAssignees() {
    String[] assignees = new String[] { "kermit", "gonzo", "mispiggy" };
    WorkflowDefinition workflowDefinition = new WorkflowDefinition().name("testWorkflow").description("This is a test workflow").addHumanStep("first task", assignees[0]).addHumanStep("second step", assignees[1]).addHumanStep("third step", assignees[2]);
    // Validate
    activitiRule.getRuntimeService().startProcessInstanceByKey(convertAndDeploy(workflowDefinition));
    for (String assignee : assignees) {
        Task task = activitiRule.getTaskService().createTaskQuery().singleResult();
        assertEquals(assignee, task.getAssignee());
        activitiRule.getTaskService().complete(task.getId());
    }
    assertEquals(0, activitiRule.getRuntimeService().createProcessInstanceQuery().count());
}
Also used : Task(org.activiti.engine.task.Task) WorkflowDefinition(org.activiti.workflow.simple.definition.WorkflowDefinition) Test(org.junit.Test)

Example 19 with WorkflowDefinition

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

the class WorkflowConversionTest method testFeedbackStepWithUserSelectionAtRuntimeAllFeedbackProvided.

@Test
public void testFeedbackStepWithUserSelectionAtRuntimeAllFeedbackProvided() {
    WorkflowDefinition workflowDefinition = new WorkflowDefinition().name("testWorkflow").description("This is a test workflow").addFeedbackStep("Test feedback", "kermit");
    activitiRule.getRuntimeService().startProcessInstanceByKey(convertAndDeploy(workflowDefinition));
    // First, a task should be assigned to kermit to select the people
    assertEquals(1, taskService.createTaskQuery().count());
    assertEquals(1, taskService.createTaskQuery().taskAssignee("kermit").count());
    Task task = taskService.createTaskQuery().singleResult();
    // Completing the task using the predefined process variable (normally done through the form)
    TaskService taskService = activitiRule.getTaskService();
    taskService.complete(task.getId(), CollectionUtil.singletonMap(FeedbackStepDefinitionConverter.VARIABLE_FEEDBACK_PROVIDERS, Arrays.asList("gonzo", "fozzie")));
    // Three tasks should be available now
    assertEquals(3, taskService.createTaskQuery().count());
    assertEquals(1, taskService.createTaskQuery().taskAssignee("kermit").count());
    assertEquals(1, taskService.createTaskQuery().taskAssignee("gonzo").count());
    assertEquals(1, taskService.createTaskQuery().taskAssignee("fozzie").count());
    // Completing the feedback tasks first should only leave the 'gather feedback' task for kermit open
    for (Task feedbackTask : taskService.createTaskQuery().list()) {
        if (!feedbackTask.getAssignee().equals("kermit")) {
            activitiRule.getTaskService().complete(feedbackTask.getId());
        }
    }
    assertEquals(1, taskService.createTaskQuery().count());
    assertEquals(1, taskService.createTaskQuery().taskAssignee("kermit").count());
    // Completing this last task should finish the process
    activitiRule.getTaskService().complete(activitiRule.getTaskService().createTaskQuery().singleResult().getId());
    assertEquals(0, activitiRule.getRuntimeService().createProcessInstanceQuery().count());
}
Also used : Task(org.activiti.engine.task.Task) TaskService(org.activiti.engine.TaskService) WorkflowDefinition(org.activiti.workflow.simple.definition.WorkflowDefinition) Test(org.junit.Test)

Example 20 with WorkflowDefinition

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

the class WorkflowConversionTest method testSimplestProcess.

@Test
public void testSimplestProcess() {
    WorkflowDefinition workflowDefinition = new WorkflowDefinition().name("testWorkflow").description("This is a test workflow");
    // Validate
    ProcessInstance processInstance = activitiRule.getRuntimeService().startProcessInstanceByKey(convertAndDeploy(workflowDefinition));
    assertTrue(processInstance.isEnded());
}
Also used : WorkflowDefinition(org.activiti.workflow.simple.definition.WorkflowDefinition) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) Test(org.junit.Test)

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