From 8ba88f97a98567e0050d3ee5f4b6ffc2891f6096 Mon Sep 17 00:00:00 2001 From: Frederico Palma Date: Wed, 2 Jan 2008 22:41:04 +0000 Subject: [PATCH] git-svn-id: https://svn.coded.pt/svn/SIPRP@638 bb69d46d-e84e-40c8-a05a-06db0d633741 --- .../src/siprp/ficha/EmpresaPanel.java | 5 +- .../locais_analise/EnviarAnalisesWindow.java | 28 ++++++- .../EnviarAnalisesWindowLogic.java | 13 +++- .../LocaisAnaliseDataProvider.java | 65 ++++++++++++++++ .../locais_analise/LocaisAnaliseLogic.java | 14 ++++ .../LocaisRealizacaoDataProvider.java | 2 +- .../src/siprp/update/UpdateList.java | 2 +- .../siprp/update/updates/V8_2_To_V8_3.java | 78 +++++++++++++++++++ 8 files changed, 199 insertions(+), 8 deletions(-) create mode 100644 trunk/SIPRPSoft/src/siprp/update/updates/V8_2_To_V8_3.java diff --git a/trunk/SIPRPSoft/src/siprp/ficha/EmpresaPanel.java b/trunk/SIPRPSoft/src/siprp/ficha/EmpresaPanel.java index bede830c..e7669c40 100644 --- a/trunk/SIPRPSoft/src/siprp/ficha/EmpresaPanel.java +++ b/trunk/SIPRPSoft/src/siprp/ficha/EmpresaPanel.java @@ -319,7 +319,7 @@ public class EmpresaPanel extends JPanel if( estabelecimentoID != null ) { estabelecimento = (EstabelecimentoData)JDO.load( EstabelecimentoData.class, estabelecimentoID ); - names = estabelecimento.getFieldNames(); + names = (String[])estabelecimentoComponents.keySet().toArray( new String[0] ); //estabelecimento.getFieldNames(); ComponentController.fill( names, estabelecimento.getHashData(), estabelecimentoComponents ); } @@ -418,7 +418,8 @@ public class EmpresaPanel extends JPanel ComponentController.save( names, hash, empresaComponents ); empresa.setHashData( hash ); - names = estabelecimento.getFieldNames(); +// names = estabelecimento.getFieldNames(); + names = (String[])estabelecimentoComponents.keySet().toArray( new String[0] ); hash = estabelecimento.getHashData(); ComponentController.save( names, hash, estabelecimentoComponents ); estabelecimento.setHashData( hash ); diff --git a/trunk/SIPRPSoft/src/siprp/medicina/locais_analise/EnviarAnalisesWindow.java b/trunk/SIPRPSoft/src/siprp/medicina/locais_analise/EnviarAnalisesWindow.java index 9ca5127e..3008b079 100644 --- a/trunk/SIPRPSoft/src/siprp/medicina/locais_analise/EnviarAnalisesWindow.java +++ b/trunk/SIPRPSoft/src/siprp/medicina/locais_analise/EnviarAnalisesWindow.java @@ -66,7 +66,7 @@ public class EnviarAnalisesWindow extends JFrame prestadorCombo = new JComboBox(); ecdsOuterPanel = new JPanel(); ecdsOuterPanel.setLayout( new GridLayout( 1, 1 ) ); - enviarButton = new JButton( "Enviar" ); + enviarButton = new JButton( "Gravar" ); enviarButton.addActionListener( this ); TableLayout layout = @@ -101,6 +101,21 @@ public class EnviarAnalisesWindow extends JFrame } ); dataPanel.setDate( new Date() ); + try + { + logic.dateChanged( dataPanel.getDate() ); + } + catch( Exception ex ) + { + if( dataPanel.getDate() != null ) + { + DialogException.showExceptionMessage( ex, "Erro a carregar dados de " + DateFormat.getDateInstance( DateFormat.SHORT, new Locale( "pt", "PT" ) ).format( dataPanel.getDate() ), true ); + } + else + { + DialogException.showExceptionMessage( ex, "Erro a carregar dados de null", true ); + } + } } public void refresh() @@ -153,7 +168,14 @@ public class EnviarAnalisesWindow extends JFrame Object source = e.getSource(); if( source.equals( enviarButton ) ) { - + try + { + logic.save(); + } + catch( Exception ex ) + { + DialogException.showExceptionMessage( ex, "Erro a gravar", true ); + } } } @@ -229,7 +251,7 @@ public class EnviarAnalisesWindow extends JFrame return new Object[]{ dataPanel.getDate(), ( ( IDObject )prestadorCombo.getSelectedItem() ).getID(), - ecdsPanel.save() }; + ecdsPanel != null ? ecdsPanel.save() : null }; } private void revalidate() diff --git a/trunk/SIPRPSoft/src/siprp/medicina/locais_analise/EnviarAnalisesWindowLogic.java b/trunk/SIPRPSoft/src/siprp/medicina/locais_analise/EnviarAnalisesWindowLogic.java index a0dde8e2..ec835ef2 100644 --- a/trunk/SIPRPSoft/src/siprp/medicina/locais_analise/EnviarAnalisesWindowLogic.java +++ b/trunk/SIPRPSoft/src/siprp/medicina/locais_analise/EnviarAnalisesWindowLogic.java @@ -32,7 +32,7 @@ class EnviarAnalisesWindowLogic throws Exception { window.addWindowListener( new WindowAdapter(){ - public void windowOpened( WindowEvent e ) + public void windowActivated( WindowEvent e ) { try { @@ -57,16 +57,27 @@ class EnviarAnalisesWindowLogic protected void dateChanged( Date data ) throws Exception { +System.out.println( "EnviarAnalisesWindowLogic.dateChanged: " + data ); if( data != null ) { Integer idsMarcacoes[] = locaisRealizacaoProvider.getMarcacoesEcdsIdsByDataAndPrestadorId( data, LocaisRealizacaoConstants.PRESTADOR_ID_SIPRP ); +System.out.println( "idsMarcacoes.length : " +idsMarcacoes.length ); IDObject grupos[] = logic.getGruposEcdsByMarcacoes( idsMarcacoes ); window.setEcds( grupos ); + window.fill( logic.getDataPrestadorEGruposByData( data ) ); } else { window.setEcds( new IDObject[ 0 ] ); + window.fill( null ); } } + + protected void save() + throws Exception + { + Object dados[] = ( Object[] ) window.save(); + logic.savePrestadorEGruposData( ( Date ) dados[ 0 ], ( Integer ) dados[ 1 ], ( Integer[] ) dados[ 2 ] ); + } } diff --git a/trunk/SIPRPSoft/src/siprp/medicina/locais_analise/LocaisAnaliseDataProvider.java b/trunk/SIPRPSoft/src/siprp/medicina/locais_analise/LocaisAnaliseDataProvider.java index ab48177d..00b7dce9 100644 --- a/trunk/SIPRPSoft/src/siprp/medicina/locais_analise/LocaisAnaliseDataProvider.java +++ b/trunk/SIPRPSoft/src/siprp/medicina/locais_analise/LocaisAnaliseDataProvider.java @@ -1,13 +1,22 @@ package siprp.medicina.locais_analise; +import java.util.Date; + +import siprp.medicina.locais_realizacao.LocaisRealizacaoConstants; + import com.evolute.utils.Singleton; import com.evolute.utils.arrays.Virtual2DArray; import com.evolute.utils.data.IDObject; import com.evolute.utils.data.MappableObject; import com.evolute.utils.db.DBManager; import com.evolute.utils.db.Executer; +import com.evolute.utils.sql.Assignment; +import com.evolute.utils.sql.Begin; +import com.evolute.utils.sql.Commit; +import com.evolute.utils.sql.Delete; import com.evolute.utils.sql.Expression; import com.evolute.utils.sql.Field; +import com.evolute.utils.sql.Insert; import com.evolute.utils.sql.Select; import com.evolute.utils.sql.Select2; @@ -42,6 +51,10 @@ public class LocaisAnaliseDataProvider protected IDObject[] getGruposEcdsByMarcacoes( Integer marcacoesIds[] ) throws Exception { + if( marcacoesIds == null || marcacoesIds.length == 0 ) + { + return new IDObject[ 0 ]; + } Select select = new Select2( new String[]{ "trabalhadores_ecd", "prt_tipos_elementos_protocolo", @@ -70,4 +83,56 @@ public class LocaisAnaliseDataProvider } return grupos; } + + public void savePrestadorEGruposData( Date data, Integer prestadorId, Integer gruposIds[] ) + throws Exception + { + EXECUTER.executeQuery( Begin.BEGIN ); + Delete delete = + new Delete( "trabalhadores_ecds_analise", + new Field( "data" ).isEqual( data ) ); + EXECUTER.executeQuery( delete ); + if( prestadorId != null && !LocaisRealizacaoConstants.PRESTADOR_ID_SIPRP.equals( prestadorId ) + && gruposIds != null && gruposIds.length > 0 ) + { + Insert insert = + new Insert( "trabalhadores_ecds_analise", + new Assignment[]{ + new Assignment( new Field( "data" ), data ), + new Assignment( new Field( "prestador_id" ), prestadorId ), + new Assignment( new Field( "grupo_ecds_id" ), gruposIds ) + } ); + EXECUTER.executeQuery( insert ); + } + EXECUTER.executeQuery( Commit.COMMIT ); + } + + public Object[] getDataPrestadorEGruposByData( Date data ) + throws Exception + { + Select select = + new Select2( + new String[]{ "trabalhadores_ecds_analise" }, + new Integer[]{}, + new Expression[]{}, + new String[]{ "prestador_id", "grupo_ecds_id" }, + new Field( "data" ).isEqual( data ), + null, + null, + null, + null ); + Virtual2DArray array = EXECUTER.executeQuery( select ); + if( array.columnLength() == 0 ) + { + return null; + } + Integer grupos[] = new Integer[ array.columnLength() ]; + for( int n = 0; n < grupos.length; n++ ) + { + grupos[ n ] = ( Integer ) array.get( n, 1 ); + } + return new Object[]{ data, array.get( 0, 0 ), grupos }; + } } + + \ No newline at end of file diff --git a/trunk/SIPRPSoft/src/siprp/medicina/locais_analise/LocaisAnaliseLogic.java b/trunk/SIPRPSoft/src/siprp/medicina/locais_analise/LocaisAnaliseLogic.java index 4c1dd8ac..eb4ed982 100644 --- a/trunk/SIPRPSoft/src/siprp/medicina/locais_analise/LocaisAnaliseLogic.java +++ b/trunk/SIPRPSoft/src/siprp/medicina/locais_analise/LocaisAnaliseLogic.java @@ -1,5 +1,7 @@ package siprp.medicina.locais_analise; +import java.util.Date; + import com.evolute.utils.data.IDObject; public final class LocaisAnaliseLogic @@ -33,4 +35,16 @@ public final class LocaisAnaliseLogic { return provider.getGruposEcdsByMarcacoes( marcacoesIds ); } + + protected void savePrestadorEGruposData( Date data, Integer prestadorId, Integer gruposIds[] ) + throws Exception + { + provider.savePrestadorEGruposData( data, prestadorId, gruposIds ); + } + + protected Object[] getDataPrestadorEGruposByData( Date data ) + throws Exception + { + return provider.getDataPrestadorEGruposByData( data ); + } } diff --git a/trunk/SIPRPSoft/src/siprp/medicina/locais_realizacao/LocaisRealizacaoDataProvider.java b/trunk/SIPRPSoft/src/siprp/medicina/locais_realizacao/LocaisRealizacaoDataProvider.java index 0cca4cb8..6d1c1bf0 100644 --- a/trunk/SIPRPSoft/src/siprp/medicina/locais_realizacao/LocaisRealizacaoDataProvider.java +++ b/trunk/SIPRPSoft/src/siprp/medicina/locais_realizacao/LocaisRealizacaoDataProvider.java @@ -504,7 +504,7 @@ public class LocaisRealizacaoDataProvider } Select select = new Select2( - new String[]{ "trabalhadoresEcdsDatas" }, + new String[]{ "trabalhadores_ecds_datas" }, new Integer[]{}, new Expression[]{}, new String[]{ "id" }, diff --git a/trunk/SIPRPSoft/src/siprp/update/UpdateList.java b/trunk/SIPRPSoft/src/siprp/update/UpdateList.java index c4ae7f2c..4faf22c7 100644 --- a/trunk/SIPRPSoft/src/siprp/update/UpdateList.java +++ b/trunk/SIPRPSoft/src/siprp/update/UpdateList.java @@ -29,7 +29,7 @@ public class UpdateList new siprp.update.updates.V7_5_To_V7_6(), new siprp.update.updates.V7_6_To_V7_7(), new siprp.update.updates.V7_7_To_V7_8(), new siprp.update.updates.V7_8_To_V7_9(), new siprp.update.updates.V7_9_To_V8_0(), new siprp.update.updates.V8_0_To_V8_1(), - new siprp.update.updates.V8_1_To_V8_2() }; + new siprp.update.updates.V8_1_To_V8_2(), new siprp.update.updates.V8_2_To_V8_3() }; protected static Executer EXECUTER; protected static double version = -1; diff --git a/trunk/SIPRPSoft/src/siprp/update/updates/V8_2_To_V8_3.java b/trunk/SIPRPSoft/src/siprp/update/updates/V8_2_To_V8_3.java new file mode 100644 index 00000000..df4b4e0a --- /dev/null +++ b/trunk/SIPRPSoft/src/siprp/update/updates/V8_2_To_V8_3.java @@ -0,0 +1,78 @@ +/* + * V8_12_To_V8_3.java + * + * Created on December 19, 2007, 3:12 PM + * + * To change this template, choose Tools | Template Manager + * and open the template in the editor. + */ + +package siprp.update.updates; + +import com.evolute.utils.Singleton; +import com.evolute.utils.db.DBManager; +import com.evolute.utils.db.Executer; +import com.evolute.utils.sql.Assignment; +import com.evolute.utils.sql.Field; + +/** + * + * @author fpalma + */ +public class V8_2_To_V8_3 + implements siprp.update.Update +{ + + /** + * Creates a new instance of V8_2_To_V8_3 + */ + public V8_2_To_V8_3() + { + } + + public String []listChanges() + { + return new String[]{ "Criar tabela para locais de an\u00e1lise" }; + } + + public double getStartVersion() + { + return 8.2; + } + + public double getEndVersion() + { + return 8.3; + } + + public void doUpdate() + throws Exception + { + DBManager dbm = ( DBManager ) Singleton.getInstance( Singleton.DEFAULT_DBMANAGER ); + Executer executer = dbm.getSharedExecuter(); + com.evolute.utils.sql.Update update = + new com.evolute.utils.sql.Update( + "CREATE TABLE trabalhadores_ecds_analise" + + "(" + + "id serial, " + + "data date NOT NULL, " + + "prestador_id int4 NOT NULL, " + + "grupo_ecds_id int4 NOT NULL, " + + "CONSTRAINT trabalhadores_ecds_analise_pkey PRIMARY KEY (id), " + + "CONSTRAINT trabalhadores_ecds_analise_grupo_ecds_id_fkey FOREIGN KEY (grupo_ecds_id) " + + " REFERENCES prt_grupos_protocolo (id) MATCH SIMPLE " + + " ON UPDATE NO ACTION ON DELETE NO ACTION, " + + "CONSTRAINT trabalhadores_ecds_analise_prestador_id_fkey FOREIGN KEY (prestador_id) " + + " REFERENCES prestadores (id) MATCH SIMPLE " + + " ON UPDATE NO ACTION ON DELETE NO ACTION " + + ") " + + "WITHOUT OIDS; " + + "ALTER TABLE trabalhadores_ecds_analise OWNER TO postgres;" ); + executer.executeQuery( update ); + } + + public String toString() + { + return "v" + getStartVersion() + " para v" + getEndVersion(); + } +}