Search in sources :

Example 21 with UserTask

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

the class BaseBpmnJsonConverter method convertJsonToFormProperties.

protected void convertJsonToFormProperties(JsonNode objectNode, BaseElement element) {
    JsonNode formPropertiesNode = getProperty(PROPERTY_FORM_PROPERTIES, objectNode);
    if (formPropertiesNode != null) {
        formPropertiesNode = BpmnJsonConverterUtil.validateIfNodeIsTextual(formPropertiesNode);
        JsonNode propertiesArray = formPropertiesNode.get("formProperties");
        if (propertiesArray != null) {
            for (JsonNode formNode : propertiesArray) {
                JsonNode formIdNode = formNode.get(PROPERTY_FORM_ID);
                if (formIdNode != null && StringUtils.isNotEmpty(formIdNode.asText())) {
                    FormProperty formProperty = new FormProperty();
                    formProperty.setId(formIdNode.asText());
                    formProperty.setName(getValueAsString(PROPERTY_FORM_NAME, formNode));
                    formProperty.setType(getValueAsString(PROPERTY_FORM_TYPE, formNode));
                    formProperty.setExpression(getValueAsString(PROPERTY_FORM_EXPRESSION, formNode));
                    formProperty.setVariable(getValueAsString(PROPERTY_FORM_VARIABLE, formNode));
                    if ("date".equalsIgnoreCase(formProperty.getType())) {
                        formProperty.setDatePattern(getValueAsString(PROPERTY_FORM_DATE_PATTERN, formNode));
                    } else if ("enum".equalsIgnoreCase(formProperty.getType())) {
                        JsonNode enumValuesNode = formNode.get(PROPERTY_FORM_ENUM_VALUES);
                        if (enumValuesNode != null) {
                            List<FormValue> formValueList = new ArrayList<FormValue>();
                            for (JsonNode enumNode : enumValuesNode) {
                                if (enumNode.get(PROPERTY_FORM_ENUM_VALUES_ID) != null && enumNode.get(PROPERTY_FORM_ENUM_VALUES_ID).isNull() == false && enumNode.get(PROPERTY_FORM_ENUM_VALUES_NAME) != null && enumNode.get(PROPERTY_FORM_ENUM_VALUES_NAME).isNull() == false) {
                                    FormValue formValue = new FormValue();
                                    formValue.setId(enumNode.get(PROPERTY_FORM_ENUM_VALUES_ID).asText());
                                    formValue.setName(enumNode.get(PROPERTY_FORM_ENUM_VALUES_NAME).asText());
                                    formValueList.add(formValue);
                                } else if (enumNode.get("value") != null && enumNode.get("value").isNull() == false) {
                                    FormValue formValue = new FormValue();
                                    formValue.setId(enumNode.get("value").asText());
                                    formValue.setName(enumNode.get("value").asText());
                                    formValueList.add(formValue);
                                }
                            }
                            formProperty.setFormValues(formValueList);
                        }
                    }
                    formProperty.setRequired(getValueAsBoolean(PROPERTY_FORM_REQUIRED, formNode));
                    formProperty.setReadable(getValueAsBoolean(PROPERTY_FORM_READABLE, formNode));
                    formProperty.setWriteable(getValueAsBoolean(PROPERTY_FORM_WRITABLE, formNode));
                    if (element instanceof StartEvent) {
                        ((StartEvent) element).getFormProperties().add(formProperty);
                    } else if (element instanceof UserTask) {
                        ((UserTask) element).getFormProperties().add(formProperty);
                    }
                }
            }
        }
    }
}
Also used : FormValue(org.activiti.bpmn.model.FormValue) FormProperty(org.activiti.bpmn.model.FormProperty) StartEvent(org.activiti.bpmn.model.StartEvent) UserTask(org.activiti.bpmn.model.UserTask) JsonNode(com.fasterxml.jackson.databind.JsonNode) ArrayList(java.util.ArrayList) List(java.util.List)

Example 22 with UserTask

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

the class UserTaskJsonConverter method convertElementToJson.

