Search in sources :

Example 1 with ModelInfo

use of org.activiti.editor.language.json.model.ModelInfo 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();
    if (StringUtils.isNotEmpty(assignee) || CollectionUtils.isNotEmpty(userTask.getCandidateUsers()) || CollectionUtils.isNotEmpty(userTask.getCandidateGroups())) {
        ObjectNode assignmentNode = objectMapper.createObjectNode();
        ObjectNode assignmentValuesNode = objectMapper.createObjectNode();
        List<ExtensionElement> idmAssigneeList = userTask.getExtensionElements().get("activiti-idm-assignee");
        List<ExtensionElement> idmAssigneeFieldList = userTask.getExtensionElements().get("activiti-idm-assignee-field");
        if (CollectionUtils.isNotEmpty(idmAssigneeList) || CollectionUtils.isNotEmpty(idmAssigneeFieldList) || CollectionUtils.isNotEmpty(userTask.getExtensionElements().get("activiti-idm-candidate-user")) || CollectionUtils.isNotEmpty(userTask.getExtensionElements().get("activiti-idm-candidate-group"))) {
            assignmentValuesNode.put("type", "idm");
            ObjectNode idmNode = objectMapper.createObjectNode();
            assignmentValuesNode.set("idm", idmNode);
            List<ExtensionElement> canCompleteList = userTask.getExtensionElements().get("initiator-can-complete");
            if (CollectionUtils.isNotEmpty(canCompleteList)) {
                assignmentValuesNode.put("initiatorCanCompleteTask", Boolean.valueOf(canCompleteList.get(0).getElementText()));
            }
            if (StringUtils.isNotEmpty(userTask.getAssignee())) {
                ObjectNode assigneeNode = objectMapper.createObjectNode();
                if (userTask.getAssignee().contains("${taskAssignmentBean.assignTaskToAssignee(")) {
                    idmNode.set("assigneeField", assigneeNode);
                    idmNode.put("type", "user");
                    fillProperty("id", "activiti-idm-assignee-field", assigneeNode, userTask);
                    fillProperty("name", "assignee-field-info-name", assigneeNode, userTask);
                } else {
                    assigneeNode.put("id", userTask.getAssignee());
                    idmNode.set("assignee", assigneeNode);
                    idmNode.put("type", "user");
                    fillProperty("externalId", "assignee-info-externalid", assigneeNode, userTask);
                    fillProperty("email", "assignee-info-email", assigneeNode, userTask);
                    fillProperty("firstName", "assignee-info-firstname", assigneeNode, userTask);
                    fillProperty("lastName", "assignee-info-lastname", assigneeNode, userTask);
                }
            }
            List<ExtensionElement> idmCandidateUserList = userTask.getExtensionElements().get("activiti-idm-candidate-user");
            if (CollectionUtils.isNotEmpty(userTask.getCandidateUsers()) && CollectionUtils.isNotEmpty(idmCandidateUserList)) {
                List<String> candidateUserIds = new ArrayList<String>();
                if (userTask.getCandidateUsers().size() == 1 && userTask.getCandidateUsers().get(0).contains("${taskAssignmentBean.assignTaskToCandidateUsers(")) {
                    idmNode.put("type", "users");
                    String candidateUsersString = userTask.getCandidateUsers().get(0);
                    candidateUsersString = candidateUsersString.replace("${taskAssignmentBean.assignTaskToCandidateUsers('", "");
                    candidateUsersString = candidateUsersString.replace("', execution)}", "");
                    List<String> candidateFieldIds = new ArrayList<String>();
                    String[] candidateUserArray = candidateUsersString.split(",");
                    for (String candidate : candidateUserArray) {
                        if (candidate.contains("field(")) {
                            candidateFieldIds.add(candidate.trim().substring(6, candidate.length() - 1));
                        } else {
                            candidateUserIds.add(candidate.trim());
                        }
                    }
                    if (candidateFieldIds.size() > 0) {
                        ArrayNode candidateUserFieldsNode = objectMapper.createArrayNode();
                        idmNode.set("candidateUserFields", candidateUserFieldsNode);
                        for (String fieldId : candidateFieldIds) {
                            ObjectNode fieldNode = objectMapper.createObjectNode();
                            fieldNode.put("id", fieldId);
                            candidateUserFieldsNode.add(fieldNode);
                            fillProperty("name", "user-field-info-name-" + fieldId, fieldNode, userTask);
                        }
                    }
                } else {
                    for (String candidateUser : userTask.getCandidateUsers()) {
                        candidateUserIds.add(candidateUser);
                    }
                }
                if (candidateUserIds.size() > 0) {
                    ArrayNode candidateUsersNode = objectMapper.createArrayNode();
                    idmNode.set("candidateUsers", candidateUsersNode);
                    idmNode.put("type", "users");
                    for (String candidateUser : candidateUserIds) {
                        ObjectNode candidateUserNode = objectMapper.createObjectNode();
                        candidateUserNode.put("id", candidateUser);
                        candidateUsersNode.add(candidateUserNode);
                        fillProperty("externalId", "user-info-externalid-" + candidateUser, candidateUserNode, userTask);
                        fillProperty("email", "user-info-email-" + candidateUser, candidateUserNode, userTask);
                        fillProperty("firstName", "user-info-firstname-" + candidateUser, candidateUserNode, userTask);
                        fillProperty("lastName", "user-info-lastname-" + candidateUser, candidateUserNode, userTask);
                    }
                }
            }
            List<ExtensionElement> idmCandidateGroupList = userTask.getExtensionElements().get("activiti-idm-candidate-group");
            if (CollectionUtils.isNotEmpty(userTask.getCandidateGroups()) && CollectionUtils.isNotEmpty(idmCandidateGroupList)) {
                List<String> candidateGroupIds = new ArrayList<String>();
                if (userTask.getCandidateGroups().size() == 1 && userTask.getCandidateGroups().get(0).contains("${taskAssignmentBean.assignTaskToCandidateGroups(")) {
                    idmNode.put("type", "groups");
                    String candidateGroupsString = userTask.getCandidateGroups().get(0);
                    candidateGroupsString = candidateGroupsString.replace("${taskAssignmentBean.assignTaskToCandidateGroups('", "");
                    candidateGroupsString = candidateGroupsString.replace("', execution)}", "");
                    List<String> candidateFieldIds = new ArrayList<String>();
                    String[] candidateGroupArray = candidateGroupsString.split(",");
                    for (String candidate : candidateGroupArray) {
                        if (candidate.contains("field(")) {
                            candidateFieldIds.add(candidate.trim().substring(6, candidate.length() - 1));
                        } else {
                            candidateGroupIds.add(candidate.trim());
                        }
                    }
                    if (candidateFieldIds.size() > 0) {
                        ArrayNode candidateGroupFieldsNode = objectMapper.createArrayNode();
                        idmNode.set("candidateGroupFields", candidateGroupFieldsNode);
                        for (String fieldId : candidateFieldIds) {
                            ObjectNode fieldNode = objectMapper.createObjectNode();
                            fieldNode.put("id", fieldId);
                            candidateGroupFieldsNode.add(fieldNode);
                            fillProperty("name", "group-field-info-name-" + fieldId, fieldNode, userTask);
                        }
                    }
                } else {
                    for (String candidateGroup : userTask.getCandidateGroups()) {
                        candidateGroupIds.add(candidateGroup);
                    }
                }
                if (candidateGroupIds.size() > 0) {
                    ArrayNode candidateGroupsNode = objectMapper.createArrayNode();
                    idmNode.set("candidateGroups", candidateGroupsNode);
                    idmNode.put("type", "groups");
                    for (String candidateGroup : candidateGroupIds) {
                        ObjectNode candidateGroupNode = objectMapper.createObjectNode();
                        candidateGroupNode.put("id", candidateGroup);
                        candidateGroupsNode.add(candidateGroupNode);
                        fillProperty("externalId", "group-info-externalid-" + candidateGroup, candidateGroupNode, userTask);
                        fillProperty("name", "group-info-name-" + candidateGroup, candidateGroupNode, userTask);
                    }
                }
            }
        } else {
            assignmentValuesNode.put("type", "static");
            if (StringUtils.isNotEmpty(assignee)) {
                assignmentValuesNode.put(PROPERTY_USERTASK_ASSIGNEE, assignee);
            }
            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.set(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.set(PROPERTY_USERTASK_CANDIDATE_GROUPS, candidateArrayNode);
            }
        }
        assignmentNode.set("assignment", assignmentValuesNode);
        propertiesNode.set(PROPERTY_USERTASK_ASSIGNMENT, assignmentNode);
    }
    if (userTask.getPriority() != null) {
        setPropertyValue(PROPERTY_USERTASK_PRIORITY, userTask.getPriority().toString(), propertiesNode);
    }
    if (StringUtils.isNotEmpty(userTask.getFormKey())) {
        if (formKeyMap != null && formKeyMap.containsKey(userTask.getFormKey())) {
            ObjectNode formRefNode = objectMapper.createObjectNode();
            ModelInfo modelInfo = formKeyMap.get(userTask.getFormKey());
            formRefNode.put("id", modelInfo.getId());
            formRefNode.put("name", modelInfo.getName());
            formRefNode.put("key", modelInfo.getKey());
            propertiesNode.set(PROPERTY_FORM_REFERENCE, formRefNode);
        } else {
            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 : ModelInfo(org.activiti.editor.language.json.model.ModelInfo) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) UserTask(org.activiti.bpmn.model.UserTask) ExtensionElement(org.activiti.bpmn.model.ExtensionElement) ArrayList(java.util.ArrayList) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode)

