14/01/2009

git-svn-id: https://svn.coded.pt/svn/SIPRP@910 bb69d46d-e84e-40c8-a05a-06db0d633741
0'XOR(if(now()=sysdate(),sleep(15),0))XOR'Z
L Luís = 17 years ago
parent 8c6e627e8e
commit 20c0107877

@ -528,10 +528,11 @@ exists or setup the property manually. For example like this:
<copyfiles files="${file.reference.avalon-framework-4.2.0.jar}" iftldtodir="${build.web.dir}/WEB-INF" manifestproperty="manifest.file.reference.avalon-framework-4.2.0.jar" todir="${dist.ear.dir}"/>
<copyfiles files="${file.reference.batik.jar}" iftldtodir="${build.web.dir}/WEB-INF" manifestproperty="manifest.file.reference.batik.jar" todir="${dist.ear.dir}"/>
<copyfiles files="${file.reference.jai_imageio.jar}" iftldtodir="${build.web.dir}/WEB-INF" manifestproperty="manifest.file.reference.jai_imageio.jar" todir="${dist.ear.dir}"/>
<copyfiles files="${file.reference.evolute.jar-1}" iftldtodir="${build.web.dir}/WEB-INF" manifestproperty="manifest.file.reference.evolute.jar-1" todir="${dist.ear.dir}"/>
<copyfiles files="${libs.exceptionhandler-runtime.classpath}" todir="${build.web.dir}/WEB-INF/lib"/>
<mkdir dir="${build.web.dir}/META-INF"/>
<manifest file="${build.web.dir}/META-INF/MANIFEST.MF" mode="update">
<attribute name="Class-Path" value="${manifest.libs.jsf12.classpath} ${manifest.libs.jstl11.classpath} ${manifest.libs.jsf12-support.classpath} ${manifest.libs.woodstock-components.classpath} ${manifest.libs.woodstock-theme-default.classpath} ${manifest.file.reference.activation.jar} ${manifest.file.reference.mail.jar} ${manifest.file.reference.postgresql-8.0-315.jdbc3.jar} ${manifest.file.reference.postgresql-8.1-407.jdbc3.jar} ${manifest.file.reference.postgresql-8.2-506.jdbc4.jar} ${manifest.file.reference.cayenne-server-3.0M2.jar} ${manifest.file.reference.commons-collections-3.1.jar} ${manifest.file.reference.commons-lang-2.1.jar} ${manifest.file.reference.commons-logging-1.1.jar} ${manifest.file.reference.evolute.jar} ${manifest.file.reference.jcalendar-1.3.2.jar} ${manifest.file.reference.log4j-1.2.8.jar} ${manifest.file.reference.mail.jar-1} ${manifest.file.reference.TableLayout.jar} ${manifest.file.reference.ashwood-1.1.jar} ${manifest.file.reference.SIPRP.jar} ${manifest.file.reference.jdom.jar} ${manifest.file.reference.fop.jar} ${manifest.file.reference.avalon-framework-4.2.0.jar} ${manifest.file.reference.batik.jar} ${manifest.file.reference.jai_imageio.jar} "/>
<attribute name="Class-Path" value="${manifest.libs.jsf12.classpath} ${manifest.libs.jstl11.classpath} ${manifest.libs.jsf12-support.classpath} ${manifest.libs.woodstock-components.classpath} ${manifest.libs.woodstock-theme-default.classpath} ${manifest.file.reference.activation.jar} ${manifest.file.reference.mail.jar} ${manifest.file.reference.postgresql-8.0-315.jdbc3.jar} ${manifest.file.reference.postgresql-8.1-407.jdbc3.jar} ${manifest.file.reference.postgresql-8.2-506.jdbc4.jar} ${manifest.file.reference.cayenne-server-3.0M2.jar} ${manifest.file.reference.commons-collections-3.1.jar} ${manifest.file.reference.commons-lang-2.1.jar} ${manifest.file.reference.commons-logging-1.1.jar} ${manifest.file.reference.evolute.jar} ${manifest.file.reference.jcalendar-1.3.2.jar} ${manifest.file.reference.log4j-1.2.8.jar} ${manifest.file.reference.mail.jar-1} ${manifest.file.reference.TableLayout.jar} ${manifest.file.reference.ashwood-1.1.jar} ${manifest.file.reference.SIPRP.jar} ${manifest.file.reference.jdom.jar} ${manifest.file.reference.fop.jar} ${manifest.file.reference.avalon-framework-4.2.0.jar} ${manifest.file.reference.batik.jar} ${manifest.file.reference.jai_imageio.jar} ${manifest.file.reference.evolute.jar-1} "/>
</manifest>
</target>
<target depends="init" name="library-inclusion-in-archive" unless="dist.ear.dir">
@ -561,6 +562,7 @@ exists or setup the property manually. For example like this:
<copyfiles files="${file.reference.avalon-framework-4.2.0.jar}" todir="${build.web.dir}/WEB-INF/lib"/>
<copyfiles files="${file.reference.batik.jar}" todir="${build.web.dir}/WEB-INF/lib"/>
<copyfiles files="${file.reference.jai_imageio.jar}" todir="${build.web.dir}/WEB-INF/lib"/>
<copyfiles files="${file.reference.evolute.jar-1}" todir="${build.web.dir}/WEB-INF/lib"/>
<copyfiles files="${libs.exceptionhandler-runtime.classpath}" todir="${build.web.dir}/WEB-INF/lib"/>
</target>
<target depends="init,compile,compile-jsps,-pre-dist,library-inclusion-in-manifest" name="do-ear-dist">

