Class: Twb::DataSource

Inherits:
Object
  • Object
show all
Defined in:
lib/twb/datasource.rb

Constant Summary collapse

@@hasher =
Digest::SHA256.new

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(dataSourceNode) ⇒ DataSource

Returns a new instance of DataSource.



27
28
29
30
31
32
33
34
35
# File 'lib/twb/datasource.rb', line 27

def initialize dataSourceNode
  @node    = dataSourceNode
  @name    = @node.attr('name')
  @caption = @node.attr('caption')
  @uiname  = if @caption.nil? || @caption == '' then @name else @caption end
  processConnection
  processFields
  return self
end

Instance Attribute Details

#captionObject (readonly)

Returns the value of attribute caption.



25
26
27
# File 'lib/twb/datasource.rb', line 25

def caption
  @caption
end

#connectionObject (readonly)

Returns the value of attribute connection.



25
26
27
# File 'lib/twb/datasource.rb', line 25

def connection
  @connection
end

#connHashObject (readonly)

Returns the value of attribute connHash.



25
26
27
# File 'lib/twb/datasource.rb', line 25

def connHash
  @connHash
end

#dsclassObject (readonly)

Returns the value of attribute dsclass.



25
26
27
# File 'lib/twb/datasource.rb', line 25

def dsclass
  @dsclass
end

#localfieldsObject (readonly)

Returns the value of attribute localfields.



25
26
27
# File 'lib/twb/datasource.rb', line 25

def localfields
  @localfields
end

#metadatafieldsObject (readonly)

Returns the value of attribute metadatafields.



25
26
27
# File 'lib/twb/datasource.rb', line 25

def metadatafields
  @metadatafields
end

#nameObject (readonly)

Returns the value of attribute name.



25
26
27
# File 'lib/twb/datasource.rb', line 25

def name
  @name
end

#nodeObject (readonly)

Returns the value of attribute node.



25
26
27
# File 'lib/twb/datasource.rb', line 25

def node
  @node
end

#tablesObject (readonly)

Returns the value of attribute tables.



25
26
27
# File 'lib/twb/datasource.rb', line 25

def tables
  @tables
end

#uinameObject (readonly)

Returns the value of attribute uiname.



25
26
27
# File 'lib/twb/datasource.rb', line 25

def uiname
  @uiname
end

Instance Method Details

#loadTables(connection) ⇒ Object



61
62
63
64
65
66
67
# File 'lib/twb/datasource.rb', line 61

def loadTables connection
  @tables = {}
  nodes = connection.xpath(".//relation[@type='table']")
  nodes.each do |node|
    @tables[node.attr('name')] = node.attr('table')
  end
end

#Parameters?Boolean

Returns:

  • (Boolean)


69
70
71
# File 'lib/twb/datasource.rb', line 69

def Parameters?
  @name == 'Parameters'
end

#processConnectionObject



37
38
39
40
41
42
43
44
45
# File 'lib/twb/datasource.rb', line 37

def processConnection
  @connection  = @node.at_xpath('./connection')
  unless @connection.nil?
    @dsclass = @connection.attribute('class').text
    # note: must use "dsclass" as "class" would override Rubys ".class" Kernel method
    setConnectionHash
    loadTables @connection
  end
end

#processFieldsObject



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
# File 'lib/twb/datasource.rb', line 73

def processFields
  # --
  @localfields    = {}
  @metadatafields = {}
  return if @connection.nil?
  ## load local fields
  connClass    = @node.at_xpath('./connection').attribute('class').text
  fxpath       = case connClass
                 when 'dataengine' then './column'
                 else                   './connection/relation/columns/column'
                 end
  nodes = @node.xpath(fxpath)
  # puts "DATASOURCE ::=>> @node: connClass: '#{connClass.class}' ::: #{connClass.eql?('dataengine')} fxpath: #{fxpath}  :: #{nodes.length}"
  nodes.each do |node|
    field = Twb::LocalField.new(node)
    @localfields[field.name] = field
  end
  ## load metadata fields
  nodes = @node.xpath("./connection/metadata-records/metadata-record[@class='column']")
  # note: there are other nodes "<metadata-record class='capability'>" whose nature is unclear
  #       these nodes have no value for their <name node, so we're not loading them
  nodes.each do |node|
    field = Twb::MetadataField.new(node)
    @metadatafields[field.name] = field
  end
end

#setConnectionHashObject

Notes:

- TODO: need to determine which, if any, of the connection attributes should be
        included in the hash in order to identify it unambiguously - without
        local values that obscure the data source's 'real' identity
- attributes with value '' don't contribute to the hash


52
53
54
55
56
57
58
59
# File 'lib/twb/datasource.rb', line 52

def setConnectionHash
  dsAttributes = @node.xpath('./connection/@*')
  dsConnStr    = ''
  dsAttributes.each do |attr|
    dsConnStr += attr.text
  end
  @connHash = Digest::MD5.hexdigest(dsConnStr)
end