Skip to content

Instantly share code, notes, and snippets.

@nfigay
Last active January 21, 2022 16:17
Show Gist options
  • Save nfigay/3db271413abf6f261943dc3443c7ad79 to your computer and use it in GitHub Desktop.
Save nfigay/3db271413abf6f261943dc3443c7ad79 to your computer and use it in GitHub Desktop.
Import of a hierarchy as a transversal folder structure plus Grouping hierarchy
/*
* Creation of Transversal Folder Structure script
* Author: Nicolas Figay 2020
* Version: 0.1
* This #jarchi script - from a text describing a table of content or a hierarchy - creates a folder structure for
* each ArchiMate layer and for views
* In addition, a grouping is created per hierarchy element
*/
console.log("Creation of Transversal Folder Structure script");
fileNameWithoutDir="tm.txt";
fileName=__DIR__ +fileNameWithoutDir;
var FileReader=Java.type("java.io.FileReader");
var BufferedReader=Java.type("java.io.BufferedReader");
var line; var lineLevel=0; pttrn = /^\s*/; var numberOfLevel=0;
var lastGroupingForLevels=[]; //Keep track of the parents for the hierarchy for Grouping creation
var lastFolderForLevelsArray=[[],[],[],[],[],[],[],[],[]]; // Keep track of the parents for the hierarchy per layers for Folder creation
var fr = new FileReader(fileName);
var br = new BufferedReader(fr);
newGrouping=model.createElement("grouping", fileNameWithoutDir);
lastGroupingForLevels[0]=newGrouping.id;
while ((line = br.readLine()) != null) {
//lineLevel = number of blanks at the beginning of the line
lineLevel=line.match(pttrn)[0].length+1;
newGrouping=model.createElement("grouping", line.trim());
lastGroupingForLevels[lineLevel]=newGrouping.id;
model.createRelationship("composition-relationship","",$("#"+lastGroupingForLevels[lineLevel-1]).first() ,newGrouping );
$.model.getLoadedModels().forEach((model)=>{
let index=0;
$(model).children().each(function(folder){
lastFolderForLevelsArray[index][0]=folder.id;
lastFolderForLevelsArray[index][lineLevel]=$("#"+lastFolderForLevelsArray[index][lineLevel-1]).first().createFolder(line).id;
index++;
});
});
}
@nfigay
Copy link
Author

nfigay commented Nov 24, 2020

Illustration of the outputs of this scripts are provided in this the article "What are the high added value uses of jArchi, the scripting solution integrated with Archi?" on LinkedIn.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment