archestry_lookup 0.0.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (39) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +2 -0
  3. data/.gitlab-ci.yml +1 -0
  4. data/Gemfile +3 -0
  5. data/archestry_lookup.gemspec +29 -0
  6. data/lib/archestry_lookup.rb +45 -0
  7. data/lib/context/_refactor_dialog/constructors/DockedGroupings2AppFunctions.rb +28 -0
  8. data/lib/context/_refactor_dialog/constructors/Element2ModSend.rb +28 -0
  9. data/lib/context/_refactor_dialog/constructors/ElementsInElements.rb +29 -0
  10. data/lib/context/_refactor_dialog/data/1.ModReceive2GetData.rb +29 -0
  11. data/lib/context/_refactor_dialog/data/2.GetData2Elements.rb +29 -0
  12. data/lib/context/_refactor_dialog/data/3.GenData2Dest.rb +29 -0
  13. data/lib/context/_refactor_dialog/data/4.Results2GenData.rb +29 -0
  14. data/lib/context/_refactor_dialog/folder_lookup.rb +36 -0
  15. data/lib/context/_refactor_dialog/functional/1.Expect2Events.rb +28 -0
  16. data/lib/context/_refactor_dialog/functional/2.1.Events2AppEvent.rb +28 -0
  17. data/lib/context/_refactor_dialog/functional/2.2.1.Events2ModReceive.rb +28 -0
  18. data/lib/context/_refactor_dialog/functional/2.2.2.ModReceive2AppEvent.rb +28 -0
  19. data/lib/context/_refactor_dialog/functional/3.Appevent2EventBus.rb +28 -0
  20. data/lib/context/_refactor_dialog/functional/4.1.AppEvent2Elements.rb +28 -0
  21. data/lib/context/_refactor_dialog/functional/4.2.Elements2AppEvent.rb +28 -0
  22. data/lib/context/_refactor_dialog/functional/5.1.Element2ModElements.rb +28 -0
  23. data/lib/context/_refactor_dialog/functional/5.2.Element2ModSend.rb +27 -0
  24. data/lib/context/_refactor_dialog/functional/6.ModElementsSpecs.rb +28 -0
  25. data/lib/context/_refactor_dialog/functional/7.ElementChains.rb +28 -0
  26. data/lib/context/_refactor_dialog/main.rb +69 -0
  27. data/lib/context/archestry/library.rb +53 -0
  28. data/lib/context/archestry/prepost.rb +39 -0
  29. data/lib/objects/_old.rb +43 -0
  30. data/lib/objects/lookup.rb +152 -0
  31. data/lib/schema/schema.rb +38 -0
  32. data/lib/sql/dbhandlers.rb +81 -0
  33. data/lib/sql/lookup_mfv.rb +113 -0
  34. data/lib/sql/pre.rb +51 -0
  35. data/lib/sql/view2ModelElements.rb +227 -0
  36. data/lib/tooling/hash.rb +17 -0
  37. data/lib/tooling/log.rb +49 -0
  38. data/license.txt +428 -0
  39. metadata +123 -0
