@Test public void paramJsonTest() throws Exception { HashMap<String,String> map=new HashMap<>(); map.put("v1","value1"); map.put("v2","value2"); map.put("v3",null); JsonNode sourceNode=JsonUtils.json("{'$and':[{'array':'repositories','elemMatch':{'field':'repositories.*._id','op':'>','rvalue':'${v1}'}},{'array':'repositories','elemMatch':{'field':'published','op':'=','rvalue':'${v2}'}}]}".replaceAll("'","\"")); JsonNode result=FindRequestBuilder. applyParameters(sourceNode,map); Assert.assertEquals("{'$and':[{'array':'repositories','elemMatch':{'field':'repositories.*._id','op':'>','rvalue':'value1'}},{'array':'repositories','elemMatch':{'field':'published','op':'=','rvalue':'value2'}}]}".replaceAll("'","\""), result.toString()); }
public static JsonNode applyParameters(JsonNode source,Map<String,String> parameters) { if(source instanceof ObjectNode) { return applyParameters( (ObjectNode) source, parameters); } else if(source instanceof ArrayNode) { return applyParameters( (ArrayNode)source, parameters); } else if(source instanceof TextNode) { String olds=source.asText(); String news=applyParameters(olds,parameters); if(olds!=news) { return JsonNodeFactory.instance.textNode(news); } else { return source; } } else { return source; } }
FindRequestBuilder { public static JsonNode applyParameters(JsonNode source,Map<String,String> parameters) { if(source instanceof ObjectNode) { return applyParameters( (ObjectNode) source, parameters); } else if(source instanceof ArrayNode) { return applyParameters( (ArrayNode)source, parameters); } else if(source instanceof TextNode) { String olds=source.asText(); String news=applyParameters(olds,parameters); if(olds!=news) { return JsonNodeFactory.instance.textNode(news); } else { return source; } } else { return source; } } }
FindRequestBuilder { public static JsonNode applyParameters(JsonNode source,Map<String,String> parameters) { if(source instanceof ObjectNode) { return applyParameters( (ObjectNode) source, parameters); } else if(source instanceof ArrayNode) { return applyParameters( (ArrayNode)source, parameters); } else if(source instanceof TextNode) { String olds=source.asText(); String news=applyParameters(olds,parameters); if(olds!=news) { return JsonNodeFactory.instance.textNode(news); } else { return source; } } else { return source; } }  }
FindRequestBuilder { public static JsonNode applyParameters(JsonNode source,Map<String,String> parameters) { if(source instanceof ObjectNode) { return applyParameters( (ObjectNode) source, parameters); } else if(source instanceof ArrayNode) { return applyParameters( (ArrayNode)source, parameters); } else if(source instanceof TextNode) { String olds=source.asText(); String news=applyParameters(olds,parameters); if(olds!=news) { return JsonNodeFactory.instance.textNode(news); } else { return source; } } else { return source; } }  static Map<String,String> fillDefaults(JsonNode savedSearch,
                                                  Map<String,String> parameterValues,
                                                  TypeResolver types); static FindRequest buildRequest(JsonNode savedSearch,
                                           String entity,
                                           String version,
                                           ClientIdentification clid,
                                           Map<String,String> parameterValues); static JsonNode applyParameters(JsonNode source,Map<String,String> parameters); static String applyParameters(String source,Map<String,String> parameters); }
FindRequestBuilder { public static JsonNode applyParameters(JsonNode source,Map<String,String> parameters) { if(source instanceof ObjectNode) { return applyParameters( (ObjectNode) source, parameters); } else if(source instanceof ArrayNode) { return applyParameters( (ArrayNode)source, parameters); } else if(source instanceof TextNode) { String olds=source.asText(); String news=applyParameters(olds,parameters); if(olds!=news) { return JsonNodeFactory.instance.textNode(news); } else { return source; } } else { return source; } }  static Map<String,String> fillDefaults(JsonNode savedSearch,
                                                  Map<String,String> parameterValues,
                                                  TypeResolver types); static FindRequest buildRequest(JsonNode savedSearch,
                                           String entity,
                                           String version,
                                           ClientIdentification clid,
                                           Map<String,String> parameterValues); static JsonNode applyParameters(JsonNode source,Map<String,String> parameters); static String applyParameters(String source,Map<String,String> parameters); static final String ERR_SAVED_SEARCH_INVALID_TYPE; static final String ERR_SAVED_SEARCH_NO_DEFAULT_VALUE; static final String ERR_SAVED_SEARCH_MISSING_PARAM; }