Search in sources :

Example 66 with ObjectNode

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.node.ObjectNode in project Activiti by Activiti.

the class DemoDataConfiguration method createModelData.

protected void createModelData(String name, String description, String jsonFile) {
    List<Model> modelList = repositoryService.createModelQuery().modelName("Demo model").list();
    if (modelList == null || modelList.isEmpty()) {
        Model model = repositoryService.newModel();
        model.setName(name);
        ObjectNode modelObjectNode = new ObjectMapper().createObjectNode();
        modelObjectNode.put("name", name);
        modelObjectNode.put("description", description);
        model.setMetaInfo(modelObjectNode.toString());
        repositoryService.saveModel(model);
        try {
            InputStream svgStream = this.getClass().getClassLoader().getResourceAsStream("org/activiti/rest/demo/model/test.svg");
            repositoryService.addModelEditorSourceExtra(model.getId(), IOUtils.toByteArray(svgStream));
        } catch (Exception e) {
            LOGGER.warn("Failed to read SVG", e);
        }
        try {
            InputStream editorJsonStream = this.getClass().getClassLoader().getResourceAsStream(jsonFile);
            repositoryService.addModelEditorSource(model.getId(), IOUtils.toByteArray(editorJsonStream));
        } catch (Exception e) {
            LOGGER.warn("Failed to read editor JSON", e);
        }
    }
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) InputStream(java.io.InputStream) Model(org.activiti.engine.repository.Model) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 67 with ObjectNode

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.node.ObjectNode in project Activiti by Activiti.

the class UelExpressionCondition method evaluate.

public boolean evaluate(String sequenceFlowId, DelegateExecution execution) {
    String conditionExpression = null;
    if (Context.getProcessEngineConfiguration().isEnableProcessDefinitionInfoCache()) {
        ObjectNode elementProperties = Context.getBpmnOverrideElementProperties(sequenceFlowId, execution.getProcessDefinitionId());
        conditionExpression = getActiveValue(initialConditionExpression, DynamicBpmnConstants.SEQUENCE_FLOW_CONDITION, elementProperties);
    } else {
        conditionExpression = initialConditionExpression;
    }
    Expression expression = Context.getProcessEngineConfiguration().getExpressionManager().createExpression(conditionExpression);
    Object result = expression.getValue(execution);
    if (result == null) {
        throw new ActivitiException("condition expression returns null");
    }
    if (!(result instanceof Boolean)) {
        throw new ActivitiException("condition expression returns non-Boolean: " + result + " (" + result.getClass().getName() + ")");
    }
    return (Boolean) result;
}
Also used : ActivitiException(org.activiti.engine.ActivitiException) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) Expression(org.activiti.engine.delegate.Expression)

Example 68 with ObjectNode

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.node.ObjectNode in project Activiti by Activiti.

the class ImportUploadReceiver method deployUploadedFile.

protected void deployUploadedFile() {
    try {
        try {
            if (fileName.endsWith(".bpmn20.xml") || fileName.endsWith(".bpmn")) {
                validFile = true;
                XMLInputFactory xif = XmlUtil.createSafeXmlInputFactory();
                InputStreamReader in = new InputStreamReader(new ByteArrayInputStream(outputStream.toByteArray()), "UTF-8");
                XMLStreamReader xtr = xif.createXMLStreamReader(in);
                BpmnModel bpmnModel = new BpmnXMLConverter().convertToBpmnModel(xtr);
                if (bpmnModel.getMainProcess() == null || bpmnModel.getMainProcess().getId() == null) {
                    notificationManager.showErrorNotification(Messages.MODEL_IMPORT_FAILED, i18nManager.getMessage(Messages.MODEL_IMPORT_INVALID_BPMN_EXPLANATION));
                } else {
                    if (bpmnModel.getLocationMap().isEmpty()) {
                        notificationManager.showErrorNotification(Messages.MODEL_IMPORT_INVALID_BPMNDI, i18nManager.getMessage(Messages.MODEL_IMPORT_INVALID_BPMNDI_EXPLANATION));
                    } else {
                        String processName = null;
                        if (StringUtils.isNotEmpty(bpmnModel.getMainProcess().getName())) {
                            processName = bpmnModel.getMainProcess().getName();
                        } else {
                            processName = bpmnModel.getMainProcess().getId();
                        }
                        modelData = repositoryService.newModel();
                        ObjectNode modelObjectNode = new ObjectMapper().createObjectNode();
                        modelObjectNode.put(MODEL_NAME, processName);
                        modelObjectNode.put(MODEL_REVISION, 1);
                        modelData.setMetaInfo(modelObjectNode.toString());
                        modelData.setName(processName);
                        repositoryService.saveModel(modelData);
                        BpmnJsonConverter jsonConverter = new BpmnJsonConverter();
                        ObjectNode editorNode = jsonConverter.convertToJson(bpmnModel);
                        repositoryService.addModelEditorSource(modelData.getId(), editorNode.toString().getBytes("utf-8"));
                    }
                }
            } else {
                notificationManager.showErrorNotification(Messages.MODEL_IMPORT_INVALID_FILE, i18nManager.getMessage(Messages.MODEL_IMPORT_INVALID_FILE_EXPLANATION));
            }
        } catch (Exception e) {
            String errorMsg = e.getMessage().replace(System.getProperty("line.separator"), "<br/>");
            notificationManager.showErrorNotification(Messages.MODEL_IMPORT_FAILED, errorMsg);
        }
    } finally {
        if (outputStream != null) {
            try {
                outputStream.close();
            } catch (IOException e) {
                notificationManager.showErrorNotification("Server-side error", e.getMessage());
            }
        }
    }
}
Also used : XMLStreamReader(javax.xml.stream.XMLStreamReader) InputStreamReader(java.io.InputStreamReader) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) ByteArrayInputStream(java.io.ByteArrayInputStream) IOException(java.io.IOException) BpmnJsonConverter(org.activiti.editor.language.json.converter.BpmnJsonConverter) XMLInputFactory(javax.xml.stream.XMLInputFactory) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) IOException(java.io.IOException) BpmnModel(org.activiti.bpmn.model.BpmnModel) BpmnXMLConverter(org.activiti.bpmn.converter.BpmnXMLConverter)

