|
|
@@ -17,23 +17,41 @@ import argparse
|
|
|
|
|
|
# packages from pypi:
|
|
|
import flask
|
|
|
-from flask_cors import CORS
|
|
|
+import flask_cors
|
|
|
|
|
|
# our own packages:
|
|
|
from drawio2py.parser import Parser as drawio_parser
|
|
|
+from drawio2py.generator import generate_diagram
|
|
|
+import drawio2py.util
|
|
|
from drawio2oml.convert import page_to_oml
|
|
|
from drawio2oml.bundle.oml_generator import write_bundle
|
|
|
-from drawio2oml import util
|
|
|
+from drawio2oml import util
|
|
|
from xopp2py import parser as xopp_parser
|
|
|
from xopp2oml import writer as xopp_oml_writer
|
|
|
|
|
|
+from drawio2oml.pt import fetcher as pt_fetcher
|
|
|
+from drawio2oml.pt import renderer as pt_renderer
|
|
|
+
|
|
|
argparser = argparse.ArgumentParser(
|
|
|
description = "Backend for DTDesign drawio plugin.")
|
|
|
argparser.add_argument('projectdir', help="Path to SystemDesignOntology2Layers OML project directory (containing \"build.gradle\"). Example: /home/maestro/repos/dtdesign/examples/oml/SystemDesignOntology2Layers")
|
|
|
+argparser.add_argument('shapelibdir', help="Path to where the Draw.io shape libraries (bunch of XML files) for FTG, PM and PT are at. Necessary for rendering process traces. Example: /home/maestro/repos/drawio/src/main/webapp/myPlugins/shape_libs")
|
|
|
args = argparser.parse_args() # exits on error
|
|
|
|
|
|
+WEE = "http://localhost:8081"
|
|
|
+WEE_FETCHER = pt_fetcher.Fetcher(WEE)
|
|
|
+
|
|
|
# See below
|
|
|
DTDESIGN_PROJECT_DIR = args.projectdir
|
|
|
+SHAPE_LIB_DIR = args.shapelibdir
|
|
|
+
|
|
|
+# Quick check to see if the projectdir argument is valid:
|
|
|
+if not os.path.isfile(DTDESIGN_PROJECT_DIR + "/build.gradle"):
|
|
|
+ sys.exit("Invalid projectdir: " + DTDESIGN_PROJECT_DIR)
|
|
|
+
|
|
|
+# Quick check to see if the shapelibdir argument is valid:
|
|
|
+if not os.path.isfile(SHAPE_LIB_DIR + "/pt.xml"):
|
|
|
+ sys.exit("Invalid shapelibdir: " + SHAPE_LIB_DIR)
|
|
|
|
|
|
OML_DESCRIPTION_DIR = DTDESIGN_PROJECT_DIR + "/src/oml/ua.be/sdo2l/description"
|
|
|
OML_ARTIFACT_DIR = OML_DESCRIPTION_DIR + "/artifacts"
|
|
|
@@ -44,9 +62,6 @@ XOPP_DIR = FILES_DIR + "/xopp"
|
|
|
CSV_DIR = FILES_DIR + "/csv"
|
|
|
ANYFILE_DIR = FILES_DIR + "/file"
|
|
|
|
|
|
-# Quick check to see if the projectdir argument is correct:
|
|
|
-if not os.path.isfile(DTDESIGN_PROJECT_DIR + "/build.gradle"):
|
|
|
- sys.exit("Invalid projectdir: " + DTDESIGN_PROJECT_DIR)
|
|
|
|
|
|
print()
|
|
|
print(" ",DTDESIGN_PROJECT_DIR)
|
|
|
@@ -76,7 +91,7 @@ for d in [DRAWIO_DIR, XOPP_DIR, CSV_DIR, ANYFILE_DIR]:
|
|
|
os.makedirs(d, exist_ok=True)
|
|
|
|
|
|
app = flask.Flask(__name__)
|
|
|
-CORS(app)
|
|
|
+flask_cors.CORS(app)
|
|
|
|
|
|
# API version
|
|
|
@app.route("/version", methods=["GET"])
|
|
|
@@ -110,6 +125,17 @@ def put_drawio_file(model_name):
|
|
|
f.write(diagram)
|
|
|
return json.dumps(parsed_as), 200 # OK
|
|
|
|
|
|
+# Even though the slashes in pt_iri will be escaped, we still have to tell Flask it's a 'path' or it won't accept it.
|
|
|
+@app.route("/render_pt/<path:pt_iri>", methods=["GET"])
|
|
|
+def render_pt(pt_iri):
|
|
|
+ last_event = WEE_FETCHER.get_pt(pt_iri)
|
|
|
+ id_gen = drawio2py.util.DrawioIDGenerator()
|
|
|
+ page = drawio2py.util.generate_empty_page(id_gen, "XXX")
|
|
|
+ default_layer = page.root.children[0]
|
|
|
+ pt_renderer.render(SHAPE_LIB_DIR, last_event, parent=default_layer, id_gen=id_gen)
|
|
|
+ diagram_node = generate_diagram(page)
|
|
|
+ return ET.tostring(diagram_node, encoding="unicode"), 200 # OK
|
|
|
+
|
|
|
@app.route("/files/xopp/<file_name>", methods=["PUT"])
|
|
|
def put_xopp_file(file_name):
|
|
|
if file_name[-5:] != ".xopp":
|
|
|
@@ -151,6 +177,7 @@ def put_any_file(model_name):
|
|
|
f.write(file_data)
|
|
|
return json.dumps(["file"]), 200 # OK
|
|
|
|
|
|
+# TODO: this endpoint should queue rebuilds (using Futures?), such that only one rebuild is running at a time.
|
|
|
@app.route("/rebuild_oml", methods=["PUT"])
|
|
|
def rebuild_oml():
|
|
|
with open(OML_DESCRIPTION_DIR+'/bundle.oml', 'wt') as f:
|