Search in sources :

Example 1 with MSystem

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

the class Adempiere method startupEnvironment.

//  startup
/**
	 * 	Startup Adempiere Environment.
	 * 	Automatically called for Server connections
	 * 	For testing call this method.
	 *	@param isClient true if client connection
	 *  @return successful startup
	 */
public static boolean startupEnvironment(boolean isClient) {
    //	returns if already initiated
    startup(isClient);
    if (!DB.isConnected()) {
        log.severe("No Database");
        return false;
    }
    //	Initializes Base Context too
    MSystem system = MSystem.get(Env.getCtx());
    if (system == null)
        return false;
    //	Initialize main cached Singletons
    ModelValidationEngine.get();
    try {
        String className = system.getEncryptionKey();
        if (className == null || className.length() == 0) {
            className = System.getProperty(SecureInterface.ADEMPIERE_SECURE);
            if (className != null && className.length() > 0 && !className.equals(SecureInterface.ADEMPIERE_SECURE_DEFAULT)) {
                //	test it
                SecureEngine.init(className);
                system.setEncryptionKey(className);
                system.save();
            }
        }
        SecureEngine.init(className);
        //
        if (isClient)
            //	Login Client loaded later
            MClient.get(Env.getCtx(), 0);
        else
            MClient.getAll(Env.getCtx());
    } catch (Exception e) {
        log.warning("Environment problems: " + e.toString());
    }
    //	Start Workflow Document Manager (in other package) for PO
    String className = null;
    try {
        className = "org.compiere.wf.DocWorkflowManager";
        Class.forName(className);
        //	Initialize Archive Engine
        className = "org.compiere.print.ArchiveEngine";
        Class.forName(className);
    } catch (Exception e) {
        log.warning("Not started: " + className + " - " + e.getMessage());
    }
    if (!isClient)
        DB.updateMail();
    return true;
}
Also used : MSystem(org.compiere.model.MSystem) UnavailableServiceException(javax.jnlp.UnavailableServiceException) IOException(java.io.IOException)

Example 2 with MSystem

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

the class AdempiereMonitor method createLogMgtPage.

//	createSummaryPage
/**
	 * 	Add Log Management to page
	 *	@param bb body
	 */
