Class: JasperServer::ReportRequest

Inherits:
Object
  • Object
show all
Defined in:
lib/jasper_server/report_request.rb

Overview

Represents a request for a report, to be sent to the JasperServer via the JasperServer::Client.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(report_unit, output_format, report_params = {}) ⇒ ReportRequest

The request consists of three arguments:

report_unit

The path on the JasperServer to the “report unit” (i.e. a bundle consisting of the JRXML file and other resources used in the report). E.g.: /example/my-report

output_format

The desired output format. E.g.: PDF, CSV, HTML, etc.

report_params

Hash of parameters to be fed into the report. The client will take care of performing the appropriate type conversions (for example, Time values are turned into integer timestamps and are automatically adjusted for timezone). E.g. { 'fruit' => "Apple", 'date' => Time.now}

Raises:

  • (ArgumentError)


20
21
22
23
24
25
# File 'lib/jasper_server/report_request.rb', line 20

def initialize(report_unit, output_format, report_params = {})
  raise ArgumentError, "Missing output_format in report request!" if output_format.nil? || output_format.empty?
  @report_unit   = report_unit
  @output_format = output_format.upcase
  @report_params = report_params
end

Instance Attribute Details

#output_formatObject

Returns the value of attribute output_format.



6
7
8
# File 'lib/jasper_server/report_request.rb', line 6

def output_format
  @output_format
end

#report_paramsObject

Returns the value of attribute report_params.



6
7
8
# File 'lib/jasper_server/report_request.rb', line 6

def report_params
  @report_params
end

#report_unitObject

Returns the value of attribute report_unit.



6
7
8
# File 'lib/jasper_server/report_request.rb', line 6

def report_unit
  @report_unit
end

Class Method Details

.convert_time_to_jasper_timestamp(time) ⇒ Object

Converts the given Time into a timestamp integer acceptable by JasperServer. The timezone adjustment is performed (converted to UTC).



29
30
31
32
33
34
35
# File 'lib/jasper_server/report_request.rb', line 29

def self.convert_time_to_jasper_timestamp(time)
  # convert to milisecond timestamp
  ts = time.to_i * 1000
  # adjust for timezone
  ts -= time.utc_offset * 1000
  return ts
end