Class: GoodData::Report
- Inherits:
-
MdObject
- Object
- GoodData::Rest::Object
- GoodData::Rest::Resource
- MdObject
- GoodData::Report
- Includes:
- Mixin::Lockable
- Defined in:
- lib/gooddata/models/metadata/report.rb
Constant Summary
Constants inherited from MdObject
MdObject::IDENTIFIERS_CFG, MdObject::MD_OBJ_CTG
Constants included from Mixin::MdIdToUri
Mixin::MdIdToUri::IDENTIFIERS_CFG
Constants included from Mixin::MdObjectIndexer
Mixin::MdObjectIndexer::MD_OBJ_CTG
Instance Attribute Summary
Attributes inherited from GoodData::Rest::Object
Class Method Summary collapse
-
.all(options = { :client => GoodData.connection, :project => GoodData.project }) ⇒ Array<GoodData::MdObject> | Array<Hash>
Method intended to get all objects of that type in a specified project.
- .create(options = { :client => GoodData.connection, :project => GoodData.project }) ⇒ Object
- .data_result(result, options = {}) ⇒ Object
Instance Method Summary collapse
-
#add_definition(report_definition) ⇒ GoodData::Report
Add a report definition to a report.
-
#add_definition!(report_definition) ⇒ GoodData::Report
Add a report definition to a report.
-
#definition ⇒ GoodData::ReportDefinition
(also: #latest_report_definition)
Returns the newest (current version) report definition as an object.
-
#definition_uri ⇒ String
(also: #latest_report_definition_uri)
Returns the newest (current version) report definition uri.
-
#definition_uris ⇒ Array<String>
Gets list of uris of report definitions (versions) of this report.
-
#definitions ⇒ Array<GoodData::ReportDefinition>
(also: #report_definitions)
Gets a report definitions (versions) of this report as objects.
-
#delete ⇒ GoodData::Report
Deletes report along with its report definitions.
-
#execute(options = {}) ⇒ GoodData::DataResult
Computes the report and returns the result.
-
#export(format, options = {}) ⇒ String
Returns binary data of the exported report in a given format.
-
#exportable? ⇒ Boolean
Returns true if you can export and object.
-
#purge_report_of_unused_definitions! ⇒ String
Returns the newest (current version) report definition uri.
-
#remove_definition(definition) ⇒ GoodData::Report
Removes definition from the report.
-
#remove_definition_but_latest ⇒ GoodData::Report
TODO: Cover with test.
-
#replace(mapping) ⇒ GoodData::Report
Method used for replacing values in their state according to mapping.
-
#update_definition(opts = { :new_definition => true }, &block) ⇒ GoodData::ReportDefinition
Update report definition and reflect the change in report.
Methods included from Mixin::Lockable
#lock, #lock!, #lock_with_dependencies!, #locked?, #unlock, #unlock!, #unlock_with_dependencies!, #unlocked?
Methods inherited from MdObject
#==, #add_tag, #browser_uri, #deprecated, #deprecated=, find_replaceable_values, #initialize, #listed?, #project, #reload!, #remove_tag, replace, #replace!, replace_bracketed, replace_quoted, #save, #save_as, #tag_set, #unlisted, #unlisted=, #validate
Methods included from Mixin::MdIdToUri
Methods included from Mixin::MdObjectIndexer
Methods included from Mixin::MdObjectQuery
#all, #dependency, #dependency?, #query, #usedby, #usedby?, #using, #using?
Methods included from Mixin::MdFinders
#find_by_identifier, #find_by_tag, #find_by_title, #find_first_by_identifier, #find_first_by_title
Methods included from Mixin::MdObjId
Methods included from Mixin::MdGrantees
#change_permission, #grant, #grantees, #revoke
Methods included from Mixin::MdRelations
#dependency, #dependency?, #usedby, #usedby?, #using, #using?
Methods included from Mixin::ObjId
Methods included from Mixin::Links
Methods inherited from GoodData::Rest::Resource
Methods inherited from GoodData::Rest::Object
client, default_client, #initialize, #saved?
Methods included from Mixin::DataPropertyReader
Methods included from Mixin::DataPropertyWriter
Methods included from Mixin::MetaPropertyReader
Methods included from Mixin::MetaPropertyWriter
Methods included from Mixin::MetaGetter
Methods included from Mixin::DataGetter
Methods included from Mixin::RootKeyGetter
Methods included from Mixin::ContentGetter
Constructor Details
This class inherits a constructor from GoodData::MdObject
Class Method Details
.all(options = { :client => GoodData.connection, :project => GoodData.project }) ⇒ Array<GoodData::MdObject> | Array<Hash>
Method intended to get all objects of that type in a specified project
20 21 22 |
# File 'lib/gooddata/models/metadata/report.rb', line 20 def all( = { :client => GoodData.connection, :project => GoodData.project }) query('report', Report, ) end |
.create(options = { :client => GoodData.connection, :project => GoodData.project }) ⇒ Object
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 |
# File 'lib/gooddata/models/metadata/report.rb', line 24 def create( = { :client => GoodData.connection, :project => GoodData.project }) client, project = GoodData.get_client_and_project() title = [:title] fail 'Report needs a title specified' unless title summary = [:summary] || '' = .dup .delete(:identifier) rd = [:rd] || ReportDefinition.create() rd.save report = { 'report' => { 'content' => { 'domains' => [], 'definitions' => [rd.uri] }, 'meta' => { 'tags' => '', 'deprecated' => '0', 'summary' => summary, 'title' => title } } } # TODO: write test for report definitions with explicit identifiers report['report']['meta']['identifier'] = [:identifier] if [:identifier] client.create(Report, report, :project => project) end |
.data_result(result, options = {}) ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/gooddata/models/metadata/report.rb', line 56 def data_result(result, = {}) client = [:client] data_result_uri = result['execResult']['dataResult'] begin result = client.poll_on_response(data_result_uri, ) do |body| body && body['taskState'] && body['taskState']['status'] == 'WAIT' end rescue RestClient::BadRequest => e resp = JSON.parse(e.response) if GoodData::Helpers.get_path(resp, %w(error component)) == 'MD::DataResult' raise GoodData::UncomputableReport else raise e end end if result.empty? ReportDataResult.new(data: [], top: 0, left: 0) else ReportDataResult.from_xtab(result) end end |
Instance Method Details
#add_definition(report_definition) ⇒ GoodData::Report
Add a report definition to a report. This will show on a UI as a new version.
84 85 86 87 88 |
# File 'lib/gooddata/models/metadata/report.rb', line 84 def add_definition(report_definition) rep_def = project.report_definitions(report_definition) content['definitions'] = definition_uris << rep_def.uri self end |
#add_definition!(report_definition) ⇒ GoodData::Report
Add a report definition to a report. This will show on a UI as a new version.
94 95 96 97 |
# File 'lib/gooddata/models/metadata/report.rb', line 94 def add_definition!(report_definition) res = add_definition(report_definition) res.save end |
#definition ⇒ GoodData::ReportDefinition Also known as: latest_report_definition
Returns the newest (current version) report definition as an object
102 103 104 |
# File 'lib/gooddata/models/metadata/report.rb', line 102 def definition project.report_definitions(latest_report_definition_uri) end |
#definition_uri ⇒ String Also known as: latest_report_definition_uri
Returns the newest (current version) report definition uri
111 112 113 |
# File 'lib/gooddata/models/metadata/report.rb', line 111 def definition_uri definition_uris.last end |
#definition_uris ⇒ Array<String>
Gets list of uris of report definitions (versions) of this report.
128 129 130 |
# File 'lib/gooddata/models/metadata/report.rb', line 128 def definition_uris content['definitions'] end |
#definitions ⇒ Array<GoodData::ReportDefinition> Also known as: report_definitions
Gets a report definitions (versions) of this report as objects.
120 121 122 |
# File 'lib/gooddata/models/metadata/report.rb', line 120 def definitions content['definitions'].pmap { |uri| project.report_definitions(uri) } end |
#delete ⇒ GoodData::Report
Deletes report along with its report definitions.
135 136 137 138 139 140 |
# File 'lib/gooddata/models/metadata/report.rb', line 135 def delete defs = definitions super defs.peach(&:delete) self end |
#execute(options = {}) ⇒ GoodData::DataResult
Computes the report and returns the result. If it is not computable returns nil.
145 146 147 148 149 |
# File 'lib/gooddata/models/metadata/report.rb', line 145 def execute( = {}) fail 'You have to save the report before executing. If you do not want to do that please use GoodData::ReportDefinition' unless saved? result = client.post '/gdc/xtab2/executor3', 'report_req' => { 'report' => uri } GoodData::Report.data_result(result, .merge(client: client)) end |
#export(format, options = {}) ⇒ String
Returns binary data of the exported report in a given format. The format can be either 'csv', 'xls', 'xlsx' or 'pdf'.
162 163 164 165 166 |
# File 'lib/gooddata/models/metadata/report.rb', line 162 def export(format, = {}) result = client.post('/gdc/xtab2/executor3', 'report_req' => { 'report' => uri }) result1 = client.post('/gdc/exporter/executor', :result_req => { :format => format, :result => result }) client.poll_on_code(result1['uri'], .merge(process: false)) end |
#exportable? ⇒ Boolean
Returns true if you can export and object
154 155 156 |
# File 'lib/gooddata/models/metadata/report.rb', line 154 def exportable? true end |
#purge_report_of_unused_definitions! ⇒ String
Returns the newest (current version) report definition uri
171 172 173 174 175 176 177 178 179 |
# File 'lib/gooddata/models/metadata/report.rb', line 171 def purge_report_of_unused_definitions! full_list = definition_uris remove_definition_but_latest purged_list = definition_uris to_remove = full_list - purged_list save to_remove.each { |uri| client.delete(uri) } self end |
#remove_definition(definition) ⇒ GoodData::Report
Removes definition from the report. The definition to remove can be passed in any form that is accepted by GoodData::ReportDefintion[]
186 187 188 189 190 191 |
# File 'lib/gooddata/models/metadata/report.rb', line 186 def remove_definition(definition) a_def = GoodData::ReportDefinition[definition, project: project, client: client] def_uri = a_def.uri content['definitions'] = definition_uris.reject { |x| x == def_uri } self end |
#remove_definition_but_latest ⇒ GoodData::Report
TODO: Cover with test. You would probably need something that will be able to create a report easily from a definition Removes all definitions but the latest from the report. This is useful for cleaning up before you create a template out of a project.
198 199 200 201 202 203 204 |
# File 'lib/gooddata/models/metadata/report.rb', line 198 def remove_definition_but_latest to_remove = definition_uris - [latest_report_definition_uri] to_remove.each do |uri| remove_definition(uri) end self end |
#replace(mapping) ⇒ GoodData::Report
Method used for replacing values in their state according to mapping. Can be used to replace any values but it is typically used to replace the URIs. Returns a new object of the same type.
210 211 212 213 214 215 216 |
# File 'lib/gooddata/models/metadata/report.rb', line 210 def replace(mapping) new_defs = definitions.map do |rep_def| rep_def.replace(mapping) end new_defs.pmap(&:save) self end |
#update_definition(opts = { :new_definition => true }, &block) ⇒ GoodData::ReportDefinition
Update report definition and reflect the change in report
223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 |
# File 'lib/gooddata/models/metadata/report.rb', line 223 def update_definition(opts = { :new_definition => true }, &block) # TODO: Cache the latest report definition somehow repdef = definition.dup block.call(repdef, self) if block_given? if opts[:new_definition] new_def = GoodData::ReportDefinition.create(:client => client, :project => project) rd = repdef.json['reportDefinition'] rd.delete('links') %w(author uri created identifier updated contributor).each { |k| rd['meta'].delete(k) } new_def.json['reportDefinition'] = rd new_def.save add_definition!(new_def) return new_def else repdef.save end repdef end |