From 20c0107877e56e86e5b31f2358aa6b58a97ca931 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=20Lu=C3=ADs=20=3D?= Date: Wed, 14 Jan 2009 12:43:43 +0000 Subject: [PATCH] 14/01/2009 git-svn-id: https://svn.coded.pt/svn/SIPRP@910 bb69d46d-e84e-40c8-a05a-06db0d633741 --- trunk/PlanosActuacao/nbproject/build-impl.xml | 4 +- .../nbproject/genfiles.properties | 6 +- .../nbproject/project.properties | 5 +- trunk/PlanosActuacao/nbproject/project.xml | 58 +- .../src/java/SIPRPNode.driver.xml | 2 +- trunk/PlanosActuacao/src/java/db/Db.java | 28 +- .../src/java/db/DbRelatorios.java | 75 +++ trunk/PlanosActuacao/src/java/db/Dblocal.java | 25 +- .../src/java/db/DblocalRelatorios.java | 67 ++ .../src/java/db/entidades/Utilizador.java | 16 + .../providers/CreatePlanosDataProvider.java | 599 ++++++++++++++++++ .../db/providers/GenericDataProvider.java | 6 +- .../java/db/providers/PlanosDataProvider.java | 31 +- .../java/phaselistener/MainPhaseListener.java | 5 + .../java/planosactuacao/ApplicationBean1.java | 45 ++ .../src/java/planosactuacao/ListaPlanos.java | 113 +++- .../java/planosactuacao/PlanosActuacao.java | 101 ++- .../src/java/utils/JSFUtils.java | 10 + 18 files changed, 1080 insertions(+), 116 deletions(-) create mode 100644 trunk/PlanosActuacao/src/java/db/DbRelatorios.java create mode 100644 trunk/PlanosActuacao/src/java/db/DblocalRelatorios.java create mode 100644 trunk/PlanosActuacao/src/java/db/providers/CreatePlanosDataProvider.java diff --git a/trunk/PlanosActuacao/nbproject/build-impl.xml b/trunk/PlanosActuacao/nbproject/build-impl.xml index c9528224..436c0272 100644 --- a/trunk/PlanosActuacao/nbproject/build-impl.xml +++ b/trunk/PlanosActuacao/nbproject/build-impl.xml @@ -528,10 +528,11 @@ exists or setup the property manually. For example like this: + - + @@ -561,6 +562,7 @@ exists or setup the property manually. For example like this: + diff --git a/trunk/PlanosActuacao/nbproject/genfiles.properties b/trunk/PlanosActuacao/nbproject/genfiles.properties index 5ed00186..09bfd282 100644 --- a/trunk/PlanosActuacao/nbproject/genfiles.properties +++ b/trunk/PlanosActuacao/nbproject/genfiles.properties @@ -1,8 +1,8 @@ -build.xml.data.CRC32=78944a2b +build.xml.data.CRC32=d13032c5 build.xml.script.CRC32=50b8b881 build.xml.stylesheet.CRC32=c0ebde35 # This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. # Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. -nbproject/build-impl.xml.data.CRC32=78944a2b -nbproject/build-impl.xml.script.CRC32=20e88eee +nbproject/build-impl.xml.data.CRC32=d13032c5 +nbproject/build-impl.xml.script.CRC32=e228659e nbproject/build-impl.xml.stylesheet.CRC32=174458fc diff --git a/trunk/PlanosActuacao/nbproject/project.properties b/trunk/PlanosActuacao/nbproject/project.properties index 83edacb9..bdef867e 100644 --- a/trunk/PlanosActuacao/nbproject/project.properties +++ b/trunk/PlanosActuacao/nbproject/project.properties @@ -30,6 +30,7 @@ file.reference.commons-collections-3.1.jar=../common/lib/commons-collections-3.1 file.reference.commons-lang-2.1.jar=../common/lib/commons-lang-2.1.jar file.reference.commons-logging-1.1.jar=../common/lib/commons-logging-1.1.jar file.reference.evolute.jar=../common/lib/evolute.jar +file.reference.evolute.jar-1=jars/evolute.jar file.reference.fop.jar=lib/fop.jar file.reference.jai_imageio.jar=lib/jai_imageio.jar file.reference.jcalendar-1.3.2.jar=../common/lib/jcalendar-1.3.2.jar @@ -43,6 +44,7 @@ file.reference.postgresql-8.2-506.jdbc4.jar=jars/postgresql-8.2-506.jdbc4.jar file.reference.SIPRP.jar=lib/SIPRP.jar file.reference.TableLayout.jar=../common/lib/TableLayout.jar includes=** +j2ee.deploy.on.save=false j2ee.platform=1.5 j2ee.server.type=Tomcat60 jar.compress=false @@ -72,7 +74,8 @@ javac.classpath=\ ${file.reference.fop.jar}:\ ${file.reference.avalon-framework-4.2.0.jar}:\ ${file.reference.batik.jar}:\ - ${file.reference.jai_imageio.jar} + ${file.reference.jai_imageio.jar}:\ + ${file.reference.evolute.jar-1} # Space-separated list of extra javac options javac.compilerargs= javac.debug=true diff --git a/trunk/PlanosActuacao/nbproject/project.xml b/trunk/PlanosActuacao/nbproject/project.xml index 33574ad4..31e06595 100644 --- a/trunk/PlanosActuacao/nbproject/project.xml +++ b/trunk/PlanosActuacao/nbproject/project.xml @@ -7,113 +7,117 @@ PlanosActuacao 1.6 - + ${libs.jsf12.classpath} WEB-INF/lib - + ${libs.jstl11.classpath} WEB-INF/lib - + ${libs.jsf12-support.classpath} WEB-INF/lib - + ${libs.woodstock-components.classpath} WEB-INF/lib - + ${libs.woodstock-theme-default.classpath} WEB-INF/lib - + ${file.reference.activation.jar} WEB-INF/lib - + ${file.reference.mail.jar} WEB-INF/lib - + ${file.reference.postgresql-8.0-315.jdbc3.jar} WEB-INF/lib - + ${file.reference.postgresql-8.1-407.jdbc3.jar} WEB-INF/lib - + ${file.reference.postgresql-8.2-506.jdbc4.jar} WEB-INF/lib - + ${file.reference.cayenne-server-3.0M2.jar} WEB-INF/lib - + ${file.reference.commons-collections-3.1.jar} WEB-INF/lib - + ${file.reference.commons-lang-2.1.jar} WEB-INF/lib - + ${file.reference.commons-logging-1.1.jar} WEB-INF/lib - + ${file.reference.evolute.jar} WEB-INF/lib - + ${file.reference.jcalendar-1.3.2.jar} WEB-INF/lib - + ${file.reference.log4j-1.2.8.jar} WEB-INF/lib - + ${file.reference.mail.jar-1} WEB-INF/lib - + ${file.reference.TableLayout.jar} WEB-INF/lib - + ${file.reference.ashwood-1.1.jar} WEB-INF/lib - + ${file.reference.SIPRP.jar} WEB-INF/lib - + ${file.reference.jdom.jar} WEB-INF/lib - + ${file.reference.fop.jar} WEB-INF/lib - + ${file.reference.avalon-framework-4.2.0.jar} WEB-INF/lib - + ${file.reference.batik.jar} WEB-INF/lib - + ${file.reference.jai_imageio.jar} WEB-INF/lib + + ${file.reference.evolute.jar-1} + WEB-INF/lib + - + ${libs.exceptionhandler-runtime.classpath} WEB-INF/lib diff --git a/trunk/PlanosActuacao/src/java/SIPRPNode.driver.xml b/trunk/PlanosActuacao/src/java/SIPRPNode.driver.xml index 9d60be44..04818612 100644 --- a/trunk/PlanosActuacao/src/java/SIPRPNode.driver.xml +++ b/trunk/PlanosActuacao/src/java/SIPRPNode.driver.xml @@ -2,6 +2,6 @@ - + diff --git a/trunk/PlanosActuacao/src/java/db/Db.java b/trunk/PlanosActuacao/src/java/db/Db.java index fdc263d7..28b48762 100644 --- a/trunk/PlanosActuacao/src/java/db/Db.java +++ b/trunk/PlanosActuacao/src/java/db/Db.java @@ -11,6 +11,8 @@ import java.sql.ResultSet; import java.sql.Statement; import javax.faces.context.FacesContext; import javax.servlet.http.HttpSession; +import planosactuacao.ApplicationBean1; +import utils.JSFUtils; /** * @@ -32,23 +34,37 @@ public class Db { public Connection connect() throws Exception { Class.forName("org.postgresql.Driver").newInstance(); - connection = DriverManager.getConnection(connectionURL, User, Pass); - HttpSession session = (HttpSession)FacesContext.getCurrentInstance().getExternalContext().getSession(true); +// FacesContext fc = FacesContext.getCurrentInstance(); +// ApplicationBean1 application = JSFUtils.getApplicationBean(fc); +// if(application.getConnection() == null) +// { + connection = DriverManager.getConnection(connectionURL, User, Pass); +// application.setConnection(connection); +// } + + connection = DriverManager.getConnection(connectionURL, User, Pass); + HttpSession session = (HttpSession)FacesContext.getCurrentInstance().getExternalContext().getSession(true); session.setAttribute("connection", connection); return connection; } public Connection getConnection() { - HttpSession session = (HttpSession)FacesContext.getCurrentInstance().getExternalContext().getSession(false); - connection = (Connection) session.getAttribute("connection"); +// FacesContext fc = FacesContext.getCurrentInstance(); +// ApplicationBean1 application = JSFUtils.getApplicationBean(fc); +// connection = application.getConnection(); + HttpSession session = (HttpSession)FacesContext.getCurrentInstance().getExternalContext().getSession(false); + connection = (Connection) session.getAttribute("connection"); return connection; } public Statement createStatement() { - HttpSession session = (HttpSession)FacesContext.getCurrentInstance().getExternalContext().getSession(false); - connection = (Connection) session.getAttribute("connection"); + HttpSession session = (HttpSession)FacesContext.getCurrentInstance().getExternalContext().getSession(false); + connection = (Connection) session.getAttribute("connection"); +// FacesContext fc = FacesContext.getCurrentInstance(); +// ApplicationBean1 application = JSFUtils.getApplicationBean(fc); +// connection = application.getConnection(); Statement st; try { diff --git a/trunk/PlanosActuacao/src/java/db/DbRelatorios.java b/trunk/PlanosActuacao/src/java/db/DbRelatorios.java new file mode 100644 index 00000000..2e830aad --- /dev/null +++ b/trunk/PlanosActuacao/src/java/db/DbRelatorios.java @@ -0,0 +1,75 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ + +package db; + +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.ResultSet; +import java.sql.Statement; +import javax.faces.context.FacesContext; +import planosactuacao.ApplicationBean1; +import utils.JSFUtils; + +/** + * + * @author lluis + */ +public class DbRelatorios { + //String connectionURL = "jdbc:postgresql://storage:5432/siprp"; //testes + String connectionURL = "jdbc:postgresql://localhost:5436/siprp"; //real + + + String User = "postgres"; + String Pass = null; + Connection connection = null; + + public Connection connect() throws Exception + { + Class.forName("org.postgresql.Driver").newInstance(); + //FacesContext fc = FacesContext.getCurrentInstance(); + //ApplicationBean1 application = JSFUtils.getApplicationBean(fc); + //if(application.getConnection() == null) + //{ + connection = DriverManager.getConnection(connectionURL, User, Pass); + //application.setConnection(connection); + //} + +// connection = DriverManager.getConnection(connectionURL, User, Pass); +// HttpSession session = (HttpSession)FacesContext.getCurrentInstance().getExternalContext().getSession(true); +// session.setAttribute("connection", connection); + return connection; + } + + public Connection getConnection() + { + ////FacesContext fc = FacesContext.getCurrentInstance(); + ////ApplicationBean1 application = JSFUtils.getApplicationBean(fc); + ////connection = application.getConnection(); + //HttpSession session = (HttpSession)FacesContext.getCurrentInstance().getExternalContext().getSession(false); + //connection = (Connection) session.getAttribute("connection"); + return connection; + } + + public Statement createStatement() + { + //HttpSession session = (HttpSession)FacesContext.getCurrentInstance().getExternalContext().getSession(false); + //connection = (Connection) session.getAttribute("connection"); + ////FacesContext fc = FacesContext.getCurrentInstance(); + ////ApplicationBean1 application = JSFUtils.getApplicationBean(fc); + ////connection = application.getConnection(); + Statement st; + try + { + st = connection.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY); + return st; + } + catch(Exception ex) + { + ex.printStackTrace(); + return null; + } + } +} diff --git a/trunk/PlanosActuacao/src/java/db/Dblocal.java b/trunk/PlanosActuacao/src/java/db/Dblocal.java index a8914f4b..a6f4c713 100644 --- a/trunk/PlanosActuacao/src/java/db/Dblocal.java +++ b/trunk/PlanosActuacao/src/java/db/Dblocal.java @@ -15,6 +15,8 @@ import java.sql.ResultSet; import java.sql.Statement; import javax.faces.context.FacesContext; import javax.servlet.http.HttpSession; +import planosactuacao.ApplicationBean1; +import utils.JSFUtils; /** * @@ -33,22 +35,35 @@ public class Dblocal { Connection connection = null; /** Creates a new instance of Dblocal */ - public Dblocal() { + public Dblocal(){ } public Connection connect() throws Exception { Class.forName("org.postgresql.Driver").newInstance(); - connection = DriverManager.getConnection(connectionURL, User, Pass); - HttpSession session = (HttpSession)FacesContext.getCurrentInstance().getExternalContext().getSession(true); +// FacesContext fc = FacesContext.getCurrentInstance(); +// ApplicationBean1 application = JSFUtils.getApplicationBean(fc); +// if(application.getConnection() == null) +// { + connection = DriverManager.getConnection(connectionURL, User, Pass); +// application.setLocalConnection(connection); +// } + + + + HttpSession session = (HttpSession)FacesContext.getCurrentInstance().getExternalContext().getSession(true); session.setAttribute("connection_local", connection); return connection; } public Statement createStatement() { - HttpSession session = (HttpSession)FacesContext.getCurrentInstance().getExternalContext().getSession(false); - connection = (Connection) session.getAttribute("connection_local"); + HttpSession session = (HttpSession)FacesContext.getCurrentInstance().getExternalContext().getSession(false); + connection = (Connection) session.getAttribute("connection_local"); +// FacesContext fc = FacesContext.getCurrentInstance(); +// ApplicationBean1 application = JSFUtils.getApplicationBean(fc); +// +// connection = application.getLocalConnection(); Statement st; try { diff --git a/trunk/PlanosActuacao/src/java/db/DblocalRelatorios.java b/trunk/PlanosActuacao/src/java/db/DblocalRelatorios.java new file mode 100644 index 00000000..fa80b89c --- /dev/null +++ b/trunk/PlanosActuacao/src/java/db/DblocalRelatorios.java @@ -0,0 +1,67 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ + +package db; + +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.ResultSet; +import java.sql.Statement; +import javax.faces.context.FacesContext; +import planosactuacao.ApplicationBean1; +import utils.JSFUtils; + +/** + * + * @author lluis + */ +public class DblocalRelatorios { + //String connectionURL = "jdbc:postgresql://storage/siprp_local"; //testes + + //String connectionURL = "jdbc:postgresql://storage/siprp_local_3"; //testes local_3 + String connectionURL = "jdbc:postgresql://localhost:5436/siprp_local_3"; + + + + String User = "postgres"; + String Pass = null; + Connection connection = null; + + public Connection connect() throws Exception + { + Class.forName("org.postgresql.Driver").newInstance(); + connection = DriverManager.getConnection(connectionURL, User, Pass); + + + + //HttpSession session = (HttpSession)FacesContext.getCurrentInstance().getExternalContext().getSession(true); + //session.setAttribute("connection_local", connection); + return connection; + } + + public Statement createStatement() + { + //HttpSession session = (HttpSession)FacesContext.getCurrentInstance().getExternalContext().getSession(false); + //connection = (Connection) session.getAttribute("connection_local"); + + Statement st; + try + { + st = connection.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY); + return st; + } + catch(Exception ex) + { + ex.printStackTrace(); + return null; + } + } + + public void close() throws Exception + { + connection.close(); + } + +} diff --git a/trunk/PlanosActuacao/src/java/db/entidades/Utilizador.java b/trunk/PlanosActuacao/src/java/db/entidades/Utilizador.java index 9ff62553..6614efce 100644 --- a/trunk/PlanosActuacao/src/java/db/entidades/Utilizador.java +++ b/trunk/PlanosActuacao/src/java/db/entidades/Utilizador.java @@ -36,8 +36,10 @@ public class Utilizador { private String primeiro_login; private String apagado; private Date data_password; + private Integer estabelecimento_gestor = null; public Integer getId() { + return id; } @@ -228,4 +230,18 @@ public class Utilizador { public void setData_password(Date data_password) { this.data_password = data_password; } + + /** + * @return the estabelecimento_gestor + */ + public Integer getEstabelecimento_gestor() { + return estabelecimento_gestor; + } + + /** + * @param estabelecimento_gestor the estabelecimento_gestor to set + */ + public void setEstabelecimento_gestor(Integer estabelecimento_gestor) { + this.estabelecimento_gestor = estabelecimento_gestor; + } } diff --git a/trunk/PlanosActuacao/src/java/db/providers/CreatePlanosDataProvider.java b/trunk/PlanosActuacao/src/java/db/providers/CreatePlanosDataProvider.java new file mode 100644 index 00000000..ed1dcbda --- /dev/null +++ b/trunk/PlanosActuacao/src/java/db/providers/CreatePlanosDataProvider.java @@ -0,0 +1,599 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ + +package db.providers; + +import db.DbRelatorios; +import db.DblocalRelatorios; +import db.entidades.Area; +import db.entidades.Medida; +import db.entidades.PlanoActuacao; +import db.entidades.PostoTrabalho; +import db.entidades.Risco; +import db.entidades.Valor; +import java.sql.ResultSet; +import java.sql.Statement; +import java.util.ArrayList; +import java.util.Date; +import java.util.GregorianCalendar; +import java.util.List; +import utils.Utils; + +/** + * + * @author lluis + */ +public class CreatePlanosDataProvider { + DbRelatorios db; + DblocalRelatorios dblocal; + + public CreatePlanosDataProvider() + { + try + { + db = new DbRelatorios(); + db.connect(); + dblocal = new DblocalRelatorios(); + dblocal.connect(); + } + catch(Exception ex) + { + ex.printStackTrace(); + } + } + + + protected Integer getMaxTableId(String table) + { + Statement st = createStatement(); + String id = table + ".id"; + String sql = "SELECT max(" + id + ")+1 AS MAXID FROM " + table; + try + { + ResultSet rs = st.executeQuery(sql); + rs.first(); + Integer newId = new Integer(rs.getInt("MAXID")); + if(newId.intValue() == 0) + { + newId = new Integer(1); + } + return newId; + } + catch(Exception ex) + { + return new Integer(1); + } + } + + public List getPlanosOnline() throws Exception + { + GregorianCalendar xmas = new GregorianCalendar(1990, 11, 25); + Date dummyDate = xmas.getTime(); + ArrayList list = new ArrayList(); + list.add(dummyDate); + Statement st = createStatement(); + String sql = "select data_visita from planos_actuacao"; + ResultSet rs = st.executeQuery(sql); + + if(rs.isBeforeFirst()) + { + rs.first(); + do + { + java.sql.Date sqlDate = rs.getDate("data_visita"); + java.util.Date data_visita = new java.util.Date(sqlDate.getTime()); + System.out.println("DATA PLANO : " + data_visita.toString()); + list.add(data_visita); + }while(rs.next()); + } + return list; + } + + + + //=================== + + public PlanoActuacao getFullPlano(PlanoActuacao plano, Integer relatorioId) + { + try + { + plano = getAreasByPlano(plano, relatorioId); + } + catch(Exception ex) + { + ex.printStackTrace(); + } + + return plano; + } + + private PlanoActuacao getAreasByPlano(PlanoActuacao plano, Integer relatorioId) throws Exception + { + Statement st = createLocalStatement(); + + String sql = "select distinct area_id, hs_relatorio_area.description as descricao from hs_relatorio_posto "; + sql += "inner join hs_relatorio_posto_medida on hs_relatorio_posto_medida.posto_id = hs_relatorio_posto.id "; + sql += "inner join hs_relatorio_medida on hs_relatorio_medida.id = hs_relatorio_posto_medida.medida_id "; + sql += "inner join hs_relatorio_risco on hs_relatorio_risco.id = hs_relatorio_medida.risco_id "; + sql += "inner join hs_relatorio on hs_relatorio.id = hs_relatorio_risco.relatorio_id "; + sql += "inner join hs_relatorio_area on hs_relatorio_area.id = area_id "; + sql += "where hs_relatorio.id = " + relatorioId + " "; + sql += "order by area_id "; + System.out.println("AREAS BY PLANO SQL : " + sql); + ResultSet rs = st.executeQuery(sql); + + List areas = new ArrayList(); + if(rs.isBeforeFirst()) + { + rs.first(); + do + { + Area a = new Area(); + a.setId(new Integer( rs.getInt("area_id") )); + a.setArea_id(a.getId()); + if(existemMedidasByArea(a.getId())) + { + a.setDescricao(Utils.unicodeToHTML(rs.getString("descricao"))); + try + { + a.setRiscos(getRiscosByArea(a)); + } + catch(Exception ex) + { + System.out.println("ERRO RISCOS BY AREA !!!!"); + ex.printStackTrace(); + a.setRiscos(null); + } + + areas.add(a); + } + + }while(rs.next()); + plano.setAreas(areas); + } + return plano; + } + + private List getRiscosByArea(Area a) throws Exception + { + Statement st = createLocalStatement(); + String sql = "select distinct hs_relatorio_risco.id, hs_relatorio_risco.description as descricao from hs_relatorio_posto "; + sql += "inner join hs_relatorio_posto_medida on hs_relatorio_posto_medida.posto_id = hs_relatorio_posto.id "; + sql += "inner join hs_relatorio_medida on hs_relatorio_medida.id = hs_relatorio_posto_medida.medida_id "; + sql += "inner join hs_relatorio_risco on hs_relatorio_risco.id = hs_relatorio_medida.risco_id "; + sql += "inner join hs_relatorio on hs_relatorio.id = hs_relatorio_risco.relatorio_id "; + sql += "inner join hs_relatorio_area on hs_relatorio_area.id = area_id "; + sql += "where area_id = " + a.getId() + " "; + sql += "order by hs_relatorio_risco.id "; + System.out.println("RISCOS BY AREA SQL : " + sql); + ResultSet rs = st.executeQuery(sql); + List riscos = new ArrayList(); + if(rs.isBeforeFirst()) + { + + rs.first(); + do + { + Risco r = new Risco(); + r.setId(new Integer( rs.getInt("id") )); + if(existemMedidasByRisco(r.getId())) + { + r.setDescricao(Utils.unicodeToHTML(rs.getString("descricao"))); + r.setValores(getValoresByRisco(r, a)); + //Integer valor = getValorByRisco(r, a); + //r.setValor(valor); + r.setRisco_id(new Integer( rs.getInt("id") )); + r.setMedidas(getMedidasByRisco( r, a)); + riscos.add(r); + } + + }while(rs.next()); + } + return riscos; + + } + + private List getValoresByRisco(Risco r, Area a) throws Exception + //private Integer getValorByRisco(Risco r, Area a) throws Exception + { + Statement st = createLocalStatement(); + String sql = "select valor from "; + sql += "(select distinct hs_relatorio_posto_risco.risco_id, "; + sql += "case when hs_relatorio_posto_risco.valor_qualitativo_id isnull and hs_relatorio_posto_risco.probabilidade isnull and hs_relatorio_posto_risco.severidade isnull then null "; + sql += "when hs_relatorio_posto_risco.valor_qualitativo_id isnull then hs_relatorio_posto_risco.probabilidade * hs_relatorio_posto_risco.severidade "; + sql += "else hs_relatorio_posto_risco.valor_qualitativo_id "; + sql += "end as valor "; + sql += "from hs_relatorio_posto "; + sql += "inner join hs_relatorio_posto_medida on hs_relatorio_posto_medida.posto_id = hs_relatorio_posto.id "; + sql += "inner join hs_relatorio_medida on hs_relatorio_medida.id = hs_relatorio_posto_medida.medida_id "; + sql += "inner join hs_relatorio_risco on hs_relatorio_risco.id = hs_relatorio_medida.risco_id "; + sql += "inner join hs_relatorio_posto_risco on (hs_relatorio_posto_risco.posto_id = hs_relatorio_posto.id and hs_relatorio_posto_risco.risco_id = hs_relatorio_risco.id) "; + sql += "inner join hs_relatorio on hs_relatorio.id = hs_relatorio_risco.relatorio_id "; + sql += "inner join hs_relatorio_area on hs_relatorio_area.id = area_id "; + sql += "where hs_relatorio_posto_risco.risco_id = " + r.getId() + " and area_id = " + a.getId() + ") subquery "; + sql += "order by subquery.valor"; + System.out.println("VALORES BY RISCO : " + sql); + ResultSet rs = st.executeQuery(sql); + List valores = new ArrayList(); + Integer valor = null; + if(rs.isBeforeFirst()) + { + rs.first(); + do + { + Valor v = new Valor(); + Object oValor = rs.getObject("valor"); + + if(oValor == null) + { + v.setValor(null); + //r.setValor(null); + valor = null; + } + else + { + v.setValor((Integer) oValor); + //r.setValor((Integer) oValor); + valor = (Integer) oValor; + } +// System.out.println("RISCO : " + r.getId().toString() + "VALOR : " + oValor.toString()); + //int valor = rs.getInt("valor"); + //v.setValor(new Integer(valor)); + //v.setMedidas(getMedidasByValor(v, r, a)); + valores.add(v); + }while(rs.next()); + } + return valores; + //return valor; + } + +// private List getMedidasByValor(Valor v, Risco r, Area a) throws Exception +// { +// Statement st = dblocal.createStatement(); +// String sql = "select distinct medida_id, valor, descricao from "; +// sql += "( select distinct hs_relatorio_posto_medida.medida_id, hs_relatorio_posto_risco.risco_id, hs_relatorio_medida.description as descricao, "; +// sql += "case when hs_relatorio_posto_risco.valor_qualitativo_id isnull and hs_relatorio_posto_risco.probabilidade isnull and hs_relatorio_posto_risco.severidade isnull then null "; +// sql += "when hs_relatorio_posto_risco.valor_qualitativo_id isnull then hs_relatorio_posto_risco.probabilidade * hs_relatorio_posto_risco.severidade "; +// sql += "else hs_relatorio_posto_risco.valor_qualitativo_id "; +// sql += "end as valor "; +// sql += "from hs_relatorio_posto "; +// sql += "inner join hs_relatorio_posto_medida on hs_relatorio_posto_medida.posto_id = hs_relatorio_posto.id "; +// sql += "inner join hs_relatorio_medida on hs_relatorio_medida.id = hs_relatorio_posto_medida.medida_id "; +// sql += "inner join hs_relatorio_risco on hs_relatorio_risco.id = hs_relatorio_medida.risco_id "; +// sql += "inner join hs_relatorio_posto_risco on (hs_relatorio_posto_risco.posto_id = hs_relatorio_posto.id and hs_relatorio_posto_risco.risco_id = hs_relatorio_risco.id) "; +// sql += "inner join hs_relatorio on hs_relatorio.id = hs_relatorio_risco.relatorio_id "; +// sql += "inner join hs_relatorio_area on hs_relatorio_area.id = area_id "; +// sql += "where hs_relatorio_posto_risco.risco_id = " + r.getId() + " and area_id = " + a.getId() + " and hs_relatorio_posto_medida.is_plano_actuacao = true" + ") subquery "; +// //sql += "where hs_relatorio_posto_risco.risco_id = " + r.getId() + " and area_id = " + a.getId() + ") subquery "; +// //sql += "where valor = " + v.getValor() + " "; +// sql += "order by subquery.medida_id, valor"; +// System.out.println("MEDIDAS BY VALOR SQL : " + sql); +// ResultSet rs = st.executeQuery(sql); +// List medidas = new ArrayList(); +// if(rs.isBeforeFirst()) +// { +// rs.first(); +// do +// { +// Medida m = new Medida(); +// //int valor = rs.getInt("valor"); +// //m.setValor(new Integer(valor)); +// m.setId(new Integer( rs.getInt("medida_id") )); +// m.setDescricao(Utils.unicodeToHTML(rs.getString("descricao"))); +// m.setPostos(getPostosByMedidaAndValor(m, v, a)); +// medidas.add(m); +// }while(rs.next()); +// } +// return medidas; +// } + + private List getMedidasByRisco(Risco r, Area a) throws Exception + { + Statement st = createLocalStatement(); + String sql = "select distinct medida_id, valor, descricao from "; + sql += "( select distinct hs_relatorio_posto_medida.medida_id, hs_relatorio_posto_risco.risco_id, hs_relatorio_medida.description as descricao, "; + sql += "case when hs_relatorio_posto_risco.valor_qualitativo_id isnull and hs_relatorio_posto_risco.probabilidade isnull and hs_relatorio_posto_risco.severidade isnull then null "; + sql += "when hs_relatorio_posto_risco.valor_qualitativo_id isnull then hs_relatorio_posto_risco.probabilidade * hs_relatorio_posto_risco.severidade "; + sql += "else hs_relatorio_posto_risco.valor_qualitativo_id "; + sql += "end as valor "; + sql += "from hs_relatorio_posto "; + sql += "inner join hs_relatorio_posto_medida on hs_relatorio_posto_medida.posto_id = hs_relatorio_posto.id "; + sql += "inner join hs_relatorio_medida on hs_relatorio_medida.id = hs_relatorio_posto_medida.medida_id "; + sql += "inner join hs_relatorio_risco on hs_relatorio_risco.id = hs_relatorio_medida.risco_id "; + sql += "inner join hs_relatorio_posto_risco on (hs_relatorio_posto_risco.posto_id = hs_relatorio_posto.id and hs_relatorio_posto_risco.risco_id = hs_relatorio_risco.id) "; + sql += "inner join hs_relatorio on hs_relatorio.id = hs_relatorio_risco.relatorio_id "; + sql += "inner join hs_relatorio_area on hs_relatorio_area.id = area_id "; + sql += "where hs_relatorio_posto_risco.risco_id = " + r.getId() + " and area_id = " + a.getId() + " and hs_relatorio_posto_medida.is_plano_actuacao = true" + ") subquery "; + //sql += "where hs_relatorio_posto_risco.risco_id = " + r.getId() + " and area_id = " + a.getId() + ") subquery "; + //sql += "where valor = " + v.getValor() + " "; + sql += "order by subquery.medida_id, valor"; + System.out.println("MEDIDAS BY RISCO SQL : " + sql); + ResultSet rs = st.executeQuery(sql); + List medidas = new ArrayList(); + if(rs.isBeforeFirst()) + { + rs.first(); + do + { + Medida m = new Medida(); + //int valor = rs.getInt("valor"); + //m.setValor(new Integer(valor)); + m.setId(new Integer( rs.getInt("medida_id") )); + m.setMedida_id(m.getId()); + m.setDescricao(Utils.unicodeToHTML(rs.getString("descricao"))); + //m.setPostos(getPostosByMedidaAndValor(m, v, a)); + m.setPostos(getPostosByMedida(r, m, a)); + medidas.add(m); + }while(rs.next()); + } + return medidas; + } + +// private List getPostosByMedidaAndValor(Medida m, Valor v, Area a) throws Exception +// { +// Statement st = dblocal.createStatement(); +// String sql = "select subquery.posto_id, valor, descricao from "; +// sql += "(select hs_relatorio_posto_medida.posto_id, hs_relatorio_posto.description as descricao, "; +// sql += "case when hs_relatorio_posto_risco.valor_qualitativo_id isnull and hs_relatorio_posto_risco.probabilidade isnull and hs_relatorio_posto_risco.severidade isnull then null "; +// sql += "when hs_relatorio_posto_risco.valor_qualitativo_id isnull then hs_relatorio_posto_risco.probabilidade * hs_relatorio_posto_risco.severidade "; +// sql += "else hs_relatorio_posto_risco.valor_qualitativo_id "; +// sql += "end as valor "; +// sql += "from hs_relatorio_posto_medida "; +// sql += "inner join hs_relatorio_posto_risco on hs_relatorio_posto_risco.posto_id = hs_relatorio_posto_medida.posto_id "; +// sql += "inner join hs_relatorio_posto on hs_relatorio_posto.id = hs_relatorio_posto_medida.posto_id "; +// sql += "inner join hs_relatorio_area on hs_relatorio_area.id = area_id "; +// sql += "where medida_id = " + m.getId() + " and area_id = " + a.getId() + ") subquery "; +// //sql += "where valor = " + v.getValor(); +// System.out.println("POSTOS BY MEDIDA SQL : " + sql); +// ResultSet rs = st.executeQuery(sql); +// List postos = new ArrayList(); +// if(rs.isBeforeFirst()) +// { +// rs.first(); +// do +// { +// PostoTrabalho p = new PostoTrabalho(); +// p.setId(new Integer( rs.getInt("posto_id") )); +// p.setDescricao(Utils.unicodeToHTML(rs.getString("descricao"))); +// postos.add(p); +// }while(rs.next()); +// } +// return postos; +// } + + private List getPostosByMedida(Risco r, Medida m, Area a) throws Exception + { + Statement st = createLocalStatement(); + String sql = "select subquery.posto_id, valor, descricao from "; + sql += "(select hs_relatorio_posto_medida.posto_id, hs_relatorio_posto.description as descricao, "; + sql += "case when hs_relatorio_posto_risco.valor_qualitativo_id isnull and hs_relatorio_posto_risco.probabilidade isnull and hs_relatorio_posto_risco.severidade isnull then null "; + sql += "when hs_relatorio_posto_risco.valor_qualitativo_id isnull then hs_relatorio_posto_risco.probabilidade * hs_relatorio_posto_risco.severidade "; + sql += "else hs_relatorio_posto_risco.valor_qualitativo_id "; + sql += "end as valor "; + sql += "from hs_relatorio_posto_medida "; + sql += "inner join hs_relatorio_posto_risco on hs_relatorio_posto_risco.posto_id = hs_relatorio_posto_medida.posto_id "; + sql += "inner join hs_relatorio_posto on hs_relatorio_posto.id = hs_relatorio_posto_medida.posto_id "; + sql += "inner join hs_relatorio_area on hs_relatorio_area.id = area_id "; + sql += "where medida_id = " + m.getId() + " and area_id = " + a.getId() + " and risco_id = " + r.getId() + ") subquery "; + //sql += "where valor = " + v.getValor(); + System.out.println("POSTOS BY MEDIDA SQL : " + sql); + ResultSet rs = st.executeQuery(sql); + List postos = new ArrayList(); + if(rs.isBeforeFirst()) + { + rs.first(); + do + { + PostoTrabalho p = new PostoTrabalho(); + p.setId(new Integer( rs.getInt("posto_id") )); + p.setPosto_id(p.getId()); + p.setDescricao(Utils.unicodeToHTML(rs.getString("descricao"))); + postos.add(p); + }while(rs.next()); + } + return postos; + } + + + + private boolean existemMedidasByArea(Integer area_id) throws Exception + { + Statement st = createLocalStatement(); + String sql = "select distinct medida_id, valor, descricao "; + sql += "from ( select distinct hs_relatorio_posto_medida.medida_id, hs_relatorio_posto_risco.risco_id, hs_relatorio_medida.description as descricao, "; + sql += "case when hs_relatorio_posto_risco.valor_qualitativo_id isnull and hs_relatorio_posto_risco.probabilidade isnull and hs_relatorio_posto_risco.severidade isnull then null "; + sql += "when hs_relatorio_posto_risco.valor_qualitativo_id isnull then hs_relatorio_posto_risco.probabilidade * hs_relatorio_posto_risco.severidade else hs_relatorio_posto_risco.valor_qualitativo_id end as valor from hs_relatorio_posto "; + sql += "inner join hs_relatorio_posto_medida on hs_relatorio_posto_medida.posto_id = hs_relatorio_posto.id "; + sql += "inner join hs_relatorio_medida on hs_relatorio_medida.id = hs_relatorio_posto_medida.medida_id "; + sql += "inner join hs_relatorio_risco on hs_relatorio_risco.id = hs_relatorio_medida.risco_id "; + sql += "inner join hs_relatorio_posto_risco on (hs_relatorio_posto_risco.posto_id = hs_relatorio_posto.id and hs_relatorio_posto_risco.risco_id = hs_relatorio_risco.id) "; + sql += "inner join hs_relatorio on hs_relatorio.id = hs_relatorio_risco.relatorio_id "; + sql += "inner join hs_relatorio_area on hs_relatorio_area.id = area_id "; + sql += "where area_id = " + area_id + " and hs_relatorio_posto_medida.is_plano_actuacao = true) subquery order by subquery.medida_id, valor"; + System.out.println("EXISTEM MEDIDAS BY AREA SQL : " + sql); + ResultSet rs = st.executeQuery(sql); + if(rs.isBeforeFirst()) + { + return true; + } + else + { + return false; + } + } + + private boolean existemMedidasByRisco(Integer risco_id) throws Exception + { + Statement st = createLocalStatement(); + String sql = "select distinct medida_id "; + sql += "from ( select distinct hs_relatorio_posto_medida.medida_id, hs_relatorio_posto_risco.risco_id, hs_relatorio_medida.description as descricao, "; + sql += "case when hs_relatorio_posto_risco.valor_qualitativo_id isnull and hs_relatorio_posto_risco.probabilidade isnull and hs_relatorio_posto_risco.severidade isnull then null "; + sql += "when hs_relatorio_posto_risco.valor_qualitativo_id isnull then hs_relatorio_posto_risco.probabilidade * hs_relatorio_posto_risco.severidade else hs_relatorio_posto_risco.valor_qualitativo_id end as valor from hs_relatorio_posto "; + sql += "inner join hs_relatorio_posto_medida on hs_relatorio_posto_medida.posto_id = hs_relatorio_posto.id "; + sql += "inner join hs_relatorio_medida on hs_relatorio_medida.id = hs_relatorio_posto_medida.medida_id "; + sql += "inner join hs_relatorio_risco on hs_relatorio_risco.id = hs_relatorio_medida.risco_id "; + sql += "inner join hs_relatorio_posto_risco on (hs_relatorio_posto_risco.posto_id = hs_relatorio_posto.id and hs_relatorio_posto_risco.risco_id = hs_relatorio_risco.id) "; + sql += "inner join hs_relatorio on hs_relatorio.id = hs_relatorio_risco.relatorio_id "; + sql += "inner join hs_relatorio_area on hs_relatorio_area.id = area_id "; + sql += "where hs_relatorio_posto_risco.risco_id = " + risco_id + " and hs_relatorio_posto_medida.is_plano_actuacao = true) subquery order by medida_id"; + System.out.println("EXISTEM MEDIDAS BY RISCO SQL : " + sql); + ResultSet rs = st.executeQuery(sql); + if(rs.isBeforeFirst()) + { + return true; + } + else + { + return false; + } + + } + + + public Integer createPlano(PlanoActuacao p) throws Exception + { + Statement st = createStatement(); + Integer newId = getMaxTableId("planos_actuacao"); + String sql = "insert into planos_actuacao (id, estabelecimento_id, fase, data_visita, data_relatorio, nome_estabelecimento, empresa_id, nome_empresa, data_controlo, tecnico_hs_id, tecnico_hs_nome) values ("; + sql += newId + ", "; + sql += p.getEstabelecimento_id() + ", "; + sql += p.getFase() + ", '"; + java.sql.Date sqlDate = new java.sql.Date(p.getData_visita().getTime()); + sql += sqlDate + "', '"; + sqlDate = new java.sql.Date(p.getData_relatorio().getTime()); + sql += sqlDate + "', '"; + sql += p.getNome_estabelecimento() + "', "; + sql += p.getEmpresa_id() + ", '"; + sql += p.getNome_empresa() + "', '"; + Date today = new Date(); + sqlDate = new java.sql.Date(today.getTime()); + sql += sqlDate + "', "; + sql += p.getTecnico_hs_id() + ", "; + if(p.getTecnico_hs_nome() == null) + { + sql += null; + } + else + { + sql += "'" + p.getTecnico_hs_nome() + "'"; + } + + sql += ")"; + + System.out.println("SQL CREATE PLANO : " + sql); + st.execute(sql); + + return newId; + } + + + public Integer createArea(Area a) throws Exception + { + Statement st = createStatement(); + Integer newId = getMaxTableId("plano_areas"); + String sql = "insert into plano_areas (id, area_id, plano_id, descricao) values ("; + sql += newId + ", "; + sql += a.getArea_id() + ", "; + sql += a.getPlano_id() + ", '"; + sql += a.getDescricao() + "' "; + sql += ")"; + + System.out.println("SQL CREATE AREA : " + sql); + st.execute(sql); + return newId; + } + + public Integer createRisco(Risco r) throws Exception + { + Statement st = createStatement(); + Integer newId = getMaxTableId("plano_riscos"); + String sql = "insert into plano_riscos (id, area_id, descricao, valor, risco_id) values ("; + sql += newId + ", "; + sql += r.getArea_id() + ", '"; + sql += r.getDescricao() + "', "; + sql += r.getValor() + ", "; + sql += r.getId(); + sql += ")"; + + System.out.println("SQL CREATE RISCO : " + sql); + st.execute(sql); + return newId; + } + + public Integer createValor(Valor v) throws Exception + { + Statement st = createStatement(); + Integer newId = getMaxTableId("plano_valores"); + String sql = "insert into plano_valores (id, risco_id, valor) values ("; + sql += newId + ", "; + sql += v.getRisco_id() + ", "; + sql += v.getValor() + ""; + sql += ")"; + + System.out.println("SQL CREATE VALOR : " + sql); + st.execute(sql); + return newId; + } + + public Integer createMedida(Medida m) throws Exception + { + Statement st = createStatement(); + Integer newId = getMaxTableId("plano_medidas"); + String sql = "insert into plano_medidas (id, medida_id, risco_id, descricao) values ("; + sql += newId + ", "; + sql += m.getMedida_id() + ", "; + sql += m.getRisco_id() + ", '"; + sql += m.getDescricao() + "' "; + sql += ")"; + + System.out.println("SQL CREATE MEDIDA : " + sql); + st.execute(sql); + return newId; + } + + public void createPostoTrabalho(PostoTrabalho p) throws Exception + { + Statement st = createStatement(); + Integer newId = getMaxTableId("plano_postos_trabalho"); + String sql = "insert into plano_postos_trabalho (id, posto_id, medida_id, descricao) values ("; + sql += newId + ", "; + sql += p.getPosto_id() + ", "; + sql += p.getMedida_id() + ", '"; + sql += p.getDescricao() + "' "; + sql += ")"; + + System.out.println("SQL CREATE POSTO : " + sql); + st.execute(sql); + } + + + + //==================== + + + + public String getEmpresaNome(Integer empresa_id) throws Exception + { + Statement st = createLocalStatement(); + String sql ="SELECT designacao_social FROM empresas WHERE id = " + empresa_id; + ResultSet rslocal = st.executeQuery(sql); + rslocal.first(); + String nome = Utils.unicodeToHTML(rslocal.getString("designacao_social")); + return nome; + } + + + protected Statement createStatement() + { + + return db.createStatement(); + } + + protected Statement createLocalStatement() + { + + return dblocal.createStatement(); + } +} diff --git a/trunk/PlanosActuacao/src/java/db/providers/GenericDataProvider.java b/trunk/PlanosActuacao/src/java/db/providers/GenericDataProvider.java index e32962c7..91213754 100644 --- a/trunk/PlanosActuacao/src/java/db/providers/GenericDataProvider.java +++ b/trunk/PlanosActuacao/src/java/db/providers/GenericDataProvider.java @@ -5,6 +5,9 @@ package db.providers; +import com.evolute.utils.timer.TimedEvent; +import com.evolute.utils.timer.Timer; +import planosactuacao.PlanosActuacao; import db.Db; import java.sql.ResultSet; import java.sql.Statement; @@ -22,7 +25,8 @@ public class GenericDataProvider { { try { - db.connect(); + db.connect(); + } catch(Exception ex) { diff --git a/trunk/PlanosActuacao/src/java/db/providers/PlanosDataProvider.java b/trunk/PlanosActuacao/src/java/db/providers/PlanosDataProvider.java index 763b41ff..0a00b4da 100644 --- a/trunk/PlanosActuacao/src/java/db/providers/PlanosDataProvider.java +++ b/trunk/PlanosActuacao/src/java/db/providers/PlanosDataProvider.java @@ -444,13 +444,35 @@ public class PlanosDataProvider extends GenericDataProvider{ case Global.DIRECTOR_SIPRP: sql += "WHERE fase > 1 AND fase < 6"; - break; + break; + + case Global.RH: + sql += "WHERE fase > 1 AND fase < 6"; + break; + + case Global.DIRECTOR_GERAL_RH: + sql += "WHERE fase > 1 AND fase < 6"; + break; + + case Global.GESTOR: + sql += "WHERE fase > 1 AND fase < 6"; + break; } - if(userType != Global.DIRECTOR_SIPRP && userType != Global.TECNICO_HS && userType != Global.DIRECTOR_NACIONAL_SEGURANCA) + if(userType != Global.DIRECTOR_SIPRP && userType != Global.TECNICO_HS && userType != Global.DIRECTOR_NACIONAL_SEGURANCA && userType != Global.DIRECTOR_GERAL_RH && userType != Global.GESTOR) { sql += " and estabelecimento_id = " + u.getEstabelecimento_id(); } + //System.out.println("USER ESTABELECIMENTO GESTOR : " + u.getEstabelecimento_gestor().intValue()); + if(userType == Global.GESTOR) + { + if(u.getEstabelecimento_gestor().intValue() > 0) + { + sql += " and estabelecimento_id = " + u.getEstabelecimento_gestor(); + } + } + + System.out.println("PLANOS SEGUIMENTO SQL : " + sql); ResultSet rs = st.executeQuery(sql); ArrayList list = getFullPlanos(rs); return list; @@ -461,11 +483,12 @@ public class PlanosDataProvider extends GenericDataProvider{ int userType = u.getTipo().intValue(); Statement st = createStatement(); String sql = "select * from planos_actuacao where fase = 6"; - if(userType != Global.DIRECTOR_SIPRP && userType != Global.TECNICO_HS && userType != Global.DIRECTOR_NACIONAL_SEGURANCA) + if(userType != Global.DIRECTOR_SIPRP && userType != Global.TECNICO_HS && userType != Global.DIRECTOR_NACIONAL_SEGURANCA && userType != Global.DIRECTOR_GERAL_RH) { sql += " and estabelecimento_id = " + u.getEstabelecimento_id(); } - + + System.out.println("PLANOS CONCLUIDOS SQL : " + sql); ResultSet rs = st.executeQuery(sql); ArrayList list = getFullPlanos(rs); return list; diff --git a/trunk/PlanosActuacao/src/java/phaselistener/MainPhaseListener.java b/trunk/PlanosActuacao/src/java/phaselistener/MainPhaseListener.java index 343da0c3..aba044ff 100644 --- a/trunk/PlanosActuacao/src/java/phaselistener/MainPhaseListener.java +++ b/trunk/PlanosActuacao/src/java/phaselistener/MainPhaseListener.java @@ -151,6 +151,7 @@ public class MainPhaseListener implements PhaseListener{ session.setDisableMenuPlanos(false); if(sview.matches("/ViewPlano.jsp")) { + if(u.getTipo().intValue() == Global.DIRECTOR_SIPRP) { //session.setDisableMenu(false); @@ -178,6 +179,10 @@ public class MainPhaseListener implements PhaseListener{ session.setDisableMenu(false); if(sview.matches("/ListaPlanos.jsp")) { + if(u.getTipo().intValue() == Global.RH || u.getTipo().intValue() == Global.GESTOR) + { + session.setDisableMenuUtilizadores(true); + } session.setDisableMenuPlanos(true); } } diff --git a/trunk/PlanosActuacao/src/java/planosactuacao/ApplicationBean1.java b/trunk/PlanosActuacao/src/java/planosactuacao/ApplicationBean1.java index 1bc2e261..d0aa545c 100644 --- a/trunk/PlanosActuacao/src/java/planosactuacao/ApplicationBean1.java +++ b/trunk/PlanosActuacao/src/java/planosactuacao/ApplicationBean1.java @@ -7,6 +7,7 @@ package planosactuacao; import com.sun.rave.web.ui.appbase.AbstractApplicationBean; +import java.sql.Connection; import javax.faces.FacesException; /** @@ -33,6 +34,10 @@ public class ApplicationBean1 extends AbstractApplicationBean { } // + private boolean timerStarted = false; + private Connection localConnection = null; + private Connection connection = null; + /** *

