hg merge release-2.1 (merge release2.1 into development)
This commit is contained in:
commit
839a5370dc
|
@ -0,0 +1,11 @@
|
|||
SET SQLBLANKLINES ON
|
||||
SET DEFINE OFF
|
||||
|
||||
-- IDEMPIERE-2757 Key for M_Storage wrongly defined on dictionary
|
||||
-- Aug 6, 2015 5:28:43 PM COT
|
||||
UPDATE AD_Column SET IsParent='Y', IsUpdateable='N',Updated=TO_DATE('2015-08-06 17:28:43','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Column_ID=210887
|
||||
;
|
||||
|
||||
SELECT register_migration_script('201508061729_IDEMPIERE-2757.sql') FROM dual
|
||||
;
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
-- IDEMPIERE-2757 Key for M_Storage wrongly defined on dictionary
|
||||
-- Aug 6, 2015 5:28:43 PM COT
|
||||
UPDATE AD_Column SET IsParent='Y', IsUpdateable='N',Updated=TO_TIMESTAMP('2015-08-06 17:28:43','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Column_ID=210887
|
||||
;
|
||||
|
||||
SELECT register_migration_script('201508061729_IDEMPIERE-2757.sql') FROM dual
|
||||
;
|
||||
|
|
@ -598,17 +598,29 @@ public class MProduct extends X_M_Product
|
|||
m_precision = null;
|
||||
|
||||
// AttributeSetInstance reset
|
||||
if (is_ValueChanged(COLUMNNAME_M_AttributeSet_ID))
|
||||
if (getM_AttributeSetInstance_ID() > 0 && is_ValueChanged(COLUMNNAME_M_AttributeSet_ID))
|
||||
{
|
||||
MAttributeSetInstance asi = new MAttributeSetInstance(getCtx(), getM_AttributeSetInstance_ID(), get_TrxName());
|
||||
setM_AttributeSetInstance_ID(0);
|
||||
// Delete the old m_attributesetinstance
|
||||
try {
|
||||
asi.deleteEx(true, get_TrxName());
|
||||
} catch (AdempiereException ex)
|
||||
{
|
||||
log.saveError("Error", "Error deleting the AttributeSetInstance");
|
||||
return false;
|
||||
if (asi.getM_AttributeSet_ID() != getM_AttributeSet_ID())
|
||||
setM_AttributeSetInstance_ID(0);
|
||||
}
|
||||
if (!newRecord && is_ValueChanged(COLUMNNAME_M_AttributeSetInstance_ID))
|
||||
{
|
||||
// IDEMPIERE-2752 check if the ASI is referenced in other products before trying to delete it
|
||||
int oldasiid = get_ValueOldAsInt(COLUMNNAME_M_AttributeSetInstance_ID);
|
||||
if (oldasiid > 0) {
|
||||
MAttributeSetInstance oldasi = new MAttributeSetInstance(getCtx(), get_ValueOldAsInt(COLUMNNAME_M_AttributeSetInstance_ID), get_TrxName());
|
||||
int cnt = DB.getSQLValueEx(get_TrxName(), "SELECT COUNT(*) FROM M_Product WHERE M_AttributeSetInstance_ID=?", oldasi.getM_AttributeSetInstance_ID());
|
||||
if (cnt == 1) {
|
||||
// Delete the old m_attributesetinstance
|
||||
try {
|
||||
oldasi.deleteEx(true, get_TrxName());
|
||||
} catch (AdempiereException ex)
|
||||
{
|
||||
log.saveError("Error", "Error deleting the AttributeSetInstance");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1989,6 +1989,7 @@ public abstract class PO
|
|||
*/
|
||||
public boolean save()
|
||||
{
|
||||
checkValidContext();
|
||||
CLogger.resetLast();
|
||||
boolean newRecord = is_new(); // save locally as load resets
|
||||
if (!newRecord && !is_Changed())
|
||||
|
@ -3116,6 +3117,7 @@ public abstract class PO
|
|||
*/
|
||||
public boolean delete (boolean force)
|
||||
{
|
||||
checkValidContext();
|
||||
CLogger.resetLast();
|
||||
if (is_new())
|
||||
return true;
|
||||
|
@ -4701,4 +4703,10 @@ public abstract class PO
|
|||
log.saveError(msg, info);
|
||||
}
|
||||
}
|
||||
|
||||
private void checkValidContext() {
|
||||
if (getCtx().size() == 0)
|
||||
throw new AdempiereException("Context lost");
|
||||
}
|
||||
|
||||
} // PO
|
||||
|
|
|
@ -1616,7 +1616,7 @@ public final class Env
|
|||
String foreignTable = colToken.getReferenceTableName();
|
||||
if (v != null) {
|
||||
if (format != null && format.length() > 0) {
|
||||
if (v instanceof Integer && (Integer) v > 0 && token.endsWith("_ID")) {
|
||||
if (v instanceof Integer && (Integer) v > 0 && !Util.isEmpty(foreignTable)) {
|
||||
int tblIndex = format.indexOf(".");
|
||||
String tableName = null;
|
||||
if (tblIndex > 0)
|
||||
|
|
|
@ -57,8 +57,16 @@ public class PoFiller{
|
|||
return;
|
||||
else if (oldValue != null && oldValue.toString().equals(value))
|
||||
return;
|
||||
else
|
||||
else {
|
||||
if (po instanceof MColumn && "IsToolbarButton".equals(columnName)) {
|
||||
// IDEMPIERE-2064 - backward compatibility with 2packs generated before IDEMPIERE-2477
|
||||
if ("true".equals(value))
|
||||
value ="Y";
|
||||
else if ("false".equals(value))
|
||||
value ="N";
|
||||
}
|
||||
po.set_ValueNoCheck(columnName, value);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -20,12 +20,14 @@ import java.sql.Timestamp;
|
|||
import java.util.Properties;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import org.adempiere.util.ServerContext;
|
||||
import org.compiere.model.AdempiereProcessor;
|
||||
import org.compiere.model.AdempiereProcessor2;
|
||||
import org.compiere.model.AdempiereProcessorLog;
|
||||
import org.compiere.model.MClient;
|
||||
import org.compiere.model.MSchedule;
|
||||
import org.compiere.model.MSystem;
|
||||
import org.compiere.model.PO;
|
||||
import org.compiere.util.CLogger;
|
||||
import org.compiere.util.Env;
|
||||
import org.compiere.util.TimeUtil;
|
||||
|
@ -47,11 +49,9 @@ public abstract class AdempiereServer implements Runnable
|
|||
protected AdempiereServer (AdempiereProcessor model, int initialNap)
|
||||
{
|
||||
p_model = model;
|
||||
m_ctx = new Properties(model.getCtx());
|
||||
if (p_system == null)
|
||||
p_system = MSystem.get(m_ctx);
|
||||
p_client = MClient.get(m_ctx);
|
||||
Env.setContext(m_ctx, "#AD_Client_ID", p_client.getAD_Client_ID());
|
||||
p_system = MSystem.get(model.getCtx());
|
||||
p_client = MClient.get(model.getCtx(), model.getAD_Client_ID());
|
||||
m_initialNap = initialNap;
|
||||
|
||||
Timestamp dateNextRun = getDateNextRun(true);
|
||||
|
@ -89,8 +89,6 @@ public abstract class AdempiereServer implements Runnable
|
|||
|
||||
/** Logger */
|
||||
protected CLogger log = CLogger.getCLogger(getClass());
|
||||
/** Context */
|
||||
private Properties m_ctx = null;
|
||||
/** System */
|
||||
protected volatile static MSystem p_system = null;
|
||||
/** Client */
|
||||
|
@ -102,7 +100,7 @@ public abstract class AdempiereServer implements Runnable
|
|||
*/
|
||||
public Properties getCtx()
|
||||
{
|
||||
return m_ctx;
|
||||
return Env.getCtx();
|
||||
} // getCtx
|
||||
|
||||
/**
|
||||
|
@ -118,12 +116,35 @@ public abstract class AdempiereServer implements Runnable
|
|||
return m_initialNap;
|
||||
}
|
||||
|
||||
public void runNow()
|
||||
{
|
||||
Properties context = new Properties();
|
||||
Env.setContext(context, "#AD_Client_ID", p_model.getAD_Client_ID());
|
||||
if (p_model instanceof PO) {
|
||||
PO po = (PO) p_model;
|
||||
if (po.get_ColumnIndex("AD_Org_ID") >= 0)
|
||||
Env.setContext(context, "#AD_Org_ID", po.get_ValueAsInt("AD_Org_ID"));
|
||||
if (po.get_ColumnIndex("AD_User_ID") >= 0)
|
||||
Env.setContext(context, "#AD_User_ID", po.get_ValueAsInt("AD_User_ID"));
|
||||
}
|
||||
|
||||
Properties prevContext = ServerContext.getCurrentInstance();
|
||||
try {
|
||||
ServerContext.setCurrentInstance(context);
|
||||
m_sleeping = false;
|
||||
doRunNow();
|
||||
} finally {
|
||||
ServerContext.dispose();
|
||||
ServerContext.setCurrentInstance(prevContext);
|
||||
m_sleeping = true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Run Now
|
||||
*/
|
||||
public void runNow()
|
||||
public void doRunNow()
|
||||
{
|
||||
m_sleeping = false;
|
||||
p_startWork = System.currentTimeMillis();
|
||||
doWork();
|
||||
long now = System.currentTimeMillis();
|
||||
|
@ -138,13 +159,9 @@ public abstract class AdempiereServer implements Runnable
|
|||
//
|
||||
if (log.isLoggable(Level.FINE))
|
||||
log.fine(getStatistics());
|
||||
m_sleeping = true;
|
||||
} // runNow
|
||||
|
||||
/**************************************************************************
|
||||
* Run async
|
||||
*/
|
||||
public void run ()
|
||||
public void run()
|
||||
{
|
||||
final Thread currentThread = Thread.currentThread();
|
||||
final String oldThreadName = currentThread.getName();
|
||||
|
@ -157,7 +174,35 @@ public abstract class AdempiereServer implements Runnable
|
|||
} catch (SecurityException e) {}
|
||||
}
|
||||
|
||||
m_sleeping = false;
|
||||
Properties context = new Properties();
|
||||
Env.setContext(context, "#AD_Client_ID", p_model.getAD_Client_ID());
|
||||
if (p_model instanceof PO) {
|
||||
PO po = (PO) p_model;
|
||||
if (po.get_ColumnIndex("AD_Org_ID") >= 0)
|
||||
Env.setContext(context, "#AD_Org_ID", po.get_ValueAsInt("AD_Org_ID"));
|
||||
if (po.get_ColumnIndex("AD_User_ID") >= 0)
|
||||
Env.setContext(context, "#AD_User_ID", po.get_ValueAsInt("AD_User_ID"));
|
||||
}
|
||||
|
||||
try {
|
||||
ServerContext.setCurrentInstance(context);
|
||||
m_sleeping = false;
|
||||
doRun();
|
||||
} finally {
|
||||
m_sleeping = true;
|
||||
ServerContext.dispose();
|
||||
if (renamed) {
|
||||
// Revert the name back if the current thread was renamed.
|
||||
// We do not check the exception here because we know it works.
|
||||
currentThread.setName(oldThreadName);
|
||||
}
|
||||
}
|
||||
}
|
||||
/**************************************************************************
|
||||
* Run async
|
||||
*/
|
||||
protected void doRun()
|
||||
{
|
||||
if (m_start == 0)
|
||||
m_start = System.currentTimeMillis();
|
||||
|
||||
|
@ -192,12 +237,6 @@ public abstract class AdempiereServer implements Runnable
|
|||
p_model.setDateLastRun(lastRun);
|
||||
p_model.setDateNextRun(new Timestamp(m_nextWork));
|
||||
p_model.saveEx();
|
||||
m_sleeping = true;
|
||||
if (renamed) {
|
||||
// Revert the name back if the current thread was renamed.
|
||||
// We do not check the exception here because we know it works.
|
||||
currentThread.setName(oldThreadName);
|
||||
}
|
||||
} // run
|
||||
|
||||
/**
|
||||
|
|
|
@ -27,10 +27,8 @@ import java.text.SimpleDateFormat;
|
|||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
import java.util.List;
|
||||
import java.util.Properties;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import org.adempiere.util.ServerContext;
|
||||
import org.compiere.model.MAttachment;
|
||||
import org.compiere.model.MClient;
|
||||
import org.compiere.model.MMailText;
|
||||
|
@ -84,9 +82,6 @@ public class Scheduler extends AdempiereServer
|
|||
/** Transaction */
|
||||
protected Trx m_trx = null;
|
||||
|
||||
// ctx for the report/process
|
||||
protected Properties m_schedulerctx = new Properties();
|
||||
|
||||
/**
|
||||
* Work
|
||||
*/
|
||||
|
@ -96,29 +91,27 @@ public class Scheduler extends AdempiereServer
|
|||
.append(" - ");
|
||||
|
||||
// Prepare a ctx for the report/process - BF [1966880]
|
||||
m_schedulerctx.clear();
|
||||
MClient schedclient = MClient.get(getCtx(), m_model.getAD_Client_ID());
|
||||
Env.setContext(m_schedulerctx, "#AD_Client_ID", schedclient.getAD_Client_ID());
|
||||
Env.setContext(m_schedulerctx, "#AD_Language", schedclient.getAD_Language());
|
||||
Env.setContext(m_schedulerctx, "#AD_Org_ID", m_model.getAD_Org_ID());
|
||||
Env.setContext(getCtx(), "#AD_Client_ID", schedclient.getAD_Client_ID());
|
||||
Env.setContext(getCtx(), "#AD_Language", schedclient.getAD_Language());
|
||||
Env.setContext(getCtx(), "#AD_Org_ID", m_model.getAD_Org_ID());
|
||||
if (m_model.getAD_Org_ID() != 0) {
|
||||
MOrgInfo schedorg = MOrgInfo.get(getCtx(), m_model.getAD_Org_ID(), null);
|
||||
if (schedorg.getM_Warehouse_ID() > 0)
|
||||
Env.setContext(m_schedulerctx, "#M_Warehouse_ID", schedorg.getM_Warehouse_ID());
|
||||
Env.setContext(getCtx(), "#M_Warehouse_ID", schedorg.getM_Warehouse_ID());
|
||||
}
|
||||
Env.setContext(m_schedulerctx, "#AD_User_ID", getAD_User_ID());
|
||||
Env.setContext(m_schedulerctx, "#SalesRep_ID", getAD_User_ID());
|
||||
Env.setContext(getCtx(), "#AD_User_ID", getAD_User_ID());
|
||||
Env.setContext(getCtx(), "#SalesRep_ID", getAD_User_ID());
|
||||
// TODO: It can be convenient to add AD_Scheduler.AD_Role_ID
|
||||
MUser scheduser = MUser.get(getCtx(), getAD_User_ID());
|
||||
MRole[] schedroles = scheduser.getRoles(m_model.getAD_Org_ID());
|
||||
if (schedroles != null && schedroles.length > 0)
|
||||
Env.setContext(m_schedulerctx, "#AD_Role_ID", schedroles[0].getAD_Role_ID()); // first role, ordered by AD_Role_ID
|
||||
Env.setContext(getCtx(), "#AD_Role_ID", schedroles[0].getAD_Role_ID()); // first role, ordered by AD_Role_ID
|
||||
Timestamp ts = new Timestamp(System.currentTimeMillis());
|
||||
SimpleDateFormat dateFormat4Timestamp = new SimpleDateFormat("yyyy-MM-dd");
|
||||
Env.setContext(m_schedulerctx, "#Date", dateFormat4Timestamp.format(ts)+" 00:00:00" ); // JDBC format
|
||||
ServerContext.setCurrentInstance(m_schedulerctx);
|
||||
Env.setContext(getCtx(), "#Date", dateFormat4Timestamp.format(ts)+" 00:00:00" ); // JDBC format
|
||||
|
||||
MProcess process = new MProcess(m_schedulerctx, m_model.getAD_Process_ID(), null);
|
||||
MProcess process = new MProcess(getCtx(), m_model.getAD_Process_ID(), null);
|
||||
try
|
||||
{
|
||||
m_trx = Trx.get(Trx.createTrxName("Scheduler"), true);
|
||||
|
@ -138,9 +131,6 @@ public class Scheduler extends AdempiereServer
|
|||
m_trx.close();
|
||||
}
|
||||
|
||||
// clear thread local context
|
||||
ServerContext.dispose();
|
||||
|
||||
//
|
||||
int no = m_model.deleteLog();
|
||||
m_summary.append(" Logs deleted=").append(no);
|
||||
|
@ -162,7 +152,7 @@ public class Scheduler extends AdempiereServer
|
|||
if (log.isLoggable(Level.INFO)) log.info(process.toString());
|
||||
|
||||
boolean isReport = (process.isReport() || process.getAD_ReportView_ID() > 0 || process.getJasperReport() != null || process.getAD_PrintFormat_ID() > 0);
|
||||
String schedulerName = Env.parseContext(m_schedulerctx, -1, m_model.getName(), false, true);
|
||||
String schedulerName = Env.parseContext(getCtx(), -1, m_model.getName(), false, true);
|
||||
|
||||
// Process (see also MWFActivity.performWork
|
||||
int AD_Table_ID = m_model.getAD_Table_ID();
|
||||
|
@ -464,7 +454,7 @@ public class Scheduler extends AdempiereServer
|
|||
String sql = variable.substring(5); // w/o tag
|
||||
//sql = Env.parseContext(m_vo.ctx, m_vo.WindowNo, sql, false, true); // replace variables
|
||||
//hengsin, capture unparseable error to avoid subsequent sql exception
|
||||
sql = Env.parseContext(m_schedulerctx, 0, sql, false, false); // replace variables
|
||||
sql = Env.parseContext(getCtx(), 0, sql, false, false); // replace variables
|
||||
if (sql.equals(""))
|
||||
log.log(Level.WARNING, "(" + sPara.getColumnName() + ") - Default SQL variable parse failed: " + variable);
|
||||
else {
|
||||
|
@ -508,7 +498,7 @@ public class Scheduler extends AdempiereServer
|
|||
String tail=index < (columnName.length()-1) ? columnName.substring(index+1) : null;
|
||||
columnName = columnName.substring(0, index);
|
||||
// try Env
|
||||
String env = Env.getContext(m_schedulerctx, columnName);
|
||||
String env = Env.getContext(getCtx(), columnName);
|
||||
if (env == null || env.length() == 0)
|
||||
env = Env.getContext(getCtx(), columnName);
|
||||
if (env.length() == 0)
|
||||
|
|
|
@ -253,7 +253,8 @@ public class WPAttributeDialog extends Window implements EventListener<Event>
|
|||
|
||||
MAttributeSet as = null;
|
||||
|
||||
if (m_M_Product_ID != 0)
|
||||
int M_AttributeSet_ID = Env.getContextAsInt(Env.getCtx(), m_WindowNoParent, "M_AttributeSet_ID");
|
||||
if (m_M_Product_ID != 0 && M_AttributeSet_ID == 0)
|
||||
{
|
||||
// Get Model
|
||||
m_masi = MAttributeSetInstance.get(Env.getCtx(), m_M_AttributeSetInstance_ID, m_M_Product_ID);
|
||||
|
@ -269,7 +270,6 @@ public class WPAttributeDialog extends Window implements EventListener<Event>
|
|||
}
|
||||
else
|
||||
{
|
||||
int M_AttributeSet_ID = Env.getContextAsInt(Env.getCtx(), m_WindowNoParent, "M_AttributeSet_ID");
|
||||
m_masi = new MAttributeSetInstance (Env.getCtx(), m_M_AttributeSetInstance_ID, M_AttributeSet_ID, null);
|
||||
as = m_masi.getMAttributeSet();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue