Search in sources :

Example 6 with FormDefinition

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

the class BaseStepDefinitionConverterTest method testCovertFormPropertiesWithListValues.

@Test
public void testCovertFormPropertiesWithListValues() {
    TestStepDefinitionConverter converter = new TestStepDefinitionConverter();
    // Create a form with two properties, one of which is a ListProperty
    FormDefinition formDefinition = new FormDefinition();
    ListPropertyDefinition approveEnum = new ListPropertyDefinition();
    approveEnum.setName("Approval");
    approveEnum.setType("enum");
    approveEnum.addEntry(new ListPropertyEntry("true", "Approve"));
    approveEnum.addEntry(new ListPropertyEntry("false", "Reject"));
    formDefinition.addFormProperty(approveEnum);
    TextPropertyDefinition reason = new TextPropertyDefinition();
    reason.setName("Reason");
    reason.setType("string");
    formDefinition.addFormProperty(reason);
    BooleanPropertyDefinition validate = new BooleanPropertyDefinition();
    validate.setName("Validate");
    validate.setType("boolean");
    formDefinition.addFormProperty(validate);
    List<FormProperty> properties = converter.convertProperties(formDefinition);
    assertTrue(properties.size() == 3);
    FormProperty firstProperty = properties.get(0);
    assertNotNull(firstProperty);
    assertEquals("Approval", firstProperty.getName());
    assertEquals("enum", firstProperty.getType());
    // Assert the values are set
    List<FormValue> values = firstProperty.getFormValues();
    assertTrue(values.size() == 2);
    FormValue firstValue = values.get(0);
    assertEquals("Approve", firstValue.getName());
    assertEquals("true", firstValue.getId());
    FormValue secondValue = values.get(1);
    assertEquals("Reject", secondValue.getName());
    assertEquals("false", secondValue.getId());
    // Now confirm the second property, a non list property, is well formed as well.
    FormProperty secondProperty = properties.get(1);
    assertNotNull(secondProperty);
    assertTrue(secondProperty.getFormValues().isEmpty());
    assertEquals("Reason", secondProperty.getName());
    assertEquals("string", secondProperty.getType());
    FormProperty thirdProperty = properties.get(2);
    assertNotNull(thirdProperty);
    assertTrue(thirdProperty.getFormValues().isEmpty());
    assertEquals("Validate", thirdProperty.getName());
    assertEquals("boolean", thirdProperty.getType());
}
Also used : ListPropertyEntry(org.activiti.workflow.simple.definition.form.ListPropertyEntry) BooleanPropertyDefinition(org.activiti.workflow.simple.definition.form.BooleanPropertyDefinition) FormValue(org.activiti.bpmn.model.FormValue) TextPropertyDefinition(org.activiti.workflow.simple.definition.form.TextPropertyDefinition) FormProperty(org.activiti.bpmn.model.FormProperty) ListPropertyDefinition(org.activiti.workflow.simple.definition.form.ListPropertyDefinition) FormDefinition(org.activiti.workflow.simple.definition.form.FormDefinition) Test(org.junit.Test)

Example 7 with FormDefinition

use of org.activiti.workflow.simple.definition.form.FormDefinition 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 8 with FormDefinition

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

the class TaskTable method getSteps.

public List<HumanStepDefinition> getSteps() {
    List<HumanStepDefinition> steps = new ArrayList<HumanStepDefinition>();
    for (Object itemId : getItemIds()) {
        Item item = getItem(itemId);
        HumanStepDefinition humanStepDefinition = new HumanStepDefinition();
        String name = (String) item.getItemProperty(ID_NAME).getValue();
        if (name != null && name.length() > 0) {
            humanStepDefinition.setName(name);
        }
        String assignee = (String) ((ComboBox) item.getItemProperty(ID_ASSIGNEE).getValue()).getValue();
        if (assignee != null && assignee.length() > 0) {
            humanStepDefinition.setAssignee(assignee);
        }
        String groups = (String) ((ComboBox) item.getItemProperty("groups").getValue()).getValue();
        List<String> candidateGroups = new ArrayList<String>();
        if (groups != null && groups.length() > 0) {
            for (String group : groups.split(",")) {
                candidateGroups.add(group.trim());
            }
        }
        humanStepDefinition.setCandidateGroups(candidateGroups);
        String description = (String) ((TextField) item.getItemProperty(ID_DESCRIPTION).getValue()).getValue();
        if (description != null && description.length() > 0) {
            humanStepDefinition.setDescription(description);
        }
        humanStepDefinition.setStartsWithPrevious((boolean) ((CheckBox) item.getItemProperty(ID_START_WITH_PREVIOUS).getValue()).booleanValue());
        FormDefinition formDefinition = taskFormModel.getForm(itemId);
        humanStepDefinition.setForm(formDefinition);
        steps.add(humanStepDefinition);
    }
    return steps;
}
Also used : Item(com.vaadin.data.Item) HumanStepDefinition(org.activiti.workflow.simple.definition.HumanStepDefinition) CheckBox(com.vaadin.ui.CheckBox) ArrayList(java.util.ArrayList) FormDefinition(org.activiti.workflow.simple.definition.form.FormDefinition)