Construct a new application data bean instance.

*/ @@ -101,4 +106,44 @@ public class ApplicationBean1 extends AbstractApplicationBean { public String getLocaleCharacterEncoding() { return super.getLocaleCharacterEncoding(); } + + /** + * @return the timerStarted + */ + public boolean isTimerStarted() { + return timerStarted; + } + + /** + * @param timerStarted the timerStarted to set + */ + public void setTimerStarted(boolean timerStarted) { + this.timerStarted = timerStarted; + } + + /** + * @return the connection + */ + public Connection getConnection() { + return connection; + } + + /** + * @param connection the connection to set + */ + public void setConnection(Connection connection) { + this.connection = connection; + } + + public Connection getLocalConnection() { + return localConnection; + } + + /** + * @param connection the connection to set + */ + public void setLocalConnection(Connection connection) { + this.localConnection = connection; + } + } diff --git a/trunk/PlanosActuacao/src/java/planosactuacao/ListaPlanos.java b/trunk/PlanosActuacao/src/java/planosactuacao/ListaPlanos.java index faf06ab0..fd326798 100644 --- a/trunk/PlanosActuacao/src/java/planosactuacao/ListaPlanos.java +++ b/trunk/PlanosActuacao/src/java/planosactuacao/ListaPlanos.java @@ -6,17 +6,18 @@ package planosactuacao; +import com.evolute.utils.timer.TimedEvent; +import com.evolute.utils.timer.Timer; import com.sun.data.provider.RowKey; import com.sun.rave.web.ui.appbase.AbstractPageBean; import com.sun.webui.jsf.component.Table; import com.sun.webui.jsf.component.TableRowGroup; +import db.Dblocal; import db.entidades.PlanoActuacao; import db.providers.UtilizadoresDataProvider; import db.entidades.Utilizador; import db.providers.PlanosDataProvider; import global.Global; -import java.io.File; -import java.io.FileInputStream; import java.util.ArrayList; import java.util.Calendar; import java.util.Date; @@ -24,7 +25,6 @@ import java.util.List; import javax.faces.FacesException; import javax.faces.component.html.HtmlPanelGrid; import javax.faces.context.FacesContext; -import javax.servlet.ServletContext; import javax.servlet.http.HttpServletResponse; import siprp.database.cayenne.providers.PlanoActuacaoDAO; import siprp.planoactuacao.print.PlanoActuacaoPDFCreator; @@ -169,6 +169,7 @@ public class ListaPlanos extends AbstractPageBean { FacesContext fc = getFacesContext(); String user_id = JSFUtils.getRequestParameter(fc, "user"); + String estab_gestor = JSFUtils.getRequestParameter(fc, "estab_gestor"); System.out.println("LISTA PLANOS - USER ID : " + user_id); Utilizador u = null; if(user_id != null) @@ -183,6 +184,20 @@ public class ListaPlanos extends AbstractPageBean { UtilizadoresDataProvider udp = new UtilizadoresDataProvider(); udp.checkConnection(); u = udp.getUtilizador(userId); + if(u.getTipo().intValue() == Global.GESTOR) + { + try + { + Integer estabelecimento_gestor = new Integer(Integer.parseInt(estab_gestor)); + System.out.println("ESTABELECIMENTO GESTOR : " + estabelecimento_gestor.intValue()); + u.setEstabelecimento_gestor(estabelecimento_gestor); + } + catch(Exception ex2) + { + ex2.printStackTrace(); + } + + } getSessionBean1().setCurrentUser(u); @@ -200,14 +215,14 @@ public class ListaPlanos extends AbstractPageBean { } u = getSessionBean1().getCurrentUser(); - if(u.getTipo().intValue() == Global.DIRECTOR_SIPRP) + if(u.getTipo().intValue() == Global.DIRECTOR_SIPRP || u.getTipo().intValue() == Global.RH || u.getTipo().intValue() == Global.DIRECTOR_GERAL_RH || u.getTipo().intValue() == Global.GESTOR) { gridActual.setRendered(false); tableRowGroup2.setEmptyDataMsg("Sem registos"); tableRowGroup3.setEmptyDataMsg("Sem registos"); } - if(u.getTipo().intValue() != Global.DIRECTOR_SIPRP) + if(u.getTipo().intValue() != Global.DIRECTOR_SIPRP && u.getTipo().intValue() != Global.RH && u.getTipo().intValue() != Global.DIRECTOR_GERAL_RH) { getSessionBean1().setDisableMenuUtilizadores(true); tableRowGroup1.setEmptyDataMsg("Sem registos"); @@ -384,6 +399,38 @@ FacesContext context = FacesContext.getCurrentInstance(); private void initialize() { + try + { + Dblocal dblocal = new Dblocal(); + dblocal.connect(); + } + catch(Exception ex) + { + ex.printStackTrace(); + } + + if(!getApplicationBean1().isTimerStarted()) + { + Timer.scheduleEvent(new TimedEvent(){ + public void executeAction() throws Exception + { + try + { + PlanosActuacao planos = new PlanosActuacao(); + } + catch( Exception ex ) + { + } + Timer.resetEvent( this ); + } + }, 3600); + getApplicationBean1().setTimerStarted(true); + + } + + + + Utilizador u = getSessionBean1().getCurrentUser(); Integer estabelecimento_id = null; @@ -420,15 +467,15 @@ FacesContext context = FacesContext.getCurrentInstance(); //// Integer id = es.getId(); // estabelecimento id ?? // } - PlanosActuacao planos = new PlanosActuacao(u); + ////PlanosActuacao planos = new PlanosActuacao(u); - List listPlanosActivos = planos.getPlanosActivos(u); + List listPlanosActivos = getPlanosActivos(u); getSessionBean1().getPlanosActualDataProvider().setList(listPlanosActivos); - List listPlanosSeguimento = planos.getPlanosSeguimento(u); + List listPlanosSeguimento = getPlanosSeguimento(u); getSessionBean1().getPlanosSeguimentoDataProvider().setList(listPlanosSeguimento); - List listPlanosConcluidos = planos.getPlanosConcluidos(u); + List listPlanosConcluidos = getPlanosConcluidos(u); getSessionBean1().getPlanosConcluidosDataProvider().setList(listPlanosConcluidos); //checkPlanosDelayed(); @@ -525,7 +572,53 @@ FacesContext context = FacesContext.getCurrentInstance(); // { // System.out.println(" " + p.getDescricao()); // } -// } +// } + + public List getPlanosActivos(Utilizador u) + { + ArrayList list = new ArrayList(); + try + { + if(u.getTipo().intValue() != Global.DIRECTOR_SIPRP && u.getTipo().intValue() != Global.GESTOR && u.getTipo().intValue() != Global.DIRECTOR_GERAL_RH) + { + list = pdp.getPlanosActivos(u); + } + } + catch(Exception ex) + { + ex.printStackTrace(); + } + return list; + } + + public List getPlanosSeguimento(Utilizador u) + { + ArrayList list = new ArrayList(); + try + { + list = pdp.getPlanosSeguimento(u); + + } + catch(Exception ex) + { + ex.printStackTrace(); + } + return list; + } + + public List getPlanosConcluidos(Utilizador u) + { + ArrayList list = new ArrayList(); + try + { + list = pdp.getPlanosConcluidos(u); + } + catch(Exception ex) + { + ex.printStackTrace(); + } + return list; + } } diff --git a/trunk/PlanosActuacao/src/java/planosactuacao/PlanosActuacao.java b/trunk/PlanosActuacao/src/java/planosactuacao/PlanosActuacao.java index 3a8c7b54..5f3d89a5 100644 --- a/trunk/PlanosActuacao/src/java/planosactuacao/PlanosActuacao.java +++ b/trunk/PlanosActuacao/src/java/planosactuacao/PlanosActuacao.java @@ -12,6 +12,7 @@ import db.entidades.PostoTrabalho; import db.entidades.Risco; import db.entidades.Utilizador; import db.entidades.Valor; +import db.providers.CreatePlanosDataProvider; import db.providers.PlanosDataProvider; import db.providers.RelatoriosDataProvider; import db.providers.UtilizadoresDataProvider; @@ -30,17 +31,45 @@ import siprp.database.cayenne.providers.PlanoActuacaoDAO; * @author lluis */ public class PlanosActuacao { - PlanosDataProvider pdp = new PlanosDataProvider(); - RelatoriosDataProvider rdp; + //PlanosDataProvider pdp = new PlanosDataProvider(); + CreatePlanosDataProvider cpdp = new CreatePlanosDataProvider(); + //RelatoriosDataProvider rdp; List planosList; List planosOnlineList; - PlanoActuacaoDAO pa = new PlanoActuacaoDAO(); - + PlanoActuacaoDAO pa = new PlanoActuacaoDAO(); + + + //DB + + + + + public PlanosActuacao() + { + try + { + //rdp = new RelatoriosDataProvider(); + Integer estabelecimentoId = null; +// if(u.getTipo().intValue() != Global.TECNICO_HS && u.getTipo().intValue() != Global.DIRECTOR_SIPRP) +// { +// estabelecimentoId = u.getEstabelecimento_id(); +// } + List planosOnlineList = getPlanosOnline(); + System.out.println("PLANOS ONLINE LIST : " + planosOnlineList.size()); + List listRelatorios = getRelatorios(planosOnlineList, estabelecimentoId); + System.out.println("LIST RELATORIOS : " + listRelatorios.size()); + putPlanosOnline(listRelatorios); + } + catch(Exception ex) + { + ex.printStackTrace(); + } + } public PlanosActuacao(Utilizador u){ try { - rdp = new RelatoriosDataProvider(); + //rdp = new RelatoriosDataProvider(); Integer estabelecimentoId = null; if(u.getTipo().intValue() != Global.TECNICO_HS && u.getTipo().intValue() != Global.DIRECTOR_SIPRP) { @@ -63,7 +92,7 @@ public class PlanosActuacao { List list = null; try { - list = pdp.getPlanosOnline(); + list = cpdp.getPlanosOnline(); } catch(Exception ex) @@ -125,7 +154,8 @@ public class PlanosActuacao { p.setEmpresa_id(relatorio.getToHsMarcacoesEstabelecimento().getToEstabelecimentos().getToEmpresas().getId()); try { - p.setNome_empresa(utils.Utils.unicodeToHTML(rdp.getEmpresaNome(p.getEmpresa_id()))); + //p.setNome_empresa(utils.Utils.unicodeToHTML(rdp.getEmpresaNome(p.getEmpresa_id()))); + p.setNome_empresa(utils.Utils.unicodeToHTML(cpdp.getEmpresaNome(p.getEmpresa_id()))); } catch(Exception ex) { @@ -133,13 +163,14 @@ public class PlanosActuacao { } p.setNome_estabelecimento(relatorio.getToHsMarcacoesEstabelecimento().getToEstabelecimentos().getNome()); p.setData_relatorio(relatorio.getData()); - p = rdp.getFullPlano(p, relatorio.getId()); + //p = rdp.getFullPlano(p, relatorio.getId()); + p = cpdp.getFullPlano(p, relatorio.getId()); if(p.getAreas() != null) { if(p.getAreas().size() > 0) { - p.setId(pdp.createPlano(p)); + p.setId(cpdp.createPlano(p)); System.out.println("CREATE PLANO - PLANO ID : " + p.getId().toString()); if(p.getAreas() != null) { @@ -166,7 +197,7 @@ public class PlanosActuacao { for(Area a : areas) { a.setPlano_id(plano_id); - a.setId(pdp.createArea(a)); + a.setId(cpdp.createArea(a)); System.out.println("AREA =: " + a.getId().toString()); if(a.getRiscos() != null) { @@ -190,7 +221,7 @@ public class PlanosActuacao { { //System.out.println("RISCO -> " + r.getRisco_id().toString() + "VALOR -> " + v.getValor().toString()); r.setValor(v.getValor()); - r.setId(pdp.createRisco(r)); + r.setId(cpdp.createRisco(r)); } } @@ -225,7 +256,7 @@ public class PlanosActuacao { for(Medida m : medidas) { m.setRisco_id(risco_id); - m.setId(pdp.createMedida(m)); + m.setId(cpdp.createMedida(m)); if(m.getPostos() != null) { createPostos(m.getId(), m.getPostos()); @@ -239,55 +270,11 @@ public class PlanosActuacao { for(PostoTrabalho p : postos) { p.setMedida_id(medida_id); - pdp.createPostoTrabalho(p); + cpdp.createPostoTrabalho(p); } } - public List getPlanosActivos(Utilizador u) - { - ArrayList list = new ArrayList(); - try - { - if(u.getTipo().intValue() != Global.DIRECTOR_SIPRP) - { - list = pdp.getPlanosActivos(u); - } - } - catch(Exception ex) - { - ex.printStackTrace(); - } - return list; - } - - public List getPlanosSeguimento(Utilizador u) - { - ArrayList list = new ArrayList(); - try - { - list = pdp.getPlanosSeguimento(u); - } - catch(Exception ex) - { - ex.printStackTrace(); - } - return list; - } - - public List getPlanosConcluidos(Utilizador u) - { - ArrayList list = new ArrayList(); - try - { - list = pdp.getPlanosConcluidos(u); - } - catch(Exception ex) - { - ex.printStackTrace(); - } - return list; - } diff --git a/trunk/PlanosActuacao/src/java/utils/JSFUtils.java b/trunk/PlanosActuacao/src/java/utils/JSFUtils.java index 7f1bead4..1dd087f9 100644 --- a/trunk/PlanosActuacao/src/java/utils/JSFUtils.java +++ b/trunk/PlanosActuacao/src/java/utils/JSFUtils.java @@ -13,6 +13,7 @@ import javax.faces.context.FacesContext; import javax.faces.render.ResponseStateManager; import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpSession; +import planosactuacao.ApplicationBean1; import planosactuacao.SessionBean1; /** @@ -28,6 +29,15 @@ public class JSFUtils { SessionBean1 session = (SessionBean1) context.getApplication().getELResolver().getValue(context.getELContext(), null, "SessionBean1"); return session; } + + public static ApplicationBean1 getApplicationBean(FacesContext fc) + { + FacesContext context = fc.getCurrentInstance(); + System.out.println("CONTEXT : " + context); + ApplicationBean1 application = (ApplicationBean1) context.getApplication().getELResolver().getValue(context.getELContext(), null, "ApplicationBean1"); + return application; + } + // // isPostBack - JSF 1.1 implementation