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

Action in vertex not taken into account #211

Closed
epoiseau opened this issue Oct 10, 2019 · 7 comments
Closed

Action in vertex not taken into account #211

epoiseau opened this issue Oct 10, 2019 · 7 comments

Comments

@epoiseau
Copy link

I have a model created using the studio. Actions specified in edges are taken into account. Actions specified in Vertex are not taken into account. I have used the same command for the action both in vertex and edges. The action is similar to this one (setting a variable to a value)

test=true;

So the question is : Are actions in vertex taken into account ?
See attached example.

test.json.txt

@KristianKarl
Copy link
Contributor

I believe GraphWalker is evaluating the expression test=true; after the evaluation of which out edges are available.
So in other words, actions are executed as the last thing done in an element.

@xiechunhong
Copy link

It seems that actions in vertices are lost, after model.build()
In JsonContextFactory.java line 155, maybe it's a bug.

  public List<Context> create(String jsonStr) {
    List<Context> contexts = new ArrayList<>();
    JsonMultimodel jsonMultimodel = new Gson().fromJson(jsonStr, JsonMultimodel.class);

    if (isNull(jsonMultimodel) || isNull(jsonMultimodel.getModels())) {
      throw new ContextFactoryException("The json file is not a valid GraphWalker model(s) file");
    }

    // Seed the [global] singleton random generator, if any seed was set in the json file
    if (jsonMultimodel.getSeed() != null) {
      SingletonRandomGenerator.setSeed(jsonMultimodel.getSeed());
    }

    for (JsonModel jsonModel : jsonMultimodel.getModels()) {
      JsonContext context = new JsonContext();
      Model model = jsonModel.getModel();

      context.setModel(model.build()); // after this line, actions in vertices are lost.
      if (jsonModel.getGenerator() != null) {
        context.setPathGenerator(GeneratorFactory.parse(jsonModel.getGenerator()));
      }
      for (Element element : context.getModel().getElements()) {
        if (element.getId().equals(jsonModel.getStartElementId())) {
          context.setNextElement(element);
          break;
        }
      }
      contexts.add(context);
    }

    return contexts;
  }

@KristianKarl
Copy link
Contributor

Indeed, It's a bug. Good catch @xiechunhong , thanks!

Setting actions are missing in:

public void setVertex(Vertex.RuntimeVertex vertex) {
id = vertex.getId();
name = vertex.getName();
sharedState = vertex.getSharedState();
if (vertex.hasRequirements()) {
requirements = new ArrayList<>();
for (Requirement requirement : vertex.getRequirements()) {
requirements.add(requirement.getKey());
}
}
if (vertex.hasProperties()) {
properties = new HashMap<>();
properties.putAll(vertex.getProperties());
}
}

I'll fix it during the day.

@KristianKarl
Copy link
Contributor

I created a PR #233 .

@xiechunhong
Copy link

Super fast response! @KristianKarl
Another thing:
In graphwalker-core SimpleMachine.java,the execute method for vertex, there is no actions execution call (just like the first line in edge execute method), could it be another bug, or it is just as designed?
private void execute(RuntimeVertex vertex) (line 303)

  private void execute(RuntimeEdge edge) {
    execute(edge.getActions()); // this line will execute the actions defined in edge
    if (edge.hasName()) {
      getCurrentContext().execute(edge.getName());
    }
  }

  private void execute(List<Action> actions) {
    for (Action action : actions) {
      getCurrentContext().execute(action);
    }
  }

  private void execute(RuntimeVertex vertex) {
    // maybe vertex also need to execute the actions here
    if (vertex.hasName()) {
      getCurrentContext().execute(vertex.getName());
    }
  }

@xiechunhong
Copy link

OK, I see your changes of the code, the issue (vertex doesn't execute the actions in SimpleMachine.java) I mentioned at the above comment is fixed! Great work! @KristianKarl

@KristianKarl
Copy link
Contributor

The fix is available now in the latest 4.3.0-SNAPSHOT version, which is available here: https://github.com/GraphWalker/graphwalker-project/releases/tag/LATEST-BUILDS

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants