{
* A Hibernate session retrieved from {@link SQLUtil}.
*/
protected Session sess;
+
/**
* Indicates whether to use a transaction or not.
*/
@@ -49,10 +54,10 @@ public WHS(boolean transaction) {
* The main workhorse of this class. Retrieves the session from {@link SQLUtil}
* and wraps the invocation of
* {@link #lambda()} into transaction.
- *
* @return The object returned by {@link #lambda()}
*/
public ResultType p() {
+
sess = SQLUtil.getSession();
Transaction tx = null;
try {
@@ -76,4 +81,4 @@ public ResultType p() {
}
}
-}
+}
\ No newline at end of file
diff --git a/engine/pom.xml b/engine/pom.xml
index 9b1f183..b8cd51a 100644
--- a/engine/pom.xml
+++ b/engine/pom.xml
@@ -1,116 +1,211 @@
-
-
- 4.0.0
-
-
- apertereports
- org.apertereports
- 2.5-SNAPSHOT
-
-
- engine
- Jasper Integration
-
-
-
- org.apertereports
- common
- 2.5-SNAPSHOT
-
-
- net.sf.jasperreports
- jasperreports
- 4.5.1
-
-
- eclipse
- jdtcore
-
-
- xml-apis
- xml-apis
-
-
-
-
- org.codehaus.groovy
- groovy-all
-
-
- commons-digester
- commons-digester
-
-
- commons-logging
- commons-logging
-
-
- commons-codec
- commons-codec
-
-
- commons-lang
- commons-lang
-
-
- commons-collections
- commons-collections
-
-
- org.apache.poi
- poi
- 3.7
-
-
- net.sf.jasperreports
- jasperreports-fonts
- 4.0.0
-
-
- net.sourceforge.barbecue
- barbecue
- 1.5-beta1
-
-
- org.openspml
- openspml
- 0.5
-
-
-
- org.apache.maven.surefire
- surefire-junit4
- test
-
-
- junit
- junit
- test
-
-
- postgresql
- postgresql
- test
-
-
-
-
-
-
- src/main/resources
- true
-
-
-
-
- org.apache.maven.plugins
- maven-compiler-plugin
-
- 1.6
- 1.6
- UTF-8
-
-
-
-
-
+
+
+ 4.0.0
+
+
+ apertereports
+ org.apertereports
+ 2.5-SNAPSHOT
+
+
+ engine
+ Jasper Integration
+
+
+
+ org.apertereports
+ common
+ 2.5-SNAPSHOT
+
+
+ org.apache.httpcomponents
+ fluent-hc
+ 4.2.1
+
+
+
+ net.sf.jasperreports
+ jasperreports
+ 6.3.0
+
+
+ eclipse
+ jdtcore
+
+
+ xml-apis
+ xml-apis
+
+
+
+
+
+ com.liferay.portal
+ portal-service
+ ${global.liferay.version}
+ provided
+
+
+ com.liferay.portal
+ util-bridges
+ ${global.liferay.version}
+ provided
+
+
+ com.liferay.portal
+ util-taglib
+ ${global.liferay.version}
+ provided
+
+
+ com.liferay.portal
+ util-java
+ ${global.liferay.version}
+ provided
+
+
+ javax.portlet
+ portlet-api
+ 2.0
+ provided
+
+
+ javax.servlet
+ servlet-api
+ 2.4
+ provided
+
+
+ javax.servlet.jsp
+ jsp-api
+ 2.0
+ provided
+
+
+ javax.servlet
+ jstl
+ 1.2
+ provided
+
+
+
+ javax.faces
+ javax.faces-api
+ 2.1
+
+
+
+
+ com.lowagie
+ itext
+ 2.1.7.js5
+
+
+ bouncycastle
+ bcmail-jdk14
+
+
+ bouncycastle
+ bcprov-jdk14
+
+
+
+
+ org.codehaus.groovy
+ groovy-all
+
+
+ com.jaspersoft
+ webserviceds
+ 1.0.3
+
+
+ commons-digester
+ commons-digester
+
+
+ commons-logging
+ commons-logging
+
+
+ commons-codec
+ commons-codec
+
+
+ commons-lang
+ commons-lang
+
+
+ commons-collections
+ commons-collections
+
+
+ org.apache.poi
+ poi
+ 3.7
+
+
+ net.sf.jasperreports
+ jasperreports-fonts
+ 4.0.0
+
+
+ net.sourceforge.barbecue
+ barbecue
+ 1.5-beta1
+
+
+ org.openspml
+ openspml
+ 0.5
+
+
+
+ org.apache.maven.surefire
+ surefire-junit4
+ test
+
+
+ junit
+ junit
+ test
+
+
+ postgresql
+ postgresql
+ test
+
+
+ com.liferay.portal
+ portal-impl
+ ${global.liferay.version}
+ provided
+
+
+ de.itsdconsulting
+ jdbc.driver.decrypt
+
+
+
+
+
+
+
+
+ src/main/resources
+ true
+
+
+
+
+ org.apache.maven.plugins
+ maven-compiler-plugin
+
+ 1.7
+ 1.7
+ UTF-8
+
+
+
+
+
\ No newline at end of file
diff --git a/engine/src/main/java/org/apertereports/engine/ReportMaster.java b/engine/src/main/java/org/apertereports/engine/ReportMaster.java
index 9368a88..04246d1 100644
--- a/engine/src/main/java/org/apertereports/engine/ReportMaster.java
+++ b/engine/src/main/java/org/apertereports/engine/ReportMaster.java
@@ -18,18 +18,22 @@
import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
+
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.sql.DataSource;
+
import net.sf.jasperreports.engine.JRException;
import net.sf.jasperreports.engine.JRExporter;
import net.sf.jasperreports.engine.JRExporterParameter;
import net.sf.jasperreports.engine.JRParameter;
import net.sf.jasperreports.engine.JRPropertiesMap;
+import net.sf.jasperreports.engine.JRPropertiesUtil;
import net.sf.jasperreports.engine.JasperCompileManager;
import net.sf.jasperreports.engine.JasperFillManager;
import net.sf.jasperreports.engine.JasperPrint;
import net.sf.jasperreports.engine.JasperReport;
+import net.sf.jasperreports.engine.SimpleJasperReportsContext;
import net.sf.jasperreports.engine.data.JRMapCollectionDataSource;
import net.sf.jasperreports.engine.export.JRCsvExporter;
import net.sf.jasperreports.engine.export.JRCsvExporterParameter;
@@ -40,558 +44,730 @@
import net.sf.jasperreports.engine.export.JRXlsExporter;
import net.sf.jasperreports.engine.export.JRXlsExporterParameter;
import net.sf.jasperreports.engine.query.JRXPathQueryExecuterFactory;
+import net.sf.jasperreports.engine.query.QueryExecuterFactory;
import net.sf.jasperreports.engine.util.JRFontNotFoundException;
+
import org.apache.commons.lang.StringUtils;
import org.apertereports.common.ARConstants;
import org.apertereports.common.ConfigurationConstants;
import org.apertereports.common.exception.ARException;
import org.apertereports.common.exception.ARRuntimeException;
+import org.apertereports.common.users.User;
import org.apertereports.common.utils.LocaleUtils;
import org.apertereports.common.utils.ReportGeneratorUtils;
import org.apertereports.engine.SubreportProvider.Subreport;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+
import pl.net.bluesoft.util.lang.StringUtil;
+import com.jaspersoft.webservice.data.WebServiceDataAdapterService;
+import com.jaspersoft.webservice.data.authenitcator.BasicAuthenticator;
+import com.jaspersoft.webservice.data.enumerations.AuthType;
+import com.jaspersoft.webservice.data.enumerations.LanguageType;
+import com.liferay.portal.kernel.json.JSONArray;
+import com.liferay.portal.kernel.json.JSONFactoryUtil;
+import com.liferay.portal.kernel.json.JSONObject;
+import com.liferay.portal.kernel.util.InfrastructureUtil;
+
/**
* A workhorse of the Jasper reports engine. This class is responsible for
* generating, exporting and converting JRXMLs to {@link JasperPrint}s and later
* to expected formats.
*
- * The static methods of this class should be used to convert the report to
- * whatever format one wants.
In order to maintain the report generation
- * from a template one should create a new instance of this class.
+ *
+ * The static methods of this class should be used to convert the report to
+ * whatever format one wants.
+ *
+ * In order to maintain the report generation from a template one should create
+ * a new instance of this class.
*/
public class ReportMaster implements ARConstants, ConfigurationConstants {
- private static final Logger logger = LoggerFactory.getLogger(ReportMaster.class.getName());
- private static Pattern subreportPattern = Pattern.compile("\\<\\!\\[CDATA\\[\\$P\\{[^}]*\\} [^\"]*\"([^\"]*)\\.jasper\"");
- private static Pattern jasperReportPattern = Pattern.compile("]+>(\\s+]+>)*",
- Pattern.MULTILINE);
- private static Pattern subreportReportElementPattern = Pattern.compile(
- "\\s*]+>(\\s*)", Pattern.MULTILINE);
- private static String subreportMapParameter = "\n\t";
- /**
- * Currently processed Jasper report.
- */
- private AperteReport report;
-
- /**
- * Constructs a new ReportMaster with a given {@link JasperReport}.
- *
- * @param report A {@link JasperReport}
- */
- public ReportMaster(AperteReport report) {
- super();
- this.report = report;
- }
-
- /**
- * Creates a new ReportMaster instance that omits the {@link ReportCache}
- * and compiles the report from source directly.
- *
- * @param reportSource A JRXML report source
- * @param subreportProvider Subreport provider
- * @throws AperteReportsException on error
- */
- public ReportMaster(String reportSource, SubreportProvider subreportProvider) throws ARException {
- this(reportSource, null, subreportProvider);
- }
-
- /**
- * Creates a new ReportMaster instance that checks the cache for a compiled
- * version of this report. If the compiled report is not found, it creates
- * it using a given JRXML report source.
- *
- * @param reportSource A JRXML report source
- * @param cacheId A report cache id
- * @param subreportProvider Subreport provider
- * @throws JRException on Jasper error
- * @throws SubreportNotFoundException
- */
- public ReportMaster(String reportSource, String cacheId, SubreportProvider subreportProvider)
- throws ARException {
- super();
- report = compileReport(reportSource, cacheId, subreportProvider);
- }
-
- /**
- * Creates a new ReportMaster instance that checks the cache for a compiled
- * version of this report. If the compiled report is not found, it creates
- * it using a given bytes of a JRXML report source.
- *
- * @param reportSource Bytes of a JRXML report source
- * @param cacheId A report cache id
- * @param subreportProvider Subreport provider
- * @throws AperteReportsException on error
- */
- public ReportMaster(byte[] reportSource, String cacheId, SubreportProvider subreportProvider)
- throws ARException {
- super();
- report = compileReport(reportSource, cacheId, subreportProvider);
- }
-
- /**
- * Exports a {@link JasperPrint} to a desired format. The method also takes
- * a
- * customParameters param. These are included unconditionally
- * in the exporter instance used to generate the report.
- *
- * Currently the only configuration parameter that can be handled is
- * {@link org.apertereports.common.ConfigurationConstants#JASPER_REPORTS_CHARACTER_ENCODING}
- * - the character encoding of the output report.
- *
- * @param jasperPrint A {@link JasperPrint}
- * @param format Desired output format (i.e. PDF, HTML etc)
- * @param customExporterParams Additional custom {@link JRExporterParameter}
- * map
- * @param configuration Configuration parameters
- * @return Bytes of a generated report
- * @throws AperteReportsException on error
- */
- public static byte[] exportReport(JasperPrint jasperPrint, String format,
- Map customExporterParams, Map configuration)
- throws ARException {
-
- if (configuration == null) {
- configuration = new HashMap();
- }
- if (customExporterParams == null) {
- customExporterParams = new HashMap();
- }
-
- try {
- ReportType outputFormat = ReportType.valueOf(StringUtils.upperCase(format));
- ByteArrayOutputStream bos = new ByteArrayOutputStream();
- JRExporter exporter;
-
- String characterEncoding = configuration.get(JASPER_REPORTS_CHARACTER_ENCODING);
- if (!StringUtil.hasText(characterEncoding)) {
- characterEncoding = "Cp1250";
- logger.info("Injecting default character encoding: " + characterEncoding);
- }
-
- if (outputFormat == ReportType.PDF) {
- exporter = new JRPdfExporter();
- exporter.setParameter(JRPdfExporterParameter.CHARACTER_ENCODING, characterEncoding);
- } else if (outputFormat == ReportType.HTML) {
- exporter = new JRHtmlExporter();
- exporter.setParameter(JRHtmlExporterParameter.IS_USING_IMAGES_TO_ALIGN, Boolean.FALSE);
- exporter.setParameter(JRHtmlExporterParameter.IGNORE_PAGE_MARGINS, Boolean.TRUE);
- } else if (outputFormat == ReportType.XLS) {
- exporter = new JRXlsExporter();
- exporter.setParameter(JRXlsExporterParameter.CHARACTER_ENCODING, characterEncoding);
- exporter.setParameter(JRXlsExporterParameter.IGNORE_PAGE_MARGINS, Boolean.TRUE);
- exporter.setParameter(JRXlsExporterParameter.IS_DETECT_CELL_TYPE, Boolean.TRUE);
- exporter.setParameter(JRXlsExporterParameter.IS_WHITE_PAGE_BACKGROUND, false);
- } else if (outputFormat == ReportType.CSV) {
- exporter = new JRCsvExporter();
- exporter.setParameter(JRCsvExporterParameter.CHARACTER_ENCODING, characterEncoding);
- exporter.setParameter(JRCsvExporterParameter.RECORD_DELIMITER, RECORD_DELIMITER);
- exporter.setParameter(JRCsvExporterParameter.FIELD_DELIMITER, FIELD_DELIMITER);
- } else {
- throw new IllegalStateException("Invalid report type. Permitted types are: HTML, PDF, XLS, CSV");
- }
-
- if (customExporterParams != null && !customExporterParams.isEmpty()) {
- for (Iterator> it = customExporterParams.entrySet().iterator(); it.hasNext();) {
- Map.Entry entry = it.next();
- exporter.setParameter(entry.getKey(), entry.getValue());
- }
- }
-
- exporter.setParameter(JRExporterParameter.JASPER_PRINT_LIST, Collections.singletonList(jasperPrint));
- exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, bos);
- exporter.exportReport();
- return bos.toByteArray();
- } catch (JRException e) {
- throw new ARException(ErrorCode.JASPER_REPORTS_EXCEPTION, e);
- }
- }
-
- /**
- * Exports a report to a desired format. Omits the custom parameters.
- *
- * @param jasperPrint A {@link JasperPrint}
- * @param format Desired output format (i.e. PDF, HTML etc)
- * @param configuration Configuration parameters
- * @return Bytes of a generated report
- * @throws AperteReportsException on error
- * @see #exportReport(net.sf.jasperreports.engine.JasperPrint, String,
- * java.util.Map, java.util.Map)
- */
- public static byte[] exportReport(JasperPrint jasperPrint, String format, Map configuration)
- throws ARException {
- return exportReport(jasperPrint, format, null, configuration);
- }
-
- /**
- * Compiles an input JRXML string report source to a {@link JasperPrint}.
- * Uses a {@link ReportCache} to cache the compilation.
- *
- *
- * @param reportSource A JRXML string source
- * @param cacheId Report cache id
- * @param subreportProvider
- * @return Compiled report
- * @throws JRException on Jasper error
- * @throws SubreportNotFoundException
- */
- public static AperteReport compileReport(byte[] reportSource, String cacheId, SubreportProvider subreportProvider)
- throws ARException {
- return compileReport(reportSource, cacheId, subreportProvider, false);
- }
-
- private static AperteReport compileReport(byte[] reportSource, String cacheId, SubreportProvider subreportProvider,
- boolean hasParent) throws ARException {
- logger.info("Trying to fetch report '" + cacheId + "' from cache");
- AperteReport compiledReport = ReportCache.getReport(cacheId);
- Set subreportNames = new HashSet();
- if (compiledReport == null) {
- logger.info("Report not found. Compiling...");
-
- String source = processSubreports(hasParent, new String(reportSource), subreportNames);
- ByteArrayInputStream bis = new ByteArrayInputStream(source.getBytes());
- try {
- compiledReport = new AperteReport(JasperCompileManager.compileReport(bis));
- logger.info("Compiled.");
- } catch (JRException e) {
- logger.error("report source exception", e);
- throw new ARException(ErrorCode.REPORT_SOURCE_EXCEPTION, e);
- }
- } else {
- logger.info("Report found");
-
- subreportNames.addAll(compiledReport.getSubreports().keySet());
- compiledReport.getSubreports().clear();
- }
- compileSubreports(subreportProvider, compiledReport, subreportNames);
-
- ReportCache.putReport(cacheId, compiledReport);
-
- return compiledReport;
- }
-
- private static void compileSubreports(SubreportProvider subreportProvider, AperteReport compiledReport,
- Set subreportNames) throws ARException {
- if (subreportNames.size() > 0) {
- if (subreportProvider == null) {
- subreportProvider = new EmptySubreportProvider();
- }
- Map subreports = subreportProvider.getSubreports((String[]) subreportNames.toArray(new String[subreportNames.size()]));
- Map compiledSubreports = new HashMap(subreports.size(), 1);
- for (Subreport subreport : subreports.values()) {
- AperteReport compiledSubreport = compileReport(subreport.getContent(), subreport.getCacheId(),
- subreportProvider, true);
- compiledSubreports.put(subreport.getName(), compiledSubreport);
- }
- compiledReport.setSubreports(compiledSubreports);
- }
- }
-
- public static AperteReport compileReport(String reportSource, String cacheId, SubreportProvider subreportProvider)
- throws ARException {
- try {
- return compileReport(ReportGeneratorUtils.decodeContent(reportSource), cacheId, subreportProvider);
- } catch (UnsupportedEncodingException e) {
- throw new ARRuntimeException(ErrorCode.UNSUPPORTED_ENCODING, e);
- }
- }
-
- public byte[] generateAndExportReport(String format, Map reportParameters,
- Map exporterParameters, Map configuration)
- throws ARException {
- JasperPrint jasperPrint = generateReport(reportParameters, configuration);
- return exportReport(jasperPrint, format, exporterParameters, configuration);
- }
-
- /**
- * Generates and exports a report to the desired format from the source
- * passed as a constructor parameter. Returns
- * null on error. The error is noticed by a {@link Logger}
- * instance.
- *
- *
- * @param format Output format
- * @param reportParameters Report parameters
- * @param configuration Exporter configuration
- * @return Bytes of a generated report
- */
- public byte[] generateAndExportReport(String format, Map reportParameters,
- Map configuration) throws ARException {
- return generateAndExportReport(format, reportParameters, null, configuration);
- }
-
- private static String processSubreports(boolean hasParent, String source, Set subreportNames) {
- Matcher m = subreportPattern.matcher(source);
- while (m.find()) {
- String subReportName = m.group(1);
- subreportNames.add(subReportName);
- source = m.replaceFirst(""
- + "" + "" + "$1");
- }
-
- logger.info(subreportNames.size() + " subreports found");
-
- if (subreportNames.size() > 0 || hasParent) {
- m = jasperReportPattern.matcher(source);
- m.find();
- source = m.replaceFirst(m.group() + subreportMapParameter);
- }
- return source;
- }
-
- /**
- * Generates a {@link JasperPrint} using given parameters from the source
- * passed as a constructor parameter. Returns
- * null on error. The error is noticed by a {@link Logger}
- * instance.
- *
- * @param reportParameters Report parameters
- * @param configuration Configuration, can be null
- * @return Output JasperPrint
- */
- private JasperPrint generateReport(Map reportParameters, Map configuration)
- throws ARException {
- try {
- JasperPrint jasperPrint = buildJasperPrint(reportParameters, configuration);
- return jasperPrint;
- } catch (JRFontNotFoundException e) {
- throw new ARException(ErrorCode.FONT_NOT_FOUND, e);
- } catch (Exception e) {
- logger.error("Unknown error", e);
- throw new ARException(e);
- }
- }
-
- public JasperPrint generateReport(Map reportParameters) throws ARException {
- return generateReport(reportParameters, null);
- }
-
- /**
- * Gets a list of report parameters derived from the compiled Jasper report.
- * Returns
- * null on error. The error is noticed by a
- * {@link Logger} instance.
- *
- * @return a list of {@link ReportParameter}
- */
- public List getParameters() {
- if (report == null) {
- logger.info("No active report configuration");
- return null;
- }
- JRParameter[] parameters = getJasperReport().getParameters();
- List outputList = new ArrayList();
- for (JRParameter parameter : parameters) {
- ReportParameter outputParameter = new ReportParameter();
- outputParameter.setType(parameter.getValueClassName());
- outputParameter.setName(parameter.getName());
-
- JRPropertiesMap propertiesMap = parameter.getPropertiesMap();
- if (propertiesMap == null || !propertiesMap.hasProperties()) {
- continue;
- }
-
- String[] propertyNames = propertiesMap.getPropertyNames();
- Map outputProperties = new HashMap(propertyNames.length, 1);
- for (String propertyName : propertyNames) {
- try {
- Keys key = Keys.valueOf(StringUtils.upperCase(propertyName));
- ReportProperty property = new ReportProperty(key, propertiesMap.getProperty(propertyName));
- outputProperties.put(key, property);
- } catch (IllegalArgumentException e) {
- throw new ARRuntimeException(ErrorCode.UNKNOWN_PROPERTY_NAME, e, propertyName);
- }
- }
- outputParameter.setProperties(outputProperties);
- outputList.add(outputParameter);
- }
- return outputList;
- }
-
- /**
- * Gets current report's name.
- *
- * @return The name of the report
- */
- public String getReportName() {
- return getJasperReport().getName();
- }
-
- public AperteReport getAperteReport() {
- return report;
- }
-
- /**
- * Builds a new {@link JasperPrint} of the current report using given
- * parameters.
- *
- * @param reportParameters Input report parameters
- * @param configuration Jasper configuration parameters, can be null
- * @return A {@link JasperPrint}
- * @throws JRException on Jasper error
- * @throws NamingException on errors while accessing the initial context
- * @throws SQLException on errors while accessing a configured datasource
- */
- private JasperPrint buildJasperPrint(Map reportParameters, Map configuration)
- throws JRException, NamingException, SQLException {
-
- //previously data source was passed as a method argument, but it was not used nowhere
-//xxx dataSource condition
-// Object dataSource = null;
-
- if (configuration == null) {
- configuration = new HashMap();
- }
- if (reportParameters == null) {
- reportParameters = new HashMap();
- }
-
- logger.info("Starting building jasper print");
- JasperPrint jasperPrint = null;
-
- injectDefaultValues(reportParameters);
-
- if (report.getSubreports().size() > 0) {
- reportParameters.put(SUBREPORT_MAP_PARAMETER_NAME, report.getAllNestedSubreports());
- }
-
- Connection connection = null;
- try {
-// if (dataSource == null) {
- String jndiDataSource = configuration.get(Parameter.DATASOURCE.name());
- connection = jndiDataSource != null ? getConnectionByJNDI(jndiDataSource)
- : getConnectionFromReport(getJasperReport());
- if (connection != null) {
- jasperPrint = JasperFillManager.fillReport(getJasperReport(), reportParameters,
- connection);
- } else {
- Collection