From bc655a7a89de120ef433f5747a37d2c41c31276b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tiago=20Sim=C3=A3o?= Date: Thu, 15 Jul 2010 11:06:17 +0000 Subject: [PATCH] git-svn-id: https://svn.coded.pt/svn/SIPRP@1304 bb69d46d-e84e-40c8-a05a-06db0d633741 --- trunk/SIPRPSoft/src/siprp/Main.java | 115 ++++----------- trunk/SIPRPSoft/src/siprp/SHSTLogger.java | 136 ------------------ .../SIPRPSoft/src/siprp/SIPRPLoggerInit.java | 36 +++++ 3 files changed, 61 insertions(+), 226 deletions(-) delete mode 100644 trunk/SIPRPSoft/src/siprp/SHSTLogger.java create mode 100644 trunk/SIPRPSoft/src/siprp/SIPRPLoggerInit.java diff --git a/trunk/SIPRPSoft/src/siprp/Main.java b/trunk/SIPRPSoft/src/siprp/Main.java index 3c8bd61c..e2950974 100644 --- a/trunk/SIPRPSoft/src/siprp/Main.java +++ b/trunk/SIPRPSoft/src/siprp/Main.java @@ -44,7 +44,6 @@ import com.evolute.utils.db.DBException; import com.evolute.utils.db.DBManager; import com.evolute.utils.db.JDBCManager; import com.evolute.utils.db.keyretrievers.JDBCAutoKeyRetriever; -import com.evolute.utils.error.ErrorLogger; import com.evolute.utils.jdbc.DBStatementExecuter; import com.evolute.utils.jdbc.StatementExecuterFactory; import com.evolute.utils.sql.Insert; @@ -64,7 +63,6 @@ public class Main implements com.evolute.utils.ui.window.Connector static { - ESTADO_PROCESSO_BY_CODE.put( PROCESSO_ABERTO_CODE, PROCESSO_ABERTO_DESCRIPTION ); ESTADO_PROCESSO_BY_CODE.put( PROCESSO_FECHADO_CODE, PROCESSO_FECHADO_DESCRIPTION ); ESTADO_PROCESSO_BY_CODE.put( PROCESSO_CANCELADO_CODE, PROCESSO_CANCELADO_DESCRIPTION ); @@ -87,57 +85,18 @@ public class Main implements com.evolute.utils.ui.window.Connector new SIPRPUIInitializer().doInit(); SIPRPPropertiesLoader.getInstance().load(); - -// Singleton.setInstance( SingletonConstants.COMPANY_NAME, "Centro Cl\u00ednico Avenida" ); -// Singleton.setInstance( SingletonConstants.COMPANY_LOGO, "logo_evo.jpg" ); -// Singleton.setInstance( SingletonConstants.WEB_AWARE, Boolean.FALSE ); -// Singleton.setInstance( SingletonConstants.DB_NAME, "shst" ); -// Singleton.setInstance( SingletonConstants.COMPANY_NAME, "SIPRP - Sociedade Ib\u00e9rica de Preven\u00e7\u00e3o de Riscos Profissionais" ); -// Singleton.setInstance( SingletonConstants.COMPANY_LOGO, "logo_combo.jpg" ); -// Singleton.setInstance( SingletonConstants.WEB_AWARE, Boolean.TRUE ); -// Singleton.setInstance( SingletonConstants.LOCAL_DB_NAME, "siprp" ); new SIPRPDataLoader().load(); -// new ClinicaAvenidaDataLoader().load(); -// new IBookDataLoader().load(); dbase = (String) Singleton.getInstance( SingletonConstants.LOCAL_DB_NAME ); -// dbase = "siprp_local3"; -/* Calendar cal = Calendar.getInstance(); - cal.set( 2004, 06, 14 ); - if( cal.before( Calendar.getInstance() ) ) - { - com.evolute.utils.ui.DialogException.showException( new RuntimeException( "Unknown error ocurred." ) ); - } - else - { -*/ Insert.setDefaultKeyRetriever( JDBCAutoKeyRetriever.DEFAULT ); -// String server = System.getProperty( "server.address" ); -// if( server == null ) -// { -// server = "ws_fpalma"; -// } -// -// String user = "root"; -// String passwd = "UNIXLuvsU"; -// -// DBManager dbm = new JDBCManager( "jdbc:mysql://" + server + "/" + dbase, -// user, passwd , 10, 8, 8, null ); - - UnicodeChecker.setUseDoubleSlash( true ); -// Singleton.setInstance( Singleton.DEFAULT_DBMANAGER, dbm ); + + Insert.setDefaultKeyRetriever( JDBCAutoKeyRetriever.DEFAULT ); + + UnicodeChecker.setUseDoubleSlash( true ); -// StatementExecuterFactory.initialize( -// new DBStatementExecuter( dbm.getSharedExecuter() ) ); -// } -// FichaWindow window = new FichaWindow(); -/* window.setLogo( new ImageIcon( - new Main().getClass().getClassLoader().getResource( "logo/logo_w400.png" ) - ).getImage() );*/ -// window.show(); avisos = new AvisosPanel(); String logoFileName = ( String ) Singleton.getInstance( SingletonConstants.COMPANY_LOGO ); - loginWindow = new LoginWindow( new Main(), /*"logo"+File.separator +*/ logoFileName,//"logo"+File.separator + "logo_w400.jpg", + loginWindow = new LoginWindow( new Main(), logoFileName, new String[] { (String) Singleton.getInstance( SingletonConstants.SOFTWARE_NAME ) }, new String[] { "Vers\u00E3o " + ProjectTools.getInstance().getVersion(), "(EVOLUTE 2004-2010)" }, "", (String)Singleton.getInstance( SingletonConstants.LOCAL_USER ), @@ -147,66 +106,63 @@ public class Main implements com.evolute.utils.ui.window.Connector loginWindow.getButtOK().setEnabled( false ); JPanel left = loginWindow.getLeftPanel(); left.setBackground( Color.white ); -// GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment(); + loginWindow.setSize( 1024, 510 ); loginWindow.setExtendedState(loginWindow.getExtendedState() | LoginWindow.MAXIMIZED_BOTH); loginWindow.setVisible( true ); SwingUtilities.invokeLater( new Runnable() { + @Override public void run() { loginWindow.expandAll(); } } ); - fopConfigFile = loadFopConfigFile(); } - - private static File loadFopConfigFile() { - - try { + private static File loadFopConfigFile() + { + try + { InputStream is = ClassLoader.getSystemClassLoader() .getResourceAsStream("siprp/util/fop/fop.xconf"); - if (is != null) { + if (is != null) + { File tempFile = File.createTempFile("fop", ".xconf"); FileOutputStream fos = new FileOutputStream(tempFile); byte[] buf = new byte[256]; int read = 0; - while ((read = is.read(buf)) > 0) { + while ((read = is.read(buf)) > 0) + { fos.write(buf, 0, read); } return tempFile; } return null; - } catch (Exception e) { + } + catch (Exception e) + { e.printStackTrace(); return null; } } + @Override public boolean connect( String user, String passwd ) { String url = null; try { - // run initialization SQL -// SQLQuery initQuery[] = new SQLQuery[] {}; -// String server = System.getProperty( "server.address" ); String server = null; if( server == null ) { - //server = "192.168.1.191"; server = (String)Singleton.getInstance( SingletonConstants.LOCAL_URL ); -// server = "storage"; -// server = "ws_fpalma"; } String prefix = (String)Singleton.getInstance( SingletonConstants.LOCAL_URL_PREFIX ); url = prefix + server + "/" + dbase; -// System.out.println( "url: " + url + " user: " + user + " ps: " + passwd ); DBManager dbm = new JDBCManager( url, user, passwd , 10, 8, 8, null ); -// UnicodeChecker.setUseDoubleSlash( true ); Singleton.setInstance( Singleton.DEFAULT_DBMANAGER, dbm ); StatementExecuterFactory.initialize( @@ -218,9 +174,6 @@ public class Main implements com.evolute.utils.ui.window.Connector Singleton.setInstance( Singleton.TODAY, new Date() ); initializeCayenne( url, user, passwd); - -//cleanData( dbm.getSharedExecuter() ); -//msg( dbm.getSharedExecuter() ); } catch( Exception ex ) { @@ -229,37 +182,16 @@ public class Main implements com.evolute.utils.ui.window.Connector return false; } Singleton.setInstance( Singleton.USERNAME, user ); - try - { - ErrorLogger.initializeLogger( new SHSTLogger() ); - } - catch( Exception ex ) - { - ex.printStackTrace( System.out ); - } - //Singleton.setInstance( Singleton.USERNAME, user ); + SIPRPLoggerInit.init(); siprpTracker = new SIPRPTracker( avisos ); avisos.refresh(); -// new Exception().printStackTrace(); -// try -// { -// Thread.sleep( 1000 ); -// } -// catch( Exception ex ){} -// new Exception().printStackTrace(); + LembretesDemon.go(); return true; } -// public static void reconnectJDO() -// { -// PersistenceManagerFactory pmf = ( PersistenceManagerFactory ) Singleton.getInstance( Singleton.DEFAULT_PERSISTENCE_MANAGER_FACTORY ); -// PersistenceManager pm = pmf.getPersistenceManager(); -// Singleton.setInstance( SingletonConstants.PERSISTENCE_MANAGER, pm ); -// com.evolute.utils.jdo.JDOObject.setPersistentManager( pm ); -// } - + @Override public boolean disconnect() { if( siprpTracker.quit() ) @@ -280,6 +212,7 @@ public class Main implements com.evolute.utils.ui.window.Connector return false; } + @Override public void executeAction( DefaultMutableTreeNode node ) { try @@ -293,6 +226,7 @@ public class Main implements com.evolute.utils.ui.window.Connector } + @Override public void exit() { if( siprpTracker == null || siprpTracker.quit() ) @@ -301,6 +235,7 @@ public class Main implements com.evolute.utils.ui.window.Connector } } + @Override public MutableTreeNode getTree() { return siprpTracker.getRoot(); diff --git a/trunk/SIPRPSoft/src/siprp/SHSTLogger.java b/trunk/SIPRPSoft/src/siprp/SHSTLogger.java deleted file mode 100644 index 501594d8..00000000 --- a/trunk/SIPRPSoft/src/siprp/SHSTLogger.java +++ /dev/null @@ -1,136 +0,0 @@ -/* - * SIPRPLogger.java - * - * Created on 15 de Marco de 2005, 15:31 - */ - -package siprp; - -import com.evolute.project.ProjectTools; -import com.evolute.utils.Singleton; -import com.evolute.utils.db.DBManager; -import com.evolute.utils.db.Executer; -import com.evolute.utils.db.SQLRetriever; -import com.evolute.utils.error.Logger; -import com.evolute.utils.sql.Assignment; -import com.evolute.utils.sql.Field; -import com.evolute.utils.sql.Insert; - -/** - * - * @author lflores - - * MySQL -CREATE TABLE errors -( - id INT NOT NULL AUTO_INCREMENT, - PRIMARY KEY( id ), - date TIMESTAMP NOT NULL DEFAULT 'now()', - type VARCHAR(20), - environment VARCHAR( 255 ), - description TEXT -); - * - *PostgreSQL -CREATE TABLE errors -( - id SERIAL, - PRIMARY KEY( id ), - date TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, - type VARCHAR(20), - environment VARCHAR( 255 ), - description VARCHAR( 256000 ) -) - - */ -public class SHSTLogger implements Logger -{ - private final String java = System.getProperty( "java.version" ) - + "-" + System.getProperty( "java.vm.version" ); - private final String os = System.getProperty( "os.name" ) + " - " + - System.getProperty( "os.version" ); - private final String user = ( String )Singleton.getInstance( Singleton.USERNAME ); - private final String ENV = "Java: " + java + " \nOS: " + os + " \nUser: " + user - + "\n Software: " + ( String )Singleton.getInstance( SingletonConstants.SOFTWARE_NAME ) - + "\n Version: " + ProjectTools.getInstance().getVersion(); - private final Executer executer; - - /** Creates a new instance of SIPRPLogger */ - public SHSTLogger() - throws Exception - { - DBManager dbm = ( DBManager )Singleton.getInstance( Singleton.DEFAULT_DBMANAGER ); - executer = dbm.getExclusiveExecuter( this ); - } - - @Override - public void log( String str ) - { - String mem = "(" + Runtime.getRuntime().freeMemory() + "/" + - Runtime.getRuntime().maxMemory() + ")"; - if( str.length() > 254000 ) - { - str = str.substring( 0, 254000 ) + " Message too big (" + str.length() + "), truncated."; - } - try - { - executer.executeQuery( new Insert( "errors", new Assignment[] { - new Assignment( new Field( "type" ), "LOG" ), - new Assignment( new Field( "environment" ), ENV + mem ), - new Assignment( new Field( "description" ), str ) - } ), null ); - } - catch( Exception ex ) - { - logException( ex ); - } - } - - @Override - public void logException( Throwable ex ) - { - StackTraceElement ste[] = ex.getStackTrace(); - StringBuffer sb = new StringBuffer(); - for( int i = 0; i < ste.length; ++i ) - { - sb.append( ste[ i ].toString() ); - } - String str = "Exception Message: " + ex.getMessage() + "\nStack Trace: " + sb.toString(); - String mem = "(" + Runtime.getRuntime().freeMemory() + "/" + - Runtime.getRuntime().maxMemory() + ")"; - if( str.length() > 254000 ) - { - str = str.substring( 0, 254000 ) + " Message too big (" + str.length() + "), truncated."; - } - try - { - executer.executeQuery( new Insert( "errors", new Assignment[] { - new Assignment( new Field( "type" ), "ERROR" ), - new Assignment( new Field( "environment" ), ENV + mem ), - new Assignment( new Field( "description" ), str ) - } ), new SQLRetriever() ); - } - catch( Exception ex1 ) - { - ex.printStackTrace(); - } - } - - @Override - public void close() { - - } - - @Override - public void log(String str, java.util.logging.Level level) { - // TODO Auto-generated method stub - - } - - @Override - public void logException(Throwable ex, java.util.logging.Level level) { - // TODO Auto-generated method stub - - } - -} diff --git a/trunk/SIPRPSoft/src/siprp/SIPRPLoggerInit.java b/trunk/SIPRPSoft/src/siprp/SIPRPLoggerInit.java new file mode 100644 index 00000000..957b9f83 --- /dev/null +++ b/trunk/SIPRPSoft/src/siprp/SIPRPLoggerInit.java @@ -0,0 +1,36 @@ +package siprp; + +import java.util.HashMap; +import java.util.Map; + +import com.evolute.project.ProjectTools; +import com.evolute.utils.error.ErrorLogger; +import com.evolute.utils.error.LoggerProperties; +import com.evolute.utils.error.ProjectsEnum; +import com.evolute.utils.error.ws.WSLogger; +import com.evolute.utils.network.proxy.EvoProxyObject; + +public class SIPRPLoggerInit +{ + + static void init() + { + Map map = new HashMap(); + + map.put( LoggerProperties.PROJECT, ProjectsEnum.SIPRP.toString() ); + map.put( LoggerProperties.SOFTWARE_VERSION, ProjectTools.getInstance().getVersion().toString() ); + map.put( LoggerProperties.SOFTWARE_NAME, "SIPRPSoft" ); + + try + { + EvoProxyObject.configSystemProxySelector(); + EvoProxyObject.getProxy(); + ErrorLogger.initializeLogger( new WSLogger( map ) ); + } + catch ( Exception e ) + { + ErrorLogger.logException( e ); + } + } + +}