/**
* OpenCPS is the open source Core Public Services software
* Copyright (C) 2016-present OpenCPS community

* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.

* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*/

package org.opencps.jasperreport.util;

import java.util.Map;

import org.opencps.jasperreport.compile.JRReportTemplate;
import org.opencps.jasperreport.datasource.JRJSONDataSource;

import com.liferay.portal.kernel.log.Log;
import com.liferay.portal.kernel.log.LogFactoryUtil;
import com.liferay.portal.kernel.util.StringPool;

import net.sf.jasperreports.engine.JRException;
import net.sf.jasperreports.engine.JasperExportManager;
import net.sf.jasperreports.engine.JasperFillManager;
import net.sf.jasperreports.engine.JasperPrint;

/**
 * @author trungnt
 *
 */
public class JRReportUtil {

	public static JasperPrint getJasperPrint(
	    JRReportTemplate jrReportTemplate, Map<String, Object> parameters,
	    JRJSONDataSource dataSource) {

		JasperPrint jasperPrint = null;
		try {
			jasperPrint = JasperFillManager
			    .fillReport(jrReportTemplate, null, dataSource);

		}
		catch (Exception e) {
			_log
			    .error(e);
		}
		return jasperPrint;
	}
	
	public static String exportReportToPdfFile(
	    JasperPrint jasperPrint, String outputDestination, String exportName) {

		try {
			JasperExportManager
			    .exportReportToPdfFile(
			        jasperPrint, outputDestination + exportName);
			return outputDestination + exportName;
		}
		catch (JRException e) {
			_log
			    .error(e);
			return StringPool.BLANK;
		}
	}

	private static Log _log = LogFactoryUtil
	    .getLog(JRReportUtil.class
	        .getName());
}


@@ -1354,191 +1354,403 @@
 tic 
-JasperPrint getJasperPrint(%0A%09    JRReportTemplate jrReportTemplate, Map%3CString, Object%3E parameters,%0A%09    JRJSONDataSource dataSource) %7B%0A%0A%09%09JasperPrint jasperPrint = null;%0A%09%09try %7B%0A%09%09%09j
+String createReportPDFfFile(%0A%09    String jrxmlTemplate, String jsonData, Map%3CString, Object%3E parameters,%0A%09    String outputDestination, String exportName) %7B%0A%0A%09%09String sourceFileName = outputDestination + exportName;%0A%09%09try %7B%0A%09%09%09JRReportTemplate reportTemplate = JRReportTemplate%0A%09%09%09    .compile(jrxmlTemplate);%0A%09%09%09JRJSONDataSource dataSource = JRJSONDataSource%0A%09%09%09    .getInstance(jsonData);%0A%09%09%09J
 aspe
@@ -1760,50 +1760,45 @@
 int 
-= J
+j
 asper
-FillManager%0A%09%09%09    .fillReport(jrR
+Print =%0A%09%09%09    getJasperPrint(r
 epor
@@ -1812,12 +1812,18 @@
 te, 
-null
+parameters
 , da
@@ -1834,16 +1834,78 @@
 urce);%0A%0A
+%09%09%09return exportReportToPdfFile(jasperPrint, sourceFileName);%0A
 %09%09%7D%0A%09%09ca
@@ -1950,20 +1950,18 @@
 ror(e);%0A
-%09%09%7D
 %0A
+%09
 %09%09return
@@ -1965,172 +1965,253 @@
 urn 
-jasperPrint;%0A%09%7D%0A%09%0A%09public static String exportReportToPdfFile(%0A%09    JasperPrint jasperPrint, String outputDestination, String exportName) %7B%0A%0A%09%09try
+StringPool.BLANK;%0A%0A%09%09%7D%0A%0A%09%7D%0A%0A%09protected static JasperPrint getJasperPrint(%0A%09    JRReportTemplate jrReportTemplate, Map%3CString, Object%3E parameters,%0A%09    JRJSONDataSource dataSource)%0A%09    throws JRException
  %7B%0A
+%0A
 %09%09
-%09
 Jasper
-Export
+Print jasperPrint = JasperFill
 Mana
@@ -2220,149 +2220,201 @@
 r%0A%09%09
-%09
     .
+fillR
 e
-x
 port
+(jr
 ReportT
-oPdfFile(%0A%09%09%09        jasperPrint, outputDestination + exportName);%0A%09%09%09return outputDestination + exportName;%0A%09%09%7D%0A%09%09catch (
+emplate, null, dataSource);%0A%0A%09%09return jasperPrint;%0A%09%7D%0A%0A%09protected static String exportReportToPdfFile(%0A%09    JasperPrint jasperPrint, String sourceFileName)%0A%09    throws 
 JREx
@@ -2424,71 +2424,88 @@
 tion
- e)
  %7B%0A
+%0A
 %09%09
-%09_log%0A%09%09%09    .error(e);%0A%09%09%09return StringPool.BLANK;%0A%09%09%7D
+return JasperExportManager%0A%09%09    .exportReportToHtmlFile(sourceFileName);%0A
 %0A%09%7D%0A
@@ -2603,9 +2603,8 @@
 e());%0A%7D%0A
-%0A

Add method createExportFile