You are not logged in.
Pages: 1
Hi everybody,
I would like to test the functionality of custom targets (e.g. SFTP) in the new RS 3.0 Enterprise. Unfortunately I don't find the place where I can do the configuration for that. On the other hand the interface allows me to disseminate the generated reports only on TeamSpace or by e-mail in ad-hoc execution as well as in the scheduled reports.
Can you please give me some hint?
Many thanks in advance,
Cristian
Offline
Offline
Hi All,
Following this, you may try to use a script similar to one I got from Arno:
import net.datenwerke.rs.core.service.sendto.hooks.SendToTargetProviderHook
import net.datenwerke.rs.core.service.sendto.hooks.adapter.SendToTargetProviderHookAdapter
import net.datenwerke.rs.core.client.sendto.SendToClientConfig
import net.datenwerke.rs.core.service.reportmanager.entities.reports.Report
import net.datenwerke.rs.core.service.reportmanager.engine.config.ReportExecutionConfig
import net.datenwerke.rs.core.service.reportmanager.engine.CompiledReport
import java.io.ByteArrayInputStream
import com.jcraft.jsch.ChannelSftp;
import com.jcraft.jsch.JSch;
import com.jcraft.jsch.Session;
/**
* basic configuration
*/
def HOOK_NAME = "SEND_TO_SFTP"
def menuTitle = "SFTP"
def successMessage = "Sent to SFTP"
def hostname = "HOST_IP"
def port = 22
def user = "sftp_user"
def password = "sftp_user_password"
def path = "/var/local/reports"
def exportFormat = "PDF"
def reportFilename = "report"
/**
* Hook Implementation
*/
class SendToViaSFTP extends SendToTargetProviderHookAdapter{
private GLOBALS;
private String successMessage;
private String menuTitle;
private String hostname;
private int port;
private String user;
private String password;
private String path;
private String exportFormat;
private String reportFilename;
public SendToViaSFTP(GLOBALS,
successMessage, menuTitle,
hostname, port, user, password, path,
exportFormat,
reportFilename
){
this.GLOBALS = GLOBALS;
this.successMessage = successMessage;
this.menuTitle = menuTitle;
this.hostname = hostname;
this.port = port;
this.user = user;
this.password = password;
this.path = path;
this.exportFormat = exportFormat;
this.reportFilename = reportFilename;
}
public String getId(){
return getClass().getName();
}
public SendToClientConfig consumes(Report report){
SendToClientConfig config = new SendToClientConfig();
config.setTitle(menuTitle);
config.setSelectFormat(true);
return config;
}
public String sendTo(CompiledReport executedReport, Report report, String format, HashMap<String, String> values,
ReportExecutionConfig... execConfig){
/* prepare connection */
java.util.Properties config = new java.util.Properties();
config.put("StrictHostKeyChecking", "no");
JSch ssh = new JSch();
Session session = ssh.getSession(user, hostname, port);
session.setConfig(config);
session.setPassword(password);
session.connect();
ChannelSftp channel = (ChannelSftp) session.openChannel("sftp");
channel.connect();
try{
/* upload files */
String target = path + "/" + reportFilename + "." + executedReport.getFileExtension();
if(executedReport.getReport() instanceof String) {
channel.put(new ByteArrayInputStream(executedReport.getReport().getBytes("UTF-8")), target);
} else {
channel.put(new ByteArrayInputStream(executedReport.getReport()), target );
}
} finally {
/* disconnect */
channel.disconnect();
session.disconnect();
}
/* return success */
return successMessage;
}
}
/* instantiate hook and plug it in */
def hookImpl = new SendToViaSFTP(
GLOBALS,
successMessage, menuTitle,
hostname, port, user, password, path,
exportFormat,
reportFilename
);
GLOBALS.services.callbackRegistry.attachHook(HOOK_NAME, SendToTargetProviderHook.class, hookImpl)
You will need additional library added to your classpath. It can be found here
Note that with this configuration the report file name is fixed, so the file will be overwritten next time you use sent-to option.
Maybe someone here has an idea how to set the report file name to one that would be used when the report is exported in a normal way or just make it unique?
Cheers,
Karolina
Last edited by karolina (2016-07-16 09:42:00)
Offline
OK, I found a way to set the file name to one containing the report name plus current date:
try{
/* report file name */
SimpleDateFormat df = new SimpleDateFormat("yyyyMMdd_HHmmssSSS")
String dateSuffix = df.format(new Date())
def reportFilename = report.getName()
.replaceAll("[^a-zA-ZüÜöÖäÄß\\(\\)\\[\\]\\-\\.0-9]+","_") + "_" + dateSuffix
/* upload files */
String target = path + "/" + reportFilename + "." + executedReport.getFileExtension();
if(executedReport.getReport() instanceof String) {
channel.put(new ByteArrayInputStream(executedReport.getReport().getBytes("UTF-8")), target);
} else {
channel.put(new ByteArrayInputStream(executedReport.getReport()), target );
}
The complete script:
import net.datenwerke.rs.core.service.sendto.hooks.SendToTargetProviderHook
import net.datenwerke.rs.core.service.sendto.hooks.adapter.SendToTargetProviderHookAdapter
import net.datenwerke.rs.core.client.sendto.SendToClientConfig
import net.datenwerke.rs.core.service.reportmanager.entities.reports.Report
import net.datenwerke.rs.core.service.reportmanager.engine.config.ReportExecutionConfig
import net.datenwerke.rs.core.service.reportmanager.engine.CompiledReport
import java.io.ByteArrayInputStream
import com.jcraft.jsch.ChannelSftp;
import com.jcraft.jsch.JSch;
import com.jcraft.jsch.Session;
import java.text.SimpleDateFormat;
/**
* basic configuration
*/
def HOOK_NAME = "SEND_TO_SFTP_FN"
def menuTitle = "SFTP"
def successMessage = "Sent to SFTP"
def hostname = "host_ip"
def port = 22 //SSH port number
def user = "sftp_user"
def password = "sftp_password"
def path = "/path/to/your/target/folder"
def exportFormat = "PDF"
/**
* Hook Implementation
*/
class SendToViaSFTP extends SendToTargetProviderHookAdapter{
private String successMessage;
private String menuTitle;
private String hostname;
private int port;
private String user;
private String password;
private String path;
private String exportFormat;
public SendToViaSFTP(successMessage, menuTitle,
hostname, port, user, password, path,
exportFormat
){
this.successMessage = successMessage;
this.menuTitle = menuTitle;
this.hostname = hostname;
this.port = port;
this.user = user;
this.password = password;
this.path = path;
this.exportFormat = exportFormat;
}
public String getId(){
return getClass().getName();
}
public SendToClientConfig consumes(Report report){
SendToClientConfig config = new SendToClientConfig();
config.setTitle(menuTitle);
config.setSelectFormat(true);
return config;
}
public String sendTo(CompiledReport executedReport, Report report, String format, HashMap<String, String> values,
ReportExecutionConfig... execConfig){
/* prepare connection */
java.util.Properties config = new java.util.Properties();
config.put("StrictHostKeyChecking", "no");
JSch ssh = new JSch();
Session session = ssh.getSession(user, hostname, port);
session.setConfig(config);
session.setPassword(password);
session.connect();
ChannelSftp channel = (ChannelSftp) session.openChannel("sftp");
channel.connect();
try{
/* report file name */
SimpleDateFormat df = new SimpleDateFormat("yyyyMMdd_HHmmssSSS")
String dateSuffix = df.format(new Date())
def reportFilename = report.getName()
.replaceAll("[^a-zA-ZüÜöÖäÄß\\(\\)\\[\\]\\-\\.0-9]+","_") + "_" + dateSuffix
/* upload files */
String target = path + "/" + reportFilename + "." + executedReport.getFileExtension();
if(executedReport.getReport() instanceof String) {
channel.put(new ByteArrayInputStream(executedReport.getReport().getBytes("UTF-8")), target);
} else {
channel.put(new ByteArrayInputStream(executedReport.getReport()), target );
}
} finally {
/* disconnect */
channel.disconnect();
session.disconnect();
}
/* return success */
return successMessage;
}
}
/* instantiate hook and plug it in */
def hookImpl = new SendToViaSFTP(
successMessage, menuTitle,
hostname, port, user, password, path,
exportFormat
);
GLOBALS.services.callbackRegistry.attachHook(HOOK_NAME, SendToTargetProviderHook.class, hookImpl)
Cheers,
Karolina
Offline
Many Thanks Thomas and Karolina for the information. The last script sent by Karolina works like a charm.
Offline
I'm happy it was helpful.
It contains Arno's & Thorsten's work as well
Karolina
Offline
Pages: 1