Search in sources :

Example 56 with TextNode

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.node.TextNode in project drools by kiegroup.

the class DMNFeelExpressionEvaluatorTest method expressionMapTest.

@Test
public void expressionMapTest() {
    String expressionCollectionJsonString = new TextNode("{ x : 5, y : 3 }").toString();
    Map<String, BigDecimal> result = (Map<String, BigDecimal>) expressionEvaluator.convertResult(expressionCollectionJsonString, Map.class.getCanonicalName(), Collections.EMPTY_LIST);
    assertEquals(2, result.size());
    assertEquals(BigDecimal.valueOf(5), result.get("x"));
    assertEquals(BigDecimal.valueOf(3), result.get("y"));
}
Also used : TextNode(com.fasterxml.jackson.databind.node.TextNode) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) BigDecimal(java.math.BigDecimal) Test(org.junit.Test)

Example 57 with TextNode

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

the class JSONSchemaUtil method getSchemaType.

public static JsonNode getSchemaType(boolean wrapped, String... types) {
    JsonNode typesNode;
    if (types.length == 1) {
        typesNode = new TextNode(types[0]);
    } else {
        ArrayNode arrNode = ValueUtil.JSON.createArrayNode();
        Arrays.stream(types).forEach(arrNode::add);
        typesNode = arrNode;
    }
    return wrapped ? ValueUtil.JSON.createObjectNode().set("type", typesNode) : typesNode;
}
Also used : JsonNode(com.fasterxml.jackson.databind.JsonNode) TextNode(com.fasterxml.jackson.databind.node.TextNode) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode)

Example 58 with TextNode

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.node.TextNode in project autorest-clientruntime-for-java by Azure.

the class ValidatorTests method validateRecursive.

@Test
public void validateRecursive() throws Exception {
    TextNode textNode = new TextNode("\"\"");
    Validator.validate(textNode);
}
Also used : TextNode(com.fasterxml.jackson.databind.node.TextNode) Test(org.junit.Test)

Example 59 with TextNode

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

the class EdgeBulkImportService method setEntityFields.

@Override
protected void setEntityFields(Edge entity, Map<BulkImportColumnType, String> fields) {
    ObjectNode additionalInfo = (ObjectNode) Optional.ofNullable(entity.getAdditionalInfo()).orElseGet(JacksonUtil::newObjectNode);
    fields.forEach((columnType, value) -> {
        switch(columnType) {
            case NAME:
                entity.setName(value);
                break;
            case TYPE:
                entity.setType(value);
                break;
            case LABEL:
                entity.setLabel(value);
                break;
            case DESCRIPTION:
                additionalInfo.set("description", new TextNode(value));
                break;
            case ROUTING_KEY:
                entity.setRoutingKey(value);
                break;
            case SECRET:
                entity.setSecret(value);
                break;
        }
    });
    entity.setAdditionalInfo(additionalInfo);
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) TextNode(com.fasterxml.jackson.databind.node.TextNode)

Example 60 with TextNode

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.node.TextNode in project walkmod-core by walkmod.

the class AddTransformationYMLAction method doAction.

