Class: JDBCReport
  
  
  
  
    - Inherits:
 
    - 
      JasperReport
      
        
        show all
      
      
 
    
  
  
    
  
    
  
  
  
    - Defined in:
 
    - backend/app/model/reports/jdbc_report.rb
 
  
  Instance Attribute Summary
  
  Attributes inherited from JasperReport
  #data_source, #export_file, #format, #jrprint
  
    
      Instance Method Summary
      (collapse)
    
    
  
  
  
  
  
  
  
  
  
  
  compile, finalize, #initialize, #report, report, report_base, #title
  
  
  
  
  
  
  
  
  
  
  included
  Constructor Details
  
    This class inherits a constructor from JasperReport
  
 
  
    Instance Method Details
    
      
  
  
    - (Object) default_params 
  
  
  
  
    
      
7
8
9
10
11
12
13
14
15
16 
     | 
    
      # File 'backend/app/model/reports/jdbc_report.rb', line 7
def default_params
  params = {} 
  params[JsonQueryExecuterFactory::JSON_DATE_PATTERN] ||= "yyyy-MM-dd"      
  params[JsonQueryExecuterFactory::JSON_NUMBER_PATTERN] ||= "#,##0.##"       
  params[JsonQueryExecuterFactory::JSON_LOCALE] ||= Locale::ENGLISH          
  params[JRParameter::REPORT_LOCALE] ||= ::Locale::US
  params["repositoryId"] = @repo_id.to_java(:int)
  params["basePath"] = @base_path
  params
end
     | 
  
 
    
      
  
  
    - (Object) fill(params = {}) 
  
  
  
  
    
      
18
19
20
21
22
23
24
25 
     | 
    
      # File 'backend/app/model/reports/jdbc_report.rb', line 18
def fill( params = {} )
  params.merge!(default_params) 
  DB.open(false) do |db| 
      db.pool.hold do |conn| 
        @jrprint =  JasperFillManager.fill_report(report, java.util.HashMap.new(params), conn )
      end 
  end 
end
     | 
  
 
    
      
  
  
    - (Object) render(format, params = {}) 
  
  
  
  
    
      
73
74
75
76
77
78 
     | 
    
      # File 'backend/app/model/reports/jdbc_report.rb', line 73
def render(format, params = {})
  if [:pdf, :html, :xlsx, :csv, :json ].include?(format) 
    fill(params)
    self.send("to_#{format.to_s}")
  end
end
     | 
  
 
    
      
  
  
    - (Object) to_csv 
  
  
  
  
    
      
38
39
40
41
42
43
44
45
46 
     | 
    
      # File 'backend/app/model/reports/jdbc_report.rb', line 38
def to_csv
  exporter = JRCsvExporter.new
  exporter.exporter_input = SimpleExporterInput.new(@jrprint)
  @export_file = Tempfile.new(SecureRandom.hex)
  exporter.exporter_output = SimpleWriterExporterOutput.new(@export_file.to_outputstream)
  exporter.export_report
  @export_file.rewind 
  @export_file.read.to_java_bytes 
end
 
     | 
  
 
    
      
  
  
    - (Object) to_html 
  
  
  
  
    
      
31
32
33
34
35
36 
     | 
    
      # File 'backend/app/model/reports/jdbc_report.rb', line 31
def to_html
  @export_file = Tempfile.new("location.html")
  JasperExportManager.export_report_to_html_file(@jrprint, @export_file.path)
  @export_file.rewind 
  @export_file.read.to_java_bytes 
end
     | 
  
 
    
      
  
  
    - (Object) to_json 
  
  
  
  
    
      
62
63
64
65
66
67
68
69
70
71 
     | 
    
      # File 'backend/app/model/reports/jdbc_report.rb', line 62
def to_json
   json = { "results" => [] }
   csv = CSV.parse(String.from_java_bytes(to_csv), :headers => true)
   csv.each do |row|
    result = {}
    row.each { |,val| result[.downcase] = val unless .nil?  }
    json["results"] <<  result 
   end
   JSON(json).to_java_bytes 
end
     | 
  
 
    
      
  
  
    - (Object) to_pdf 
  
  
  
  
    
      
27
28
29 
     | 
    
      # File 'backend/app/model/reports/jdbc_report.rb', line 27
def to_pdf
   JasperExportManager.export_report_to_pdf(@jrprint)
end
 
     | 
  
 
    
      
  
  
    - (Object) to_xlsx 
  
  
  
  
    
      
48
49
50
51
52
53
54
55
56
57
58
59
60 
     | 
    
      # File 'backend/app/model/reports/jdbc_report.rb', line 48
def to_xlsx
  exporter = JRXlsxExporter.new
  exporter.exporter_input = SimpleExporterInput.new(@jrprint)
  @export_file = Tempfile.new(SecureRandom.hex)
  exporter.exporter_output = SimpleOutputStreamExporterOutput.new(@export_file.to_outputstream)
  configuration = SimpleXlsxReportConfiguration.new 
  configuration.one_page_per_sheet = false 
  exporter.configuration = configuration
  exporter.export_report
  @export_file.rewind 
  @export_file.read.to_java_bytes 
end
 
     |