Search in sources :

Example 6 with FormProperty

use of org.activiti.bpmn.model.FormProperty in project Activiti by Activiti.

the class FormPropertiesConverterTest method validateModel.

private void validateModel(BpmnModel model) {
    assertEquals("formPropertiesProcess", model.getMainProcess().getId());
    assertEquals("User registration", model.getMainProcess().getName());
    assertEquals(true, model.getMainProcess().isExecutable());
    FlowElement startFlowElement = model.getMainProcess().getFlowElement("startNode");
    assertNotNull(startFlowElement);
    assertTrue(startFlowElement instanceof StartEvent);
    StartEvent startEvent = (StartEvent) startFlowElement;
    for (FormProperty formProperty : startEvent.getFormProperties()) {
        assertEquals(true, formProperty.isRequired());
    }
    FlowElement userFlowElement = model.getMainProcess().getFlowElement("userTask");
    assertNotNull(userFlowElement);
    assertTrue(userFlowElement instanceof UserTask);
    UserTask userTask = (UserTask) userFlowElement;
    List<FormProperty> formProperties = userTask.getFormProperties();
    assertNotNull(formProperties);
    assertEquals("Invalid form properties list: ", 8, formProperties.size());
    for (FormProperty formProperty : formProperties) {
        if (formProperty.getId().equals("new_property_1")) {
            checkFormProperty(formProperty, false, false, false);
        } else if (formProperty.getId().equals("new_property_2")) {
            checkFormProperty(formProperty, false, false, true);
        } else if (formProperty.getId().equals("new_property_3")) {
            checkFormProperty(formProperty, false, true, false);
        } else if (formProperty.getId().equals("new_property_4")) {
            checkFormProperty(formProperty, false, true, true);
        } else if (formProperty.getId().equals("new_property_5")) {
            checkFormProperty(formProperty, true, false, false);
            List<Map<String, Object>> formValues = new ArrayList<Map<String, Object>>();
            for (FormValue formValue : formProperty.getFormValues()) {
                Map<String, Object> formValueMap = new HashMap<String, Object>();
                formValueMap.put("id", formValue.getId());
                formValueMap.put("name", formValue.getName());
                formValues.add(formValueMap);
            }
            checkFormPropertyFormValues(formValues);
        } else if (formProperty.getId().equals("new_property_6")) {
            checkFormProperty(formProperty, true, false, true);
        } else if (formProperty.getId().equals("new_property_7")) {
            checkFormProperty(formProperty, true, true, false);
        } else if (formProperty.getId().equals("new_property_8")) {
            checkFormProperty(formProperty, true, true, true);
        }
    }
}
Also used : FormValue(org.activiti.bpmn.model.FormValue) FormProperty(org.activiti.bpmn.model.FormProperty) HashMap(java.util.HashMap) UserTask(org.activiti.bpmn.model.UserTask) ArrayList(java.util.ArrayList) FlowElement(org.activiti.bpmn.model.FlowElement) StartEvent(org.activiti.bpmn.model.StartEvent) HashMap(java.util.HashMap) Map(java.util.Map)

Example 7 with FormProperty

use of org.activiti.bpmn.model.FormProperty in project Activiti by Activiti.

the class BaseStepDefinitionConverter method convertProperties.

/**
   * Converts form properties. Multiple step types can contain forms,
   * hence why it it a shared method here.
   */
