From 3456ab5b6b7fbbaa26c1730b4eb026dc45140b0b Mon Sep 17 00:00:00 2001 From: Carlos Ruiz Date: Tue, 15 Jan 2019 18:36:59 +0100 Subject: [PATCH] IDEMPIERE-3824 Implement apply packin from folder from command line / improve error messaging and rollback on error --- .../org/adempiere/base/PackInFolderApplication.java | 12 +++++++++--- .../adempiere/pipo/srv/PipoDictionaryService.java | 1 + .../adempiere/plugin/utils/AbstractActivator.java | 4 ++++ .../plugin/utils/PackInApplicationActivator.java | 7 ++++++- 4 files changed, 20 insertions(+), 4 deletions(-) diff --git a/org.adempiere.base/src/org/adempiere/base/PackInFolderApplication.java b/org.adempiere.base/src/org/adempiere/base/PackInFolderApplication.java index 5caef4bfb7..04f278051f 100644 --- a/org.adempiere.base/src/org/adempiere/base/PackInFolderApplication.java +++ b/org.adempiere.base/src/org/adempiere/base/PackInFolderApplication.java @@ -32,6 +32,7 @@ import org.compiere.Adempiere; import org.compiere.model.MPInstance; import org.compiere.process.ProcessCall; import org.compiere.process.ProcessInfo; +import org.compiere.process.ProcessInfoUtil; import org.compiere.util.CLogMgt; import org.compiere.util.Env; import org.eclipse.equinox.app.IApplication; @@ -76,14 +77,19 @@ public class PackInFolderApplication implements IApplication { instance.createParameter(10, "Folder", directory); pi.setAD_PInstance_ID(instance.getAD_PInstance_ID()); ProcessCall process = Core.getProcess("org.adempiere.pipo2.PackInFolder"); - process.startProcess(ctx, pi, null); + boolean success = process.startProcess(ctx, pi, null); + ProcessInfoUtil.setLogFromDB(pi); StringBuilder msgout = new StringBuilder("Process=").append(pi.getTitle()) - .append(" Error=").append(pi.isError()).append(" Summary=") - .append(pi.getSummary()); + .append("\n Error=").append(pi.isError()) + .append("\n Summary=").append(pi.getSummary()) + .append("\n Logs=\n").append(pi.getLogInfo(false).replaceAll("
", "\n")); System.out.println(msgout.toString()); + if (!success) + return new Integer(1); } else { System.out.println("Apply PackIn from Folder usage:"); System.out.println("RUN_ApplyPackInFromFolder.sh folder"); + return new Integer(1); } diff --git a/org.adempiere.pipo/src/org/adempiere/pipo/srv/PipoDictionaryService.java b/org.adempiere.pipo/src/org/adempiere/pipo/srv/PipoDictionaryService.java index c1f4885a50..91bf138f84 100644 --- a/org.adempiere.pipo/src/org/adempiere/pipo/srv/PipoDictionaryService.java +++ b/org.adempiere.pipo/src/org/adempiere/pipo/srv/PipoDictionaryService.java @@ -110,6 +110,7 @@ public class PipoDictionaryService implements IDictionaryService { Trx.get(trxName, false).commit(true); if (logger.isLoggable(Level.INFO)) logger.info("commit " + trxName); } catch (Exception e) { + Trx.get(trxName, false).rollback(); adPackageImp.setP_Msg(e.getLocalizedMessage()); packIn.getNotifier().addFailureLine(e.getLocalizedMessage()); packIn.setSuccess(false); diff --git a/org.adempiere.plugin.utils/src/org/adempiere/plugin/utils/AbstractActivator.java b/org.adempiere.plugin.utils/src/org/adempiere/plugin/utils/AbstractActivator.java index 4ffe6436c2..908f27549d 100644 --- a/org.adempiere.plugin.utils/src/org/adempiere/plugin/utils/AbstractActivator.java +++ b/org.adempiere.plugin.utils/src/org/adempiere/plugin/utils/AbstractActivator.java @@ -159,6 +159,10 @@ public abstract class AbstractActivator implements BundleActivator, ServiceTrack m_processInfo = processInfo; } + public ProcessInfo getProcessInfo() { + return m_processInfo; + } + public void setProcessUI(IProcessUI processUI) { m_processUI = processUI; }; diff --git a/org.adempiere.plugin.utils/src/org/adempiere/plugin/utils/PackInApplicationActivator.java b/org.adempiere.plugin.utils/src/org/adempiere/plugin/utils/PackInApplicationActivator.java index eb9369aa92..23c9578933 100644 --- a/org.adempiere.plugin.utils/src/org/adempiere/plugin/utils/PackInApplicationActivator.java +++ b/org.adempiere.plugin.utils/src/org/adempiere/plugin/utils/PackInApplicationActivator.java @@ -169,7 +169,12 @@ public class PackInApplicationActivator extends AbstractActivator { currentFile = zipFile; if (!packIn(zipFile)) { // stop processing further packages if one fail - addLog(Level.WARNING, "Failed application of " + zipFile); + String msg = "Failed application of " + zipFile; + addLog(Level.SEVERE, msg); + if (getProcessInfo() != null) { + getProcessInfo().setError(true); + getProcessInfo().setSummary("@Error@: " + msg); + } break; } addLog(Level.INFO, "Successful application of " + zipFile);