Search in sources :

Example 46 with JsonNode

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.JsonNode in project jackson-databind by FasterXML.

the class ArrayNode method serialize.

/*
    /**********************************************************
    /* Public API, serialization
    /**********************************************************
     */
@Override
public void serialize(JsonGenerator f, SerializerProvider provider) throws IOException {
    final List<JsonNode> c = _children;
    final int size = c.size();
    f.writeStartArray(size);
    for (int i = 0; i < size; ++i) {
        // we'll typically have array list
        // For now, assuming it's either BaseJsonNode, JsonSerializable
        JsonNode n = c.get(i);
        if (n instanceof BaseJsonNode) {
            ((BaseJsonNode) n).serialize(f, provider);
        } else {
            ((JsonSerializable) n).serialize(f, provider);
        }
    }
    f.writeEndArray();
}
Also used : JsonSerializable(com.fasterxml.jackson.databind.JsonSerializable) JsonNode(com.fasterxml.jackson.databind.JsonNode)

Example 47 with JsonNode

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.JsonNode in project jackson-databind by FasterXML.

the class TestNullNode method testNullHandling.

public void testNullHandling() throws Exception {
    // First, a stand-alone null
    JsonNode n = objectReader().readTree("null");
    assertNotNull(n);
    assertTrue(n.isNull());
    assertFalse(n.isNumber());
    assertFalse(n.isTextual());
    assertEquals("null", n.asText());
    assertEquals(n, NullNode.instance);
    n = objectMapper().readTree("null");
    assertNotNull(n);
    assertTrue(n.isNull());
    // Then object property
    ObjectNode root = (ObjectNode) objectReader().readTree("{\"x\":null}");
    assertEquals(1, root.size());
    n = root.get("x");
    assertNotNull(n);
    assertTrue(n.isNull());
}
Also used : JsonNode(com.fasterxml.jackson.databind.JsonNode)

Example 48 with JsonNode

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.JsonNode in project series-rest-api by 52North.

the class IoParameters method createFromQuery.

public static IoParameters createFromQuery(RequestParameterSet parameters, File defaultConfig) {
    Map<String, JsonNode> queryParameters = new HashMap<>();
    for (String parameter : parameters.availableParameterNames()) {
        JsonNode value = parameters.getParameterValue(parameter);
        queryParameters.put(parameter.toLowerCase(), value);
    }
    return new IoParameters(queryParameters, defaultConfig);
}
Also used : HashMap(java.util.HashMap) JsonNode(com.fasterxml.jackson.databind.JsonNode)

Example 49 with JsonNode

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

the class BpmnJsonConverter method convertToBpmnModel.