@Override
protected void convertElementToJson(ObjectNode propertiesNode, BaseElement baseElement) {
    UserTask userTask = (UserTask) baseElement;
    String assignee = userTask.getAssignee();
    String owner = userTask.getOwner();
    if (StringUtils.isNotEmpty(assignee) || StringUtils.isNotEmpty(owner) || CollectionUtils.isNotEmpty(userTask.getCandidateUsers()) || CollectionUtils.isNotEmpty(userTask.getCandidateGroups())) {
        ObjectNode assignmentNode = objectMapper.createObjectNode();
        ObjectNode assignmentValuesNode = objectMapper.createObjectNode();
        if (StringUtils.isNotEmpty(assignee)) {
            assignmentValuesNode.put(PROPERTY_USERTASK_ASSIGNEE, assignee);
        }
        if (StringUtils.isNotEmpty(owner)) {
            assignmentValuesNode.put(PROPERTY_USERTASK_OWNER, owner);
        }
        if (CollectionUtils.isNotEmpty(userTask.getCandidateUsers())) {
            ArrayNode candidateArrayNode = objectMapper.createArrayNode();
            for (String candidateUser : userTask.getCandidateUsers()) {
                ObjectNode candidateNode = objectMapper.createObjectNode();
                candidateNode.put("value", candidateUser);
                candidateArrayNode.add(candidateNode);
            }
            assignmentValuesNode.put(PROPERTY_USERTASK_CANDIDATE_USERS, candidateArrayNode);
        }
        if (CollectionUtils.isNotEmpty(userTask.getCandidateGroups())) {
            ArrayNode candidateArrayNode = objectMapper.createArrayNode();
            for (String candidateGroup : userTask.getCandidateGroups()) {
                ObjectNode candidateNode = objectMapper.createObjectNode();
                candidateNode.put("value", candidateGroup);
                candidateArrayNode.add(candidateNode);
            }
            assignmentValuesNode.put(PROPERTY_USERTASK_CANDIDATE_GROUPS, candidateArrayNode);
        }
        assignmentNode.put("assignment", assignmentValuesNode);
        propertiesNode.put(PROPERTY_USERTASK_ASSIGNMENT, assignmentNode);
    }
    if (userTask.getPriority() != null) {
        setPropertyValue(PROPERTY_USERTASK_PRIORITY, userTask.getPriority().toString(), propertiesNode);
    }
    if (StringUtils.isNotEmpty(userTask.getFormKey())) {
        setPropertyValue(PROPERTY_FORMKEY, userTask.getFormKey(), propertiesNode);
    }
    setPropertyValue(PROPERTY_USERTASK_DUEDATE, userTask.getDueDate(), propertiesNode);
    setPropertyValue(PROPERTY_USERTASK_CATEGORY, userTask.getCategory(), propertiesNode);
    addFormProperties(userTask.getFormProperties(), propertiesNode);
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) UserTask(org.activiti.bpmn.model.UserTask) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode)

Example 23 with UserTask

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

the class BpmnJsonConverterUtil method parseListeners.

