#1 2015-01-26 22:35:50

karolina
Member
Registered: 2014-08-09

export file names

Hi,

Is there a way to setup file name when exporting a report (except exporting it into a TeamSpace)?
In a script report I'd like to construct it from some parameters + report name etc.

cheers,
Karolina

Offline

#2 2015-01-27 06:51:17

Arno Mittelbach
datenwerke
Registered: 2012-02-14

Re: export file names

Hi Karolina,

we already have that one on the todo list but there is currently no nice way of doing this. What is possible is to hook into the
export process and override the HTTP Headers which allows you to set the file name for download. The corresponding hook is

net.datenwerke.rs.core.server.reportexport.hooks.ReportExportAdjustHttpHeaderHook

Anyhow. I'll give the ticket a +1.

Cheers
Arno

Offline

#3 2015-01-27 17:50:41

karolina
Member
Registered: 2014-08-09

Re: export file names

Hi Arno,

Thank you for giving the +1 for the ticket.
To be honest, I can't find a way to get parameters' values of the exported report neither through Report object, nor by CompiledReport... any hint?

Cheers,

Karolina

Last edited by karolina (2015-01-27 17:50:59)

Offline

#4 2015-01-28 18:28:23

Thorsten J. Krause
Guest

Re: export file names

Hi Karolina,

the interface isn't really great there: You have to loop over all ParameterInstances and find the one with the matching key:

package tmp

import java.text.SimpleDateFormat

import javax.servlet.http.HttpServletRequest
import javax.servlet.http.HttpServletResponse

import net.datenwerke.rs.core.server.reportexport.hooks.ReportExportAdjustHttpHeaderHook
import net.datenwerke.rs.core.service.parameters.entities.ParameterInstance
import net.datenwerke.rs.core.service.reportmanager.engine.CompiledReport
import net.datenwerke.rs.core.service.reportmanager.entities.reports.Report

def HOOK_NAME = "ADJUST_DL_FNAME"

def makeExportFilename = { Report report ->
	String reportName = report.getName();

	
	import net.datenwerke.rs.core.service.parameters.entities.ParameterInstance;
	
	for(ParameterInstance pi : report.getParameterInstances()){
		if("P_CUSTNUM".equals(pi.getKey())){
			System.out.println(pi.getSelectedValue(null));
		}
	}
		
	return reportName.replaceAll("[^a-zA-ZüÜöÖäÄß\\(\\)\\[\\] \\-\\.0-9]+","_");
}

def callback =  [
	adjustHeaders : { Report report, CompiledReport executedReport, HttpServletRequest req, HttpServletResponse resp ->
		
		SimpleDateFormat format = new SimpleDateFormat("yyyyMMddHHmm");
		resp.setHeader("Content-Disposition", "attachement; filename=\"" + format.format(Calendar.getInstance().getTime()) + "_" + makeExportFilename(report)+"."+ executedReport.getFileExtension() +"\""); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
	}
] as ReportExportAdjustHttpHeaderHook

GLOBALS.services.callbackRegistry.attachHook(HOOK_NAME, ReportExportAdjustHttpHeaderHook.class, callback)

Board footer

Powered by FluxBB