private void createLogMgtPage(body bb) {
    bb.addElement(new hr());
    //	Ini Parameters
    table table = new table();
    table.setBorder(1);
    table.setCellSpacing(2);
    table.setCellPadding(2);
    //
    Properties ctx = new Properties();
    MSystem system = MSystem.get(ctx);
    tr line = new tr();
    line.addElement(new th().addElement(system.getDBAddress()));
    line.addElement(new td().addElement(Ini.getAdempiereHome()));
    table.addElement(line);
    //	OS + Name
    line = new tr();
    String info = System.getProperty("os.name") + " " + System.getProperty("os.version");
    String s = System.getProperty("sun.os.patch.level");
    if (s != null && s.length() > 0)
        info += " (" + s + ")";
    line.addElement(new th().addElement(info));
    info = system.getName();
    if (system.getCustomPrefix() != null)
        info += " (" + system.getCustomPrefix() + ")";
    line.addElement(new td().addElement(info));
    table.addElement(line);
    //	Java + email
    line = new tr();
    info = System.getProperty("java.vm.name") + " " + System.getProperty("java.vm.version");
    line.addElement(new th().addElement(info));
    line.addElement(new td().addElement(system.getUserName()));
    table.addElement(line);
    //	DB + Instance
    line = new tr();
    CConnection cc = CConnection.get();
    AdempiereDatabase db = cc.getDatabase();
    info = db.getDescription();
    line.addElement(new th().addElement(info));
    line.addElement(new td().addElement(cc.getConnectionURL()));
    //		line.addElement(new td().addElement(system.getDBInstance()));
    table.addElement(line);
    //	Processors/Support
    line = new tr();
    line.addElement(new th().addElement("Processor/Support"));
    line.addElement(new td().addElement(system.getNoProcessors() + "/" + system.getSupportUnits()));
    table.addElement(line);
    //	Memory
    line = new tr();
    MemoryMXBean memory = ManagementFactory.getMemoryMXBean();
    line.addElement(new th().addElement("VM Memory"));
    line.addElement(new td().addElement(new CMemoryUsage(memory.getNonHeapMemoryUsage()).toString()));
    table.addElement(line);
    line = new tr();
    line.addElement(new th().addElement("Heap Memory"));
    line.addElement(new td().addElement(new CMemoryUsage(memory.getHeapMemoryUsage()).toString()));
    table.addElement(line);
    //	Runtime
    line = new tr();
    RuntimeMXBean rt = ManagementFactory.getRuntimeMXBean();
    line.addElement(new th().addElement("Runtime " + rt.getName()));
    line.addElement(new td().addElement(TimeUtil.formatElapsed(rt.getUptime())));
    table.addElement(line);
    //	Threads
    line = new tr();
    ThreadMXBean th = ManagementFactory.getThreadMXBean();
    line.addElement(new th().addElement("Threads " + th.getThreadCount()));
    line.addElement(new td().addElement("Peak=" + th.getPeakThreadCount() + ", Demons=" + th.getDaemonThreadCount() + ", Total=" + th.getTotalStartedThreadCount()));
    table.addElement(line);
    //Transactions
    Trx[] trxs = Trx.getActiveTransactions();
    for (Trx trx : trxs) {
        if (trx != null && trx.isActive()) {
            line = new tr();
            line.addElement(new th().addElement("Active Transaction "));
            line.addElement(new td().addElement("Name=" + trx.getTrxName() + ", StartTime=" + trx.getStartTime()));
            table.addElement(line);
        }
    }
    //	Cache Reset
    line = new tr();
    line.addElement(new th().addElement(CacheMgt.get().toStringX()));
    line.addElement(new td().addElement(new a("adempiereMonitor?CacheReset=Yes", "Reset Cache")));
    table.addElement(line);
    //	Trace Level
    line = new tr();
    line.addElement(new th().addElement(new label("TraceLevel").addElement("Trace Log Level")));
    form myForm = new form("adempiereMonitor", form.METHOD_POST, form.ENC_DEFAULT);
    //	LogLevel Selection
    option[] options = new option[CLogMgt.LEVELS.length];
    for (int i = 0; i < options.length; i++) {
        options[i] = new option(CLogMgt.LEVELS[i].getName());
        options[i].addElement(CLogMgt.LEVELS[i].getName());
        if (CLogMgt.LEVELS[i] == CLogMgt.getLevel())
            options[i].setSelected(true);
    }
    select sel = new select("TraceLevel", options);
    myForm.addElement(sel);
    myForm.addElement(new input(input.TYPE_SUBMIT, "Set", "Set"));
    line.addElement(new td().addElement(myForm));
    table.addElement(line);
    //
    line = new tr();
    CLogFile fileHandler = CLogFile.get(true, null, false);
    line.addElement(new th().addElement("Trace File"));
    line.addElement(new td().addElement(new a("adempiereMonitor?Trace=" + fileHandler.getFileName(), "Current")));
    table.addElement(line);
    //
    line = new tr();
    line.addElement(new td().addElement(new a("adempiereMonitor?Trace=ROTATE", "Rotate Trace Log")));
    line.addElement(new td().addElement(new a("adempiereMonitor?Trace=DELETE", "Delete all Trace Logs")));
    table.addElement(line);
    //
    bb.addElement(table);
    //	List Log Files
    p p = new p();
    p.addElement(new b("All Log Files: "));
    //	All in dir
    File logDir = fileHandler.getLogDirectory();
    if (logDir != null && logDir.isDirectory()) {
        File[] logs = logDir.listFiles();
        for (int i = 0; i < logs.length; i++) {
            // Skip if is not a file - teo_sarca [ 1726066 ]
            if (!logs[i].isFile())
                continue;
            if (i != 0)
                p.addElement(" - ");
            String fileName = logs[i].getAbsolutePath();
            a link = new a("adempiereMonitor?Trace=" + fileName, fileName);
            p.addElement(link);
            int size = (int) (logs[i].length() / 1024);
            if (size < 1024)
                p.addElement(" (" + size + "k)");
            else
                p.addElement(" (" + size / 1024 + "M)");
        }
    }
    bb.addElement(p);
    //	Clients and Web Stores
    table = new table();
    table.setBorder(1);
    table.setCellSpacing(2);
    table.setCellPadding(2);
    //	
    line = new tr();
    MClient[] clients = MClient.getAll(ctx);
    line.addElement(new th().addElement("Client #" + clients.length + " - EMail Test:"));
    p = new p();
    for (int i = 0; i < clients.length; i++) {
        MClient client = clients[i];
        if (i > 0)
            p.addElement(" - ");
        p.addElement(new a("adempiereMonitor?EMail=" + client.getAD_Client_ID(), client.getName()));
    }
    if (clients.length == 0)
        p.addElement("&nbsp;");
    line.addElement(new td().addElement(p));
    table.addElement(line);
    //	
    line = new tr();
    MStore[] wstores = MStore.getActive();
    line.addElement(new th().addElement("Active Web Stores #" + wstores.length));
    p = new p();
    for (int i = 0; i < wstores.length; i++) {
        MStore store = wstores[i];
        if (i > 0)
            p.addElement(" - ");
        a a = new a(store.getWebContext(), store.getName());
        a.setTarget("t" + i);
        p.addElement(a);
    }
    if (wstores.length == 0)
        p.addElement("&nbsp;");
    line.addElement(new td().addElement(p));
    table.addElement(line);
    //
    bb.addElement(table);
}
Also used : org.apache.ecs.xhtml.select(org.apache.ecs.xhtml.select) org.apache.ecs.xhtml.hr(org.apache.ecs.xhtml.hr) Properties(java.util.Properties) MClient(org.compiere.model.MClient) MemoryMXBean(java.lang.management.MemoryMXBean) Trx(org.compiere.util.Trx) MSystem(org.compiere.model.MSystem) org.apache.ecs.xhtml.table(org.apache.ecs.xhtml.table) ThreadMXBean(java.lang.management.ThreadMXBean) org.apache.ecs.xhtml.a(org.apache.ecs.xhtml.a) CLogFile(org.compiere.util.CLogFile) org.apache.ecs.xhtml.b(org.apache.ecs.xhtml.b) RuntimeMXBean(java.lang.management.RuntimeMXBean) org.apache.ecs.xhtml.label(org.apache.ecs.xhtml.label) org.apache.ecs.xhtml.td(org.apache.ecs.xhtml.td) CConnection(org.compiere.db.CConnection) org.apache.ecs.xhtml.p(org.apache.ecs.xhtml.p) Timestamp(java.sql.Timestamp) org.apache.ecs.xhtml.input(org.apache.ecs.xhtml.input) AdempiereDatabase(org.compiere.db.AdempiereDatabase) org.apache.ecs.xhtml.th(org.apache.ecs.xhtml.th) org.apache.ecs.xhtml.form(org.apache.ecs.xhtml.form) CMemoryUsage(org.compiere.util.CMemoryUsage) MStore(org.compiere.model.MStore) CLogFile(org.compiere.util.CLogFile) File(java.io.File) org.apache.ecs.xhtml.tr(org.apache.ecs.xhtml.tr) org.apache.ecs.xhtml.option(org.apache.ecs.xhtml.option)