protected List<FormProperty> convertProperties(FormDefinition formDefinition) {
    List<FormProperty> formProperties = new ArrayList<FormProperty>();
    for (FormPropertyDefinition propertyDefinition : formDefinition.getFormPropertyDefinitions()) {
        FormProperty formProperty = new FormProperty();
        formProperties.add(formProperty);
        formProperty.setId(propertyDefinition.getName());
        formProperty.setName(propertyDefinition.getName());
        formProperty.setRequired(propertyDefinition.isMandatory());
        String type = null;
        if (propertyDefinition instanceof NumberPropertyDefinition) {
            type = "long";
        } else if (propertyDefinition instanceof DatePropertyDefinition) {
            type = "date";
        } else if (propertyDefinition instanceof BooleanPropertyDefinition) {
            type = "boolean";
        } else if (propertyDefinition instanceof ListPropertyDefinition) {
            type = "enum";
            ListPropertyDefinition listDefinition = (ListPropertyDefinition) propertyDefinition;
            if (!listDefinition.getEntries().isEmpty()) {
                List<FormValue> formValues = new ArrayList<FormValue>(listDefinition.getEntries().size());
                for (ListPropertyEntry entry : listDefinition.getEntries()) {
                    FormValue formValue = new FormValue();
                    // We're using same value for id and name for the moment
                    formValue.setId(entry.getValue());
                    formValue.setName(entry.getName());
                    formValues.add(formValue);
                }
                formProperty.setFormValues(formValues);
            }
        } else {
            // Fallback to simple text
            type = "string";
        }
        formProperty.setType(type);
    }
    return formProperties;
}
Also used : ListPropertyEntry(org.activiti.workflow.simple.definition.form.ListPropertyEntry) BooleanPropertyDefinition(org.activiti.workflow.simple.definition.form.BooleanPropertyDefinition) FormValue(org.activiti.bpmn.model.FormValue) FormProperty(org.activiti.bpmn.model.FormProperty) ArrayList(java.util.ArrayList) FormPropertyDefinition(org.activiti.workflow.simple.definition.form.FormPropertyDefinition) NumberPropertyDefinition(org.activiti.workflow.simple.definition.form.NumberPropertyDefinition) ListPropertyDefinition(org.activiti.workflow.simple.definition.form.ListPropertyDefinition) ArrayList(java.util.ArrayList) List(java.util.List) DatePropertyDefinition(org.activiti.workflow.simple.definition.form.DatePropertyDefinition)

Example 8 with FormProperty

use of org.activiti.bpmn.model.FormProperty in project Activiti by Activiti.

the class FeedbackStepDefinitionConverter method createSelectPeopleUserTask.

protected UserTask createSelectPeopleUserTask(FeedbackStepDefinition feedbackStepDefinition, WorkflowDefinitionConversion conversion, Map<String, BaseElement> processElements) {
    UserTask selectPeopleUserTask = new UserTask();
    selectPeopleUserTask.setId(conversion.getUniqueNumberedId(ConversionConstants.USER_TASK_ID_PREFIX));
    selectPeopleUserTask.setName(getSelectPeopleTaskName());
    selectPeopleUserTask.setAssignee(feedbackStepDefinition.getFeedbackInitiator());
    addFlowElement(conversion, selectPeopleUserTask, true);
    processElements.put(SELECT_PEOPLE_USER_TASK, selectPeopleUserTask);
    // TODO: work out form such that it can be used in Activiti Explorer, ie. add correct form properties
    // The following is just a a bit of a dummy form property
    FormProperty feedbackProvidersProperty = new FormProperty();
    feedbackProvidersProperty.setId(VARIABLE_FEEDBACK_PROVIDERS);
    feedbackProvidersProperty.setName("Who needs to provide feedback?");
    feedbackProvidersProperty.setRequired(true);
    // TODO: we need some kind of 'people' property type here
    feedbackProvidersProperty.setType("string");
    selectPeopleUserTask.setFormProperties(Arrays.asList(feedbackProvidersProperty));
    // that injects these variables into the process (instead of having it provided by the end user in a form)
    if (feedbackStepDefinition.getFeedbackProviders() != null && !feedbackStepDefinition.getFeedbackProviders().isEmpty()) {
        if (selectPeopleUserTask.getTaskListeners() == null) {
            selectPeopleUserTask.setTaskListeners(new ArrayList<ActivitiListener>());
        }
        ActivitiListener taskListener = new ActivitiListener();
        taskListener.setEvent("complete");
        taskListener.setImplementationType(ImplementationType.IMPLEMENTATION_TYPE_CLASS);
        taskListener.setImplementation("org.activiti.engine.impl.bpmn.listener.ScriptTaskListener");
        FieldExtension languageField = new FieldExtension();
        languageField.setFieldName("language");
        languageField.setStringValue("JavaScript");
        FieldExtension scriptField = new FieldExtension();
        scriptField.setFieldName("script");
        StringBuilder script = new StringBuilder();
        if (JvmUtil.isJDK8()) {
            script.append("load(\"nashorn:mozilla_compat.js\");");
        }
        script.append("importPackage (java.util); var feedbackProviders = new ArrayList();" + System.getProperty("line.separator"));
        for (String feedbackProvider : feedbackStepDefinition.getFeedbackProviders()) {
            script.append("feedbackProviders.add('" + feedbackProvider + "');" + System.getProperty("line.separator"));
        }
        script.append("task.getExecution().setVariable('" + VARIABLE_FEEDBACK_PROVIDERS + "', feedbackProviders);" + System.getProperty("line.separator"));
        scriptField.setStringValue(script.toString());
        taskListener.setFieldExtensions(Arrays.asList(languageField, scriptField));
        selectPeopleUserTask.getTaskListeners().add(taskListener);
    }
    return selectPeopleUserTask;
}
Also used : FormProperty(org.activiti.bpmn.model.FormProperty) FieldExtension(org.activiti.bpmn.model.FieldExtension) UserTask(org.activiti.bpmn.model.UserTask) ActivitiListener(org.activiti.bpmn.model.ActivitiListener)

Example 9 with FormProperty

use of org.activiti.bpmn.model.FormProperty in project Activiti by Activiti.

the class StartEventConverterTest method validateModel.

private void validateModel(BpmnModel model) {
    FlowElement flowElement = model.getMainProcess().getFlowElement("start");
    assertTrue(flowElement instanceof StartEvent);
    StartEvent startEvent = (StartEvent) flowElement;
    assertEquals("start", startEvent.getId());
    assertEquals("startName", startEvent.getName());
    assertEquals("startFormKey", startEvent.getFormKey());
    assertEquals("startInitiator", startEvent.getInitiator());
    assertEquals("startDoc", startEvent.getDocumentation());
    List<FormProperty> formProperties = startEvent.getFormProperties();
    assertEquals(2, formProperties.size());
    FormProperty formProperty = formProperties.get(0);
    assertEquals("startFormProp1", formProperty.getId());
    assertEquals("startFormProp1", formProperty.getName());
    assertEquals("string", formProperty.getType());
    formProperty = formProperties.get(1);
    assertEquals("startFormProp2", formProperty.getId());
    assertEquals("startFormProp2", formProperty.getName());
    assertEquals("boolean", formProperty.getType());
}
Also used : FormProperty(org.activiti.bpmn.model.FormProperty) FlowElement(org.activiti.bpmn.model.FlowElement) StartEvent(org.activiti.bpmn.model.StartEvent)

Example 10 with FormProperty

use of org.activiti.bpmn.model.FormProperty in project Activiti by Activiti.

the class UserTaskConverterTest method validateModel.

