lib/gooddata/models/report_definition.rb in gooddata-0.6.0.pre7 vs lib/gooddata/models/report_definition.rb in gooddata-0.6.0.pre8

- old
+ new

@@ -108,25 +108,45 @@ unsaved_metrics.each {|m| m.title = "Untitled metric" unless m.title} begin unsaved_metrics.each {|m| m.save} rd = GoodData::ReportDefinition.create(options) - rd.save - rd.execute + get_data_result(execute_inline(rd)) ensure - rd.delete if rd && rd.saved? unsaved_metrics.each {|m| m.delete if m && m.saved?} end end + def execute_inline(rd) + rd = rd.respond_to?(:raw_data) ? rd.raw_data : rd + data = { + :report_req => { + :definitionContent => { + :content => rd, + :projectMetadata => GoodData::project.links["metadata"]}}} + GoodData.post("/gdc/app/projects/#{GoodData.project.pid}/execute", data) + end + + def get_data_result(result) + data_result_uri = result["execResult"]["dataResult"] + result = GoodData.get data_result_uri + while result["taskState"] && result["taskState"]["status"] == "WAIT" do + sleep 10 + result = GoodData.get data_result_uri + end + ReportDataResult.new(GoodData.get data_result_uri) + end + def create(options={}) left = Array(options[:left]) top = Array(options[:top]) left = ReportDefinition.find(left) top = ReportDefinition.find(top) + fail "All metrics in report definition must be saved" unless (left + top).all? {|i| i.saved?} + ReportDefinition.new({ "reportDefinition" => { "content" => { "grid" => { "sort" => { @@ -155,20 +175,14 @@ content["grid"]["metrics"].map {|i| GoodData::Metric[i["uri"]]} end def execute result = if saved? - GoodData.post '/gdc/xtab2/executor3', {"report_req" => {"reportDefinition" => uri}} + GoodData.post '/gdc/xtab2/executor', {"report_req" => {"reportDefinition" => uri}} else - # GoodData.post '/gdc/xtab2/executor3', {"report_req" => raw_data} - fail("this is currently unsupported. For executing unsaved report definitions please use class method execute.") + ReportDefinition.execute_inline(self) end - data_result_uri = result["execResult"]["dataResult"] - result = GoodData.get data_result_uri - while result["taskState"] && result["taskState"]["status"] == "WAIT" do - sleep 10 - result = GoodData.get data_result_uri - end - ReportDataResult.new(GoodData.get data_result_uri) + ReportDefinition::get_data_result(result) end + end end \ No newline at end of file