IDEMPIERE-3824 Implement apply packin from folder from command line / improve error messaging and rollback on error

This commit is contained in:
Carlos Ruiz 2019-01-15 18:36:59 +01:00
parent db714f918e
commit 3456ab5b6b
4 changed files with 20 additions and 4 deletions

View File

@ -32,6 +32,7 @@ import org.compiere.Adempiere;
import org.compiere.model.MPInstance; import org.compiere.model.MPInstance;
import org.compiere.process.ProcessCall; import org.compiere.process.ProcessCall;
import org.compiere.process.ProcessInfo; import org.compiere.process.ProcessInfo;
import org.compiere.process.ProcessInfoUtil;
import org.compiere.util.CLogMgt; import org.compiere.util.CLogMgt;
import org.compiere.util.Env; import org.compiere.util.Env;
import org.eclipse.equinox.app.IApplication; import org.eclipse.equinox.app.IApplication;
@ -76,14 +77,19 @@ public class PackInFolderApplication implements IApplication {
instance.createParameter(10, "Folder", directory); instance.createParameter(10, "Folder", directory);
pi.setAD_PInstance_ID(instance.getAD_PInstance_ID()); pi.setAD_PInstance_ID(instance.getAD_PInstance_ID());
ProcessCall process = Core.getProcess("org.adempiere.pipo2.PackInFolder"); 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()) StringBuilder msgout = new StringBuilder("Process=").append(pi.getTitle())
.append(" Error=").append(pi.isError()).append(" Summary=") .append("\n Error=").append(pi.isError())
.append(pi.getSummary()); .append("\n Summary=").append(pi.getSummary())
.append("\n Logs=\n").append(pi.getLogInfo(false).replaceAll("<br>", "\n"));
System.out.println(msgout.toString()); System.out.println(msgout.toString());
if (!success)
return new Integer(1);
} else { } else {
System.out.println("Apply PackIn from Folder usage:"); System.out.println("Apply PackIn from Folder usage:");
System.out.println("RUN_ApplyPackInFromFolder.sh folder"); System.out.println("RUN_ApplyPackInFromFolder.sh folder");
return new Integer(1);
} }

View File

@ -110,6 +110,7 @@ public class PipoDictionaryService implements IDictionaryService {
Trx.get(trxName, false).commit(true); Trx.get(trxName, false).commit(true);
if (logger.isLoggable(Level.INFO)) logger.info("commit " + trxName); if (logger.isLoggable(Level.INFO)) logger.info("commit " + trxName);
} catch (Exception e) { } catch (Exception e) {
Trx.get(trxName, false).rollback();
adPackageImp.setP_Msg(e.getLocalizedMessage()); adPackageImp.setP_Msg(e.getLocalizedMessage());
packIn.getNotifier().addFailureLine(e.getLocalizedMessage()); packIn.getNotifier().addFailureLine(e.getLocalizedMessage());
packIn.setSuccess(false); packIn.setSuccess(false);

View File

@ -159,6 +159,10 @@ public abstract class AbstractActivator implements BundleActivator, ServiceTrack
m_processInfo = processInfo; m_processInfo = processInfo;
} }
public ProcessInfo getProcessInfo() {
return m_processInfo;
}
public void setProcessUI(IProcessUI processUI) { public void setProcessUI(IProcessUI processUI) {
m_processUI = processUI; m_processUI = processUI;
}; };

View File

@ -169,7 +169,12 @@ public class PackInApplicationActivator extends AbstractActivator {
currentFile = zipFile; currentFile = zipFile;
if (!packIn(zipFile)) { if (!packIn(zipFile)) {
// stop processing further packages if one fail // 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; break;
} }
addLog(Level.INFO, "Successful application of " + zipFile); addLog(Level.INFO, "Successful application of " + zipFile);