-
Notifications
You must be signed in to change notification settings - Fork 5
/
makeAbstractSchema.vbs
416 lines (332 loc) · 13.3 KB
/
makeAbstractSchema.vbs
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
option explicit
!INC Local Scripts.EAConstants-VBScript
' script: makeAbstractSchema
' purpose: switch known stereotypes, from FeatureType to GI_Class etc.
' formål: endre kjente stereotyper for revisjon av sosi fagområder
' author: Kent
' version: 2023-10-27 classes and attributes handled, codelists with codes become GI_Enumerations
' version: 2023-10-28 roles with role names handled
' TBD: complete enumerations (<memo>)
' TBD: remove old stereotype from package and class! (only possible with sql?)
' TBD: tagged values on GI_Property and GI_Enum not visible under Properties tab, just stereotype name (however scripts will work)
' TBD: fix æøå in Notes also at this stage?
DIM debug,txt
debug = false
sub makeAbstract()
Repository.EnsureOutputVisible "Script"
Dim theElement as EA.Element
dim conn as EA.Connector
dim connend as EA.ConnectorEnd
Dim newETag as EA.TaggedValue
Dim newATag as EA.AttributeTag
Dim newCTag as EA.RoleTag
Set theElement = Repository.GetTreeSelectedObject()
if not theElement is nothing then
dim box
box = Msgbox ("Skript makeAbstractSchema" & vbCrLf & vbCrLf & "Skriptversjon 2023-10-27" & vbCrLf & _
"Endrer kjente stereotyper for modernisering av elementene i sosi fagområde: [" & theElement.Name & "]." & vbCrLf & _
"NOTE! This script will automatically change your model!",1)
select case box
case vbOK
Repository.ClearOutput "Script"
Repository.CreateOutputTab "Error"
Repository.ClearOutput "Error"
if Repository.GetTreeSelectedItemType() = otPackage then
makeAbstractSchema(theElement)
else
if Repository.GetTreeSelectedItemType() = otElement and theElement.Type = "Class" then
makeAbstractClass(theElement)
else
MsgBox( "This script requires a package or a class to be selected in the Project Browser." & vbCrLf & _
"Please select this and try again." )
end if
end if
Repository.WriteOutput "Script", Now & " End of processing.",0
case VBcancel
end select
else
MsgBox( "This script requires a package or a class to be selected in the Project Browser." & vbCrLf & _
"Please select this and try again." )
end if
end sub
sub makeAbstractSchema(pkg)
dim elements as EA.Collection
dim i
if debug then Repository.WriteOutput "Script", Now & " Stereotypes will be changed for Package : [«" & pkg.element.Stereotype & "» " & pkg.Name & "].",0 end if
' Repository.WriteOutput "Script", Now & " Stereotype LCase : " & LCase(pkg.element.Stereotype) & ".",0
if LCase(pkg.element.Stereotype) = "applicationschema" then
' theElement.GetStereotypeList()
' Repository.WriteOutput "Script", "FQ Stereotype [" & pkg.element.FQStereotype & "]" & vbCrLf ,0
'? Repository.WriteOutput "Script", "Has Stereotype [" & pkg.element.HasStereotype() & "]" & vbCrLf ,0
'? pkg.element.Stereotype = ""
'? pkg.element.Stereotype.Remove()
pkg.element.Stereotype = "AbstractSchema"
pkg.element.Update()
pkg.element.Refresh()
Repository.WriteOutput "Script", " Stereotype changed for Package : [«" & pkg.element.Stereotype & "» " & pkg.Name & ".",0
end if
set elements = pkg.Elements
for i = 0 to elements.Count - 1
dim element as EA.Element
set element = elements.GetAt( i )
if element.Type = "Class" then
makeAbstractClass(element)
element.Refresh()
end if
next
dim subP as EA.Package
for each subP in pkg.packages
makeAbstractSchema(subP)
next
end sub
sub makeAbstractClass(theElement)
' Dim theElement as EA.Element
dim attr as EA.Attribute
dim conn as EA.Connector
dim connend as EA.ConnectorEnd
Dim newETag as EA.TaggedValue
Dim newATag as EA.AttributeTag
Dim newCTag as EA.RoleTag
if debug then Repository.WriteOutput "Script", " Stereotypes will be changed for Class : [«" & theElement.Stereotype & "» " & theElement.Name & "].",0 end if
' Repository.WriteOutput "Script", "Old Stereotype [" & theElement.Stereotype & "]" & vbCrLf ,0
' Repository.WriteOutput "Script", "FQ Stereotype [" & theElement.FQStereotype & "]" & vbCrLf ,0
' Repository.WriteOutput "Script", "StereotypeList [" & theElement.GetStereotypeList() & "]" & vbCrLf ,0
' Repository.WriteOutput "Script", "StereotypeEx [" & theElement.StereotypeEx & "]" & vbCrLf ,0
if LCase(theElement.Stereotype) = "featuretype" then
' theElement.GetStereotypeList()
' Repository.WriteOutput "Script", "FQ featuretype Stereotype [" & theElement.FQStereotype & "]" & vbCrLf ,0
theElement.Stereotype = "GI_Class"
for each attr in theElement.Attributes
makeAbstractAttribute(attr)
theElement.Update()
theElement.Refresh()
next
end if
if LCase(theElement.Stereotype) = "datatype" then
' theElement.GetStereotypeList()
' Repository.WriteOutput "Script", "FQ datatype Stereotype [" & theElement.FQStereotype & "]" & vbCrLf ,0
theElement.Stereotype = "GI_DataType"
for each attr in theElement.Attributes
makeAbstractAttribute(attr)
next
theElement.Update()
theElement.Refresh()
end if
if LCase(theElement.Stereotype) = "codelist" then
' theElement.GetStereotypeList()
' Repository.WriteOutput "Script", "FQ codelist Stereotype [" & theElement.FQStereotype & "]" & vbCrLf ,0
if theElement.Attributes.Count() > 0 then
theElement.Stereotype = "enumeration"
else
theElement.Stereotype = "GI_CodeSet"
end if
if theElement.Attributes.Count() > 0 then
Repository.WriteOutput "Script", "Warning: Class with codes not empty! [" & theElement.Name & " has "& theElement.Attributes.Count() & " codes]" & vbCrLf ,0
for each attr in theElement.Attributes
makeAbstractAttribute(attr)
next
end if
theElement.Update()
theElement.Refresh()
end if
' Repository.WriteOutput "Script", "New Stereotype [" & theElement.Stereotype & "]" & vbCrLf ,0
Repository.WriteOutput "Script", " Stereotype changed for Class : [«" & theElement.Stereotype & "» " & theElement.Name & "].",0
for each conn in theElement.Connectors
'''Repository.WriteOutput "Script", "Connector found [" & theElement.Name & "]" & " Connector.Name [" & conn.Name & "]" & " Connector.Type [" & conn.Type & "]" & vbCrLf ,0
if conn.Type = "Generalization" or conn.Type = "Realisation" or conn.Type = "NoteLink" then
else
' find roles referring to the other class
if conn.ClientID = theElement.ElementID then
if debug then Repository.WriteOutput "Script", "Connector to supplier [" & theElement.Name & "]" & " conn.SupplierEnd.Role [" & conn.SupplierEnd.Role & "] to Class [" & Repository.GetElementByID(conn.SupplierID).Name & "]" & vbCrLf ,0 end if
set connend = conn.SupplierEnd
else
if debug then Repository.WriteOutput "Script", "Connector to client [" & theElement.Name & "]" & " conn.ClientEnd.Role [" & conn.ClientEnd.Role & "]" & " to Class [" & Repository.GetElementByID(conn.ClientID).Name & "]" & vbCrLf ,0 end if
set connend = conn.ClientEnd
end if
if debug then Repository.WriteOutput "Script", "Class [" & theElement.Name & "]" & " role.Name [" & connend.Role & "]" & " role.Stereotype [" & connend.Stereotype & "]" & " role.StereotypeEx [" & connend.StereotypeEx & "]" & vbCrLf ,0 end if
if connend.Role <> "" then
connend.Stereotype = "GI_Property"
connend.Update()
conn.Update()
end if
end if
next
theElement.Update()
theElement.Refresh()
end sub
sub makeAbstractAttribute(attr)
' Dim theElement as EA.Element
' dim attr as EA.Attribute
dim conn as EA.Connector
dim connend as EA.ConnectorEnd
Dim newETag as EA.TaggedValue
Dim newATag as EA.AttributeTag
Dim newCTag as EA.RoleTag
' Repository.WriteOutput "Script", "Old Stereotype [" & attr.Stereotype & "]" & vbCrLf ,0
' Repository.WriteOutput "Script", "FQ Stereotype [" & attr.FQStereotype & "]" & vbCrLf ,0
' Repository.WriteOutput "Script", "StereotypeList [" & theElement.GetStereotypeList() & "]" & vbCrLf ,0
' Repository.WriteOutput "Script", "StereotypeEx [" & attr.StereotypeEx & "]" & vbCrLf ,0
if LCase(attr.Stereotype) = "egenskap" then
' theElement.GetStereotypeList()
' Repository.WriteOutput "Script", "FQ egenskap Stereotype [" & attr.FQStereotype & "]" & vbCrLf ,0
attr.Stereotype = "GI_Property"
attr.Update()
end if
if LCase(attr.Stereotype) = "enum" or LCase(attr.Type) = "<undefined>" or LCase(attr.Type) = "" then
' theElement.GetStereotypeList()
' Repository.WriteOutput "Script", "FQ enum Stereotype [" & attr.FQStereotype & "]" & vbCrLf ,0
attr.Stereotype = "GI_EnumerationLiteral"
attr.Update()
end if
if LCase(attr.Stereotype) = "" and LCase(attr.Type) <> "" then
' theElement.GetStereotypeList()
' Repository.WriteOutput "Script", "FQ Stereotype [" & attr.FQStereotype & "]" & vbCrLf ,0
attr.Stereotype = "GI_Property"
attr.Update()
end if
' Repository.WriteOutput "Script", "New Stereotype [" & attr.Stereotype & "]" & vbCrLf ,0
if LCase(attr.Stereotype) = "enum" or LCase(attr.Stereotype) = "GI_EnumerationLiteral" or LCase(attr.Type) = "<undefined>" or LCase(attr.Type) = "" then
else
Repository.WriteOutput "Script", " Stereotype changed for Atribute : [«" & attr.Stereotype & "» " & attr.Name & "].",0
end if
end sub
function getTaggedValue(element,taggedValueName)
dim i, existingTaggedValue
getTaggedValue = ""
for i = 0 to element.TaggedValues.Count - 1
set existingTaggedValue = element.TaggedValues.GetAt(i)
if existingTaggedValue.Name = taggedValueName then
getTaggedValue = existingTaggedValue.Value
end if
next
end function
function getPackageTaggedValue(package,taggedValueName)
dim i, existingTaggedValue
getPackageTaggedValue = ""
for i = 0 to package.element.TaggedValues.Count - 1
set existingTaggedValue = package.element.TaggedValues.GetAt(i)
if existingTaggedValue.Name = taggedValueName then
getPackageTaggedValue = existingTaggedValue.Value
end if
next
end function
function getConnectorEndTaggedValue(connectorEnd,taggedValueName)
getConnectorEndTaggedValue = ""
if not connectorEnd is nothing and Len(taggedValueName) > 0 then
dim existingTaggedValue as EA.RoleTag
dim i
for i = 0 to connectorEnd.TaggedValues.Count - 1
set existingTaggedValue = connectorEnd.TaggedValues.GetAt(i)
if existingTaggedValue.Tag = taggedValueName then
getConnectorEndTaggedValue = existingTaggedValue.Value
end if
next
end if
end function
function iso8601date(str)
iso8601date = ""
if Len(str) >= 10 then
iso8601date = Mid(str,7,4) & "-" & Mid(str,4,2) & "-" & Mid(str,1,2)
end if
end function
function readutf8(str)
' make string utf-8
Dim txt, res, tegn, utegn, vtegn, wtegn, xtegn, i
Dim c3, c4, c5, c6, c7, ca, e2
readutf8 = ""
'exit function
'txt = Trim(str)
txt = str
c3 = 195 ' vanligste startbyte for utf8
c4 = 196
c5 = 197
c6 = 198
c7 = 199
ca = 202
e2 = 226
' c3 = 195 b6 = 182 ö
' c3 = 195 a1 = 161 á
' c5 = 197 8b = 139 ŋ
' loop gjennom alle tegn
res = ""
i = 0
While i < Len(txt)
i = i + 1
tegn = Mid(txt,i,1)
' Repository.WriteOutput "Script", "readutf8: i=" & i & " tegn=" & tegn,0
Select case int(AscW(tegn))
Case c3
'Repository.WriteOutput "Script", "readutf8: c3A i=" & i & " tegn=" & tegn & "int(AscW(tegn))=" & int(AscW(tegn)) ,0
'Repository.WriteOutput "Script", "readutf8: c3B int(AscW((Mid(txt,i+1,1)))=" & int(AscW(Mid(txt,i+1,1))) ,0
i = i + 1
Select case int(AscW(Mid(txt,i,1)))
Case 134
res=res+"Æ"
Case 152
res=res+"Ø"
Case 732
res=res+"Ø"
Case 133
res=res+"Å"
Case 8230
res=res+"Å"
Case 166
res=res+"æ"
Case 184
res=res+"ø"
Case 165
res=res+"å"
Case 129
res=res+"Á"
Case 161
res=res+"á"
Case 182
res=res+"ö"
Case else
utegn = int(AscW(tegn)) & 511
vtegn = utegn * 64
wtegn = int(AscW(Mid(txt,i+1,1))) & 1023
xtegn = wtegn
Repository.WriteOutput "Script", "readutf8: c3 i=" & i & " tegn=" & tegn & " " & int(AscW(Mid(txt,i,1))) & " -> " & utegn & " + " & vtegn & " + " & wtegn & " + " & xtegn & " + " & res & " " & AscW(vtegn)+AscW(xtegn),0
' res=res+Chr(AscW(vtegn)+AscW(xtegn))
res=res+"Ã"+Mid(txt,i,1)
End Select
'Case c4
Case c5
'Repository.WriteOutput "Script", "readutf8: c5A i=" & i & " tegn=" & tegn & "int(AscW(tegn))=" & int(AscW(tegn)) ,0
'Repository.WriteOutput "Script", "readutf8: c5B int(AscW((Mid(txt,i+1,1)))=" & int(AscW(Mid(txt,i+1,1))) ,0
i = i + 1
Select case int(AscW(Mid(txt,i,1)))
Case 160
res=res+"Š"
Case 161
res=res+"š"
Case 138
res=res+"Ŋ"
Case 139
res=res+"ŋ"
' Case 8249
' res=res+"ŋ"
Case else
utegn = int(AscW(tegn)) & 511
vtegn = utegn * 64
wtegn = int(AscW(Mid(txt,i+1,1))) & 1023
xtegn = wtegn
Repository.WriteOutput "Script", "readutf8: c5 i=" & i & " tegn=" & tegn & " " & Mid(txt,i,1) & " " & int(AscW(Mid(txt,i,1))) & " -> " & utegn & " + " & vtegn & " + " & wtegn & " + " & xtegn & " + " & res & " " & AscW(vtegn)+AscW(xtegn),0
' res=res+Chr(AscW(vtegn)+AscW(xtegn))
res=res+"Ã"+Mid(txt,i,1)
End Select
'Case c6
'Case c7
'Case ca
Case e2
' + 80 + 93 = "en dash" = halv fonthøyde, ( + 80 + 94 = "em dash" = full fonthøyde)
i = i + 2
res=res+"–"
Case else
res=res+tegn
End Select
Wend
readutf8 = res
End function
makeAbstract