Class: ConnectorsSdk::Confluence::Adapter::ContentNode

Inherits:
Node
  • Object
show all
Defined in:
lib/connectors_sdk/confluence/adapter.rb

Direct Known Subclasses

AttachmentNode

Instance Attribute Summary

Attributes inherited from Node

#base_url, #node, #permissions

Instance Method Summary collapse

Methods inherited from Node

#initialize, #to_es_document

Constructor Details

This class inherits a constructor from ConnectorsSdk::Confluence::Adapter::Node

Instance Method Details

#bodyObject



133
134
135
# File 'lib/connectors_sdk/confluence/adapter.rb', line 133

def body
  text_from_html(node.body.export_view.value)
end

#commentsObject



137
138
139
140
141
# File 'lib/connectors_sdk/confluence/adapter.rb', line 137

def comments
  node.children&.comment&.results&.slice(0, MAX_CONTENT_COMMENTS_TO_INDEX)&.map do |comment|
    text_from_html(comment.body.export_view.value)
  end&.join("\n")
end

#descriptionObject



143
144
145
146
147
148
# File 'lib/connectors_sdk/confluence/adapter.rb', line 143

def description
  [
    node.space&.name,
    node.ancestors&.map(&:title) # 'attachment' type nodes do not have `ancestors`, making this logic incomplete
  ].flatten.select(&:present?).join('/')
end

#fieldsObject



157
158
159
160
161
162
163
164
165
166
167
168
# File 'lib/connectors_sdk/confluence/adapter.rb', line 157

def fields
  {
    :description => description,
    :body => body,
    :comments => comments,
    :created_by => node.history&.createdBy&.displayName,
    :project => node.space.try!(:[], :key),

    :created_at => ConnectorsSdk::Base::Adapter.normalize_date(node.history&.createdDate),
    :last_updated => ConnectorsSdk::Base::Adapter.normalize_date(node.history&.lastUpdated&.when)
  }.merge(permissions_hash)
end

#idObject



109
110
111
# File 'lib/connectors_sdk/confluence/adapter.rb', line 109

def id
  Confluence::Adapter.confluence_content_id_to_es_id(node.id)
end

#pathObject



150
151
152
153
154
155
# File 'lib/connectors_sdk/confluence/adapter.rb', line 150

def path
  [
    description,
    title
  ].select(&:present?).join('/')
end

#titleObject



125
126
127
# File 'lib/connectors_sdk/confluence/adapter.rb', line 125

def title
  node.title
end

#typeObject



113
114
115
116
117
118
119
120
121
122
123
# File 'lib/connectors_sdk/confluence/adapter.rb', line 113

def type
  case node.type
  when 'page'
    node.type
  when 'blogpost'
    'blog post'
  else
    ConnectorsShared::ExceptionTracking.capture_message("Unknown confluence type: #{node.type}")
    nil
  end
end

#urlObject



129
130
131
# File 'lib/connectors_sdk/confluence/adapter.rb', line 129

def url
  Addressable::URI.join(base_url, node._links.webui.gsub(LEADING_SLASH_REGEXP, '')).to_s
end