lutaml 0.8.1 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b0a582c930c66da4590b8f707825f61e407bbe2492c95aa6f6a61725e95e62d4
4
- data.tar.gz: cb3045bd11c726aa0d9462f72216e783545c37e2a701c223c5dc335eb1fb8213
3
+ metadata.gz: b4a5e17292ce48ecab9f02dfbc1ba4630fd8ccc8abbeef241830dba6751b21e3
4
+ data.tar.gz: 82da115e0396750610178e711864546b19212f55a6a5119ce12464c0337a45a6
5
5
  SHA512:
6
- metadata.gz: 57aecd47776c51bafead92eaa4a245639d5b38999b04b5a12343e23c0ee97141605e4b723eb0663e4b88e775d9aba6c7458a125f4d011495d26cb0e6d17e714c
7
- data.tar.gz: 6ae62810f1212d029efbc6829a29a7fee18306e8a672c5d8ab08d6907979dfaa6db2743763400d35f3f8d4c5551ab57db53dae8c88577703ddac7869e9adfc28
6
+ metadata.gz: d07503ca2cdf8d33fb64f17dccf2eb0fefccbdc0853887713a8f62df1248799589b4cf5b017defbff2611f92563107bbc24f3a6a269d44775cad68a01e843c03
7
+ data.tar.gz: '00392dc2b1a84f56343486d677c1494564d7ef46d26fc2d63eebc92ae29b0861488b812726a529a4d6f0b371e2bad72c1163912d6f0ea3752d6f0c26f02c9762'
@@ -10,5 +10,3 @@ on:
10
10
  jobs:
11
11
  rake:
12
12
  uses: metanorma/ci/.github/workflows/graphviz-rake.yml@main
13
- secrets:
14
- pat_token: ${{ secrets.LUTAML_CI_PAT_TOKEN }}
@@ -1,3 +1,3 @@
1
1
  module Lutaml
2
- VERSION = "0.8.1".freeze
2
+ VERSION = "0.9.0".freeze
3
3
  end
@@ -20,8 +20,15 @@ module Lutaml
20
20
  # @param options [Hash] options for parsing
21
21
  # @return [Lutaml::Uml::Document]
22
22
  def self.parse(xml, _options = {})
23
+ sparx_root = Xmi::Sparx::SparxRoot
24
+ xmi_doc = Nokogiri::XML(File.read(xml))
25
+ namespace = xmi_doc.at_xpath("//xmi:XMI").namespaces
26
+ if namespace["xmlns:uml"].split("/").last == "20131001"
27
+ sparx_root = Xmi::Sparx::SparxRoot2013
28
+ end
29
+
23
30
  xml_content = File.read(xml)
24
- xmi_model = Xmi::Sparx::SparxRoot2013.from_xml(xml_content)
31
+ xmi_model = sparx_root.from_xml(xml_content)
25
32
  new.parse(xmi_model)
26
33
  end
27
34
 
@@ -42,7 +49,7 @@ module Lutaml
42
49
  model = xmi_model.model
43
50
  {
44
51
  name: model.name,
45
- packages: serialize_model_packages(model)
52
+ packages: serialize_model_packages(model),
46
53
  }
47
54
  end
48
55
 
@@ -60,7 +67,7 @@ module Lutaml
60
67
  diagrams: serialize_model_diagrams(package.id),
61
68
  packages: serialize_model_packages(package),
62
69
  definition: doc_node_attribute_value(package.id, "documentation"),
63
- stereotype: doc_node_attribute_value(package.id, "stereotype")
70
+ stereotype: doc_node_attribute_value(package.id, "stereotype"),
64
71
  }
65
72
  end
66
73
  end
@@ -71,9 +78,10 @@ module Lutaml
71
78
  # @note xpath ./packagedElement[@xmi:type="uml:Class" or
72
79
  # @xmi:type="uml:AssociationClass"]
73
80
  def serialize_model_classes(package, model)