protected static void parseListeners(JsonNode listenersNode, BaseElement element, boolean isTaskListener) {
    if (listenersNode == null)
        return;
    listenersNode = validateIfNodeIsTextual(listenersNode);
    for (JsonNode listenerNode : listenersNode) {
        listenerNode = validateIfNodeIsTextual(listenerNode);
        JsonNode eventNode = listenerNode.get(PROPERTY_LISTENER_EVENT);
        if (eventNode != null && eventNode.isNull() == false && StringUtils.isNotEmpty(eventNode.asText())) {
            ActivitiListener listener = new ActivitiListener();
            listener.setEvent(eventNode.asText());
            if (StringUtils.isNotEmpty(getValueAsString(PROPERTY_LISTENER_CLASS_NAME, listenerNode))) {
                listener.setImplementationType(ImplementationType.IMPLEMENTATION_TYPE_CLASS);
                listener.setImplementation(getValueAsString(PROPERTY_LISTENER_CLASS_NAME, listenerNode));
            } else if (StringUtils.isNotEmpty(getValueAsString(PROPERTY_LISTENER_EXPRESSION, listenerNode))) {
                listener.setImplementationType(ImplementationType.IMPLEMENTATION_TYPE_EXPRESSION);
                listener.setImplementation(getValueAsString(PROPERTY_LISTENER_EXPRESSION, listenerNode));
            } else if (StringUtils.isNotEmpty(getValueAsString(PROPERTY_LISTENER_DELEGATE_EXPRESSION, listenerNode))) {
                listener.setImplementationType(ImplementationType.IMPLEMENTATION_TYPE_DELEGATEEXPRESSION);
                listener.setImplementation(getValueAsString(PROPERTY_LISTENER_DELEGATE_EXPRESSION, listenerNode));
            }
            JsonNode fieldsNode = listenerNode.get(PROPERTY_LISTENER_FIELDS);
            if (fieldsNode != null) {
                for (JsonNode fieldNode : fieldsNode) {
                    JsonNode nameNode = fieldNode.get(PROPERTY_FIELD_NAME);
                    if (nameNode != null && nameNode.isNull() == false && StringUtils.isNotEmpty(nameNode.asText())) {
                        FieldExtension fieldExtension = new FieldExtension();
                        fieldExtension.setFieldName(nameNode.asText());
                        fieldExtension.setStringValue(getValueAsString(PROPERTY_FIELD_STRING_VALUE, fieldNode));
                        if (StringUtils.isEmpty(fieldExtension.getStringValue())) {
                            fieldExtension.setStringValue(getValueAsString(PROPERTY_FIELD_STRING, fieldNode));
                        }
                        if (StringUtils.isEmpty(fieldExtension.getStringValue())) {
                            fieldExtension.setExpression(getValueAsString(PROPERTY_FIELD_EXPRESSION, fieldNode));
                        }
                        listener.getFieldExtensions().add(fieldExtension);
                    }
                }
            }
            if (element instanceof Process) {
                ((Process) element).getExecutionListeners().add(listener);
            } else if (element instanceof SequenceFlow) {
                ((SequenceFlow) element).getExecutionListeners().add(listener);
            } else if (element instanceof UserTask) {
                if (isTaskListener) {
                    ((UserTask) element).getTaskListeners().add(listener);
                } else {
                    ((UserTask) element).getExecutionListeners().add(listener);
                }
            } else if (element instanceof FlowElement) {
                ((FlowElement) element).getExecutionListeners().add(listener);
            }
        }
    }
}
Also used : FieldExtension(org.activiti.bpmn.model.FieldExtension) SequenceFlow(org.activiti.bpmn.model.SequenceFlow) FlowElement(org.activiti.bpmn.model.FlowElement) UserTask(org.activiti.bpmn.model.UserTask) JsonNode(com.fasterxml.jackson.databind.JsonNode) Process(org.activiti.bpmn.model.Process) ActivitiListener(org.activiti.bpmn.model.ActivitiListener)

Example 24 with UserTask

use of org.activiti.bpmn.model.UserTask 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 25 with UserTask

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

the class ValuedDataObjectConverterTest method validateModel.

