Search in sources :

Example 11 with WorkflowDefinition

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

the class WorkflowConversionTest method testGroupsForHumanStep.

@Test
public void testGroupsForHumanStep() {
    WorkflowDefinition workflowDefinition = new WorkflowDefinition().name("testWorkflow").description("This is a test workflow").addHumanStepForGroup("step1", "management", "sales").addHumanStepForGroup("step1", "sales");
    activitiRule.getRuntimeService().startProcessInstanceByKey(convertAndDeploy(workflowDefinition));
    // Complete first task
    TaskService taskService = activitiRule.getTaskService();
    assertEquals(1, taskService.createTaskQuery().taskCandidateGroup("management").count());
    assertEquals(1, taskService.createTaskQuery().taskCandidateGroup("sales").count());
    assertEquals(1, taskService.createTaskQuery().taskCandidateGroupIn(Arrays.asList("management")).count());
    assertEquals(1, taskService.createTaskQuery().taskCandidateGroupIn(Arrays.asList("management", "sales")).count());
    taskService.complete(taskService.createTaskQuery().singleResult().getId());
    // Second task is only done by sales
    assertEquals(0, taskService.createTaskQuery().taskCandidateGroup("management").count());
    assertEquals(1, taskService.createTaskQuery().taskCandidateGroup("sales").count());
    assertEquals(0, taskService.createTaskQuery().taskCandidateGroupIn(Arrays.asList("management")).count());
    assertEquals(1, taskService.createTaskQuery().taskCandidateGroupIn(Arrays.asList("sales")).count());
    assertEquals(1, taskService.createTaskQuery().taskCandidateGroupIn(Arrays.asList("management", "sales")).count());
}
Also used : TaskService(org.activiti.engine.TaskService) WorkflowDefinition(org.activiti.workflow.simple.definition.WorkflowDefinition) Test(org.junit.Test)

Example 12 with WorkflowDefinition

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

the class WorkflowConversionTest method testFeedbackStepWithFixedUsersFeedbackHaltedByInitiator.

