From: Sweidan Omar Date: Mon, 10 Jan 2022 10:24:32 +0000 (+0000) Subject: #308 X-Git-Url: http://git.useribm.hu/?a=commitdiff_plain;h=f31e6d9a105f4069eb3eee5f40ee9676ff3d87dd;p=mediacube.git #308 git-tfs-id: [http://tfs.userrendszerhaz.hu:8080/tfs/DefaultCollection]$/MediaCube;C32686 --- diff --git a/server/user.jobengine.osgi.server/src/user/jobengine/server/ast/JobTemplate.java b/server/user.jobengine.osgi.server/src/user/jobengine/server/ast/JobTemplate.java index 90a63b33..ad940586 100644 --- a/server/user.jobengine.osgi.server/src/user/jobengine/server/ast/JobTemplate.java +++ b/server/user.jobengine.osgi.server/src/user/jobengine/server/ast/JobTemplate.java @@ -5,10 +5,14 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; + /** * Gyökér osztály. */ public class JobTemplate extends AST { + private static final Logger logger = LogManager.getLogger(JobTemplate.class); private CommandSequence commandSequence = null; private DeclarationSequence declarationSequence = null; @@ -98,37 +102,54 @@ public class JobTemplate extends AST { List inputvariables = new ArrayList<>(); List inputparameters = new ArrayList<>(); List errors = new ArrayList<>(); + if (declarationSequence != null) { for (Declaration declaration : declarationSequence.getDeclarations()) { - if (declaration instanceof ParameterDeclaration) + if (declaration instanceof ParameterDeclaration) { parameters.put(declaration.getName(), declaration.getType()); - if (declaration instanceof VariableDeclaration) + } + if (declaration instanceof VariableDeclaration) { variables.put(declaration.getName(), declaration.getType()); + } } } if (commandSequence != null) { for (Command command : commandSequence.getCommands()) { if (command instanceof CallJobStepCommand) { + ParameterSequence inputParameterSequence = ((CallJobStepCommand) command) .getInputParameterSequence(); if (inputParameterSequence != null) { for (Parameter parameter : inputParameterSequence.getParameters()) { - if (!(parameter instanceof InputParameter)) + if (!(parameter instanceof InputParameter)) { throw new Exception(((CallJobStepCommand) command).getType() + ": class cast problem with input parameter name " + parameter.toString()); + } Expression expression = ((InputParameter) parameter).getExpression(); - if (expression instanceof VariableExpression) { - if (!inputvariables.contains(expression.getName())) - inputvariables.add(expression.getName()); - } - if (expression instanceof ParameterExpression) { - if (!inputparameters.contains(expression.getName())) - inputparameters.add(expression.getName()); + if (expression != null) { + if (expression instanceof VariableExpression) { + if (commandSequence.getCommands().get(0).equals(command)) { + // Egy paraméter tévesen változóként lett hivatkozva + if (parameters.containsKey(expression.getName())) { + if (errors.isEmpty()) { + errors.add( + String.format("Parameter %s is used as variable.", parameter)); + } + } + } + if (!inputvariables.contains(expression.getName())) + inputvariables.add(expression.getName()); + } + if (expression instanceof ParameterExpression) { + if (!inputparameters.contains(expression.getName())) + inputparameters.add(expression.getName()); + } } } } + ParameterSequence outputParameterSequence = ((CallJobStepCommand) command) .getOutputParameterSequence(); if (outputParameterSequence != null) { @@ -137,22 +158,34 @@ public class JobTemplate extends AST { throw new Exception(((CallJobStepCommand) command).getType() + ": class cast problem with output parameter name " + parameter.toString()); VariableName name = ((OutputParameter) parameter).getVariableName(); - if (!inputvariables.contains(name.getName())) - inputvariables.add(name.getName()); + if (name != null) { + if (!inputvariables.contains(name.getName())) + inputvariables.add(name.getName()); + } else { + if (errors.isEmpty()) { + errors.add("A " + ((CallJobStepCommand) command).getType() + + "folyamat kimeneti paramétere hibásan lett megadva a template fájlban!"); + } + } } } } } - for (String input : inputvariables) { - if (!variables.containsKey(input)) - errors.add(String.format("Variable declaration missing for '%s'.", input)); + for (String inputvariable : inputvariables) { + if (!variables.containsKey(inputvariable)) { + if (errors.isEmpty()) { + errors.add(String.format("Variable declaration missing for '%s'.", inputvariable)); + } + } } - for (String input : inputparameters) { - if (!parameters.containsKey(input)) - errors.add(String.format("Parameter declaration missing for '%s'.", input)); + for (String inputparameter : inputparameters) { + if (!parameters.containsKey(inputparameter)) { + if (errors.isEmpty()) { + errors.add(String.format("Parameter declaration missing for '%s'.", inputparameter)); + } + } } - } if (errors.size() > 0) { @@ -160,6 +193,7 @@ public class JobTemplate extends AST { errors.forEach(e -> sb.append(e)); throw new Exception("JobTemplate validation error: " + sb.toString()); } + return errors; }