74
- package.packaged_element.select { |e|
75
- e.type?("uml:Class") || e.type?("uml:AssociationClass")
76
- }.map do |klass|
81
+ package.packaged_element.select do |e|
82
+ e.type?("uml:Class") || e.type?("uml:AssociationClass") ||
83
+ e.type?("uml:Interface")
84
+ end.map do |klass|
77
85
  {
78
86
  xmi_id: klass.id,
79
87
  name: klass.name,
@@ -84,7 +92,7 @@ module Lutaml
84
92
  constraints: serialize_class_constraints(klass.id),
85
93
  is_abstract: doc_node_attribute_value(klass.id, "isAbstract"),
86
94
  definition: doc_node_attribute_value(klass.id, "documentation"),
87
- stereotype: doc_node_attribute_value(klass.id, "stereotype")
95
+ stereotype: doc_node_attribute_value(klass.id, "stereotype"),
88
96
  }
89
97
  end
90
98
  end
@@ -93,12 +101,12 @@ module Lutaml
93
101
  # @return [Array<Hash>]
94
102
  # @note xpath ./packagedElement[@xmi:type="uml:Enumeration"]
95
103
  def serialize_model_enums(package)
96
- package.packaged_element
97
- .select { |e| e.type?("uml:Enumeration") }.map do |enum|
98
- # xpath .//ownedLiteral[@xmi:type="uml:EnumerationLiteral"]
99
- owned_literals = enum.owned_literal.map do |owned_literal|
100
- owned_literal.to_hash.transform_keys(&:to_sym)
101
- end
104
+ package.packaged_element.select { |e| e.type?("uml:Enumeration") }
105
+ .map do |enum|
106
+ # xpath .//ownedLiteral[@xmi:type="uml:EnumerationLiteral"]
107
+ owned_literals = enum.owned_literal.map do |owned_literal|
108
+ owned_literal.to_hash.transform_keys(&:to_sym)
109
+ end
102
110
 
103
111
  {
104
112
  xmi_id: enum.id,
@@ -116,7 +124,7 @@ module Lutaml
116
124
  def serialize_model_data_types(model)
117
125
  all_data_type_elements = []
118
126
  select_all_packaged_elements(all_data_type_elements, model,
119
- "uml:DataType")
127
+ "uml:DataType")
120
128
  all_data_type_elements.map do |klass|