Example 69 with ObjectNode

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.node.ObjectNode in project Activiti by Activiti.

the class CopyModelPopupWindow method addButtons.

protected void addButtons() {
    // Cancel
    Button cancelButton = new Button(i18nManager.getMessage(Messages.BUTTON_CANCEL));
    cancelButton.addStyleName(Reindeer.BUTTON_SMALL);
    cancelButton.addListener(new ClickListener() {

        private static final long serialVersionUID = 1L;

        public void buttonClick(ClickEvent event) {
            close();
        }
    });
    // Create
    Button createButton = new Button(i18nManager.getMessage(Messages.PROCESS_NEW_POPUP_CREATE_BUTTON));
    createButton.addStyleName(Reindeer.BUTTON_SMALL);
    createButton.addListener(new ClickListener() {

        private static final long serialVersionUID = 1L;

        public void buttonClick(ClickEvent event) {
            if (StringUtils.isEmpty((String) nameTextField.getValue())) {
                form.setComponentError(new UserError("The name field is required."));
                return;
            }
            Model newModelData = repositoryService.newModel();
            ObjectNode modelObjectNode = new ObjectMapper().createObjectNode();
            modelObjectNode.put(MODEL_NAME, (String) nameTextField.getValue());
            String description = null;
            if (StringUtils.isNotEmpty((String) descriptionTextArea.getValue())) {
                description = (String) descriptionTextArea.getValue();
            } else {
                description = "";
            }
            modelObjectNode.put(MODEL_DESCRIPTION, description);
            newModelData.setMetaInfo(modelObjectNode.toString());
            newModelData.setName((String) nameTextField.getValue());
            repositoryService.saveModel(newModelData);
            repositoryService.addModelEditorSource(newModelData.getId(), repositoryService.getModelEditorSource(modelData.getId()));
            repositoryService.addModelEditorSourceExtra(newModelData.getId(), repositoryService.getModelEditorSourceExtra(modelData.getId()));
            close();
            ExplorerApp.get().getViewManager().showEditorProcessDefinitionPage(newModelData.getId());
        }
    });
    // Alignment
    HorizontalLayout buttonLayout = new HorizontalLayout();
    buttonLayout.setSpacing(true);
    buttonLayout.addComponent(cancelButton);
    buttonLayout.addComponent(createButton);
    addComponent(buttonLayout);
    windowLayout.setComponentAlignment(buttonLayout, Alignment.BOTTOM_RIGHT);
}
Also used : UserError(com.vaadin.terminal.UserError) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) Button(com.vaadin.ui.Button) ClickEvent(com.vaadin.ui.Button.ClickEvent) Model(org.activiti.engine.repository.Model) ClickListener(com.vaadin.ui.Button.ClickListener) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) HorizontalLayout(com.vaadin.ui.HorizontalLayout)

Example 70 with ObjectNode

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.node.ObjectNode in project Activiti by Activiti.

the class EditorProcessDefinitionDetailPanel method deployModel.

protected void deployModel() {
    try {
        if (SimpleTableEditorConstants.TABLE_EDITOR_CATEGORY.equals(modelData.getCategory())) {
            deploySimpleTableEditorModel(repositoryService.getModelEditorSource(modelData.getId()));
        } else {
            final ObjectNode modelNode = (ObjectNode) new ObjectMapper().readTree(repositoryService.getModelEditorSource(modelData.getId()));
            deployModelerModel(modelNode);
        }
    } catch (Exception e) {
        LOGGER.error("Failed to deploy model", e);
        ExplorerApp.get().getNotificationManager().showErrorNotification(Messages.PROCESS_TOXML_FAILED, e);
    }
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Aggregations

ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)2446 JsonNode (com.fasterxml.jackson.databind.JsonNode)556 Test (org.junit.Test)556 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)509 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)370 IOException (java.io.IOException)214 ArrayList (java.util.ArrayList)119 HashMap (java.util.HashMap)107 Map (java.util.Map)106 List (java.util.List)96 StringEntity (org.apache.http.entity.StringEntity)94 Deployment (org.activiti.engine.test.Deployment)85 Test (org.testng.annotations.Test)81 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)69 ProcessInstance (org.activiti.engine.runtime.ProcessInstance)65 HttpPost (org.apache.http.client.methods.HttpPost)57 AbstractRpcLwM2MIntegrationTest (org.thingsboard.server.transport.lwm2m.rpc.AbstractRpcLwM2MIntegrationTest)54 TextNode (com.fasterxml.jackson.databind.node.TextNode)52 File (java.io.File)51 Task (org.activiti.engine.task.Task)51