Last active
October 25, 2020 09:54
-
-
Save tsanov/8c28c6e3478fa7f833107874831dc71a to your computer and use it in GitHub Desktop.
#jArchi Compare Names with CSV
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
| /* | |
| * Verify if the values in the first column of a CSV file are used as names | |
| * in the selection | |
| * | |
| * This work is derived from: | |
| * - smileham/Import from CSV.ajs | |
| * - smileham/Export to CSV.ajs | |
| * | |
| * Requires jArchi - https://www.archimatetool.com/blog/2018/07/02/jarchi/ | |
| * Requires PapaParse - https://www.papaparse.com/ | |
| * | |
| */ | |
| version = "Version 20200516.1130\n\n"; | |
| var debug = false; | |
| console.show(); | |
| console.clear(); | |
| console.log(version); | |
| load(__DIR__ + "lib/papaparse.min.js"); | |
| console.log("> Starting CSV Reading"); | |
| var filePath =window.promptOpenFile({title: "Open CSV", filterExtensions:["*.CSV"], fileName:""}); | |
| if(filePath){ | |
| console.log("> File to import: " + filePath); | |
| var FileReader = Java.type("java.io.FileReader"); | |
| var theCSVFile = new FileReader(filePath); | |
| var theCSV=""; | |
| var data = theCSVFile.read(); | |
| console.log("> Please wait ..."); | |
| while(data!=-1){ | |
| var theCharacter = String.fromCharCode(data); | |
| theCSV+=theCharacter; | |
| data = theCSVFile.read(); | |
| } | |
| theCSVFile.close(); | |
| console.log("> Loaded!"); | |
| var theDataFile = Papa.parse(theCSV); | |
| var theData = theDataFile.data; | |
| var theView = $(selection); | |
| console.log("> Current selection length: " + theView.length); | |
| console.log("> Names found in the current selection :\n"); | |
| if(theView){ | |
| theView.forEach( | |
| function(artifact){ | |
| var artifactNameAsArrayOfStrings = artifact.name.split(" "); | |
| theData.forEach( | |
| function(csv_line){ | |
| var intersection = []; | |
| var csvLine0AsArrayOfStrings = csv_line[0].split(" "); | |
| for(var i =0; i < csvLine0AsArrayOfStrings.length; i++){ | |
| var s1 = csvLine0AsArrayOfStrings[i].trim().toLowerCase(); | |
| for(var j=0; j<artifactNameAsArrayOfStrings.length; j++){ | |
| if(s1 && s1==artifactNameAsArrayOfStrings[j].trim().toLowerCase()) | |
| intersection.push(s1); | |
| } | |
| } | |
| if(intersection.length) | |
| console.log("intersection: "+intersection+" of artifact "+artifact.name+" and CSV line "+csv_line[0]); | |
| } | |
| ); | |
| } | |
| ); | |
| }; | |
| } | |
| console.log("> Compare Names with CSV completed!"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment