Search in sources :

Example 1 with FormPropertyDefinition

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

the class FormPopupWindow method getFormPropertyDefinition.

protected FormPropertyDefinition getFormPropertyDefinition(Item item) {
    String type = (String) ((ComboBox) item.getItemProperty(PropertyTable.ID_PROPERTY_TYPE).getValue()).getValue();
    FormPropertyDefinition result = null;
    if (type.equals("number")) {
        result = new NumberPropertyDefinition();
    } else if (type.equals("date")) {
        result = new DatePropertyDefinition();
    } else {
        result = new TextPropertyDefinition();
    }
    // Set generic properties
    result.setName((String) item.getItemProperty(PropertyTable.ID_PROPERTY_NAME).getValue());
    result.setMandatory((Boolean) ((CheckBox) item.getItemProperty(PropertyTable.ID_PROPERTY_REQUIRED).getValue()).getValue());
    return result;
}
Also used : NumberPropertyDefinition(org.activiti.workflow.simple.definition.form.NumberPropertyDefinition) TextPropertyDefinition(org.activiti.workflow.simple.definition.form.TextPropertyDefinition) CheckBox(com.vaadin.ui.CheckBox) FormPropertyDefinition(org.activiti.workflow.simple.definition.form.FormPropertyDefinition) DatePropertyDefinition(org.activiti.workflow.simple.definition.form.DatePropertyDefinition)

Example 2 with FormPropertyDefinition

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

the class FormPopupWindow method createForm.

public FormDefinition createForm() {
    FormDefinition formDefinition = new FormDefinition();
    for (Object itemId : propertyTable.getItemIds()) {
        Item item = propertyTable.getItem(itemId);
        FormPropertyDefinition formPropertyDefinition = getFormPropertyDefinition(item);
        formDefinition.addFormProperty(formPropertyDefinition);
    }
    return formDefinition;
}
Also used : Item(com.vaadin.data.Item) FormPropertyDefinition(org.activiti.workflow.simple.definition.form.FormPropertyDefinition) FormDefinition(org.activiti.workflow.simple.definition.form.FormDefinition)

Example 3 with FormPropertyDefinition

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

the class AlfrescoFormCreator method createForm.

public void createForm(M2Type contentType, Form formConfig, FormDefinition formDefinition, WorkflowDefinitionConversion conversion) {
    if (formDefinition != null && formDefinition.getFormGroups() != null) {
        for (FormPropertyGroup group : formDefinition.getFormGroups()) {
            // Create a group in the form-config
            String groupId = null;
            if (group.getId() != null) {
                groupId = AlfrescoConversionUtil.getValidIdString(group.getId());
            } else {
                groupId = AlfrescoConversionUtil.getValidIdString(group.getTitle());
            }
            FormSet formSet = formConfig.getFormAppearance().addFormSet(groupId, getAppearanceForGroup(group), group.getTitle(), getTemplateForGroup(group));
            // Convert all properties
            AlfrescoFormPropertyConverter converter = null;
            for (FormPropertyDefinition property : group.getFormPropertyDefinitions()) {
                converter = propertyConverters.get(property.getClass());
                if (converter == null) {
                    throw new AlfrescoSimpleWorkflowException("Unsupported property type: " + property.getClass().getName());
                }
                converter.convertProperty(contentType, formSet.getId(), formConfig, property, conversion);
            }
        }
    }
    if (formDefinition != null && formDefinition.getFormPropertyDefinitions() != null && !formDefinition.getFormPropertyDefinitions().isEmpty()) {
        for (FormPropertyDefinition def : formDefinition.getFormPropertyDefinitions()) {
            if (def instanceof AlfrescoTransitionsPropertyDefinition) {
                AlfrescoFormPropertyConverter converter = propertyConverters.get(def.getClass());
                if (converter != null) {
                    converter.convertProperty(contentType, null, formConfig, def, conversion);
                }
            }
        }
    }
    // Finally, add default "transitions" if not already added to the model
    if (formConfig.getFormAppearance().getFormSet(AlfrescoConversionConstants.FORM_SET_RESPONSE) == null) {
        formConfig.getFormAppearance().addFormSet(AlfrescoConversionConstants.FORM_SET_RESPONSE, null, null, null);
        formConfig.getFormFieldVisibility().addShowFieldElement(AlfrescoConversionConstants.FORM_FIELD_TRANSITIONS);
        formConfig.getFormAppearance().addFormField(AlfrescoConversionConstants.FORM_FIELD_TRANSITIONS, null, AlfrescoConversionConstants.FORM_SET_RESPONSE);
    }
}
Also used : AlfrescoTransitionsPropertyDefinition(org.activiti.workflow.simple.alfresco.form.AlfrescoTransitionsPropertyDefinition) FormPropertyGroup(org.activiti.workflow.simple.definition.form.FormPropertyGroup) FormSet(org.activiti.workflow.simple.alfresco.model.config.FormSet) FormPropertyDefinition(org.activiti.workflow.simple.definition.form.FormPropertyDefinition) AlfrescoSimpleWorkflowException(org.activiti.workflow.simple.alfresco.conversion.exception.AlfrescoSimpleWorkflowException)

