Class: Lutaml::Qea::Factory::GeneralizationBuilder
- Inherits:
-
BaseTransformer
- Object
- BaseTransformer
- Lutaml::Qea::Factory::GeneralizationBuilder
- Defined in:
- lib/lutaml/qea/factory/generalization_builder.rb
Instance Attribute Summary
Attributes inherited from BaseTransformer
Instance Method Summary collapse
- #convert_to_general_attributes(attributes) ⇒ Object
- #convert_to_top_element_attributes(attributes) ⇒ Object
- #load_association_generalizations(object_id) ⇒ Object
-
#load_generalization(object_id, visited = Set.new, is_leaf = true) ⇒ Object
rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/MethodLength,Metrics/PerceivedComplexity,Style/OptionalBooleanParameter.
Methods inherited from BaseTransformer
#initialize, #transform, #transform_collection
Constructor Details
This class inherits a constructor from Lutaml::Qea::Factory::BaseTransformer
Instance Method Details
#convert_to_general_attributes(attributes) ⇒ Object
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/lutaml/qea/factory/generalization_builder.rb', line 108 def convert_to_general_attributes(attributes) attributes.map do |attr| Lutaml::Uml::GeneralAttribute.new.tap do |gen_attr| gen_attr.id = attr.id gen_attr.name = attr.name gen_attr.type = attr.type gen_attr.xmi_id = attr.xmi_id gen_attr.is_derived = !!attr.is_derived gen_attr.cardinality = attr.cardinality gen_attr.definition = attr.definition&.strip gen_attr.association = attr.association gen_attr.has_association = !!attr.association gen_attr.type_ns = attr.type_ns end end end |
#convert_to_top_element_attributes(attributes) ⇒ Object
125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 |
# File 'lib/lutaml/qea/factory/generalization_builder.rb', line 125 def convert_to_top_element_attributes(attributes) attributes.map do |attr| Lutaml::Uml::TopElementAttribute.new.tap do |top_attr| top_attr.id = attr.id top_attr.name = attr.name top_attr.type = attr.type top_attr.xmi_id = attr.xmi_id top_attr.cardinality = attr.cardinality top_attr.definition = attr.definition&.strip top_attr.association = attr.association top_attr.type_ns = attr.type_ns top_attr.is_derived = !!attr.is_derived end end end |
#load_association_generalizations(object_id) ⇒ Object
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/lutaml/qea/factory/generalization_builder.rb', line 86 def load_association_generalizations(object_id) return [] if object_id.nil? gen_connectors = database.connectors_for_object(object_id) .select { |c| c.generalization? && c.start_object_id == object_id } gen_connectors.filter_map do |ea_connector| guid = ea_connector.ea_guid parent_object_id = ea_connector.end_object_id parent_obj = find_object_by_id(parent_object_id) next unless parent_obj Lutaml::Uml::AssociationGeneralization.new.tap do |ag| ag.id = normalize_guid_to_xmi_format(guid, "EAID") ag.type = "uml:Generalization" ag.general = normalize_guid_to_xmi_format(parent_obj.ea_guid, "EAID") end end end |
#load_generalization(object_id, visited = Set.new, is_leaf = true) ⇒ Object
rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/MethodLength,Metrics/PerceivedComplexity,Style/OptionalBooleanParameter
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/lutaml/qea/factory/generalization_builder.rb', line 13 def load_generalization(object_id, visited = Set.new, is_leaf = true) # rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/MethodLength,Metrics/PerceivedComplexity,Style/OptionalBooleanParameter return nil if object_id.nil? if visited.include?(object_id) warn "Circular inheritance detected for object_id #{object_id}, " \ "stopping recursion" return nil end visited = visited.dup.add(object_id) current_obj = find_object_by_id(object_id) return nil unless current_obj ea_connector = database.connectors_for_object(object_id) .find { |c| c.generalization? && c.start_object_id == object_id } gen_transformer = GeneralizationTransformer.new(database) generalization = if ea_connector.nil? gen_transformer.transform(nil, current_obj) else gen_transformer.transform(ea_connector, current_obj) end return nil unless generalization current_attrs = load_attributes(object_id) current_assoc_attrs = AssociationBuilder.new(database) .load_association_attributes(object_id) general_attrs = convert_to_general_attributes( current_attrs + current_assoc_attrs, ) upper_klass = generalization.general_upper_klass gen_name = generalization.general_name general_attrs.each do |attr| attr.gen_name = gen_name name_ns = case attr.type_ns when "core", "gml" upper_klass else attr.type_ns end attr.name_ns = name_ns || upper_klass end generalization.general_attributes = general_attrs .sort_by { |a| [a.name.to_s, a.id] } generalization.attributes = transform_general_attributes( generalization, ) generalization.owned_props = generalization.attributes .reject(&:has_association) generalization.assoc_props = generalization.attributes .select(&:has_association) parent_object_id = ea_connector&.end_object_id if parent_object_id parent_gen = load_generalization(parent_object_id, visited, false) if parent_gen generalization.general = parent_gen generalization.has_general = true end end if is_leaf && generalization.has_general collect_inherited_properties(generalization) end generalization end |