List of usage examples for com.fasterxml.jackson.databind.node ObjectNode replace
public JsonNode replace(String paramString, JsonNode paramJsonNode)
From source file:com.pros.jsontransform.ObjectTransformer.java
private void transformStructure(final JsonNode sourceNode, final JsonNode transformNode, final ObjectNode targetNode) throws ObjectTransformerException { // process $path directive JsonNode newSourceNode = updateSourceFromPath(sourceNode, transformNode.get(PATH)); JsonNode structureNode = transformNode.get(STRUCTURE); if (structureNode.isObject()) { // mapping an object ObjectNode childNode = (ObjectNode) targetNode.get(transformNode.path(APPEND).asText()); if (childNode == null) { // no $append directive found, need new object childNode = mapper.createObjectNode(); targetNode.replace(transformNodeFieldName, childNode); }/*w w w .j a va2 s.c om*/ // visit child object transformNode(newSourceNode, structureNode, childNode); } else if (structureNode.isArray()) { // mapping an array ArrayNode childNode = (ArrayNode) targetNode.get(transformNode.path(APPEND).asText()); if (childNode == null) { // no $append directive found, need new object childNode = mapper.createArrayNode(); targetNode.replace(transformNodeFieldName, childNode); } processArray(newSourceNode, transformNode, childNode); } // restore path restoreSourceFromPath(sourceNode, transformNode.get(PATH)); }
From source file:org.apache.syncope.core.workflow.activiti.ActivitiUserWorkflowAdapter.java
protected void exportProcessModel(final OutputStream os) { Model model = getModel(getProcessDefinition()); ObjectMapper objectMapper = new ObjectMapper(); try {//from w w w . j av a2 s .com ObjectNode modelNode = (ObjectNode) objectMapper.readTree(model.getMetaInfo()); modelNode.put(ModelDataJsonConstants.MODEL_ID, model.getId()); modelNode.replace(MODEL_DATA_JSON_MODEL, objectMapper.readTree(engine.getRepositoryService().getModelEditorSource(model.getId()))); os.write(modelNode.toString().getBytes()); } catch (IOException e) { LOG.error("While exporting workflow definition {}", model.getId(), e); } }
From source file:org.apache.syncope.core.workflow.flowable.FlowableUserWorkflowAdapter.java
protected void exportProcessModel(final String key, final OutputStream os) { Model model = getModel(getProcessDefinitionByKey(key)); try {// ww w.jav a 2 s . com ObjectNode modelNode = (ObjectNode) OBJECT_MAPPER.readTree(model.getMetaInfo()); modelNode.put(ModelDataJsonConstants.MODEL_ID, model.getId()); modelNode.replace(MODEL_DATA_JSON_MODEL, OBJECT_MAPPER.readTree(engine.getRepositoryService().getModelEditorSource(model.getId()))); os.write(modelNode.toString().getBytes()); } catch (IOException e) { LOG.error("While exporting workflow definition {}", model.getId(), e); } }
From source file:org.flowable.editor.dmn.converter.DmnJsonConverterUtil.java
public static JsonNode migrateModel(JsonNode decisionTableNode, ObjectMapper objectMapper) { // check if model is version 1 if (decisionTableNode.get("modelVersion") == null || decisionTableNode.get("modelVersion").isNull()) { // split input rule nodes into operator and expression nodes ///*from www . j ava 2s .co m*/ // determine input node ids JsonNode inputExpressionNodes = decisionTableNode.get("inputExpressions"); Map<String, String> inputExpressionIds = new HashMap<>(); if (inputExpressionNodes != null && !inputExpressionNodes.isNull()) { for (JsonNode inputExpressionNode : inputExpressionNodes) { if (inputExpressionNode.get("id") != null && !inputExpressionNode.get("id").isNull()) { String inputId = inputExpressionNode.get("id").asText(); String inputType = null; if (inputExpressionNode.get("type") != null && !inputExpressionNode.get("type").isNull()) { inputType = inputExpressionNode.get("type").asText(); } inputExpressionIds.put(inputId, inputType); } } } // split input rule nodes JsonNode ruleNodes = decisionTableNode.get("rules"); ArrayNode newRuleNodes = objectMapper.createArrayNode(); if (ruleNodes != null && !ruleNodes.isNull()) { for (JsonNode ruleNode : ruleNodes) { ObjectNode newRuleNode = objectMapper.createObjectNode(); for (String inputExpressionId : inputExpressionIds.keySet()) { if (ruleNode.has(inputExpressionId)) { String operatorId = inputExpressionId + "_operator"; String expressionId = inputExpressionId + "_expression"; String operatorValue = null; String expressionValue = null; if (ruleNode.get(inputExpressionId) != null && !ruleNode.get(inputExpressionId).isNull()) { String oldExpression = ruleNode.get(inputExpressionId).asText(); if (StringUtils.isNotEmpty(oldExpression)) { if (oldExpression.indexOf(' ') != -1) { operatorValue = oldExpression.substring(0, oldExpression.indexOf(' ')); expressionValue = oldExpression.substring(oldExpression.indexOf(' ') + 1); } else { // no prefixed operator expressionValue = oldExpression; } // remove outer escape quotes if (expressionValue.startsWith("\"") && expressionValue.endsWith("\"")) { expressionValue = expressionValue.substring(1, expressionValue.length() - 1); } // if build in date function if (expressionValue.startsWith("fn_date(")) { expressionValue = expressionValue.substring(9, expressionValue.lastIndexOf('\'')); } else if (expressionValue.startsWith("date:toDate(")) { expressionValue = expressionValue.substring(13, expressionValue.lastIndexOf('\'')); } // determine type is null if (StringUtils.isEmpty(inputExpressionIds.get(inputExpressionId))) { String expressionType = determineExpressionType(expressionValue); inputExpressionIds.put(inputExpressionId, expressionType); } } } // add new operator kv if (StringUtils.isNotEmpty(operatorValue)) { newRuleNode.put(operatorId, operatorValue); } else { // default value newRuleNode.put(operatorId, "=="); } // add new expression kv if (StringUtils.isNotEmpty(expressionValue)) { newRuleNode.put(expressionId, expressionValue); } else { // default value newRuleNode.put(expressionId, "-"); } } } Iterator<String> ruleProperty = ruleNode.fieldNames(); while (ruleProperty.hasNext()) { String outputExpressionId = ruleProperty.next(); if (!inputExpressionIds.containsKey(outputExpressionId)) { // is output expression String outputExpressionValue = ruleNode.get(outputExpressionId).asText(); // remove outer escape quotes if (StringUtils.isNotEmpty(outputExpressionValue) && outputExpressionValue.startsWith("\"") && outputExpressionValue.endsWith("\"")) { outputExpressionValue = outputExpressionValue.substring(1, outputExpressionValue.length() - 1); } // if build in date function if (outputExpressionValue.startsWith("fn_date(")) { outputExpressionValue = outputExpressionValue.substring(9, outputExpressionValue.lastIndexOf('\'')); } else if (outputExpressionValue.startsWith("date:toDate(")) { outputExpressionValue = outputExpressionValue.substring(13, outputExpressionValue.lastIndexOf('\'')); } newRuleNode.put(outputExpressionId, outputExpressionValue); } } newRuleNodes.add(newRuleNode); } // set input expression nodes types if (inputExpressionNodes != null && !inputExpressionNodes.isNull()) { for (JsonNode inputExpressionNode : inputExpressionNodes) { if (inputExpressionNode.get("id") != null && !inputExpressionNode.get("id").isNull()) { String inputId = inputExpressionNode.get("id").asText(); ((ObjectNode) inputExpressionNode).put("type", inputExpressionIds.get(inputId)); } } } // replace rules node ObjectNode decisionTableObjectNode = (ObjectNode) decisionTableNode; decisionTableObjectNode.replace("rules", newRuleNodes); } } return decisionTableNode; }