Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
Jos van Roosmalen committed Oct 9, 2020
1 parent cc0a2e7 commit 6899e2a
Show file tree
Hide file tree
Showing 8 changed files with 57 additions and 11,884 deletions.
3 changes: 2 additions & 1 deletion buildPackageUiJar.bat
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@

echo Packaging the front end...
copy /Y node_modules_override\litegraph.js node_modules\litegraph.js\build\litegraph.js
copy /Y cp ml-backend\src\main\ml-modules\root\custom-modules\pipes\litegraph.sjs node_modules/litegraph.js/build/litegraph.js
node_modules\litegraph.js\build\litegraph.js
call quasar build

echo Moving the front-end package to SpringBoot static resources folder...
Expand Down
2 changes: 1 addition & 1 deletion buildPackageUiJar.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ git fetch --all
# build the front end SPA UI

echo "Copying overrides..."
cp node_modules_override/litegraph.js node_modules/litegraph.js/build/litegraph.js
cp ml-backend/src/main/ml-modules/root/custom-modules/pipes/litegraph.sjs node_modules/litegraph.js/build/litegraph.js
# quasar build --modern

# create static resource directory first
Expand Down
73 changes: 25 additions & 48 deletions ml-backend/src/main/ml-modules/root/custom-modules/pipes/core.sjs
Original file line number Diff line number Diff line change
Expand Up @@ -559,50 +559,6 @@ function init (LiteGraph) {
}

}
,
{
"functionName": "addProperty",
"blockName": "Add property",
"library": "Enrich",
"inputs": [
{
"name": "doc",
"type": "node"
},
{
"name": "value",
"type": null
}

],

"properties": [
{
name: "propertyName",
type: "Property name"
}

],
"outputs": [

{
name: "doc",
type: "node"
}
],
"function": {
"ref": null,
"code": "let doc = (this.getInputData(0)!=undefined)?this.getInputData(0):{}; \
let val = (this.getInputData(1)!=undefined)?this.getInputData(1):'';\
let propertyName = this.properties['propertyName'];\
if (xdmp.nodeKind(doc) == 'document' && doc.documentFormat == 'JSON') {\
doc=doc.toObject();\
}\
doc[propertyName] = val;\
this.setOutputData( 0, doc);"
}

}
]

let code = ""
Expand Down Expand Up @@ -631,9 +587,8 @@ function init (LiteGraph) {
code += "};"
//register in the syst em
code += "LiteGraph.registerNodeType('" + config.library + "/" + config.blockName + "', " + config.functionName + " );"
}

//xdmp.log(code)
}
// xdmp.log(code)
eval(code)

