Merge f182e5092cc5

This commit is contained in:
Heng Sin Low 2013-03-01 15:30:58 +08:00
commit f68ac8d544
6 changed files with 204 additions and 7 deletions

View File

@ -24,6 +24,7 @@ import java.math.BigDecimal;
import java.sql.CallableStatement; import java.sql.CallableStatement;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.util.Properties; import java.util.Properties;
import java.util.UUID;
import java.util.logging.Level; import java.util.logging.Level;
import javax.script.ScriptEngine; import javax.script.ScriptEngine;
@ -159,9 +160,53 @@ public final class ProcessUtil {
process = Core.getProcess(className); process = Core.getProcess(className);
if (process == null) { 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; 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; boolean success = false;
try try
@ -223,7 +268,7 @@ public final class ProcessUtil {
// now add the method arguments to the engine // now add the method arguments to the engine
engine.put(MRule.ARGUMENTS_PREFIX + "Ctx", ctx); engine.put(MRule.ARGUMENTS_PREFIX + "Ctx", ctx);
if (trx == null) 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 + "Trx", trx);
engine.put(MRule.ARGUMENTS_PREFIX + "TrxName", trx.getTrxName()); engine.put(MRule.ARGUMENTS_PREFIX + "TrxName", trx.getTrxName());
engine.put(MRule.ARGUMENTS_PREFIX + "Record_ID", pi.getRecord_ID()); engine.put(MRule.ARGUMENTS_PREFIX + "Record_ID", pi.getRecord_ID());

View File

@ -26,6 +26,7 @@ import java.util.Properties;
import javax.script.ScriptEngine; import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager; import javax.script.ScriptEngineManager;
import org.compiere.Adempiere;
import org.compiere.util.CCache; import org.compiere.util.CCache;
import org.compiere.util.CLogger; import org.compiere.util.CLogger;
import org.compiere.util.Msg; import org.compiere.util.Msg;
@ -195,7 +196,7 @@ public class MRule extends X_AD_Rule
* @return ScriptEngine * @return ScriptEngine
*/ */
public ScriptEngine getScriptEngine() { public ScriptEngine getScriptEngine() {
factory = new ScriptEngineManager(); factory = new ScriptEngineManager(Adempiere.class.getClassLoader());
String engineName = getEngineName(); String engineName = getEngineName();
if (engineName != null) if (engineName != null)
engine = factory.getEngineByName(getEngineName()); engine = factory.getEngineByName(getEngineName());

View File

@ -176,6 +176,10 @@
class="org.adempiere.pipo2.handler.GenericPOElementHandler" class="org.adempiere.pipo2.handler.GenericPOElementHandler"
id="table.genericHandler"> id="table.genericHandler">
</handler> </handler>
<handler
class="org.adempiere.pipo2.handler.ModelValidatorElementHandler"
id="AD_ModelValidator">
</handler>
</extension> </extension>
</plugin> </plugin>

View File

@ -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 List<Integer>validators = new ArrayList<Integer>();
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<String> 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<String> 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<String> 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);
}
}

View File

@ -31,6 +31,7 @@ import org.compiere.model.I_AD_Form;
import org.compiere.model.I_AD_ImpFormat; import org.compiere.model.I_AD_ImpFormat;
import org.compiere.model.I_AD_Menu; import org.compiere.model.I_AD_Menu;
import org.compiere.model.I_AD_Message; 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_PrintFormat;
import org.compiere.model.I_AD_Process; import org.compiere.model.I_AD_Process;
import org.compiere.model.I_AD_Reference; import org.compiere.model.I_AD_Reference;
@ -186,7 +187,8 @@ public class PackOutProcess extends SvrProcess
return I_AD_Window.Table_Name; return I_AD_Window.Table_Name;
else if (X_AD_Package_Exp_Detail.TYPE_Workflow.equals(type)) else if (X_AD_Package_Exp_Detail.TYPE_Workflow.equals(type))
return I_AD_Workflow.Table_Name; 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; return type;
} }

View File

@ -116,11 +116,11 @@ public class WProcessInfo extends ProcessInfo {
//try append W prefix to class name //try append W prefix to class name
if (zkName == null) if (zkName == null)
{ {
try {
int lastdot = className.lastIndexOf("."); int lastdot = className.lastIndexOf(".");
zkName = className.substring(0, lastdot) + ".W" + className.substring(lastdot+1); zkName = className.substring(0, lastdot) + ".W" + className.substring(lastdot+1);
try {
this.getClass().getClassLoader().loadClass(zkName); this.getClass().getClassLoader().loadClass(zkName);
} catch (ClassNotFoundException e) { } catch (Exception e) {
zkName = null; zkName = null;
} }
} }