diff --git a/org.adempiere.base/src/org/adempiere/util/ProcessUtil.java b/org.adempiere.base/src/org/adempiere/util/ProcessUtil.java index f3cec3714f..da0f39d49e 100644 --- a/org.adempiere.base/src/org/adempiere/util/ProcessUtil.java +++ b/org.adempiere.base/src/org/adempiere/util/ProcessUtil.java @@ -24,6 +24,7 @@ import java.math.BigDecimal; import java.sql.CallableStatement; import java.sql.ResultSet; import java.util.Properties; +import java.util.UUID; import java.util.logging.Level; import javax.script.ScriptEngine; @@ -159,8 +160,52 @@ public final class ProcessUtil { process = Core.getProcess(className); if (process == null) { - pi.setSummary("Failed to create new process instance for " + className, true); + //Get Class + Class processClass = null; + //use context classloader if available + ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); + if (classLoader != null) + { + try + { + processClass = classLoader.loadClass(className); + } + catch (ClassNotFoundException ex) + { + log.log(Level.FINE, className, ex); + } + } + if (processClass == null) + { + classLoader = ProcessUtil.class.getClassLoader(); + try + { + processClass = classLoader.loadClass(className); + } + catch (ClassNotFoundException ex) + { + log.log(Level.WARNING, className, ex); + pi.setSummary ("ClassNotFound", true); return false; + } + } + + if (processClass == null) { + pi.setSummary("No Instance for " + pi.getClassName(), true); + return false; + } + + //Get Process + try + { + process = (ProcessCall)processClass.newInstance(); + } + catch (Exception ex) + { + log.log(Level.WARNING, "Instance for " + className, ex); + pi.setSummary ("InstanceError", true); + return false; + } } boolean success = false; @@ -223,7 +268,7 @@ public final class ProcessUtil { // now add the method arguments to the engine engine.put(MRule.ARGUMENTS_PREFIX + "Ctx", ctx); if (trx == null) - trx = Trx.get(pi.getTitle()+"_"+pi.getAD_PInstance_ID(), true); + trx = Trx.get(pi.getTitle()+"_"+pi.getAD_PInstance_ID() + "_" + UUID.randomUUID(), true); engine.put(MRule.ARGUMENTS_PREFIX + "Trx", trx); engine.put(MRule.ARGUMENTS_PREFIX + "TrxName", trx.getTrxName()); engine.put(MRule.ARGUMENTS_PREFIX + "Record_ID", pi.getRecord_ID()); diff --git a/org.adempiere.base/src/org/compiere/model/MRule.java b/org.adempiere.base/src/org/compiere/model/MRule.java index bdf7b2adcf..d50ac7a447 100644 --- a/org.adempiere.base/src/org/compiere/model/MRule.java +++ b/org.adempiere.base/src/org/compiere/model/MRule.java @@ -26,6 +26,7 @@ import java.util.Properties; import javax.script.ScriptEngine; import javax.script.ScriptEngineManager; +import org.compiere.Adempiere; import org.compiere.util.CCache; import org.compiere.util.CLogger; import org.compiere.util.Msg; @@ -195,7 +196,7 @@ public class MRule extends X_AD_Rule * @return ScriptEngine */ public ScriptEngine getScriptEngine() { - factory = new ScriptEngineManager(); + factory = new ScriptEngineManager(Adempiere.class.getClassLoader()); String engineName = getEngineName(); if (engineName != null) engine = factory.getEngineByName(getEngineName()); diff --git a/org.adempiere.pipo.handlers/plugin.xml b/org.adempiere.pipo.handlers/plugin.xml index 68b3a3a02c..9341c2796c 100644 --- a/org.adempiere.pipo.handlers/plugin.xml +++ b/org.adempiere.pipo.handlers/plugin.xml @@ -176,6 +176,10 @@ class="org.adempiere.pipo2.handler.GenericPOElementHandler" id="table.genericHandler"> + + diff --git a/org.adempiere.pipo.handlers/src/org/adempiere/pipo2/handler/ModelValidatorElementHandler.java b/org.adempiere.pipo.handlers/src/org/adempiere/pipo2/handler/ModelValidatorElementHandler.java new file mode 100644 index 0000000000..e91ed49a96 --- /dev/null +++ b/org.adempiere.pipo.handlers/src/org/adempiere/pipo2/handler/ModelValidatorElementHandler.java @@ -0,0 +1,145 @@ +package org.adempiere.pipo2.handler; + +import java.util.ArrayList; +import java.util.List; +import java.util.logging.Level; + +import javax.xml.transform.sax.TransformerHandler; + +import org.adempiere.pipo2.AbstractElementHandler; +import org.adempiere.pipo2.Element; +import org.adempiere.pipo2.PIPOContext; +import org.adempiere.pipo2.PackOut; +import org.adempiere.pipo2.PoExporter; +import org.adempiere.pipo2.PoFiller; +import org.adempiere.pipo2.exception.POSaveFailedException; +import org.compiere.model.X_AD_ModelValidator; +import org.compiere.model.X_AD_Package_Imp_Detail; +import org.compiere.util.Env; +import org.xml.sax.SAXException; +import org.xml.sax.helpers.AttributesImpl; + +public class ModelValidatorElementHandler extends AbstractElementHandler{ + + private Listvalidators = new ArrayList(); + + private static final String AD_MODELVALIDATOR = "AD_ModelValidator"; + + @Override + public void startElement(PIPOContext ctx, Element element) throws SAXException { + + String action = null; + + String entitytype = getStringValue(element, "EntityType"); + String name = getStringValue(element, "Name"); + + if (isProcessElement(ctx.ctx, entitytype)) { + + X_AD_ModelValidator validator = findPO(ctx, element); + if (validator == null) { + int id = findIdByColumn(ctx, X_AD_ModelValidator.Table_Name, X_AD_ModelValidator.COLUMNNAME_Name, name, /*ignorecase=*/true); + validator = new X_AD_ModelValidator(ctx.ctx, id, getTrxName(ctx)); + } + List excludes = defaultExcludeList(X_AD_ModelValidator.Table_Name); + if (validator.getAD_ModelValidator_ID() == 0 && isOfficialId(element, "AD_ModelValidator_ID")) + validator.setAD_ModelValidator_ID(getIntValue(element, "AD_ModelValidator_ID")); + + if (validators.contains(validator.getAD_ModelValidator_ID())) { + element.skip = true; + return; + } + + PoFiller pf = new PoFiller(ctx, validator, element, this); + List notfounds = pf.autoFill(excludes); + if (notfounds.size() > 0) { + element.defer = true; + element.unresolved = notfounds.toString(); + return; + } + + if (validator.is_new() || validator.is_Changed()) { + X_AD_Package_Imp_Detail impDetail = createImportDetail(ctx, element.qName, X_AD_ModelValidator.Table_Name, X_AD_ModelValidator.Table_ID); + if (!validator.is_new()) { + backupRecord(ctx, impDetail.getAD_Package_Imp_Detail_ID(), AD_MODELVALIDATOR, validator); + action = "Update"; + } else { + action = "New"; + } + + if (validator.save(getTrxName(ctx)) == true) { + logImportDetail(ctx, impDetail, 1, validator.getName(), + validator.get_ID(), action); + + element.recordId = validator.getAD_ModelValidator_ID(); + + validators.add(validator.getAD_ModelValidator_ID()); + + } else { + logImportDetail(ctx, impDetail, 0, validator.getName(), + validator.get_ID(), action); + throw new POSaveFailedException("Failed to save Model Validator " + validator.getName()); + } + } + } else { + element.skip = true; + } + + } + + @Override + public void endElement(PIPOContext ctx, Element element) throws SAXException { + // TODO Auto-generated method stub + + } + + + + public void create(PIPOContext ctx, TransformerHandler document) throws SAXException { + int ad_modelvalidator_id = Env.getContextAsInt(ctx.ctx, X_AD_ModelValidator.COLUMNNAME_AD_ModelValidator_ID); + + if (validators.contains(ad_modelvalidator_id)) + return; + + validators.add(ad_modelvalidator_id); + + X_AD_ModelValidator validator = new X_AD_ModelValidator(ctx.ctx, ad_modelvalidator_id, null); + + if (ctx.packOut.getFromDate() != null) { + if (validator.getUpdated().compareTo(ctx.packOut.getFromDate()) < 0) { + return; + } + } + + AttributesImpl atts = new AttributesImpl(); + addTypeName(atts, "table"); + document.startElement("", "", "AD_ModelValidator", atts); + createADModelValidatorBinding(ctx, document, validator); + + PackOut packOut = ctx.packOut; + try{ + new CommonTranslationHandler().packOut(packOut,document,null,validator.get_ID()); + } + catch(Exception e) + { + if (log.isLoggable(Level.INFO)) log.info(e.toString()); + } + + document.endElement("", "", "AD_ModelValidator"); + } + + private void createADModelValidatorBinding(PIPOContext ctx, TransformerHandler document, X_AD_ModelValidator validator) { + PoExporter filler = new PoExporter(ctx, document, validator); + if (validator.getAD_ModelValidator_ID() <= PackOut.MAX_OFFICIAL_ID) + filler.add(X_AD_ModelValidator.COLUMNNAME_AD_ModelValidator_ID, new AttributesImpl()); + List excludes = defaultExcludeList(X_AD_ModelValidator.Table_Name); + filler.export(excludes); + } + + @Override + public void packOut(PackOut packout, TransformerHandler packoutHandler, TransformerHandler docHandler, int recordId) throws Exception { + Env.setContext(packout.getCtx().ctx, X_AD_ModelValidator.COLUMNNAME_AD_ModelValidator_ID, recordId); + this.create(packout.getCtx(), packoutHandler); + packout.getCtx().ctx.remove(X_AD_ModelValidator.COLUMNNAME_AD_ModelValidator_ID); + } + +} diff --git a/org.adempiere.pipo/src/org/adempiere/pipo2/PackOutProcess.java b/org.adempiere.pipo/src/org/adempiere/pipo2/PackOutProcess.java index 9642908f9f..f50b0b432d 100644 --- a/org.adempiere.pipo/src/org/adempiere/pipo2/PackOutProcess.java +++ b/org.adempiere.pipo/src/org/adempiere/pipo2/PackOutProcess.java @@ -31,6 +31,7 @@ import org.compiere.model.I_AD_Form; import org.compiere.model.I_AD_ImpFormat; import org.compiere.model.I_AD_Menu; import org.compiere.model.I_AD_Message; +import org.compiere.model.I_AD_ModelValidator; import org.compiere.model.I_AD_PrintFormat; import org.compiere.model.I_AD_Process; import org.compiere.model.I_AD_Reference; @@ -186,7 +187,8 @@ public class PackOutProcess extends SvrProcess return I_AD_Window.Table_Name; else if (X_AD_Package_Exp_Detail.TYPE_Workflow.equals(type)) return I_AD_Workflow.Table_Name; - + else if (X_AD_Package_Exp_Detail.TYPE_ModelValidator.equals(type)) + return I_AD_ModelValidator.Table_Name; return type; } diff --git a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/process/WProcessInfo.java b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/process/WProcessInfo.java index 5f873092e8..350d05bb74 100644 --- a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/process/WProcessInfo.java +++ b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/process/WProcessInfo.java @@ -116,11 +116,11 @@ public class WProcessInfo extends ProcessInfo { //try append W prefix to class name if (zkName == null) { - int lastdot = className.lastIndexOf("."); - zkName = className.substring(0, lastdot) + ".W" + className.substring(lastdot+1); try { + int lastdot = className.lastIndexOf("."); + zkName = className.substring(0, lastdot) + ".W" + className.substring(lastdot+1); this.getClass().getClassLoader().loadClass(zkName); - } catch (ClassNotFoundException e) { + } catch (Exception e) { zkName = null; } }