From 376445fe057a63b645c52bee8618f733f39d064e Mon Sep 17 00:00:00 2001 From: Diogo Neves Date: Wed, 16 Dec 2009 18:49:25 +0000 Subject: [PATCH] package de utilidades para impressao. git-svn-id: https://svn.coded.pt/svn/SIPRP@1135 bb69d46d-e84e-40c8-a05a-06db0d633741 --- .../src/java/utils/print/AreaToPrint.java | 89 ++ .../src/java/utils/print/DataToPrint.java | 66 + .../src/java/utils/print/EmpresaToPrint.java | 67 + .../print/LegislacaoAplicavelToPrint.java | 53 + .../src/java/utils/print/MedidaToPrint.java | 58 + .../utils/print/PlanoActuacaoPDFCreator.java | 56 + .../print/PlanoActuacaoPrintDataProvider.java | 1233 +++++++++++++++++ .../utils/print/PlanoActuacaoToPrint.java | 134 ++ .../src/java/utils/print/PostoToPrint.java | 36 + .../java/utils/print/PrintableInterface.java | 8 + .../src/java/utils/print/RiscoToPrint.java | 188 +++ 11 files changed, 1988 insertions(+) create mode 100644 trunk/PlanosActuacao/src/java/utils/print/AreaToPrint.java create mode 100644 trunk/PlanosActuacao/src/java/utils/print/DataToPrint.java create mode 100644 trunk/PlanosActuacao/src/java/utils/print/EmpresaToPrint.java create mode 100644 trunk/PlanosActuacao/src/java/utils/print/LegislacaoAplicavelToPrint.java create mode 100644 trunk/PlanosActuacao/src/java/utils/print/MedidaToPrint.java create mode 100644 trunk/PlanosActuacao/src/java/utils/print/PlanoActuacaoPDFCreator.java create mode 100644 trunk/PlanosActuacao/src/java/utils/print/PlanoActuacaoPrintDataProvider.java create mode 100644 trunk/PlanosActuacao/src/java/utils/print/PlanoActuacaoToPrint.java create mode 100644 trunk/PlanosActuacao/src/java/utils/print/PostoToPrint.java create mode 100644 trunk/PlanosActuacao/src/java/utils/print/PrintableInterface.java create mode 100644 trunk/PlanosActuacao/src/java/utils/print/RiscoToPrint.java diff --git a/trunk/PlanosActuacao/src/java/utils/print/AreaToPrint.java b/trunk/PlanosActuacao/src/java/utils/print/AreaToPrint.java new file mode 100644 index 00000000..11c0be69 --- /dev/null +++ b/trunk/PlanosActuacao/src/java/utils/print/AreaToPrint.java @@ -0,0 +1,89 @@ +package utils.print; + +import java.util.Vector; + +import org.jdom.Element; + +public class AreaToPrint + implements PrintableInterface, Comparable +{ + protected String designacao; + protected Vector riscos; + protected Integer ordem; + protected boolean generico; + + 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() + { + return designacao; + } + + public void setDesignacao( String designacao ) + { + this.designacao = designacao; + } + + public Vector getRiscos() + { + return riscos; + } + + public void setRiscos( Vector riscos ) + { + this.riscos = riscos; + } + + public void addRisco( RiscoToPrint risco ) + { + riscos.add( risco ); + } + + protected boolean isGenerico() + { + return generico; + } + + @Override + public Element toJdomElement() throws Exception + { + Element areaElement = new Element( "area" ); + Element designacaoElement = new Element( "designacao" ); + designacaoElement.setText( designacao ); + areaElement.addContent( designacaoElement ); + for( RiscoToPrint risco : riscos ) + { + areaElement.addContent( risco.toJdomElement() ); + } + 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 ( ( ( AreaToPrint ) o ).ordem == null ) ? -1 : ordem.compareTo( ( ( AreaToPrint ) o ).ordem ); + } + } + return 0; + } + +} diff --git a/trunk/PlanosActuacao/src/java/utils/print/DataToPrint.java b/trunk/PlanosActuacao/src/java/utils/print/DataToPrint.java new file mode 100644 index 00000000..cc10e7ea --- /dev/null +++ b/trunk/PlanosActuacao/src/java/utils/print/DataToPrint.java @@ -0,0 +1,66 @@ +package utils.print; + +import java.util.Calendar; +import java.util.Date; + +import org.jdom.Element; + +import com.evolute.utils.date.DateUtils; + +public class DataToPrint + implements PrintableInterface +{ + protected String tag; + protected Date data; + + public DataToPrint( String tag, Date data ) + { + super(); + this.tag = tag; + this.data = data; + } + + @Override + public Element toJdomElement() throws Exception + { + Element dataElement = new Element( tag ); + Calendar cal = Calendar.getInstance(); + cal.setTime( data ); + int ano = cal.get( Calendar.YEAR ); + int mes = cal.get( Calendar.MONTH ); + int dia = cal.get( Calendar.DAY_OF_MONTH ); + Element anoElement = new Element( "ano" ); + anoElement.setText( "" + ano ); + dataElement.addContent( anoElement ); + Element mesElement = new Element( "mes" ); + mesElement.setText( "" + ( mes + 1 ) ); + dataElement.addContent( mesElement ); + Element mesExtensoElement = new Element( "mes-extenso" ); + mesExtensoElement.setText( DateUtils.MONTHS_FULL_PT[ mes ] ); + dataElement.addContent( mesExtensoElement ); + Element diaElement = new Element( "dia" ); + diaElement.setText( "" + dia ); + dataElement.addContent( diaElement ); + return dataElement; + } + + public String getTag() + { + return tag; + } + + public void setTag( String tag ) + { + this.tag = tag; + } + + public Date getData() + { + return data; + } + + public void setData( Date data ) + { + this.data = data; + } +} diff --git a/trunk/PlanosActuacao/src/java/utils/print/EmpresaToPrint.java b/trunk/PlanosActuacao/src/java/utils/print/EmpresaToPrint.java new file mode 100644 index 00000000..ecf1be41 --- /dev/null +++ b/trunk/PlanosActuacao/src/java/utils/print/EmpresaToPrint.java @@ -0,0 +1,67 @@ +package utils.print; + +import org.jdom.Element; + +public class EmpresaToPrint + implements PrintableInterface +{ + protected String designacaoSocial; + protected String logotipo; + protected String estabelecimento; + + public EmpresaToPrint( String designacaoSocial, String logotipo, + String estabelecimento ) + { + super(); + this.designacaoSocial = designacaoSocial; + this.logotipo = logotipo; + this.estabelecimento = estabelecimento; + } + + public String getDesignacaoSocial() + { + return designacaoSocial; + } + + public void setDesignacaoSocial( String designacaoSocial ) + { + this.designacaoSocial = designacaoSocial; + } + + public String getLogotipo() + { + return logotipo; + } + + public void setLogotipo( String logotipo ) + { + this.logotipo = logotipo; + } + + public String getEstabelecimento() + { + return estabelecimento; + } + + public void setEstabelecimento( String estabelecimento ) + { + this.estabelecimento = estabelecimento; + } + + @Override + public Element toJdomElement() throws Exception + { + Element empresaElement = new Element( "empresa" ); + Element designacaoSocialElement = new Element( "designacao-social" ); + designacaoSocialElement.setText( designacaoSocial ); + empresaElement.addContent( designacaoSocialElement ); + Element logotipoElement = new Element( "logotipo" ); + logotipoElement.setText( logotipo ); + empresaElement.addContent( logotipoElement ); + Element estabelecimentoElement = new Element( "estabelecimento" ); + estabelecimentoElement.setText( estabelecimento ); + empresaElement.addContent( estabelecimentoElement ); + return empresaElement; + } + +} diff --git a/trunk/PlanosActuacao/src/java/utils/print/LegislacaoAplicavelToPrint.java b/trunk/PlanosActuacao/src/java/utils/print/LegislacaoAplicavelToPrint.java new file mode 100644 index 00000000..2ba5da5d --- /dev/null +++ b/trunk/PlanosActuacao/src/java/utils/print/LegislacaoAplicavelToPrint.java @@ -0,0 +1,53 @@ +package utils.print; + +import java.util.Vector; + +import org.jdom.Element; + +public class LegislacaoAplicavelToPrint + implements PrintableInterface +{ + protected Vector diplomasGerais; + protected String[] nomesGruposEspecificos; + protected Vector[] diplomasEspecificos; + + public LegislacaoAplicavelToPrint( Vector diplomasGerais, + String[] nomesGruposEspecificos, Vector[] diplomasEspecificos ) + { + super(); + this.diplomasGerais = diplomasGerais; + this.nomesGruposEspecificos = nomesGruposEspecificos; + this.diplomasEspecificos = diplomasEspecificos; + } + + @Override + public Element toJdomElement() throws Exception + { + Element legislacaoAplicavelElement = new Element( "legislacao-aplicavel" ); + Element legislacaoGeralElement = new Element( "legislacao-geral" ); + for( String diploma : diplomasGerais ) + { + Element diplomaElement = new Element( "diploma" ); + diplomaElement.setText( diploma ); + 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/PlanosActuacao/src/java/utils/print/MedidaToPrint.java b/trunk/PlanosActuacao/src/java/utils/print/MedidaToPrint.java new file mode 100644 index 00000000..b9e40513 --- /dev/null +++ b/trunk/PlanosActuacao/src/java/utils/print/MedidaToPrint.java @@ -0,0 +1,58 @@ +package utils.print; + +import java.util.Vector; + +import org.jdom.Element; + +public class MedidaToPrint + implements PrintableInterface +{ + protected String descricao; + protected Vector postos; + + public MedidaToPrint( String descricao, Vector postos ) + { + super(); + this.descricao = descricao; + this.postos = postos; + } + + @Override + public Element toJdomElement() throws Exception + { + Element medidaElement = new Element( "medida" ); + Element descricaoElement = new Element( "descricao" ); + descricaoElement.setText( descricao ); + medidaElement.addContent( descricaoElement ); + for( PostoToPrint posto : postos ) + { + medidaElement.addContent( posto.toJdomElement() ); + } + return medidaElement; + } + + public String getDescricao() + { + return descricao; + } + + public void setDescricao( String descricao ) + { + this.descricao = descricao; + } + + public Vector getPostos() + { + return postos; + } + + public void setPostos( Vector postos ) + { + this.postos = postos; + } + + public void addPosto( PostoToPrint posto ) + { + postos.add( posto ); + } +} diff --git a/trunk/PlanosActuacao/src/java/utils/print/PlanoActuacaoPDFCreator.java b/trunk/PlanosActuacao/src/java/utils/print/PlanoActuacaoPDFCreator.java new file mode 100644 index 00000000..b7692a00 --- /dev/null +++ b/trunk/PlanosActuacao/src/java/utils/print/PlanoActuacaoPDFCreator.java @@ -0,0 +1,56 @@ +package utils.print; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.FileOutputStream; +import java.io.InputStream; + +import org.jdom.Document; +import org.jdom.output.Format; +import org.jdom.output.XMLOutputter; + +import siprp.Main; +import siprp.util.fop.PDFCreator; + +import com.evolute.utils.xml.XSLTransformer; + +public class PlanoActuacaoPDFCreator +{ + + public byte[] createPDF( Integer planoId, boolean web ) throws Exception + { + PlanoActuacaoToPrint plano = PlanoActuacaoPrintDataProvider.getProvider( web ).getPlanoToPrint( planoId ); + Document foDoc = new Document( plano.toJdomElement() ); + XMLOutputter outputter = new XMLOutputter(Format.getPrettyFormat()); + ByteArrayOutputStream foBaos = new ByteArrayOutputStream(); + outputter.output( foDoc, foBaos ); + + + byte fo[] = + applyTemplate( + getClass().getClassLoader().getResourceAsStream( + PlanoActuacaoPrintDataProvider.getProvider( web ).empresaUsaPlanoAlargadoPorPlanoId( planoId ) ? + "siprp/planoactuacao/print/plano_actuacao_alargado.xsl" + : "siprp/planoactuacao/print/plano_actuacao.xsl" ), + new ByteArrayInputStream( foBaos.toByteArray() ) ); + + +// FileOutputStream fos = new FileOutputStream("/home/jneto/Desktop/a.fo"); +// fos.write(fo); + + + PDFCreator.setUserConfig(Main.fopConfigFile); + PDFCreator pdfCreator = PDFCreator.getPDFCreator(); + + byte pdf[] = pdfCreator.createPdfFromFo( fo ); + return pdf; + } + + public byte[] applyTemplate( InputStream xsl, InputStream dataStream ) throws Exception + { + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + XSLTransformer.getXSLTransformer().transform( dataStream, xsl, baos ); + return baos.toByteArray(); + } + +} diff --git a/trunk/PlanosActuacao/src/java/utils/print/PlanoActuacaoPrintDataProvider.java b/trunk/PlanosActuacao/src/java/utils/print/PlanoActuacaoPrintDataProvider.java new file mode 100644 index 00000000..d8c08889 --- /dev/null +++ b/trunk/PlanosActuacao/src/java/utils/print/PlanoActuacaoPrintDataProvider.java @@ -0,0 +1,1233 @@ +package utils.print; + +import com.evolute.utils.Singleton; +import com.evolute.utils.arrays.Virtual2DArray; +import com.evolute.utils.data.Mappable; +import com.evolute.utils.data.MappableObject; +import com.evolute.utils.db.DBManager; +import com.evolute.utils.db.Executer; +import com.evolute.utils.sql.BlobUpdate; +import java.util.Date; + + +import com.evolute.utils.sql.Expression; +import com.evolute.utils.sql.Field; +import com.evolute.utils.sql.Select; +import com.evolute.utils.sql.Select2; +import db.DBConstants; +import db.PlanoActuacaoDBInit; +import db.providers.GenericDataProvider; +import java.util.Collections; +import java.util.Comparator; +import java.util.HashMap; +import java.util.Vector; + + +public class PlanoActuacaoPrintDataProvider extends GenericDataProvider +{ + + 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; + + protected final boolean web; + + public PlanoActuacaoPrintDataProvider( boolean web ) + throws Exception + { + this.web = web; + if( Singleton.getInstance( DBConstants.WEB_DBMANAGER ) == null ) + { + PlanoActuacaoDBInit.initDB( web ); + } + DBManager WEB_DBMANAGER = ( DBManager ) Singleton.getInstance( DBConstants.WEB_DBMANAGER ); + WEB_EXECUTER = WEB_DBMANAGER.getSharedExecuter( this ); + DBManager LOCAL_DBMANAGER = ( DBManager ) Singleton.getInstance( DBConstants.LOCAL_DBMANAGER ); + LOCAL_EXECUTER = LOCAL_DBMANAGER.getSharedExecuter( this ); + } + + public static PlanoActuacaoPrintDataProvider getProvider( boolean web ) + throws Exception + { + synchronized( LOCK ) + { + if( instance == null ) + { + instance = new PlanoActuacaoPrintDataProvider( web ); + } + } + return instance; + } + + public boolean empresaUsaPlanoAlargadoPorPlanoId( Integer planoId ) + throws Exception + { + try + { + Select select = + new Select2( + new String[]{ "hs_relatorio", "marcacoes_estabelecimento", "estabelecimentos", "empresas" }, + new Integer[]{ Select2.JOIN_INNER, Select2.JOIN_INNER, Select2.JOIN_INNER }, + new Expression[]{ + new Field( "hs_relatorio.marcacao_id" ).isEqual( new Field( "marcacoes_estabelecimento.id" ) ), + new Field( "marcacoes_estabelecimento.estabelecimento_id" ).isEqual( new Field( "estabelecimentos.id" ) ), + new Field( "estabelecimentos.empresa_id" ).isEqual( new Field( "empresas.id" ) ) + }, + new String[]{ "imprimir_tabela_alargada" }, + new Field( "hs_relatorio.id" ).isEqual( planoId ), + null, + null, + null, + null ); + Virtual2DArray array = LOCAL_EXECUTER.executeQuery( select ); + + return array.get( 0, 0 ) != null ? ( ( Boolean ) array.get( 0, 0 ) ).booleanValue() : false; + } + catch( Exception ex ) + { + return true; + } + } + + + public PlanoActuacaoToPrint getPlanoToPrint( Integer id ) + throws Exception + { + Virtual2DArray array; + if( web ) + { + Select select = + new Select2( + new String[]{ "planos_actuacao" }, + new Integer[]{}, + new Expression[]{}, + new String[]{ "empresa_id", "nome_empresa", + "estabelecimento_id", "nome_estabelecimento", + "data_relatorio", "data_visita", "observacoes_dl", + "observacoes_dns", "validacao_director_loja", + "validacao_dns" }, + new Field( "id" ).isEqual( id ), + null, + null, + null, + null ); + array = WEB_EXECUTER.executeQuery( select ); + } + else + { + Select select = + new Select2( + new String[]{ "hs_relatorio", "marcacoes_estabelecimento", "estabelecimentos", "empresas" }, + new Integer[]{ Select2.JOIN_INNER, Select2.JOIN_INNER, Select2.JOIN_INNER }, + new Expression[]{ + new Field( "hs_relatorio.marcacao_id" ).isEqual( new Field( "marcacoes_estabelecimento.id" ) ), + new Field( "marcacoes_estabelecimento.estabelecimento_id" ).isEqual( new Field( "estabelecimentos.id" ) ), + new Field( "estabelecimentos.empresa_id" ).isEqual( new Field( "empresas.id" ) ) + }, + new String[]{ "empresas.id", "empresas.designacao_social", + "estabelecimentos.id", "estabelecimentos.nome", + "hs_relatorio.data", "marcacoes_estabelecimento.data", "''", + "''", "false", + "false" }, + new Field( "hs_relatorio.id" ).isEqual( id ), + null, + null, + null, + null ); + array = LOCAL_EXECUTER.executeQuery( select ); + } + Integer empresaId = ( Integer ) array.get( 0, 0 ); + String nomeEmpresa = ( String ) array.get( 0, 1 ); + Integer estabelecimentoId = ( Integer ) array.get( 0, 2 ); + String nomeEstabelecimento = ( String ) array.get( 0, 3 ); + Integer logoId = getLogotipoIdForEmpresaId( empresaId ); + Date dataRelatorio = ( Date ) array.get( 0, 4 ); + Date dataVisita = ( Date ) array.get( 0, 5 ); + String observacoesDl = ( String ) array.get( 0, 6 ); + String observacoesDns = ( String ) array.get( 0, 7 ); + Boolean validacaoDl = ( Boolean ) array.get( 0, 8 ); + Boolean validacaoDns = ( Boolean ) array.get( 0, 9 ); + EmpresaToPrint empresa = new EmpresaToPrint( nomeEmpresa, + "http://www.evolute.pt:13080/SIPRPImages/image?id=" + logoId, +// "http://apdp/siprp/auchan_jumbo_lado.jpg", + nomeEstabelecimento ); + PlanoActuacaoToPrint plano = + new PlanoActuacaoToPrint( + empresa, + dataRelatorio != null ? new DataToPrint( "data-relatorio", dataRelatorio ) : null, + dataVisita != null ? new DataToPrint( "data-hs", dataVisita ) : null, + getLegislacaoAplicavel( id ), + getAreasToPrintByPlanoId( id, validacaoDl, validacaoDns ), + observacoesDl, + observacoesDns ); + return plano; + } + + public Integer getLogotipoIdForEmpresaId( Integer empresaId ) + throws Exception + { + Select select = + new Select2( + new String[]{ "empresas" }, + new Integer[]{}, + new Expression[]{}, + new String[]{ "empresa_logo_id" }, + new Field( "id" ).isEqual( empresaId ), + null, + null, + null, + null ); + Virtual2DArray array = LOCAL_EXECUTER.executeQuery( select ); + return array.columnLength() > 0 ? ( Integer ) array.get( 0, 0 ) : null; + } + +// 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 ).and( +// new Field( "hs_relatorio_legislacao.categoria" ).isEqual( null ) ), +// null, +// null, +// null, +// null ); +// Virtual2DArray array = LOCAL_EXECUTER.executeQuery( select ); +// Vector diplomas = new Vector(); +// for( int n = 0; n < array.columnLength(); n++ ) +// { +// String descricao = ( String ) array.get( n, 0 ); +// diplomas.add( descricao ); +// } +// LegislacaoAplicavelToPrint legislacao = +// new LegislacaoAplicavelToPrint( diplomas ); +// +// return legislacao; +// } + + public LegislacaoAplicavelToPrint getLegislacaoAplicavel( Integer relatorioId ) + 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", + "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++ ) + { + 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 + { + if( !categoria.equals( last ) ) + { + nomes.add( categoria ); + diplomas.add( new Vector() ); + } + last = categoria; + diplomas.lastElement().add( descricao ); + } + } + LegislacaoAplicavelToPrint legislacao = + new LegislacaoAplicavelToPrint( diplomasGerais, nomes.toArray( new String[ nomes.size() ] ), + diplomas.toArray( new Vector[ diplomas.size() ] )); + return legislacao; + } + + public Vector getAreasToPrintByPlanoId( Integer planoId, boolean validacaoDl, boolean validacaoDns ) + throws Exception + { + Virtual2DArray array; + Vector areas = new Vector(); + if( web ) + { + Select select = + new Select2( + new String[]{ "plano_areas" }, + new Integer[]{}, + new Expression[]{}, + new String[]{ "id", "descricao", "1" }, + new Field( "plano_id" ).isEqual( planoId ), + new String[]{ "id" }, + null, + null, + null ); + array = WEB_EXECUTER.executeQuery( select ); + } + else + { + Select select = + new Select2( + new String[]{ "hs_relatorio_area" }, + new Integer[]{}, + new Expression[]{}, + new String[]{ "id", "description", "ordem" }, + new Field( "relatorio_id" ).isEqual( planoId ).and( + new Field( "deleted_date" ).isEqual( null ) ), + new String[]{ "id" }, + null, + null, + null ); + array = LOCAL_EXECUTER.executeQuery( select ); + } + for( int n = 0; n < array.columnLength(); n++ ) + { + 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, ordem, generico ) ); + } + } + Collections.sort( areas ); + return areas; + } + + public Vector getRiscosToPrintByAreaId( Integer areaId, boolean validacaoDl, boolean validacaoDns ) + throws Exception + { + Virtual2DArray array; + Vector riscos = new Vector(); + if( web ) + { + Select select = + new Select2( + new String[]{ "plano_riscos" }, + new Integer[]{}, + new Expression[]{}, + new String[]{ "id", "descricao", "valor", "responsavel_execucao", + "recursos_necessarios", "data_inicio", "data_fim", + "parecer_dl", "parecer_dns", "verificacao_siprp"}, + new Field( "area_id" ).isEqual( areaId ).and( + new Field( "activo" ).isEqual( "y" ) ), + new String[]{ "id" }, + null, + null, + null ); + array = WEB_EXECUTER.executeQuery( select ); + for( int n = 0; n < array.columnLength(); n++ ) + { + Integer id = ( Integer ) array.get( n, 0 ); + String descricao = ( String ) array.get( n, 1 ); + Integer valor = ( Integer ) array.get( n, 2 ); + String responsavelExecucao = ( String ) array.get( n, 3 ); + String recursosNecessarios = ( String ) array.get( n, 4 ); + Date dataInicio = ( Date ) array.get( n, 5 ); + Date dataFim = ( Date ) array.get( n, 6 ); + String parecerDl = ( String ) array.get( n, 7 ); + if( ( parecerDl == null || parecerDl.trim().length() == 0 ) + && validacaoDl ) + { + parecerDl = "De acordo"; + } + String parecerDns = ( String ) array.get( n, 8 ); + if( ( parecerDns == null || parecerDns.trim().length() == 0 ) + && validacaoDns ) + { + parecerDns = "De acordo"; + } + String verificacaoSiprp = ( String ) array.get( n, 9 ); + riscos.add( + new RiscoToPrint( + descricao, + valor+"", + getMedidasToPrintByRiscoId( id ), + responsavelExecucao, + recursosNecessarios, + dataInicio != null ? new DataToPrint( "data-prevista-inicio", dataInicio ) : null, + dataFim != null ? new DataToPrint( "data-prevista-conclusao", dataFim ) : null, + parecerDl, + parecerDns, + verificacaoSiprp, null, null ) ); + } + } + else + { + Select select = + new Select2( + new String[]{ "hs_relatorio_risco", "hs_relatorio_posto_risco", "hs_relatorio_posto", "hs_relatorio_risco_valor_qualitativo" }, + new Integer[]{ Select2.JOIN_INNER, Select2.JOIN_INNER, Select2.JOIN_LEFT_OUTER }, + new Expression[]{ + new Field( "hs_relatorio_risco.id" ).isEqual( new Field( "hs_relatorio_posto_risco.risco_id" ) ), + new Field( "hs_relatorio_posto_risco.posto_id" ).isEqual( new Field( "hs_relatorio_posto.id" ) ), + new Field( "hs_relatorio_posto_risco.valor_qualitativo_id" ).isEqual(new Field("hs_relatorio_risco_valor_qualitativo.id")) + }, + new String[]{ "hs_relatorio_risco.id", + "hs_relatorio_risco.description", + "hs_relatorio_posto_risco.probabilidade * hs_relatorio_posto_risco.severidade", + "hs_relatorio_risco_valor_qualitativo.description", + "hs_relatorio_posto.id", + "null", + "null", + "null", + "null", + "null" }, + new Field( "hs_relatorio_posto.area_id" ).isEqual( areaId ).and( + new Field( "hs_relatorio_risco.deleted_date" ).isEqual( null ) ).and( + new Field( "hs_relatorio_posto.deleted_date" ).isEqual( null ) ), + new String[]{ "hs_relatorio_risco.id" }, + null, + null, + null ); + array = LOCAL_EXECUTER.executeQuery( select ); + 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 ); + String descricao = ( String ) array.get( n, 1 ); + Integer risco = ( Integer ) array.get( n, 2 ); + String risco_qual = ((String) array.get( n, 3)); + if(risco_qual!=null){ + risco_qual = risco_qual.substring(0, 3).toUpperCase(); + } + Integer posto = ( Integer ) array.get( n, 4 ); + + String finalRisco; + + if(risco!=null){ + finalRisco = ""+risco; + }else if(risco_qual!=null){ + finalRisco = ""+risco_qual; + }else{ + continue; + } + + String key = descricao + "_" + finalRisco; + if( !riscosIdMap.containsKey( key ) ) + { + riscosIdMap.put( key, new Vector() ); + riscosVector.add( key ); + } + 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 ) + { + int index = risco.lastIndexOf( "_" ); + String descricao = risco.substring( 0, index ); + String valor = risco.substring( index + 1, risco.length() ) ; + Vector medidas = new Vector(); + for( Integer id : riscosIdMap.get( risco ) ) + { + Integer posto = riscoPostoMap.get(id); + medidas.addAll( getMedidasToPrintByRiscoId( id , posto) ); + } + if( medidas.size() > 0 ) + { + riscos.add( + new RiscoToPrint( + descricao, + valor, + medidas, + null, + null, + 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 ( UNCONTROLLED.equals( o1.valorQualitativo ) ) + { + o1Value = 100; + } + else if ( CONTROLLED.equals( o1.valorQualitativo ) ) + { + o1Value = 200; + } + else if ( INDETERMINATE.equals( o1.valorQualitativo ) ) + { + o1Value = 300; + } + + if( o2.valorQuantitativo != null ) + { + o2Value = -o2.valorQuantitativo; + } + else if ( UNCONTROLLED.equals( o2.valorQualitativo ) ) + { + o2Value = 100; + } + else if ( CONTROLLED.equals( o2.valorQualitativo ) ) + { + o2Value = 200; + } + else if ( INDETERMINATE.equals( o2.valorQualitativo ) ) + { + o2Value = 300; + } + return o1Value.compareTo(o2Value); + } + }); + return riscos; + } + + public Vector getMedidasToPrintByRiscoId( Integer riscoId) throws Exception{ + return getMedidasToPrintByRiscoId(riscoId, null); + } + + public Vector getMedidasToPrintByRiscoId( Integer riscoId, Integer posto ) + throws Exception + { + Vector medidas = new Vector(); + Virtual2DArray array; + if( web ) + { + Select select = + new Select2( + new String[]{ "plano_medidas" }, + new Integer[]{}, + new Expression[]{}, + new String[]{ "id", "descricao" }, + new Field( "risco_id" ).isEqual( riscoId ), + new String[]{ "id" }, + null, + null, + null ); + array = WEB_EXECUTER.executeQuery( select ); + } + else + { + Expression filter = new Field( "hs_relatorio_medida.risco_id" ).isEqual( riscoId ).and( + new Field( "hs_relatorio_medida.deleted_date" ).isEqual( null ) ) + .and(new Field("hs_relatorio_medida.description").isDifferent("")); + + if(posto!=null){ + filter = filter.and(new Field("hs_relatorio_posto_medida.posto_id").isEqual(posto)); + } + + Select select = + new Select2( + new String[]{"hs_relatorio_medida", "hs_relatorio_posto_medida"}, + new Integer[]{Select2.JOIN_INNER}, + new Expression[]{new Field("hs_relatorio_medida.id").isEqual(new Field("hs_relatorio_posto_medida.medida_id"))}, + new String[]{ "hs_relatorio_medida.id", "hs_relatorio_medida.description", "hs_relatorio_posto_medida.is_plano_actuacao" }, + filter, + new String[]{ "hs_relatorio_medida.id" }, + null, + null, + null ); + array = LOCAL_EXECUTER.executeQuery( select ); + } + for( int n = 0; n < array.columnLength(); n++ ) + { + Integer id = ( Integer ) array.get( n, 0 ); + String descricao = ( String ) array.get( n, 1 ); + Boolean isPlanoActuacao = false; + if ( ! web ) + { + isPlanoActuacao = ( Boolean ) array.get( n, 2 ); + } + + Vector postos = getPostosToPrintByMedidaId( id ); + if( postos.size() > 0 && isPlanoActuacao) + { + medidas.add( new MedidaToPrint( descricao, postos ) ); + } + } + return medidas; + } + + public Vector getPostosToPrintByMedidaId( Integer medidaId ) + throws Exception + { + Vector postos = new Vector(); + Virtual2DArray array; + if( web ) + { + Select select = + new Select2( + new String[]{ "plano_postos_trabalho" }, + new Integer[]{}, + new Expression[]{}, + new String[]{ "id", "descricao" }, + new Field( "medida_id" ).isEqual( medidaId ), + new String[]{ "id" }, + null, + null, + null ); + array = WEB_EXECUTER.executeQuery( select ); + } + else + { + Select select = + new Select2( + new String[]{ "hs_relatorio_posto", "hs_relatorio_posto_medida" }, + new Integer[]{ Select2.JOIN_INNER }, + new Expression[]{ + new Field( "hs_relatorio_posto.id" ).isEqual( new Field( "hs_relatorio_posto_medida.posto_id" ) ) + }, + new String[]{ "hs_relatorio_posto.id", "hs_relatorio_posto.description" }, + new Field( "hs_relatorio_posto_medida.medida_id" ).isEqual( medidaId ), + new String[]{ "hs_relatorio_posto.id" }, + null, + null, + null ); + array = LOCAL_EXECUTER.executeQuery( select ); + } + for( int n = 0; n < array.columnLength(); n++ ) + { + String descricao = ( String ) array.get( n, 1 ); + postos.add( new PostoToPrint( descricao ) ); + } + return postos; + } + + /** + * Para fazer dump dos logotipos para converter para jpeg + */ + public Mappable[] getLogotipos() + throws Exception + { + Select select = + new Select2( + new String[]{ "image" }, + new Integer[]{}, + new Expression[]{}, + new String[]{ "id", "image_data" }, + null, + null, + null, + null, + null ); + Virtual2DArray array = LOCAL_EXECUTER.executeQuery( select ); + Mappable logotipos[] = new Mappable[ array.columnLength() ]; + for( int n = 0; n < logotipos.length; n++ ) + { + Integer id = ( Integer ) array.get( n, 0 ); + byte data[] = ( byte[] ) array.get( n, 1 ); + logotipos[ n ] = + new MappableObject( id, data ); + } + return logotipos; + } + + /** + * Para fazer import dos logotipos convertidos para jpeg + */ + public void updateLogotipo( Integer id, byte[] data ) + throws Exception + { + BlobUpdate update = + new BlobUpdate( "image", "image_data", data, new Field( "id" ).isEqual( id ) ); + LOCAL_EXECUTER.executeQuery( update ); + } + + +// 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 boolean web; +// +// public PlanoActuacaoPrintDataProvider( boolean web ) throws Exception +// { +// this.web = web; +// } +// +// public static PlanoActuacaoPrintDataProvider getProvider( boolean web ) +// throws Exception +// { +// synchronized( LOCK ) +// { +// if( instance == null ) +// { +// instance = new PlanoActuacaoPrintDataProvider( web ); +// } +// } +// return instance; +// } +// +// public boolean empresaUsaPlanoAlargadoPorPlanoId( Integer planoId ) +// throws Exception +// { +// try +// { +// Select select = new Select2( +// new String[]{ "hs_relatorio", "marcacoes_estabelecimento", "estabelecimentos", "empresas" }, +// new Integer[]{ Select2.JOIN_INNER, Select2.JOIN_INNER, Select2.JOIN_INNER }, +// new Expression[]{ +// new Field( "hs_relatorio.marcacao_id" ).isEqual( new Field( "marcacoes_estabelecimento.id" ) ), +// new Field( "marcacoes_estabelecimento.estabelecimento_id" ).isEqual( new Field( "estabelecimentos.id" ) ), +// new Field( "estabelecimentos.empresa_id" ).isEqual( new Field( "empresas.id" ) ) +// }, +// new String[]{ "imprimir_tabela_alargada" }, +// new Field( "hs_relatorio.id" ).isEqual( planoId ), +// null, +// null, +// null, +// null +// ); +// Statement LOCAL_EXECUTER = createStatementLocal(); +// ResultSet rs = LOCAL_EXECUTER.executeQuery( select.toString() ); +// +// if ( rs.first() ) +// { +// Boolean imp = rs.getBoolean( "imprimir_tabela_alargada" ); +// if ( imp == null ) +// { +// imp = false; +// } +// return imp; +// } +//// return array.get( 0, 0 ) != null ? ( ( Boolean ) array.get( 0, 0 ) ).booleanValue() : false; +// } +// catch( Exception ex ) +// { +// ex.printStackTrace( ); +// } +// return true; +// } +// +// +// public PlanoActuacaoToPrint getPlanoToPrint( Integer id ) +// throws Exception +// { +// ResultSet array; +// Statement WEB_EXECUTER = createStatement(); +// Statement LOCAL_EXECUTER = createStatementLocal(); +// if( web ) +// { +// Select select = new Select2( +// new String[]{ "planos_actuacao" }, +// new Integer[]{}, +// new Expression[]{}, +// new String[]{ "empresa_id", "nome_empresa", +// "estabelecimento_id", "nome_estabelecimento", +// "data_relatorio", "data_visita", "observacoes_dl", +// "observacoes_dns", "validacao_director_loja", +// "validacao_dns" }, +// new Field( "id" ).isEqual( id ), +// null, null, null, null +// ); +// +// array = WEB_EXECUTER.executeQuery( select.toString() ); +// } +// else +// { +// Select select = +// new Select2( +// new String[]{ "hs_relatorio", "marcacoes_estabelecimento", "estabelecimentos", "empresas" }, +// new Integer[]{ Select2.JOIN_INNER, Select2.JOIN_INNER, Select2.JOIN_INNER }, +// new Expression[]{ +// new Field( "hs_relatorio.marcacao_id" ).isEqual( new Field( "marcacoes_estabelecimento.id" ) ), +// new Field( "marcacoes_estabelecimento.estabelecimento_id" ).isEqual( new Field( "estabelecimentos.id" ) ), +// new Field( "estabelecimentos.empresa_id" ).isEqual( new Field( "empresas.id" ) ) +// }, +// new String[]{ "empresas.id", "empresas.designacao_social", +// "estabelecimentos.id", "estabelecimentos.nome", +// "hs_relatorio.data", "marcacoes_estabelecimento.data", "''", +// "''", "false", +// "false" }, +// new Field( "hs_relatorio.id" ).isEqual( id ), +// null, +// null, +// null, +// null ); +// array = LOCAL_EXECUTER.executeQuery( select.toString() ); +// } +// +// if ( array.first() ) +// { +// Integer empresaId = array.getInt( 0 ); +// String nomeEmpresa = array.getString( 1 ); +// Integer estabelecimentoId = array.getInt( 2 ); +// String nomeEstabelecimento = array.getString( 3 ); +// Integer logoId = getLogotipoIdForEmpresaId( empresaId ); +// Date dataRelatorio = array.getDate( 4 ); +// Date dataVisita = array.getDate( 5 ); +// String observacoesDl = array.getString( 6 ); +// String observacoesDns = array.getString( 7 ); +// Boolean validacaoDl = array.getBoolean( 8 ); +// Boolean validacaoDns = array.getBoolean( 9 ); +// +// EmpresaToPrint empresa = new EmpresaToPrint( nomeEmpresa, +// "http://www.evolute.pt:13080/SIPRPImages/image?id=" + logoId, +// // "http://apdp/siprp/auchan_jumbo_lado.jpg", +// nomeEstabelecimento ); +// PlanoActuacaoToPrint plano = +// new PlanoActuacaoToPrint( +// empresa, +// dataRelatorio != null ? new DataToPrint( "data-relatorio", dataRelatorio ) : null, +// dataVisita != null ? new DataToPrint( "data-hs", dataVisita ) : null, +// getLegislacaoAplicavel( id ), +// getAreasToPrintByPlanoId( id, validacaoDl, validacaoDns ), +// observacoesDl, +// observacoesDns ); +// return plano; +// } +// else +// { +// return null; +// } +// } +// +// +// +// public Integer getLogotipoIdForEmpresaId( Integer empresaId ) +// throws Exception +// { +// Select select = new Select2( +// new String[]{ "empresas" }, +// new Integer[]{}, +// new Expression[]{}, +// new String[]{ "empresa_logo_id" }, +// new Field( "id" ).isEqual( empresaId ), +// null, null, null, null +// ); +// Statement LOCAL_EXECUTER = createStatementLocal(); +// ResultSet array = LOCAL_EXECUTER.executeQuery( select.toString() ); +// if ( array.first() ) +// { +// return array.getInt( 0 ); +// } +// +// return null; +//// return array.columnLength() > 0 ? ( Integer ) array.get( 0, 0 ) : null; +// } +// +// +// public LegislacaoAplicavelToPrint getLegislacaoAplicavel( Integer relatorioId ) +// 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", +// "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 +// ); +// +// Statement LOCAL_EXECUTER = createStatementLocal(); +// ResultSet array = LOCAL_EXECUTER.executeQuery( select.toString() ); +// Vector diplomasGerais = new Vector(); +// Vector nomes = new Vector(); +// Vector> diplomas = new Vector>(); +// String last = null; +// +// if ( array.isBeforeFirst() ) +// { +// array.first(); +// do +// { +// String categoria = array.getString( 0 ); +// String descricao = array.getString( 1 ); +// +// if ( categoria == null || categoria.trim().length() == 0 ) +// { +// diplomasGerais.add( descricao ); +// } +// else +// { +// if ( ! categoria.equals( last ) ) +// { +// nomes.add( categoria ); +// diplomas.add( new Vector< String >() ); +// } +// last = categoria; +// diplomas.lastElement().add( descricao ); +// } +// } +// while ( array.next() ); +// } +// +// LegislacaoAplicavelToPrint legislacao = +// new LegislacaoAplicavelToPrint( diplomasGerais, nomes.toArray( new String[ nomes.size() ] ), +// diplomas.toArray( new Vector[ diplomas.size() ] ) +// ); +// return legislacao; +// } +// +// +// +// public Vector getAreasToPrintByPlanoId( Integer planoId, boolean validacaoDl, boolean validacaoDns ) +// throws Exception +// { +// ResultSet array; +// Vector areas = new Vector(); +// +// Statement WEB_EXECUTER = createStatement(); +// Statement LOCAL_EXECUTER = createStatementLocal(); +// if( web ) +// { +// Select select = new Select2( +// new String[]{ "plano_areas" }, +// new Integer[]{}, +// new Expression[]{}, +// new String[]{ "id", "descricao", "1" }, +// new Field( "plano_id" ).isEqual( planoId ), +// new String[]{ "id" }, +// null, null, null +// ); +// array = WEB_EXECUTER.executeQuery( select.toString() ); +// } +// else +// { +// Select select = new Select2( +// new String[]{ "hs_relatorio_area" }, +// new Integer[]{}, +// new Expression[]{}, +// new String[]{ "id", "description", "ordem" }, +// new Field( "relatorio_id" ).isEqual( planoId ).and( +// new Field( "deleted_date" ).isEqual( null ) ), +// new String[]{ "id" }, +// null, null, null +// ); +// array = LOCAL_EXECUTER.executeQuery( select.toString() ); +// } +// +// if ( array.first() ) +// { +// do +// { +// Integer areaId = array.getInt( 0 ); +// String areaDescricao = array.getString( 1 ); +// Integer ordem = array.getInt( 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 +// ); +// +// ResultSet genArray = LOCAL_EXECUTER.executeQuery( selectGen.toString() ); +// if ( genArray.first() ) +// { +// Integer count = new Integer( genArray.getInt( 0 ) ); +// if ( count != null ) +// { +// generico = count.intValue() > 0; +// } +// } +// } +// +// Vector riscos = getRiscosToPrintByAreaId( areaId, validacaoDl, validacaoDns ); +// if( riscos.size() > 0 ) +// { +// areas.add( new AreaToPrint( areaDescricao, riscos, ordem, generico ) ); +// } +// } +// while ( array.next() ); +// } +// +// Collections.sort( areas ); +// return areas; +// } +// +// +// public Vector getRiscosToPrintByAreaId( Integer areaId, boolean validacaoDl, boolean validacaoDns ) +// throws Exception +// { +// Statement WEB_EXECUTER = createStatement(); +// Statement LOCAL_EXECUTER = createStatementLocal(); +// ResultSet array; +// +// Vector riscos = new Vector(); +// if ( web ) +// { +// Select select = new Select2( +// new String[]{"plano_riscos"}, +// new Integer[]{}, +// new Expression[]{}, +// new String[]{"id", "descricao", "valor", "responsavel_execucao", +// "recursos_necessarios", "data_inicio", "data_fim", +// "parecer_dl", "parecer_dns", "verificacao_siprp"}, +// new Field("area_id").isEqual(areaId).and( +// new Field("activo").isEqual("y")), +// new String[]{"id"}, +// null, +// null, +// null +// ); +// +// array = WEB_EXECUTER.executeQuery( select.toString() ); +// if ( array.first() ) +// { +// do +// { +// Integer id = array.getInt( 0 ); +// String descricao = array.getString( 1 ); +// Integer valor = array.getInt( 2 ); +// String responsavelExecucao = array.getString( 3 ); +// String recursosNecessarios = array.getString( 4 ); +// Date dataInicio = array.getDate( 5 ); +// Date dataFim = array.getDate( 6 ); +// +// String parecerDl = array.getString( 7 ); +// if ( (parecerDl == null || parecerDl.trim().length() == 0 ) && validacaoDl ) +// { +// parecerDl = "De acordo"; +// } +// +// String parecerDns = array.getString( 8 ); +// if ( (parecerDns == null || parecerDns.trim().length() == 0) && validacaoDns ) +// { +// parecerDns = "De acordo"; +// } +// +// String verificacaoSiprp = array.getString( 9 ); +// riscos.add( new RiscoToPrint( +// descricao, +// valor+"", +// getMedidasToPrintByRiscoId( id ), +// responsavelExecucao, +// recursosNecessarios, +// dataInicio != null ? new DataToPrint( "data-prevista-inicio", dataInicio ) : null, +// dataFim != null ? new DataToPrint( "data-prevista-conclusao", dataFim ) : null, +// parecerDl, +// parecerDns, +// verificacaoSiprp, null, null ) ); +// } while ( array.next() ); +// } +// for( int n = 0; n < array.columnLength(); n++ ) +// { +// +// +// String verificacaoSiprp = ( String ) array.get( n, 9 ); +// riscos.add( +// new RiscoToPrint( +// descricao, +// valor+"", +// getMedidasToPrintByRiscoId( id ), +// responsavelExecucao, +// recursosNecessarios, +// dataInicio != null ? new DataToPrint( "data-prevista-inicio", dataInicio ) : null, +// dataFim != null ? new DataToPrint( "data-prevista-conclusao", dataFim ) : null, +// parecerDl, +// parecerDns, +// verificacaoSiprp, null, null ) ); +// } +// } +// else +// { +// Select select = +// new Select2( +// new String[]{ "hs_relatorio_risco", "hs_relatorio_posto_risco", "hs_relatorio_posto", "hs_relatorio_risco_valor_qualitativo" }, +// new Integer[]{ Select2.JOIN_INNER, Select2.JOIN_INNER, Select2.JOIN_LEFT_OUTER }, +// new Expression[]{ +// new Field( "hs_relatorio_risco.id" ).isEqual( new Field( "hs_relatorio_posto_risco.risco_id" ) ), +// new Field( "hs_relatorio_posto_risco.posto_id" ).isEqual( new Field( "hs_relatorio_posto.id" ) ), +// new Field( "hs_relatorio_posto_risco.valor_qualitativo_id" ).isEqual(new Field("hs_relatorio_risco_valor_qualitativo.id")) +// }, +// new String[]{ "hs_relatorio_risco.id", +// "hs_relatorio_risco.description", +// "hs_relatorio_posto_risco.probabilidade * hs_relatorio_posto_risco.severidade", +// "hs_relatorio_risco_valor_qualitativo.description", +// "hs_relatorio_posto.id", +// "null", +// "null", +// "null", +// "null", +// "null" }, +// new Field( "hs_relatorio_posto.area_id" ).isEqual( areaId ).and( +// new Field( "hs_relatorio_risco.deleted_date" ).isEqual( null ) ).and( +// new Field( "hs_relatorio_posto.deleted_date" ).isEqual( null ) ), +// new String[]{ "hs_relatorio_risco.id" }, +// null, +// null, +// null ); +// array = LOCAL_EXECUTER.executeQuery( select ); +// 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 ); +// String descricao = ( String ) array.get( n, 1 ); +// Integer risco = ( Integer ) array.get( n, 2 ); +// String risco_qual = ((String) array.get( n, 3)); +// if(risco_qual!=null){ +// risco_qual = risco_qual.substring(0, 3).toUpperCase(); +// } +// Integer posto = ( Integer ) array.get( n, 4 ); +// +// String finalRisco; +// +// if(risco!=null){ +// finalRisco = ""+risco; +// }else if(risco_qual!=null){ +// finalRisco = ""+risco_qual; +// }else{ +// continue; +// } +// +// String key = descricao + "_" + finalRisco; +// if( !riscosIdMap.containsKey( key ) ) +// { +// riscosIdMap.put( key, new Vector() ); +// riscosVector.add( key ); +// } +// 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 ) +// { +// int index = risco.lastIndexOf( "_" ); +// String descricao = risco.substring( 0, index ); +// String valor = risco.substring( index + 1, risco.length() ) ; +// Vector medidas = new Vector(); +// for( Integer id : riscosIdMap.get( risco ) ) +// { +// Integer posto = riscoPostoMap.get(id); +// medidas.addAll( getMedidasToPrintByRiscoId( id , posto) ); +// } +// if( medidas.size() > 0 ) +// { +// riscos.add( +// new RiscoToPrint( +// descricao, +// valor, +// medidas, +// null, +// null, +// 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; +// } +// +// +// +// protected Statement createStatementLocal() +// { +// Dblocal db = new Dblocal(); +// return db.createStatement(); +// } +// protected Statement createStatement() +// { +// Db db = new Db(); +// return db.createStatement(); +// } +} diff --git a/trunk/PlanosActuacao/src/java/utils/print/PlanoActuacaoToPrint.java b/trunk/PlanosActuacao/src/java/utils/print/PlanoActuacaoToPrint.java new file mode 100644 index 00000000..6406bff7 --- /dev/null +++ b/trunk/PlanosActuacao/src/java/utils/print/PlanoActuacaoToPrint.java @@ -0,0 +1,134 @@ +package utils.print; + +import java.util.Vector; + +import org.jdom.Element; + +public class PlanoActuacaoToPrint + implements PrintableInterface +{ + protected EmpresaToPrint empresa; + protected DataToPrint dataRelatorio; + protected DataToPrint dataHs; + protected LegislacaoAplicavelToPrint legislacaoAplicavel; + protected Vector areas; + protected String observacoesDl; + protected String observacoesDns; + + public PlanoActuacaoToPrint( EmpresaToPrint empresa, DataToPrint dataRelatorio, + DataToPrint dataHs, LegislacaoAplicavelToPrint legislacaoAplicavel, + Vector areas, String observacoesDl, String observacoesDns ) + { + super(); + this.empresa = empresa; + this.dataRelatorio = dataRelatorio; + this.dataHs = dataHs; + this.legislacaoAplicavel = legislacaoAplicavel; + this.areas = areas; + this.observacoesDl = observacoesDl; + this.observacoesDns = observacoesDns; + } + + public EmpresaToPrint getEmpresa() + { + return empresa; + } + + public void setEmpresa( EmpresaToPrint empresa ) + { + this.empresa = empresa; + } + + public DataToPrint getDataRelatorio() + { + return dataRelatorio; + } + + public void setDataRelatorio( DataToPrint dataRelatorio ) + { + this.dataRelatorio = dataRelatorio; + } + + public DataToPrint getDataHs() + { + return dataHs; + } + + public void setDataHs( DataToPrint dataHs ) + { + this.dataHs = dataHs; + } + + public LegislacaoAplicavelToPrint getLegislacaoAplicavel() + { + return legislacaoAplicavel; + } + + public void setLegislacaoAplicavel( + LegislacaoAplicavelToPrint legislacaoAplicavel ) + { + this.legislacaoAplicavel = legislacaoAplicavel; + } + + public Vector getAreas() + { + return areas; + } + + public void setAreas( Vector areas ) + { + this.areas = areas; + } + + public void addArea( AreaToPrint area ) + { + areas.add( area ); + } + + @Override + public Element toJdomElement() throws Exception + { + Element planoElement = new Element( "plano" ); + planoElement.addContent( empresa.toJdomElement() ); + planoElement.addContent( dataRelatorio.toJdomElement() ); + planoElement.addContent( dataHs.toJdomElement() ); + planoElement.addContent( legislacaoAplicavel.toJdomElement() ); + if( areas.size() > 0 ) + { + Element conclusoesElement = new Element( "conclusoes" ); + for( AreaToPrint area : areas ) + { + conclusoesElement.addContent( area.toJdomElement() ); + } + planoElement.addContent( conclusoesElement ); + } + Element observacoesDlElement = new Element( "observacoes-dl" ); + observacoesDlElement.setText( observacoesDl ); + planoElement.addContent( observacoesDlElement ); + Element observacoesDnsElement = new Element( "observacoes-dns" ); + observacoesDnsElement.setText( observacoesDns ); + planoElement.addContent( observacoesDnsElement ); + return planoElement; + } + + public String getObservacoesDl() + { + return observacoesDl; + } + + public void setObservacoesDl( String observacoesDl ) + { + this.observacoesDl = observacoesDl; + } + + public String getObservacoesDns() + { + return observacoesDns; + } + + public void setObservacoesDns( String observacoesDns ) + { + this.observacoesDns = observacoesDns; + } + +} diff --git a/trunk/PlanosActuacao/src/java/utils/print/PostoToPrint.java b/trunk/PlanosActuacao/src/java/utils/print/PostoToPrint.java new file mode 100644 index 00000000..faebd86d --- /dev/null +++ b/trunk/PlanosActuacao/src/java/utils/print/PostoToPrint.java @@ -0,0 +1,36 @@ +package utils.print; + +import org.jdom.Element; + + +public class PostoToPrint + implements PrintableInterface +{ + protected String designacao; + + public PostoToPrint( String designacao ) + { + this.designacao = designacao; + } + + @Override + public Element toJdomElement() + throws Exception + { + Element postoElement = new Element( "posto" ); + Element designacaoElement = new Element( "designacao" ); + designacaoElement.setText( designacao ); + postoElement.addContent( designacaoElement ); + return postoElement; + } + + public String getDesignacao() + { + return designacao; + } + + public void setDesignacao( String designacao ) + { + this.designacao = designacao; + } +} diff --git a/trunk/PlanosActuacao/src/java/utils/print/PrintableInterface.java b/trunk/PlanosActuacao/src/java/utils/print/PrintableInterface.java new file mode 100644 index 00000000..5040e04d --- /dev/null +++ b/trunk/PlanosActuacao/src/java/utils/print/PrintableInterface.java @@ -0,0 +1,8 @@ +package utils.print; + +import org.jdom.Element; + +public interface PrintableInterface +{ + public Element toJdomElement() throws Exception; +} diff --git a/trunk/PlanosActuacao/src/java/utils/print/RiscoToPrint.java b/trunk/PlanosActuacao/src/java/utils/print/RiscoToPrint.java new file mode 100644 index 00000000..e2f4040d --- /dev/null +++ b/trunk/PlanosActuacao/src/java/utils/print/RiscoToPrint.java @@ -0,0 +1,188 @@ +package utils.print; + +import java.util.Vector; + +import org.jdom.Element; + +public class RiscoToPrint + implements PrintableInterface +{ + protected String descricao; + protected String valor; + protected Vector medidas; + protected String responsavel; + protected String recursos; + protected DataToPrint dataPrevistaInicio; + protected DataToPrint dataPrevistaConclusao; + 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, Integer valorQuantitativo, String valorQualitativo ) + { + super(); + this.descricao = descricao; + this.valor = valor; + this.medidas = medidas; + this.responsavel = responsavel; + this.recursos = recursos; + this.dataPrevistaInicio = dataPrevistaInicio; + this.dataPrevistaConclusao = dataPrevistaConclusao; + this.parecerDl = parecerDl; + this.parecerDns = parecerDns; + this.verificacaoSiprp = verificacaoSiprp; + this.valorQuantitativo = valorQuantitativo; + this.valorQualitativo = valorQualitativo; + } + + @Override + public Element toJdomElement() throws Exception + { + Element riscoElement = new Element( "risco" ); + Element descricaoElement = new Element( "descricao" ); + descricaoElement.setText( descricao ); + riscoElement.addContent( descricaoElement ); + Element valorElement = new Element( "valor" ); + valorElement.setText( valor != null ? valor.toString() : " " ); + riscoElement.addContent( valorElement ); + for( MedidaToPrint medida : medidas ) + { + riscoElement.addContent( medida.toJdomElement() ); + } + Element responsavelElement = new Element( "responsavel" ); + responsavelElement.setText( responsavel ); + riscoElement.addContent( responsavelElement ); + Element recursosElement = new Element( "recursos" ); + recursosElement.setText( recursos ); + riscoElement.addContent( recursosElement ); + if( dataPrevistaInicio != null ) + { + riscoElement.addContent( dataPrevistaInicio.toJdomElement() ); + } + if( dataPrevistaConclusao != null ) + { + riscoElement.addContent( dataPrevistaConclusao.toJdomElement() ); + } + Element parecerDlElement = new Element( "parecer-dl" ); + parecerDlElement.setText( parecerDl ); + riscoElement.addContent( parecerDlElement ); + Element parecerDnsElement = new Element( "parecer-dns" ); + parecerDnsElement.setText( parecerDns ); + riscoElement.addContent( parecerDnsElement ); + Element verificacaoSiprpElement = new Element( "verificacao-siprp" ); + verificacaoSiprpElement.setText( verificacaoSiprp ); + riscoElement.addContent( verificacaoSiprpElement ); + return riscoElement; + } + + public String getDescricao() + { + return descricao; + } + + public void setDescricao( String descricao ) + { + this.descricao = descricao; + } + + public String getValor() + { + return valor; + } + + public void setValor( String valor ) + { + this.valor = valor; + } + + public Vector getMedidas() + { + return medidas; + } + + public void setMedidas( Vector medidas ) + { + this.medidas = medidas; + } + + public void addMedida( MedidaToPrint medida ) + { + medidas.add( medida ); + } + + public String getResponsavel() + { + return responsavel; + } + + public void setResponsavel( String responsavel ) + { + this.responsavel = responsavel; + } + + public String getRecursos() + { + return recursos; + } + + public void setRecursos( String recursos ) + { + this.recursos = recursos; + } + + public DataToPrint getDataPrevistaInicio() + { + return dataPrevistaInicio; + } + + public void setDataPrevistaInicio( DataToPrint dataPrevistaInicio ) + { + this.dataPrevistaInicio = dataPrevistaInicio; + } + + public DataToPrint getDataPrevistaConclusao() + { + return dataPrevistaConclusao; + } + + public void setDataPrevistaConclusao( DataToPrint dataPrevistaConclusao ) + { + this.dataPrevistaConclusao = dataPrevistaConclusao; + } + + public String getParecerDl() + { + return parecerDl; + } + + public void setParecerDl( String parecerDl ) + { + this.parecerDl = parecerDl; + } + + public String getParecerDns() + { + return parecerDns; + } + + public void setParecerDns( String parecerDns ) + { + this.parecerDns = parecerDns; + } + + public String getVerificacaoSiprp() + { + return verificacaoSiprp; + } + + public void setVerificacaoSiprp( String verificacaoSiprp ) + { + this.verificacaoSiprp = verificacaoSiprp; + } + +}