//Output for a subgraph
Expand Down Expand Up @@ -1289,6 +1244,29 @@ function init (LiteGraph) {

LiteGraph.registerNodeType("Format/FormatDateTime", FormatDateTime);


function addPropertyBlock() {
xdmp.log("JOS TEST");
this.addInput('doc', 'node');
this.addInput('value');
this.addOutput('doc', 'node');
this.addProperty('propertyName', 'Property name');
};
addPropertyBlock.title = 'Add property';
addPropertyBlock.prototype.onExecute = function() {
let doc = (this.getInputData(0) != undefined) ? this.getInputData(0) : {};
let val = this.getInputData(1);
xdmp.log(Sequence.from(["JOSInput",doc,"Val",val]));
let propertyName = this.properties['propertyName'];
if (xdmp.nodeKind(doc) == 'document' && doc.documentFormat == 'JSON') {
doc = doc.toObject();
}
doc[propertyName] = val;
xdmp.log(Sequence.from(["JOSResults",doc]));
this.setOutputData(0, doc);
};
LiteGraph.registerNodeType('Enrich/AddProperty', addPropertyBlock);

function CreateTriple () {
this.addInput("subject");
this.addInput("object");
Expand Down Expand Up @@ -2019,7 +1997,6 @@ function init (LiteGraph) {
this.setOutputData(0, outputval)
}
LiteGraph.registerNodeType("Format/stringPadding", StringPadding);

}

module.exports = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -319,24 +319,7 @@ function executeGraphStep(doc,uri,config,context){


function executeGraphFromJson(jsonGraph,uri, input,context){


//xdmp.log(context)
// let markLogicNodes = require("/lib/marklogicNodes")



/*
Library refactoring
var core = require("/custom-modules/core");
var user = require("/custom-modules/user");
core
user.init(LiteGraph);
*/



if(registeredNodeType==false) {
if( registeredNodeType === false ) {
for (let model of jsonGraph.models)
LiteGraph.registerNodeType(model.source + "/" + model.collection, createGraphNodeFromModel(model));
//userBlocks.initUserBlocks(LiteGraph);
Expand All @@ -346,14 +329,18 @@ function executeGraphFromJson(jsonGraph,uri, input,context){
// graph.configure(jsonGraph.executionGraph)
registeredNodeType=true
}


// graph.stop()

graph.configure(jsonGraph.executionGraph)



let arr = Object.keys(LiteGraph.registered_node_types)
arr.unshift("Start registered blocks:")
arr.push("End registered blocks")
xdmp.log(Sequence.from(arr))
xdmp.trace(TRACE_ID_DETAILS,Sequence.from(arr));

const errors = graph.configure(jsonGraph.executionGraph)
if ( errors.length > 0 ) {
const str = "The following blocks are not found: "+errors.join()
xdmp.trace(TRACE_ID_DETAILS,str);
throw Error(str);
}
graph.addInput("input", "");
graph.addInput("uri", "");
graph.addInput("collections", "");
Expand All @@ -368,8 +355,7 @@ function executeGraphFromJson(jsonGraph,uri, input,context){
graph.start();

return graph.getOutputData("output")
}//graph.global_outputs

}

module.exports = {
extractModelByCollectionMatch,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
const TRACE_ID = "pipes-litegraph";

(function(global) {
// *************************************************************
// LiteGraph CLASS *******
Expand Down Expand Up @@ -102,6 +104,7 @@
*/

registerNodeType: function(type, base_class) {
xdmp.trace(TRACE_ID,"Registering block "+type);
if (!base_class.prototype) {
throw "Cannot register a simple object, it must be a class with a prototype";
}
Expand Down Expand Up @@ -744,6 +747,7 @@
for (var i = 0; i < num; i++) {
for (var j = 0; j < limit; ++j) {
var node = nodes[j];
xdmp.log(Sequence.from(["GOING TO EXECUTE",node.title,node.onExecute]));
if (node.mode == LiteGraph.ALWAYS && node.onExecute) {
node.onExecute(); //hard to send elapsed time
}
Expand All @@ -764,6 +768,7 @@
for (var i = 0; i < num; i++) {
for (var j = 0; j < limit; ++j) {
var node = nodes[j];
xdmp.log(Sequence.from(["GOING TO EXECUTE",node.title,node.onExecute]));
if (node.mode == LiteGraph.ALWAYS && node.onExecute) {
node.onExecute();
}
Expand Down Expand Up @@ -1850,7 +1855,7 @@
* Configure a graph from a JSON string
* @method configure
* @param {String} str configure a graph from a JSON string
* @param {Boolean} returns if there was any error parsing
* @param {Array} returns node types in case of errors
*/
LGraph.prototype.configure = function(data, keep_old) {
if (!data) {
Expand Down Expand Up @@ -1880,15 +1885,15 @@
this[i] = data[i];
}

var error = false;
var errors =[];

//create nodes
this._nodes = [];
if (nodes) {
for (var i = 0, l = nodes.length; i < l; ++i) {
var n_info = nodes[i]; //stored info
var node = LiteGraph.createNode(n_info.type, n_info.title);
if (!node) {
if (!node || !node.onExecute) {
if (LiteGraph.debug) {
console.log(
"Node not found or has errors: " + n_info.type
Expand All @@ -1899,7 +1904,7 @@
node = new LGraphNode();
node.last_serialization = n_info;
node.has_errors = true;
error = true;
errors.push(n_info.type);
//continue;
}

Expand Down Expand Up @@ -1930,7 +1935,7 @@
this.updateExecutionOrder();
this._version++;
this.setDirtyCanvas(true, true);
return error;
return errors;
};

LGraph.prototype.load = function(url) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -395,13 +395,11 @@ function InvokeExecuteGraph (input) {
}

} catch (e) {

xdmp.log("Exception occured during graph execution: " + e, "error")

xdmp.log(Sequence.from(["Exception occured during graph execution: " + e.message,e.stack,"End"]), "error")
result = {
uri: uri,
result: graphResult,
error: e
error: "Error during graph execution. Check the log for details: "+e.message
}

}
Expand Down
Loading

0 comments on commit 6899e2a

Please sign in to comment.