Added possibility to run QueryTemplate with defaults(no provided params)

This commit is contained in:
Luca Frosini 2022-02-08 12:49:25 +01:00
parent c6305c9570
commit 34fe3af013
1 changed files with 12 additions and 5 deletions

View File

@ -263,9 +263,11 @@ public class QueryTemplateManagement extends EntityElementManagement<QueryTempla
public void setParams(String params) throws ResourceRegistryException {
try {
ObjectMapper objectMapper = new ObjectMapper();
JsonNode jsonNode = objectMapper.readTree(params);
setParams(jsonNode);
if(params!=null && params.compareTo("")!=0) {
ObjectMapper objectMapper = new ObjectMapper();
JsonNode jsonNode = objectMapper.readTree(params);
setParams(jsonNode);
}
} catch (ResourceRegistryException e) {
throw e;
} catch (Exception e) {
@ -287,9 +289,14 @@ public class QueryTemplateManagement extends EntityElementManagement<QueryTempla
try {
String read = read();
QueryTemplate queryTemplate = ElementMapper.unmarshal(QueryTemplate.class, read);
JsonNode jsonNode = queryTemplate.getJsonQuery(params);
JsonNode query = null;
if(params!=null) {
query = queryTemplate.getJsonQuery(params);
}else {
query = queryTemplate.getJsonQuery();
}
JsonQuery jsonQuery = new JsonQuery();
jsonQuery.setJsonQuery(jsonNode);
jsonQuery.setJsonQuery(query);
return jsonQuery.query();
} catch (ResourceRegistryException e) {
throw e;