From 2ff561973a452c96d28de659194ea6716f1290e9 Mon Sep 17 00:00:00 2001 From: Frederico Palma Date: Mon, 20 Jul 2009 01:01:58 +0000 Subject: [PATCH] git-svn-id: https://svn.coded.pt/svn/SIPRP@1068 bb69d46d-e84e-40c8-a05a-06db0d633741 --- .../companydataloaders/SIPRPDataLoader.java | 24 +-- .../higiene/relatorio/print/AreaToPrint.java | 8 +- .../print/RelatorioPrintDataProvider.java | 5 +- .../planoactuacao/print/AreaToPrint.java | 34 +++- .../print/LegislacaoAplicavelToPrint.java | 47 ++--- .../print/PlanoActuacaoPrintDataProvider.java | 161 +++++++++++++----- .../planoactuacao/print/RiscoToPrint.java | 6 +- .../planoactuacao/print/plano_actuacao.xsl | 125 ++++++++++++-- .../print/plano_actuacao_alargado.xsl | 125 ++++++++++++-- 9 files changed, 421 insertions(+), 114 deletions(-) diff --git a/trunk/SIPRPSoft/src/siprp/companydataloaders/SIPRPDataLoader.java b/trunk/SIPRPSoft/src/siprp/companydataloaders/SIPRPDataLoader.java index 3a3c69b3..21dd83e2 100644 --- a/trunk/SIPRPSoft/src/siprp/companydataloaders/SIPRPDataLoader.java +++ b/trunk/SIPRPSoft/src/siprp/companydataloaders/SIPRPDataLoader.java @@ -93,12 +93,12 @@ public class SIPRPDataLoader implements CompanyDataLoader // Singleton.setInstance( SingletonConstants.LOCAL_DB_NAME, "siprp_local_3" ); // Singleton.setInstance( SingletonConstants.LOCAL_DRIVER_NAME, "org.postgresql.Driver" ); // - Singleton.setInstance( SingletonConstants.LOCAL_USER, "postgres" ); - Singleton.setInstance( SingletonConstants.LOCAL_PASSWORD, "Typein" ); - Singleton.setInstance( SingletonConstants.LOCAL_URL_PREFIX, "jdbc:postgresql://" ); - Singleton.setInstance( SingletonConstants.LOCAL_URL, "10.158.2.2:5432" ); - Singleton.setInstance( SingletonConstants.LOCAL_DB_NAME, "siprp_local" ); - Singleton.setInstance( SingletonConstants.LOCAL_DRIVER_NAME, "org.postgresql.Driver" ); +// Singleton.setInstance( SingletonConstants.LOCAL_USER, "postgres" ); +// Singleton.setInstance( SingletonConstants.LOCAL_PASSWORD, "Typein" ); +// Singleton.setInstance( SingletonConstants.LOCAL_URL_PREFIX, "jdbc:postgresql://" ); +// Singleton.setInstance( SingletonConstants.LOCAL_URL, "10.158.2.2:5432" ); +// Singleton.setInstance( SingletonConstants.LOCAL_DB_NAME, "siprp_local" ); +// Singleton.setInstance( SingletonConstants.LOCAL_DRIVER_NAME, "org.postgresql.Driver" ); // Singleton.setInstance( SingletonConstants.LOCAL_USER, "postgres" ); // Singleton.setInstance( SingletonConstants.LOCAL_PASSWORD, "Typein" ); @@ -136,12 +136,12 @@ public class SIPRPDataLoader implements CompanyDataLoader // Singleton.setInstance( SingletonConstants.LOCAL_DB_NAME, "siprp_local3" ); // Singleton.setInstance( SingletonConstants.LOCAL_DRIVER_NAME, "org.postgresql.Driver" ); -// Singleton.setInstance( SingletonConstants.LOCAL_USER, "postgres" ); -// Singleton.setInstance( SingletonConstants.LOCAL_PASSWORD, "Typein" ); -// Singleton.setInstance( SingletonConstants.LOCAL_URL_PREFIX, "jdbc:postgresql://" ); -// Singleton.setInstance( SingletonConstants.LOCAL_URL, "localhost:5432" ); -// Singleton.setInstance( SingletonConstants.LOCAL_DB_NAME, "siprp_local" ); -// Singleton.setInstance( SingletonConstants.LOCAL_DRIVER_NAME, "org.postgresql.Driver" ); + Singleton.setInstance( SingletonConstants.LOCAL_USER, "postgres" ); + Singleton.setInstance( SingletonConstants.LOCAL_PASSWORD, "Typein" ); + Singleton.setInstance( SingletonConstants.LOCAL_URL_PREFIX, "jdbc:postgresql://" ); + Singleton.setInstance( SingletonConstants.LOCAL_URL, "localhost:5432" ); + Singleton.setInstance( SingletonConstants.LOCAL_DB_NAME, "siprp_local" ); + Singleton.setInstance( SingletonConstants.LOCAL_DRIVER_NAME, "org.postgresql.Driver" ); // Singleton.setInstance( SingletonConstants.LOCAL_USER, "postgres" ); // Singleton.setInstance( SingletonConstants.LOCAL_PASSWORD, "Typein" ); diff --git a/trunk/SIPRPSoft/src/siprp/higiene/relatorio/print/AreaToPrint.java b/trunk/SIPRPSoft/src/siprp/higiene/relatorio/print/AreaToPrint.java index c85b1b87..da9eb289 100644 --- a/trunk/SIPRPSoft/src/siprp/higiene/relatorio/print/AreaToPrint.java +++ b/trunk/SIPRPSoft/src/siprp/higiene/relatorio/print/AreaToPrint.java @@ -48,10 +48,10 @@ public class AreaToPrint { return 1; } - } - if( ordem != null ) - { - return ordem.compareTo( ( ( AreaToPrint ) o ).ordem ); + if( ordem != null ) + { + return ordem.compareTo( ( ( AreaToPrint ) o ).ordem ); + } } return 0; } diff --git a/trunk/SIPRPSoft/src/siprp/higiene/relatorio/print/RelatorioPrintDataProvider.java b/trunk/SIPRPSoft/src/siprp/higiene/relatorio/print/RelatorioPrintDataProvider.java index 7fe9eed1..44bcfed8 100644 --- a/trunk/SIPRPSoft/src/siprp/higiene/relatorio/print/RelatorioPrintDataProvider.java +++ b/trunk/SIPRPSoft/src/siprp/higiene/relatorio/print/RelatorioPrintDataProvider.java @@ -237,9 +237,10 @@ public class RelatorioPrintDataProvider new String[]{ "hs_relatorio_legislacao" }, new Integer[]{}, new Expression[]{}, - new String[]{ "hs_relatorio_legislacao.categoria", "hs_relatorio_legislacao.descricao" }, + new String[]{ "hs_relatorio_legislacao.categoria", "hs_relatorio_legislacao.descricao", + "COALESCE(hs_relatorio_legislacao.categoria,'A')"}, new Field( "hs_relatorio_legislacao.hs_relatorio_id" ).isEqual( relatorioId ), - new String[]{ "hs_relatorio_legislacao.categoria DESC" }, + new String[]{ "COALESCE(hs_relatorio_legislacao.categoria,'A')", "ordem" }, null, null, null ); diff --git a/trunk/SIPRPSoft/src/siprp/planoactuacao/print/AreaToPrint.java b/trunk/SIPRPSoft/src/siprp/planoactuacao/print/AreaToPrint.java index 1cb43ab6..36847ce6 100644 --- a/trunk/SIPRPSoft/src/siprp/planoactuacao/print/AreaToPrint.java +++ b/trunk/SIPRPSoft/src/siprp/planoactuacao/print/AreaToPrint.java @@ -5,16 +5,20 @@ import java.util.Vector; import org.jdom.Element; public class AreaToPrint - implements PrintableInterface + implements PrintableInterface, Comparable { protected String designacao; protected Vector riscos; + protected Integer ordem; + protected boolean generico; - public AreaToPrint( String designacao, Vector riscos ) + public AreaToPrint( String designacao, Vector riscos, Integer ordem, boolean generico ) { super(); this.designacao = designacao; this.riscos = riscos; + this.ordem = ordem; + this.generico = generico; } public String getDesignacao() @@ -41,6 +45,11 @@ public class AreaToPrint { riscos.add( risco ); } + + protected boolean isGenerico() + { + return generico; + } @Override public Element toJdomElement() throws Exception @@ -56,4 +65,25 @@ public class AreaToPrint return areaElement; } + @Override + public int compareTo(Object o) + { + if( o instanceof AreaToPrint ) + { + if( generico && !( ( AreaToPrint ) o ).generico ) + { + return -1; + } + else if( !generico && ( ( AreaToPrint ) o ).generico ) + { + return 1; + } + if( ordem != null ) + { + return ordem.compareTo( ( ( AreaToPrint ) o ).ordem ); + } + } + return 0; + } + } diff --git a/trunk/SIPRPSoft/src/siprp/planoactuacao/print/LegislacaoAplicavelToPrint.java b/trunk/SIPRPSoft/src/siprp/planoactuacao/print/LegislacaoAplicavelToPrint.java index 66850fd5..0d53ee46 100644 --- a/trunk/SIPRPSoft/src/siprp/planoactuacao/print/LegislacaoAplicavelToPrint.java +++ b/trunk/SIPRPSoft/src/siprp/planoactuacao/print/LegislacaoAplicavelToPrint.java @@ -7,38 +7,45 @@ import org.jdom.Element; public class LegislacaoAplicavelToPrint implements PrintableInterface { - protected Vector diplomas; + protected Vector diplomasGerais; + protected String[] nomesGruposEspecificos; + protected Vector[] diplomasEspecificos; - public LegislacaoAplicavelToPrint( Vector diplomas ) + public LegislacaoAplicavelToPrint( Vector diplomasGerais, + String[] nomesGruposEspecificos, Vector[] diplomasEspecificos ) { super(); - this.diplomas = diplomas; + this.diplomasGerais = diplomasGerais; + this.nomesGruposEspecificos = nomesGruposEspecificos; + this.diplomasEspecificos = diplomasEspecificos; } - public Vector getDiplomas() - { - return diplomas; - } - - public void setDiplomas( Vector diplomas ) - { - this.diplomas = diplomas; - } - - protected void addDiploma( String diploma ) - { - diplomas.add( diploma ); - } - @Override public Element toJdomElement() throws Exception { Element legislacaoAplicavelElement = new Element( "legislacao-aplicavel" ); - for( String diploma : diplomas ) + Element legislacaoGeralElement = new Element( "legislacao-geral" ); + for( String diploma : diplomasGerais ) { Element diplomaElement = new Element( "diploma" ); diplomaElement.setText( diploma ); - legislacaoAplicavelElement.addContent( diplomaElement ); + legislacaoGeralElement.addContent( diplomaElement ); + } + legislacaoAplicavelElement.addContent( legislacaoGeralElement ); + + for( int e = 0; e < nomesGruposEspecificos.length; e++ ) + { + Element legislacaoEspecificaElement = new Element( "legislacao-especifica" ); + Element designacaoElement = new Element( "designacao" ); + designacaoElement.setText( nomesGruposEspecificos[ e ] ); + legislacaoEspecificaElement.addContent( designacaoElement ); + for( String diploma : diplomasEspecificos[ e ] ) + { + Element diplomaElement = new Element( "diploma" ); + diplomaElement.setText( diploma ); + legislacaoEspecificaElement.addContent( diplomaElement ); + } + legislacaoAplicavelElement.addContent( legislacaoEspecificaElement ); } return legislacaoAplicavelElement; } diff --git a/trunk/SIPRPSoft/src/siprp/planoactuacao/print/PlanoActuacaoPrintDataProvider.java b/trunk/SIPRPSoft/src/siprp/planoactuacao/print/PlanoActuacaoPrintDataProvider.java index 22f1f31a..5325ff0e 100644 --- a/trunk/SIPRPSoft/src/siprp/planoactuacao/print/PlanoActuacaoPrintDataProvider.java +++ b/trunk/SIPRPSoft/src/siprp/planoactuacao/print/PlanoActuacaoPrintDataProvider.java @@ -1,5 +1,7 @@ package siprp.planoactuacao.print; +import java.util.Collections; +import java.util.Comparator; import java.util.Date; import java.util.HashMap; import java.util.Vector; @@ -24,6 +26,9 @@ public class PlanoActuacaoPrintDataProvider { private static final Object LOCK = new Object(); private static PlanoActuacaoPrintDataProvider instance = null; + protected static final Object UNCONTROLLED = "Incontrolado"; + protected static final Object CONTROLLED = "Controlado"; + protected static final Object INDETERMINATE = "Indeterminado"; protected final Executer WEB_EXECUTER; protected final Executer LOCAL_EXECUTER; @@ -79,7 +84,7 @@ public class PlanoActuacaoPrintDataProvider null ); Virtual2DArray array = LOCAL_EXECUTER.executeQuery( select ); - return ( ( Boolean ) array.get( 0, 0 ) ).booleanValue(); + return array.get( 0, 0 ) != null ? ( ( Boolean ) array.get( 0, 0 ) ).booleanValue() : false; } catch( Exception ex ) { @@ -207,47 +212,50 @@ public class PlanoActuacaoPrintDataProvider // return legislacao; // } - public LegislacaoAplicavelToPrint getLegislacaoAplicavel( Integer planoId ) - throws Exception -{ - Select select = - new Select2( - new String[]{ "hs_relatorio_legislacao" }, - new Integer[]{}, - new Expression[]{}, - new String[]{ "hs_relatorio_legislacao.categoria", "hs_relatorio_legislacao.descricao" }, - new Field( "hs_relatorio_legislacao.hs_relatorio_id" ).isEqual( planoId ), - new String[]{ "hs_relatorio_legislacao.categoria DESC" }, - null, - null, - null ); - Virtual2DArray array = LOCAL_EXECUTER.executeQuery( select ); - Vector diplomasGerais = new Vector(); - Vector nomes = new Vector(); - Vector> diplomas = new Vector>(); - String last = null; - for( int n = 0; n < array.columnLength(); n++ ) + public LegislacaoAplicavelToPrint getLegislacaoAplicavel( Integer relatorioId ) + throws Exception { - String categoria = ( String ) array.get( n, 0 ); - String descricao = ( String ) array.get( n, 1 ); - if( categoria == null || categoria.trim().length() == 0 ) - { - diplomasGerais.add( descricao ); - } - else + Select select = + new Select2( + new String[]{ "hs_relatorio_legislacao" }, + new Integer[]{}, + new Expression[]{}, + new String[]{ "hs_relatorio_legislacao.categoria", "hs_relatorio_legislacao.descricao", + "COALESCE(hs_relatorio_legislacao.categoria,'A')"}, + new Field( "hs_relatorio_legislacao.hs_relatorio_id" ).isEqual( relatorioId ), + new String[]{ "COALESCE(hs_relatorio_legislacao.categoria,'A')", "ordem" }, + null, + null, + null ); + Virtual2DArray array = LOCAL_EXECUTER.executeQuery( select ); + Vector diplomasGerais = new Vector(); + Vector nomes = new Vector(); + Vector> diplomas = new Vector>(); + String last = null; + for( int n = 0; n < array.columnLength(); n++ ) { - if( !categoria.equals( last ) ) + String categoria = ( String ) array.get( n, 0 ); + String descricao = ( String ) array.get( n, 1 ); + if( categoria == null || categoria.trim().length() == 0 ) { - nomes.add( categoria ); - diplomas.add( new Vector() ); + diplomasGerais.add( descricao ); + } + else + { + if( !categoria.equals( last ) ) + { + nomes.add( categoria ); + diplomas.add( new Vector() ); + } + last = categoria; + diplomas.lastElement().add( descricao ); } - diplomas.lastElement().add( descricao ); } + LegislacaoAplicavelToPrint legislacao = + new LegislacaoAplicavelToPrint( diplomasGerais, nomes.toArray( new String[ nomes.size() ] ), + diplomas.toArray( new Vector[ diplomas.size() ] )); + return legislacao; } - LegislacaoAplicavelToPrint legislacao = - new LegislacaoAplicavelToPrint( diplomasGerais); - return legislacao; -} public Vector getAreasToPrintByPlanoId( Integer planoId, boolean validacaoDl, boolean validacaoDns ) throws Exception @@ -261,7 +269,7 @@ public class PlanoActuacaoPrintDataProvider new String[]{ "plano_areas" }, new Integer[]{}, new Expression[]{}, - new String[]{ "id", "descricao" }, + new String[]{ "id", "descricao", "1" }, new Field( "plano_id" ).isEqual( planoId ), new String[]{ "id" }, null, @@ -276,7 +284,7 @@ public class PlanoActuacaoPrintDataProvider new String[]{ "hs_relatorio_area" }, new Integer[]{}, new Expression[]{}, - new String[]{ "id", "description" }, + new String[]{ "id", "description", "ordem" }, new Field( "relatorio_id" ).isEqual( planoId ).and( new Field( "deleted_date" ).isEqual( null ) ), new String[]{ "id" }, @@ -289,12 +297,35 @@ public class PlanoActuacaoPrintDataProvider { Integer areaId = ( Integer ) array.get( n, 0 ); String areaDescricao = ( String ) array.get( n, 1 ); + Integer ordem = ( Integer ) array.get( n, 2 ); + boolean generico = false; + if( !web ) + { + Select selectGen = + new Select2( + new String[]{ "hs_relatorio_posto" }, + new Integer[]{}, + new Expression[]{}, + new String[]{ "COUNT( hs_relatorio_posto.id )" }, + new Field( "hs_relatorio_posto.area_id" ).isEqual( areaId ).and( + new Field( "hs_relatorio_posto.is_principal" ).isEqual( true ) ), + null, + null, + null, + null ); + Virtual2DArray genArray = LOCAL_EXECUTER.executeQuery( selectGen ); + if( genArray.columnLength() > 0 && genArray.get( 0, 0 ) != null ) + { + generico = ( ( Number ) genArray.get( 0, 0 ) ).intValue() > 0; + } + } Vector riscos = getRiscosToPrintByAreaId( areaId, validacaoDl, validacaoDns ); if( riscos.size() > 0 ) { - areas.add( new AreaToPrint( areaDescricao, riscos ) ); + areas.add( new AreaToPrint( areaDescricao, riscos, ordem, generico ) ); } } + Collections.sort( areas ); return areas; } @@ -353,7 +384,7 @@ public class PlanoActuacaoPrintDataProvider dataFim != null ? new DataToPrint( "data-prevista-conclusao", dataFim ) : null, parecerDl, parecerDns, - verificacaoSiprp ) ); + verificacaoSiprp, null, null ) ); } } else @@ -388,6 +419,8 @@ public class PlanoActuacaoPrintDataProvider Vector riscosVector = new Vector(); HashMap> riscosIdMap = new HashMap>(); HashMap riscoPostoMap = new HashMap(); + HashMap valoresQuantitativos = new HashMap(); + HashMap valoresQualitativos = new HashMap(); for( int n = 0; n < array.columnLength(); n++ ) { Integer id = ( Integer ) array.get( n, 0 ); @@ -417,6 +450,8 @@ public class PlanoActuacaoPrintDataProvider } riscosIdMap.get( key ).add( id ); riscoPostoMap.put(id, posto); + valoresQuantitativos.put( key, risco ); + valoresQualitativos.put( key, ((String) array.get( n, 3)) ); } for( String risco : riscosVector ) { @@ -442,11 +477,53 @@ public class PlanoActuacaoPrintDataProvider null, null, null, - null ) ); + null, + valoresQuantitativos.get( risco ), + valoresQualitativos.get( risco ) ) ); } } } - + Collections.sort(riscos, new Comparator(){ + + @Override + public int compare(RiscoToPrint o1, RiscoToPrint o2) { + Integer o1Value = 1000; + Integer o2Value = 1000; + if( o1.valorQuantitativo != null ) + { + o1Value = -o1.valorQuantitativo; + } + else if(o1.valorQualitativo.equals(UNCONTROLLED)) + { + o1Value = 100; + } + else if(o1.valorQualitativo.equals(CONTROLLED)) + { + o1Value = 200; + } + else if(o1.valorQualitativo.equals(INDETERMINATE)) + { + o1Value = 300; + } + if( o2.valorQuantitativo != null ) + { + o2Value = -o2.valorQuantitativo; + } + else if(o2.valorQualitativo.equals(UNCONTROLLED)) + { + o2Value = 100; + } + else if(o2.valorQualitativo.equals(CONTROLLED)) + { + o2Value = 200; + } + else if(o2.valorQualitativo.equals(INDETERMINATE)) + { + o2Value = 300; + } + return o1Value.compareTo(o2Value); + } + }); return riscos; } diff --git a/trunk/SIPRPSoft/src/siprp/planoactuacao/print/RiscoToPrint.java b/trunk/SIPRPSoft/src/siprp/planoactuacao/print/RiscoToPrint.java index e904dcd9..1f56e97f 100644 --- a/trunk/SIPRPSoft/src/siprp/planoactuacao/print/RiscoToPrint.java +++ b/trunk/SIPRPSoft/src/siprp/planoactuacao/print/RiscoToPrint.java @@ -17,11 +17,13 @@ public class RiscoToPrint protected String parecerDl; protected String parecerDns; protected String verificacaoSiprp; + protected Integer valorQuantitativo; + protected String valorQualitativo; public RiscoToPrint( String descricao, String valor, Vector medidas, String responsavel, String recursos, DataToPrint dataPrevistaInicio, DataToPrint dataPrevistaConclusao, - String parecerDl, String parecerDns, String verificacaoSiprp ) + String parecerDl, String parecerDns, String verificacaoSiprp, Integer valorQuantitativo, String valorQualitativo ) { super(); this.descricao = descricao; @@ -34,6 +36,8 @@ public class RiscoToPrint this.parecerDl = parecerDl; this.parecerDns = parecerDns; this.verificacaoSiprp = verificacaoSiprp; + this.valorQuantitativo = valorQuantitativo; + this.valorQualitativo = valorQualitativo; } @Override diff --git a/trunk/SIPRPSoft/src/siprp/planoactuacao/print/plano_actuacao.xsl b/trunk/SIPRPSoft/src/siprp/planoactuacao/print/plano_actuacao.xsl index 2e624a5e..631a080d 100644 --- a/trunk/SIPRPSoft/src/siprp/planoactuacao/print/plano_actuacao.xsl +++ b/trunk/SIPRPSoft/src/siprp/planoactuacao/print/plano_actuacao.xsl @@ -25,8 +25,8 @@ - - + + @@ -98,7 +98,6 @@   -     @@ -820,16 +819,112 @@   5. LEGISLAÇÃO APLICÁVEL     - - - - - - - . - ; - - - + + 5.1 Legislação de aplicação geral   + + + + + + + + + + + • + + + + + + + + . + + + ; + + + + + + + + +   + + + 5.2 Legislação específica   + + + + + + + + + + + + + + + • + + + + + + + + . + + + ; + + + + + + + + + +   +       @@ -936,7 +1031,7 @@ - + @@ -1033,7 +1128,7 @@ Data prevista de conclusão - Verificação SIPRP + Verificação SIPRP diff --git a/trunk/SIPRPSoft/src/siprp/planoactuacao/print/plano_actuacao_alargado.xsl b/trunk/SIPRPSoft/src/siprp/planoactuacao/print/plano_actuacao_alargado.xsl index e0a66b29..b6d14b8d 100644 --- a/trunk/SIPRPSoft/src/siprp/planoactuacao/print/plano_actuacao_alargado.xsl +++ b/trunk/SIPRPSoft/src/siprp/planoactuacao/print/plano_actuacao_alargado.xsl @@ -88,8 +88,6 @@ Plano de Actuação       - @@ -98,7 +96,6 @@   -     @@ -821,16 +818,112 @@   5. LEGISLAÇÃO APLICÁVEL     - - - - - - - . - ; - - - + + 5.1 Legislação de aplicação geral   + + + + + + + + + + + • + + + + + + + + . + + + ; + + + + + + + + +   + + + 5.2 Legislação específica   + + + + + + + + + + + + + + + • + + + + + + + + . + + + ; + + + + + + + + + +   +       @@ -1036,13 +1129,13 @@ Data prevista de conclusão - Parecer DL + Parecer DL - Parecer DNS + Parecer DNS - Verificação SIPRP + Verificação SIPRP