Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Contribute all leafs in node, if node is selected by expression #7

Closed
juanpablo-santos opened this issue Jul 7, 2017 · 5 comments
Closed

Comments

@juanpablo-santos
Copy link
Contributor

Hi,

Currently, if a JSONPath expression selects a node rather than a leaf, then no matter what, it gets converted to a String. This is because on VariableResolver#addPostContentParameters, the call to the filter methods uses a toString on the resolved variable (which, in JSONPath can also be a map, if the expression resolves to a node instead of a leaf)

For large pipelines, which use a lot of JSONPath params, it would be nice to have one or two variables representing JSONPath nodes, instead of having one variable for each needed value (as a side effect, this would also allow to access the whole webhook payload). F.ex, inside the pipeline is really easy to do something like

"""
Dear email template,
<a href="$sender.email">$sender.full_name"</a> has come to known blablabla
"""

and it's much more manageable if the job has only one or a couple of JSONPath params rather than 10 or 12.

It seems that to achieve this only requires a couple of changes on VariableResolver:

  1. on VariableResolver#L62, the call to filter should be changed to:
map.put(gv.getKey() + "_" + i, filter(o, gv.getRegexpFilter()));
  1. replace the filter method with:
private Object filter(Object string, String regexpFilter) {
    if( string instanceof String ) {
        if (string == null || regexpFilter == null || regexpFilter.isEmpty()) {
          return string;
        }
        return string.replaceAll(regexpFilter, "");
    } else {
        LOGGER.info( "NOT filtering " + string )
        return object;
    }
}

As noted above, the ability to filter values on the parameter would be lost for nodes, although that functionality wouldn't be really useful for them anyway.

WDYT?

thanks,
juan pablo

@juanpablo-santos
Copy link
Contributor Author

Hi,

having a closer look at this, it is not as straightforward as I thought initially. Will tinker a bit to see if it's possible to come with something not too obscure.

br,
juan pablo

@tomasbjerre
Copy link
Contributor

tomasbjerre commented Jul 10, 2017

Perhaps if a node is found from a JSONPath or XPath then all leafs in the node can be contributed in variables like:

$nodename_leafname1
$nodename_leafname2
$nodename_leafname3
...

Also perhaps any child nodes should be contributed as well.

There can even be an option to contribute everything without having to add a JSONPath or XPath.

@juanpablo-santos
Copy link
Contributor Author

juanpablo-santos commented Jul 11, 2017

Hi Tomas,

I think I'll be able to have a PR for this issue by tomorrow; I've already made the appropiate changes with their corresponding unit tests, but would like to test it on a live installation first to ensure evertyhing is fine.

br,
juan pablo

juanpablo-santos pushed a commit to juanpablo-santos/generic-webhook-trigger-plugin that referenced this issue Jul 12, 2017
tomasbjerre added a commit that referenced this issue Jul 12, 2017
 fixes #7: Contribute all leafs in node, if node is selected by expression
@tomasbjerre
Copy link
Contributor

I released this in 1.11 now!

@juanpablo-santos
Copy link
Contributor Author

Cool, thanks! :-)

@tomasbjerre tomasbjerre changed the title JSONPath params are always converted to String Contribute all leafs in node, if node is selected by expression Jul 12, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants