Search in sources :

Example 1 with HumanStepDefinition

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

the class WorkflowDefinitionConversionTest method testCustomReference.

/**
	 * Test if a custom reference (eg. type=cm:person) is turned into an association on the
	 * model.
	 */
@Test
public void testCustomReference() throws Exception {
    // TODO: finish test once all types are present
    WorkflowDefinition definition = new WorkflowDefinition();
    definition.setId("process");
    HumanStepDefinition humanStep = new HumanStepDefinition();
    humanStep.setId("step1");
    FormDefinition form = new FormDefinition();
    humanStep.setForm(form);
    FormPropertyGroup group = new FormPropertyGroup();
    group.setId("group");
    group.setTitle("My group");
    humanStep.getForm().addFormPropertyGroup(group);
    // Add simple text
    ReferencePropertyDefinition textProperty = new ReferencePropertyDefinition();
    textProperty.setName("person");
    textProperty.setMandatory(true);
    textProperty.setType("cm:person");
    group.addFormProperty(textProperty);
    definition.addStep(humanStep);
    WorkflowDefinitionConversion conversion = conversionFactory.createWorkflowDefinitionConversion(definition);
    conversion.convert();
    // Check content-model
    M2Model model = AlfrescoConversionUtil.getContentModel(conversion);
    assertNotNull(model);
    M2Type type = model.getTypes().get(0);
    assertNotNull(type);
    // Simple text
    M2ClassAssociation association = getAssociationFromType("person", type);
    assertEquals("cm:person", association.getTarget().getClassName());
    assertTrue(association.getTarget().isMandatory());
}
Also used : WorkflowDefinitionConversion(org.activiti.workflow.simple.converter.WorkflowDefinitionConversion) HumanStepDefinition(org.activiti.workflow.simple.definition.HumanStepDefinition) M2Type(org.activiti.workflow.simple.alfresco.model.M2Type) ReferencePropertyDefinition(org.activiti.workflow.simple.definition.form.ReferencePropertyDefinition) M2Model(org.activiti.workflow.simple.alfresco.model.M2Model) WorkflowDefinition(org.activiti.workflow.simple.definition.WorkflowDefinition) FormPropertyGroup(org.activiti.workflow.simple.definition.form.FormPropertyGroup) FormDefinition(org.activiti.workflow.simple.definition.form.FormDefinition) M2ClassAssociation(org.activiti.workflow.simple.alfresco.model.M2ClassAssociation) Test(org.junit.Test)

Example 2 with HumanStepDefinition

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

the class WorkflowDefinitionConversionTest method testTaskListenerForOutgoingProperties.

@Test
public void testTaskListenerForOutgoingProperties() throws Exception {
    WorkflowDefinition definition = new WorkflowDefinition();
    definition.setId("process");
    HumanStepDefinition humanStep = new HumanStepDefinition();
    humanStep.setId("step1");
    FormDefinition form = new FormDefinition();
    humanStep.setForm(form);
    TextPropertyDefinition text = new TextPropertyDefinition();
    text.setName("my text");
    text.getParameters().put(AlfrescoConversionConstants.PARAMETER_ADD_PROPERTY_TO_OUTPUT, true);
    FormPropertyGroup group = new FormPropertyGroup();
    group.setId("group");
    form.getFormGroups().add(group);
    group.getFormPropertyDefinitions().add(text);
    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(2L, task.getTaskListeners().size());
            assertEquals("create", task.getTaskListeners().get(0).getEvent());
            assertEquals("complete", task.getTaskListeners().get(1).getEvent());
            listenerFound = true;
        }
    }
    assertTrue(listenerFound);
}
Also used : WorkflowDefinitionConversion(org.activiti.workflow.simple.converter.WorkflowDefinitionConversion) HumanStepDefinition(org.activiti.workflow.simple.definition.HumanStepDefinition) TextPropertyDefinition(org.activiti.workflow.simple.definition.form.TextPropertyDefinition) FlowElement(org.activiti.bpmn.model.FlowElement) UserTask(org.activiti.bpmn.model.UserTask) WorkflowDefinition(org.activiti.workflow.simple.definition.WorkflowDefinition) FormPropertyGroup(org.activiti.workflow.simple.definition.form.FormPropertyGroup) Process(org.activiti.bpmn.model.Process) FormDefinition(org.activiti.workflow.simple.definition.form.FormDefinition) Test(org.junit.Test)

