Last active
January 21, 2022 16:17
-
-
Save nfigay/3db271413abf6f261943dc3443c7ad79 to your computer and use it in GitHub Desktop.
Import of a hierarchy as a transversal folder structure plus Grouping hierarchy
This file contains hidden or 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
/* | |
* 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++; | |
}); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.