use of org.compiere.model.MClient in project adempiere by adempiere.
the class MPrintFormat method copy.
// copy
/**
* Copy existing Definition To Client
* @param ctx context
* @param from_AD_PrintFormat_ID format
* @param to_AD_PrintFormat_ID to format or 0 for new
* @param to_Client_ID to client (ignored, if to_AD_PrintFormat_ID <> 0)
* @return print format
*/
private static MPrintFormat copy(Properties ctx, int from_AD_PrintFormat_ID, int to_AD_PrintFormat_ID, int to_Client_ID) {
MClient company = MClient.get(ctx);
s_log.info("From AD_PrintFormat_ID=" + from_AD_PrintFormat_ID + ", To AD_PrintFormat_ID=" + to_AD_PrintFormat_ID + ", To Client_ID=" + to_Client_ID);
if (from_AD_PrintFormat_ID == 0)
throw new IllegalArgumentException("From_AD_PrintFormat_ID is 0");
//
MPrintFormat from = new MPrintFormat(ctx, from_AD_PrintFormat_ID, null);
// could be 0
MPrintFormat to = new MPrintFormat(ctx, to_AD_PrintFormat_ID, null);
MPrintFormat.copyValues(from, to);
// New
if (to_AD_PrintFormat_ID == 0) {
if (to_Client_ID < 0)
to_Client_ID = Env.getAD_Client_ID(ctx);
to.setClientOrg(to_Client_ID, 0);
}
//Set Name - Remove TEMPLATE
to.setName(company.getValue() + " -> " + Util.replace(to.getName(), "** TEMPLATE **", "").trim());
String sql = "SELECT count(*) from AD_PrintFormat WHERE AD_Client_ID = ? AND AD_Table_ID = ? AND Name = ?";
String suggestedName = to.getName();
int count = 0;
while (DB.getSQLValue(to.get_TrxName(), sql, to.getAD_Client_ID(), to.getAD_Table_ID(), suggestedName) > 0) {
count++;
suggestedName = to.getName() + " (" + count + ")";
}
to.setName(suggestedName);
//
to.saveEx();
// Copy Items
to.setItems(copyItems(from, to));
return to;
}
use of org.compiere.model.MClient in project adempiere by adempiere.
the class TranslationDocSync method doIt.
// prepare
/**
* Perform process.
* @return Message
* @throws Exception
*/
protected String doIt() throws Exception {
MClient client = MClient.get(getCtx());
if (client.isMultiLingualDocument())
throw new AdempiereUserError("@AD_Client_ID@: @IsMultiLingualDocument@");
//
log.info("" + client);
String sql = "SELECT * FROM AD_Table " + "WHERE TableName LIKE '%_Trl' AND TableName NOT LIKE 'AD%' " + "ORDER BY TableName";
PreparedStatement pstmt = null;
ResultSet rs = null;
try {
pstmt = DB.prepareStatement(sql, get_TrxName());
rs = pstmt.executeQuery();
while (rs.next()) {
processTable(new MTable(getCtx(), rs, null), client.getAD_Client_ID());
}
} catch (Exception e) {
log.log(Level.SEVERE, sql, e);
} finally {
DB.close(rs, pstmt);
rs = null;
pstmt = null;
}
return "OK";
}
use of org.compiere.model.MClient in project adempiere by adempiere.
the class WebEnv method initWeb.
// initWeb
/**
* Init Web.
* Only call directly for Filters, etc.
* @param context servlet context
* @return false if initialization problems
*/
public static boolean initWeb(ServletContext context) {
if (s_initOK) {
log.info(context.getServletContextName());
return true;
}
// Load Environment Variables (serverApps/src/web/WEB-INF/web.xml)
Enumeration en = context.getInitParameterNames();
StringBuffer info = new StringBuffer("Servlet Context Init Parameters: ").append(context.getServletContextName());
while (en.hasMoreElements()) {
String name = en.nextElement().toString();
String value = context.getInitParameter(name);
System.setProperty(name, value);
info.append("\n").append(name).append("=").append(value);
}
try {
s_initOK = Adempiere.startup(false);
} catch (Exception ex) {
log.log(Level.SEVERE, "startup", ex);
}
if (!s_initOK)
return false;
// Logging now initiated
log.info(info.toString());
//
Properties ctx = new Properties();
MClient client = MClient.get(ctx, 0);
MSystem system = MSystem.get(ctx);
client.sendEMail(client.getRequestEMail(), "Server started: " + system.getName(), "ServerInfo: " + context.getServerInfo(), null);
return s_initOK;
}
use of org.compiere.model.MClient in project adempiere by adempiere.
the class MobileEnv method initWeb.
// initWeb
/**
* Init Web.
* Only call directly for Filters, etc.
* @param context servlet context
* @return false if initialization problems
*/
public static boolean initWeb(ServletContext context) {
if (s_initOK) {
log.info(context.getServletContextName());
return true;
}
// Load Environment Variables (serverApps/src/web/WEB-INF/web.xml)
Enumeration en = context.getInitParameterNames();
StringBuffer info = new StringBuffer("Servlet Context Init Parameters: ").append(context.getServletContextName());
while (en.hasMoreElements()) {
String name = en.nextElement().toString();
String value = context.getInitParameter(name);
System.setProperty(name, value);
info.append("\n").append(name).append("=").append(value);
}
try {
s_initOK = Adempiere.startup(false);
} catch (Exception ex) {
log.log(Level.SEVERE, "startup", ex);
}
if (!s_initOK)
return false;
// Logging now initiated
log.info(info.toString());
//
Properties ctx = new Properties();
MClient client = MClient.get(ctx, 0);
MSystem system = MSystem.get(ctx);
return s_initOK;
}
use of org.compiere.model.MClient in project adempiere by adempiere.
the class MobileSessionCtx method getDefaults.
// setWStore
/**
* Get Web Store Defaults
* @return context
*/
private Properties getDefaults() {
// No Web Store
if (wstore == null)
return new Properties();
//
Integer key = new Integer(wstore.getW_Store_ID());
Properties newCtx = (Properties) s_cacheCtx.get(key);
/** Create New Context */
if (newCtx == null) {
log.info(wstore.getWebContext());
newCtx = new Properties();
// copy explicitly
Enumeration e = ctx.keys();
while (e.hasMoreElements()) {
String pKey = (String) e.nextElement();
newCtx.setProperty(pKey, ctx.getProperty(pKey));
}
Env.setContext(newCtx, "#AD_Client_ID", wstore.getAD_Client_ID());
Env.setContext(newCtx, "#AD_Org_ID", wstore.getAD_Org_ID());
//
Env.setContext(newCtx, "#SalesRep_ID", wstore.getSalesRep_ID());
Env.setContext(newCtx, "#M_PriceList_ID", wstore.getM_PriceList_ID());
Env.setContext(newCtx, "#M_Warehouse_ID", wstore.getM_Warehouse_ID());
//
String s = wstore.getWebParam1();
Env.setContext(newCtx, "webParam1", s == null ? "" : s);
s = wstore.getWebParam2();
Env.setContext(newCtx, "webParam2", s == null ? "" : s);
s = wstore.getWebParam3();
Env.setContext(newCtx, "webParam3", s == null ? "" : s);
s = wstore.getWebParam4();
Env.setContext(newCtx, "webParam4", s == null ? "" : s);
s = wstore.getWebParam5();
Env.setContext(newCtx, "webParam5", s == null ? "" : s);
s = wstore.getWebParam6();
Env.setContext(newCtx, "webParam6", s == null ? "" : s);
s = wstore.getStylesheet();
if (s == null)
s = "standard";
else {
int index = s.lastIndexOf('.');
if (index != -1)
s = s.substring(0, index);
}
Env.setContext(newCtx, "Stylesheet", s);
//
s = wstore.getWebInfo();
if (s != null && s.length() > 0)
Env.setContext(newCtx, HDR_INFO, s);
// Payment Term
Env.setContext(newCtx, "#M_PriceList_ID", wstore.getM_PriceList_ID());
// Default User - SalesRep
if (Env.getContextAsInt(newCtx, "#AD_User_ID") == 0)
Env.setContext(newCtx, "#AD_User_ID", wstore.getSalesRep_ID());
// Default Role for access
if (Env.getContextAsInt(newCtx, "#AD_Role_ID") == 0) {
// HARDCODED - System
int AD_Role_ID = 0;
Env.setContext(newCtx, "#AD_Role_ID", AD_Role_ID);
}
// Client
MClient client = MClient.get(newCtx, wstore.getAD_Client_ID());
// Name,Description, SMTPHost,RequestEMail,RequestUser, RequestUserPw
Env.setContext(newCtx, "name", client.getName());
Env.setContext(newCtx, "description", client.getDescription());
// AD_Language
if (newCtx.getProperty("#AD_Language") == null && client.getAD_Language() != null)
Env.setContext(newCtx, "#AD_Language", client.getAD_Language());
// DocumentDir
String docDir = client.getDocumentDir();
Env.setContext(newCtx, CTX_DOCUMENT_DIR, docDir == null ? "" : docDir);
// Default Language
if (newCtx.getProperty("#AD_Language") == null)
Env.setContext(newCtx, "#AD_Language", "en_US");
// Save Context - Key is AD_Client_ID
s_cacheCtx.put(key, newCtx);
}
// return new Properties (pp); seems not to work with JSP
Enumeration e = newCtx.keys();
while (e.hasMoreElements()) {
String pKey = (String) e.nextElement();
ctx.setProperty(pKey, newCtx.getProperty(pKey));
}
return ctx;
}
Aggregations