Created
August 31, 2021 08:21
-
-
Save nfigay/a4f402ec184a6561e7155712dadaf8f2 to your computer and use it in GitHub Desktop.
This #jArchi script creates a PlantUML file (.puml) with all elements in the selected views - one file per view * A simple graph is produced, no nesting produced
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* PlantUML View export as Graph Script (PlantUML-V2G) | |
* Author: Nicolas Figay 2020 | |
* Version: 0.1 | |
* This script creates a .puml file with all elements in the selected views - one file per view | |
* A simple graph is produced, no nesting produced | |
*/ | |
console.log("PlantUML View export Script"); | |
load(__DIR__ + "lib/archimate.js"); | |
String.prototype.capitalize = function() { | |
return this.charAt(0).toUpperCase() + this.slice(1); | |
} | |
var FileWriter=Java.type("java.io.FileWriter"); | |
var views = selection.filter("archimate-diagram-model"); | |
if (views.length == 0){console.log ("No view selected -> let's select one or several");} | |
views.each (function(view){ | |
var fileName = window.promptSaveFile( { title: "Plant UML export", filterExtensions: [ "*.puml" ], fileName: view.name + ".puml" } ); | |
if(fileName) { | |
var fw = new FileWriter(fileName); | |
fw.write("@startuml\n"); | |
fw.write("!includeurl https://raw.githubusercontent.com/ebbypeter/Archimate-PlantUML/master/Archimate.puml\n"); | |
fw.write("LAYOUT_AS_SKETCH()\n"); | |
fw.write("LAYOUT_LEFT_RIGHT\n"); | |
fw.write("'LAYOUT_TOP_DOWN\n"); | |
fw.write ("Grouping("); | |
fw.write (view.id); | |
fw.write (',"'); | |
fw.write (view.name); | |
fw.write ("::ArchiMate view from Archi generated with plantuml-V2G 0.1"); | |
fw.write ('"){'); | |
fw.write ("\n"); | |
did="#"+view.id; | |
$(did).find().filter('element').each(function(node) { | |
switch (node.type) { | |
case 'junction': | |
// At this time jArchi is not providing yet the access to the type of a Junction | |
// A temporary workaround for dealing with it, here again a dedicated property e.g. puml.junctionType which as value "And" or "Or" | |
index=ja_ArchiMateObjects.indexOf(node.type); | |
puml=puml_ArchiMateObjects[index]; //I.e. "Junction_Or" - To be change with "Junction_And" if property.junctionType value is equal to "And" | |
break; | |
case 'location': | |
// Could be Business_Location or Other_Location for PlantUML-ArchiMate | |
// A way to take it into account is to define a dedicated property, e.g. puml.location which as value "Business" in order to use Business in place of Other (default) | |
puml="Other_Location"; | |
break; | |
default: | |
index=ja_ArchiMateObjects.indexOf(node.type); | |
puml=puml_ArchiMateObjects[index]; | |
} | |
fw.write(puml); | |
fw.write('('); | |
fw.write(node.id.replace(/-/g, "_")); | |
fw.write(',"'); | |
fw.write(node.name); | |
fw.write ('")\n'); | |
}); | |
$(did).find().filter('relationship').each(function(relation) { | |
switch (relation.type) { | |
case "access-relationship": | |
//at this time not possible to obtain the type, i.e. read, write, etc. with jArchi | |
default: | |
fw.write("Rel_"); | |
fw.write(relation.type.replace(/-relationship/g, "").capitalize()); | |
fw.write("("); | |
fw.write(relation.source.id.replace(/-/g, "_")); | |
fw.write(","); | |
fw.write(relation.target.id.replace(/-/g, "_")); | |
fw.write(',"'); | |
fw.write(relation.name); | |
fw.write('")'); | |
fw.write ("\n"); | |
} | |
}); | |
fw.write ("}\n"); | |
fw.write("@enduml\n"); | |
fw.close(); // forgetting to close it results in a truncated file | |
} | |
} | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment