tla-sbuilder 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (210) hide show
  1. checksums.yaml +7 -0
  2. data/README.md +328 -0
  3. data/VERSION +1 -0
  4. data/bin/sbuilder.rb +5 -0
  5. data/lib/cli/cli-customer.rb +420 -0
  6. data/lib/cli/cli-example.rb +92 -0
  7. data/lib/cli/cli-pet.rb +767 -0
  8. data/lib/cli/cli-text.rb +226 -0
  9. data/lib/cli/cli.rb +298 -0
  10. data/lib/sbuilder.rb +52 -0
  11. data/lib/sbuilder/constants.rb +72 -0
  12. data/lib/sbuilder/controller.rb +798 -0
  13. data/lib/sbuilder/default-sbuilder.yaml +372 -0
  14. data/lib/sbuilder/domain.rb +124 -0
  15. data/lib/sbuilder/domain_cardinality.rb +37 -0
  16. data/lib/sbuilder/domain_value.rb +81 -0
  17. data/lib/sbuilder/exception.rb +27 -0
  18. data/lib/sbuilder/extension_loader.rb +721 -0
  19. data/lib/sbuilder/factory.rb +234 -0
  20. data/lib/sbuilder/model.rb +356 -0
  21. data/lib/sbuilder/mustache/template.rb +125 -0
  22. data/lib/sbuilder/mustache/template_reader.rb +206 -0
  23. data/lib/sbuilder/mustache/template_reader_context.rb +371 -0
  24. data/lib/sbuilder/param_set.rb +132 -0
  25. data/lib/sbuilder/param_set_db.rb +20 -0
  26. data/lib/sbuilder/param_set_def.rb +57 -0
  27. data/lib/sbuilder/param_set_if.rb +68 -0
  28. data/lib/sbuilder/param_set_loader.rb +77 -0
  29. data/lib/sbuilder/param_set_loader_swagger.rb +424 -0
  30. data/lib/sbuilder/param_set_step.rb +62 -0
  31. data/lib/sbuilder/param_sets.rb +54 -0
  32. data/lib/sbuilder/parameter.rb +97 -0
  33. data/lib/sbuilder/parameter_container.rb +72 -0
  34. data/lib/sbuilder/parameter_dom.rb +70 -0
  35. data/lib/sbuilder/parameter_ref.rb +71 -0
  36. data/lib/sbuilder/resolver.rb +78 -0
  37. data/lib/sbuilder/resolver_loader.rb +79 -0
  38. data/lib/sbuilder/resolver_loader_yaml.rb +103 -0
  39. data/lib/sbuilder/resolver_rule.rb +36 -0
  40. data/lib/sbuilder/resolver_rule_match.rb +55 -0
  41. data/lib/sbuilder/resolver_rule_ref.rb +37 -0
  42. data/lib/utils/hash_inject.rb +12 -0
  43. data/lib/utils/logger.rb +80 -0
  44. data/lib/utils/netio.rb +58 -0
  45. data/lib/utils/string_inject.rb +10 -0
  46. data/lib/utils/version.rb +13 -0
  47. data/mustache/cfg/const_def.mustache +8 -0
  48. data/mustache/cfg/const_run.mustache +3 -0
  49. data/mustache/cfg/invariant-infrastructure-service.mustache +4 -0
  50. data/mustache/cfg/macro_run.mustache +6 -0
  51. data/mustache/cfg/module_footer.mustache +0 -0
  52. data/mustache/cfg/module_header.mustache +7 -0
  53. data/mustache/data-model-dump.mustache +19 -0
  54. data/mustache/data-model-footer.mustache +5 -0
  55. data/mustache/data-model-header.mustache +16 -0
  56. data/mustache/definition_types.mustache +40 -0
  57. data/mustache/domains.mustache +20 -0
  58. data/mustache/domains_assign.mustache +22 -0
  59. data/mustache/domains_run.mustache +21 -0
  60. data/mustache/extend/extend_assumptions.mustache +7 -0
  61. data/mustache/extend/extend_const.mustache +5 -0
  62. data/mustache/extend/extend_implementation.mustache +9 -0
  63. data/mustache/extend/extend_invariant.mustache +7 -0
  64. data/mustache/extend/extend_invariant_cfg.mustache +7 -0
  65. data/mustache/extend/extend_macros.mustache +19 -0
  66. data/mustache/extend/extend_operations.mustache +9 -0
  67. data/mustache/extend/extend_state.mustache +9 -0
  68. data/mustache/infrastructure-service-init.mustache +36 -0
  69. data/mustache/infrastructure-service-variables.mustache +10 -0
  70. data/mustache/interface_processes.mustache +38 -0
  71. data/mustache/interface_stubs_dummy.mustache +13 -0
  72. data/mustache/interface_types.mustache +52 -0
  73. data/mustache/markdown-header.mustache +24 -0
  74. data/mustache/markdown-toc.mustache +13 -0
  75. data/mustache/name_definition_type.mustache +5 -0
  76. data/mustache/name_domain.mustache +5 -0
  77. data/mustache/name_domain_value.mustache +5 -0
  78. data/mustache/name_domain_value_prefix.mustache +5 -0
  79. data/mustache/name_interface_response_type.mustache +6 -0
  80. data/mustache/name_interface_type.mustache +6 -0
  81. data/mustache/name_parameter_definition.mustache +5 -0
  82. data/mustache/name_parameter_type.mustache +6 -0
  83. data/mustache/name_process.mustache +6 -0
  84. data/mustache/name_type_invariant.mustache +5 -0
  85. data/mustache/name_variable.mustache +6 -0
  86. data/mustache/operator-infrastructure-service.mustache +13 -0
  87. data/mustache/possibility/module_extends.mustache +1 -0
  88. data/mustache/possibility/module_footer.mustache +1 -0
  89. data/mustache/possibility/module_header.mustache +8 -0
  90. data/mustache/possibility/possibility_definition.mustache +12 -0
  91. data/mustache/possibility/possibility_directive.mustache +1 -0
  92. data/mustache/possibility/possility_setup.mustache +28 -0
  93. data/mustache/setup/module_footer.mustache +1 -0
  94. data/mustache/setup/module_header.mustache +9 -0
  95. data/mustache/setup/operator_run.mustache +7 -0
  96. data/mustache/setup/operator_tick.mustache +2 -0
  97. data/mustache/setup/steps_run.mustache +22 -0
  98. data/mustache/setup/steps_run_bind_rule.mustache +51 -0
  99. data/mustache/setup/steps_run_bind_set.mustache +37 -0
  100. data/mustache/setup/steps_run_parameterBind.mustache +80 -0
  101. data/mustache/setup/steps_run_parameterExact.mustache +79 -0
  102. data/mustache/state_type_invariant-infrastructure-service.mustache +49 -0
  103. data/mustache/state_type_invariant.mustache +17 -0
  104. data/mustache/state_type_invariant_cfg.mustache +18 -0
  105. data/mustache/state_variables.mustache +20 -0
  106. data/mustache/tla/const_def.mustache +5 -0
  107. data/mustache/tla/const_run.mustache +3 -0
  108. data/mustache/tla/macro-infrastructure-service.mustache +14 -0
  109. data/mustache/tla/macro_run.mustache +40 -0
  110. data/mustache/tla/module_footer.mustache +2 -0
  111. data/mustache/tla/module_header.mustache +9 -0
  112. data/mustache/tla/operator_run.mustache +8 -0
  113. data/mustache/tla/operators-infrastructure-service.mustache +12 -0
  114. data/mustache/tla/plc_define_footer.mustache +1 -0
  115. data/mustache/tla/plc_define_header.mustache +1 -0
  116. data/mustache/tla/plc_define_run.mustache +59 -0
  117. data/mustache/tla/plc_footer.mustache +2 -0
  118. data/mustache/tla/plc_header.mustache +2 -0
  119. data/mustache/tla/plc_run_state.mustache +12 -0
  120. data/mustache/tla/plc_tail.mustache +8 -0
  121. data/mustache/tla/plc_translation.mustache +2 -0
  122. data/resources/schema/json_schema/draft-04.json +150 -0
  123. data/resources/schema/swagger/2.0/schema.json +1591 -0
  124. data/src-extend/README +2 -0
  125. data/src-extend/extend/extend_assumptions.mustache +7 -0
  126. data/src-extend/extend/extend_const.mustache +5 -0
  127. data/src-extend/extend/extend_implementation.mustache +9 -0
  128. data/src-extend/extend/extend_invariant.mustache +11 -0
  129. data/src-extend/extend/extend_invariant_cfg.mustache +7 -0
  130. data/src-extend/extend/extend_macros.mustache +19 -0
  131. data/src-extend/extend/extend_operations.mustache +9 -0
  132. data/src-extend/extend/extend_state.mustache +9 -0
  133. data/src-extend/extend_app/assumption +20 -0
  134. data/src-extend/extend_app/correctness +19 -0
  135. data/src-extend/extend_app/correctness.cfg +9 -0
  136. data/src-extend/extend_app/infrastructure +25 -0
  137. data/src-extend/extend_app/interface +11 -0
  138. data/src-extend/extend_app/operator +18 -0
  139. data/src-extend/extend_app/possibility +16 -0
  140. data/src-extend/extend_app/service +33 -0
  141. data/src-extend/extend_app/state +16 -0
  142. data/src-extend/extend_app/transaction +22 -0
  143. data/src/pet/assumption +29 -0
  144. data/src/pet/assumption_address_domains.tla +12 -0
  145. data/src/pet/assumption_domains.tla +16 -0
  146. data/src/pet/assumption_generic.tla +8 -0
  147. data/src/pet/assumption_id_domains.tla +2 -0
  148. data/src/pet/assumption_owner_domains.tla +14 -0
  149. data/src/pet/assumption_pet_domains.tla +16 -0
  150. data/src/pet/assumption_tag_domains.tla +13 -0
  151. data/src/pet/correctness +24 -0
  152. data/src/pet/correctness.cfg +9 -0
  153. data/src/pet/correctness_coherent_owner_address.tla +6 -0
  154. data/src/pet/correctness_pet_name.tla +4 -0
  155. data/src/pet/correctness_ref_tag.tla +13 -0
  156. data/src/pet/correctness_type_invariants.tla +12 -0
  157. data/src/pet/correctness_unique_pet.tla +3 -0
  158. data/src/pet/correctness_unique_tag.tla +3 -0
  159. data/src/pet/docs/Petstore.md +117 -0
  160. data/src/pet/extend/extend_assumptions.mustache +7 -0
  161. data/src/pet/extend/extend_implementation.mustache +9 -0
  162. data/src/pet/extend/extend_invariant.mustache +11 -0
  163. data/src/pet/extend/extend_invariant_cfg.mustache +7 -0
  164. data/src/pet/extend/extend_macros.mustache +19 -0
  165. data/src/pet/extend/extend_operations.mustache +9 -0
  166. data/src/pet/extend/extend_state.mustache +9 -0
  167. data/src/pet/infrastructure +25 -0
  168. data/src/pet/infrastructure_id_get.tla +24 -0
  169. data/src/pet/interface +12 -0
  170. data/src/pet/interface_delete_pet.tla +5 -0
  171. data/src/pet/interface_get_pet.tla +4 -0
  172. data/src/pet/interface_post_pet.tla +5 -0
  173. data/src/pet/interface_post_tag.tla +5 -0
  174. data/src/pet/interface_put_tag.tla +3 -0
  175. data/src/pet/operator +30 -0
  176. data/src/pet/operator_find_tag_by_owner_name.tla +1 -0
  177. data/src/pet/operator_get_pet.tla +4 -0
  178. data/src/pet/operator_get_pet_by_tag.tla +4 -0
  179. data/src/pet/operator_get_tag.tla +10 -0
  180. data/src/pet/operator_new_owner.tla +3 -0
  181. data/src/pet/operator_new_pet.tla +13 -0
  182. data/src/pet/operator_new_tag.tla +3 -0
  183. data/src/pet/operator_next_pet_id.tla +3 -0
  184. data/src/pet/operator_responses.tla +8 -0
  185. data/src/pet/operator_tag_exists.tla +2 -0
  186. data/src/pet/operator_tag_owner_validated.tla +2 -0
  187. data/src/pet/operator_tag_referenced.tla +4 -0
  188. data/src/pet/operator_valid_owner.tla +17 -0
  189. data/src/pet/operator_valid_pet.tla +6 -0
  190. data/src/pet/operator_valid_tag.tla +5 -0
  191. data/src/pet/possibility +18 -0
  192. data/src/pet/possibility_at_least_two_tags.tla +12 -0
  193. data/src/pet/possibility_invalid_tag_address.tla +8 -0
  194. data/src/pet/service +35 -0
  195. data/src/pet/service_pet_delete.tla +11 -0
  196. data/src/pet/service_pet_get.tla +27 -0
  197. data/src/pet/service_pet_post.tla +78 -0
  198. data/src/pet/service_tag_post.tla +53 -0
  199. data/src/pet/service_tag_put.tla +82 -0
  200. data/src/pet/state +16 -0
  201. data/src/pet/state_infra.tla +6 -0
  202. data/src/pet/state_pet.tla +5 -0
  203. data/src/pet/state_tag_id.tla +2 -0
  204. data/src/pet/transaction +23 -0
  205. data/src/pet/transaction_delete_pet.tla +13 -0
  206. data/src/pet/transaction_enter_pet.tla +13 -0
  207. data/src/pet/transaction_enter_tag.tla +56 -0
  208. data/src/pet/transaction_error.tla +23 -0
  209. data/tla-sbuilder.gemspec +43 -0
  210. metadata +353 -0
