Skip to content

Add correct behaviour in case user creates a cycle in the script#81

Merged
blcham merged 3 commits intomainfrom
add-proper-cycle-processing
Nov 14, 2025
Merged

Add correct behaviour in case user creates a cycle in the script#81
blcham merged 3 commits intomainfrom
add-proper-cycle-processing

Conversation

@MSattrtand
Copy link
Collaborator

Resolves #76

Cycles can only be created when new dependencies are added through the sm:next relation, assuming no files contain cycles. So in scriptService.createDependency I've added a catch that should restore the model before changes were made in case writeScript fails with IllegalStateException, which will be thrown in case we have a cycle in the graph.

Editor will show a message that will indicate that:

image

Copy link
Contributor

@blcham blcham left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see that it solves some of the issues, but it doesn't make sense to do it this complicated way. Moreover, it has a negative side effect that it modifies the file anyway, forcing the s-pipes editor to reload.

The write method should throw an exception, but it should not empty the file.

I believe there are multiple ways how to solve this issue:

  1. the best way:
  • we should investigate why we empty file first, this should no happen. If it is happening using:
    public static void writeScript(OutputStream outputStream, Model model) {
        RDFWriter.create()
                .format(new RDFFormat(CustomLangs.SPIPES_TURTLE))
                .source(model)
                .output(outputStream);
    }

you could even reprogram it to:

    public static void writeScript(OutputStream outputStream, Model model) {
        Graph graph = model.getGraph();
        SPipesFormatter formatter = new SPipesFormatter(graph, PrefixMapFactory.create(graph.getPrefixMapping()));
        formatter.writeTo(outputStream);
    }

  1. less optimal -- use builder:
    public static SPipesFormatter getScriptFormatter(Model model) {
        Graph graph = model.getGraph();
        return new SPipesFormatter(graph, PrefixMapFactory.create(graph.getPrefixMapping()));
    }

@blcham
Copy link
Contributor

blcham commented Nov 12, 2025

Please try to investigate 1) using test JenaUtils.writeScriptWhenCycleInDependenciesDoesNotWriteToOutputStream()

Copy link
Contributor

@blcham blcham left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see my comment

@blcham blcham merged commit b72e890 into main Nov 14, 2025
2 checks passed
@blcham blcham deleted the add-proper-cycle-processing branch November 14, 2025 16:33
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

Successfully merging this pull request may close these issues.

Add correct behaviour in case user creates a cycle in the script

2 participants