lib/lutaml/xmi/parsers/xml.rb in lutaml-xmi-0.2.1 vs lib/lutaml/xmi/parsers/xml.rb in lutaml-xmi-0.2.2

- old
+ new

@@ -1,15 +1,16 @@ require "nokogiri" +require "htmlentities" require "lutaml/uml/has_attributes" require "lutaml/uml/document" module Lutaml module XMI module Parsers # Class for parsing .xmi schema files into ::Lutaml::Uml::Document class XML - LOVER_VALUE_MAPPINGS = { + LOWER_VALUE_MAPPINGS = { "0" => "C", "1" => "M", }.freeze attr_reader :main_model, :xmi_cache @@ -53,11 +54,11 @@ } end end def serialize_model_classes(model) - model.xpath('./packagedElement[@xmi:type="uml:Class"]').map do |klass| + model.xpath('./packagedElement[@xmi:type="uml:Class" or @xmi:type="uml:AssociationClass"]').map do |klass| { xmi_id: klass["xmi:id"], xmi_uuid: klass["xmi:uuid"], name: klass["name"], package: model, @@ -143,11 +144,11 @@ member_end_attribute_name: member_end_attribute_name, owner_end: owner_end, definition: definition } end - end + end.uniq end def serialize_class_operations(klass) klass.xpath('.//ownedOperation').map do |attribute| type = attribute.xpath(".//type").first || {} @@ -165,10 +166,11 @@ def serialize_class_constraints(klass) class_element_metadata(klass).xpath("./constraints/constraint").map do |constraint| { xmi_id: constraint["xmi:id"], body: constraint["name"], + definition: HTMLEntities.new.decode(constraint["description"]) } end end def serialize_owned_type(owner_xmi_id, link, linke_owner_name) @@ -189,11 +191,11 @@ end connector_role = assoc_connector.children.find { |node| node.name == 'role' } if connector_role owned_attribute_name = connector_role.attributes["name"]&.value end - owned_cardinality = { "min" => LOVER_VALUE_MAPPINGS[min], "max" => max } + owned_cardinality = { "min" => LOWER_VALUE_MAPPINGS[min], "max" => max } end else owned_node = main_model.xpath(%(//ownedAttribute[@association]/type[@xmi:idref="#{xmi_id}"])).first if owned_node assoc = owned_node.parent @@ -208,11 +210,17 @@ def serialize_member_type(owner_xmi_id, link, link_member_name) return if link.name == 'NoteLink' return generalization_association(owner_xmi_id, link) if link.name == "Generalization" xmi_id = link.attributes[link_member_name].value - member_end = lookup_entity_name(xmi_id) || connector_source_name(xmi_id) + if link.attributes["start"].value == owner_xmi_id + xmi_id = link.attributes["end"].value + member_end = lookup_entity_name(xmi_id) || connector_target_name(xmi_id) + else + xmi_id = link.attributes["start"].value + member_end = lookup_entity_name(xmi_id) || connector_source_name(xmi_id) + end if link.name == "Association" connector_type = link_member_name == "start" ? "source" : "target" assoc_connector = main_model.xpath(%(//connector[@xmi:idref="#{link['xmi:id']}"]/#{connector_type})).first if assoc_connector @@ -224,11 +232,11 @@ end connector_role = assoc_connector.children.find { |node| node.name == 'role' } if connector_role member_end_attribute_name = connector_role.attributes["name"]&.value end - member_end_cardinality = { "min" => LOVER_VALUE_MAPPINGS[min], "max" => max } + member_end_cardinality = { "min" => LOWER_VALUE_MAPPINGS[min], "max" => max } end else member_end_node = main_model.xpath(%(//ownedAttribute[@association]/type[@xmi:idref="#{xmi_id}"])).first if member_end_node assoc = member_end_node.parent @@ -284,10 +292,10 @@ def cardinality_min_value(node) lower_value_node = node.xpath(".//lowerValue").first return unless lower_value_node lower_value = lower_value_node.attributes["value"]&.value - LOVER_VALUE_MAPPINGS[lower_value] + LOWER_VALUE_MAPPINGS[lower_value] end def cardinality_max_value(node) upper_value_node = node.xpath(".//upperValue").first return unless upper_value_node