@Test
public void testFeedbackStepWithFixedUsersFeedbackHaltedByInitiator() {
    WorkflowDefinition workflowDefinition = new WorkflowDefinition().name("testWorkflow").description("This is a test workflow").addFeedbackStep("Test feedback", "kermit", Arrays.asList("gonzo", "mispiggy", "fozzie"));
    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();
    taskService.complete(task.getId());
    // Four tasks should be available now
    assertEquals(4, taskService.createTaskQuery().count());
    assertEquals(1, taskService.createTaskQuery().taskAssignee("kermit").count());
    assertEquals(1, taskService.createTaskQuery().taskAssignee("gonzo").count());
    assertEquals(1, taskService.createTaskQuery().taskAssignee("mispiggy").count());
    assertEquals(1, taskService.createTaskQuery().taskAssignee("fozzie").count());
    // Completing only one feedback task
    for (Task feedbackTask : taskService.createTaskQuery().list()) {
        if (!feedbackTask.getAssignee().equals("kermit")) {
            activitiRule.getTaskService().complete(feedbackTask.getId());
            break;
        }
    }
    assertEquals(3, taskService.createTaskQuery().count());
    assertEquals(1, taskService.createTaskQuery().taskAssignee("kermit").count());
    // Completing the 'gather feedback' task by kermit should cancel the remaining feedback tasks
    activitiRule.getTaskService().complete(activitiRule.getTaskService().createTaskQuery().taskAssignee("kermit").singleResult().getId());
    assertEquals(0, taskService.createTaskQuery().count());
    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 13 with WorkflowDefinition

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

the class JsonConverterTest method testHumanStepConversion.

@Test
public void testHumanStepConversion() {
    WorkflowDefinition workflowDefinition = new WorkflowDefinition().name("testWorkflow").addHumanStep("step1", "fred").addHumanStepForGroup("step2", Collections.singletonList("group")).addHumanStepForWorkflowInitiator("step3");
    // Add form to last step
    HumanStepDefinition stepWithForm = new HumanStepDefinition();
    stepWithForm.setName("step4");
    stepWithForm.setDescription("Step description");
    workflowDefinition.getSteps().add(stepWithForm);
    FormDefinition formDefinition = new FormDefinition();
    stepWithForm.setForm(formDefinition);
    formDefinition.setFormKey("123");
    TextPropertyDefinition textProp = new TextPropertyDefinition();
    textProp.setMandatory(true);
    textProp.setName("textProp");
    textProp.setWritable(false);
    formDefinition.addFormProperty(textProp);
    textProp.getParameters().put("custom-parameter", "This is a test");
    NumberPropertyDefinition numberProp = new NumberPropertyDefinition();
    numberProp.setMandatory(true);
    numberProp.setName("numberProp");
    numberProp.setWritable(false);
    formDefinition.addFormProperty(numberProp);
    ReferencePropertyDefinition reference = new ReferencePropertyDefinition();
    reference.setMandatory(true);
    reference.setName("referenceProp");
    reference.setWritable(false);
    reference.setType("referencedType");
    formDefinition.addFormProperty(reference);
    ListPropertyDefinition itemType = new ListPropertyDefinition();
    itemType.setMandatory(true);
    itemType.setName("referenceProp");
    itemType.setWritable(false);
    itemType.addEntry(new ListPropertyEntry("1", "Item 1"));
    itemType.addEntry(new ListPropertyEntry("2", "Item 2"));
    formDefinition.addFormProperty(itemType);
    // Write result to byte-array
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    Writer writer = new OutputStreamWriter(baos);
    converter.writeWorkflowDefinition(workflowDefinition, writer);
    // Parse definition based on written JSON
    WorkflowDefinition parsedDefinition = converter.readWorkflowDefinition(baos.toByteArray());
    assertEquals(workflowDefinition.getSteps().size(), parsedDefinition.getSteps().size());
    int index = 0;
    for (StepDefinition stepDefinition : parsedDefinition.getSteps()) {
        assertTrue(stepDefinition instanceof HumanStepDefinition);
        HumanStepDefinition humanStep = (HumanStepDefinition) stepDefinition;
        HumanStepDefinition originalStep = (HumanStepDefinition) workflowDefinition.getSteps().get(index);
        // Check general human-step fields
        assertEquals(originalStep.getAssignee(), humanStep.getAssignee());
        assertEquals(originalStep.getAssignmentType(), humanStep.getAssignmentType());
        assertEquals(originalStep.getCandidateGroups(), humanStep.getCandidateGroups());
        assertEquals(originalStep.getCandidateUsers(), humanStep.getCandidateUsers());
        assertEquals(originalStep.getName(), humanStep.getName());
        assertEquals(originalStep.getDescription(), humanStep.getDescription());
        if (originalStep.getForm() != null) {
            // Encountered step with form attached to it, should be last step
            assertEquals(3, index);
            assertEquals("123", humanStep.getForm().getFormKey());
            assertEquals(originalStep.getForm().getFormPropertyDefinitions().size(), humanStep.getForm().getFormPropertyDefinitions().size());
            // Check form-fields, generic fields
            for (int i = 0; i < originalStep.getForm().getFormPropertyDefinitions().size(); i++) {
                FormPropertyDefinition origDef = originalStep.getForm().getFormPropertyDefinitions().get(i);
                FormPropertyDefinition parsedDef = humanStep.getForm().getFormPropertyDefinitions().get(i);
                assertEquals(origDef.getName(), parsedDef.getName());
                assertEquals(origDef.isMandatory(), parsedDef.isMandatory());
                assertEquals(origDef.isWritable(), parsedDef.isWritable());
                assertEquals(origDef.getClass(), parsedDef.getClass());
                if (parsedDef instanceof TextPropertyDefinition) {
                    assertTrue(parsedDef.getParameters() != null);
                    assertEquals(1L, parsedDef.getParameters().size());
                    assertEquals("This is a test", parsedDef.getParameters().get("custom-parameter"));
                }
                if (parsedDef instanceof ListPropertyDefinition) {
                    ListPropertyDefinition parsed = (ListPropertyDefinition) parsedDef;
                    assertEquals(2L, parsed.getEntries().size());
                }
            }
        }
        index++;
    }
}
Also used : ListPropertyEntry(org.activiti.workflow.simple.definition.form.ListPropertyEntry) ReferencePropertyDefinition(org.activiti.workflow.simple.definition.form.ReferencePropertyDefinition) TextPropertyDefinition(org.activiti.workflow.simple.definition.form.TextPropertyDefinition) WorkflowDefinition(org.activiti.workflow.simple.definition.WorkflowDefinition) FormPropertyDefinition(org.activiti.workflow.simple.definition.form.FormPropertyDefinition) ByteArrayOutputStream(java.io.ByteArrayOutputStream) NumberPropertyDefinition(org.activiti.workflow.simple.definition.form.NumberPropertyDefinition) HumanStepDefinition(org.activiti.workflow.simple.definition.HumanStepDefinition) ListStepDefinition(org.activiti.workflow.simple.definition.ListStepDefinition) ListConditionStepDefinition(org.activiti.workflow.simple.definition.ListConditionStepDefinition) StepDefinition(org.activiti.workflow.simple.definition.StepDefinition) HumanStepDefinition(org.activiti.workflow.simple.definition.HumanStepDefinition) ListPropertyDefinition(org.activiti.workflow.simple.definition.form.ListPropertyDefinition) OutputStreamWriter(java.io.OutputStreamWriter) FormDefinition(org.activiti.workflow.simple.definition.form.FormDefinition) Writer(java.io.Writer) OutputStreamWriter(java.io.OutputStreamWriter) Test(org.junit.Test)

Example 14 with WorkflowDefinition

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

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

the class SimpleTableEditor method createWorkflow.

protected WorkflowDefinition createWorkflow() {
    WorkflowDefinition workflow = new WorkflowDefinition();
    workflow.setName((String) nameField.getValue());
    String description = (String) descriptionField.getValue();
    if (description != null && description.length() > 0) {
        workflow.setDescription(description);
    }
    List<HumanStepDefinition> steps = taskTable.getSteps();
    for (int i = 0; i < steps.size(); i++) {
        HumanStepDefinition currentStep = steps.get(i);
        // Check if we have a parallel block
        int nextIndex = i + 1;
        ParallelStepsDefinition parallelStepsDefinition = null;
        while (nextIndex < steps.size() && steps.get(nextIndex).isStartsWithPrevious()) {
            if (parallelStepsDefinition == null) {
                parallelStepsDefinition = new ParallelStepsDefinition();
                ListStepDefinition<ParallelStepsDefinition> listStepDef = new ListStepDefinition<ParallelStepsDefinition>();
                listStepDef.addStep(currentStep);
                parallelStepsDefinition.addStepList(listStepDef);
            }
            ListStepDefinition<ParallelStepsDefinition> listStepDef = new ListStepDefinition<ParallelStepsDefinition>();
            listStepDef.addStep(steps.get(nextIndex));
            parallelStepsDefinition.addStepList(listStepDef);
            nextIndex++;
        }
        if (parallelStepsDefinition != null) {
            workflow.addStep(parallelStepsDefinition);
            i = nextIndex - 1;
        } else {
            workflow.addStep(currentStep);
        }
    }
    return workflow;
}
Also used : HumanStepDefinition(org.activiti.workflow.simple.definition.HumanStepDefinition) WorkflowDefinition(org.activiti.workflow.simple.definition.WorkflowDefinition) ParallelStepsDefinition(org.activiti.workflow.simple.definition.ParallelStepsDefinition) ListStepDefinition(org.activiti.workflow.simple.definition.ListStepDefinition)

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