use of org.compiere.process.ProcessInfoParameter in project adempiere by adempiere.
the class ComponentChange method prepare.
@Override
protected void prepare() {
for (ProcessInfoParameter para : getParameter()) {
String name = para.getParameterName();
if (para.getParameter() == null)
;
else // BR [ 264 ] Parameter Name Changed
if (name.equals("M_Product_ID"))
p_M_Product_ID = para.getParameterAsInt();
else if (name.equals("ValidTo"))
p_ValidTo = ((Timestamp) para.getParameter());
else if (name.equals("ValidFrom"))
p_ValidFrom = ((Timestamp) para.getParameter());
else if (name.equals("Action"))
p_Action = ((String) para.getParameter());
else if (name.equals("M_Product_To_ID"))
p_New_M_Product_ID = para.getParameterAsInt();
else if (name.equals("Qty"))
p_Qty = ((BigDecimal) para.getParameter());
else if (name.equals("M_ChangeNotice_ID"))
p_M_ChangeNotice_ID = para.getParameterAsInt();
else
log.log(Level.SEVERE, "prepare - Unknown Parameter: " + name);
}
}
use of org.compiere.process.ProcessInfoParameter in project adempiere by adempiere.
the class ServerReportCtl method runJasperProcess.
// StartDocumentPrint
/**
* Runs a Jasper process that prints the record
*
* @param recordId
* @param reportEngine
* @param isDirectPrint
* @param printerName
* @param processInfo
* @return
*/
public static boolean runJasperProcess(int recordId, ReportEngine reportEngine, boolean isDirectPrint, String printerName, ProcessInfo processInfo) {
Trx trx;
if (processInfo != null)
trx = Trx.get(processInfo.getTransactionName(), false);
else
trx = null;
MPrintFormat format = reportEngine.getPrintFormat();
ProcessInfo jasperProcessInfo = new ProcessInfo("", format.getJasperProcess_ID());
jasperProcessInfo.setPrintPreview(!isDirectPrint);
MQuery query = reportEngine.getQuery();
if (query != null)
recordId = (Integer) query.getCode(0);
jasperProcessInfo.setRecord_ID(recordId);
Vector<ProcessInfoParameter> jasperPrintParams = new Vector<ProcessInfoParameter>();
ProcessInfoParameter pip;
if (printerName != null && printerName.trim().length() > 0) {
// Override printer name
pip = new ProcessInfoParameter(PARAM_PRINTER_NAME, printerName, null, null, null);
jasperPrintParams.add(pip);
}
pip = new ProcessInfoParameter(PARAM_PRINT_FORMAT, format, null, null, null);
jasperPrintParams.add(pip);
pip = new ProcessInfoParameter(PARAM_PRINT_INFO, reportEngine.getPrintInfo(), null, null, null);
jasperPrintParams.add(pip);
jasperProcessInfo.setParameter(jasperPrintParams.toArray(new ProcessInfoParameter[] {}));
// Parent set to null for synchronous processing, see bugtracker 3010932
ServerProcessCtl.process(// Parent set to null for synchronous processing, see bugtracker 3010932
null, jasperProcessInfo, trx);
if (processInfo != null)
processInfo.setPDFReport(jasperProcessInfo.getPDFReport());
boolean result = true;
return (result);
}
use of org.compiere.process.ProcessInfoParameter in project adempiere by adempiere.
the class FinReportJasper method doIt.
/**************************************************************************
* Perform process.
* @return Message to be translated
* @throws Exception
*/
protected String doIt() throws Exception {
// Call the normal FinReport to fill the T_Report table
String finReportMsg = super.doIt();
// Now invoke the associated jasper report (must report on the T_Report table)
ArrayList<ProcessInfoParameter> list = new ArrayList<ProcessInfoParameter>();
// Copy the list of parameters from the financial report
ProcessInfoParameter[] oldpara = getParameter();
for (int i = 0; i < oldpara.length; i++) list.add(oldpara[i]);
// and add the T_Report_AD_PInstance_ID parameter
list.add(new ProcessInfoParameter("T_Report_AD_PInstance_ID", new Integer(getAD_PInstance_ID()), null, null, null));
ProcessInfoParameter[] pars = new ProcessInfoParameter[list.size()];
list.toArray(pars);
// Load Report Definition
m_report = new MReport(getCtx(), getRecord_ID(), get_TrxName());
MProcess proc = new MProcess(getCtx(), m_report.getJasperProcess_ID(), get_TrxName());
MPInstance instance = new MPInstance(proc, getRecord_ID());
instance.saveEx();
ProcessInfo poInfo = new ProcessInfo(proc.getName(), proc.getAD_Process_ID());
poInfo.setParameter(pars);
poInfo.setRecord_ID(getRecord_ID());
poInfo.setAD_Process_ID(proc.getAD_Process_ID());
poInfo.setAD_PInstance_ID(instance.getAD_PInstance_ID());
// need to commit in order to allow jasper to view the data
Trx trx = Trx.get(get_TrxName(), true);
trx.commit();
// CarlosRuiz - globalqss - allow procedure preprocess
if (proc.getProcedureName() != null && proc.getProcedureName().length() > 0) {
// execute on this thread/connection
String sql = "{call " + proc.getProcedureName() + "(?)}";
try {
// ro??
CallableStatement cstmt = DB.prepareCall(sql);
cstmt.setInt(1, getAD_PInstance_ID());
cstmt.executeUpdate();
cstmt.close();
} catch (Exception e) {
log.log(Level.SEVERE, sql, e);
poInfo.setSummary(Msg.getMsg(Env.getCtx(), "ProcessRunError") + " " + e.getLocalizedMessage());
}
}
// TODO - allow java class preprocess if the classname <> ProcessUtil.JASPER_STARTER_CLASS
ProcessUtil.startJavaProcess(getCtx(), poInfo, trx);
return finReportMsg;
}
use of org.compiere.process.ProcessInfoParameter in project adempiere by adempiere.
the class ReportStarter method startProcess.
/**
* Start the process.
* Called then pressing the Process button in R_Request.
* It should only return false, if the function could not be performed
* as this causes the process to abort.
* @author rlemeill
* @param ctx context
* @param pi standard process info
* @param trx
* @return true if success
*/
public boolean startProcess(Properties ctx, ProcessInfo pi, Trx trx) {
processInfo = pi;
String Name = pi.getTitle();
int AD_PInstance_ID = pi.getAD_PInstance_ID();
int Record_ID = pi.getRecord_ID();
log.info("Name=" + Name + " AD_PInstance_ID=" + AD_PInstance_ID + " Record_ID=" + Record_ID);
String trxName = null;
if (trx != null) {
trxName = trx.getTrxName();
}
ReportData reportData = getReportData(pi, trxName);
if (reportData == null) {
reportResult(AD_PInstance_ID, "Can not find report data", trxName);
return false;
}
String reportPath = reportData.getReportFilePath();
if (Util.isEmpty(reportPath, true)) {
reportResult(AD_PInstance_ID, "Can not find report", trxName);
return false;
}
JasperData data = null;
File reportFile = null;
String fileExtension = "";
HashMap<String, Object> params = new HashMap<String, Object>();
addProcessParameters(AD_PInstance_ID, params, trxName);
addProcessInfoParameters(params, pi.getParameter());
reportFile = getReportFile(reportPath, (String) params.get("ReportType"));
if (reportFile == null || reportFile.exists() == false) {
log.severe("No report file found for given type, falling back to " + reportPath);
reportFile = getReportFile(reportPath);
}
if (reportFile == null || reportFile.exists() == false) {
String tmp = "Can not find report file at path - " + reportPath;
log.severe(tmp);
reportResult(AD_PInstance_ID, tmp, trxName);
}
if (reportFile != null) {
data = processReport(reportFile);
if (data.getJasperReport() == null) {
log.severe("Could not load Jasper Report " + reportPath);
return false;
}
fileExtension = reportFile.getName().substring(reportFile.getName().lastIndexOf("."), reportFile.getName().length());
} else {
return false;
}
JasperReport jasperReport = data.getJasperReport();
String jasperName = data.getJasperName();
String name = jasperReport.getName();
File reportDir = data.getReportDir();
// Add reportDir to class path
ClassLoader scl = ClassLoader.getSystemClassLoader();
try {
java.net.URLClassLoader ucl = new java.net.URLClassLoader(new java.net.URL[] { reportDir.toURI().toURL() }, scl);
net.sf.jasperreports.engine.util.JRResourcesUtil.setThreadClassLoader(ucl);
} catch (MalformedURLException me) {
log.warning("Could not add report directory to classpath: " + me.getMessage());
}
if (jasperReport != null) {
File[] subreports;
// Subreports
if (reportPath.startsWith("http://") || reportPath.startsWith("https://")) {
// Locate and download subreports from remote webcontext
subreports = getHttpSubreports(jasperName + "Subreport", reportPath, fileExtension);
} else if (reportPath.startsWith("attachment:")) {
subreports = getAttachmentSubreports(reportPath);
} else if (reportPath.startsWith("resource:")) {
subreports = getResourceSubreports(name + "Subreport", reportPath, fileExtension);
} else // TODO: Implement file:/ lookup for subreports
{
// Locate subreports from local/remote filesystem
subreports = reportDir.listFiles(new FileFilter(jasperName + "Subreport", reportDir, fileExtension));
}
for (int i = 0; i < subreports.length; i++) {
// @Trifon - begin
if (subreports[i].getName().toLowerCase().endsWith(".jasper") || subreports[i].getName().toLowerCase().endsWith(".jrxml")) {
JasperData subData = processReport(subreports[i]);
if (subData.getJasperReport() != null) {
params.put(subData.getJasperName(), subData.getJasperFile().getAbsolutePath());
}
}
// @Trifon - end
}
if (Record_ID > 0)
params.put("RECORD_ID", new Integer(Record_ID));
// contribution from Ricardo (ralexsander)
// in iReports you can 'SELECT' AD_Client_ID, AD_Org_ID and AD_User_ID using only AD_PINSTANCE_ID
params.put("AD_PINSTANCE_ID", new Integer(AD_PInstance_ID));
// FR [3123850] - Add continiuosly needed parameters to Jasper Starter - Carlos Ruiz - GlobalQSS
params.put("AD_CLIENT_ID", new Integer(Env.getAD_Client_ID(Env.getCtx())));
params.put("AD_ROLE_ID", new Integer(Env.getAD_Role_ID(Env.getCtx())));
params.put("AD_USER_ID", new Integer(Env.getAD_User_ID(Env.getCtx())));
Language currLang = Env.getLanguage(Env.getCtx());
String printerName = null;
MPrintFormat printFormat = null;
PrintInfo printInfo = null;
ProcessInfoParameter[] pip = pi.getParameter();
// Get print format and print info parameters
if (pip != null) {
for (int i = 0; i < pip.length; i++) {
if (ServerReportCtl.PARAM_PRINT_FORMAT.equalsIgnoreCase(pip[i].getParameterName())) {
printFormat = (MPrintFormat) pip[i].getParameter();
}
if (ServerReportCtl.PARAM_PRINT_INFO.equalsIgnoreCase(pip[i].getParameterName())) {
printInfo = (PrintInfo) pip[i].getParameter();
}
if (ServerReportCtl.PARAM_PRINTER_NAME.equalsIgnoreCase(pip[i].getParameterName())) {
printerName = (String) pip[i].getParameter();
}
}
}
if (printFormat != null) {
if (printInfo != null) {
// Set the language of the print format if we're printing a document
if (printInfo.isDocument()) {
currLang = printFormat.getLanguage();
}
}
// Set printer name unless already set.
if (printerName == null) {
printerName = printFormat.getPrinterName();
}
}
params.put("CURRENT_LANG", currLang.getAD_Language());
params.put(JRParameter.REPORT_LOCALE, currLang.getLocale());
// Resources
File resFile = null;
if (reportPath.startsWith("attachment:") && attachment != null) {
resFile = getAttachmentResourceFile(jasperName, currLang);
} else if (reportPath.startsWith("resource:")) {
resFile = getResourcesForResourceFile(jasperName, currLang);
// TODO: Implement file:/ for resources
} else {
resFile = new File(jasperName + "_" + currLang.getLocale().getLanguage() + ".properties");
if (!resFile.exists()) {
resFile = null;
}
if (resFile == null) {
resFile = new File(jasperName + ".properties");
if (!resFile.exists()) {
resFile = null;
}
}
}
if (resFile != null) {
try {
PropertyResourceBundle res = new PropertyResourceBundle(new FileInputStream(resFile));
params.put("RESOURCE", res);
} catch (IOException e) {
;
}
}
Connection conn = null;
try {
conn = trx != null ? trx.getConnection() : getConnection();
jasperPrint = JasperFillManager.fillReport(jasperReport, params, conn);
if (reportData.isDirectPrint() && !processInfo.isPrintPreview()) {
log.info("ReportStarter.startProcess print report -" + jasperPrint.getName());
//RF 1906632
if (!processInfo.isBatch()) {
// Get printer job
PrinterJob printerJob = org.compiere.print.CPrinter.getPrinterJob(printerName);
// Set print request attributes
// Paper Attributes:
PrintRequestAttributeSet prats = new HashPrintRequestAttributeSet();
// add: copies, job-name, priority
if (// @Trifon
printInfo == null || printInfo.isDocumentCopy() || printInfo.getCopies() < 1)
prats.add(new Copies(1));
else
prats.add(new Copies(printInfo.getCopies()));
Locale locale = Language.getLoginLanguage().getLocale();
// @Trifon
String printFormat_name = printFormat == null ? "" : printFormat.getName();
int numCopies = printInfo == null ? 0 : printInfo.getCopies();
prats.add(new JobName(printFormat_name + "_" + pi.getRecord_ID(), locale));
prats.add(PrintUtil.getJobPriority(jasperPrint.getPages().size(), numCopies, true));
// Create print service exporter
JRPrintServiceExporter exporter = new JRPrintServiceExporter();
;
// Set parameters
exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
exporter.setParameter(JRPrintServiceExporterParameter.PRINT_SERVICE, printerJob.getPrintService());
exporter.setParameter(JRPrintServiceExporterParameter.PRINT_SERVICE_ATTRIBUTE_SET, printerJob.getPrintService().getAttributes());
exporter.setParameter(JRPrintServiceExporterParameter.PRINT_REQUEST_ATTRIBUTE_SET, prats);
exporter.setParameter(JRPrintServiceExporterParameter.DISPLAY_PAGE_DIALOG, Boolean.FALSE);
exporter.setParameter(JRPrintServiceExporterParameter.DISPLAY_PRINT_DIALOG, Boolean.FALSE);
// Print report / document
exporter.exportReport();
} else {
// Used For the PH
try {
File PDF = File.createTempFile("mail", ".pdf");
JasperExportManager.exportReportToPdfFile(jasperPrint, PDF.getAbsolutePath());
processInfo.setPDFReport(PDF);
} catch (IOException e) {
log.severe("ReportStarter.startProcess: Can not make PDF File - " + e.getMessage());
}
}
// You can use JasperPrint to create PDF
// JasperExportManager.exportReportToPdfFile(jasperPrint, "BasicReport.pdf");
} else {
log.info("ReportStarter.startProcess run report -" + jasperPrint.getName());
JRViewerProvider viewerLauncher = getReportViewerProvider();
//viewerLauncher.openViewer(jasperPrint, pi.getTitle()+" - " + reportPath);
viewerLauncher.openViewer(jasperPrint, pi.getTitle() + "_" + pi.getRecord_ID() + ".pdf");
}
} catch (JRException e) {
log.severe("ReportStarter.startProcess: Can not run report - " + e.getMessage());
} finally {
if (conn != null && trx == null)
try {
conn.close();
} catch (SQLException e) {
throw new AdempiereException("@Error@ " + e);
}
}
}
reportResult(AD_PInstance_ID, null, trxName);
return true;
}
use of org.compiere.process.ProcessInfoParameter in project adempiere by adempiere.
the class ImportInventoryMove method prepare.
/**
* Prepare - e.g., get Parameters.
*/
protected void prepare() {
for (ProcessInfoParameter para : getParameter()) {
String name = para.getParameterName();
if (para.getParameter() == null)
;
else if ("IsImportOnlyNoErrors".equals(name))
isImportOnlyNoErrors = para.getParameterAsBoolean();
else if ("DeleteOldImported".equals(name))
deleteOldImported = para.getParameterAsBoolean();
else if ("DocAction".equals(name))
docAction = para.getParameterAsString();
else
log.log(Level.SEVERE, "Unknown Parameter: " + name);
}
}
Aggregations