121
129
  {
122
130
  xmi_id: klass.id,
@@ -144,7 +152,7 @@ module Lutaml
144
152
  {
145
153
  xmi_id: diagram.id,
146
154
  name: diagram.properties.name,
147
- definition: diagram.properties.documentation
155
+ definition: diagram.properties.documentation,
148
156
  }
149
157
  end
150
158
  end
@@ -160,22 +168,20 @@ module Lutaml
160
168
  matched_element.links.association.empty?
161
169
 
162
170
  matched_element.links.association.map do |assoc|
163
- link_member_name = assoc.start == xmi_id ? "end" : "start"
164
- linke_owner_name = link_member_name == "start" ? "end" : "start"
171
+ link_member = assoc.start == xmi_id ? "end" : "start"
172
+ linke_owner_name = link_member == "start" ? "end" : "start"
165
173
 
166
174
  member_end, member_end_type, member_end_cardinality,
167
175
  member_end_attribute_name, member_end_xmi_id =
168
- serialize_member_type(xmi_id, assoc, link_member_name)
176
+ serialize_member_type(xmi_id, assoc, link_member)
169
177
 
170
178
  owner_end = serialize_owned_type(xmi_id, assoc, linke_owner_name)
171
179
 
172
- if member_end && ((member_end_type != 'aggregation') ||
173
- (member_end_type == 'aggregation' && member_end_attribute_name))
180
+ if member_end && ((member_end_type != "aggregation") ||
181
+ (member_end_type == "aggregation" && member_end_attribute_name))
174
182
 
175
- doc_node_name = (link_member_name == "start" ?
176
- "source" : "target")
177
- definition = fetch_definition_node_value(assoc.id,
178
- doc_node_name)
183
+ doc_node_name = (link_member == "start" ? "source" : "target")
184
+ definition = fetch_definition_node_value(assoc.id, doc_node_name)
179
185
 
180
186
  {
181
187
  xmi_id: assoc.id,
@@ -186,7 +192,7 @@ module Lutaml
186
192
  member_end_xmi_id: member_end_xmi_id,
187
193
  owner_end: owner_end,
188
194
  owner_end_xmi_id: xmi_id,
189
- definition: definition
195
+ definition: definition,
190
196
  }
191
197
  end
192
198
  end
@@ -239,7 +245,7 @@ module Lutaml
239
245
  if connector_node
240
246
  # In ea-xmi-2.5.1, constraints are moved to source/target under
241
247
  # connectors
242
- constraints = [:source, :target].map do |st|
248
+ constraints = %i[source target].map do |st|
243
249
  connector_node.send(st).constraints.constraint
244
250
  end.flatten
245
251
 
@@ -267,8 +273,7 @@ module Lutaml
267
273
  end
268
274
 
269
275
  xmi_id = link.send(linke_owner_name.to_sym)
270
- owner_end = lookup_entity_name(xmi_id) ||
271
- connector_source_name(xmi_id)
276
+ lookup_entity_name(xmi_id) || connector_source_name(xmi_id)
272
277
 
273
278
  # not necessary
274
279
  # if link.name == "Association"
@@ -279,14 +284,13 @@ module Lutaml
279
284
  # fetch_owned_attribute_node(xmi_id)
280
285
  # end
281
286
  # [owner_end, owned_cardinality, owned_attribute_name]
282
- owner_end
287
+ # owner_end
283
288
  end
284
289
 
285
290
  # @param owner_xmi_id [String]
286
291
  # @param link [Shale::Mapper]
287
- # @param link_member_name [String]
288
292
  # @return [Array<String, String>]
289
- def serialize_member_end(owner_xmi_id, link, link_member_name)
293
+ def serialize_member_end(owner_xmi_id, link)
290
294
  case link.name
291
295
  when "NoteLink"
292
296
  return
@@ -313,8 +317,7 @@ module Lutaml
313
317
  # @param link_member_name [String]
314
318
  # @return [Array<String, String, Hash, String, String>]
315
319
  def serialize_member_type(owner_xmi_id, link, link_member_name)
316
- member_end, xmi_id = serialize_member_end(
317
- owner_xmi_id, link, link_member_name)
320
+ member_end, xmi_id = serialize_member_end(owner_xmi_id, link)
318
321
 
319
322
  if link.name == "Association"
320
323
  connector_type = link_member_name == "start" ? "source" : "target"
@@ -326,7 +329,7 @@ module Lutaml
326
329
  end
327
330
 
328
331
  [member_end, "aggregation", member_end_cardinality,
329
- member_end_attribute_name, xmi_id]
332
+ member_end_attribute_name, xmi_id]
330
333
  end
331
334
 
332
335
  # @param link_id [String]
@@ -338,9 +341,9 @@ module Lutaml
338
341
 
339
342
  if assoc_connector
340
343
  assoc_connector_type = assoc_connector.type
341
- if assoc_connector_type && assoc_connector_type.multiplicity
342
- cardinality = assoc_connector_type.multiplicity.split('..')
343
- cardinality.unshift('1') if cardinality.length == 1
344
+ if assoc_connector_type&.multiplicity
345
+ cardinality = assoc_connector_type.multiplicity.split("..")
346
+ cardinality.unshift("1") if cardinality.length == 1
344
347
  min, max = cardinality
345
348
  end
346
349
  assoc_connector_role = assoc_connector.role
@@ -385,15 +388,14 @@ module Lutaml
385
388
  def fetch_owned_attribute_node(xmi_id)
386
389
  all_elements = all_packaged_elements
387
390
 
388
- owned_attributes = all_elements.map { |e| e.owned_attribute }.flatten
391
+ owned_attributes = all_elements.map(&:owned_attribute).flatten
389
392
  oa = owned_attributes.select do |a|