Example 9 with FormDefinition

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

the class TaskTable method generateActionButtons.

protected HorizontalLayout generateActionButtons(Object taskItemId) {
    HorizontalLayout actionButtons = new HorizontalLayout();
    FormDefinition form = taskFormModel.getForm(taskItemId);
    Button formButton = new Button(form == null ? i18nManager.getMessage(Messages.PROCESS_EDITOR_TASK_FORM_CREATE) : i18nManager.getMessage(Messages.PROCESS_EDITOR_TASK_FORM_EDIT));
    formButton.addListener(new ShowFormClickListener(taskFormModel, taskItemId));
    formButton.setData(taskItemId);
    actionButtons.addComponent(formButton);
    Button deleteTaskButton = new Button("-");
    deleteTaskButton.setData(taskItemId);
    deleteTaskButton.addListener(new DeleteTaskClickListener(this));
    actionButtons.addComponent(deleteTaskButton);
    Button addTaskButton = new Button("+");
    addTaskButton.setData(taskItemId);
    addTaskButton.addListener(new AddTaskClickListener(this));
    actionButtons.addComponent(addTaskButton);
    return actionButtons;
}
Also used : ShowFormClickListener(org.activiti.explorer.ui.process.simple.editor.listener.ShowFormClickListener) Button(com.vaadin.ui.Button) DeleteTaskClickListener(org.activiti.explorer.ui.process.simple.editor.listener.DeleteTaskClickListener) FormDefinition(org.activiti.workflow.simple.definition.form.FormDefinition) HorizontalLayout(com.vaadin.ui.HorizontalLayout) AddTaskClickListener(org.activiti.explorer.ui.process.simple.editor.listener.AddTaskClickListener)

Example 10 with FormDefinition

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

the class FormPopupWindow method initUi.

protected void initUi() {
    VerticalLayout layout = new VerticalLayout();
    layout.setSpacing(true);
    addComponent(layout);
    // Description
    layout.addComponent(new Label(DESCRIPTION));
    // Property table
    propertyTable = new PropertyTable();
    layout.addComponent(propertyTable);
    fillFormFields();
    // Buttons
    HorizontalLayout buttons = new HorizontalLayout();
    buttons.setSpacing(true);
    // Save button
    Button saveButton = new Button(ExplorerApp.get().getI18nManager().getMessage(Messages.BUTTON_SAVE));
    buttons.addComponent(saveButton);
    saveButton.addListener(new Button.ClickListener() {

        private static final long serialVersionUID = -2906886872414089331L;

        public void buttonClick(ClickEvent event) {
            FormDefinition form = createForm();
            formModel.addForm(taskItemId, form);
            close();
        }
    });
    // Delete button
    Button deleteButton = new Button(ExplorerApp.get().getI18nManager().getMessage(Messages.BUTTON_DELETE));
    buttons.addComponent(deleteButton);
    deleteButton.addListener(new Button.ClickListener() {

        private static final long serialVersionUID = 5267967369680365653L;

        public void buttonClick(ClickEvent event) {
            formModel.removeForm(taskItemId);
            close();
        }
    });
    layout.addComponent(new Label(""));
    layout.addComponent(buttons);
}
Also used : PropertyTable(org.activiti.explorer.ui.process.simple.editor.table.PropertyTable) Button(com.vaadin.ui.Button) ClickEvent(com.vaadin.ui.Button.ClickEvent) Label(com.vaadin.ui.Label) VerticalLayout(com.vaadin.ui.VerticalLayout) FormDefinition(org.activiti.workflow.simple.definition.form.FormDefinition) HorizontalLayout(com.vaadin.ui.HorizontalLayout)

Aggregations

FormDefinition (org.activiti.workflow.simple.definition.form.FormDefinition)14 HumanStepDefinition (org.activiti.workflow.simple.definition.HumanStepDefinition)9 Test (org.junit.Test)8 WorkflowDefinition (org.activiti.workflow.simple.definition.WorkflowDefinition)7 WorkflowDefinitionConversion (org.activiti.workflow.simple.converter.WorkflowDefinitionConversion)6 UserTask (org.activiti.bpmn.model.UserTask)4 M2Model (org.activiti.workflow.simple.alfresco.model.M2Model)4 M2Type (org.activiti.workflow.simple.alfresco.model.M2Type)4 FlowElement (org.activiti.bpmn.model.FlowElement)3 FormPropertyGroup (org.activiti.workflow.simple.definition.form.FormPropertyGroup)3 ListPropertyEntry (org.activiti.workflow.simple.definition.form.ListPropertyEntry)3 TextPropertyDefinition (org.activiti.workflow.simple.definition.form.TextPropertyDefinition)3 Item (com.vaadin.data.Item)2 Button (com.vaadin.ui.Button)2 HorizontalLayout (com.vaadin.ui.HorizontalLayout)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 Process (org.activiti.bpmn.model.Process)2 M2ClassAssociation (org.activiti.workflow.simple.alfresco.model.M2ClassAssociation)2 ListConditionStepDefinition (org.activiti.workflow.simple.definition.ListConditionStepDefinition)2 StepDefinition (org.activiti.workflow.simple.definition.StepDefinition)2