lutaml-xmi 0.2.0 → 0.2.1

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: a8097eb270cce873bbed9f698a85383bc579844db4729be05923d2866bb2d47a
4
- data.tar.gz: 327a2b1dfe675de37dc5ba0cffeb502581c8889dc62193ac0fa96ad166bea477
3
+ metadata.gz: 00fbd8ecac2e908005b2e8721296f5ad95c49bd164b32bc9954e8bf94d82ad18
4
+ data.tar.gz: 14e0bffadfb34e0980fba6d535576b3fff50b663c2f26f3174b1ab908a1883d2
5
5
  SHA512:
6
- metadata.gz: b222a705723f2f07767955f17f4a3789dce863697d865937708c3abdf0c59fa100dfdd754f188930a131950e9ab5e033ebb3be8d447ddf06f9c400157837f984
7
- data.tar.gz: 8772040cc940d2de1389592ea7a3fb3b06c2d114d17511072d8bb4abe748d26111d58b4bcff626e1d3b55bb6b98a9ba017a52572b6853be399dfd650721d36ba
6
+ metadata.gz: 432706c232ea18b66169dad9ce3a5f25612824563cde18484b3e83bab07804a503b7c145e62c67d0516e0b3ea83f38e6ed7fda461ee88b5d4a0a9a153142a300
7
+ data.tar.gz: 40d9499f0866b91bd5b04a8d2e47b0b894c82f6a129893f8b0d1f57e15ac37981d9a12c87b14f5f2acb0bbd6e4dd797ed910d28379f159bafed63e187947857d
@@ -127,10 +127,13 @@ module Lutaml
127
127
  def serialize_model_associations(klass)
128
128
  xmi_id = klass["xmi:id"]