Example 4 with FormPropertyDefinition

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

the class InitializeAlfrescoModelsConversionListener method addAspectsForReusedProperties.

protected void addAspectsForReusedProperties(WorkflowDefinition workflowDefinition, M2Model model, String processId) {
    Map<String, FormPropertyDefinition> definitionMap = new HashMap<String, FormPropertyDefinition>();
    // Add start-form properties
    addDefinitionsToMap(workflowDefinition.getStartFormDefinition(), definitionMap);
    // Run through steps recursivelye, looking for properties
    addAspectsForReusedProperties(workflowDefinition.getSteps(), model, processId, definitionMap);
    // Check if the map contains values other than null, this indicates duplicate properties are found
    for (Entry<String, FormPropertyDefinition> entry : definitionMap.entrySet()) {
        if (entry.getValue() != null) {
            // Create an aspect for this property. The aspect itself will be populated when the first
            // property is converted with that name
            M2Aspect aspect = new M2Aspect();
            aspect.setName(AlfrescoConversionUtil.getQualifiedName(processId, entry.getKey()));
            model.getAspects().add(aspect);
        }
    }
}
Also used : HashMap(java.util.HashMap) FormPropertyDefinition(org.activiti.workflow.simple.definition.form.FormPropertyDefinition) M2Aspect(org.activiti.workflow.simple.alfresco.model.M2Aspect)

Example 5 with FormPropertyDefinition

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

FormPropertyDefinition (org.activiti.workflow.simple.definition.form.FormPropertyDefinition)6 NumberPropertyDefinition (org.activiti.workflow.simple.definition.form.NumberPropertyDefinition)3 DatePropertyDefinition (org.activiti.workflow.simple.definition.form.DatePropertyDefinition)2 FormDefinition (org.activiti.workflow.simple.definition.form.FormDefinition)2 ListPropertyDefinition (org.activiti.workflow.simple.definition.form.ListPropertyDefinition)2 ListPropertyEntry (org.activiti.workflow.simple.definition.form.ListPropertyEntry)2 TextPropertyDefinition (org.activiti.workflow.simple.definition.form.TextPropertyDefinition)2 Item (com.vaadin.data.Item)1 CheckBox (com.vaadin.ui.CheckBox)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 OutputStreamWriter (java.io.OutputStreamWriter)1 Writer (java.io.Writer)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 FormProperty (org.activiti.bpmn.model.FormProperty)1 FormValue (org.activiti.bpmn.model.FormValue)1 AlfrescoSimpleWorkflowException (org.activiti.workflow.simple.alfresco.conversion.exception.AlfrescoSimpleWorkflowException)1 AlfrescoTransitionsPropertyDefinition (org.activiti.workflow.simple.alfresco.form.AlfrescoTransitionsPropertyDefinition)1 M2Aspect (org.activiti.workflow.simple.alfresco.model.M2Aspect)1