Pencil-icon.png

Load external data and generate reports

This script is an example of how to load a project into jBEAM, then import using some pre-existing importer and finally, generating a PDF report.

This example uses a GIDAS importer but can be easily adapted for other types of importers. There are several ways to find an existing importer, this script showcases two.

import java.io.File;
import java.util.List;

import org.asam.cea.Cea2Bus.Cea2BusIF;

import com.AMS.jBEAM.*;
import com.AMS.jBEAM.ProjectServiceIF.ProjectSyncMode;

jBEAMParameter parameters = jB.getParameters();

String outputFileString = parameters.getParameter("script.outputFile");
if (GeneralUtils.isEmpty(outputFileString)) {
 System.out.println("The parameter \"script.outputFile\" is not defined!");
return null;
}

String projectFileString = parameters.getParameter("script.projectFile");
if (GeneralUtils.isEmpty(projectFileString)) {
 System.out.println( "The parameter \"script.projectFile\" is not defined!");
return null;
}

String importFileString = parameters.getParameter("script.importFile");
if (GeneralUtils.isEmpty(importFileString)) {
 System.out.println("The parameter \"script.importFile\" is not defined!");
return null;
}

jB.openProject(projectFileString);

//Variant 1: Get importer by class
List<FileImport_Gidas> gidasImporters = jC.getComponentsByClass(FileImport_Gidas.class);

if (GeneralUtils.isEmpty(gidasImporters)) {
return "No GIDAS Importer in project file!";
}

//Use the first import
FileImport_Gidas fileImportGidas = gidasImporters.get(0);

//Variant 2: Get Importer by name
//  FileImport_Gidas fileImportGidas = (FileImport_Gidas) jC.getComponentByName("myGidasImporter");

fileImportGidas.setImportFile(new File(importFileString));

jC.validateFramework(true);

FileExport_PDF_Graphic pdfExport = jC.newComponent(FileExport_PDF_Graphic.class);
pdfExport.setExportFile(new File(outputFileString));
pdfExport.export(true);

return "Success!";

This script is used via command line. 

java -jar jBEAM.jar ScriptURL="file:///url/to/myscript.groovy" script.projectFile="X:/Path/To/MyProjectFile.jbt" script.importFile="X:/Path/To/MyGidasFile.asc" script.outputFile="X:/Path/To/MyExportFile.pdf"

The first parameter ScriptURL must be an url to a file containing the script above. The other three parameters are used by the script itself. The first one to tell the script where the to-be-imported project file is located. The second one is which file to use for the GIDAS importer. The last parameter is the desired path for the exported pdf.

How To » How to collection for customization of jBEAM (using API or scripts) » Load external data and generate reports
Tags:

Copyright by Kistler Chemnitz GmbH 2021
XWiki Enterprise 4.4 - Documentation