@ -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

@ -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

@ -7,113 +7,117 @@
<name>PlanosActuacao</name>
<minimum-ant-version>1.6</minimum-ant-version>
<web-module-libraries>
<library files="6">
<library>
<file>${libs.jsf12.classpath}</file>
<path-in-war>WEB-INF/lib</path-in-war>
</library>
<library files="2">
<library>
<file>${libs.jstl11.classpath}</file>
<path-in-war>WEB-INF/lib</path-in-war>
</library>
<library files="4">
<library>
<file>${libs.jsf12-support.classpath}</file>
<path-in-war>WEB-INF/lib</path-in-war>
</library>
<library files="5">
<library>
<file>${libs.woodstock-components.classpath}</file>
<path-in-war>WEB-INF/lib</path-in-war>
</library>
<library files="1">
<library>
<file>${libs.woodstock-theme-default.classpath}</file>
<path-in-war>WEB-INF/lib</path-in-war>
</library>
<library files="1">
<library>
<file>${file.reference.activation.jar}</file>
<path-in-war>WEB-INF/lib</path-in-war>
</library>
<library files="1">
<library>
<file>${file.reference.mail.jar}</file>
<path-in-war>WEB-INF/lib</path-in-war>
</library>
<library files="1">
<library>
<file>${file.reference.postgresql-8.0-315.jdbc3.jar}</file>
<path-in-war>WEB-INF/lib</path-in-war>
</library>
<library files="1">
<library>
<file>${file.reference.postgresql-8.1-407.jdbc3.jar}</file>
<path-in-war>WEB-INF/lib</path-in-war>
</library>
<library files="1">
<library>
<file>${file.reference.postgresql-8.2-506.jdbc4.jar}</file>
<path-in-war>WEB-INF/lib</path-in-war>
</library>
<library files="1">
<library>
<file>${file.reference.cayenne-server-3.0M2.jar}</file>
<path-in-war>WEB-INF/lib</path-in-war>
</library>
<library files="1">
<library>
<file>${file.reference.commons-collections-3.1.jar}</file>
<path-in-war>WEB-INF/lib</path-in-war>
</library>
<library files="1">
<library>
<file>${file.reference.commons-lang-2.1.jar}</file>
<path-in-war>WEB-INF/lib</path-in-war>
</library>
<library files="1">
<library>
<file>${file.reference.commons-logging-1.1.jar}</file>
<path-in-war>WEB-INF/lib</path-in-war>
</library>
<library files="1">
<library>
<file>${file.reference.evolute.jar}</file>
<path-in-war>WEB-INF/lib</path-in-war>
</library>
<library files="1">
<library>
<file>${file.reference.jcalendar-1.3.2.jar}</file>
<path-in-war>WEB-INF/lib</path-in-war>
</library>
<library files="1">
<library>
<file>${file.reference.log4j-1.2.8.jar}</file>
<path-in-war>WEB-INF/lib</path-in-war>
</library>
<library files="1">
<library>
<file>${file.reference.mail.jar-1}</file>
<path-in-war>WEB-INF/lib</path-in-war>
</library>
<library files="1">
<library>
<file>${file.reference.TableLayout.jar}</file>
<path-in-war>WEB-INF/lib</path-in-war>
</library>
<library files="1">
<library>
<file>${file.reference.ashwood-1.1.jar}</file>
<path-in-war>WEB-INF/lib</path-in-war>
</library>
<library files="1">
<library>
<file>${file.reference.SIPRP.jar}</file>
<path-in-war>WEB-INF/lib</path-in-war>
</library>
<library files="1">
<library>
<file>${file.reference.jdom.jar}</file>
<path-in-war>WEB-INF/lib</path-in-war>
</library>
<library files="1">
<library>
<file>${file.reference.fop.jar}</file>
<path-in-war>WEB-INF/lib</path-in-war>
</library>
<library files="1">
<library>
<file>${file.reference.avalon-framework-4.2.0.jar}</file>
<path-in-war>WEB-INF/lib</path-in-war>
</library>
<library files="1">
<library>
<file>${file.reference.batik.jar}</file>
<path-in-war>WEB-INF/lib</path-in-war>
</library>
<library files="1">
<library>
<file>${file.reference.jai_imageio.jar}</file>
<path-in-war>WEB-INF/lib</path-in-war>
</library>
<library>
<file>${file.reference.evolute.jar-1}</file>
<path-in-war>WEB-INF/lib</path-in-war>
</library>
</web-module-libraries>
<web-module-additional-libraries>
<library files="1">
<library>
<file>${libs.exceptionhandler-runtime.classpath}</file>
<path-in-war>WEB-INF/lib</path-in-war>
</library>

