From 87c95b9beed642ed68b711af8d9a7368572cf179 Mon Sep 17 00:00:00 2001 From: Frederico Palma Date: Thu, 19 Mar 2009 12:31:34 +0000 Subject: [PATCH] git-svn-id: https://svn.coded.pt/svn/SIPRP@977 bb69d46d-e84e-40c8-a05a-06db0d633741 --- .../higiene/relatorio/print/DBConstants.java | 17 +++++ .../relatorio/print/EquipamentosToPrint.java | 7 +- .../relatorio/print/LogotiposDumper.java | 33 ---------- .../relatorio/print/LogotiposImporter.java | 64 ------------------- .../relatorio/print/RelatorioDBInit.java | 33 ++++++++++ .../relatorio/print/RelatorioPDFCreator.java | 4 +- .../print/RelatorioPrintDataProvider.java | 24 +++---- .../relatorio/print/RelatorioToPrint.java | 5 +- .../higiene/relatorio/print/TestPrint.java | 4 +- 9 files changed, 72 insertions(+), 119 deletions(-) create mode 100644 trunk/SIPRPSoft/src/siprp/higiene/relatorio/print/DBConstants.java delete mode 100644 trunk/SIPRPSoft/src/siprp/higiene/relatorio/print/LogotiposDumper.java delete mode 100644 trunk/SIPRPSoft/src/siprp/higiene/relatorio/print/LogotiposImporter.java create mode 100644 trunk/SIPRPSoft/src/siprp/higiene/relatorio/print/RelatorioDBInit.java diff --git a/trunk/SIPRPSoft/src/siprp/higiene/relatorio/print/DBConstants.java b/trunk/SIPRPSoft/src/siprp/higiene/relatorio/print/DBConstants.java new file mode 100644 index 00000000..06e1a1fa --- /dev/null +++ b/trunk/SIPRPSoft/src/siprp/higiene/relatorio/print/DBConstants.java @@ -0,0 +1,17 @@ +package siprp.higiene.relatorio.print; + +public interface DBConstants +{ + +// public static final String LOCAL_URL = "jdbc:postgresql://localhost:5436/siprp_local_3"; +//// public static final String LOCAL_URL = "jdbc:postgresql://storage/siprp_local"; +// public static final String LOCAL_USER = "postgres"; +//// public static final String LOCAL_PASSWORD = "Typein"; +// public static final String LOCAL_PASSWORD = null; + + public static final String LOCAL_URL = "jdbc:postgresql://www.evolute.pt:5436/siprp_local_3"; + public static final String LOCAL_USER = "postgres"; + public static final String LOCAL_PASSWORD = "Typein"; + + public static final String LOCAL_DBMANAGER = "LOCAL DBMANAGER"; +} diff --git a/trunk/SIPRPSoft/src/siprp/higiene/relatorio/print/EquipamentosToPrint.java b/trunk/SIPRPSoft/src/siprp/higiene/relatorio/print/EquipamentosToPrint.java index c1f93225..7323db41 100644 --- a/trunk/SIPRPSoft/src/siprp/higiene/relatorio/print/EquipamentosToPrint.java +++ b/trunk/SIPRPSoft/src/siprp/higiene/relatorio/print/EquipamentosToPrint.java @@ -1,7 +1,5 @@ package siprp.higiene.relatorio.print; -import java.util.Arrays; - import org.jdom.Element; public class EquipamentosToPrint @@ -20,7 +18,10 @@ public class EquipamentosToPrint throws Exception { Element equipamentosElement = new Element( "equipamentos" ); - equipamentosElement.addContent( Arrays.asList( equipamentos ) ); + for( EquipamentoToPrint equipamento : equipamentos ) + { + equipamentosElement.addContent( equipamento.toJdomElement() ); + } return equipamentosElement; } } diff --git a/trunk/SIPRPSoft/src/siprp/higiene/relatorio/print/LogotiposDumper.java b/trunk/SIPRPSoft/src/siprp/higiene/relatorio/print/LogotiposDumper.java deleted file mode 100644 index 430d6b14..00000000 --- a/trunk/SIPRPSoft/src/siprp/higiene/relatorio/print/LogotiposDumper.java +++ /dev/null @@ -1,33 +0,0 @@ -package siprp.higiene.relatorio.print; - -import java.io.File; -import java.io.FileOutputStream; -import java.util.Date; - -import com.evolute.utils.data.Mappable; - -public class LogotiposDumper -{ - public static void main( String args[] ) - throws Exception - { - System.out.println( "Dumper: " + new Date() ); - dump( args[ 0 ] ); - } - - public static void dump( String path ) - throws Exception - { - Mappable[] logotipos = RelatorioPrintDataProvider.getProvider( true ).getLogotipos(); - for( Mappable logotipo : logotipos ) - { - File file = new File( path, "" + logotipo.getID() + ".png" ); - file.createNewFile(); - FileOutputStream fos = new FileOutputStream( file ); - fos.write( ( byte[] ) logotipo.getValue() ); - fos.close(); - } - } - - -} diff --git a/trunk/SIPRPSoft/src/siprp/higiene/relatorio/print/LogotiposImporter.java b/trunk/SIPRPSoft/src/siprp/higiene/relatorio/print/LogotiposImporter.java deleted file mode 100644 index 9ab52600..00000000 --- a/trunk/SIPRPSoft/src/siprp/higiene/relatorio/print/LogotiposImporter.java +++ /dev/null @@ -1,64 +0,0 @@ -package siprp.higiene.relatorio.print; - -import java.io.File; -import java.io.FileInputStream; -import java.io.FilenameFilter; -import java.util.Date; -import java.util.Vector; - -public class LogotiposImporter -{ - public static void main( String args[] ) - throws Exception - { - System.out.println( "Importer: " + new Date() ); - load( args[ 0 ] ); - } - - public static void load( String path ) - throws Exception - { - File dir = new File( path ); - File files[] = dir.listFiles( new FilenameFilter(){ - - @Override - public boolean accept( File dir, String name ) - { - return name.length() >= 4 && ".jpg".equals( name.substring( name.length() - 4, name.length() ) ); - } - } ); - for( File file : files ) - { - FileInputStream fis = new FileInputStream( file ); - int ret = 0; - Vector buffers = new Vector(); - Vector sizes = new Vector(); - byte data[]; - int size = 0; - do - { - byte buff[] = new byte[ 1024 ]; - ret = fis.read( buff, 0, buff.length ); - if( ret > 0 ) - { - size += ret; - buffers.add( buff ); - sizes.add( ret ); - } - } while( ret >= 0 ); - fis.close(); - data = new byte[ size ]; - int off = 0; - for( int n = 0; n < buffers.size(); n++ ) - { - byte buff[] = buffers.get( n ); - int s = sizes.get( n ); - System.arraycopy( buff, 0, data, off, s ); - off += s; - } - Integer id = new Integer( file.getName().split( "[.]" )[ 0 ] ); - - RelatorioPrintDataProvider.getProvider( true ).updateLogotipo( id, data ); - } - } -} diff --git a/trunk/SIPRPSoft/src/siprp/higiene/relatorio/print/RelatorioDBInit.java b/trunk/SIPRPSoft/src/siprp/higiene/relatorio/print/RelatorioDBInit.java new file mode 100644 index 00000000..51c9fd53 --- /dev/null +++ b/trunk/SIPRPSoft/src/siprp/higiene/relatorio/print/RelatorioDBInit.java @@ -0,0 +1,33 @@ +package siprp.higiene.relatorio.print; + +import siprp.SingletonConstants; + +import com.evolute.utils.Singleton; +import com.evolute.utils.db.DBManager; +import com.evolute.utils.db.JDBCManager; +import com.evolute.utils.db.keyretrievers.PostgresqlAutoKeyRetriever; +import com.evolute.utils.sql.Insert; +import com.evolute.utils.strings.UnicodeChecker; + +public class RelatorioDBInit +{ + public static void initDB() + throws Exception + { +// if( web ) +// { + String url = DBConstants.LOCAL_URL; + String user = DBConstants.LOCAL_USER; + String pwd = DBConstants.LOCAL_PASSWORD; + DBManager localManager = new JDBCManager( url, user, pwd, 10, 8, 8, null ); + Singleton.setInstance( DBConstants.LOCAL_DBMANAGER, localManager ); +// } +// else +// { +// Singleton.setInstance( DBConstants.LOCAL_DBMANAGER, Singleton.getInstance( Singleton.DEFAULT_DBMANAGER ) ); +// } + + Insert.setDefaultKeyRetriever( PostgresqlAutoKeyRetriever.RETRIEVER ); + UnicodeChecker.setUseDoubleSlash( true ); + } +} diff --git a/trunk/SIPRPSoft/src/siprp/higiene/relatorio/print/RelatorioPDFCreator.java b/trunk/SIPRPSoft/src/siprp/higiene/relatorio/print/RelatorioPDFCreator.java index fd67a6a2..8ac7c456 100644 --- a/trunk/SIPRPSoft/src/siprp/higiene/relatorio/print/RelatorioPDFCreator.java +++ b/trunk/SIPRPSoft/src/siprp/higiene/relatorio/print/RelatorioPDFCreator.java @@ -13,9 +13,9 @@ import com.evolute.utils.xml.XSLTransformer; public class RelatorioPDFCreator { - public byte[] createPDF( Integer planoId, boolean web ) throws Exception + public byte[] createPDF( Integer planoId ) throws Exception { - RelatorioToPrint relatorio = RelatorioPrintDataProvider.getProvider( web ).getRelatorioToPrint( planoId ); + RelatorioToPrint relatorio = RelatorioPrintDataProvider.getProvider().getRelatorioToPrint( planoId ); Document foDoc = new Document( relatorio.toJdomElement() ); XMLOutputter outputter = new XMLOutputter(); ByteArrayOutputStream foBaos = new ByteArrayOutputStream(); diff --git a/trunk/SIPRPSoft/src/siprp/higiene/relatorio/print/RelatorioPrintDataProvider.java b/trunk/SIPRPSoft/src/siprp/higiene/relatorio/print/RelatorioPrintDataProvider.java index a7803737..e97f8cd3 100644 --- a/trunk/SIPRPSoft/src/siprp/higiene/relatorio/print/RelatorioPrintDataProvider.java +++ b/trunk/SIPRPSoft/src/siprp/higiene/relatorio/print/RelatorioPrintDataProvider.java @@ -4,9 +4,7 @@ import java.util.Date; import java.util.HashMap; import java.util.Vector; -import siprp.SingletonConstants; import siprp.planoactuacao.db.DBConstants; -import siprp.planoactuacao.db.PlanoActuacaoDBInit; import com.evolute.utils.Singleton; import com.evolute.utils.arrays.Virtual2DArray; @@ -28,25 +26,25 @@ public class RelatorioPrintDataProvider protected final Executer EXECUTER; - public RelatorioPrintDataProvider( boolean web ) + public RelatorioPrintDataProvider() throws Exception { - if( Singleton.getInstance( DBConstants.WEB_DBMANAGER ) == null ) + if( Singleton.getInstance( DBConstants.LOCAL_DBMANAGER ) == null ) { - PlanoActuacaoDBInit.initDB( web ); + RelatorioDBInit.initDB(); } DBManager LOCAL_DBMANAGER = ( DBManager ) Singleton.getInstance( DBConstants.LOCAL_DBMANAGER ); EXECUTER = LOCAL_DBMANAGER.getSharedExecuter( this ); } - public static RelatorioPrintDataProvider getProvider( boolean web ) + public static RelatorioPrintDataProvider getProvider() throws Exception { synchronized( LOCK ) { if( instance == null ) { - instance = new RelatorioPrintDataProvider( web ); + instance = new RelatorioPrintDataProvider(); } } return instance; @@ -117,8 +115,7 @@ public class RelatorioPrintDataProvider EmpresaToPrint empresa = new EmpresaToPrint( nomeEmpresa, "http://www.evolute.pt:13080/SIPRPImages/image?id=" + logoId, nomeEstabelecimento, actividadeEmpresa ); - //TODO: - RelatorioToPrint plano = null; + RelatorioToPrint plano = new RelatorioToPrint( empresa, dataRelatorio != null ? new DataToPrint( "data-relatorio", dataRelatorio ) : null, @@ -235,7 +232,7 @@ public class RelatorioPrintDataProvider new Expression[]{}, new String[]{ "hs_relatorio_equipamento.tipo", "hs_relatorio_equipamento.marca", "hs_relatorio_equipamento.modelo" }, - new Field( "hs_relatorio_equipamento.relatorio_id" ).isEqual( relatorioId ), + new Field( "hs_relatorio_equipamento.hs_relatorio_id" ).isEqual( relatorioId ), null, null, null, @@ -329,9 +326,8 @@ public class RelatorioPrintDataProvider "hs_relatorio_posto_risco.probabilidade", "hs_relatorio_posto_risco.severidade", "hs_relatorio_risco_valor_qualitativo.description" }, - new Field( "hs_relatorio_posto.posto_id" ).isEqual( postoId ).and( - new Field( "hs_relatorio_risco.deleted_date" ).isEqual( null ) ).and( - new Field( "hs_relatorio_posto.deleted_date" ).isEqual( null ) ), + new Field( "hs_relatorio_posto_risco.posto_id" ).isEqual( postoId ).and( + new Field( "hs_relatorio_risco.deleted_date" ).isEqual( null ) ), new String[]{ "hs_relatorio_risco.id" }, null, null, @@ -367,7 +363,7 @@ public class RelatorioPrintDataProvider new String[]{ "hs_relatorio_medida" }, new Integer[]{}, new Expression[]{}, - new String[]{ "hs_relatorio_medida.id", "hs_relatorio_medida.requisitos_legais" }, + new String[]{ "hs_relatorio_medida.id", "hs_relatorio_medida.requesitos_legais" }, new Field( "hs_relatorio_medida.risco_id" ).isEqual( riscoId ).and( new Field( "hs_relatorio_medida.deleted_date" ).isEqual( null ) ), new String[]{ "hs_relatorio_medida.id" }, diff --git a/trunk/SIPRPSoft/src/siprp/higiene/relatorio/print/RelatorioToPrint.java b/trunk/SIPRPSoft/src/siprp/higiene/relatorio/print/RelatorioToPrint.java index cee83520..aff787d4 100644 --- a/trunk/SIPRPSoft/src/siprp/higiene/relatorio/print/RelatorioToPrint.java +++ b/trunk/SIPRPSoft/src/siprp/higiene/relatorio/print/RelatorioToPrint.java @@ -117,7 +117,10 @@ public class RelatorioToPrint planoElement.addContent( empresa.toJdomElement() ); planoElement.addContent( dataRelatorio.toJdomElement() ); planoElement.addContent( dataHs.toJdomElement() ); - planoElement.addContent( dataProximaHs.toJdomElement() ); + if( dataProximaHs != null ) + { + planoElement.addContent( dataProximaHs.toJdomElement() ); + } planoElement.addContent( legislacaoAplicavel.toJdomElement() ); planoElement.addContent( normalizacaoAplicavel.toJdomElement() ); planoElement.addContent( equipamentos.toJdomElement() ); diff --git a/trunk/SIPRPSoft/src/siprp/higiene/relatorio/print/TestPrint.java b/trunk/SIPRPSoft/src/siprp/higiene/relatorio/print/TestPrint.java index 0130c8db..ae0f318a 100644 --- a/trunk/SIPRPSoft/src/siprp/higiene/relatorio/print/TestPrint.java +++ b/trunk/SIPRPSoft/src/siprp/higiene/relatorio/print/TestPrint.java @@ -55,9 +55,9 @@ public class TestPrint // fos.write( fo ); // fos.close(); - for( int n = 49; n <= 49; n++ ) + for( int n = 57; n <= 57; n++ ) { - byte pdf[] = new RelatorioPDFCreator().createPDF( n, false ); + byte pdf[] = new RelatorioPDFCreator().createPDF( n ); FileOutputStream fos = new FileOutputStream( "/home/fpalma/Desktop/" + n + ".pdf" ); fos.write( pdf ); fos.close();