/******************************************************************************
* Product: Adempiere ERP & CRM Smart Business Solution *
* Copyright (C) 1999-2006 ComPiere, Inc. All Rights Reserved. *
* This program is free software; you can redistribute it and/or modify it *
* under the terms version 2 of the GNU General Public License as published *
* by the Free Software Foundation. This program is distributed in the hope *
* that it will be useful, but WITHOUT ANY WARRANTY; without even the implied *
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
* See the GNU General Public License for more details. *
* You should have received a copy of the GNU General Public License along *
* with this program; if not, write to the Free Software Foundation, Inc., *
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. *
* For the text or an alternative of this public license, you may reach us *
* ComPiere, Inc., 2620 Augustine Dr. #245, Santa Clara, CA 95054, USA *
* or via info@compiere.org or http://www.compiere.org/license.html *
*****************************************************************************/
package org.compiere.util;
import java.beans.Expression;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.net.URL;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Timestamp;
import java.text.DecimalFormat;
import java.text.MessageFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.Properties;
import java.util.Set;
import java.util.logging.Level;
import javax.swing.ImageIcon;
import org.adempiere.base.Core;
import org.adempiere.base.IResourceFinder;
import org.adempiere.util.IProcessUI;
import org.adempiere.util.ServerContext;
import org.adempiere.util.ServerContextProvider;
import org.compiere.Adempiere;
import org.compiere.db.CConnection;
import org.compiere.dbPort.Convert;
import org.compiere.model.GridTab;
import org.compiere.model.GridWindowVO;
import org.compiere.model.MClient;
import org.compiere.model.MColumn;
import org.compiere.model.MQuery;
import org.compiere.model.MRefList;
import org.compiere.model.MRole;
import org.compiere.model.MSequence;
import org.compiere.model.MSession;
import org.compiere.model.MSysConfig;
import org.compiere.model.MTable;
import org.compiere.model.MZoomCondition;
import org.compiere.model.PO;
import org.compiere.process.ProcessInfo;
import org.compiere.process.SvrProcess;
/**
* System Environment and static variables.
*
* @author Jorg Janke
* @version $Id: Env.java,v 1.3 2006/07/30 00:54:36 jjanke Exp $
*
* @author Teo Sarca, www.arhipac.ro
*
BF [ 1619390 ] Use default desktop browser as external browser
*
BF [ 2017987 ] Env.getContext(TAB_INFO) should NOT use global context
*
FR [ 2392044 ] Introduce Env.WINDOW_MAIN
*/
public final class Env
{
//Environments Constants
public static final String AD_CLIENT_ID = "#AD_Client_ID";
public static final String AD_CLIENT_NAME = "#AD_Client_Name";
public static final String AD_ORG_ID = "#AD_Org_ID";
public static final String AD_ORG_NAME = "#AD_Org_Name";
public static final String AD_PRINTCOLOR_ID = "#AD_PrintColor_ID";
public static final String AD_PRINTFONT_ID = "#AD_PrintFont_ID";
public static final String AD_PRINTPAPER_ID = "#AD_PrintPaper_ID";
public static final String AD_PRINTTABLEFORMAT_ID = "#AD_PrintTableFormat_ID";
public static final String AD_ROLE_ID = "#AD_Role_ID";
public static final String AD_ROLE_NAME = "#AD_Role_Name";
public static final String AD_ROLE_TYPE = "#AD_Role_Type";
public static final String AD_SESSION_ID = "#AD_Session_ID";
public static final String AD_USER_ID = "#AD_User_ID";
public static final String AD_USER_NAME = "#AD_User_Name";
public static final String C_ACCTSCHEMA_ID = "$C_AcctSchema_ID";
public static final String C_BANKACCOUNT_ID = "#C_BankAccount_ID";
public static final String C_BP_GROUP_ID = "#C_BP_Group_ID";
public static final String C_CASHBOOK_ID = "#C_CashBook_ID";
public static final String C_CONVERSIONTYPE_ID = "#C_ConversionType_ID";
public static final String C_COUNTRY_ID = "#C_Country_ID";
public static final String C_CURRENCY_ID = "$C_Currency_ID";
public static final String C_DOCTYPETARGET_ID = "#C_DocTypeTarget_ID";
public static final String C_DUNNING_ID = "#C_Dunning_ID";
public static final String C_PAYMENTTERM_ID = "#C_PaymentTerm_ID";
public static final String C_REGION_ID = "#C_Region_ID";
public static final String C_TAXCATEGORY_ID = "#C_TaxCategory_ID";
public static final String C_TAX_ID = "#C_Tax_ID";
public static final String C_UOM_ID = "#C_UOM_ID";
public static final String CLIENT_INFO_DESKTOP_HEIGHT = "#clientInfo_desktopHeight";
public static final String CLIENT_INFO_DESKTOP_WIDTH = "#clientInfo_desktopWidth";
public static final String CLIENT_INFO_MOBILE = "#clientInfo_mobile";
public static final String CLIENT_INFO_ORIENTATION = "#clientInfo_orientation";
public static final String CLIENT_INFO_TIME_ZONE = "#clientInfo_timeZone";
public static final String DATE = "#Date";
public static final String DB_TYPE = "#DBType";
public static final String GL_CATEGORY_ID = "#GL_Category_ID";
public static final String HAS_ALIAS = "$HasAlias";
public static final String IS_CAN_APPROVE_OWN_DOC = "#IsCanApproveOwnDoc";
public static final String IS_CLIENT_ADMIN = "#IsClientAdmin";
public static final String DEVELOPER_MODE = "#DeveloperMode";
/** Context Language identifier */
public static final String LANGUAGE = "#AD_Language";
public static final String LANGUAGE_NAME = "#LanguageName";
public static final String LOCAL_HTTP_ADDRESS = "#LocalHttpAddr";
public static final String LOCALE = "#Locale";
public static final String M_PRICELIST_ID = "#M_PriceList_ID";
public static final String M_PRODUCT_CATEGORY_ID = "#M_Product_Category_ID";
public static final String M_WAREHOUSE_ID = "#M_Warehouse_ID";
/** Context for multi factor authentication */
public static final String MFA_Registration_ID = "#MFA_Registration_ID";
/** Context for POS ID */
public static final String POS_ID = "#POS_ID";
public static final String R_STATUSCATEGORY_ID = "#R_StatusCategory_ID";
public static final String R_STATUS_ID = "#R_Status_ID";
public static final String RUNNING_UNIT_TESTING_TEST_CASE = "#RUNNING_UNIT_TESTING_TEST_CASE";
public static final String SALESREP_ID = "#SalesRep_ID";
public static final String SHOW_ACCOUNTING = "#ShowAcct";
public static final String SHOW_ADVANCED = "#ShowAdvanced";
public static final String SHOW_TRANSLATION = "#ShowTrl";
public static final String STANDARD_PRECISION = "#StdPrecision";
public static final String STANDARD_REPORT_FOOTER_TRADEMARK_TEXT = "#STANDARD_REPORT_FOOTER_TRADEMARK_TEXT";
public static final String SYSTEM_NAME = "#System_Name";
public static final String UI_CLIENT = "#UIClient";
public static final String USER_LEVEL = "#User_Level";
private static final String PREFIX_SYSTEM_VARIABLE = "$env.";
private final static ContextProvider clientContextProvider = new DefaultContextProvider();
private static List eventListeners = new ArrayList();
public static int adWindowDummyID =200054;
/** Logger */
private static CLogger log = CLogger.getCLogger(Env.class);
/**
* @param provider
* @deprecated
*/
public static void setContextProvider(ContextProvider provider)
{
}
/**
* Add environment event listener
* @param listener
*/
public static void addEventListener(IEnvEventListener listener)
{
eventListeners.add(listener);
}
/**
* Remove environment event listener
* @param listener
* @return boolean
*/
public static boolean removeEventListener(IEnvEventListener listener)
{
return eventListeners.remove(listener);
}
/**
* Exit System
* @param status System exit status (usually 0 for no error)
*/
public static void exitEnv (int status)
{
//hengsin, avoid unncessary query of session when exit without log in
if (DB.isConnected()) {
// End Session
MSession session = MSession.get(Env.getCtx()); // finish
if (session != null) {
session = new MSession(getCtx(), session.getAD_Session_ID(), null);
session.logout();
}
}
//
reset(true); // final cache reset
//
CLogMgt.shutdown();
//
if (Ini.isClient())
System.exit (status);
} // close
/**
* Logout from the system
*/
public static void logout()
{
// End Session
MSession session = MSession.get(Env.getCtx()); // finish
if (session != null) {
session = new MSession(getCtx(), session.getAD_Session_ID(), null);
session.logout();
}
//
reset(true); // final cache reset
//
}
/**
* Reset Cache
* @param finalCall true to clear everything otherwise login data remains
*/
public static void reset (boolean finalCall)
{
IEnvEventListener[] listeners = eventListeners.toArray(new IEnvEventListener[0]);
for(IEnvEventListener listener : listeners)
{
listener.onReset(finalCall);
}
// Clear all Context
if (finalCall)
getCtx().clear();
else // clear window context only
{
Object[] keys = getCtx().keySet().toArray();
for (int i = 0; i < keys.length; i++)
{
String tag = keys[i].toString();
if (Character.isDigit(tag.charAt(0)))
getCtx().remove(keys[i]);
}
}
if (Ini.isClient()) {
DB.closeTarget();
}
// Reset Role Access
if (!finalCall)
{
if (Ini.isClient()) {
// Cache
CacheMgt.get().resetLocalCache();
DB.setDBTarget(CConnection.get());
}
MRole defaultRole = MRole.getDefault(getCtx(), false);
if (defaultRole != null)
defaultRole.loadAccess(true); // Reload
}
} // resetAll
/** Window No for Main */
public static final int WINDOW_MAIN = 0;
/** Tab No for Info */
public static final int TAB_INFO = 1113;
/**
* Get Context
* @return Properties
*/
public static final Properties getCtx()
{
return getContextProvider().getContext();
} // getCtx
/**
* Get context provider
* @return context provider for current environment
*/
public static ContextProvider getContextProvider() {
if (Ini.isClient())
return clientContextProvider;
else
return ServerContextProvider.INSTANCE;
}
/**
* Replace the contents of the current session/process context.
* Don't use this to setup a new session/process context, use ServerContext.setCurrentInstance instead.
* @param ctx context
*/
public static void setCtx (Properties ctx)
{
if (ctx == null)
throw new IllegalArgumentException ("Require Context");
//nothing to do if ctx is already the current context
if (ServerContext.getCurrentInstance() == ctx)
return;
getCtx().clear();
getCtx().putAll(ctx);
} // setCtx
/**
* Set Global Context to Value
* @param ctx context
* @param context context key
* @param value context value
*/
public static void setContext (Properties ctx, String context, String value)
{
if (ctx == null || context == null)
return;
if (log.isLoggable(Level.FINER)) log.finer("Context " + context + "==" + value);
//
if (value == null || value.length() == 0)
ctx.remove(context);
else
ctx.setProperty(context, value);
} // setContext
/**
* Set Global Context to Value
* @param ctx context
* @param context context key
* @param value context value
*/
public static void setContext (Properties ctx, String context, Timestamp value)
{
if (ctx == null || context == null)
return;
if (value == null)
{
ctx.remove(context);
if (log.isLoggable(Level.FINER)) log.finer("Context " + context + "==" + value);
}
else
{ // JDBC Format 2005-05-09 00:00:00.0
// BUG:3075946 KTU, Fix Thai Date
//String stringValue = value.toString();
String stringValue = "";
Calendar c1 = Calendar.getInstance();
c1.setTime(value);
stringValue = DisplayType.getTimestampFormat_Default().format(c1.getTime());
// Chop off .0 (nanos)
//stringValue = stringValue.substring(0, stringValue.indexOf("."));
// KTU
ctx.setProperty(context, stringValue);
if (log.isLoggable(Level.FINER)) log.finer("Context " + context + "==" + stringValue);
}
} // setContext
/**
* Set Global Context to (int) Value
* @param ctx context
* @param context context key
* @param value context value
*/
public static void setContext (Properties ctx, String context, int value)
{
if (ctx == null || context == null)
return;
if (log.isLoggable(Level.FINER)) log.finer("Context " + context + "==" + value);
//
ctx.setProperty(context, String.valueOf(value));
} // setContext
/**
* Set Global Context to Y/N Value
* @param ctx context
* @param context context key
* @param value context value
*/
public static void setContext (Properties ctx, String context, boolean value)
{
setContext (ctx, context, convert(value));
} // setContext
/**
* Set Context for Window to Value
* @param ctx context
* @param WindowNo window no
* @param context context key
* @param value context value
*/
public static void setContext (Properties ctx, int WindowNo, String context, String value)
{
if (ctx == null || context == null)
return;
if (log.isLoggable(Level.FINER)) log.finer("Context("+WindowNo+") " + context + "==" + value);
//
if (value == null || value.equals(""))
ctx.remove(WindowNo+"|"+context);
else
ctx.setProperty(WindowNo+"|"+context, value);
} // setContext
/**
* Set Context for Window to Value
* @param ctx context
* @param WindowNo window no
* @param context context key
* @param value context value
*/
public static void setContext (Properties ctx, int WindowNo, String context, Timestamp value)
{
if (ctx == null || context == null)
return;
if (value == null)
{
ctx.remove(WindowNo+"|"+context);
if (log.isLoggable(Level.FINER)) log.finer("Context("+WindowNo+") " + context + "==" + value);
}
else
{ // JDBC Format 2005-05-09 00:00:00.0
// BUG:3075946 KTU, Fix Thai year
//String stringValue = value.toString();
String stringValue = "";
Calendar c1 = Calendar.getInstance();
c1.setTime(value);
stringValue = DisplayType.getTimestampFormat_Default().format(c1.getTime());
// Chop off .0 (nanos)
//stringValue = stringValue.substring(0, stringValue.indexOf("."));
// KTU
ctx.setProperty(WindowNo+"|"+context, stringValue);
if (log.isLoggable(Level.FINER)) log.finer("Context("+WindowNo+") " + context + "==" + stringValue);
}
} // setContext
/**
* Set Context for Window to int Value
* @param ctx context
* @param WindowNo window no
* @param context context key
* @param value context value
*/
public static void setContext (Properties ctx, int WindowNo, String context, int value)
{
if (ctx == null || context == null)
return;
if (log.isLoggable(Level.FINER)) log.finer("Context("+WindowNo+") " + context + "==" + value);
//
ctx.setProperty(WindowNo+"|"+context, String.valueOf(value));
} // setContext
/**
* Set context value for window and tab
* @param ctx
* @param WindowNo
* @param TabNo
* @param context context key
* @param value context value
*/
public static void setContext (Properties ctx, int WindowNo, int TabNo, String context, int value)
{
if (ctx == null || context == null)
return;
if (log.isLoggable(Level.FINER)) log.finer("Context("+WindowNo+") " + context + "==" + value);
//
ctx.setProperty(WindowNo+"|"+TabNo+"|"+context, String.valueOf(value));
} // setContext
/**
* Set Context for Window to Y/N Value
* @param ctx context
* @param WindowNo window no
* @param context context key
* @param value context value
*/
public static void setContext (Properties ctx, int WindowNo, String context, boolean value)
{
setContext (ctx, WindowNo, context, convert(value));
} // setContext
/**
* Convert boolean value to Y or N
* @param value
* @return Y for true, N for false
*/
private static String convert(boolean value) {
return value ? "Y" : "N";
}
/**
* Set Context for Window and tab to Y/N Value
* @param ctx context
* @param WindowNo window no
* @param TabNo
* @param context context key
* @param value context value
*/
public static void setContext (Properties ctx, int WindowNo, int TabNo, String context, boolean value)
{
setContext (ctx, WindowNo, TabNo, context, convert(value));
} // setContext
/**
* Set Context for Window and Tab to Value
* @param ctx context
* @param WindowNo window no
* @param TabNo tab no
* @param context context key
* @param value context value
* */
public static void setContext (Properties ctx, int WindowNo, int TabNo, String context, String value)
{
if (ctx == null || context == null)
return;
if (log.isLoggable(Level.FINEST)) log.finest("Context("+WindowNo+","+TabNo+") " + context + "==" + value);
//
if (value == null)
if (context.endsWith("_ID"))
// TODO: Research potential problems with tables with Record_ID=0
value = new String("0");
else
value = new String("");
ctx.setProperty(WindowNo+"|"+TabNo+"|"+context, value);
} // setContext
/**
* Set Auto Commit
* @param ctx context
* @param autoCommit auto commit (save)
* @Deprecated user setProperty instead
*/
@Deprecated
public static void setAutoCommit (Properties ctx, boolean autoCommit)
{
if (ctx == null)
return;
ctx.setProperty("AutoCommit", convert(autoCommit));
} // setAutoCommit
/**
* Set Auto Commit for Window
* @param ctx context
* @param WindowNo window no
* @param autoCommit auto commit (save)
*/
public static void setAutoCommit (Properties ctx, int WindowNo, boolean autoCommit)
{
if (ctx == null)
return;
ctx.setProperty(WindowNo+"|AutoCommit", convert(autoCommit));
} // setAutoCommit
/**
* Set Auto New Record
* @param ctx context
* @param autoNew auto new record
* @Deprecated user setProperty instead
*/
@Deprecated
public static void setAutoNew (Properties ctx, boolean autoNew)
{
if (ctx == null)
return;
ctx.setProperty("AutoNew", convert(autoNew));
} // setAutoNew
/**
* Set Auto New Record for Window
* @param ctx context
* @param WindowNo window no
* @param autoNew auto new record
*/
public static void setAutoNew (Properties ctx, int WindowNo, boolean autoNew)
{
if (ctx == null)
return;
ctx.setProperty(WindowNo+"|AutoNew", convert(autoNew));
} // setAutoNew
/**
* Set IsSOTrx Y/N flag
* @param ctx context
* @param isSOTrx SO Context
*/
public static void setSOTrx (Properties ctx, boolean isSOTrx)
{
if (ctx == null)
return;
ctx.setProperty("IsSOTrx", convert(isSOTrx));
} // setSOTrx
/**
* Get global Value of Context
* @param ctx context
* @param context context key
* @return value or ""
*/
public static String getContext (Properties ctx, String context)
{
if (ctx == null || context == null)
throw new IllegalArgumentException ("Require Context");
if (context.startsWith(PREFIX_SYSTEM_VARIABLE)) {
String retValue = System.getenv(context.substring(PREFIX_SYSTEM_VARIABLE.length()));
if (retValue == null)
retValue = "";
return retValue;
}
return ctx.getProperty(context, "");
} // getContext
/**
* Get Value of Context for Window.
* if not found global context if available and enabled
* @param ctx context
* @param WindowNo window
* @param context context key
* @param onlyWindow if true, no defaults are used unless explicitly asked for
* @return value or ""
*/
public static String getContext (Properties ctx, int WindowNo, String context, boolean onlyWindow)
{
if (ctx == null)
throw new IllegalArgumentException ("No Ctx");
if (context == null)
throw new IllegalArgumentException ("Require Context");
String s = ctx.getProperty(WindowNo+"|"+context);
if (s == null)
{
// Explicit Base Values
if (Env.isGlobalVariable(context) || Env.isPreference(context))
return getContext(ctx, context);
if (onlyWindow) // no Default values
return "";
return getContext(ctx, "#" + context);
}
return s;
} // getContext
/**
* Get Value of Context for Window.
* If not found, try global context.
* @param ctx context
* @param WindowNo window
* @param context context key
* @return value or ""
*/
public static String getContext (Properties ctx, int WindowNo, String context)
{
return getContext(ctx, WindowNo, context, false);
} // getContext
/**
* Get Value of Context for Window and Tab.
* If not found, try global context.
* If TabNo is TAB_INFO, only tab's context will be checked.
* @param ctx context
* @param WindowNo window no
* @param TabNo tab no
* @param context context key
* @return value or ""
*/
public static String getContext (Properties ctx, int WindowNo, int TabNo, String context)
{
if (ctx == null || context == null)
throw new IllegalArgumentException ("Require Context");
String s = ctx.getProperty(WindowNo+"|"+TabNo+"|"+context);
// If TAB_INFO, don't check Window and Global context - teo_sarca BF [ 2017987 ]
if (TAB_INFO == TabNo)
return s != null ? s : "";
//
if (Util.isEmpty(s))
return getContext(ctx, WindowNo, context, false);
return s;
} // getContext
/**
* Get Value of Context for Window and Tab.
* If not found, try global context.
* If TabNo is TAB_INFO, only tab's context will be checked.
* @param ctx context
* @param WindowNo window no
* @param TabNo tab no
* @param context context key
* @param onlyTab if true, no window value is searched
* @return value or ""
*/
public static String getContext (Properties ctx, int WindowNo, int TabNo, String context, boolean onlyTab)
{
return getContext(ctx, WindowNo, TabNo, context, onlyTab, onlyTab);
}
/**
* Get Value of Context for Window and Tab.
* If not found, try global context.
* If TabNo is TAB_INFO, only tab's context will be checked.
* @param ctx context
* @param WindowNo window no
* @param TabNo tab no
* @param context context key
* @param onlyTab if true, no window value is searched
* @param onlyWindow if true, no global context will be searched
* @return value or ""
*/
public static String getContext (Properties ctx, int WindowNo, int TabNo, String context, boolean onlyTab, boolean onlyWindow)
{
if (ctx == null || context == null)
throw new IllegalArgumentException ("Require Context");
String s = ctx.getProperty(WindowNo+"|"+TabNo+"|"+context);
//
if (Util.isEmpty(s) && ! onlyTab)
return getContext(ctx, WindowNo, context, onlyWindow);
return s;
} // getContext
/**
* Get Context and convert it to an integer (0 if error)
* @param ctx context
* @param context context key
* @return value
*/
public static int getContextAsInt(Properties ctx, String context)
{
if (ctx == null || context == null)
throw new IllegalArgumentException ("Require Context");
String s = getContext(ctx, context);
if (s.length() == 0)
s = getContext(ctx, 0, context, false); // search 0 and defaults
if (s.length() == 0)
return 0;
//
try
{
return Integer.parseInt(s);
}
catch (NumberFormatException e)
{
log.log(Level.SEVERE, "(" + context + ") = " + s, e);
}
return 0;
} // getContextAsInt
/**
* Get Context and convert it to an integer (0 if error)
* @param ctx context
* @param WindowNo window no
* @param context context key
* @return value or 0
*/
public static int getContextAsInt(Properties ctx, int WindowNo, String context)
{
String s = getContext(ctx, WindowNo, context, false);
if (s.length() == 0)
return 0;
//
try
{
return Integer.parseInt(s);
}
catch (NumberFormatException e)
{
log.log(Level.SEVERE, "(" + context + ") = " + s, e);
}
return 0;
} // getContextAsInt
/**
* Get Context and convert it to an integer (0 if error)
* @param ctx context
* @param WindowNo window no
* @param context context key
* @param onlyWindow if true, do not try global context if context key not found with window
* @return value or 0
*/
public static int getContextAsInt(Properties ctx, int WindowNo, String context, boolean onlyWindow)
{
String s = getContext(ctx, WindowNo, context, onlyWindow);
if (s.length() == 0)
return 0;
//
try
{
return Integer.parseInt(s);
}
catch (NumberFormatException e)
{
log.log(Level.SEVERE, "(" + context + ") = " + s, e);
}
return 0;
} // getContextAsInt
/**
* Get Context and convert it to an integer (0 if error)
* @param ctx context
* @param WindowNo window no
* @param TabNo tab no
* @param context context key
* @return value or 0
*/
public static int getContextAsInt (Properties ctx, int WindowNo, int TabNo, String context)
{
String s = getContext(ctx, WindowNo, TabNo, context);
if (Util.isEmpty(s))
return 0;
//
try
{
return Integer.parseInt(s);
}
catch (NumberFormatException e)
{
log.log(Level.SEVERE, "(" + context + ") = " + s, e);
}
return 0;
} // getContextAsInt
/**
* Is AutoCommit
* @param ctx context
* @return true if auto commit
*/
public static boolean isAutoCommit (Properties ctx)
{
if (ctx == null)
throw new IllegalArgumentException ("Require Context");
String s = getContext(ctx, "AutoCommit");
if (s != null && s.equals("Y"))
return true;
return false;
} // isAutoCommit
/**
* Is Window AutoCommit (if not set use default)
* @param ctx context
* @param WindowNo window no
* @return true if auto commit
*/
public static boolean isAutoCommit (Properties ctx, int WindowNo)
{
if (ctx == null)
throw new IllegalArgumentException ("Require Context");
String s = getContext(ctx, WindowNo, "AutoCommit", false);
if (s != null)
{
if (s.equals("Y"))
return true;
else
return false;
}
return isAutoCommit(ctx);
} // isAutoCommit
/**
* Is Auto New Record
* @param ctx context
* @return true if auto new
*/
public static boolean isAutoNew (Properties ctx)
{
if (ctx == null)
throw new IllegalArgumentException ("Require Context");
String s = getContext(ctx, "AutoNew");
if (s != null && s.equals("Y"))
return true;
return false;
} // isAutoNew
/**
* Is Window Auto New Record (if not set use default)
* @param ctx context
* @param WindowNo window no
* @return true if auto new record
*/
public static boolean isAutoNew (Properties ctx, int WindowNo)
{
if (ctx == null)
throw new IllegalArgumentException ("Require Context");
String s = getContext(ctx, WindowNo, "AutoNew", false);
if (s != null)
{
if (s.equals("Y"))
return true;
else
return false;
}
return isAutoNew(ctx);
} // isAutoNew
/**
* Is Sales Order Trx
* @param ctx context
* @return true if SO (default)
*/
public static boolean isSOTrx (Properties ctx)
{
String s = getContext(ctx, "IsSOTrx");
if (s != null && s.equals("N"))
return false;
return true;
} // isSOTrx
/**
* Is Sales Order Trx
* @param ctx context
* @param WindowNo window no
* @return true if SO (default)
*/
public static boolean isSOTrx (Properties ctx, int WindowNo)
{
String s = getContext(ctx, WindowNo, "IsSOTrx", true);
if (s != null && s.equals("N"))
return false;
return true;
} // isSOTrx
/**
* Get Context and convert it to Timestamp.
* If error return today's date.
* @param ctx context
* @param context context key
* @return Timestamp
*/
public static Timestamp getContextAsDate(Properties ctx, String context)
{
return getContextAsDate(ctx, 0, context);
} // getContextAsDate
/**
* Get Context and convert it to Timestamp.
* If error return today's date.
* @param ctx context
* @param WindowNo window no
* @param context context key
* @return Timestamp
*/
public static Timestamp getContextAsDate(Properties ctx, int WindowNo, String context)
{
if (ctx == null || context == null)
throw new IllegalArgumentException ("Require Context");
String s = getContext(ctx, WindowNo, context, false);
// JDBC Format YYYY-MM-DD example 2000-09-11 00:00:00.0
if (Util.isEmpty(s))
return new Timestamp(System.currentTimeMillis());
// BUG:3075946 KTU - Fix Thai Date
/*
// timestamp requires time
if (s.trim().length() == 10)
s = s.trim() + " 00:00:00.0";
else if (s.indexOf('.') == -1)
s = s.trim() + ".0";
return Timestamp.valueOf(s);*/
Date date = null;
try {
date = DisplayType.getTimestampFormat_Default().parse(s);
} catch (ParseException e) {
e.printStackTrace();
return null;
}
Timestamp timeStampDate = new Timestamp(date.getTime());
return timeStampDate;
// KTU
} // getContextAsDate
/**
* Get Login AD_Client_ID
* @param ctx context
* @return login AD_Client_ID
*/
public static int getAD_Client_ID (Properties ctx)
{
return Env.getContextAsInt(ctx, AD_CLIENT_ID);
} // getAD_Client_ID
/**
* Get Login AD_Org_ID
* @param ctx context
* @return login AD_Org_ID
*/
public static int getAD_Org_ID (Properties ctx)
{
return Env.getContextAsInt(ctx, AD_ORG_ID);
} // getAD_Org_ID
/**
* Get Login AD_User_ID
* @param ctx context
* @return login AD_User_ID
*/
public static int getAD_User_ID (Properties ctx)
{
return Env.getContextAsInt(ctx, AD_USER_ID);
} // getAD_User_ID
/**
* Get Login AD_Role_ID
* @param ctx context
* @return login AD_Role_ID
*/
public static int getAD_Role_ID (Properties ctx)
{
return Env.getContextAsInt(ctx, AD_ROLE_ID);
} // getAD_Role_ID
/**
* Get Preference.
*