public BpmnModel convertToBpmnModel(JsonNode modelNode) {
    BpmnModel bpmnModel = new BpmnModel();
    bpmnModel.setTargetNamespace("http://activiti.org/test");
    Map<String, JsonNode> shapeMap = new HashMap<String, JsonNode>();
    Map<String, JsonNode> sourceRefMap = new HashMap<String, JsonNode>();
    Map<String, JsonNode> edgeMap = new HashMap<String, JsonNode>();
    Map<String, List<JsonNode>> sourceAndTargetMap = new HashMap<String, List<JsonNode>>();
    readShapeDI(modelNode, 0, 0, shapeMap, sourceRefMap, bpmnModel);
    filterAllEdges(modelNode, edgeMap, sourceAndTargetMap, shapeMap, sourceRefMap);
    readEdgeDI(edgeMap, sourceAndTargetMap, bpmnModel);
    ArrayNode shapesArrayNode = (ArrayNode) modelNode.get(EDITOR_CHILD_SHAPES);
    if (shapesArrayNode == null || shapesArrayNode.size() == 0)
        return bpmnModel;
    boolean nonEmptyPoolFound = false;
    Map<String, Lane> elementInLaneMap = new HashMap<String, Lane>();
    // first create the pool structure
    for (JsonNode shapeNode : shapesArrayNode) {
        String stencilId = BpmnJsonConverterUtil.getStencilId(shapeNode);
        if (STENCIL_POOL.equals(stencilId)) {
            Pool pool = new Pool();
            pool.setId(BpmnJsonConverterUtil.getElementId(shapeNode));
            pool.setName(JsonConverterUtil.getPropertyValueAsString(PROPERTY_NAME, shapeNode));
            pool.setProcessRef(JsonConverterUtil.getPropertyValueAsString(PROPERTY_PROCESS_ID, shapeNode));
            pool.setExecutable(JsonConverterUtil.getPropertyValueAsBoolean(PROPERTY_PROCESS_EXECUTABLE, shapeNode, true));
            bpmnModel.getPools().add(pool);
            Process process = new Process();
            process.setId(pool.getProcessRef());
            process.setName(pool.getName());
            process.setExecutable(pool.isExecutable());
            bpmnModel.addProcess(process);
            ArrayNode laneArrayNode = (ArrayNode) shapeNode.get(EDITOR_CHILD_SHAPES);
            for (JsonNode laneNode : laneArrayNode) {
                // should be a lane, but just check to be certain
                String laneStencilId = BpmnJsonConverterUtil.getStencilId(laneNode);
                if (STENCIL_LANE.equals(laneStencilId)) {
                    nonEmptyPoolFound = true;
                    Lane lane = new Lane();
                    lane.setId(BpmnJsonConverterUtil.getElementId(laneNode));
                    lane.setName(JsonConverterUtil.getPropertyValueAsString(PROPERTY_NAME, laneNode));
                    lane.setParentProcess(process);
                    process.getLanes().add(lane);
                    processJsonElements(laneNode.get(EDITOR_CHILD_SHAPES), modelNode, lane, shapeMap, bpmnModel);
                    if (CollectionUtils.isNotEmpty(lane.getFlowReferences())) {
                        for (String elementRef : lane.getFlowReferences()) {
                            elementInLaneMap.put(elementRef, lane);
                        }
                    }
                }
            }
        }
    }
    // Signal Definitions exist on the root level
    JsonNode signalDefinitionNode = BpmnJsonConverterUtil.getProperty(PROPERTY_SIGNAL_DEFINITIONS, modelNode);
    signalDefinitionNode = BpmnJsonConverterUtil.validateIfNodeIsTextual(signalDefinitionNode);
    // no idea why this needs to be done twice ..
    signalDefinitionNode = BpmnJsonConverterUtil.validateIfNodeIsTextual(signalDefinitionNode);
    if (signalDefinitionNode != null) {
        if (signalDefinitionNode instanceof ArrayNode) {
            ArrayNode signalDefinitionArrayNode = (ArrayNode) signalDefinitionNode;
            Iterator<JsonNode> signalDefinitionIterator = signalDefinitionArrayNode.iterator();
            while (signalDefinitionIterator.hasNext()) {
                JsonNode signalDefinitionJsonNode = signalDefinitionIterator.next();
                String signalId = signalDefinitionJsonNode.get(PROPERTY_SIGNAL_DEFINITION_ID).asText();
                String signalName = signalDefinitionJsonNode.get(PROPERTY_SIGNAL_DEFINITION_NAME).asText();
                String signalScope = signalDefinitionJsonNode.get(PROPERTY_SIGNAL_DEFINITION_SCOPE).asText();
                Signal signal = new Signal();
                signal.setId(signalId);
                signal.setName(signalName);
                signal.setScope((signalScope.toLowerCase().equals("processinstance")) ? Signal.SCOPE_PROCESS_INSTANCE : Signal.SCOPE_GLOBAL);
                bpmnModel.addSignal(signal);
            }
        }
    }
    if (nonEmptyPoolFound == false) {
        Process process = new Process();
        bpmnModel.getProcesses().add(process);
        process.setId(BpmnJsonConverterUtil.getPropertyValueAsString(PROPERTY_PROCESS_ID, modelNode));
        process.setName(BpmnJsonConverterUtil.getPropertyValueAsString(PROPERTY_NAME, modelNode));
        String namespace = BpmnJsonConverterUtil.getPropertyValueAsString(PROPERTY_PROCESS_NAMESPACE, modelNode);
        if (StringUtils.isNotEmpty(namespace)) {
            bpmnModel.setTargetNamespace(namespace);
        }
        process.setDocumentation(BpmnJsonConverterUtil.getPropertyValueAsString(PROPERTY_DOCUMENTATION, modelNode));
        JsonNode processExecutableNode = JsonConverterUtil.getProperty(PROPERTY_PROCESS_EXECUTABLE, modelNode);
        if (processExecutableNode != null && StringUtils.isNotEmpty(processExecutableNode.asText())) {
            process.setExecutable(JsonConverterUtil.getPropertyValueAsBoolean(PROPERTY_PROCESS_EXECUTABLE, modelNode));
        }
        BpmnJsonConverterUtil.convertJsonToMessages(modelNode, bpmnModel);
        BpmnJsonConverterUtil.convertJsonToListeners(modelNode, process);
        JsonNode eventListenersNode = BpmnJsonConverterUtil.getProperty(PROPERTY_EVENT_LISTENERS, modelNode);
        if (eventListenersNode != null) {
            eventListenersNode = BpmnJsonConverterUtil.validateIfNodeIsTextual(eventListenersNode);
            BpmnJsonConverterUtil.parseEventListeners(eventListenersNode.get(PROPERTY_EVENTLISTENER_VALUE), process);
        }
        JsonNode processDataPropertiesNode = modelNode.get(EDITOR_SHAPE_PROPERTIES).get(PROPERTY_DATA_PROPERTIES);
        if (processDataPropertiesNode != null) {
            List<ValuedDataObject> dataObjects = BpmnJsonConverterUtil.convertJsonToDataProperties(processDataPropertiesNode, process);
            process.setDataObjects(dataObjects);
            process.getFlowElements().addAll(dataObjects);
        }
        processJsonElements(shapesArrayNode, modelNode, process, shapeMap, bpmnModel);
    } else {
        // sequence flows are on root level so need additional parsing for pools
        for (JsonNode shapeNode : shapesArrayNode) {
            if (STENCIL_SEQUENCE_FLOW.equalsIgnoreCase(BpmnJsonConverterUtil.getStencilId(shapeNode)) || STENCIL_ASSOCIATION.equalsIgnoreCase(BpmnJsonConverterUtil.getStencilId(shapeNode))) {
                String sourceRef = BpmnJsonConverterUtil.lookForSourceRef(shapeNode.get(EDITOR_SHAPE_ID).asText(), modelNode.get(EDITOR_CHILD_SHAPES));
                if (sourceRef != null) {
                    Lane lane = elementInLaneMap.get(sourceRef);
                    SequenceFlowJsonConverter flowConverter = new SequenceFlowJsonConverter();
                    if (lane != null) {
                        flowConverter.convertToBpmnModel(shapeNode, modelNode, this, lane, shapeMap, bpmnModel);
                    } else {
                        flowConverter.convertToBpmnModel(shapeNode, modelNode, this, bpmnModel.getProcesses().get(0), shapeMap, bpmnModel);
                    }
                }
            }
        }
    }
    // sequence flows are now all on root level
    Map<String, SubProcess> subShapesMap = new HashMap<String, SubProcess>();
    for (Process process : bpmnModel.getProcesses()) {
        for (FlowElement flowElement : process.findFlowElementsOfType(SubProcess.class)) {
            SubProcess subProcess = (SubProcess) flowElement;
            fillSubShapes(subShapesMap, subProcess);
        }
        if (subShapesMap.size() > 0) {
            List<String> removeSubFlowsList = new ArrayList<String>();
            for (FlowElement flowElement : process.findFlowElementsOfType(SequenceFlow.class)) {
                SequenceFlow sequenceFlow = (SequenceFlow) flowElement;
                if (subShapesMap.containsKey(sequenceFlow.getSourceRef())) {
                    SubProcess subProcess = subShapesMap.get(sequenceFlow.getSourceRef());
                    if (subProcess.getFlowElement(sequenceFlow.getId()) == null) {
                        subProcess.addFlowElement(sequenceFlow);
                        removeSubFlowsList.add(sequenceFlow.getId());
                    }
                }
            }
            for (String flowId : removeSubFlowsList) {
                process.removeFlowElement(flowId);
            }
        }
    }
    Map<String, FlowWithContainer> allFlowMap = new HashMap<String, FlowWithContainer>();
    List<Gateway> gatewayWithOrderList = new ArrayList<Gateway>();
    // post handling of process elements
    for (Process process : bpmnModel.getProcesses()) {
        postProcessElements(process, process.getFlowElements(), edgeMap, bpmnModel, allFlowMap, gatewayWithOrderList);
    }
    // sort the sequence flows
    for (Gateway gateway : gatewayWithOrderList) {
        List<ExtensionElement> orderList = gateway.getExtensionElements().get("EDITOR_FLOW_ORDER");
        if (CollectionUtils.isNotEmpty(orderList)) {
            for (ExtensionElement orderElement : orderList) {
                String flowValue = orderElement.getElementText();
                if (StringUtils.isNotEmpty(flowValue)) {
                    if (allFlowMap.containsKey(flowValue)) {
                        FlowWithContainer flowWithContainer = allFlowMap.get(flowValue);
                        flowWithContainer.getFlowContainer().removeFlowElement(flowWithContainer.getSequenceFlow().getId());
                        flowWithContainer.getFlowContainer().addFlowElement(flowWithContainer.getSequenceFlow());
                    }
                }
            }
        }
        gateway.getExtensionElements().remove("EDITOR_FLOW_ORDER");
    }
    return bpmnModel;
}
Also used : ValuedDataObject(org.activiti.bpmn.model.ValuedDataObject) HashMap(java.util.HashMap) SequenceFlow(org.activiti.bpmn.model.SequenceFlow) ArrayList(java.util.ArrayList) ExtensionElement(org.activiti.bpmn.model.ExtensionElement) JsonNode(com.fasterxml.jackson.databind.JsonNode) Process(org.activiti.bpmn.model.Process) SubProcess(org.activiti.bpmn.model.SubProcess) BpmnModel(org.activiti.bpmn.model.BpmnModel) Signal(org.activiti.bpmn.model.Signal) Gateway(org.activiti.bpmn.model.Gateway) ArrayList(java.util.ArrayList) List(java.util.List) Pool(org.activiti.bpmn.model.Pool) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) SubProcess(org.activiti.bpmn.model.SubProcess) Lane(org.activiti.bpmn.model.Lane) FlowElement(org.activiti.bpmn.model.FlowElement)

Example 50 with JsonNode

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

the class BpmnJsonConverter method processJsonElements.

public void processJsonElements(JsonNode shapesArrayNode, JsonNode modelNode, BaseElement parentElement, Map<String, JsonNode> shapeMap, BpmnModel bpmnModel) {
    for (JsonNode shapeNode : shapesArrayNode) {
        String stencilId = BpmnJsonConverterUtil.getStencilId(shapeNode);
        Class<? extends BaseBpmnJsonConverter> converter = convertersToBpmnMap.get(stencilId);
        try {
            BaseBpmnJsonConverter converterInstance = converter.newInstance();
            converterInstance.convertToBpmnModel(shapeNode, modelNode, this, parentElement, shapeMap, bpmnModel);
        } catch (Exception e) {
            LOGGER.error("Error converting {}", BpmnJsonConverterUtil.getStencilId(shapeNode), e);
        }
    }
}
Also used : JsonNode(com.fasterxml.jackson.databind.JsonNode)

Aggregations

JsonNode (com.fasterxml.jackson.databind.JsonNode)4090 Test (org.junit.Test)1257 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)802 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)544 IOException (java.io.IOException)532 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)384 ArrayList (java.util.ArrayList)315 Test (org.junit.jupiter.api.Test)276 HashMap (java.util.HashMap)249 Map (java.util.Map)201 DefaultSerializerProvider (com.fasterxml.jackson.databind.ser.DefaultSerializerProvider)174 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)127 List (java.util.List)122 InputStream (java.io.InputStream)116 KernelTest (com.twosigma.beakerx.KernelTest)114 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)84 Response (javax.ws.rs.core.Response)79 File (java.io.File)78 HttpGet (org.apache.http.client.methods.HttpGet)75 ByteArrayInputStream (java.io.ByteArrayInputStream)70