390
393
  !!a.association && a.uml_type && a.uml_type.idref == xmi_id
391
394
  end.first
392
395
 
393
396
  if oa
394
397
  cardinality = cardinality_min_max_value(
395
- oa.lower_value&.value,
396
- oa.upper_value&.value
398
+ oa.lower_value&.value, oa.upper_value&.value
397
399
  )
398
400
  oa_name = oa.name
399
401
  end
@@ -416,22 +418,23 @@ module Lutaml
416
418
  def serialize_class_attributes(klass)
417
419
  klass.owned_attribute.select { |attr| attr.type?("uml:Property") }
418
420
  .map do |oa|
419
- uml_type = oa.uml_type
420
- uml_type_idref = uml_type.idref if uml_type
421
-
422
- if oa.association.nil?
423
- {
424
- id: oa.id,
425
- name: oa.name,
426
- type: lookup_entity_name(uml_type_idref) || uml_type_idref,
427
- xmi_id: uml_type_idref,
428
- is_derived: oa.is_derived,
429
- cardinality: cardinality_min_max_value(
430
- oa.lower_value&.value,
431
- oa.upper_value&.value),
432
- definition: lookup_attribute_documentation(oa.id),
433
- }
434
- end
421
+ uml_type = oa.uml_type
422
+ uml_type_idref = uml_type.idref if uml_type
423
+
424
+ if oa.association.nil?
425
+ {
426
+ id: oa.id,
427
+ name: oa.name,
428
+ type: lookup_entity_name(uml_type_idref) || uml_type_idref,
429
+ xmi_id: uml_type_idref,
430
+ is_derived: oa.is_derived,
431
+ cardinality: cardinality_min_max_value(
432
+ oa.lower_value&.value,
433
+ oa.upper_value&.value,
434
+ ),
435
+ definition: lookup_attribute_documentation(oa.id),
436
+ }
437
+ end
435
438
  end.compact
436
439
  end
437
440
 
@@ -441,7 +444,7 @@ module Lutaml
441
444
  def cardinality_min_max_value(min, max)
442
445
  {
443
446
  "min" => cardinality_value(min, true),
444
- "max" => cardinality_value(max, false)
447
+ "max" => cardinality_value(max, false),
445
448
  }
446
449
  end
447
450
 
@@ -451,7 +454,7 @@ module Lutaml
451
454
  def cardinality_value(value, is_min = false)
452
455
  return unless value
453
456
 
454
- is_min ? LOWER_VALUE_MAPPINGS[value] : value
457
+ is_min ? LOWER_VALUE_MAPPINGS[value.to_s] : value
455
458
  end
456
459
 
457
460
  # @node [Shale::Mapper]
@@ -523,12 +526,11 @@ module Lutaml
523
526
  # @return [Array<Xmi::Uml::PackagedElement>]
524
527
  def all_packaged_elements
525
528
  all_elements = []
526
- [
527
- @xmi_root_model.model.packaged_element +
529
+ packaged_element_roots = @xmi_root_model.model.packaged_element +
528
530
  @xmi_root_model.extension.primitive_types.packaged_element +
529
- @xmi_root_model.extension.profiles.profile
530
- .map {|p| p.packaged_element }
531
- ].flatten.each do |e|
531
+ @xmi_root_model.extension.profiles.profile.map(&:packaged_element)
532
+
533
+ packaged_element_roots.flatten.each do |e|
532
534
  select_all_packaged_elements(all_elements, e, nil)
533
535
  end
534
536
 
@@ -589,7 +591,7 @@ module Lutaml
589
591
  result[node.id] = node.name
590
592
  end
591
593
 
592
- attrs.each_pair do |k, v|
594
+ attrs.each_pair do |k, _v|
593
595
  map_id_name(result, node.send(k))
594
596
  end
595
597
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lutaml
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.1
4
+ version: 0.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-06-19 00:00:00.000000000 Z
11
+ date: 2024-06-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: expressir