diff --git a/agama/engine/pom.xml b/agama/engine/pom.xml index 36338e9ffe5..9ad965d76d5 100644 --- a/agama/engine/pom.xml +++ b/agama/engine/pom.xml @@ -192,6 +192,13 @@ kryo 5.3.0 + + + + net.lingala.zip4j + zip4j + 2.11.2 + diff --git a/agama/engine/src/main/java/io/jans/agama/timer/Transpilation.java b/agama/engine/src/main/java/io/jans/agama/timer/Transpilation.java index f3caf0d07da..6ac4080d10a 100644 --- a/agama/engine/src/main/java/io/jans/agama/timer/Transpilation.java +++ b/agama/engine/src/main/java/io/jans/agama/timer/Transpilation.java @@ -158,7 +158,7 @@ public void process() throws IOException { String error = null, shortError = null; try { - TranspilationResult result = Transpiler.transpile(qname, map.keySet(), fl.getSource()); + TranspilationResult result = Transpiler.transpile(qname, fl.getSource()); logger.debug("Successful transpilation"); FlowMetadata meta = fl.getMetadata(); diff --git a/agama/transpiler/src/main/java/io/jans/agama/dsl/Transpiler.java b/agama/transpiler/src/main/java/io/jans/agama/dsl/Transpiler.java index 0748ccfd824..a2b076967a1 100644 --- a/agama/transpiler/src/main/java/io/jans/agama/dsl/Transpiler.java +++ b/agama/transpiler/src/main/java/io/jans/agama/dsl/Transpiler.java @@ -60,7 +60,6 @@ public class Transpiler { private final Logger logger = LoggerFactory.getLogger(Transpiler.class); private String flowId; - private Set flowNames; private String fanny; private Processor processor; @@ -89,18 +88,13 @@ public class Transpiler { } - public Transpiler(String flowQName, Set flowQNames) throws TranspilerException { + public Transpiler(String flowQName) throws TranspilerException { if (flowQName == null) throw new TranspilerException("Qualified name cannot be null", new NullPointerException()); this.flowId = flowQName; fanny = "_" + flowQName.replaceAll("\\.", "_"); //Generates a valid JS function name - - if (flowQNames != null) { - flowNames = new HashSet(flowQNames); - flowNames.remove(flowQName); - } processor = new Processor(false); xpathCompiler = processor.newXPathCompiler(); @@ -212,8 +206,7 @@ private void applyValidations(SaplingDocument doc) throws TranspilerException { try { XdmNode node = doc.toXdmNode(processor); - //Ensure only existing flows are referenced - checkUnknownInvocation(flowNames, node); + checkAutoInvocations(node); checkInputsUniqueness(node); } catch (SaxonApiException se) { throw new TranspilerException("Validation failed", se); @@ -229,21 +222,13 @@ private void validateName(AuthnFlowParser.FlowContext flowContext) throws Transp } - private void checkUnknownInvocation(Set known, XdmNode node) - throws TranspilerException, SaxonApiException { - - if (known != null) { - List invocations = xpathCompiler.evaluate(Visitor.FLOWCALL_XPATH_EXPR, node) - .stream().map(XdmItem::getStringValue).collect(Collectors.toList()); + private void checkAutoInvocations(XdmNode node) throws TranspilerException, SaxonApiException { + + Set invocations = xpathCompiler.evaluate(Visitor.FLOWCALL_XPATH_EXPR, node) + .stream().map(XdmItem::getStringValue).collect(Collectors.toSet()); - for (String t : invocations) { - if (t.equals(flowId)) - throw new TranspilerException("A flow cannot trigger an instance of itself"); - - if (!known.contains(t)) - throw new TranspilerException("Invocation of unknown element '" + t + "'"); - } - } + if (invocations.contains(flowId)) + throw new TranspilerException("A flow must not trigger an instance of itself"); } @@ -278,19 +263,16 @@ private void generateFromXml(String fileName, OutputStream out) throws Exception * Transpiles the input source code to code runnable by Agama flow engine in the * form of a Javascript function * @param flowQname Qualified name of the input flow - * @param flowQNames A list of known flow names. This is used to validate which flows can be - * triggered from the input flow (Trigger directive). Passing null disables the validation. - * Passing an empty list will make validation fail if any Trigger directive is found * @param source Source code of input flow (written using Agama DSL) * @return A TranspilerResult object holding the details of the generated function * @throws SyntaxException When the input source has syntactic errors, details are contained * in the exception thrown * @throws TranspilerException When other kind of processing error occurred. */ - public static TranspilationResult transpile(String flowQname, Set flowQNames, String source) + public static TranspilationResult transpile(String flowQname, String source) throws TranspilerException, SyntaxException { - Transpiler tr = new Transpiler(flowQname, flowQNames); + Transpiler tr = new Transpiler(flowQname); try { XdmNode doc = tr.asXML(source); @@ -306,36 +288,29 @@ public static TranspilationResult transpile(String flowQname, Set flowQN } } - + public static void runSyntaxCheck(String flowQname, String source) throws SyntaxException, TranspilerException { - Transpiler tr = new Transpiler(flowQname, null); + Transpiler tr = new Transpiler(flowQname); tr.validateName(tr.getFlowContext(source)); } - + public static void runSyntaxCheck(String source) throws SyntaxException, TranspilerException { - Transpiler tr = new Transpiler("", null); + Transpiler tr = new Transpiler(""); tr.getFlowContext(source); } public static void main(String... args) throws Exception { - - Set knownFlows = null; + int len = args.length; - if (len < 2) { - System.err.println("Expecting at least 2 params: input file path and flow ID"); + if (len != 2) { + System.err.println("Expecting 2 params: input file path and flow ID"); return; - } else if (len > 2) { - - knownFlows = new HashSet<>(); - for (int i = 3; i < len; i++) { - knownFlows.add(args[i]); - } } - Transpiler tr = new Transpiler(args[1], knownFlows); + Transpiler tr = new Transpiler(args[1]); String dslCode = new String(Files.readAllBytes(Paths.get(args[0])), UTF_8); XdmNode doc = tr.asXML(dslCode);