@Override
public void doAction(JsonNode chainsNode) throws Exception {
    ArrayNode transformationsNode = null;
    boolean isMultiModule = chainsNode.has("modules");
    ObjectMapper mapper = provider.getObjectMapper();
    if (!isMultiModule) {
        boolean validChainName = chain != null && !"".equals(chain) && !"default".equals(chain);
        if (!chainsNode.has("chains")) {
            if (chainsNode.has("transformations")) {
                JsonNode aux = chainsNode.get("transformations");
                if (aux.isArray()) {
                    transformationsNode = (ArrayNode) aux;
                }
                if (!validChainName) {
                    ObjectNode auxRoot = (ObjectNode) chainsNode;
                    if (transformationsNode == null) {
                        transformationsNode = new ArrayNode(mapper.getNodeFactory());
                    }
                    auxRoot.set("transformations", transformationsNode);
                } else {
                    // reset the root
                    chainsNode = new ObjectNode(mapper.getNodeFactory());
                    ObjectNode auxRoot = (ObjectNode) chainsNode;
                    // the default chain list added
                    ObjectNode chainObject = new ObjectNode(mapper.getNodeFactory());
                    chainObject.set("name", new TextNode("default"));
                    chainObject.set("transformations", transformationsNode);
                    ArrayNode chainsListNode = new ArrayNode(mapper.getNodeFactory());
                    // the requested chain added
                    ObjectNode newChain = new ObjectNode(mapper.getNodeFactory());
                    newChain.set("name", new TextNode(chain));
                    if (path != null && !"".equals(path.trim())) {
                        ObjectNode readerNode = new ObjectNode(mapper.getNodeFactory());
                        newChain.set("reader", readerNode);
                        populateWriterReader(readerNode, path, null, null, null, null);
                        ObjectNode writerNode = new ObjectNode(mapper.getNodeFactory());
                        newChain.set("writer", writerNode);
                        populateWriterReader(writerNode, path, null, null, null, null);
                    }
                    transformationsNode = new ArrayNode(mapper.getNodeFactory());
                    newChain.set("transformations", transformationsNode);
                    if (before == null || !"default".equals(before)) {
                        chainsListNode.add(chainObject);
                    }
                    chainsListNode.add(newChain);
                    if (before != null && "default".equals(before)) {
                        chainsListNode.add(chainObject);
                    }
                    auxRoot.set("chains", chainsListNode);
                }
            } else {
                ObjectNode auxRoot = (ObjectNode) chainsNode;
                transformationsNode = new ArrayNode(mapper.getNodeFactory());
                boolean writeChainInfo = validChainName;
                if (!writeChainInfo) {
                    writeChainInfo = path != null && !"".equals(path.trim());
                    chain = "default";
                }
                if (writeChainInfo) {
                    ArrayNode auxChainsList = new ArrayNode(mapper.getNodeFactory());
                    ObjectNode aux = new ObjectNode(mapper.getNodeFactory());
                    auxChainsList.add(aux);
                    aux.set("name", new TextNode(chain));
                    if (path != null && !"".equals(path.trim())) {
                        ObjectNode readerNode = new ObjectNode(mapper.getNodeFactory());
                        aux.set("reader", readerNode);
                        populateWriterReader(readerNode, path, null, null, null, null);
                    }
                    auxRoot.set("chains", auxChainsList);
                    if (path != null && !"".equals(path.trim())) {
                        ObjectNode writerNode = new ObjectNode(mapper.getNodeFactory());
                        aux.set("writer", writerNode);
                        populateWriterReader(writerNode, path, null, null, null, null);
                    }
                    auxRoot = aux;
                }
                auxRoot.set("transformations", transformationsNode);
            }
        } else {
            if (validChainName) {
                JsonNode aux = chainsNode.get("chains");
                boolean found = false;
                if (aux.isArray()) {
                    Iterator<JsonNode> it = aux.elements();
                    while (it.hasNext()) {
                        JsonNode next = it.next();
                        if (next.has("name")) {
                            String id = next.get("name").asText();
                            if (chain.equals(id)) {
                                found = true;
                                if (next.has("transformations")) {
                                    JsonNode auxTrans = next.get("transformations");
                                    if (auxTrans.isArray()) {
                                        transformationsNode = (ArrayNode) auxTrans;
                                    } else {
                                        throw new Exception("The chain [" + chain + "] does not have a valid transformations node");
                                    }
                                } else if (next.isObject()) {
                                    ObjectNode auxNext = (ObjectNode) next;
                                    transformationsNode = new ArrayNode(mapper.getNodeFactory());
                                    auxNext.set("transformations", transformationsNode);
                                } else {
                                    throw new Exception("The chain [" + chain + "] does not have a valid structure");
                                }
                            }
                        }
                    }
                    if (!found) {
                        ChainConfig chainCfg = new ChainConfigImpl();
                        chainCfg.setName(chain);
                        WalkerConfig walkerCfg = new WalkerConfigImpl();
                        List<TransformationConfig> transfs = new LinkedList<TransformationConfig>();
                        transfs.add(transformationCfg);
                        walkerCfg.setTransformations(transfs);
                        chainCfg.setWalkerConfig(walkerCfg);
                        provider.addChainConfig(chainCfg, false, before);
                        return;
                    }
                }
            } else {
                ObjectNode node = new ObjectNode(mapper.getNodeFactory());
                node.set("name", new TextNode(chain));
                ArrayNode transNodes = new ArrayNode(mapper.getNodeFactory());
                node.set("transformations", transNodes);
                ArrayNode array = (ArrayNode) chainsNode.get("chains");
                array.add(node);
                ObjectNode transformationNode = new ObjectNode(mapper.getNodeFactory());
                transNodes.add(transformationNode);
                createTransformation(transformationNode, transformationCfg);
                return;
            }
        }
        if (transformationsNode != null) {
            ObjectNode transformationNode = new ObjectNode(mapper.getNodeFactory());
            if (order != null && order < transformationsNode.size()) {
                transformationsNode.insert(order, transformationNode);
            } else {
                transformationsNode.add(transformationNode);
            }
            createTransformation(transformationNode, transformationCfg);
            provider.write(chainsNode);
            return;
        } else if (chain != null) {
            throw new Exception("The chain [" + chain + "] does not exists");
        }
    }
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) WalkerConfig(org.walkmod.conf.entities.WalkerConfig) TransformationConfig(org.walkmod.conf.entities.TransformationConfig) ChainConfigImpl(org.walkmod.conf.entities.impl.ChainConfigImpl) JsonNode(com.fasterxml.jackson.databind.JsonNode) TextNode(com.fasterxml.jackson.databind.node.TextNode) WalkerConfigImpl(org.walkmod.conf.entities.impl.WalkerConfigImpl) LinkedList(java.util.LinkedList) ChainConfig(org.walkmod.conf.entities.ChainConfig) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Aggregations

TextNode (com.fasterxml.jackson.databind.node.TextNode)140 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)48 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)37 Test (org.junit.Test)37 JsonNode (com.fasterxml.jackson.databind.JsonNode)34 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)16 IntNode (com.fasterxml.jackson.databind.node.IntNode)16 ArrayList (java.util.ArrayList)16 Test (org.junit.jupiter.api.Test)15 MockScheduler (org.apache.kafka.common.utils.MockScheduler)14 MockTime (org.apache.kafka.common.utils.MockTime)14 ExpectedTaskBuilder (org.apache.kafka.trogdor.common.ExpectedTasks.ExpectedTaskBuilder)14 ExpectedTasks (org.apache.kafka.trogdor.common.ExpectedTasks)13 DoubleNode (com.fasterxml.jackson.databind.node.DoubleNode)12 WorkerRunning (org.apache.kafka.trogdor.rest.WorkerRunning)12 TreeNode (com.fasterxml.jackson.core.TreeNode)11 HashMap (java.util.HashMap)11 List (java.util.List)11 NoOpTaskSpec (org.apache.kafka.trogdor.task.NoOpTaskSpec)11 Map (java.util.Map)10