lutaml 0.10.4 → 0.10.6
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.
- checksums.yaml +4 -4
- data/.gitignore +8 -0
- data/.rubocop.yml +10 -0
- data/.rubocop_todo.yml +218 -94
- data/TODO.cleanups/01-resolve-production-todos.md +65 -0
- data/TODO.cleanups/02-reduce-metrics-offenses.md +37 -0
- data/TODO.cleanups/03-reduce-rspec-multiple-expectations.md +54 -0
- data/TODO.cleanups/04-reduce-rspec-example-length.md +45 -0
- data/TODO.cleanups/05-replace-marshal-load.md +37 -0
- data/TODO.cleanups/06-replace-eval-in-tests.md +41 -0
- data/TODO.cleanups/07-fix-lint-offenses.md +74 -0
- data/TODO.cleanups/08-reduce-memoized-helpers-and-nesting.md +43 -0
- data/TODO.cleanups/09-reduce-verified-doubles-and-rspec-style.md +57 -0
- data/TODO.cleanups/10-split-large-files.md +47 -0
- data/bin/console +0 -1
- data/exe/lutaml +1 -0
- data/lib/lutaml/cli/element_identifier.rb +3 -6
- data/lib/lutaml/cli/interactive_shell/bookmark_commands.rb +88 -0
- data/lib/lutaml/cli/interactive_shell/command_base.rb +32 -0
- data/lib/lutaml/cli/interactive_shell/export_handler.rb +67 -0
- data/lib/lutaml/cli/interactive_shell/help_display.rb +114 -0
- data/lib/lutaml/cli/interactive_shell/navigation_commands.rb +135 -0
- data/lib/lutaml/cli/interactive_shell/query_commands.rb +185 -0
- data/lib/lutaml/cli/interactive_shell.rb +116 -802
- data/lib/lutaml/cli/uml/build_command.rb +5 -5
- data/lib/lutaml/cli/uml/verify_command.rb +0 -1
- data/lib/lutaml/converter/xmi_to_uml.rb +3 -153
- data/lib/lutaml/converter/xmi_to_uml_generalization.rb +193 -0
- data/lib/lutaml/formatter/graphviz.rb +1 -2
- data/lib/lutaml/qea/database.rb +1 -47
- data/lib/lutaml/qea/factory/association_builder.rb +188 -0
- data/lib/lutaml/qea/factory/base_transformer.rb +0 -1
- data/lib/lutaml/qea/factory/class_transformer.rb +40 -590
- data/lib/lutaml/qea/factory/diagram_transformer.rb +0 -3
- data/lib/lutaml/qea/factory/generalization_builder.rb +211 -0
- data/lib/lutaml/qea/factory/package_transformer.rb +1 -2
- data/lib/lutaml/qea/factory/stereotype_loader.rb +34 -0
- data/lib/lutaml/qea/lookup_indexes.rb +54 -0
- data/lib/lutaml/qea/models/ea_datatype.rb +0 -2
- data/lib/lutaml/qea/validation/validation_engine.rb +0 -2
- data/lib/lutaml/uml/has_members.rb +0 -1
- data/lib/lutaml/uml/inheritance_walker.rb +92 -0
- data/lib/lutaml/uml/model_helpers.rb +129 -0
- data/lib/lutaml/uml/node/attribute.rb +3 -1
- data/lib/lutaml/uml/node/class_node.rb +3 -3
- data/lib/lutaml/uml/operation.rb +2 -0
- data/lib/lutaml/uml_repository/class_lookup_index.rb +40 -0
- data/lib/lutaml/uml_repository/exporters/markdown/class_page_builder.rb +179 -0
- data/lib/lutaml/uml_repository/exporters/markdown/formatting.rb +36 -0
- data/lib/lutaml/uml_repository/exporters/markdown/index_page_builder.rb +73 -0
- data/lib/lutaml/uml_repository/exporters/markdown/link_resolver.rb +40 -0
- data/lib/lutaml/uml_repository/exporters/markdown/package_page_builder.rb +107 -0
- data/lib/lutaml/uml_repository/exporters/markdown_exporter.rb +26 -538
- data/lib/lutaml/uml_repository/index_builder.rb +3 -271
- data/lib/lutaml/uml_repository/index_builders/association_index.rb +141 -0
- data/lib/lutaml/uml_repository/index_builders/class_index.rb +94 -0
- data/lib/lutaml/uml_repository/index_builders/package_index.rb +57 -0
- data/lib/lutaml/uml_repository/package_exporter.rb +10 -20
- data/lib/lutaml/uml_repository/package_loader.rb +37 -17
- data/lib/lutaml/uml_repository/repository/deprecated.rb +39 -0
- data/lib/lutaml/uml_repository/repository/loader.rb +112 -0
- data/lib/lutaml/uml_repository/repository.rb +7 -57
- data/lib/lutaml/uml_repository/static_site/association_serialization.rb +142 -0
- data/lib/lutaml/uml_repository/static_site/configuration.rb +0 -2
- data/lib/lutaml/uml_repository/static_site/data_transformer.rb +52 -873
- data/lib/lutaml/uml_repository/static_site/generator.rb +29 -8
- data/lib/lutaml/uml_repository/static_site/search_index_builder.rb +1 -4
- data/lib/lutaml/uml_repository/static_site/serializers/attribute_serializer.rb +78 -0
- data/lib/lutaml/uml_repository/static_site/serializers/class_serializer.rb +124 -0
- data/lib/lutaml/uml_repository/static_site/serializers/diagram_serializer.rb +60 -0
- data/lib/lutaml/uml_repository/static_site/serializers/inheritance_resolver.rb +258 -0
- data/lib/lutaml/uml_repository/static_site/serializers/metadata_builder.rb +48 -0
- data/lib/lutaml/uml_repository/static_site/serializers/operation_serializer.rb +57 -0
- data/lib/lutaml/uml_repository/static_site/serializers/package_serializer.rb +94 -0
- data/lib/lutaml/uml_repository/static_site/serializers/package_tree_builder.rb +93 -0
- data/lib/lutaml/version.rb +1 -1
- data/lib/lutaml/xmi/liquid_drops/association_drop.rb +13 -35
- data/lib/lutaml/xmi/liquid_drops/attribute_drop.rb +12 -18
- data/lib/lutaml/xmi/liquid_drops/cardinality_drop.rb +14 -6
- data/lib/lutaml/xmi/liquid_drops/connector_drop.rb +0 -3
- data/lib/lutaml/xmi/liquid_drops/constraint_drop.rb +1 -3
- data/lib/lutaml/xmi/liquid_drops/data_type_drop.rb +13 -70
- data/lib/lutaml/xmi/liquid_drops/dependency_drop.rb +2 -5
- data/lib/lutaml/xmi/liquid_drops/diagram_drop.rb +5 -11
- data/lib/lutaml/xmi/liquid_drops/enum_drop.rb +8 -16
- data/lib/lutaml/xmi/liquid_drops/enum_owned_literal_drop.rb +3 -9
- data/lib/lutaml/xmi/liquid_drops/generalization_attribute_drop.rb +11 -13
- data/lib/lutaml/xmi/liquid_drops/generalization_drop.rb +27 -85
- data/lib/lutaml/xmi/liquid_drops/klass_drop.rb +39 -91
- data/lib/lutaml/xmi/liquid_drops/operation_drop.rb +3 -9
- data/lib/lutaml/xmi/liquid_drops/package_drop.rb +16 -44
- data/lib/lutaml/xmi/liquid_drops/root_drop.rb +3 -11
- data/lib/lutaml/xmi/liquid_drops/source_target_drop.rb +2 -5
- data/lib/lutaml/xmi/parsers/xmi_base.rb +2 -749
- data/lib/lutaml/xmi/parsers/xmi_class_members.rb +45 -0
- data/lib/lutaml/xmi/parsers/xmi_connector.rb +251 -0
- data/lib/lutaml/xmi/parsers/xml.rb +7 -120
- data/lib/lutaml/xmi/xmi_lookup_service.rb +42 -0
- data/lib/lutaml.rb +0 -1
- metadata +48 -21
- data/lib/lutaml/cli/commands/base_command.rb +0 -118
- data/lib/lutaml/command_line.rb +0 -272
- data/lib/lutaml/sysml/allocate.rb +0 -9
- data/lib/lutaml/sysml/allocated.rb +0 -9
- data/lib/lutaml/sysml/binding_connector.rb +0 -9
- data/lib/lutaml/sysml/block.rb +0 -32
- data/lib/lutaml/sysml/constraint_block.rb +0 -14
- data/lib/lutaml/sysml/copy.rb +0 -8
- data/lib/lutaml/sysml/derive_requirement.rb +0 -9
- data/lib/lutaml/sysml/nested_connector_end.rb +0 -13
- data/lib/lutaml/sysml/refine.rb +0 -9
- data/lib/lutaml/sysml/requirement.rb +0 -44
- data/lib/lutaml/sysml/requirement_related.rb +0 -9
- data/lib/lutaml/sysml/satisfy.rb +0 -9
- data/lib/lutaml/sysml/test_case.rb +0 -25
- data/lib/lutaml/sysml/trace.rb +0 -9
- data/lib/lutaml/sysml/verify.rb +0 -8
- data/lib/lutaml/sysml/xmi_file.rb +0 -486
- data/lib/lutaml/sysml.rb +0 -11
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Lutaml
|
|
4
|
+
module Xmi
|
|
5
|
+
module Parsers
|
|
6
|
+
module XmiBase
|
|
7
|
+
# Class member (attribute, operation, constraint) helpers
|
|
8
|
+
# used by XmiLookupService and Pipeline C (XmiToUml)
|
|
9
|
+
|
|
10
|
+
# @param klass_id [String]
|
|
11
|
+
# @return [Lutaml::Model::Serializable]
|
|
12
|
+
# @note xpath %(//element[@xmi:idref="#{klass_id}"])
|
|
13
|
+
def fetch_element(klass_id)
|
|
14
|
+
xmi_index.find_element(klass_id)
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def loopup_assoc_def(association)
|
|
18
|
+
connector = fetch_connector(association)
|
|
19
|
+
connector&.documentation&.value
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
# @param xmi_id [String]
|
|
23
|
+
# @return [String]
|
|
24
|
+
def get_ns_by_xmi_id(xmi_id)
|
|
25
|
+
return unless xmi_id
|
|
26
|
+
|
|
27
|
+
p = find_packaged_element_by_id(xmi_id)
|
|
28
|
+
return unless p
|
|
29
|
+
|
|
30
|
+
find_upper_level_packaged_element(p.id)&.name
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
# @param min [String]
|
|
34
|
+
# @param max [String]
|
|
35
|
+
# @return [Hash]
|
|
36
|
+
def cardinality_min_max_value(min, max)
|
|
37
|
+
{
|
|
38
|
+
min: min,
|
|
39
|
+
max: max,
|
|
40
|
+
}
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
end
|
|
@@ -0,0 +1,251 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Lutaml
|
|
4
|
+
module Xmi
|
|
5
|
+
module Parsers
|
|
6
|
+
module XmiBase
|
|
7
|
+
# Association/connector serialization helpers used by Pipeline C
|
|
8
|
+
|
|
9
|
+
# @param link_id [String]
|
|
10
|
+
# @return [Lutaml::Model::Serializable]
|
|
11
|
+
# @note xpath %(//connector[@xmi:idref="#{link_id}"])
|
|
12
|
+
def fetch_connector(link_id)
|
|
13
|
+
xmi_index.find_connector(link_id)
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
# @param link_id [String]
|
|
17
|
+
# @param node_name [String] source or target
|
|
18
|
+
# @return [String]
|
|
19
|
+
# @note xpath
|
|
20
|
+
# %(//connector[@xmi:idref="#{link_id}"]/#{node_name}/documentation)
|
|
21
|
+
def fetch_definition_node_value(link_id, node_name)
|
|
22
|
+
connector_node = fetch_connector(link_id)
|
|
23
|
+
return nil unless connector_node
|
|
24
|
+
|
|
25
|
+
node = connector_node.send(node_name.to_sym)
|
|
26
|
+
return nil unless node
|
|
27
|
+
|
|
28
|
+
documentation = node.documentation
|
|
29
|
+
|
|
30
|
+
if documentation.is_a?(::Xmi::Sparx::Element::Documentation)
|
|
31
|
+
documentation&.value
|
|
32
|
+
else
|
|
33
|
+
documentation
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
# @param owner_xmi_id [String]
|
|
38
|
+
# @param link [Lutaml::Model::Serializable]
|
|
39
|
+
# @param link_member_name [String]
|
|
40
|
+
# @return [String]
|
|
41
|
+
def serialize_owned_type(owner_xmi_id, link, linke_owner_name)
|
|
42
|
+
case link
|
|
43
|
+
when ::Xmi::Sparx::Element::NoteLink
|
|
44
|
+
return
|
|
45
|
+
when ::Xmi::Sparx::Element::Generalization
|
|
46
|
+
owner_end, _owner_end_type, _owner_xmi_id =
|
|
47
|
+
generalization_association(owner_xmi_id, link)
|
|
48
|
+
return owner_end
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
xmi_id = link.send(linke_owner_name.to_sym)
|
|
52
|
+
lookup_entity_name(xmi_id) || connector_source_name(xmi_id)
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
# @param owner_xmi_id [String]
|
|
56
|
+
# @param link [Lutaml::Model::Serializable]
|
|
57
|
+
# @return [Array<String, String>]
|
|
58
|
+
def serialize_member_end(owner_xmi_id, link) # rubocop:disable Metrics/MethodLength,Metrics/AbcSize,Metrics/CyclomaticComplexity
|
|
59
|
+
case link.name
|
|
60
|
+
when "NoteLink"
|
|
61
|
+
return
|
|
62
|
+
when "Generalization"
|
|
63
|
+
return generalization_association(owner_xmi_id, link)
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
xmi_id = link.start
|
|
67
|
+
source_or_target = :source
|
|
68
|
+
|
|
69
|
+
if link.start == owner_xmi_id
|
|
70
|
+
xmi_id = link.end
|
|
71
|
+
source_or_target = :target
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
connector = fetch_connector(link.id)
|
|
75
|
+
ea_type = connector&.properties&.ea_type
|
|
76
|
+
member_end_type = ea_type&.downcase
|
|
77
|
+
|
|
78
|
+
member_end = member_end_name(xmi_id, source_or_target, link)
|
|
79
|
+
[member_end, member_end_type, xmi_id]
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
# @param xmi_id [String]
|
|
83
|
+
# @param source_or_target [Symbol]
|
|
84
|
+
# @return [String]
|
|
85
|
+
def member_end_name(xmi_id, source_or_target, link) # rubocop:disable Metrics/MethodLength
|
|
86
|
+
connector_label = connector_labels(xmi_id, source_or_target)
|
|
87
|
+
entity_name = lookup_entity_name(xmi_id)
|
|
88
|
+
connector_name = connector_name_by_source_or_target(
|
|
89
|
+
xmi_id, source_or_target
|
|
90
|
+
)
|
|
91
|
+
|
|
92
|
+
case link
|
|
93
|
+
when ::Xmi::Sparx::Element::Aggregation
|
|
94
|
+
connector_label || entity_name || connector_name
|
|
95
|
+
else
|
|
96
|
+
entity_name || connector_name
|
|
97
|
+
end
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
# @param owner_xmi_id [String]
|
|
101
|
+
# @param link [Lutaml::Model::Serializable]
|
|
102
|
+
# @param link_member_name [String]
|
|
103
|
+
# @return [Array<String, String, Hash, String, String>]
|
|
104
|
+
def serialize_member_type(owner_xmi_id, link, link_member_name) # rubocop:disable Metrics/MethodLength,Metrics/AbcSize
|
|
105
|
+
member_end, member_end_type, xmi_id =
|
|
106
|
+
serialize_member_end(owner_xmi_id, link)
|
|
107
|
+
|
|
108
|
+
if link.is_a?(::Xmi::Sparx::Element::Association)
|
|
109
|
+
connector_type = link_member_name == "start" ? "source" : "target"
|
|
110
|
+
member_end_cardinality, member_end_attribute_name =
|
|
111
|
+
fetch_assoc_connector(link.id, connector_type)
|
|
112
|
+
else
|
|
113
|
+
member_end_cardinality, member_end_attribute_name =
|
|
114
|
+
fetch_owned_attribute_node(xmi_id)
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
if fetch_connector_name(link.id)
|
|
118
|
+
member_end = fetch_connector_name(link.id)
|
|
119
|
+
end
|
|
120
|
+
|
|
121
|
+
[member_end, member_end_type, member_end_cardinality,
|
|
122
|
+
member_end_attribute_name, xmi_id]
|
|
123
|
+
end
|
|
124
|
+
|
|
125
|
+
def fetch_connector_name(link_id)
|
|
126
|
+
connector = fetch_connector(link_id)
|
|
127
|
+
connector&.name
|
|
128
|
+
end
|
|
129
|
+
|
|
130
|
+
# @param link_id [String]
|
|
131
|
+
# @param connector_type [String]
|
|
132
|
+
# @return [Array<Hash, String>]
|
|
133
|
+
# @note xpath %(//connector[@xmi:idref="#{link_id}"]/#{connector_type})
|
|
134
|
+
def fetch_assoc_connector(link_id, connector_type) # rubocop:disable Metrics/AbcSize,Metrics/MethodLength,Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity
|
|
135
|
+
connector = fetch_connector(link_id)
|
|
136
|
+
return [nil, nil] unless connector
|
|
137
|
+
|
|
138
|
+
assoc_connector = connector.send(connector_type.to_sym)
|
|
139
|
+
|
|
140
|
+
if assoc_connector
|
|
141
|
+
assoc_connector_type = assoc_connector.type
|
|
142
|
+
if assoc_connector_type&.multiplicity
|
|
143
|
+
cardinality = assoc_connector_type.multiplicity.split("..")
|
|
144
|
+
cardinality.unshift("1") if cardinality.length == 1
|
|
145
|
+
min, max = cardinality
|
|
146
|
+
end
|
|
147
|
+
|
|
148
|
+
assoc_connector_role = assoc_connector.role
|
|
149
|
+
attribute_name = assoc_connector.model.name if assoc_connector_role
|
|
150
|
+
cardinality = cardinality_min_max_value(min, max)
|
|
151
|
+
end
|
|
152
|
+
|
|
153
|
+
[cardinality, attribute_name]
|
|
154
|
+
end
|
|
155
|
+
|
|
156
|
+
# @param owner_xmi_id [String]
|
|
157
|
+
# @param link [Lutaml::Model::Serializable]
|
|
158
|
+
# @return [Array<String, String, Hash, String, String>]
|
|
159
|
+
# @note match return value of serialize_member_type
|
|
160
|
+
def generalization_association(owner_xmi_id, link) # rubocop:disable Metrics/MethodLength
|
|
161
|
+
member_end_type = "generalization"
|
|
162
|
+
xmi_id = link.start
|
|
163
|
+
source_or_target = :source
|
|
164
|
+
|
|
165
|
+
if link.start == owner_xmi_id
|
|
166
|
+
member_end_type = "inheritance"
|
|
167
|
+
xmi_id = link.end
|
|
168
|
+
source_or_target = :target
|
|
169
|
+
end
|
|
170
|
+
|
|
171
|
+
member_end = member_end_name(xmi_id, source_or_target, link)
|
|
172
|
+
|
|
173
|
+
[member_end, member_end_type, xmi_id]
|
|
174
|
+
end
|
|
175
|
+
|
|
176
|
+
# Multiple items if search type is idref. Should search association?
|
|
177
|
+
# @param xmi_id [String]
|
|
178
|
+
# @return [Array<Hash, String>]
|
|
179
|
+
# @note xpath
|
|
180
|
+
# %(//ownedAttribute[@association]/type[@xmi:id ref="#{xmi_id}"])
|
|
181
|
+
def fetch_owned_attribute_node(xmi_id)
|
|
182
|
+
oa = xmi_index.find_owned_attrs_by_type(xmi_id)
|
|
183
|
+
.find { |a| !!a.association }
|
|
184
|
+
|
|
185
|
+
if oa
|
|
186
|
+
cardinality = cardinality_min_max_value(
|
|
187
|
+
oa.lower_value&.value, oa.upper_value&.value
|
|
188
|
+
)
|
|
189
|
+
oa_name = oa.name
|
|
190
|
+
end
|
|
191
|
+
|
|
192
|
+
[cardinality, oa_name]
|
|
193
|
+
end
|
|
194
|
+
|
|
195
|
+
# @param xmi_id [String]
|
|
196
|
+
# @param source_or_target [String]
|
|
197
|
+
# @return [String]
|
|
198
|
+
def connector_node_by_id(xmi_id, source_or_target)
|
|
199
|
+
connector_lookup[[source_or_target.to_sym, xmi_id]]
|
|
200
|
+
end
|
|
201
|
+
|
|
202
|
+
# Lazy-built hash index for O(1) connector lookups
|
|
203
|
+
# @return [Hash] Mapping of [direction, idref] => connector
|
|
204
|
+
def connector_lookup
|
|
205
|
+
@connector_lookup ||= begin
|
|
206
|
+
lookup = {}
|
|
207
|
+
connectors = @xmi_root_model.extension&.connectors&.connector || []
|
|
208
|
+
connectors.each do |con|
|
|
209
|
+
%i[source target].each do |dir|
|
|
210
|
+
idref = con.send(dir)&.idref
|
|
211
|
+
lookup[[dir, idref]] = con if idref
|
|
212
|
+
end
|
|
213
|
+
end
|
|
214
|
+
lookup
|
|
215
|
+
end
|
|
216
|
+
end
|
|
217
|
+
|
|
218
|
+
# @param xmi_id [String]
|
|
219
|
+
# @param source_or_target [String]
|
|
220
|
+
# @return [String]
|
|
221
|
+
def connector_name_by_source_or_target(xmi_id, source_or_target) # rubocop:disable Metrics/AbcSize
|
|
222
|
+
node = connector_node_by_id(xmi_id, source_or_target)
|
|
223
|
+
return node.name if node&.name
|
|
224
|
+
|
|
225
|
+
return if node.nil? ||
|
|
226
|
+
node.send(source_or_target.to_sym).nil? ||
|
|
227
|
+
node.send(source_or_target.to_sym).model.nil?
|
|
228
|
+
|
|
229
|
+
node.send(source_or_target.to_sym).model.name
|
|
230
|
+
end
|
|
231
|
+
|
|
232
|
+
# @param xmi_id [String]
|
|
233
|
+
# @param source_or_target [String]
|
|
234
|
+
# @return [String]
|
|
235
|
+
def connector_labels(xmi_id, source_or_target)
|
|
236
|
+
node = connector_node_by_id(xmi_id, source_or_target)
|
|
237
|
+
return if node.nil?
|
|
238
|
+
|
|
239
|
+
node.labels&.rt || node.labels&.lt
|
|
240
|
+
end
|
|
241
|
+
|
|
242
|
+
# @param xmi_id [String]
|
|
243
|
+
# @return [String]
|
|
244
|
+
# @note xpath %(//source[@xmi:idref="#{xmi_id}"]/model)
|
|
245
|
+
def connector_source_name(xmi_id)
|
|
246
|
+
connector_name_by_source_or_target(xmi_id, :source)
|
|
247
|
+
end
|
|
248
|
+
end
|
|
249
|
+
end
|
|
250
|
+
end
|
|
251
|
+
end
|
|
@@ -4,6 +4,7 @@ require "nokogiri"
|
|
|
4
4
|
require "htmlentities"
|
|
5
5
|
require "xmi"
|
|
6
6
|
require_relative "xmi_base"
|
|
7
|
+
require_relative "../xmi_lookup_service"
|
|
7
8
|
require "lutaml/converter/xmi_to_uml"
|
|
8
9
|
|
|
9
10
|
module Lutaml
|
|
@@ -13,11 +14,7 @@ module Lutaml
|
|
|
13
14
|
class Xml
|
|
14
15
|
include Lutaml::Converter::XmiToUml
|
|
15
16
|
|
|
16
|
-
|
|
17
|
-
@xmi_root_model_cache_static = {}
|
|
18
|
-
|
|
19
|
-
attr_reader :id_name_mapping, :xmi_root_model,
|
|
20
|
-
:all_packaged_elements_cache
|
|
17
|
+
attr_reader :id_name_mapping, :xmi_root_model
|
|
21
18
|
|
|
22
19
|
include XmiBase
|
|
23
20
|
|
|
@@ -30,69 +27,12 @@ module Lutaml
|
|
|
30
27
|
new.parse(xmi_model)
|
|
31
28
|
end
|
|
32
29
|
|
|
33
|
-
# @param xml [String] path to xml
|
|
34
|
-
# @param with_gen [Boolean]
|
|
35
|
-
# @return [Hash]
|
|
36
|
-
def serialize_xmi(xml, with_gen: false)
|
|
37
|
-
xmi_model = get_xmi_model(xml)
|
|
38
|
-
new.serialize_xmi(xmi_model, with_gen: with_gen)
|
|
39
|
-
end
|
|
40
|
-
|
|
41
30
|
# @param xml [String] path to xml
|
|
42
31
|
# @return [Liquid::Drop]
|
|
43
32
|
def serialize_xmi_to_liquid(xml, guidance = nil)
|
|
44
33
|
xmi_model = get_xmi_model(xml)
|
|
45
34
|
new.serialize_xmi_to_liquid(xmi_model, guidance)
|
|
46
35
|
end
|
|
47
|
-
|
|
48
|
-
# @param xmi_path [String] path to xml
|
|
49
|
-
# @param name [String]
|
|
50
|
-
# @param guidance [String]
|
|
51
|
-
# @return [Hash]
|
|
52
|
-
def serialize_generalization_by_name( # rubocop:disable Metrics/MethodLength
|
|
53
|
-
xmi_path, name, guidance = nil
|
|
54
|
-
)
|
|
55
|
-
# Load from cache or file
|
|
56
|
-
xml_cache_key = (Digest::SHA256.file xmi_path).hexdigest
|
|
57
|
-
xmi_model = @xmi_root_model_cache_static[xml_cache_key] ||
|
|
58
|
-
get_xmi_model(xmi_path)
|
|
59
|
-
id_name_mapping = @id_name_mapping_static[xml_cache_key]
|
|
60
|
-
|
|
61
|
-
instance = new
|
|
62
|
-
ret_val = instance.serialize_generalization_by_name(
|
|
63
|
-
xmi_model, name, guidance, id_name_mapping
|
|
64
|
-
)
|
|
65
|
-
|
|
66
|
-
# Put xmi_model and id_name_mapping to cache
|
|
67
|
-
@id_name_mapping_static[xml_cache_key] ||= instance.id_name_mapping
|
|
68
|
-
@xmi_root_model_cache_static[xml_cache_key] ||= xmi_model
|
|
69
|
-
|
|
70
|
-
ret_val
|
|
71
|
-
end
|
|
72
|
-
|
|
73
|
-
# @param xmi_path [String] path to xml
|
|
74
|
-
# @param name [String]
|
|
75
|
-
# @return [Hash]
|
|
76
|
-
def serialize_enumeration_by_name( # rubocop:disable Metrics/MethodLength
|
|
77
|
-
xmi_path, name
|
|
78
|
-
)
|
|
79
|
-
# Load from cache or file
|
|
80
|
-
xml_cache_key = (Digest::SHA256.file xmi_path).hexdigest
|
|
81
|
-
xmi_model = @xmi_root_model_cache_static[xml_cache_key] ||
|
|
82
|
-
get_xmi_model(xmi_path)
|
|
83
|
-
id_name_mapping = @id_name_mapping_static[xml_cache_key]
|
|
84
|
-
|
|
85
|
-
instance = new
|
|
86
|
-
enum = instance.serialize_enumeration_by_name(
|
|
87
|
-
xmi_model, name, id_name_mapping
|
|
88
|
-
)
|
|
89
|
-
|
|
90
|
-
# Put xmi_model and id_name_mapping to cache
|
|
91
|
-
@id_name_mapping_static[xml_cache_key] ||= instance.id_name_mapping
|
|
92
|
-
@xmi_root_model_cache_static[xml_cache_key] ||= xmi_model
|
|
93
|
-
|
|
94
|
-
enum
|
|
95
|
-
end
|
|
96
36
|
end
|
|
97
37
|
|
|
98
38
|
# @param xmi_model [Lutaml::Model::Serializable]
|
|
@@ -102,75 +42,22 @@ module Lutaml
|
|
|
102
42
|
create_uml_document(xmi_model)
|
|
103
43
|
end
|
|
104
44
|
|
|
105
|
-
# @param xmi_model [Lutaml::Model::Serializable]
|
|
106
|
-
# @param with_gen: [Boolean]
|
|
107
|
-
# @param with_absolute_path: [Boolean]
|
|
108
|
-
# return [Hash]
|
|
109
|
-
def serialize_xmi(xmi_model, with_gen: false, with_absolute_path: false)
|
|
110
|
-
set_xmi_model(xmi_model)
|
|
111
|
-
serialize_to_hash(
|
|
112
|
-
xmi_model,
|
|
113
|
-
with_gen: with_gen,
|
|
114
|
-
with_absolute_path: with_absolute_path,
|
|
115
|
-
)
|
|
116
|
-
end
|
|
117
|
-
|
|
118
45
|
# @param xmi_model [Lutaml::Model::Serializable]
|
|
119
46
|
# @param guidance_yaml [String]
|
|
120
47
|
# return [Liquid::Drop]
|
|
121
48
|
def serialize_xmi_to_liquid(xmi_model, guidance = nil)
|
|
122
49
|
set_xmi_model(xmi_model)
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
xmi_root_model: @xmi_root_model,
|
|
126
|
-
id_name_mapping: @id_name_mapping,
|
|
127
|
-
with_gen: true,
|
|
128
|
-
with_absolute_path: true,
|
|
129
|
-
}
|
|
130
|
-
::Lutaml::Xmi::LiquidDrops::RootDrop.new(model, guidance, options)
|
|
131
|
-
end
|
|
132
|
-
|
|
133
|
-
# @param xmi_model [Lutaml::Model::Serializable]
|
|
134
|
-
# @param name [String]
|
|
135
|
-
# @param guidance_yaml [String]
|
|
136
|
-
# @param id_name_mapping [Hash]
|
|
137
|
-
# @return [Hash]
|
|
138
|
-
def serialize_generalization_by_name( # rubocop:disable Metrics/MethodLength
|
|
139
|
-
xmi_model, name, guidance = nil, id_name_mapping = nil
|
|
140
|
-
)
|
|
141
|
-
set_xmi_model(xmi_model, id_name_mapping)
|
|
142
|
-
klass = find_klass_packaged_element(name)
|
|
143
|
-
options = {
|
|
144
|
-
xmi_root_model: @xmi_root_model,
|
|
145
|
-
id_name_mapping: @id_name_mapping,
|
|
146
|
-
with_gen: true,
|
|
147
|
-
with_absolute_path: true,
|
|
148
|
-
}
|
|
149
|
-
puts "Error: Class not found for name: #{name}!" if klass.nil?
|
|
150
|
-
::Lutaml::Xmi::LiquidDrops::KlassDrop.new(
|
|
151
|
-
klass,
|
|
152
|
-
guidance,
|
|
153
|
-
options,
|
|
154
|
-
)
|
|
155
|
-
end
|
|
156
|
-
|
|
157
|
-
# @param xmi_model [Lutaml::Model::Serializable]
|
|
158
|
-
# @param name [String]
|
|
159
|
-
# @param id_name_mapping [Hash]
|
|
160
|
-
# @return [Hash]
|
|
161
|
-
def serialize_enumeration_by_name( # rubocop:disable Metrics/MethodLength
|
|
162
|
-
xmi_model, name, id_name_mapping = nil
|
|
163
|
-
)
|
|
164
|
-
set_xmi_model(xmi_model, id_name_mapping)
|
|
165
|
-
enum = find_enum_packaged_element_by_name(name)
|
|
50
|
+
uml_document = create_uml_document(xmi_model)
|
|
51
|
+
lookup = XmiLookupService.new(@xmi_root_model, @id_name_mapping)
|
|
166
52
|
options = {
|
|
167
53
|
xmi_root_model: @xmi_root_model,
|
|
168
54
|
id_name_mapping: @id_name_mapping,
|
|
55
|
+
lookup: lookup,
|
|
169
56
|
with_gen: true,
|
|
170
57
|
with_absolute_path: true,
|
|
171
58
|
}
|
|
172
|
-
|
|
173
|
-
|
|
59
|
+
::Lutaml::Xmi::LiquidDrops::RootDrop.new(uml_document, guidance,
|
|
60
|
+
options)
|
|
174
61
|
end
|
|
175
62
|
end
|
|
176
63
|
end
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "parsers/xmi_base"
|
|
4
|
+
|
|
5
|
+
module Lutaml
|
|
6
|
+
module Xmi
|
|
7
|
+
# Single bridge between Liquid Drop classes and the XMI document tree.
|
|
8
|
+
# Drops receive an instance of this service instead of including XmiBase directly.
|
|
9
|
+
class XmiLookupService
|
|
10
|
+
include Parsers::XmiBase
|
|
11
|
+
|
|
12
|
+
def initialize(xmi_root_model, id_name_mapping)
|
|
13
|
+
@xmi_root_model = xmi_root_model
|
|
14
|
+
@id_name_mapping = id_name_mapping
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
# XmiBase methods are private by default; expose as public API for Drops
|
|
18
|
+
public :doc_node_attribute_value,
|
|
19
|
+
:lookup_entity_name,
|
|
20
|
+
:lookup_attribute_documentation,
|
|
21
|
+
:find_upper_level_packaged_element,
|
|
22
|
+
:find_packaged_element_by_id,
|
|
23
|
+
:get_ns_by_xmi_id,
|
|
24
|
+
:loopup_assoc_def,
|
|
25
|
+
:fetch_connector,
|
|
26
|
+
:fetch_definition_node_value,
|
|
27
|
+
:select_dependencies_by_supplier,
|
|
28
|
+
:select_dependencies_by_client,
|
|
29
|
+
:select_all_packaged_elements,
|
|
30
|
+
:find_subtype_of_from_generalization,
|
|
31
|
+
:find_subtype_of_from_owned_attribute_type,
|
|
32
|
+
:get_package_name,
|
|
33
|
+
:xmi_index
|
|
34
|
+
|
|
35
|
+
# Convenience: find extension element by XMI id (used by Drops for
|
|
36
|
+
# dependency/inheritance lookups)
|
|
37
|
+
def find_matched_element(xmi_id)
|
|
38
|
+
xmi_index&.find_element(xmi_id)
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
end
|
data/lib/lutaml.rb
CHANGED