129
129
  main_model.xpath(%(//element[@xmi:idref="#{xmi_id}"]/links/*)).map do |link|
130
- member_end, member_end_type, member_end_cardinality, member_end_attribute_name = serialize_member_type(xmi_id, link)
131
- owned_end_cardinality, owned_end_attribute_name = serialize_owned_type(xmi_id, link)
130
+ link_member_name = link.attributes["start"].value == xmi_id ? "end" : "start"
131
+ linke_owner_name = link_member_name == "start" ? "end" : "start"
132
+ member_end, member_end_type, member_end_cardinality, member_end_attribute_name = serialize_member_type(xmi_id, link, link_member_name)
133
+ owner_end, owner_end_cardinality, owner_end_attribute_name = serialize_owned_type(xmi_id, link, linke_owner_name)
132
134
  if member_end && ((member_end_type != 'aggregation') || (member_end_type == 'aggregation' && member_end_attribute_name))
133
- definition_node = main_model.xpath(%(//connector[@xmi:idref="#{link['xmi:id']}"]/target/documentation)).first
135
+ doc_node_name = link_member_name == "start" ? "source" : "target"
136
+ definition_node = main_model.xpath(%(//connector[@xmi:idref="#{link['xmi:id']}"]/#{doc_node_name}/documentation)).first
134
137
  definition = definition_node.attributes['value']&.value if definition_node
135
138
  {
136
139
  xmi_id: link["xmi:id"],
@@ -138,6 +141,7 @@ module Lutaml
138
141
  member_end_type: member_end_type,
139
142
  member_end_cardinality: member_end_cardinality,
140
143
  member_end_attribute_name: member_end_attribute_name,
144
+ owner_end: owner_end,
141
145
  definition: definition
142
146
  }
143
147
  end
@@ -167,11 +171,12 @@ module Lutaml
167
171
  end
168
172
  end
169
173
 
170
- def serialize_owned_type(owned_xmi_id, link)
174
+ def serialize_owned_type(owner_xmi_id, link, linke_owner_name)
171
175
  return if link.name == 'NoteLink'
172
- return generalization_association(owned_xmi_id, link) if link.name == "Generalization"
176
+ return generalization_association(owner_xmi_id, link) if link.name == "Generalization"
173
177
 
174
- xmi_id = link.attributes["start"].value
178
+ xmi_id = link.attributes[linke_owner_name].value
179
+ owner_end = lookup_entity_name(xmi_id) || connector_source_name(xmi_id)
175
180
 
176
181
  if link.name == "Association"
177
182
  assoc_connector = main_model.xpath(%(//connector[@xmi:idref="#{link['xmi:id']}"]/source)).first
@@ -197,18 +202,19 @@ module Lutaml
197
202
  end
198
203
  end
199
204
 
200
- [owned_cardinality, owned_attribute_name]
205
+ [owner_end, owned_cardinality, owned_attribute_name]
201
206
  end
202
207
 
203
- def serialize_member_type(owned_xmi_id, link)
208
+ def serialize_member_type(owner_xmi_id, link, link_member_name)
204
209
  return if link.name == 'NoteLink'
205
- return generalization_association(owned_xmi_id, link) if link.name == "Generalization"
210
+ return generalization_association(owner_xmi_id, link) if link.name == "Generalization"
206
211
 
207
- xmi_id = link.attributes["start"].value
212
+ xmi_id = link.attributes[link_member_name].value
208
213
  member_end = lookup_entity_name(xmi_id) || connector_source_name(xmi_id)
209
214
 
210
215
  if link.name == "Association"
211
- assoc_connector = main_model.xpath(%(//connector[@xmi:idref="#{link['xmi:id']}"]/target)).first
216
+ connector_type = link_member_name == "start" ? "source" : "target"
217
+ assoc_connector = main_model.xpath(%(//connector[@xmi:idref="#{link['xmi:id']}"]/#{connector_type})).first
212
218
  if assoc_connector
213
219
  connector_type = assoc_connector.children.find { |node| node.name == 'type' }
214
220
  if connector_type && connector_type.attributes['multiplicity']
@@ -234,8 +240,8 @@ module Lutaml
234
240
  [member_end, "aggregation", member_end_cardinality, member_end_attribute_name]
235
241
  end
236
242
 
237
- def generalization_association(owned_xmi_id, link)
238
- if link.attributes["start"].value == owned_xmi_id
243
+ def generalization_association(owner_xmi_id, link)
244
+ if link.attributes["start"].value == owner_xmi_id
239
245
  xmi_id = link.attributes["end"].value
240
246
  member_end_type = "inheritance"
241
247
  member_end = lookup_entity_name(xmi_id) || connector_target_name(xmi_id)
@@ -1,5 +1,5 @@
1
1
  module Lutaml
2
2
  module XMI
3
- VERSION = "0.2.0"
3
+ VERSION = "0.2.1"
4
4
  end
5
5
  end
@@ -88,7 +88,6 @@ RSpec.describe Lutaml::XMI::Parsers::XML do
88
88
  end
89
89
  let(:expected_association_names) do
90
90
  %w[
91
- TemporalGeometricPrimitive
92
91
  Primitive
93
92
  TemporalGeometry
94
93
  Interval
@@ -133,11 +132,6 @@ RSpec.describe Lutaml::XMI::Parsers::XML do
133
132
  inheritance = klass.associations.find { |entity| entity.member_end == 'TemporalGeometry' }
134
133
  expect(inheritance.member_end_type).to eq('inheritance')
135
134
  expect(inheritance.member_end_cardinality).to eq({"min"=>"C", "max"=>"*"})
136
-
137
- aggregation = klass.associations.find { |entity| entity.member_end == 'TemporalGeometricPrimitive' }
138
- expect(aggregation.member_end_attribute_name).to eq('element')
139
- expect(aggregation.member_end_type).to eq('aggregation')
140
- expect(aggregation.member_end_cardinality).to eq({"min"=>"C", "max"=>"*"})
141
135
  end
142
136
 
143
137
  it "correctly parses diagrams for package" do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lutaml-xmi
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-06-02 00:00:00.000000000 Z
11
+ date: 2021-06-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: hashie