Search in sources :

Example 6 with MSystem

use of org.compiere.model.MSystem 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;
}
Also used : Enumeration(java.util.Enumeration) Properties(java.util.Properties) MSystem(org.compiere.model.MSystem) MClient(org.compiere.model.MClient)

Example 7 with MSystem

use of org.compiere.model.MSystem 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;
}
Also used : Enumeration(java.util.Enumeration) Properties(java.util.Properties) MSystem(org.compiere.model.MSystem) MClient(org.compiere.model.MClient)

Example 8 with MSystem

use of org.compiere.model.MSystem in project adempiere by adempiere.

the class RegisterSystem method doIt.

//	prepare
/**
	 * 	DoIt
	 *	@return Message
	 *	@throws Exception
	 */
protected String doIt() throws Exception {
    int AD_Registration_ID = getRecord_ID();
    log.info("doIt - AD_Registration_ID=" + AD_Registration_ID);
    //	Check Ststem
    MSystem sys = MSystem.get(getCtx());
    if (sys.getName().equals("?") || sys.getName().length() < 2)
        throw new AdempiereUserError("Set System Name in System Record");
    if (sys.getUserName().equals("?") || sys.getUserName().length() < 2)
        throw new AdempiereUserError("Set User Name (as in Web Store) in System Record");
    if (sys.getPassword().equals("?") || sys.getPassword().length() < 2)
        throw new AdempiereUserError("Set Password (as in Web Store) in System Record");
    //	Registration
    M_Registration reg = new M_Registration(getCtx(), AD_Registration_ID, get_TrxName());
    //	Location
    MLocation loc = null;
    if (reg.getC_Location_ID() > 0) {
        loc = new MLocation(getCtx(), reg.getC_Location_ID(), get_TrxName());
        if (loc.getCity() == null || loc.getCity().length() < 2)
            throw new AdempiereUserError("No City in Address");
    }
    if (loc == null)
        throw new AdempiereUserError("Please enter Address with City");
    //	Create Query String
    String enc = WebEnv.ENCODING;
    //	Send GET Request
    StringBuffer urlString = new StringBuffer("http://www.adempiere.net").append("/wstore/registrationServlet?");
    //	System Info
    urlString.append("Name=").append(URLEncoder.encode(sys.getName(), enc)).append("&UserName=").append(URLEncoder.encode(sys.getUserName(), enc)).append("&Password=").append(URLEncoder.encode(sys.getPassword(), enc));
    //	Registration Info
    if (reg.getDescription() != null && reg.getDescription().length() > 0)
        urlString.append("&Description=").append(URLEncoder.encode(reg.getDescription(), enc));
    urlString.append("&IsInProduction=").append(reg.isInProduction() ? "Y" : "N");
    if (reg.getStartProductionDate() != null)
        urlString.append("&StartProductionDate=").append(URLEncoder.encode(String.valueOf(reg.getStartProductionDate()), enc));
    urlString.append("&IsAllowPublish=").append(reg.isAllowPublish() ? "Y" : "N").append("&NumberEmployees=").append(URLEncoder.encode(String.valueOf(reg.getNumberEmployees()), enc)).append("&C_Currency_ID=").append(URLEncoder.encode(String.valueOf(reg.getC_Currency_ID()), enc)).append("&SalesVolume=").append(URLEncoder.encode(String.valueOf(reg.getSalesVolume()), enc));
    if (reg.getIndustryInfo() != null && reg.getIndustryInfo().length() > 0)
        urlString.append("&IndustryInfo=").append(URLEncoder.encode(reg.getIndustryInfo(), enc));
    if (reg.getPlatformInfo() != null && reg.getPlatformInfo().length() > 0)
        urlString.append("&PlatformInfo=").append(URLEncoder.encode(reg.getPlatformInfo(), enc));
    urlString.append("&IsRegistered=").append(reg.isRegistered() ? "Y" : "N").append("&Record_ID=").append(URLEncoder.encode(String.valueOf(reg.getRecord_ID()), enc));
    //	Address
    urlString.append("&City=").append(URLEncoder.encode(loc.getCity(), enc)).append("&C_Country_ID=").append(URLEncoder.encode(String.valueOf(loc.getC_Country_ID()), enc));
    //	Statistics
    if (reg.isAllowStatistics()) {
        urlString.append("&NumClient=").append(URLEncoder.encode(String.valueOf(DB.getSQLValue(null, "SELECT Count(*) FROM AD_Client")), enc)).append("&NumOrg=").append(URLEncoder.encode(String.valueOf(DB.getSQLValue(null, "SELECT Count(*) FROM AD_Org")), enc)).append("&NumBPartner=").append(URLEncoder.encode(String.valueOf(DB.getSQLValue(null, "SELECT Count(*) FROM C_BPartner")), enc)).append("&NumUser=").append(URLEncoder.encode(String.valueOf(DB.getSQLValue(null, "SELECT Count(*) FROM AD_User")), enc)).append("&NumProduct=").append(URLEncoder.encode(String.valueOf(DB.getSQLValue(null, "SELECT Count(*) FROM M_Product")), enc)).append("&NumInvoice=").append(URLEncoder.encode(String.valueOf(DB.getSQLValue(null, "SELECT Count(*) FROM C_Invoice")), enc));
    }
    log.fine(urlString.toString());
    //	Send it
    URL url = new URL(urlString.toString());
    StringBuffer sb = new StringBuffer();
    try {
        URLConnection uc = url.openConnection();
        InputStreamReader in = new InputStreamReader(uc.getInputStream());
        int c;
        while ((c = in.read()) != -1) sb.append((char) c);
        in.close();
    } catch (Exception e) {
        log.log(Level.SEVERE, "Connect - " + e.toString());
        throw new IllegalStateException("Cannot connect to Server - Please try later");
    }
    //
    String info = sb.toString();
    log.info("Response=" + info);
    //	Record at the end
    int index = sb.indexOf("Record_ID=");
    if (index != -1) {
        try {
            int Record_ID = Integer.parseInt(sb.substring(index + 10));
            reg.setRecord_ID(Record_ID);
            reg.setIsRegistered(true);
            reg.saveEx();
            //
            info = info.substring(0, index);
        } catch (Exception e) {
            log.log(Level.SEVERE, "Record - ", e);
        }
    }
    return info;
}
Also used : AdempiereUserError(org.compiere.util.AdempiereUserError) InputStreamReader(java.io.InputStreamReader) MSystem(org.compiere.model.MSystem) MLocation(org.compiere.model.MLocation) URL(java.net.URL) URLConnection(java.net.URLConnection) M_Registration(org.compiere.model.M_Registration)

