Class: Lutaml::Qea::Factory::ClassTransformer

Inherits:
BaseTransformer show all
Defined in:
lib/lutaml/qea/factory/class_transformer.rb

Overview

Transforms EA objects (Class type) to UML classes

Instance Attribute Summary

Attributes inherited from BaseTransformer

#database

Instance Method Summary collapse

Methods inherited from BaseTransformer

#initialize, #transform_collection

Constructor Details

This class inherits a constructor from Lutaml::Qea::Factory::BaseTransformer

Instance Method Details

#transform(ea_object) ⇒ Lutaml::Uml::Class

Transform EA object to UML class

Parameters:

  • ea_object (EaObject)

    EA object model

Returns:



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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# File 'lib/lutaml/qea/factory/class_transformer.rb', line 21

def transform(ea_object) # rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/MethodLength,Metrics/PerceivedComplexity
  return nil if ea_object.nil?

  # Allow Class, Interface, and Text objects that appear on diagrams
  is_class_type = ea_object.uml_class? || ea_object.interface?
  is_text_class = ea_object.object_type == "Text"
  return nil unless is_class_type || is_text_class

  Lutaml::Uml::Class.new.tap do |klass| # rubocop:disable Metrics/BlockLength
    # Map basic properties
    klass.name = ea_object.name
    klass.xmi_id = normalize_guid_to_xmi_format(ea_object.ea_guid,
                                                "EAID")
    klass.is_abstract = ea_object.abstract?
    # Text objects exported as Class in XMI
    klass.type = is_text_class ? "Class" : "Class"
    klass.visibility = map_visibility(ea_object.visibility)

    # Map stereotype - return string if single, array if multiple
    stereotypes = []
    if ea_object.stereotype && !ea_object.stereotype.empty?
      stereotypes << ea_object.stereotype
    end

    # Check t_xref for additional stereotypes
    # (only if not already added)
    xref_stereotype = load_stereotype_from_xref(ea_object.ea_guid)
    if xref_stereotype && !stereotypes.include?(xref_stereotype)
      stereotypes << xref_stereotype
    end

    # Return string if single stereotype, array if multiple, nil if none
    unless stereotypes.empty?
      klass.stereotype = if stereotypes.size == 1
                           stereotypes.first
                         else
                           stereotypes
                         end
    end

    # Add "interface" stereotype if it's an interface
    if ea_object.interface?
      if klass.stereotype.nil?
        klass.stereotype = "interface"
      elsif klass.stereotype.is_a?(String)
        klass.stereotype = [klass.stereotype, "interface"].uniq
      elsif klass.stereotype.is_a?(Array)
        unless klass.stereotype.include?("interface")
          klass.stereotype << "interface"
        end
      end
    end

    # Map definition/notes
    klass.definition = normalize_line_endings(ea_object.note) unless
      ea_object.note.nil? || ea_object.note.empty?

    # Load and transform attributes
    attrs = load_attributes(ea_object.ea_object_id)
    assoc_attrs = convert_to_top_element_attributes(
      load_association_attributes(ea_object.ea_object_id),
    )
    klass.attributes = attrs + assoc_attrs

    # Load and transform operations
    klass.operations = load_operations(ea_object.ea_object_id)

    # Load and transform constraints
    klass.constraints = load_constraints(ea_object.ea_object_id)

    # Load and transform tagged values
    klass.tagged_values = load_tagged_values(ea_object.ea_guid)

    # Load and transform object properties (as additional tagged values)
    klass.tagged_values.concat(
      load_object_properties(ea_object.ea_object_id),
    )

    # Load generalization (inheritance)
    klass.generalization = load_generalization(ea_object.ea_object_id)

    # Load association generalizations
    klass.association_generalization = load_association_generalizations(
      ea_object.ea_object_id,
    )

    # Load associations for this class
    klass.associations = load_class_associations(
      ea_object.ea_object_id, ea_object.ea_guid
    )
  end
end