Example 3 with MSystem

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

the class DB method main.

/**
	 * 	Run Post Migration manually
	 *	@param args ignored
	 */
public static void main(String[] args) {
    Adempiere.startup(true);
    MSystem system = MSystem.get(Env.getCtx());
    system.setIsJustMigrated(true);
    afterMigration(Env.getCtx());
}
Also used : MSystem(org.compiere.model.MSystem)

Example 4 with MSystem

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

the class ALogin method connectionOK.

//	actionPerformed
/**************************************************************************
	 *	Connection OK pressed
	 */
private void connectionOK() {
    log.info("");
    //
    setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
    confirmPanel.getOKButton().setEnabled(false);
    m_connectionOK = tryConnection();
    if (m_connectionOK) {
        //  Verify Language & Load Msg
        Language l = Language.getLoginLanguage();
        Env.verifyLanguage(m_ctx, l);
        Env.setContext(m_ctx, Env.LANGUAGE, l.getAD_Language());
        Msg.getMsg(m_ctx, "0");
        //	Migration
        MSystem system = MSystem.get(m_ctx);
        if (system.isJustMigrated()) {
            statusBar.setStatusLine("Running: After Migration ....", true);
            ADialog.info(m_WindowNo, this, "AfterMigration");
            Thread.yield();
            DB.afterMigration(m_ctx);
        }
        //	Set Defaults
        printerField.setValue(Ini.getProperty(Ini.P_PRINTER));
        //	Change Tab to Default
        loginTabPane.setSelectedIndex(1);
    }
    confirmPanel.getOKButton().setEnabled(true);
    setCursor(Cursor.getDefaultCursor());
}
Also used : Language(org.compiere.util.Language) MSystem(org.compiere.model.MSystem)

Example 5 with MSystem

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

the class DB method afterMigration.

/**************************************************************************
	 * 	Check need for post Upgrade
	 * 	@param ctx context
	 *	@return true if post upgrade ran - false if there was no need
	 */
public static boolean afterMigration(Properties ctx) {
    //	UPDATE AD_System SET IsJustMigrated='Y'
    MSystem system = MSystem.get(ctx);
    if (!system.isJustMigrated())
        return false;
    //	Role update
    log.info("Role");
    String sql = "SELECT * FROM AD_Role";
    PreparedStatement pstmt = null;
    ResultSet rs = null;
    try {
        pstmt = DB.prepareStatement(sql, null);
        rs = pstmt.executeQuery();
        while (rs.next()) {
            MRole role = new MRole(ctx, rs, null);
            role.updateAccessRecords();
        }
    } catch (Exception e) {
        log.log(Level.SEVERE, "(1)", e);
    } finally {
        close(rs);
        close(pstmt);
        rs = null;
        pstmt = null;
    }
    //	Release Specif stuff & Print Format
    try {
        Class<?> clazz = Class.forName("org.compiere.MigrateData");
        clazz.newInstance();
    } catch (Exception e) {
        log.log(Level.SEVERE, "Data", e);
    }
    //	Language check
    log.info("Language");
    MLanguage.maintain(ctx);
    //	Sequence check
    log.info("Sequence");
    SequenceCheck.validate(ctx);
    //	Costing Setup
    log.info("Costing");
    MAcctSchema[] ass = MAcctSchema.getClientAcctSchema(ctx, 0);
    for (int i = 0; i < ass.length; i++) {
        ass[i].checkCosting();
        ass[i].saveEx();
    }
    //	Reset Flag
    system.setIsJustMigrated(false);
    return system.save();
}
Also used : MAcctSchema(org.compiere.model.MAcctSchema) MRole(org.compiere.model.MRole) ResultSet(java.sql.ResultSet) POResultSet(org.compiere.model.POResultSet) PreparedStatement(java.sql.PreparedStatement) MSystem(org.compiere.model.MSystem) SQLException(java.sql.SQLException) DBException(org.adempiere.exceptions.DBException)

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