Forum Stats

  • 3,741,299 Users
  • 2,248,407 Discussions
  • 7,861,732 Comments

Discussions

Accessing Process Model programatically

I see in the XML metadata that there is programmatic access to the Process Model (i.e. "ProcessModel"). however, I don't see how you can get to it. The "Custom Transformations Scripts" only has a "logical" or "relational" object to choose from. Am I missing something?

Best Answer

Answers

  • user8021161
    user8021161 Member Posts: 6 Blue Ribbon
    edited Feb 4, 2021 6:54PM

    I use the following script more often when I want to find out what's supported by the model and what's not. Create a separate script in your modeler for the dir function and now you can dissect the entire model itself like a python dir function -

    var dir = function (objsearch) {

        with (new JavaImporter(java.util, java.util.stream)) {

            var members = new HashMap();

            var signature = function (method) {

                var s = method.getReturnType().getSimpleName()

                    + " " + method.getName() + "(";

                s = s + Arrays.stream(method.getParameters()).map(function (p) {

                    return p.getType().getSimpleName() + " " + p.getName();

                }).collect(Collectors.joining(", ")) + ")";

                return s;

            }

            for (var c = obj.getClass(); c != null; c = c.getSuperclass()) {

                Arrays.stream(c.getFields()).forEach(function (f) {

                    members.putIfAbsent(f.getName(), f.getName());

                });

                Arrays.stream(c.getMethods()).forEach(function (m) {

                    members.putIfAbsent(m.getName(), signature(m));

                });

            }

            return members.entrySet().stream()

                .sorted(function (e1e2) e1.getKey().compareTo(e2.getKey()))

                .map(function (e) e.getValue())

                .filter(function (p) !search || p.contains(search))

                .collect(Collectors.toList());

        }

    }


    var design = model.getDesign();

    var stringSelection = new java.awt.datatransfer.StringSelection(dir(design));

    var clipboard = java.awt.Toolkit.getDefaultToolkit().getSystemClipboard();

    clipboard.setContents(stringSelection, null);

Sign In or Register to comment.