@@ -0,0 +1,28 @@
1
+ ######## ####### ######## ####### ######## ########
2
+ ## / / / / License \ \ \ \
3
+ ## Copyleft culture, Copyright (C) is prohibited here
4
+ ## This work is licensed under a CC BY-SA 4.0
5
+ ## Creative Commons Attribution-ShareAlike 4.0 License
6
+ ## Refer to the http://creativecommons.org/licenses/by-sa/4.0/
7
+ ######## ####### ######## ####### ######## ########
8
+ ## / / / / Code Climate \ \ \ \
9
+ ## Language = ruby
10
+ ## Indent = space; 4 chars;
11
+ ######## ####### ######## ####### ######## ########
12
+ module ArchestryLookup
13
+ module Lookup
14
+ class << self
15
+
16
+ def lookup_functional_ElementChains(args, state, viewId, viewType)
17
+ queryName = __method__.to_s; queryName.slice! 'lookup_functional_'; queryName.to_sym
18
+ args[:dialectLookupQuery] = {queryName: queryName, cClass: 'TriggeringRelationship',
19
+ fClass: 'ApplicationFunction', fFqn: "#{state[:myAppName]}ElementSend*",
20
+ tClass: 'ApplicationFunction', tFqn: "#{state[:myAppName]}ElementSend*" }
21
+
22
+ dialectLookup(args, state, viewId, viewType)
23
+ dialectRepack(args, state, viewId, viewType, queryName)
24
+ end
25
+
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,69 @@
1
+ ######## ####### ######## ####### ######## ########
2
+ ## / / / / License \ \ \ \
3
+ ## Copyleft culture, Copyright (C) is prohibited here
4
+ ## This work is licensed under a CC BY-SA 4.0
5
+ ## Creative Commons Attribution-ShareAlike 4.0 License
6
+ ## Refer to the http://creativecommons.org/licenses/by-sa/4.0/
7
+ ######## ####### ######## ####### ######## ########
8
+ ## / / / / Code Climate \ \ \ \
9
+ ## Language = ruby
10
+ ## Indent = space; 4 chars;
11
+ ######## ####### ######## ####### ######## ########
12
+ module ArchestryLookup
13
+ module Lookup
14
+ class << self
15
+
16
+ def dialog_lookup_main(args, state)
17
+ dialog_lookup_main_constructor(args, state)
18
+ end
19
+
20
+
21
+ def dialog_lookup_main_constructor(args, state)
22
+ args[:stages][state[:dialectFolder]] = {codegenGlobal: {}, codegenPerView: {}, x: {}, panView: {lookup: {}}, perView: {}, constructor: {}}
23
+ ###_constructors views
24
+ folderId = state[:dbhandler].execute("select id from folders where name in ('_constructors')")[0][0]
25
+ state[:dbhandler].execute("select folder_id, folder_version, model_version from folders_in_model where parent_folder_id in ('#{folderId}') and model_version = (select max(model_version) from folders_in_model where parent_folder_id in ('#{folderId}')) and folder_version = (select max(folder_version) from folders_in_model where parent_folder_id in ('#{folderId}'))").each do |conFolder|
26
+
27
+ state[:dbhandler].execute("select view_id as view_id2, view_version, model_version from views_in_model where parent_folder_id in ('#{conFolder[0]}') and model_version = (select max(model_version) from views_in_model where view_id in (view_id2))") do |row|
28
+ viewAtr = state[:dbhandler].execute("select name, version from views where id in ('#{row[0]}') and version = (select max(version) from views where id in ('#{row[0]}'))")
29
+ id = row[0].tr("-", "_")
30
+
31
+ args[:con_views][id] ||= {}
32
+ args[:con_views][id][:version] = row[1]
33
+ args[:con_views][id][:name] = state[:dialectFolder]
34
+ Dialog.logger.info "ArchestryLookup constructor view '#{viewAtr[0][0]}' (id #{id}, view ver.#{row[1]}, model ver.#{row[2]}) suits for me!"
35
+ end
36
+ end
37
+ end
38
+
39
+ def dialog_lookup_post(args, state)
40
+ args[:con_views].each do |viewId, _viewProps|
41
+ viewType = :constructors
42
+ lookup_constructors_DockedGroupings2AppFunctions(args, state, viewId, viewType)
43
+ lookup_constructors_Element2ModSend(args, state, viewId, viewType)
44
+ lookup_constructors_ElementsInElements(args, state, viewId, viewType)
45
+ end
46
+
47
+ args[:views].each do |viewId, viewProps|
48
+ viewType = :perView
49
+ ArchestryLookup.logger.debug "ArchestryLookup_lookup RUN instance '#{state[:dialectFolder]}' view '#{viewProps[:name]}' ver.#{viewProps[:version]}"
50
+ ###functional
51
+ lookupStruct = {'functional' => [
52
+ 'Expect2Events', 'Events2AppEvent', 'Events2ModReceive', 'ModReceive2AppEvent',
53
+ 'Appevent2EventBus', 'AppEvent2Elements', 'Elements2AppEvent', 'Element2ModElements',
54
+ 'Element2ModSend', 'ModElementsSpecs', 'ElementChains']}
55
+ #1
56
+ lookup_run(args, lookupStruct, state, viewId, viewType)
57
+
58
+ ###data
59
+ lookupStruct = {'data' => [
60
+ 'ModReceive2GetData', 'GetData2Elements', 'GenData2Dest', 'Results2GenData']}
61
+ #1
62
+ lookup_run(args, lookupStruct, state, viewId, viewType)
63
+ ###
64
+ end
65
+ end
66
+
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,53 @@
1
+ ######## ####### ######## ####### ######## ########
2
+ ## / / / / License \ \ \ \
3
+ ## Copyleft culture, Copyright (C) is prohibited here
4
+ ## This work is licensed under a CC BY-SA 4.0
5
+ ## Creative Commons Attribution-ShareAlike 4.0 License
6
+ ## Refer to the http://creativecommons.org/licenses/by-sa/4.0/
7
+ ######## ####### ######## ####### ######## ########
8
+ ## / / / / Code Climate \ \ \ \
9
+ ## Language = ruby
10
+ ## Indent = space; 4 chars;
11
+ ######## ####### ######## ####### ######## ########
12
+ module ArchestryLookup
13
+ module Schema
14
+ class << self
15
+
16
+ def getObjLookupSchema
17
+ lookupQuery = {}
18
+ lookupQuery[:all] = {cClass: '*',
19
+ fClass: '*', fPropsK: "*", fPropsV: "*",
20
+ tClass: '*', tPropsK: "*", tPropsV: "*" }
21
+
22
+ lookupQuery[:app] = {cClass: '*',
23
+ fClass: 'Application*', fPropsK: "*", fPropsV: "*",
24
+ tClass: 'Application*', tPropsK: "*", tPropsV: "*" }
25
+
26
+ lookupQuery[:archdevops] = {cClass: '*',
27
+ fClass: 'ArchDevOps*', fPropsK: "*", fPropsV: "*",
28
+ tClass: 'ArchDevOps*', tPropsK: "*", tPropsV: "*" }
29
+
30
+ lookupQuery[:biz] = {cClass: '*',
31
+ fClass: 'Business*', fPropsK: "*", fPropsV: "*",
32
+ tClass: 'Business*', tPropsK: "*", tPropsV: "*" }
33
+
34
+ lookupQuery[:data] = {cClass: '*',
35
+ fClass: 'Data*', fPropsK: "*", fPropsV: "*",
36
+ tClass: 'Data*', tPropsK: "*", tPropsV: "*" }
37
+
38
+ lookupQuery[:tech] = {cClass: '*',
39
+ fClass: 'Technology*', fPropsK: "*", fPropsV: "*",
40
+ tClass: 'Technology*', tPropsK: "*", tPropsV: "*" }
41
+
42
+ lookupQuery[:x5] = {cClass: '*',
43
+ fClass: 'X5*', fPropsK: "*", fPropsV: "*",
44
+ tClass: 'X5*', tPropsK: "*", tPropsV: "*" }
45
+
46
+
47
+ lookupQuery
48
+
49
+ end
50
+
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,39 @@
1
+ ######## ####### ######## ####### ######## ########
2
+ ## / / / / License \ \ \ \
3
+ ## Copyleft culture, Copyright (C) is prohibited here
4
+ ## This work is licensed under a CC BY-SA 4.0
5
+ ## Creative Commons Attribution-ShareAlike 4.0 License
6
+ ## Refer to the http://creativecommons.org/licenses/by-sa/4.0/
7
+ ######## ####### ######## ####### ######## ########
8
+ ## / / / / Code Climate \ \ \ \
9
+ ## Language = ruby
10
+ ## Indent = space; 4 chars;
11
+ ######## ####### ######## ####### ######## ########
12
+ module ArchestryLookup
13
+ module Objects
14
+ class << self
15
+
16
+ def lookup_pre(args, state)
17
+ true
18
+ end
19
+
20
+ def lookup_post(args, state)
21
+ true
22
+ end
23
+
24
+
25
+ def lookup_post2(args, state)
26
+ # pp args[:folders]
27
+ args[:views][:mtype].each do |modelType, ids|
28
+ ids.each do |id|
29
+ args[:views][:id][id].each do |viewId, viewProps|
30
+ ArchestryLookup.logger.debug "ArchestryLookup_lookup RUN instance '' view '#{viewProps}' ver."
31
+ lookup_run(args, ArchestryLookup::Schema.getObjLookupSchema, state, modelType, id)
32
+ end
33
+ end
34
+ end
35
+ end
36
+
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,43 @@
1
+ ######## ####### ######## ####### ######## ########
2
+ ## / / / / License \ \ \ \
3
+ ## Copyleft culture, Copyright (C) is prohibited here
4
+ ## This work is licensed under a CC BY-SA 4.0
5
+ ## Creative Commons Attribution-ShareAlike 4.0 License
6
+ ## Refer to the http://creativecommons.org/licenses/by-sa/4.0/
7
+ ######## ####### ######## ####### ######## ########
8
+ ## / / / / Code Climate \ \ \ \
9
+ ## Language = ruby
10
+ ## Indent = space; 4 chars;
11
+ ######## ####### ######## ####### ######## ########
12
+ module ArchestryLookup
13
+ module Objects
14
+ class << self
15
+
16
+ def getProp(_args,state,conProp,direction)
17
+ rows = {}
18
+ case direction
19
+ when 'from'
20
+ eID = conProp[:fEID]
21
+ eVer = conProp[:fEVer]
22
+ when 'to'
23
+ eID = conProp[:tEID]
24
+ eVer = conProp[:tEVer]
25
+ end
26
+
27
+ ArchestryLookup::Sql.sqlQuery(state, "
28
+ select name, value
29
+ from properties
30
+ where parent_id like '#{eID}' AND
31
+ parent_version = '#{eVer}' AND
32
+ name NOT LIKE 'fqn'
33
+ ") do |row|
34
+ # ArchestryLookup.logger.debug "### ROW #{eID} #: #{row}"
35
+ rows[row[0].to_sym] = row[1]
36
+ end
37
+ return rows if not rows.empty?
38
+ end
39
+
40
+
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,152 @@
1
+ ######## ####### ######## ####### ######## ########
2
+ ## / / / / License \ \ \ \
3
+ ## Copyleft culture, Copyright (C) is prohibited here
4
+ ## This work is licensed under a CC BY-SA 4.0
5
+ ## Creative Commons Attribution-ShareAlike 4.0 License
6
+ ## Refer to the http://creativecommons.org/licenses/by-sa/4.0/
7
+ ######## ####### ######## ####### ######## ########
8
+ ## / / / / Code Climate \ \ \ \
9
+ ## Language = ruby
10
+ ## Indent = space; 4 chars;
11
+ ######## ####### ######## ####### ######## ########
12
+ module ArchestryLookup
13
+ module Objects
14
+ class << self
15
+
16
+
17
+ def archestryLookupView(args, lookupType, lookup, state, modelType, viewId)
18
+ if args[:objects][:view][modelType][viewId]
19
+ if lookup[:cClass] == '*'
20
+ args[:objects][:view][modelType][viewId][:links].each do |cClass, cProp|
21
+ archestryLookupViewRun(args, state, lookupType, lookup, modelType, viewId, cClass)
22
+ end
23
+ else
24
+ archestryLookupViewRun(args, state, lookupType, lookup, modelType, viewId, lookup[:cClass])
25
+ end
26
+ end
27
+ end
28
+
29
+
30
+ def archestryLookupViewRun(args, state, lookupType, lookup, modelType, viewId, cClass)
31
+ queryName = lookupType
32
+ if args[:objects][:view][modelType][viewId][:links][cClass].is_a?(Hash)
33
+ args[:objects][:view][modelType][viewId][:links][cClass].each do |_conPairId, conProp|
34
+
35
+ lookup[:fClass] == '*' ? fClass = /^*/ : fClass = /^#{lookup[:fClass]}/
36
+ lookup[:tClass] == '*' ? tClass = /^*/ : tClass = /^#{lookup[:tClass]}/
37
+
38
+ fPropMod = []
39
+ fPropMod << :fPropsKAll if lookup[:fPropsK] == '*'
40
+ fPropMod << :fPropsVAll if lookup[:fPropsV] == '*'
41
+ fPropMod << :fPropsAll if fPropMod.include?(:fPropsKAll) and fPropMod.include?(:fPropsVAll)
42
+
43
+ tPropMod = []
44
+ tPropMod << :tPropsKAll if lookup[:tPropsK] == '*'
45
+ tPropMod << :tPropsVAll if lookup[:tPropsV] == '*'
46
+ tPropMod << :tPropsAll if tPropMod.include?(:tPropsKAll) and tPropMod.include?(:tPropsVAll)
47
+
48
+ if fPropMod.include?(:fPropsKAll)
49
+ fPropsFiltered = true
50
+ elsif fPropMod.include?(:fPropsVAll)
51
+ fPropsFiltered = true if conProp[:fProps].has_key?(lookup[:fPropsK])
52
+ else
53
+ fPropsFiltered = true if conProp[:fProps][lookup[:fPropsK]] =~ /^#{lookup[:fPropsV]}/
54
+ end
55
+
56
+ if tPropMod.include?(:tPropsKAll)
57
+ tPropsFiltered = true
58
+ elsif tPropMod.include?(:tPropsVAll)
59
+ tPropsFiltered = true if conProp[:tProps].has_key?(lookup[:tPropsK])
60
+ else
61
+ # tPropsFiltered = true if conProp[:tProps][lookup[:tPropsK]] =~ /^#{lookup[:tPropsV]}/
62
+ end
63
+
64
+
65
+ if conProp[:viewID] == viewId and
66
+ conProp[:fClass] =~ fClass and
67
+ conProp[:tClass] =~ tClass and
68
+ fPropsFiltered == true and
69
+ tPropsFiltered == true
70
+ makeStageView(args, state, conProp, modelType, viewId, queryName, lookup, cClass)
71
+ end
72
+ end
73
+ end
74
+ end
75
+
76
+
77
+ def makeStageView(args, state, conProp, modelType, viewId, queryName, lookup, cClass)
78
+ conProp[:cClass] = cClass
79
+
80
+ if lookup.has_key?(:fPropKey)
81
+ conProp[:fProp][lookup[:fPropKey]] == lookup[:fPropValue] ? store = true : store = false
82
+ else
83
+ store = true
84
+ end
85
+
86
+ if store == true
87
+ # hash_fName = Digest::SHA256.hexdigest("#{conProp[:fName]}")[0..20]
88
+ hash_tName = Digest::SHA256.hexdigest("#{conProp[:tName]}")[0..20]
89
+ hash_fName_fId_tId = Digest::SHA256.hexdigest("#{conProp[:fName]}#{conProp[:fOID]}#{conProp[:tOID]}")[0..20]
90
+ #
91
+ # if conProp[:fProps].is_a?(Hash) and conProp[:fProps].has_key?('listenIP') and conProp[:fProps]['listenIP'] == '1.1.1.1'
92
+ # pp "fProps:: conProp:#{conProp}"
93
+ # elsif conProp[:tProps].is_a?(Hash) and conProp[:tProps].has_key?('listenIP')
94
+ # pp "tProps:: conProp:#{conProp}"
95
+ # end
96
+
97
+ args[:stages][:view][modelType] ||= {}
98
+ args[:stages][:view][modelType][viewId] ||= {}
99
+ args[:stages][:view][modelType][viewId][queryName] ||= {}
100
+ args[:stages][:view][modelType][viewId][queryName][:lookup] ||= {}
101
+ args[:stages][:view][modelType][viewId][queryName][:lookup][hash_tName] ||= {}
102
+ args[:stages][:view][modelType][viewId][queryName][:lookup][hash_tName][hash_fName_fId_tId] = conProp
103
+ end
104
+ end
105
+
106
+
107
+ def archestryRepack(args, lookup, state, modelType, viewId, viewType)
108
+ args[:stages].each do |k, v|
109
+ a = args[:stages][k]
110
+ pp viewType
111
+ unless a.has_key?(viewType) and a.has_key?(viewType) and not a[viewId].nil?
112
+ base = false
113
+ else
114
+ base = a[viewId][queryName]
115
+ end
116
+ end
117
+
118
+ if base.is_a?(Hash)
119
+ repackNames = [:fProps, :tProps, :fOID, :tOID, :fEID, :tEID]
120
+ base[:repack] = {}
121
+ repackNames.each do |repackName|
122
+ res = {}
123
+ base[:repack][repackName] ||= {}
124
+ base[:lookup].each do |_tName, hash_tNameProp|
125
+ hash_tNameProp.each do |_fName, hash_fNameProp|
126
+ res[hash_fNameProp[repackName]] = hash_fNameProp
127
+ end
128
+ end
129
+
130
+ a[viewId][queryName][:repack][repackName] = res
131
+ end
132
+ end
133
+ end
134
+
135
+
136
+ def lookupDebug(name, prop)
137
+ ArchestryLookup.logger.debug "### #{name} :: F:: '#{prop[:fName]}' fqn:#{prop[:fProps]} o:#{prop[:fOID]} e:#{prop[:fEID]} p '#{prop[:fProp]}' :: T :: '#{prop[:tName]}' fqn:#{prop[:tProps]} o:#{prop[:tOID]} e:#{prop[:tEID]} p '#{prop[:tProp]}'"
138
+ end
139
+
140
+
141
+ def lookup_run(args, lookupStruct, state, modelType, viewId)
142
+ lookupStruct.each do |lookupType, lookup|
143
+ ArchestryLookup.logger.debug "### ArchestryLookup_lookup call - type::#{lookupType}, lookupStruct::#{lookupStruct}"
144
+ archestryLookupView(args, lookupType, lookup, state, modelType, viewId)
145
+ # archestryRepack(args, lookupType, lookup, state, modelType, viewId)
146
+ end
147
+ end
148
+
149
+
150
+ end
151
+ end
152
+ end
@@ -0,0 +1,38 @@
1
+ ######## ####### ######## ####### ######## ########
2
+ ## / / / / License \ \ \ \
3
+ ## Copyleft culture, Copyright (C) is prohibited here
4
+ ## This work is licensed under a CC BY-SA 4.0
5
+ ## Creative Commons Attribution-ShareAlike 4.0 License
6
+ ## Refer to the http://creativecommons.org/licenses/by-sa/4.0/
7
+ ######## ####### ######## ####### ######## ########
8
+ ## / / / / Code Climate \ \ \ \
9
+ ## Language = ruby
10
+ ## Indent = space; 4 chars;
11
+ ######## ####### ######## ####### ######## ########
12
+
13
+ module ArchestryLookup
14
+ module Schema
15
+ class << self
16
+
17
+ def getMFVSchema
18
+ args = Hash.recursive
19
+ args[:models] = {:schema => [:name, :type, :ver, :cby, :con]}
20
+ args[:folders] = {:schema => [:name, :type, :ver, :cby, :con, :pid, :rtype]}
21
+ args[:views] = {:schema => [:name, :viewpoint, :ver, :cby, :con]}
22
+ args[:objects] = {:schema => [:view, :objfolder]}
23
+ args[:stages] = {:schema => [:view, :objfolder]}
24
+
25
+ args
26
+ end
27
+
28
+ def getElementsSchema
29
+ args = Hash.recursive
30
+ args[:elements] = {:schema => [:mID, :mName, :mType, :fID, :fName, :vID, :vName, :vPoint, :rClass],
31
+ :schemaDir => [:eClass, :oCby, :oCon]}
32
+ args
33
+ end
34
+
35
+
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,81 @@
1
+ ######## ####### ######## ####### ######## ########
2
+ ## / / / / License \ \ \ \
3
+ ## Copyleft culture, Copyright (C) is prohibited here
4
+ ## This work is licensed under a CC BY-SA 4.0
5
+ ## Creative Commons Attribution-ShareAlike 4.0 License
6
+ ## Refer to the http://creativecommons.org/licenses/by-sa/4.0/
7
+ ######## ####### ######## ####### ######## ########
8
+ ## / / / / Code Climate \ \ \ \
9
+ ## Language = ruby
10
+ ## Indent = space; 4 chars;
11
+ ######## ####### ######## ####### ######## ########
12
+ module ArchestryLookup
13
+ module Sql
14
+ class << self
15
+
16
+ def sqlQuery(state, sql)
17
+
18
+ # p "##SQL:: #{sql}"
19
+ res = {}
20
+
21
+ case state[:dbtype]
22
+ when :sqlite
23
+ res = sqliteAnswerMap(state[:db][:handler].execute2(sql))
24
+ when :pg
25
+ res = pgAnswerMap(state[:db][:handler].exec(sql))
26
+ end
27
+
28
+ # p "## SQL_RES:: #{res}"
29
+ res
30
+ end
31
+
32
+ def sqliteAnswerMap(answer)
33
+ res = {}
34
+ m = {}
35
+ n = 0
36
+ j = 0
37
+ answer.each do |result|
38
+ if n == 0
39
+ # puts "##keys::#{result}"
40
+ i = 0
41
+ result.each do |v|
42
+ m[i] = v.to_sym
43
+ i += 1
44
+ end
45
+ else
46
+ # puts "##values::#{result}"
47
+ i = 0
48
+ result.each do |v|
49
+ res[j] ||= {}
50
+ res[j][m[i]] = v
51
+ i += 1
52
+ end
53
+ j += 1
54
+ end
55
+ n += 1
56
+ end
57
+
58
+ res
59
+ end
60
+
61
+ def pgAnswerMap(answer)
62
+ res = {}
63
+ m = {}
64
+ i = 0
65
+ answer.each do |result|
66
+ # puts "##values::#{result}"
67
+ result.each do |k, v|
68
+ res[i] ||= {}
69
+ res[i][k.to_sym] = v
70
+ end
71
+ i += 1
72
+ end
73
+
74
+ res
75
+ end
76
+
77
+
78
+
79
+ end
80
+ end
81
+ end
@@ -0,0 +1,113 @@
1
+ ######## ####### ######## ####### ######## ########
2
+ ## / / / / License \ \ \ \
3
+ ## Copyleft culture, Copyright (C) is prohibited here
4
+ ## This work is licensed under a CC BY-SA 4.0
5
+ ## Creative Commons Attribution-ShareAlike 4.0 License
6
+ ## Refer to the http://creativecommons.org/licenses/by-sa/4.0/
7
+ ######## ####### ######## ####### ######## ########
8
+ ## / / / / Code Climate \ \ \ \
9
+ ## Language = ruby
10
+ ## Indent = space; 4 chars;
11
+ ######## ####### ######## ####### ######## ########
12
+ module ArchestryLookup
13
+ module Sql
14
+ class << self
15
+
16
+ #TODO: flags 'skip' in props
17
+ #
18
+
19
+ def makeInternalLookups(args, keyType, valueType, container, id)
20
+ args[keyType][valueType] ||= {}
21
+ args[keyType][valueType][:id] ||= {}
22
+ args[keyType][valueType][:id][id] = container
23
+ args[valueType][:schema].each do |k|
24
+ args[keyType][valueType][k] ||= {}
25
+ args[keyType][valueType][k][container[k]] ||= []
26
+ args[keyType][valueType][k][container[k]] << id
27
+ end
28
+ end
29
+
30
+
31
+ def archestry_model_lookup(args, state)
32
+ mfv = {}
33
+
34
+
35
+ sqlQuery(state, "SELECT m1.id as id, m1.name as name, m1.version as ver, m1.created_by as cby, m1.created_on as con FROM models as m1 WHERE version = (select max(m2.version) FROM models as m2 WHERE m1.id = m2.id)").each do |id, model|
36
+ sqlQuery(state, "SELECT p1.name, p1.value FROM properties as p1 WHERE p1.parent_id LIKE '#{model[:id]}' and p1.name LIKE 'modelType' and p1.parent_version = #{model[:ver]}").each do |id, type|
37
+ model[:type] = type[:value].to_sym
38
+
39
+ makeInternalLookups(args, :models, :models, model, model[:id])
40
+ args[:elements][:base][model[:type]][:id] ||= {}
41
+
42
+ if args[:models][:models][:id][model[:id]][:type] == :library or args[:models][:models][:id][model[:id]][:name] == state[:funcFolder]
43
+ ArchestryLookup.logger.info "Use model '#{model[:name]}' version #{model[:ver]} type '#{model[:type]}' created by '#{model[:cby]}' on #{model[:con]}"
44
+ mfv[:model] = model
45
+ getModelFolders(state, args, mfv)
46
+ end
47
+ end
48
+ end
49
+ end
50
+
51
+
52
+ def getFolderViews(args, state, mfv)
53
+ a = sqlQuery(state, "select view_id as id, model_version as mver FROM views_in_model as vm1
54
+ WHERE vm1.parent_folder_id in ('#{mfv[:folder][:id]}')
55
+ and vm1.model_version = (select max(vm2.model_version) FROM views_in_model as vm2 WHERE vm2.view_id in (vm1.view_id))").each do |k, viewInM|
56
+
57
+ viewAtr = sqlQuery(state, "select v1.id, v1.version as ver, v1.name, v1.viewpoint, v1.created_by as cby, v1.created_on as con FROM views as v1 WHERE id in ('#{viewInM[:id]}') and version = (select max(version) FROM views as v2 WHERE v2.id in ('#{viewInM[:id]}'))")
58
+
59
+ view = viewAtr[0]
60
+ # view[:tid]= view[:id].tr("-", "_")
61
+
62
+ makeInternalLookups(args, :views, :models, mfv[:model], view[:id])
63
+ makeInternalLookups(args, :views, :folders, mfv[:folder], view[:id])
64
+ makeInternalLookups(args, :views, :views, view, view[:id])
65
+
66
+ mfv[:view] = view
67
+ view[:viewpoint] == '' ? viewpoint = 'none' : viewpoint = view[:viewpoint]
68
+ ArchestryLookup.logger.info "Model '#{mfv[:model][:name]}' of type '#{mfv[:model][:type]}': view '#{view[:name]}' (id #{view[:id]}, view ver.#{view[:ver]}, model ver.#{mfv[:model][:ver]}) with viewpoint '#{viewpoint}' suits for me!"
69
+ getViewConnectionsFromView(args, state, mfv)
70
+ end
71
+ end
72
+
73
+
74
+ def getModelFolders(state, args, mfv)
75
+
76
+ args[:folders] ||={}
77
+
78
+ foldersInModel = sqlQuery(state, "select fm1.folder_id as id,
79
+ fm1.parent_folder_id as pid,
80
+ f1.name as name,
81
+ f1.type as type,
82
+ f1.version as ver,
83
+ f1.root_type as rtype,
84
+ f1.created_by as cby,
85
+ f1.created_on as con
86
+ FROM folders_in_model as fm1
87
+ INNER JOIN folders as f1 ON f1.id = fm1.folder_id and f1.version = (select max(f2.version) FROM folders as f2 WHERE f2.id = fm1.folder_id)
88
+ WHERE fm1.model_id in ('#{mfv[:model][:id]}')
89
+ and fm1.model_version = (select max(fm2.model_version) FROM folders_in_model as fm2 WHERE fm2.model_id LIKE '#{mfv[:model][:id]}')
90
+ ")
91
+
92
+ foldersInModel.each do |id, folder|
93
+ if folder[:rtype].to_i == 7 and folder[:type].to_i == 0
94
+
95
+ makeInternalLookups(args, :folders, :models, mfv[:model], folder[:id])
96
+ makeInternalLookups(args, :folders, :folders, folder, folder[:id])
97
+
98
+ mfv[:folder] = folder
99
+ getFolderViews(args, state, mfv)
100
+ # mod = :view
101
+ else
102
+ true
103
+ # p "This is Archestry core view '#{folder[:name]}' (type #{folder[:type]}, Root type #{folder[:rtype]})"
104
+ # mod = :objfolder
105
+ end
106
+
107
+ end
108
+
109
+ end
110
+
111
+ end
112
+ end
113
+ end
data/lib/sql/pre.rb ADDED
@@ -0,0 +1,51 @@
1
+ ######## ####### ######## ####### ######## ########
2
+ ## / / / / License \ \ \ \
3
+ ## Copyleft culture, Copyright (C) is prohibited here
4
+ ## This work is licensed under a CC BY-SA 4.0
5
+ ## Creative Commons Attribution-ShareAlike 4.0 License
6
+ ## Refer to the http://creativecommons.org/licenses/by-sa/4.0/
7
+ ######## ####### ######## ####### ######## ########
8
+ ## / / / / Code Climate \ \ \ \
9
+ ## Language = ruby
10
+ ## Indent = space; 4 chars;
11
+ ######## ####### ######## ####### ######## ########
12
+ module ArchestryLookup
13
+ module Sql
14
+ class << self
15
+
16
+
17
+
18
+ def preSql(state)
19
+ state[:db] = {}
20
+
21
+ case state[:dbtype]
22
+ when :sqlite
23
+ require 'sqlite3'
24
+ db = state[:dbprop][:filepath]
25
+ state[:db][:handler] = SQLite3::Database.new db
26
+ when :pg
27
+ require 'pg'
28
+ state[:db][:handler] = PG.connect( dbname: state[:dbprop][:database])
29
+ else
30
+ state[:dbtype] = :sqlite
31
+ require 'sqlite3'
32
+ db = "/tmp/archestry.sqlite"
33
+ state[:db][:handler] = SQLite3::Database.new db
34
+ end
35
+
36
+ case state[:myAppName]
37
+ when 'Dialog'
38
+ state[:db][:relSQL] = "and relationships.class in ('AggregationRelationship', 'TriggeringRelationship', 'FlowRelationship', 'AccessRelationship', 'SpecializationRelationship', 'CompositionRelationship', 'ServingRelationship', 'RealizationRelationship')"
39
+ state[:db][:elementsSQL] = "and (elements.class LIKE 'Application%' OR elements.class in ('DataObject', 'Grouping'))"
40
+ state[:db][:propSQL] = "AND properties.name LIKE 'fqn'"
41
+ when 'Archestry'
42
+ state[:db][:relSQL] = " "
43
+ state[:db][:elementsSQL] = ""
44
+ state[:db][:propSQL] = ""
45
+ end
46
+
47
+ end
48
+
49
+ end
50
+ end
51
+ end