private void validateModel(BpmnModel model) {
    FlowElement flowElement = model.getMainProcess().getFlowElement("start1");
    assertNotNull(flowElement);
    assertTrue(flowElement instanceof StartEvent);
    assertEquals("start1", flowElement.getId());
    // verify the main process data objects
    List<ValuedDataObject> dataObjects = model.getProcess(null).getDataObjects();
    assertEquals(7, dataObjects.size());
    Map<String, ValuedDataObject> objectMap = new HashMap<String, ValuedDataObject>();
    for (ValuedDataObject valueObj : dataObjects) {
        objectMap.put(valueObj.getId(), valueObj);
    }
    ValuedDataObject dataObj = objectMap.get("dObj1");
    assertEquals("dObj1", dataObj.getId());
    assertEquals("StringTest", dataObj.getName());
    assertEquals("xsd:string", dataObj.getItemSubjectRef().getStructureRef());
    assertTrue(dataObj.getValue() instanceof String);
    assertEquals("Testing1&2&3", dataObj.getValue());
    dataObj = objectMap.get("dObj2");
    assertEquals("dObj2", dataObj.getId());
    assertEquals("BooleanTest", dataObj.getName());
    assertEquals("xsd:boolean", dataObj.getItemSubjectRef().getStructureRef());
    assertTrue(dataObj.getValue() instanceof Boolean);
    assertEquals(new Boolean(true), dataObj.getValue());
    dataObj = objectMap.get("dObj3");
    assertEquals("dObj3", dataObj.getId());
    assertEquals("DateTest", dataObj.getName());
    assertEquals("xsd:datetime", dataObj.getItemSubjectRef().getStructureRef());
    assertTrue(dataObj.getValue() instanceof Date);
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
    assertEquals("2013-09-16T11:23:00", sdf.format(dataObj.getValue()));
    dataObj = objectMap.get("dObj4");
    assertEquals("dObj4", dataObj.getId());
    assertEquals("DoubleTest", dataObj.getName());
    assertEquals("xsd:double", dataObj.getItemSubjectRef().getStructureRef());
    assertTrue(dataObj.getValue() instanceof Double);
    assertEquals(new Double(123456789), dataObj.getValue());
    dataObj = objectMap.get("dObj5");
    assertEquals("dObj5", dataObj.getId());
    assertEquals("IntegerTest", dataObj.getName());
    assertEquals("xsd:int", dataObj.getItemSubjectRef().getStructureRef());
    assertTrue(dataObj.getValue() instanceof Integer);
    assertEquals(new Integer(123), dataObj.getValue());
    dataObj = objectMap.get("dObj6");
    assertEquals("dObj6", dataObj.getId());
    assertEquals("LongTest", dataObj.getName());
    assertEquals("xsd:long", dataObj.getItemSubjectRef().getStructureRef());
    assertTrue(dataObj.getValue() instanceof Long);
    assertEquals(new Long(-123456), dataObj.getValue());
    assertEquals(1, dataObj.getExtensionElements().size());
    List<ExtensionElement> testValues = dataObj.getExtensionElements().get("testvalue");
    assertNotNull(testValues);
    assertEquals(1, testValues.size());
    assertEquals("testvalue", testValues.get(0).getName());
    assertEquals("test", testValues.get(0).getElementText());
    dataObj = objectMap.get("NoData");
    assertEquals("NoData", dataObj.getId());
    assertEquals("NoData", dataObj.getName());
    assertEquals("xsd:datetime", dataObj.getItemSubjectRef().getStructureRef());
    assertNull(dataObj.getValue());
    flowElement = model.getMainProcess().getFlowElement("userTask1");
    assertNotNull(flowElement);
    assertTrue(flowElement instanceof UserTask);
    assertEquals("userTask1", flowElement.getId());
    UserTask userTask = (UserTask) flowElement;
    assertEquals("kermit", userTask.getAssignee());
    flowElement = model.getMainProcess().getFlowElement("subprocess1");
    assertNotNull(flowElement);
    assertTrue(flowElement instanceof SubProcess);
    assertEquals("subprocess1", flowElement.getId());
    SubProcess subProcess = (SubProcess) flowElement;
    assertEquals(11, subProcess.getFlowElements().size());
    // verify the sub process data objects
    dataObjects = subProcess.getDataObjects();
    assertEquals(6, dataObjects.size());
    objectMap = new HashMap<String, ValuedDataObject>();
    for (ValuedDataObject valueObj : dataObjects) {
        objectMap.put(valueObj.getId(), valueObj);
    }
    dataObj = objectMap.get("dObj7");
    assertEquals("dObj7", dataObj.getId());
    assertEquals("StringSubTest", dataObj.getName());
    assertEquals("xsd:string", dataObj.getItemSubjectRef().getStructureRef());
    assertTrue(dataObj.getValue() instanceof String);
    assertEquals("Testing456", dataObj.getValue());
    dataObj = objectMap.get("dObj8");
    assertEquals("dObj8", dataObj.getId());
    assertEquals("BooleanSubTest", dataObj.getName());
    assertEquals("xsd:boolean", dataObj.getItemSubjectRef().getStructureRef());
    assertTrue(dataObj.getValue() instanceof Boolean);
    assertEquals(new Boolean(false), dataObj.getValue());
    dataObj = objectMap.get("dObj9");
    assertEquals("dObj9", dataObj.getId());
    assertEquals("DateSubTest", dataObj.getName());
    assertEquals("xsd:datetime", dataObj.getItemSubjectRef().getStructureRef());
    assertTrue(dataObj.getValue() instanceof Date);
    assertEquals("2013-11-11T22:00:00", sdf.format(dataObj.getValue()));
    dataObj = objectMap.get("dObj10");
    assertEquals("dObj10", dataObj.getId());
    assertEquals("DoubleSubTest", dataObj.getName());
    assertEquals("xsd:double", dataObj.getItemSubjectRef().getStructureRef());
    assertTrue(dataObj.getValue() instanceof Double);
    assertEquals(new Double(678912345), dataObj.getValue());
    dataObj = objectMap.get("dObj11");
    assertEquals("dObj11", dataObj.getId());
    assertEquals("IntegerSubTest", dataObj.getName());
    assertEquals("xsd:int", dataObj.getItemSubjectRef().getStructureRef());
    assertTrue(dataObj.getValue() instanceof Integer);
    assertEquals(new Integer(45), dataObj.getValue());
    dataObj = objectMap.get("dObj12");
    assertEquals("dObj12", dataObj.getId());
    assertEquals("LongSubTest", dataObj.getName());
    assertEquals("xsd:long", dataObj.getItemSubjectRef().getStructureRef());
    assertTrue(dataObj.getValue() instanceof Long);
    assertEquals(new Long(456123), dataObj.getValue());
}
Also used : SubProcess(org.activiti.bpmn.model.SubProcess) ValuedDataObject(org.activiti.bpmn.model.ValuedDataObject) HashMap(java.util.HashMap) ExtensionElement(org.activiti.bpmn.model.ExtensionElement) UserTask(org.activiti.bpmn.model.UserTask) Date(java.util.Date) FlowElement(org.activiti.bpmn.model.FlowElement) StartEvent(org.activiti.bpmn.model.StartEvent) SimpleDateFormat(java.text.SimpleDateFormat)