Example 9 with MSystem

use of org.compiere.model.MSystem in project adempiere by adempiere.

the class CompiereUtil method initWeb.

public static boolean initWeb() {
    if (s_initOK) {
        //log.info(context.getServletContextName());
        return true;
    }
    try {
        //CLogMgt.setLevel(Level.OFF);			
        /* ADEMPIERE/COMPIERE */
        //s_initOK = Compiere.startup(false);
        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;
}
Also used : Properties(java.util.Properties) MSystem(org.compiere.model.MSystem) MClient(org.compiere.model.MClient)

Aggregations

MSystem (org.compiere.model.MSystem)9 Properties (java.util.Properties)4 MClient (org.compiere.model.MClient)4 Enumeration (java.util.Enumeration)2 File (java.io.File)1 IOException (java.io.IOException)1 InputStreamReader (java.io.InputStreamReader)1 MemoryMXBean (java.lang.management.MemoryMXBean)1 RuntimeMXBean (java.lang.management.RuntimeMXBean)1 ThreadMXBean (java.lang.management.ThreadMXBean)1 URL (java.net.URL)1 URLConnection (java.net.URLConnection)1 PreparedStatement (java.sql.PreparedStatement)1 ResultSet (java.sql.ResultSet)1 SQLException (java.sql.SQLException)1 Timestamp (java.sql.Timestamp)1 UnavailableServiceException (javax.jnlp.UnavailableServiceException)1 DBException (org.adempiere.exceptions.DBException)1 org.apache.ecs.xhtml.a (org.apache.ecs.xhtml.a)1 org.apache.ecs.xhtml.b (org.apache.ecs.xhtml.b)1