@@ -0,0 +1,234 @@
1
+
2
+ module Sbuilder
3
+
4
+ # signleton class
5
+ class Factory
6
+
7
+ @@singleton=nil # initiallly no factory object
8
+ attr_reader :options # remembers options
9
+
10
+ attr_reader :paramSetLoaders # hash[Name->Class:ParamSetLoader]
11
+ attr_reader :mapperRules # hash[Name->Class:ResolverRule]
12
+ attr_reader :mapperLoaders # hash[Name->Class:ResolverLoader]
13
+ attr_reader :parameters # hash[Name->Class:Parameter]
14
+ attr_reader :paramSets # hash[Name->Class:ParameterSet]
15
+ attr_reader :domains # hash[Name->Class:Domain]
16
+ attr_reader :extension_loaders # hash[Name->Class:ExtensionLoader]
17
+
18
+ # ------------------------------------------------------------------
19
+ # mixer
20
+ PROGNAME = "Factory" # progname for logger
21
+ include Sbuilder::Utils::MyLogger # mix logger
22
+
23
+
24
+
25
+ # ------------------------------------------------------------------
26
+ # constructore
27
+
28
+ def initialize( options = {} )
29
+ @logger = getLogger( PROGNAME, options )
30
+ @logger.info( "#{__method__} initialized options=#{options}" )
31
+ @options = options
32
+ initializeFactories
33
+ end
34
+
35
+ def initializeFactories
36
+ @extension_loaders={
37
+ Sbuilder::Constants::EXTENSION_LOADER_YAML => ExtensionLoader,
38
+ }
39
+ @parameters={
40
+ Sbuilder::Constants::PARAMETER => Parameter_Dom,
41
+ Sbuilder::Constants::PARAMETER_REF => Parameter_Ref,
42
+ }
43
+ @paramSets = {
44
+ Sbuilder::Constants::SWAGGER => ParamSet_If,
45
+ Sbuilder::Constants::SWAGGER_DEFINITION => ParamSetDef,
46
+ Sbuilder::Constants::PARAM_SET_STEPS => ParamSetStep,
47
+ }
48
+
49
+ @paramSetLoaders = {
50
+ Sbuilder::Constants::SWAGGER => ParamSetLoaderSwagger
51
+ }
52
+ @mapperLoaders = {
53
+ Sbuilder::Constants::MAPPER_YAML => ResolverLoader_YAML
54
+ }
55
+ @mapperRules = {
56
+ Sbuilder::Constants::MAPPER_RULE_MATCH => ResolverRuleMatch,
57
+ Sbuilder::Constants::MAPPER_RULE_REF => ResolverRuleRef,
58
+ }
59
+
60
+ @domains = {
61
+ Sbuilder::Constants::TYPE_DOMAIN => Domain,
62
+ Sbuilder::Constants::TYPE_VALUE_DOMAIN => DomainValue ,
63
+ Sbuilder::Constants::TYPE_CARDINALITY_DOMAIN => DomainCardinality ,
64
+ }
65
+
66
+ end
67
+
68
+ # ------------------------------------------------------------------
69
+ # singleton
70
+ class << self
71
+
72
+ def getFactory( options={} )
73
+ return @@singleton unless @@singleton.nil?
74
+ @@singleton = new( options )
75
+ end
76
+
77
+ private :new
78
+
79
+ end # class methods
80
+
81
+ # ------------------------------------------------------------------
82
+ # loaders
83
+
84
+
85
+ # return object to load mappers
86
+ def getResolverLoader( type )
87
+ if mapperLoaders[type].nil? then
88
+ msg = <<-EOS
89
+ Unknown mapper type #{type}
90
+
91
+ Valid types: #{mapperLoaders.keys}
92
+ EOS
93
+
94
+ @logger.error( "#{__method__} #{msg}" )
95
+ raise NameError.new( msg )
96
+ end
97
+
98
+ return mapperLoaders[type].new( Factory.getFactory(options), options )
99
+ end
100
+
101
+
102
+ # return object to load parameter sets
103
+ def getParamSetLoader( type )
104
+ if paramSetLoaders[type].nil? then
105
+ msg = <<-EOS
106
+ Unknown parameter type #{type}"
107
+
108
+ Validate types #{paramSetLoaders.keys}
109
+ EOS
110
+
111
+ @logger.error( "#{__method__} #{msg}" )
112
+ raise NameError.new( msg )
113
+ end
114
+ return paramSetLoaders[type].new( Factory.getFactory(options), options )
115
+ end
116
+
117
+ # ------------------------------------------------------------------
118
+ # template reader
119
+
120
+ # Create file reader for template generator if
121
+ # options[:filter_src]-> return TemplateContextReader else
122
+ # return TemplateReader
123
+ #
124
+ # @return [TemplateReader|TemplateContextReader] implementing
125
+ # 'get_template' -method for template generator.
126
+ def getTemplateReader( controller )
127
+ if options[:filter_src]
128
+ Sbuilder::TemplateContextReader.new( controller, @options )
129
+ else
130
+ Sbuilder::TemplateReader.new( controller, @options )
131
+ end
132
+ # return @template_reader if @template_reader
133
+ # @template_reader = Sbuilder::TemplateReader.new( @options )
134
+ # @template_reader
135
+ end
136
+
137
+ # ------------------------------------------------------------------
138
+ # generate
139
+ #
140
+ # @return [Template] mustache template generator
141
+ def getTemplate( reader )
142
+ Template.new( reader, @options )
143
+ # return @template if @template
144
+ # @template = Template.new( getTemplateReader, @options )
145
+ # @template
146
+ end
147
+
148
+ # ------------------------------------------------------------------
149
+ # model
150
+ def createModel
151
+ Sbuilder::Model.new( self, options )
152
+ end
153
+
154
+ # ------------------------------------------------------------------
155
+ # domainLoader
156
+
157
+ def getExtensionLoader( type )
158
+ if extension_loaders[type].nil? then
159
+
160
+ msg = <<-EOS
161
+ Unknown extension loader type #{type}"
162
+
163
+ Valid extension loader types #{extension_loaders.keys}
164
+ EOS
165
+ @logger.error( "#{__method__} #{msg}" )
166
+ raise NameError.new( msg )
167
+ end
168
+ extension_loaders[type].new( options )
169
+ # Sbuilder::ExtensionLoader.new( options )
170
+ end
171
+
172
+ # ------------------------------------------------------------------
173
+ # mapper
174
+
175
+ # create new Resolver object
176
+ def createResolver( type )
177
+ return Resolver.new( options )
178
+ end
179
+
180
+ # create new ResolverRule object
181
+ def createResolverRule( type )
182
+ if mapperRules[type].nil? then
183
+ msg = "Unknown mapper rule type #{type}"
184
+ @logger.error( "#{__method__} #{msg}" )
185
+ raise NameError.new( msg )
186
+ end
187
+
188
+ return mapperRules[type].new( options )
189
+ end
190
+
191
+ # ------------------------------------------------------------------
192
+ # domain
193
+
194
+ def createDomain( type = Sbuilder::Constants::TYPE_DOMAIN )
195
+ if domains[type].nil? then
196
+ msg = <<-EOS
197
+ Unknown domain type #{type}"
198
+
199
+ Validate types #{domains.keys}
200
+ EOS
201
+
202
+ @logger.error( "#{__method__} #{msg}" )
203
+ raise NameError.new( msg )
204
+ end
205
+
206
+ return domains[type].new( options )
207
+ end
208
+
209
+ # ------------------------------------------------------------------
210
+ # param sets
211
+
212
+ # create new Resolver object
213
+ def createParamSet( type )
214
+ if paramSets[type].nil? then
215
+ msg = "Unknown parameter type #{type}"
216
+ @logger.error( "#{__method__} #{msg}" )
217
+ raise NameError.new( msg )
218
+ end
219
+ return paramSets[type].new( options )
220
+ end
221
+
222
+ def createParameter( type )
223
+ if parameters[type].nil? then
224
+ msg = "Unknown parameter type #{type}"
225
+ @logger.error( "#{__method__} #{msg}" )
226
+ raise NameError.new( msg )
227
+ end
228
+ parameters[type].new( options )
229
+ end
230
+
231
+
232
+ end # class Factory
233
+
234
+ end # module
@@ -0,0 +1,356 @@
1
+ module Sbuilder
2
+
3
+ class Model
4
+
5
+ attr_reader :domains # hash name => Domain
6
+ attr_reader :factory # to create domain
7
+ attr_reader :interfaceExtensions # hash : { paramSet.getId -> { matcher -> ..., implementation -> .. } }
8
+ attr_reader :interfaces # hash of interfaffces { paramSet.get -> paramSet }
9
+ attr_reader :definitions # hash : { paramSet.getId -> paramSet } of swagger definitions
10
+ attr_reader :steps # array of paramSetSteps
11
+ attr_reader :possibility # [String] of setup possibility - may be nil
12
+ attr_reader :possibilities # [String:Array] possibilities in setup
13
+
14
+ # ------------------------------------------------------------------
15
+ # mixer
16
+ PROGNAME = "Model" # progname for logger
17
+ include Sbuilder::Utils::MyLogger # mix logger
18
+
19
+ @@validInterfaceExtensionProperties = ["matcher", "implementation"]
20
+
21
+ # ------------------------------------------------------------------
22
+ # constructore
23
+
24
+ def initialize( factory, options = {} )
25
+ @logger = getLogger( PROGNAME, options )
26
+ @logger.info( "#{__method__} initialized" )
27
+ @factory = factory
28
+
29
+ # model content
30
+ # @paramSets = []
31
+ @domains = {}
32
+ # create a hash capable for topological sorting
33
+ @definitions = Sbuilder::ParamSets.create( self )
34
+ @interfaces = {}
35
+ @steps = []
36
+ @possibility = nil
37
+ @possibilities = []
38
+
39
+ @interfaceExtensions = {}
40
+
41
+
42
+ end
43
+
44
+ # ------------------------------------------------------------------
45
+ # possibility stuff
46
+
47
+ def setPossibility( possi )
48
+ @possibility = possi
49
+ end
50
+
51
+ def setPossibilities( possis )
52
+ @possibilities = possis || []
53
+ @logger.info( "#{__method__} @possibilities=#{@possibilities}" )
54
+ end
55
+
56
+ # ------------------------------------------------------------------
57
+ # domain stuff
58
+
59
+ def getDomain( domainName )
60
+ ret = domains[domainName]
61
+ raise ModelException.new "Could not locate domain set #{domainName}" unless ret
62
+ return ret
63
+ end
64
+
65
+ # called when loading mappers for each domain encountered, return domain
66
+ def domainEncountered( domainName )
67
+ @logger.info( "#{__method__} domainName #{domainName}" )
68
+ return createOrUpdateDomain( domainName, nil )
69
+ end
70
+
71
+
72
+ # called from a separte plase
73
+ def extendDomain( domain )
74
+ @logger.info( "#{__method__} domain=#{domain}" )
75
+ raise ModelException.new <<-EOS unless domains[domain.name]
76
+ Unknown domain.name=#{domain.name}
77
+
78
+ Trying to extend domain '#{domain.name}', which not among resolved domains.
79
+
80
+ Known domain names are: #{domains.keys.join(', ' )}
81
+
82
+ EOS
83
+ domains[domain.name].setExtension( domain )
84
+ # return createOrUpdateDomain( domain.name, domain.cardinality )
85
+ end
86
+
87
+ # DRY method to create or update
88
+ private def createOrUpdateDomain( domainName, cardinality=1 )
89
+ @logger.info( "#{__method__} domainName #{domainName}, cardinality='#{cardinality}'" )
90
+ domain = domains[domainName]
91
+
92
+ # create if it does not exist
93
+ if domain.nil? then
94
+ domain = factory.createDomain
95
+ domain.setName( domainName )
96
+ end
97
+
98
+ # option to set cardinality
99
+ domain.setCardinality( cardinality ) if cardinality
100
+
101
+ # update model state
102
+ domains[domainName] = domain
103
+
104
+ return domain
105
+ end
106
+
107
+ # ------------------------------------------------------------------
108
+ # collection of all param sets: intefaces + definitions
109
+ def paramSets
110
+ interfaces.values + definitions.values
111
+ end
112
+
113
+ # resolve 'paramSetName'
114
+ def getParamset( paramSetName )
115
+ ret = paramSets.select { |p| p.getId == paramSetName }.first
116
+ raise ModelException.new "Could not locate param set #{paramSetName}" unless ret
117
+ ret
118
+ end
119
+
120
+ # ------------------------------------------------------------------
121
+ # step stuff
122
+ def extendStep( stepExtension )
123
+ @steps << stepExtension
124
+ end
125
+
126
+
127
+ # ------------------------------------------------------------------
128
+ # interface stuff
129
+
130
+ # accept parameters set to model
131
+ def interfaceEncountered( paramSet )
132
+ @interfaces[paramSet.getId] = paramSet
133
+
134
+ # # collect all paramsets
135
+ # addParamSet( paramSet )
136
+ end
137
+
138
+
139
+ # extend
140
+ def extendInterface( interfaceExtensionDef )
141
+
142
+ # validate properties 'interfaceExtensionDef'
143
+ begin
144
+ validateProperties( interfaceExtensionDef, @@validInterfaceExtensionProperties )
145
+ rescue ModelException => me
146
+ @logger.info( "#{__method__} model exception #{me}" )
147
+ raise ExtensionException.new( me )
148
+ end
149
+
150
+ # locate interface being extended
151
+ interfaceParamSet = getInterface( interfaceExtensionDef['matcher'] )
152
+
153
+ # record extension in '@interfaceExtensions'
154
+ putImplementationExtension( interfaceParamSet, interfaceExtensionDef )
155
+
156
+ # return the extended interface
157
+ interfaceParamSet
158
+
159
+ end
160
+
161
+ # locate 'interface' using 'matcher' (string or regexp),raise exception if not found
162
+ def getInterface( matcher )
163
+
164
+ @logger.debug( "#{__method__} matcher=#{matcher}" )
165
+
166
+ interfaces.values.each do |interfaceParamSet|
167
+ if interfaceParamSet.matchesWithParamSet( matcher ) then
168
+ return interfaceParamSet
169
+ end
170
+ end
171
+
172
+ # error w. instructios of valid intefaces - should not reach this point
173
+ raise ExtensionException.new <<-EOS
174
+
175
+ Could not find interface matching '#{matcher}'
176
+
177
+ Known interfaces: #{interfaceIds.join(',')}
178
+
179
+ EOS
180
+
181
+ end
182
+
183
+ # record extension in '@interfaceExtensions'
184
+ def putImplementationExtension( interfaceParamSet, interfaceExtensionDef )
185
+ @interfaceExtensions[interfaceParamSet.getId] = interfaceExtensionDef
186
+ end
187
+
188
+ # provide information on extension implementation during generation phase
189
+ def getImplementationExtension( interfaceParamSet )
190
+ interfaceExtensions[interfaceParamSet.getId] ? interfaceExtensions[interfaceParamSet.getId]['implementation'] : nil
191
+ end
192
+
193
+ # array of known interface ids
194
+ def interfaceIds
195
+ interfaces.values.map { |interface| interface.getId }
196
+ end
197
+
198
+ # ------------------------------------------------------------------
199
+ # definition stuff
200
+
201
+ def definitionEncountered( paramSet )
202
+ @logger.info( "#{__method__} paramSet=#{paramSet}, paramSet.class=#{paramSet.class}" )
203
+
204
+ # collect definitions
205
+ @definitions[paramSet.getId] = paramSet
206
+
207
+ # # collect all paramsets
208
+ # addParamSet( paramSet )
209
+
210
+ end
211
+
212
+
213
+ # ------------------------------------------------------------------
214
+ # generate phase
215
+
216
+ # none: nil
217
+ # domains:
218
+ # - name:
219
+ # domain_name:
220
+ # cardinality
221
+ # domain_values:
222
+ # - value:
223
+ # index:
224
+ # _comma:
225
+ # variables:
226
+ # - array
227
+ # interfaces:
228
+ # - getName:
229
+ # parameter_defintions:
230
+ # - name:
231
+ # parameter_name:
232
+ # domain:
233
+ #
234
+ #
235
+
236
+ # return hash for mustache for 'templateName' in 'interfaces', 'domains', 'variables'
237
+ def templateData( domainName )
238
+
239
+ case domainName
240
+ when 'interfaces'
241
+ templateDataInterfaces( domainName, false )
242
+ when 'infrastructureServices'
243
+ templateDataInterfaces( domainName, true )
244
+ when 'possibility'
245
+ hash = {
246
+ "possibility" => lambda { hash['possibility'].to_yaml },
247
+ "possibility" => possibility, # possibility defined in setup, currently being generated
248
+ }
249
+ when 'possibilities'
250
+ hash = {
251
+ "possibilities" => lambda { hash['possibilities'].to_yaml },
252
+ "possibilities" => possibilities, # possibilities in setup, all in current setup
253
+ }
254
+ when 'variables'
255
+ hash = {
256
+ "dump" => lambda { hash['variables'].to_yaml },
257
+ "variables" => [], # paramSets, # => TLA state variable
258
+ }
259
+ when 'steps'
260
+ hash = {
261
+ "dump" => lambda { hash['steps'].to_yaml },
262
+ "steps" => steps.map.with_index { |step,i|
263
+ {
264
+ :process => step.getName,
265
+ :interface_name => step.interfaceReference.getName,
266
+ :interface_operation => step.interfaceReference.getId,
267
+ :interface_path => step.interfaceReference.path,
268
+ # :interface_id => step.interfaceReference.getId,
269
+ :_comma => (i< steps.length-1 ? "," : ""),
270
+ :bindRule => step.bindExact == false ? step.inputs : false,
271
+ :bindSets => step.bindExact ? step.inputs.map.with_index { |input,i| input[:_comma] = i<step.inputs.length-1 ? ',' : ''; input } : false,
272
+ }
273
+ },
274
+ }
275
+ when 'none'
276
+ {
277
+ }
278
+ when 'definitions'
279
+ hash = {
280
+ "dump" => lambda { hash['definitions'].to_yaml },
281
+ "definitions" => definitions.tsort.map.with_index { |parameterName,i|
282
+ # tsort returns array of names, resolve paramSet
283
+ p = getParamset( parameterName )
284
+ { :definition_name => p.getName,
285
+ :isArray => p.isArray,
286
+ :_comma => (i< definitions.values.length-1 ? "," : ""),
287
+ :parameter_definitions => p.parameter_definitions( self )
288
+ }
289
+ }
290
+ } # => TLA definitions
291
+ when 'domains'
292
+ hash = {
293
+ "dump" => lambda { hash['domains'].to_yaml },
294
+ "domains" => domains.values.map do |domain|
295
+ {
296
+ :domain_name => domain.domain_name,
297
+ :domain_values => domain.domain_values,
298
+ }
299
+ end, # => TLA domain
300
+ }
301
+ else
302
+ raise "Unknown template '#{domainName}'"
303
+ end # case
304
+
305
+ end # getTemplateData
306
+
307
+
308
+ # Extract data model for interfaces
309
+ #
310
+ # @param infrastructureServices [Boolean] choose 'interfaces' or 'infrastructureServices'
311
+ # @return [Hash] for template rendering composed of interfaces, false if configs
312
+ #
313
+ private def templateDataInterfaces( domainName, infrastructureServices )
314
+ hash = {
315
+ "dump" => lambda { hash[domainName].to_yaml },
316
+ domainName => interfaces.values.select { |iface|
317
+
318
+ iface.infrastructureService == infrastructureServices
319
+
320
+ }.map { |iface |
321
+ {
322
+ :interface_name => iface.getName, # e.g._pet_post_
323
+ :interface_operation => iface.getId, # e.g /pet(post)
324
+ :implementation => getImplementationExtension( iface ),
325
+ :_comma => ',',
326
+ :parameter_definitions => iface.parameter_definitions( self ),
327
+ :response_definitions => iface.response && iface.response.parameters.any? ? iface.response.parameter_definitions( self ) : false,
328
+ }
329
+ } # => TLA process & stubs
330
+ }
331
+
332
+ # return 'false' instead of an array if empty
333
+ hash[domainName] = false unless hash[domainName].any?
334
+ # fix _comma for the last entry in array
335
+ fixLastComma( hash[domainName] )
336
+ return hash
337
+ end
338
+
339
+ private def fixLastComma( arrOfHashes )
340
+ arrOfHashes.last[:_comma] = "" if arrOfHashes && arrOfHashes.any?
341
+ end
342
+
343
+
344
+ private def validateProperties( defintionHash, required, allowed=nil )
345
+ allowed = required unless allowed
346
+ missingProps = required - defintionHash.keys
347
+ raise ModelException.new "Missing properties #{missingProps} in #{defintionHash} - required #{required}" if missingProps.any?
348
+
349
+ invalidProps = defintionHash.keys - allowed
350
+ raise ModelException.new "Unknown properties #{invalidProps} in #{defintionHash}- allowed #{allowed}" if invalidProps.any?
351
+
352
+ end
353
+
354
+ end # class
355
+
356
+ end