Created
January 5, 2013 01:47
-
-
Save mattsgarrison/4459120 to your computer and use it in GitHub Desktop.
This is a rough proof of concept just to see if it was feasible to run one of my workplace's legacy Crystal Reports through JRuby and eventually scheduled and queued through a Torquebox app. The particular .rpt I was playing with had DB connection info required, but no parameters passed into it. This was just a class file I tossed in the /lib fo…
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class CrystalReport | |
require 'java' | |
# Some cargo cult programming inclusions. | |
# This is just every jar file provided as part of the runtime package here: | |
# http://www.sdn.sap.com/irj/boc/index?rid=/webcontent/uuid/b0f67412-9ac0-2b10-5982-dfdf6376cd99 | |
require 'vendor/jars/crystal/com.azalea.ufl.barcode.1.0.jar' | |
require 'vendor/jars/crystal/commons-lang-2.1.jar' | |
require 'vendor/jars/crystal/CrystalReportsRuntime.jar' | |
require 'vendor/jars/crystal/icu4j.jar' | |
require 'vendor/jars/crystal/jrcerom.jar' | |
require 'vendor/jars/crystal/logging.jar' | |
require 'vendor/jars/crystal/webreporting.jar' | |
require 'vendor/jars/crystal/xpp3.jar' | |
require 'vendor/jars/crystal/commons-collections-3.1.jar' | |
require 'vendor/jars/crystal/commons-logging.jar' | |
require 'vendor/jars/crystal/cvom.jar' | |
require 'vendor/jars/crystal/jai_imageio.jar' | |
require 'vendor/jars/crystal/keycodeDecoder.jar' | |
require 'vendor/jars/crystal/pfjgraphics.jar' | |
require 'vendor/jars/crystal/webreporting-jsf.jar' | |
require 'vendor/jars/crystal/commons-configuration-1.2.jar' | |
require 'vendor/jars/crystal/CrystalCommon2.jar' | |
require 'vendor/jars/crystal/DatabaseConnectors.jar' | |
require 'vendor/jars/crystal/JDBInterface.jar' | |
require 'vendor/jars/crystal/log4j.jar' | |
require 'vendor/jars/crystal/QueryBuilder.jar' | |
require 'vendor/jars/crystal/XMLConnector.jar' | |
import "java.io" | |
import "com.crystaldecisions.reports.sdk" | |
import "com.crystaldecisions.sdk.occa.report.lib" | |
import "com.crystaldecisions.sdk.occa.report.exportoptions" | |
import "com.crystaldecisions.sdk.occa.report.reportsource.*" | |
import "com.crystaldecisions.sdk.occa.report.lib.*" | |
import "com.crystaldecisions.sdk.occa.report.data.*" | |
import "com.crystaldecisions.report.web.viewer.*" | |
# camelCase variables indicates it's coming from Java | |
# snake_case variables are Ruby | |
def report_runner | |
report_name = "app/reports/LegacyReport.rpt" | |
export_file = "public/reports/LegacyReport.rtf" | |
db_username = "user" | |
db_password = "hunter2" | |
begin | |
reportClientDoc = ReportClientDocument.new | |
reportClientDoc.open(report_name, 0) | |
exportFormat = com.crystaldecisions.sdk.occa.report.exportoptions.ReportExportFormat | |
# if needing to pass params, I think this does it but haven't tried it yet: | |
#paramController = reportClientDoc.getDataDefController().getParameterFieldController() | |
#paramController.setCurrentValue("","MyParamName","MyParamValue") | |
reportClientDoc.getDatabaseController().logon(db_username, db_password); | |
byteArrayInputStream = reportClientDoc.getPrintOutputController().export(export_format::RTF) | |
reportClientDoc.close() | |
File.open(export_file, 'w') do |f| | |
while (byte = byteArrayInputStream.read) > -1 | |
f << byte.chr | |
end | |
end | |
rescue | |
Rails.logger.error "Report Runner Failed" | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
For reference, when the output format is MSWord, this created a picture perfect report output for my old reports. That might have to suffice.