Example 3 with HumanStepDefinition

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

the class WorkflowDefinitionConversionTest method testExportArtifacts.

/**
	 * Check artifact export.
	 */
@Test
public void testExportArtifacts() throws Exception {
    WorkflowDefinition definition = new WorkflowDefinition();
    HumanStepDefinition humanStep = new HumanStepDefinition();
    humanStep.setAssignee("fred");
    humanStep.setId("step 1");
    FormDefinition form = new FormDefinition();
    form.setFormKey("wf:activitiAdhoc");
    humanStep.setForm(form);
    definition.addStep(humanStep);
    WorkflowDefinitionConversion conversion = conversionFactory.createWorkflowDefinitionConversion(definition);
    conversion.convert();
    ByteArrayOutputStream stream = new ByteArrayOutputStream();
    conversionFactory.getArtifactExporter().writeBpmnModel(stream, conversion);
    byte[] byteArray = stream.toByteArray();
    assertTrue(byteArray.length > 0);
    stream = new ByteArrayOutputStream();
    conversionFactory.getArtifactExporter().writeContentModel(stream, conversion);
    byteArray = stream.toByteArray();
    assertTrue(byteArray.length > 0);
    stream = new ByteArrayOutputStream();
    conversionFactory.getArtifactExporter().writeShareConfig(stream, conversion, true);
    byteArray = stream.toByteArray();
    assertTrue(byteArray.length > 0);
    stream = new ByteArrayOutputStream();
    conversionFactory.getArtifactExporter().writeShareConfig(stream, conversion, false);
    byteArray = stream.toByteArray();
    assertTrue(byteArray.length > 0);
}
Also used : WorkflowDefinitionConversion(org.activiti.workflow.simple.converter.WorkflowDefinitionConversion) HumanStepDefinition(org.activiti.workflow.simple.definition.HumanStepDefinition) WorkflowDefinition(org.activiti.workflow.simple.definition.WorkflowDefinition) ByteArrayOutputStream(java.io.ByteArrayOutputStream) FormDefinition(org.activiti.workflow.simple.definition.form.FormDefinition) Test(org.junit.Test)

Example 4 with HumanStepDefinition

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

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

Aggregations

HumanStepDefinition (org.activiti.workflow.simple.definition.HumanStepDefinition)12 FormDefinition (org.activiti.workflow.simple.definition.form.FormDefinition)9 WorkflowDefinition (org.activiti.workflow.simple.definition.WorkflowDefinition)8 Test (org.junit.Test)7 WorkflowDefinitionConversion (org.activiti.workflow.simple.converter.WorkflowDefinitionConversion)6 M2Model (org.activiti.workflow.simple.alfresco.model.M2Model)5 M2Type (org.activiti.workflow.simple.alfresco.model.M2Type)5 UserTask (org.activiti.bpmn.model.UserTask)4 FlowElement (org.activiti.bpmn.model.FlowElement)3 ListStepDefinition (org.activiti.workflow.simple.definition.ListStepDefinition)3 StepDefinition (org.activiti.workflow.simple.definition.StepDefinition)3 FormPropertyGroup (org.activiti.workflow.simple.definition.form.FormPropertyGroup)3 TextPropertyDefinition (org.activiti.workflow.simple.definition.form.TextPropertyDefinition)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 Process (org.activiti.bpmn.model.Process)2 PropertyReference (org.activiti.workflow.simple.alfresco.conversion.script.PropertyReference)2 M2ClassAssociation (org.activiti.workflow.simple.alfresco.model.M2ClassAssociation)2 ListConditionStepDefinition (org.activiti.workflow.simple.definition.ListConditionStepDefinition)2 ListPropertyEntry (org.activiti.workflow.simple.definition.form.ListPropertyEntry)2 ReferencePropertyDefinition (org.activiti.workflow.simple.definition.form.ReferencePropertyDefinition)2