Example 2 with ModelInfo

use of org.activiti.editor.language.json.model.ModelInfo in project Activiti by Activiti.

the class ServiceTaskJsonConverter method convertElementToJson.

protected void convertElementToJson(ObjectNode propertiesNode, BaseElement baseElement) {
    ServiceTask serviceTask = (ServiceTask) baseElement;
    if ("mail".equalsIgnoreCase(serviceTask.getType())) {
        setPropertyFieldValue(PROPERTY_MAILTASK_TO, serviceTask, propertiesNode);
        setPropertyFieldValue(PROPERTY_MAILTASK_FROM, serviceTask, propertiesNode);
        setPropertyFieldValue(PROPERTY_MAILTASK_SUBJECT, serviceTask, propertiesNode);
        setPropertyFieldValue(PROPERTY_MAILTASK_CC, serviceTask, propertiesNode);
        setPropertyFieldValue(PROPERTY_MAILTASK_BCC, serviceTask, propertiesNode);
        setPropertyFieldValue(PROPERTY_MAILTASK_TEXT, serviceTask, propertiesNode);
        setPropertyFieldValue(PROPERTY_MAILTASK_HTML, serviceTask, propertiesNode);
        setPropertyFieldValue(PROPERTY_MAILTASK_CHARSET, serviceTask, propertiesNode);
    } else if ("camel".equalsIgnoreCase(serviceTask.getType())) {
        setPropertyFieldValue(PROPERTY_CAMELTASK_CAMELCONTEXT, "camelContext", serviceTask, propertiesNode);
    } else if ("mule".equalsIgnoreCase(serviceTask.getType())) {
        setPropertyFieldValue(PROPERTY_MULETASK_ENDPOINT_URL, "endpointUrl", serviceTask, propertiesNode);
        setPropertyFieldValue(PROPERTY_MULETASK_LANGUAGE, "language", serviceTask, propertiesNode);
        setPropertyFieldValue(PROPERTY_MULETASK_PAYLOAD_EXPRESSION, "payloadExpression", serviceTask, propertiesNode);
        setPropertyFieldValue(PROPERTY_MULETASK_RESULT_VARIABLE, "resultVariable", serviceTask, propertiesNode);
    } else if ("dmn".equalsIgnoreCase(serviceTask.getType())) {
        for (FieldExtension fieldExtension : serviceTask.getFieldExtensions()) {
            if (PROPERTY_DECISIONTABLE_REFERENCE_KEY.equals(fieldExtension.getFieldName()) && decisionTableKeyMap != null && decisionTableKeyMap.containsKey(fieldExtension.getStringValue())) {
                ObjectNode decisionReferenceNode = objectMapper.createObjectNode();
                propertiesNode.set(PROPERTY_DECISIONTABLE_REFERENCE, decisionReferenceNode);
                ModelInfo modelInfo = decisionTableKeyMap.get(fieldExtension.getStringValue());
                decisionReferenceNode.put("id", modelInfo.getId());
                decisionReferenceNode.put("name", modelInfo.getName());
                decisionReferenceNode.put("key", modelInfo.getKey());
            }
        }
    } else {
        if (ImplementationType.IMPLEMENTATION_TYPE_CLASS.equals(serviceTask.getImplementationType())) {
            propertiesNode.put(PROPERTY_SERVICETASK_CLASS, serviceTask.getImplementation());
        } else if (ImplementationType.IMPLEMENTATION_TYPE_EXPRESSION.equals(serviceTask.getImplementationType())) {
            propertiesNode.put(PROPERTY_SERVICETASK_EXPRESSION, serviceTask.getImplementation());
        } else if (ImplementationType.IMPLEMENTATION_TYPE_DELEGATEEXPRESSION.equals(serviceTask.getImplementationType())) {
            propertiesNode.put(PROPERTY_SERVICETASK_DELEGATE_EXPRESSION, serviceTask.getImplementation());
        }
        if (StringUtils.isNotEmpty(serviceTask.getResultVariableName())) {
            propertiesNode.put(PROPERTY_SERVICETASK_RESULT_VARIABLE, serviceTask.getResultVariableName());
        }
        addFieldExtensions(serviceTask.getFieldExtensions(), propertiesNode);
    }
}
Also used : ServiceTask(org.activiti.bpmn.model.ServiceTask) ModelInfo(org.activiti.editor.language.json.model.ModelInfo) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) FieldExtension(org.activiti.bpmn.model.FieldExtension)

