-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathentity.js
89 lines (70 loc) · 2.22 KB
/
entity.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
/*
* Copyright (c) 2019 Centric Consulting, LLC. All rights reserved.
* Nick Tinsley
*/
const fs = require('fs')
class Entity{
constructor(deliminator, domainKey, versionInd, useInAutomationInd){
this.deliminator = deliminator
this.domainKey = domainKey
this.versionInd = versionInd
this.useInAutomationInd = useInAutomationInd
}
/*
getEntities queries the StarUML project for all of the Classes which are the entities and returns
the array of entities to the caller
*/
getEntities(){
return app.repository.select("@UMLClass")
}
/*
formatEntitiesForOutput takes an array of entites and formats the data into a CSV format
*/
formatEntitiesForOutput(etnityArray){
var i;
//console.log(etnityArray.length)
var returnArray =[]
for(i=0; i<etnityArray.length; i++){
//console.log(etnityArray[i].name)
etnityArray[i].name = etnityArray[i].name.split('.').join('')
etnityArray[i].name = etnityArray[i].name.split(' ').join(this.deliminator)
//console.log(etnityArray[i].name)
var entryString = this.domainKey +','+etnityArray[i].name+','+''+','+this.versionInd+','+this.useInAutomationInd
returnArray.push(entryString)
}
return returnArray
}
/*
writeToCsv takes an array of formated Entites, it opens a save dialog box and uses the input from the user for a file name and destination.
It then writes to the file using a filestream
*/
writeToCsv(formatedEntities){
//for csv header
var header = 'domain_key, entity_name, entity_description, version_ind, use_in_automation_ind'
//filters for save prompt, it will automaticall choose CSV as the file type
var filters =[
{name: "CSV file", extensions:["csv"]}
]
//get path and file name
var selected = app.dialogs.showSaveDialog("Type In Name",null,filters)
if(selected){
//create file stream, to write line by line
var file = fs.createWriteStream(selected)
//error handling
file.on('error',function(err){
if (err) throw err
})
//write header
file.write(header + '\n')
//write formated entities
formatedEntities.forEach(function(v){
file.write(v + '\n')
})
//close stream connection
file.end()
}else{
console.log('File selection was canceled')
}
}
}
module.exports = Entity