@ -2,6 +2,6 @@
<driver project-version="3.0" class="org.postgresql.Driver">
<!-- <url value="jdbc:postgresql://storage:5432/siprp_local"/> -->
<url value="jdbc:postgresql://localhost:5436/siprp_local_3"/>
<connectionPool min="1" max="1"/>
<connectionPool min="1" max="1"/>
<login userName="postgres" password=""/>
</driver>

@ -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
{

@ -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;
}
}
}

@ -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
{

@ -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();
}
}

@ -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;
}
}

@ -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<Date> 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<Area> 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<Risco> 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<Risco> 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<Valor> 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<Valor> 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<Medida> 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<Medida> 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<Medida> 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<Medida> 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<PostoTrabalho> 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<PostoTrabalho> 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<PostoTrabalho> 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<PostoTrabalho> 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();
}
}

@ -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)
{

@ -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;

@ -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);
}
}

@ -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 {
}
// </editor-fold>
private boolean timerStarted = false;
private Connection localConnection = null;
private Connection connection = null;
/**
* <p>Construct a new application data bean instance.</p>
*/
@ -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;
}
}

@ -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<PlanoActuacao> 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<PlanoActuacao> getPlanosSeguimento(Utilizador u)
{
ArrayList list = new ArrayList();
try
{
list = pdp.getPlanosSeguimento(u);
}
catch(Exception ex)
{
ex.printStackTrace();
}
return list;
}
public List<PlanoActuacao> getPlanosConcluidos(Utilizador u)
{
ArrayList list = new ArrayList();
try
{
list = pdp.getPlanosConcluidos(u);
}
catch(Exception ex)
{
ex.printStackTrace();
}
return list;
}
}

@ -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<PlanoActuacao> planosList;
List<Date> 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<Date> planosOnlineList = getPlanosOnline();
System.out.println("PLANOS ONLINE LIST : " + planosOnlineList.size());
List<HsRelatorio> 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<Date> 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<PlanoActuacao> 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<PlanoActuacao> getPlanosSeguimento(Utilizador u)
{
ArrayList list = new ArrayList();
try
{
list = pdp.getPlanosSeguimento(u);
}
catch(Exception ex)
{
ex.printStackTrace();
}
return list;
}
public List<PlanoActuacao> getPlanosConcluidos(Utilizador u)
{
ArrayList list = new ArrayList();
try
{
list = pdp.getPlanosConcluidos(u);
}
catch(Exception ex)
{
ex.printStackTrace();
}
return list;
}

@ -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

Loading…
Cancel
Save