From: Omar Sweidan Date: Fri, 3 Jun 2022 09:15:13 +0000 (+0200) Subject: paraméterek, és változók átküldése JS oldalára X-Git-Url: http://git.useribm.hu/?a=commitdiff_plain;h=520954a537cf159fdca0130c25439c03fd7296ba;p=mediacube.git paraméterek, és változók átküldése JS oldalára --- diff --git a/server/user.jobengine.osgi.server/src/user/jobengine/server/JobEngineConfiguration.java b/server/user.jobengine.osgi.server/src/user/jobengine/server/JobEngineConfiguration.java index 840e97c6..ec796c13 100644 --- a/server/user.jobengine.osgi.server/src/user/jobengine/server/JobEngineConfiguration.java +++ b/server/user.jobengine.osgi.server/src/user/jobengine/server/JobEngineConfiguration.java @@ -94,7 +94,8 @@ public class JobEngineConfiguration implements IJobEngineConfiguration { public IJobStep createJobStep(String stepUnitName) throws Exception { IJobStep result = null; - boolean isGroovyClass = stepUnitName.toLowerCase().endsWith(".java") || stepUnitName.toLowerCase().endsWith(".groovy"); + boolean isGroovyClass = stepUnitName.toLowerCase().endsWith(".java") + || stepUnitName.toLowerCase().endsWith(".groovy"); logger.info("Looking for {} step ClassLoader requirement", stepUnitName); if (resetStepClassLoader) { @@ -127,7 +128,8 @@ public class JobEngineConfiguration implements IJobEngineConfiguration { if (isGroovyClass) { if (dynamicStepsLoader != null) - stepClass = (Class) dynamicStepsLoader.loadClassFromSourceCode(groovyClassLoader, stepUnitName); + stepClass = (Class) dynamicStepsLoader.loadClassFromSourceCode(groovyClassLoader, + stepUnitName); } else stepClass = (Class) stepsClassLoader.loadClass(stepUnitName); @@ -273,7 +275,8 @@ public class JobEngineConfiguration implements IJobEngineConfiguration { int newMaxConcurrent = executor.getMaxConcurrent(); if (currentMaxConcurrent != newMaxConcurrent) { stepExecutor.setMaxConcurrent(newMaxConcurrent); - logger.info("Executor maxConcurrent changed from {} to {}", currentMaxConcurrent, newMaxConcurrent); + logger.info("Executor maxConcurrent changed from {} to {}", currentMaxConcurrent, + newMaxConcurrent); } } @@ -319,7 +322,11 @@ public class JobEngineConfiguration implements IJobEngineConfiguration { JobTemplate jobTemplate = loadTemplate(Paths.get(template)); JSONEncoder jsonEncoder = new JSONEncoder(); BasicDBObject program = (BasicDBObject) jsonEncoder.visitJobTemplate(jobTemplate, null); - j.put("program", program); + if (program != null) { + j.put("program", program); + } else { + logger.info("program {} is null!"); + } schedules.add(new SimpleEntry(template, j)); } catch (Exception e) { @@ -400,7 +407,7 @@ public class JobEngineConfiguration implements IJobEngineConfiguration { BasicDBObject dbo = new BasicDBObject(); BasicDBList jobList = new BasicDBList(); for (int i = 0; i < schedules.size(); i++) { - BasicDBObject temp= new BasicDBObject(); + BasicDBObject temp = new BasicDBObject(); if (schedules.get(i).getValue().get("name") != null) { temp.append("name", schedules.get(i).getValue().get("name")); } @@ -455,12 +462,14 @@ public class JobEngineConfiguration implements IJobEngineConfiguration { if (!Files.isDirectory(templatesPath)) throw new FileNotFoundException(templatesPath + " is not a directory!"); if (templateToSave.getFileName() != null) { - filePath = templatesPath.toString() + FileSystems.getDefault().getSeparator() + templateToSave.getFileName(); + filePath = templatesPath.toString() + FileSystems.getDefault().getSeparator() + + templateToSave.getFileName(); if (Files.isWritable(Paths.get(filePath))) { logger.info("{} is writable", filePath); } else { logger.info("{} is not writable", filePath); - DosFileAttributeView dos = Files.getFileAttributeView(Paths.get(filePath), DosFileAttributeView.class); + DosFileAttributeView dos = Files.getFileAttributeView(Paths.get(filePath), + DosFileAttributeView.class); if (dos != null) { try { dos.setReadOnly(false); @@ -510,13 +519,15 @@ public class JobEngineConfiguration implements IJobEngineConfiguration { String duplicateFileName = null; try { templatesPath = Paths.get(systemConfig.getConfig(DIR_TEMPLATES)); - duplicateFileName = FilenameUtils.getName(selectedJob.getString("template")).replace(".xml", "").concat("-copy.xml"); + duplicateFileName = FilenameUtils.getName(selectedJob.getString("template")).replace(".xml", "") + .concat("-copy.xml"); filePath = templatesPath.toString() + FileSystems.getDefault().getSeparator() + duplicateFileName; while (Files.exists(Paths.get(filePath))) { duplicateFileName = FilenameUtils.getName(duplicateFileName).replace(".xml", "").concat("-copy.xml"); filePath = templatesPath.toString() + FileSystems.getDefault().getSeparator() + duplicateFileName; } - InputStream is = new FileInputStream(templatesPath.toString() + FileSystems.getDefault().getSeparator() + selectedJob.getString("template")); + InputStream is = new FileInputStream(templatesPath.toString() + FileSystems.getDefault().getSeparator() + + selectedJob.getString("template")); Files.copy(is, Paths.get(filePath)); } catch (FileNotFoundException e) { logger.error("File not found: {}", filePath); diff --git a/server/user.jobengine.osgi.server/src/user/jobengine/server/ast/JSONEncoder.java b/server/user.jobengine.osgi.server/src/user/jobengine/server/ast/JSONEncoder.java index 5759ea6f..896c5a09 100644 --- a/server/user.jobengine.osgi.server/src/user/jobengine/server/ast/JSONEncoder.java +++ b/server/user.jobengine.osgi.server/src/user/jobengine/server/ast/JSONEncoder.java @@ -11,10 +11,39 @@ public class JSONEncoder implements Visitor { BasicDBObject dbo = (BasicDBObject) o; BasicDBList nodes = (BasicDBList) dbo.get("nodes"); BasicDBObject newNode = new BasicDBObject(); + BasicDBList inputs = new BasicDBList(); + BasicDBList outputs = null; + // az inputs és az outputs elemei egyenként vannak hozzáadva, mert csak + // Stringgé konvertálva tudja a JS oldal feldolgozni + List inputParameters = command.getInputParameterSequence().getParameters(); + for (int i = 0; i < inputParameters.size(); i++) { + BasicDBObject input = new BasicDBObject(); + Expression expression = ((InputParameter) inputParameters.get(i)).getExpression(); + input.append("name", expression.getName()); + + if (expression instanceof ParameterExpression) { + input.append("type", "param"); + } else { + input.append("type", "variable"); + } + inputs.add(input); + } + if (command.getOutputParameterSequence() != null) { + outputs = new BasicDBList(); + List outputParameters = command.getOutputParameterSequence().getParameters(); + for (int i = 0; i < outputParameters.size(); i++) { + outputs.add(outputParameters.get(i).toString()); + } + } + newNode.append("name", command.getType().replace("Step.java", "")).append("y", 75).append("w", 100) .append("h", 100).append("connectors", "connectorsForStep") .append("text", command.getType().replace("Step.java", "")).append("fillStyle", "green") - .append("figure", "RectangleWithGradient"); + .append("figure", "RectangleWithGradient").append("inputs", inputs); + if (outputs != null) { + newNode.append("outputs", outputs); + } + nodes.add(newNode); BasicDBList links = (BasicDBList) dbo.get("links"); @@ -38,6 +67,12 @@ public class JSONEncoder implements Visitor { @Override public Object visitDeclarationSequence(DeclarationSequence declarationSequence, Object o) { + List declarations = declarationSequence.getDeclarations(); + if (declarations != null) { + for (Declaration declaration : declarations) { + declaration.visit(this, o); + } + } return null; } @@ -56,7 +91,12 @@ public class JSONEncoder implements Visitor { BasicDBObject dbo = new BasicDBObject(); dbo.append("nodes", new BasicDBList()); dbo.append("links", new BasicDBList()); + dbo.append("params", new BasicDBList()); + dbo.append("variables", new BasicDBList()); + DeclarationSequence ds = jobTemplate.getDeclarationSequence(); + if (ds != null) + ds.visit(this, dbo); CommandSequence cs = jobTemplate.getCommandSequence(); if (cs != null) cs.visit(this, dbo); @@ -76,6 +116,12 @@ public class JSONEncoder implements Visitor { @Override public Object visitParameterDeclaration(ParameterDeclaration parameterDeclaration, Object o) { + BasicDBObject dbo = (BasicDBObject) o; + BasicDBList params = (BasicDBList) dbo.get("params"); + BasicDBObject newParameter = new BasicDBObject(); + newParameter.append("name", parameterDeclaration.getName()).append("type", parameterDeclaration.getType()); + params.add(newParameter); + return null; } @@ -91,6 +137,12 @@ public class JSONEncoder implements Visitor { @Override public Object visitVariableDeclaration(VariableDeclaration variableDeclaration, Object o) { + BasicDBObject dbo = (BasicDBObject) o; + BasicDBList variables = (BasicDBList) dbo.get("variables"); + BasicDBObject newVariable = new BasicDBObject(); + newVariable.append("name", variableDeclaration.getName()).append("type", variableDeclaration.getType()); + variables.add(newVariable); + return null; } diff --git a/server/user.mediacube.gui/js/diagramflowjs.js b/server/user.mediacube.gui/js/diagramflowjs.js index 7b534869..f399d980 100644 --- a/server/user.mediacube.gui/js/diagramflowjs.js +++ b/server/user.mediacube.gui/js/diagramflowjs.js @@ -4,17 +4,28 @@ var model={ ctx:null, nodes:[], links:[], + params:[], + variables:[], myCanvas:null, rough:false, - addNode:function(node){ + addNode: function(node){ this.nodes.push(node); }, - addLink:function(link){ + + addLink: function(link){ this.links.push(link); }, + + addParam: function(param){ + this.params.push(param); + }, + + addVariable: function(variable){ + this.variables.push(variable); + }, - clean:function(){ + clean: function(){ this.ctx.beginPath(); var grd = this.ctx.createLinearGradient(0, this.myCanvas.height, this.myCanvas.width, 0); @@ -27,12 +38,12 @@ var model={ this.ctx.stroke(); }, - clear:function(){ + clear: function(){ this.nodes=[]; this.links=[]; }, - draw:function(){ + draw: function(){ this.clean(); for (let index = 0; index < this.nodes.length; index++) { this.nodes[index].draw(this.ctx); @@ -45,7 +56,8 @@ var model={ this.nodes[mouse.selNode].highlight(this.ctx); } }, - init:function(canvasName){ + + init: function(canvasName){ this.myCanvas=document.getElementById(canvasName); this.myCanvasContainer=document.getElementById(canvasName).parentElement; this.ctx=this.myCanvas.getContext("2d"); @@ -66,7 +78,7 @@ var model={ }, - findNode:function(mouseC){ + findNode: function(mouseC){ var minArea=34435345345344; var selIndex=null; for (let index = 0; index < this.nodes.length; index++) { @@ -83,7 +95,7 @@ var model={ return selIndex; }, - copyFrom:function(sourceModel){ + copyFrom: function(sourceModel){ model.nodes=[]; if (sourceModel.nodes){ for (let index = 0; index < sourceModel.nodes.length; index++) { @@ -107,11 +119,12 @@ var model={ mouse.dragging=null; }, - selectNode:function(node){ + selectNode: function(node){ mouse.selNode=node; model.draw(); }, - connector:function(x,y,mode,title,decoration,options){ + + connector: function(x, y, mode, title, decoration, options){ this.x=x; this.y=y; this.mode=mode; @@ -177,8 +190,8 @@ var model={ return false; }; }, - anchor:function(x,y,cursorClass) - { + + anchor: function(x, y, cursorClass){ this.x=x; this.y=y; this.radius=5; @@ -213,8 +226,8 @@ var model={ return false; }; }, - node:function(x,y,w,h,connectors,text,fillStyle,figure,args) - { + + node: function(x, y, w, h, connectors, text, fillStyle, figure, inputs, outputs, args) { this.textfill=function(ctx) { var fontSize = 12; var lines = new Array(); @@ -259,6 +272,8 @@ var model={ this.h=Number(h); this.data=args; this.connectors=connectors; + this.inputs=inputs; + this.outputs=outputs; this.anchors=[ new model.anchor(0,0,"nw-resize"), new model.anchor(.5,0,"n-resize"), @@ -340,7 +355,8 @@ var model={ }); } }, - link: function(from,to,anchorIndexFrom,anchorIndexTo,text,mode){ + + link: function(from, to, anchorIndexFrom, anchorIndexTo, text, mode){ this.directionToVector=function(cursorClass){ switch (cursorClass) { case "w-resize": @@ -601,8 +617,18 @@ var model={ return false; } }, - defaultAnchors:function(figure) - { + + param: function(name, type){ + this.name= name; + this.type= type; + }, + + variable: function(name, type){ + this.name= name; + this.type= type; + }, + + defaultAnchors: function(figure) { var anchors=[]; switch (figure) { case "Square": @@ -651,7 +677,6 @@ var model={ } return anchors; } - }; var mouse={ diff --git a/server/user.mediacube.gui/js/processVisualizer2.js b/server/user.mediacube.gui/js/processVisualizer2.js index 925e68ef..f1cdac05 100644 --- a/server/user.mediacube.gui/js/processVisualizer2.js +++ b/server/user.mediacube.gui/js/processVisualizer2.js @@ -36,12 +36,12 @@ var inputConnectorDecoration={fillStyle:"red", strokeStyle: "orange", highlightS var optionsInput={ dropAllowed:true, dragAllowed:true, - radius:7 + radius: 7 }; var optionsOutput={ dropAllowed:true, dragAllowed:true, - radius:7 + radius: 7 }; var connectorsForStep=[ @@ -75,27 +75,37 @@ function getPressedKey(e) { var arrays= JSON.parse(data); var nodes= arrays.nodes; var links= arrays.links; + var params= arrays.params; + var variables= arrays.variables; var xOfNewNode= 30; // start node - model.addNode(new model.node(xOfNewNode, 75, 25, 25, connectorsForStart, "", "black", "Circle")); + model.addNode(new model.node(xOfNewNode, 75, 25, 25, connectorsForStart, "", "black", "Circle", null, null)); xOfNewNode+= 150; for (let i = 0; i < nodes.length; i++) { - model.addNode(new model.node(xOfNewNode, 75, 100, 100, connectorsForStep, nodes[i].text, "", "RectangleWithGradient")); + model.addNode(new model.node(xOfNewNode, 75, 100, 100, connectorsForStep, nodes[i].text, "", "RectangleWithGradient", nodes[i].inputs, nodes[i].outputs)); xOfNewNode+= 150; } // end node - model.addNode(new model.node(xOfNewNode, 75, 25, 25, connectorsForEnd, "", "black", "Circle")); + model.addNode(new model.node(xOfNewNode, 75, 25, 25, connectorsForEnd, "", "black", "Circle", null, null)); //adding links model.addLink(new model.link(0, 1, 0, 0, "", "straight")); - let i = 0; + let i = 0; if(links.length > 0){ - for (; i < links.length; i++) { + for (; i < links.length; i++) { model.addLink(new model.link(i+1, i+2, 1, 0, "", "straight")); } } model.addLink(new model.link(i, i+1, 1, 0, "", "straight")); model.draw(); + + for (let i = 0; i < params.length; i++) { + model.addParam(new model.param(params[i].name, params[i].type)); + } + + for (let i = 0; i < variables.length; i++) { + model.addVariable(new model.variable(variables[i].name, variables[i].type)); + } } \ No newline at end of file diff --git a/server/user.mediacube.gui/pages/jobeditor2.zul b/server/user.mediacube.gui/pages/jobeditor2.zul index f355293b..7b830eb4 100644 --- a/server/user.mediacube.gui/pages/jobeditor2.zul +++ b/server/user.mediacube.gui/pages/jobeditor2.zul @@ -40,7 +40,7 @@ - + @@ -118,9 +118,9 @@ - - - + + + diff --git a/server/user.mediacube.gui/src/user/jobengine/zk/model/JobEditorModel2.java b/server/user.mediacube.gui/src/user/jobengine/zk/model/JobEditorModel2.java index 826378dd..7cd43376 100644 --- a/server/user.mediacube.gui/src/user/jobengine/zk/model/JobEditorModel2.java +++ b/server/user.mediacube.gui/src/user/jobengine/zk/model/JobEditorModel2.java @@ -56,7 +56,6 @@ public class JobEditorModel2 extends BaseModel { private Button NewParameterButton; private IJobEngine jobEngine; private ListModelList jobs = new ListModelList<>(); - private BasicDBObject selectedJob = new BasicDBObject(); private BasicDBObject editingJob = new BasicDBObject(); private ListModelList selectedJobs; @@ -95,10 +94,10 @@ public class JobEditorModel2 extends BaseModel { @NotifyChange("editingJob") public void onNewParameterClicked() { logger.info("onNewParameterClicked"); - if(editingJob != null) { - ((BasicDBList) editingJob.get("parameters")).add(new BasicDBObject() - .append("name", "param".concat(String.valueOf(numberOfNewParams))) - .append("type", dataTypes.get(8))); + if (editingJob != null) { + ((BasicDBList) editingJob.get("parameters")) + .add(new BasicDBObject().append("name", "param".concat(String.valueOf(numberOfNewParams))) + .append("type", dataTypes.get(8))); numberOfNewParams++; } } @@ -111,10 +110,10 @@ public class JobEditorModel2 extends BaseModel { } @Command - @NotifyChange({"editingJob", "jobs", "selectedJob"}) + @NotifyChange({ "editingJob", "jobs", "selectedJob" }) public void saveData() { logger.info("saveData"); - + try { jobEngine.getJobEngineConfiguration().saveSchedulesJson(selectedJob, editingJob); } catch (Exception e) { @@ -142,18 +141,18 @@ public class JobEditorModel2 extends BaseModel { public BasicDBObject getEditingJob() { return editingJob; } - + @NotifyChange("editingJob") public void setEditingJob(BasicDBObject editingJob) { logger.info("setEditingJob"); - this.editingJob= editingJob; - if(editingJob == null) { + this.editingJob = editingJob; + if (editingJob == null) { return; } updateNextExecutionTime(editingJob); } - @NotifyChange({"editingJob", "selectedJob"}) + @NotifyChange({ "editingJob", "selectedJob" }) public void setSelectedJob(BasicDBObject selectedJob) { logger.info("setSelectedJob"); if (selectedJob == null) { @@ -162,9 +161,10 @@ public class JobEditorModel2 extends BaseModel { return; } - this.selectedJob= selectedJob; - this.editingJob= NoSQLUtils.deepCopy(selectedJob); - BindUtils.postGlobalCommand(null, null, "selectedJobChanged", Collections.singletonMap("selectedJob", selectedJob)); + this.selectedJob = selectedJob; + this.editingJob = NoSQLUtils.deepCopy(selectedJob); + BindUtils.postGlobalCommand(null, null, "selectedJobChanged", + Collections.singletonMap("selectedJob", selectedJob)); } private void updateNextExecutionTime(BasicDBObject selectedJob) { @@ -224,7 +224,7 @@ public class JobEditorModel2 extends BaseModel { } @Command - @NotifyChange({"selectedJob", "jobs", "editingJob"}) + @NotifyChange({ "selectedJob", "jobs", "editingJob" }) public void reload() { try { jobEngine.reloadGracefully(); @@ -238,40 +238,40 @@ public class JobEditorModel2 extends BaseModel { @NotifyChange("jobs") public void duplicateProcessEntry() { if (selectedJob != null) { - String newTemplateName= jobEngine.getJobEngineConfiguration().duplicateTemplate(selectedJob); + String newTemplateName = jobEngine.getJobEngineConfiguration().duplicateTemplate(selectedJob); String newProcessName = copyProcessEntry(); List innerList = jobs.getInnerList(); - - for(int i= 0;i < innerList.size(); i++) { + + for (int i = 0; i < innerList.size(); i++) { BasicDBObject currentElement = innerList.get(i); - - if(currentElement.get("name").equals(newProcessName)) { + + if (currentElement.get("name").equals(newProcessName)) { currentElement.replace("template", newTemplateName); break; } } } } - + @Command @NotifyChange("jobs") public String copyProcessEntry() { logger.info("copyProcessEntry"); - - String newName= null; + + String newName = null; if (selectedJob != null) { newName = selectedJob.getString("name").concat("-copy"); while (jobEngine.getJobEngineConfiguration().scheduleExists(newName)) { newName = newName.concat("-copy"); } - BasicDBObject newEntry= NoSQLUtils.deepCopy(selectedJob); + BasicDBObject newEntry = NoSQLUtils.deepCopy(selectedJob); newEntry.put("name", newName); - + jobEngine.getJobEngineConfiguration().getSchedules() .add(new SimpleEntry(newName, newEntry)); jobs.add(newEntry); } - + return newName; } @@ -286,15 +286,15 @@ public class JobEditorModel2 extends BaseModel { public void setDataTypes(ArrayList dataTypes) { this.dataTypes = dataTypes; } - + public void setJobs(ListModelList jobs) { this.jobs = jobs; } - + public void setSelectedJobs(ListModelList selectedJobs) { this.selectedJobs = selectedJobs; } - + private void initializeDataTypes() { dataTypes.add("java.lang.Byte"); dataTypes.add("java.lang.Short");