private void validateModel(BpmnModel model) {
    FlowElement flowElement = model.getMainProcess().getFlowElement("usertask");
    assertNotNull(flowElement);
    assertTrue(flowElement instanceof UserTask);
    assertEquals("usertask", flowElement.getId());
    UserTask userTask = (UserTask) flowElement;
    assertEquals("usertask", userTask.getId());
    assertEquals("User task", userTask.getName());
    assertEquals("testKey", userTask.getFormKey());
    assertEquals("40", userTask.getPriority());
    assertEquals("2012-11-01", userTask.getDueDate());
    assertEquals("defaultCategory", userTask.getCategory());
    assertEquals("gonzo", userTask.getOwner());
    assertEquals("kermit", userTask.getAssignee());
    assertEquals(2, userTask.getCandidateUsers().size());
    assertTrue(userTask.getCandidateUsers().contains("kermit"));
    assertTrue(userTask.getCandidateUsers().contains("fozzie"));
    assertEquals(2, userTask.getCandidateGroups().size());
    assertTrue(userTask.getCandidateGroups().contains("management"));
    assertTrue(userTask.getCandidateGroups().contains("sales"));
    List<FormProperty> formProperties = userTask.getFormProperties();
    assertEquals(2, formProperties.size());
    FormProperty formProperty = formProperties.get(0);
    assertEquals("formId", formProperty.getId());
    assertEquals("formName", formProperty.getName());
    assertEquals("string", formProperty.getType());
    assertEquals("variable", formProperty.getVariable());
    assertEquals("${expression}", formProperty.getExpression());
    formProperty = formProperties.get(1);
    assertEquals("formId2", formProperty.getId());
    assertEquals("anotherName", formProperty.getName());
    assertEquals("long", formProperty.getType());
    assertTrue(StringUtils.isEmpty(formProperty.getVariable()));
    assertTrue(StringUtils.isEmpty(formProperty.getExpression()));
    List<ActivitiListener> listeners = userTask.getTaskListeners();
    assertEquals(3, listeners.size());
    ActivitiListener listener = (ActivitiListener) listeners.get(0);
    assertTrue(ImplementationType.IMPLEMENTATION_TYPE_CLASS.equals(listener.getImplementationType()));
    assertEquals("org.test.TestClass", listener.getImplementation());
    assertEquals("create", listener.getEvent());
    assertEquals(2, listener.getFieldExtensions().size());
    assertEquals("testField", listener.getFieldExtensions().get(0).getFieldName());
    assertEquals("test", listener.getFieldExtensions().get(0).getStringValue());
    listener = (ActivitiListener) listeners.get(1);
    assertTrue(ImplementationType.IMPLEMENTATION_TYPE_EXPRESSION.equals(listener.getImplementationType()));
    assertEquals("${someExpression}", listener.getImplementation());
    assertEquals("assignment", listener.getEvent());
    listener = (ActivitiListener) listeners.get(2);
    assertTrue(ImplementationType.IMPLEMENTATION_TYPE_DELEGATEEXPRESSION.equals(listener.getImplementationType()));
    assertEquals("${someDelegateExpression}", listener.getImplementation());
    assertEquals("complete", listener.getEvent());
    flowElement = model.getMainProcess().getFlowElement("start");
    assertTrue(flowElement instanceof StartEvent);
    StartEvent startEvent = (StartEvent) flowElement;
    assertTrue(startEvent.getOutgoingFlows().size() == 1);
    flowElement = model.getMainProcess().getFlowElement("flow1");
    assertTrue(flowElement instanceof SequenceFlow);
    SequenceFlow flow = (SequenceFlow) flowElement;
    assertEquals("flow1", flow.getId());
    assertNotNull(flow.getSourceRef());
    assertNotNull(flow.getTargetRef());
}
Also used : FormProperty(org.activiti.bpmn.model.FormProperty) FlowElement(org.activiti.bpmn.model.FlowElement) SequenceFlow(org.activiti.bpmn.model.SequenceFlow) UserTask(org.activiti.bpmn.model.UserTask) StartEvent(org.activiti.bpmn.model.StartEvent) ActivitiListener(org.activiti.bpmn.model.ActivitiListener)

Aggregations

FormProperty (org.activiti.bpmn.model.FormProperty)11 FormValue (org.activiti.bpmn.model.FormValue)7 UserTask (org.activiti.bpmn.model.UserTask)7 StartEvent (org.activiti.bpmn.model.StartEvent)6 FlowElement (org.activiti.bpmn.model.FlowElement)5 ArrayList (java.util.ArrayList)4 ActivitiListener (org.activiti.bpmn.model.ActivitiListener)3 HashMap (java.util.HashMap)2 List (java.util.List)2 Map (java.util.Map)2 BooleanPropertyDefinition (org.activiti.workflow.simple.definition.form.BooleanPropertyDefinition)2 ListPropertyDefinition (org.activiti.workflow.simple.definition.form.ListPropertyDefinition)2 ListPropertyEntry (org.activiti.workflow.simple.definition.form.ListPropertyEntry)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)1 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 FieldExtension (org.activiti.bpmn.model.FieldExtension)1 SequenceFlow (org.activiti.bpmn.model.SequenceFlow)1 DatePropertyDefinition (org.activiti.workflow.simple.definition.form.DatePropertyDefinition)1 FormDefinition (org.activiti.workflow.simple.definition.form.FormDefinition)1