Aggregations

UserTask (org.activiti.bpmn.model.UserTask)48 FlowElement (org.activiti.bpmn.model.FlowElement)25 StartEvent (org.activiti.bpmn.model.StartEvent)18 SequenceFlow (org.activiti.bpmn.model.SequenceFlow)11 SubProcess (org.activiti.bpmn.model.SubProcess)11 FormProperty (org.activiti.bpmn.model.FormProperty)7 ActivitiListener (org.activiti.bpmn.model.ActivitiListener)6 BoundaryEvent (org.activiti.bpmn.model.BoundaryEvent)6 EndEvent (org.activiti.bpmn.model.EndEvent)6 HashMap (java.util.HashMap)5 BpmnModel (org.activiti.bpmn.model.BpmnModel)5 Process (org.activiti.bpmn.model.Process)5 JsonNode (com.fasterxml.jackson.databind.JsonNode)4 FormValue (org.activiti.bpmn.model.FormValue)4 IntermediateCatchEvent (org.activiti.bpmn.model.IntermediateCatchEvent)4 TimerEventDefinition (org.activiti.bpmn.model.TimerEventDefinition)4 AlfrescoUserTask (org.activiti.bpmn.model.alfresco.AlfrescoUserTask)4 HumanStepDefinition (org.activiti.workflow.simple.definition.HumanStepDefinition)4 FormDefinition (org.activiti.workflow.simple.definition.form.FormDefinition)4 ArrayList (java.util.ArrayList)3