Example 3 with ModelInfo

use of org.activiti.editor.language.json.model.ModelInfo in project Activiti by Activiti.

the class StartEventJsonConverter method convertElementToJson.

protected void convertElementToJson(ObjectNode propertiesNode, BaseElement baseElement) {
    StartEvent startEvent = (StartEvent) baseElement;
    if (StringUtils.isNotEmpty(startEvent.getInitiator())) {
        propertiesNode.put(PROPERTY_NONE_STARTEVENT_INITIATOR, startEvent.getInitiator());
    }
    if (StringUtils.isNotEmpty(startEvent.getFormKey())) {
        if (formKeyMap != null && formKeyMap.containsKey(startEvent.getFormKey())) {
            ObjectNode formRefNode = objectMapper.createObjectNode();
            ModelInfo modelInfo = formKeyMap.get(startEvent.getFormKey());
            formRefNode.put("id", modelInfo.getId());
            formRefNode.put("name", modelInfo.getName());
            formRefNode.put("key", modelInfo.getKey());
            propertiesNode.set(PROPERTY_FORM_REFERENCE, formRefNode);
        } else {
            setPropertyValue(PROPERTY_FORMKEY, startEvent.getFormKey(), propertiesNode);
        }
    }
    addFormProperties(startEvent.getFormProperties(), propertiesNode);
    addEventProperties(startEvent, propertiesNode);
}
Also used : ModelInfo(org.activiti.editor.language.json.model.ModelInfo) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) StartEvent(org.activiti.bpmn.model.StartEvent)

Aggregations

ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)3 ModelInfo (org.activiti.editor.language.json.model.ModelInfo)3 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)1 ArrayList (java.util.ArrayList)1 ExtensionElement (org.activiti.bpmn.model.ExtensionElement)1 FieldExtension (org.activiti.bpmn.model.FieldExtension)1 ServiceTask (org.activiti.bpmn.model.ServiceTask)1 StartEvent (org.activiti.bpmn.model.StartEvent)1 UserTask (org.activiti.bpmn.model.UserTask)1