diff --git a/trunk/PlanosActuacao/src/java/db/Dblocal.java b/trunk/PlanosActuacao/src/java/db/Dblocal.java new file mode 100644 index 00000000..64b8fd80 --- /dev/null +++ b/trunk/PlanosActuacao/src/java/db/Dblocal.java @@ -0,0 +1,65 @@ +/* + * Dblocal.java + * + * Created on September 20, 2007, 2:07 PM + * + * To change this template, choose Tools | Template Manager + * 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 javax.servlet.http.HttpSession; + +/** + * + * @author lluis + */ +public class Dblocal { + String connectionURL = "jdbc:postgresql://storage/siprp_local"; //testes + //String connectionURL = "jdbc:postgresql://localhost:5436/siprp_local_3"; + String User = "postgres"; + String Pass = null; + Connection connection = null; + + /** Creates a new instance of 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); + 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/Area.java b/trunk/PlanosActuacao/src/java/db/entidades/Area.java new file mode 100644 index 00000000..1926e05f --- /dev/null +++ b/trunk/PlanosActuacao/src/java/db/entidades/Area.java @@ -0,0 +1,51 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ + +package db.entidades; + +import java.util.List; + +/** + * + * @author lluis + */ +public class Area { + private Integer id; + private Integer plano_id; + private String descricao; + private List riscos; + + public Integer getId() { + return id; + } + + public void setId(Integer id) { + this.id = id; + } + + public String getDescricao() { + return descricao; + } + + public void setDescricao(String descricao) { + this.descricao = descricao; + } + + public List getRiscos() { + return riscos; + } + + public void setRiscos(List riscos) { + this.riscos = riscos; + } + + public Integer getPlano_id() { + return plano_id; + } + + public void setPlano_id(Integer plano_id) { + this.plano_id = plano_id; + } +} diff --git a/trunk/PlanosActuacao/src/java/db/entidades/Medida.java b/trunk/PlanosActuacao/src/java/db/entidades/Medida.java index 3324117f..140c7cbc 100644 --- a/trunk/PlanosActuacao/src/java/db/entidades/Medida.java +++ b/trunk/PlanosActuacao/src/java/db/entidades/Medida.java @@ -14,7 +14,7 @@ import java.util.Vector; */ public class Medida { private Integer id; - private Integer risco_id; + private Integer valor_id; private String descricao; private String activa; private List postos; @@ -43,12 +43,12 @@ public class Medida { this.activa = activa; } - public Integer getRisco_id() { - return risco_id; + public Integer getValor_id() { + return valor_id; } - public void setRisco_id(Integer risco_id) { - this.risco_id = risco_id; + public void setValor_id(Integer valor_id) { + this.valor_id = valor_id; } public List getPostos() { diff --git a/trunk/PlanosActuacao/src/java/db/entidades/PlanoActuacao.java b/trunk/PlanosActuacao/src/java/db/entidades/PlanoActuacao.java index 1e851ac3..1894fa7d 100644 --- a/trunk/PlanosActuacao/src/java/db/entidades/PlanoActuacao.java +++ b/trunk/PlanosActuacao/src/java/db/entidades/PlanoActuacao.java @@ -20,6 +20,7 @@ public class PlanoActuacao { private String nome_estabelecimento; private Integer fase; private String descricao; + private List areas; private List riscos; // @@ -128,4 +129,12 @@ public class PlanoActuacao { public void setNome_estabelecimento(String nome_estabelecimento) { this.nome_estabelecimento = nome_estabelecimento; } + + public List getAreas() { + return areas; + } + + public void setAreas(List areas) { + this.areas = areas; + } } diff --git a/trunk/PlanosActuacao/src/java/db/entidades/PostoTrabalho.java b/trunk/PlanosActuacao/src/java/db/entidades/PostoTrabalho.java index a6987b24..21e7b707 100644 --- a/trunk/PlanosActuacao/src/java/db/entidades/PostoTrabalho.java +++ b/trunk/PlanosActuacao/src/java/db/entidades/PostoTrabalho.java @@ -11,7 +11,6 @@ package db.entidades; */ public class PostoTrabalho { private Integer id; - private Integer risco_id; private Integer medida_id; private String descricao; private String activo; @@ -40,14 +39,6 @@ public class PostoTrabalho { this.activo = activo; } - public Integer getRisco_id() { - return risco_id; - } - - public void setRisco_id(Integer risco_id) { - this.risco_id = risco_id; - } - public Integer getMedida_id() { return medida_id; } diff --git a/trunk/PlanosActuacao/src/java/db/entidades/Risco.java b/trunk/PlanosActuacao/src/java/db/entidades/Risco.java index d5c1e49c..6fb65ea3 100644 --- a/trunk/PlanosActuacao/src/java/db/entidades/Risco.java +++ b/trunk/PlanosActuacao/src/java/db/entidades/Risco.java @@ -14,11 +14,12 @@ import java.util.Vector; */ public class Risco { private Integer id; - private Integer plano_id; + private Integer area_id; private String descricao; private String activo; private Integer valor; + private List valores; private List medidas; public Integer getId() { @@ -45,12 +46,12 @@ public class Risco { this.activo = activo; } - public Integer getPlano_id() { - return plano_id; + public Integer getArea_id() { + return area_id; } - public void setPlano_id(Integer plano_id) { - this.plano_id = plano_id; + public void setArea_id(Integer area_id) { + this.area_id = area_id; } public Integer getValor() { @@ -68,4 +69,12 @@ public class Risco { public void setMedidas(List medidas) { this.medidas = medidas; } + + public List getValores() { + return valores; + } + + public void setValores(List valores) { + this.valores = valores; + } } diff --git a/trunk/PlanosActuacao/src/java/db/entidades/Valor.java b/trunk/PlanosActuacao/src/java/db/entidades/Valor.java new file mode 100644 index 00000000..1dcc852d --- /dev/null +++ b/trunk/PlanosActuacao/src/java/db/entidades/Valor.java @@ -0,0 +1,51 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ + +package db.entidades; + +import java.util.List; + +/** + * + * @author lluis + */ +public class Valor { + private Integer id; + private Integer risco_id; + private Integer valor; + private List medidas; + + public Integer getValor() { + return valor; + } + + public void setValor(Integer valor) { + this.valor = valor; + } + + public List getMedidas() { + return medidas; + } + + public void setMedidas(List medidas) { + this.medidas = medidas; + } + + public Integer getId() { + return id; + } + + public void setId(Integer id) { + this.id = id; + } + + public Integer getRisco_id() { + return risco_id; + } + + public void setRisco_id(Integer risco_id) { + this.risco_id = risco_id; + } +} diff --git a/trunk/PlanosActuacao/src/java/db/providers/PlanosDataProvider.java b/trunk/PlanosActuacao/src/java/db/providers/PlanosDataProvider.java index eec27bdd..fa2adb5d 100644 --- a/trunk/PlanosActuacao/src/java/db/providers/PlanosDataProvider.java +++ b/trunk/PlanosActuacao/src/java/db/providers/PlanosDataProvider.java @@ -5,11 +5,13 @@ package db.providers; +import db.entidades.Area; import db.entidades.Medida; import db.entidades.PlanoActuacao; import db.entidades.PostoTrabalho; import db.entidades.Risco; import db.entidades.Utilizador; +import db.entidades.Valor; import global.Global; import java.sql.ResultSet; import java.sql.Statement; @@ -56,6 +58,80 @@ public class PlanosDataProvider extends GenericDataProvider{ st.execute(sql); } + public Integer createArea(Area a) throws Exception + { + Statement st = createStatement(); + Integer newId = getMaxTableId("plano_areas"); + String sql = "insert into plano_areas (id, plano_id, descricao) values ("; + sql += newId + ", "; + 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) values ("; + sql += newId + ", "; + sql += r.getArea_id() + ", '"; + sql += r.getDescricao() + "' "; + 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, valor_id, descricao) values ("; + sql += newId + ", "; + sql += m.getValor_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, medida_id, descricao) values ("; + sql += newId + ", "; + sql += p.getMedida_id() + ", '"; + sql += p.getDescricao() + "' "; + sql += ")"; + + System.out.println("SQL CREATE POSTO : " + sql); + st.execute(sql); + } + public List getPlanosOnline() throws Exception { ArrayList list = new ArrayList(); @@ -102,7 +178,7 @@ public class PlanosDataProvider extends GenericDataProvider{ } ResultSet rs = st.executeQuery(sql); - ArrayList list = fillPlanoFields(rs); + ArrayList list = getFullPlanos(rs); return list; } @@ -134,7 +210,7 @@ public class PlanosDataProvider extends GenericDataProvider{ } ResultSet rs = st.executeQuery(sql); - ArrayList list = fillPlanoFields(rs); + ArrayList list = getFullPlanos(rs); return list; } @@ -143,11 +219,11 @@ public class PlanosDataProvider extends GenericDataProvider{ Statement st = createStatement(); String sql = "select * from planos_actuacao where fase = 6"; ResultSet rs = st.executeQuery(sql); - ArrayList list = fillPlanoFields(rs); + ArrayList list = getFullPlanos(rs); return list; } - private ArrayList fillPlanoFields(ResultSet rs) throws Exception + private ArrayList getFullPlanos(ResultSet rs) throws Exception { ArrayList list = new ArrayList(); if(rs.isBeforeFirst()) @@ -162,6 +238,7 @@ public class PlanosDataProvider extends GenericDataProvider{ pa.setFase( new Integer( rs.getInt("fase") ) ); java.sql.Date sqlDate = rs.getDate("data_visita"); pa.setData_visita(new java.util.Date(sqlDate.getTime())); + pa.setAreas(getAreasByPlano(pa)); list.add(pa); }while(rs.next()); @@ -169,6 +246,124 @@ public class PlanosDataProvider extends GenericDataProvider{ return list; } + private List getAreasByPlano(PlanoActuacao p) throws Exception + { + Statement st = createStatement(); + String sql = "SELECT * FROM plano_areas WHERE plano_id = " + p.getId(); + 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("id")) ); + a.setPlano_id(new Integer( rs.getInt("plano_id") )); + a.setDescricao(rs.getString("descricao")); + a.setRiscos(getRiscosByArea(a)); + areas.add(a); + }while(rs.next()); + } + + return areas; + } + + private List getRiscosByArea(Area a) throws Exception + { + List riscos = new ArrayList(); + Statement st = createStatement(); + String sql = "SELECT * FROM plano_riscos WHERE area_id = " + a.getId(); + ResultSet rs = st.executeQuery(sql); + + if(rs.isBeforeFirst()) + { + rs.first(); + do + { + Risco r = new Risco(); + r.setId( new Integer(rs.getInt("id")) ); + r.setArea_id(new Integer( rs.getInt("area_id") )); + r.setDescricao(rs.getString("descricao")); + r.setValores(getValoresByRisco(r)); + riscos.add(r); + }while(rs.next()); + } + return riscos; + } + + private List getValoresByRisco(Risco r) throws Exception + { + List valores = new ArrayList(); + + Statement st = createStatement(); + String sql = "SELECT * FROM plano_valores WHERE risco_id = " + r.getId(); + ResultSet rs = st.executeQuery(sql); + + if(rs.isBeforeFirst()) + { + rs.first(); + do + { + Valor v = new Valor(); + v.setId( new Integer(rs.getInt("id")) ); + v.setRisco_id(new Integer( rs.getInt("risco_id") )); + v.setValor(new Integer(rs.getInt("valor"))); + v.setMedidas(getMedidasByValor(v)); + valores.add(v); + }while(rs.next()); + } + return valores; + } + + private List getMedidasByValor(Valor v) throws Exception + { + List medidas = new ArrayList(); + + Statement st = createStatement(); + String sql = "SELECT * FROM plano_medidas WHERE valor_id = " + v.getId(); + ResultSet rs = st.executeQuery(sql); + + if(rs.isBeforeFirst()) + { + rs.first(); + do + { + Medida m = new Medida(); + m.setId( new Integer(rs.getInt("id")) ); + m.setValor_id(new Integer( rs.getInt("valor_id") )); + m.setDescricao(rs.getString("descricao")); + m.setPostos(getPostosByMedida(m)); + medidas.add(m); + }while(rs.next()); + } + return medidas; + } + + private List getPostosByMedida(Medida m) throws Exception + { + List postos = new ArrayList(); + + Statement st = createStatement(); + String sql = "SELECT * FROM plano_postos_trabalho WHERE medida_id = " + m.getId(); + ResultSet rs = st.executeQuery(sql); + + if(rs.isBeforeFirst()) + { + rs.first(); + do + { + PostoTrabalho p = new PostoTrabalho(); + p.setId( new Integer(rs.getInt("id")) ); + p.setMedida_id(new Integer( rs.getInt("medida_id") )); + p.setDescricao(rs.getString("descricao")); + postos.add(p); + }while(rs.next()); + } + return postos; + } + // POSTOS TRABALHO public void createPostoTrabalhoByRisco(Integer postoTrabalhoId, Integer riscoId, Integer planoId) throws Exception { @@ -203,28 +398,28 @@ public class PlanosDataProvider extends GenericDataProvider{ return pt; } - public ArrayList getPostosTrabalhoByRisco(Integer planoId, Integer riscoId) throws Exception - { - ArrayList list = new ArrayList(); - Statement st = createStatement(); - String sql = "SELECT * FROM postos_trabalho_risco WHERE plano_id = " + planoId + " AND risco_id = " + riscoId; - - ResultSet rs = st.executeQuery(sql); - - if(rs.isBeforeFirst()) - { - rs.first(); - do - { - Integer postoTrabalhoId = new Integer( rs.getInt("posto_trabalho_id") ); - PostoTrabalho pt = getPostoTrabalho(postoTrabalhoId); - pt.setRisco_id(riscoId); - list.add(pt); - }while(rs.next()); - } - - return list; - } +// public ArrayList getPostosTrabalhoByRisco(Integer planoId, Integer riscoId) throws Exception +// { +// ArrayList list = new ArrayList(); +// Statement st = createStatement(); +// String sql = "SELECT * FROM postos_trabalho_risco WHERE plano_id = " + planoId + " AND risco_id = " + riscoId; +// +// ResultSet rs = st.executeQuery(sql); +// +// if(rs.isBeforeFirst()) +// { +// rs.first(); +// do +// { +// Integer postoTrabalhoId = new Integer( rs.getInt("posto_trabalho_id") ); +// PostoTrabalho pt = getPostoTrabalho(postoTrabalhoId); +// pt.setRisco_id(riscoId); +// list.add(pt); +// }while(rs.next()); +// } +// +// return list; +// } // RISCOS public void createRiscoByPlano(Integer riscoId, Integer planoId) throws Exception @@ -259,28 +454,28 @@ public class PlanosDataProvider extends GenericDataProvider{ return r; } - public ArrayList getRiscosByPlano(Integer planoId) throws Exception - { - ArrayList list = new ArrayList(); - Statement st = createStatement(); - String sql = "SELECT * FROM riscos_plano_actuacao WHERE plano_id = " + planoId; - - ResultSet rs = st.executeQuery(sql); - - if(rs.isBeforeFirst()) - { - rs.first(); - do - { - Integer riscoId = new Integer( rs.getInt("risco_id") ); - Risco r = getRisco(riscoId); - r.setPlano_id(planoId); - list.add(r); - }while(rs.next()); - } - - return list; - } +// public ArrayList getRiscosByPlano(Integer planoId) throws Exception +// { +// ArrayList list = new ArrayList(); +// Statement st = createStatement(); +// String sql = "SELECT * FROM riscos_plano_actuacao WHERE plano_id = " + planoId; +// +// ResultSet rs = st.executeQuery(sql); +// +// if(rs.isBeforeFirst()) +// { +// rs.first(); +// do +// { +// Integer riscoId = new Integer( rs.getInt("risco_id") ); +// Risco r = getRisco(riscoId); +// r.setPlano_id(planoId); +// list.add(r); +// }while(rs.next()); +// } +// +// return list; +// } // MEDIDAS public void createMedidaByRisco(Integer medidaId, Integer riscoId, Integer planoId) throws Exception diff --git a/trunk/PlanosActuacao/src/java/db/providers/RelatoriosDataProvider.java b/trunk/PlanosActuacao/src/java/db/providers/RelatoriosDataProvider.java new file mode 100644 index 00000000..cefa7edb --- /dev/null +++ b/trunk/PlanosActuacao/src/java/db/providers/RelatoriosDataProvider.java @@ -0,0 +1,220 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ + +package db.providers; + +import db.Dblocal; +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.List; + +/** + * + * @author lluis + */ +public class RelatoriosDataProvider extends GenericDataProvider { + Dblocal dblocal = new Dblocal(); + + public RelatoriosDataProvider() throws Exception + { + dblocal.connect(); + } + + 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 = dblocal.createStatement(); + + 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.setDescricao(rs.getString("descricao")); + try + { + a.setRiscos(getRiscosByArea(a)); + } + catch(Exception ex) + { + a.setRiscos(null); + } + + areas.add(a); + }while(rs.next()); + plano.setAreas(areas); + } + return plano; + } + + private List getRiscosByArea(Area a) throws Exception + { + Statement st = dblocal.createStatement(); + 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") )); + r.setDescricao(rs.getString("descricao")); + r.setValores(getValoresByRisco(r, a)); + riscos.add(r); + }while(rs.next()); + } + return riscos; + + } + + private List getValoresByRisco(Risco r, Area a) throws Exception + { + Statement st = dblocal.createStatement(); + String sql = "select valor from "; + sql += "(select distinct hs_relatorio_posto_risco.risco_id, "; + sql += "case hs_relatorio_posto_risco.valor_qualitativo_id isnull when true 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(); + if(rs.isBeforeFirst()) + { + rs.first(); + do + { + Valor v = new Valor(); + int valor = rs.getInt("valor"); + v.setValor(new Integer(valor)); + v.setMedidas(getMedidasByValor(v, r, a)); + valores.add(v); + }while(rs.next()); + } + return valores; + } + + 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 hs_relatorio_posto_risco.valor_qualitativo_id isnull when true 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 += "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(rs.getString("descricao")); + m.setPostos(getPostosByMedidaAndValor(m, v, 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 hs_relatorio_posto_risco.valor_qualitativo_id isnull when true 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(rs.getString("descricao")); + postos.add(p); + }while(rs.next()); + } + return postos; + } +} \ No newline at end of file diff --git a/trunk/PlanosActuacao/src/java/planosactuacao/EditarPlano.java b/trunk/PlanosActuacao/src/java/planosactuacao/EditarPlano.java index eb63431c..6378e0a4 100644 --- a/trunk/PlanosActuacao/src/java/planosactuacao/EditarPlano.java +++ b/trunk/PlanosActuacao/src/java/planosactuacao/EditarPlano.java @@ -17,14 +17,16 @@ import com.sun.webui.jsf.component.TextArea; import com.sun.webui.jsf.component.TextField; import com.sun.webui.jsf.model.Option; -import com.sun.webui.jsf.model.SingleSelectOptionsList; +import db.entidades.Area; import db.entidades.Medida; import db.entidades.PlanoActuacao; import db.entidades.PostoTrabalho; import db.entidades.Risco; import db.entidades.Utilizador; +import db.entidades.Valor; import db.providers.PlanosDataProvider; import global.Global; +import java.util.List; import java.util.Vector; import javax.faces.FacesException; import javax.faces.component.html.HtmlInputHidden; @@ -67,7 +69,11 @@ public class EditarPlano extends AbstractPageBean { Vector postos = new Vector(); HtmlPanelGrid gridPlano = new HtmlPanelGrid(); + HtmlPanelGrid gridArea; HtmlPanelGrid gridRisco; + HtmlPanelGrid gridValor; + HtmlPanelGrid gridMedida; + HtmlPanelGrid gridPosto; @@ -205,6 +211,15 @@ public class EditarPlano extends AbstractPageBean { public void setDrpIrPara(DropDown dd) { this.drpIrPara = dd; } + private StaticText lblTop = new StaticText(); + + public StaticText getLblTop() { + return lblTop; + } + + public void setLblTop(StaticText st) { + this.lblTop = st; + } /** *

Construct a new Page bean instance.

@@ -276,7 +291,6 @@ public class EditarPlano extends AbstractPageBean { */ @Override public void prerender() { - System.out.println("PRERENDER"); FacesContext fc = getFacesContext(); //boolean isPostback = JSFUtils.isPostBack12(fc); //boolean isPostback = JSFUtils.isPostBack(fc); @@ -284,9 +298,11 @@ public class EditarPlano extends AbstractPageBean { System.out.println("POSTBACK : " + isPostback); if(!isPostback) { - initializePlano(); - initialize(); - fillPlano(); + PlanoActuacao p = getSessionBean1().getPlanoActuacao(); + //initializePlano(); + initialize(p); + showPlano(p); + //fillPlano(); } else { @@ -344,370 +360,201 @@ public class EditarPlano extends AbstractPageBean { return "lista_planos"; } - private void fillPlano() - { - String indent = "      "; - Risco r = getNextRisco(plano.getId()); - fillRisco(r); - } - - private void fillRisco(Risco r) - { - String indent = "      "; - if(gridLayout.getChildren().size() > 0) - { - gridLayout.getChildren().clear(); - } - gridRisco = new HtmlPanelGrid(); - gridRisco.setWidth("100%"); - gridRisco.setStyle("border: solid 1px #000000"); - gridRisco.setColumns(1); - gridRisco.setColumnClasses("gridColLeft"); - - pg = new PanelGroup(); - st = new StaticText(); - st.setEscape(false); - st.setStyleClass("label"); - st.setStyle("color: #2c4d7a"); - st.setText("RISCO 1" + ": "); - pg.getChildren().add(st); - st = new StaticText(); - st.setEscape(false); - st.setText(r.getDescricao()); - pg.getChildren().add(st); - gridRisco.getChildren().add(pg); - - st = new StaticText(); - st.setEscape(false); - st.setText(" "); - gridRisco.getChildren().add(st); - - pg = new PanelGroup(); - st = new StaticText(); - st.setEscape(false); - st.setStyleClass("label"); - st.setText("Valor:" + " "); - pg.getChildren().add(st); - st = new StaticText(); - st.setEscape(false); - st.setText(r.getValor().toString()); - pg.getChildren().add(st); - gridRisco.getChildren().add(pg); - - st = new StaticText(); - st.setEscape(false); - st.setText(" "); - gridRisco.getChildren().add(st); - - //medidas - Vector meds = getMedidas(r.getId()); - for(int i = 0; i < meds.size(); i++) - { - Medida m = medidas.get(i); - if(m.getRisco_id().intValue() == r.getId().intValue()) - { - pg = new PanelGroup(); - st = new StaticText(); - st.setEscape(false); - st.setStyleClass("label"); - st.setText(indent + "Medida" + ": "); - pg.getChildren().add(st); - st = new StaticText(); - st.setEscape(false); - st.setText(m.getDescricao()); - pg.getChildren().add(st); - gridRisco.getChildren().add(pg); - - //postos trabalho - Vector posts = getPostosTrabalho(m.getId()); - pg = new PanelGroup(); - st = new StaticText(); - st.setEscape(false); - st.setStyleClass("label"); - st.setText(indent + indent + "Postos de trabalho afectados" + ": "); - pg.getChildren().add(st); - st = new StaticText(); - st.setEscape(false); - String spostos = ""; - for(int j = 0; j < posts.size(); j++) - { - PostoTrabalho p = posts.get(j); - spostos += p.getDescricao(); // + " "; - if(j < (posts.size() -1) ) - { - spostos += "; "; - } - } - st.setText(spostos); - pg.getChildren().add(st); - gridRisco.getChildren().add(pg); - } - } - - st = new StaticText(); - st.setEscape(false); - st.setText(" "); - gridRisco.getChildren().add(st); - - pg = new PanelGroup(); - st = new StaticText(); - st.setEscape(false); - st.setStyleClass("label"); - st.setText("Responsável de execução:"); - pg.getChildren().add(st); - txtResponsavelExecucao = new TextField(); - txtResponsavelExecucao.setColumns(100); - pg.getChildren().add(txtResponsavelExecucao); - gridRisco.getChildren().add(pg); - pg = new PanelGroup(); - st = new StaticText(); - st.setEscape(false); - st.setStyleClass("label"); - st.setText("Recursos necessários à implementação da medida:"); - pg.getChildren().add(st); - gridRisco.getChildren().add(pg); - txtRecursos = new TextArea(); - txtRecursos.setColumns(200); - gridRisco.getChildren().add(txtRecursos); - - HtmlPanelGrid grd = new HtmlPanelGrid(); - grd.setColumns(2); - grd.setColumnClasses("gridCol15, gridCol85"); - grd.setId("pgDtInicio"); - grd.setStyle("width: 100%"); - st = new StaticText(); - st.setEscape(false); - st.setStyleClass("label"); - st.setText("Data prevista de início:"); - grd.getChildren().add(st); - dtInicio = new Calendar(); - grd.getChildren().add(dtInicio); - gridRisco.getChildren().add(grd); - - grd = new HtmlPanelGrid(); - grd.setColumns(2); - grd.setColumnClasses("gridCol15, gridCol85"); - grd.setId("pgDtFim"); - grd.setStyle("width: 100%"); - st = new StaticText(); - st.setEscape(false); - st.setStyleClass("label"); - st.setText("Data prevista de conclusão:"); - grd.getChildren().add(st); - dtFim = new Calendar(); - - grd.getChildren().add(dtFim); - gridRisco.getChildren().add(grd); - - gridLayout.getChildren().add(gridRisco); - - } +// private void fillPlano() +// { +// String indent = "      "; +// Risco r = getNextRisco(plano.getId()); +// fillRisco(r); +// } +// +// private void fillRisco(Risco r) +// { +// String indent = "      "; +// if(gridLayout.getChildren().size() > 0) +// { +// gridLayout.getChildren().clear(); +// } +// gridRisco = new HtmlPanelGrid(); +// gridRisco.setWidth("100%"); +// gridRisco.setStyle("border: solid 1px #000000"); +// gridRisco.setColumns(1); +// gridRisco.setColumnClasses("gridColLeft"); +// +// pg = new PanelGroup(); +// st = new StaticText(); +// st.setEscape(false); +// st.setStyleClass("label"); +// st.setStyle("color: #2c4d7a"); +// st.setText("RISCO 1" + ": "); +// pg.getChildren().add(st); +// st = new StaticText(); +// st.setEscape(false); +// st.setText(r.getDescricao()); +// pg.getChildren().add(st); +// gridRisco.getChildren().add(pg); +// +// st = new StaticText(); +// st.setEscape(false); +// st.setText(" "); +// gridRisco.getChildren().add(st); +// +// pg = new PanelGroup(); +// st = new StaticText(); +// st.setEscape(false); +// st.setStyleClass("label"); +// st.setText("Valor:" + " "); +// pg.getChildren().add(st); +// st = new StaticText(); +// st.setEscape(false); +// st.setText(r.getValor().toString()); +// pg.getChildren().add(st); +// gridRisco.getChildren().add(pg); +// +// st = new StaticText(); +// st.setEscape(false); +// st.setText(" "); +// gridRisco.getChildren().add(st); +// +// //medidas +// Vector meds = getMedidas(r.getId()); +// for(int i = 0; i < meds.size(); i++) +// { +// Medida m = medidas.get(i); +// if(m.getRisco_id().intValue() == r.getId().intValue()) +// { +// pg = new PanelGroup(); +// st = new StaticText(); +// st.setEscape(false); +// st.setStyleClass("label"); +// st.setText(indent + "Medida" + ": "); +// pg.getChildren().add(st); +// st = new StaticText(); +// st.setEscape(false); +// st.setText(m.getDescricao()); +// pg.getChildren().add(st); +// gridRisco.getChildren().add(pg); +// +// //postos trabalho +// Vector posts = getPostosTrabalho(m.getId()); +// pg = new PanelGroup(); +// st = new StaticText(); +// st.setEscape(false); +// st.setStyleClass("label"); +// st.setText(indent + indent + "Postos de trabalho afectados" + ": "); +// pg.getChildren().add(st); +// st = new StaticText(); +// st.setEscape(false); +// String spostos = ""; +// for(int j = 0; j < posts.size(); j++) +// { +// PostoTrabalho p = posts.get(j); +// spostos += p.getDescricao(); // + " "; +// if(j < (posts.size() -1) ) +// { +// spostos += "; "; +// } +// } +// st.setText(spostos); +// pg.getChildren().add(st); +// gridRisco.getChildren().add(pg); +// } +// } +// +// st = new StaticText(); +// st.setEscape(false); +// st.setText(" "); +// gridRisco.getChildren().add(st); +// +// pg = new PanelGroup(); +// st = new StaticText(); +// st.setEscape(false); +// st.setStyleClass("label"); +// st.setText("Responsável de execução:"); +// pg.getChildren().add(st); +// txtResponsavelExecucao = new TextField(); +// txtResponsavelExecucao.setColumns(100); +// pg.getChildren().add(txtResponsavelExecucao); +// gridRisco.getChildren().add(pg); +// pg = new PanelGroup(); +// st = new StaticText(); +// st.setEscape(false); +// st.setStyleClass("label"); +// st.setText("Recursos necessários à implementação da medida:"); +// pg.getChildren().add(st); +// gridRisco.getChildren().add(pg); +// txtRecursos = new TextArea(); +// txtRecursos.setColumns(200); +// gridRisco.getChildren().add(txtRecursos); +// +// HtmlPanelGrid grd = new HtmlPanelGrid(); +// grd.setColumns(2); +// grd.setColumnClasses("gridCol15, gridCol85"); +// grd.setId("pgDtInicio"); +// grd.setStyle("width: 100%"); +// st = new StaticText(); +// st.setEscape(false); +// st.setStyleClass("label"); +// st.setText("Data prevista de início:"); +// grd.getChildren().add(st); +// dtInicio = new Calendar(); +// grd.getChildren().add(dtInicio); +// gridRisco.getChildren().add(grd); +// +// grd = new HtmlPanelGrid(); +// grd.setColumns(2); +// grd.setColumnClasses("gridCol15, gridCol85"); +// grd.setId("pgDtFim"); +// grd.setStyle("width: 100%"); +// st = new StaticText(); +// st.setEscape(false); +// st.setStyleClass("label"); +// st.setText("Data prevista de conclusão:"); +// grd.getChildren().add(st); +// dtFim = new Calendar(); +// +// grd.getChildren().add(dtFim); +// gridRisco.getChildren().add(grd); +// +// gridLayout.getChildren().add(gridRisco); +// +// } - private void initializePlano() - { - getSessionBean1().setRiscosIdx(0); - //plano - plano = new PlanoActuacao(); - plano.setId(new Integer(1)); - plano.setEstabelecimento_id(new Integer(1)); - plano.setFase(new Integer(1)); - getSessionBean1().setPlanoId(new Integer(1)); - plano.setDescricao("Plano 1"); - - //riscos - Risco r = new Risco(); - r.setId(new Integer(1)); - r.setPlano_id(new Integer(1)); - r.setDescricao("Risco A"); - r.setValor(new Integer(4)); - riscos.add(r); - - r = new Risco(); - r.setId(new Integer(2)); - r.setPlano_id(new Integer(1)); - r.setDescricao("Risco B"); - r.setValor(new Integer(6)); - riscos.add(r); - - r = new Risco(); - r.setId(new Integer(3)); - r.setPlano_id(new Integer(1)); - r.setDescricao("Risco C"); - r.setValor(new Integer(12)); - riscos.add(r); - - //medidas - Medida m = new Medida(); - m.setId(new Integer(1)); - m.setRisco_id(new Integer(1)); - m.setDescricao("Medida a"); - medidas.add(m); - - m = new Medida(); - m.setId(new Integer(2)); - m.setRisco_id(new Integer(1)); - m.setDescricao("Medida b"); - medidas.add(m); - - m = new Medida(); - m.setId(new Integer(3)); - m.setRisco_id(new Integer(2)); - m.setDescricao("Medida c"); - medidas.add(m); - - m = new Medida(); - m.setId(new Integer(4)); - m.setRisco_id(new Integer(2)); - m.setDescricao("Medida d"); - medidas.add(m); - - m = new Medida(); - m.setId(new Integer(5)); - m.setRisco_id(new Integer(2)); - m.setDescricao("Medida e"); - medidas.add(m); - - m = new Medida(); - m.setId(new Integer(6)); - m.setRisco_id(new Integer(3)); - m.setDescricao("Medida f"); - medidas.add(m); - - m = new Medida(); - m.setId(new Integer(7)); - m.setRisco_id(new Integer(3)); - m.setDescricao("Medida g"); - medidas.add(m); - - //postos trabalho - PostoTrabalho p = new PostoTrabalho(); - p.setId(new Integer(1)); - p.setMedida_id(new Integer(1)); - p.setDescricao("posto 1"); - postos.add(p); - - p = new PostoTrabalho(); - p.setId(new Integer(2)); - p.setMedida_id(new Integer(1)); - p.setDescricao("posto 2"); - postos.add(p); - - p = new PostoTrabalho(); - p.setId(new Integer(3)); - p.setMedida_id(new Integer(1)); - p.setDescricao("posto 3"); - postos.add(p); - - p = new PostoTrabalho(); - p.setId(new Integer(4)); - p.setMedida_id(new Integer(2)); - p.setDescricao("posto 4"); - postos.add(p); - - p = new PostoTrabalho(); - p.setId(new Integer(5)); - p.setMedida_id(new Integer(2)); - p.setDescricao("posto 5"); - postos.add(p); - - p = new PostoTrabalho(); - p.setId(new Integer(6)); - p.setMedida_id(new Integer(3)); - p.setDescricao("posto 6"); - postos.add(p); - - p = new PostoTrabalho(); - p.setId(new Integer(7)); - p.setMedida_id(new Integer(3)); - p.setDescricao("posto 7"); - postos.add(p); - - p = new PostoTrabalho(); - p.setId(new Integer(8)); - p.setMedida_id(new Integer(4)); - p.setDescricao("posto 8"); - postos.add(p); - - p = new PostoTrabalho(); - p.setId(new Integer(9)); - p.setMedida_id(new Integer(4)); - p.setDescricao("posto 9"); - postos.add(p); - - p = new PostoTrabalho(); - p.setId(new Integer(10)); - p.setMedida_id(new Integer(5)); - p.setDescricao("posto 10"); - postos.add(p); - - p = new PostoTrabalho(); - p.setId(new Integer(11)); - p.setMedida_id(new Integer(5)); - p.setDescricao("posto 11"); - postos.add(p); - - p = new PostoTrabalho(); - p.setId(new Integer(12)); - p.setMedida_id(new Integer(6)); - p.setDescricao("posto 12"); - postos.add(p); - - p = new PostoTrabalho(); - p.setId(new Integer(13)); - p.setMedida_id(new Integer(6)); - p.setDescricao("posto 13"); - postos.add(p); - - p = new PostoTrabalho(); - p.setId(new Integer(14)); - p.setMedida_id(new Integer(7)); - p.setDescricao("posto 14"); - postos.add(p); - - p = new PostoTrabalho(); - p.setId(new Integer(15)); - p.setMedida_id(new Integer(7)); - p.setDescricao("posto 15"); - postos.add(p); - getSessionBean1().setRiscos(riscos); - getSessionBean1().setMedidas(medidas); - getSessionBean1().setPostos(postos); - } + - private Risco getNextRisco(Integer planoId) - { - System.out.println("GET NEXT RISCO"); - System.out.println("RISCOS SIZE : " + riscos.size()); - riscos = getSessionBean1().getRiscos(); - risco_id = getSessionBean1().getRiscosIdx(); - Risco r = riscos.get(risco_id); - if(r != null) - { - if(r.getPlano_id().intValue() != planoId.intValue()) - { - r = null; - risco_id = 0; - } - } - risco_id++; - getSessionBean1().setRiscosIdx(risco_id); - return r; - } +// private Risco getNextRisco(Integer planoId) +// { +// System.out.println("GET NEXT RISCO"); +// System.out.println("RISCOS SIZE : " + riscos.size()); +// riscos = getSessionBean1().getRiscos(); +// risco_id = getSessionBean1().getRiscosIdx(); +// Risco r = riscos.get(risco_id); +// if(r != null) +// { +// if(r.getPlano_id().intValue() != planoId.intValue()) +// { +// r = null; +// risco_id = 0; +// } +// } +// risco_id++; +// getSessionBean1().setRiscosIdx(risco_id); +// return r; +// } - private Vector getMedidas(Integer riscoId) - { - Vector meds = new Vector(); - medidas = getSessionBean1().getMedidas(); - for(int i = 0; i < medidas.size(); i++) - { - Medida m = medidas.get(i); - if(m.getRisco_id().intValue() == riscoId.intValue()) - { - meds.add(m); - } - } - return meds; - } +// private Vector getMedidas(Integer riscoId) +// { +// Vector meds = new Vector(); +// medidas = getSessionBean1().getMedidas(); +// for(int i = 0; i < medidas.size(); i++) +// { +// Medida m = medidas.get(i); +// if(m.getRisco_id().intValue() == riscoId.intValue()) +// { +// meds.add(m); +// } +// } +// return meds; +// } private Vector getPostosTrabalho(Integer medidaId) { @@ -724,7 +571,7 @@ public class EditarPlano extends AbstractPageBean { return posts; } - private void initialize() + private void initialize(PlanoActuacao p) { Utilizador u = getSessionBean1().getCurrentUser(); if(u.getTipo().intValue() == Global.DIRECTOR_NACIONAL_SEGURANCA) @@ -761,7 +608,6 @@ public class EditarPlano extends AbstractPageBean { // } // } - PlanoActuacao p = getSessionBean1().getPlanoActuacao(); int fase = p.getFase().intValue(); switch(fase) @@ -794,14 +640,146 @@ public class EditarPlano extends AbstractPageBean { gridPlano.setColumns(1); gridPlano.setColumnClasses("gridColCenter"); //plano + lblTop.setText("Plano de actuação da auditoria " + p.getData_visita_str()); + gridLayout.getChildren().add(gridPlano); + } + + private void showPlano(PlanoActuacao p) + { + gridArea = new HtmlPanelGrid(); + gridArea.setColumns(1); + gridArea.setColumnClasses("gridColLeft"); + gridArea.setWidth("100%"); + gridArea.setStyle("border: solid 1px #000000"); + gridPlano.getChildren().add(gridArea); + + Area a = p.getAreas().get(0); + + pg = new PanelGroup(); + st = new StaticText(); + st.setEscape(false); + st.setText(a.getDescricao()); + pg.getChildren().add(st); + gridArea.getChildren().add(pg); + + HtmlPanelGrid grd = new HtmlPanelGrid(); + grd.setColumns(1); + grd.setWidth("100%"); + grd.setStyleClass("centerBlock"); + gridArea.getChildren().add(grd); + + //Risco + gridRisco = new HtmlPanelGrid(); + gridRisco.setStyleClass("centerBlock"); + gridRisco.setWidth("98%"); + gridRisco.setColumns(1); + gridRisco.setColumnClasses("gridColLeft"); + grd.getChildren().add(gridRisco); + + Risco r = a.getRiscos().get(0); + pg = new PanelGroup(); st = new StaticText(); st.setEscape(false); - st.setStyleClass("label"); - st.setStyle("font-size: 16px"); - st.setText(plano.getDescricao()); - gridPlano.getChildren().add(st); + st.setText(r.getDescricao()); + pg.getChildren().add(st); + gridRisco.getChildren().add(pg); + + showValores(r); - gridLayout.getChildren().add(gridPlano); + + gridMedida = new HtmlPanelGrid(); + gridMedida.setStyleClass("centerBlock"); + gridMedida.setWidth("98%"); + gridMedida.setColumns(1); + gridMedida.setColumnClasses("gridColLeft"); + grd.getChildren().add(gridMedida); + } + + private void showValores(Risco r) + { + List valores = r.getValores(); + + for(Valor v : valores) + { + HtmlPanelGrid grd = new HtmlPanelGrid(); + grd.setColumns(1); + grd.setWidth("100%"); + grd.setStyleClass("centerBlock"); + gridRisco.getChildren().add(grd); + + gridValor = new HtmlPanelGrid(); + gridValor.setStyleClass("centerBlock"); + gridValor.setWidth("98%"); + gridValor.setColumns(1); + gridValor.setColumnClasses("gridColLeft"); + grd.getChildren().add(gridValor); + pg = new PanelGroup(); + st = new StaticText(); + st.setEscape(false); + st.setText("Valor : " + v.getValor().toString()); + pg.getChildren().add(st); + gridValor.getChildren().add(pg); + + showMedidas(v); + } + } + + private void showMedidas(Valor v) + { + List medidas = v.getMedidas(); + + for(Medida m : medidas) + { + HtmlPanelGrid grd = new HtmlPanelGrid(); + grd.setColumns(1); + grd.setWidth("100%"); + grd.setStyleClass("centerBlock"); + gridValor.getChildren().add(grd); + + gridMedida = new HtmlPanelGrid(); + gridMedida.setStyleClass("centerBlock"); + gridMedida.setWidth("98%"); + gridMedida.setColumns(1); + gridMedida.setColumnClasses("gridColLeft"); + grd.getChildren().add(gridMedida); + pg = new PanelGroup(); + st = new StaticText(); + st.setEscape(false); + st.setText(m.getDescricao()); + pg.getChildren().add(st); + gridMedida.getChildren().add(pg); + + showPostos(m); + } + + } + + private void showPostos(Medida m) + { + List postos = m.getPostos(); + + for(PostoTrabalho p : postos) + { + HtmlPanelGrid grd = new HtmlPanelGrid(); + grd.setColumns(1); + grd.setWidth("100%"); + grd.setStyleClass("centerBlock"); + gridMedida.getChildren().add(grd); + + gridPosto = new HtmlPanelGrid(); + gridPosto.setStyleClass("centerBlock"); + gridPosto.setWidth("98%"); + gridPosto.setColumns(1); + gridPosto.setColumnClasses("gridColLeft"); + grd.getChildren().add(gridPosto); + pg = new PanelGroup(); + st = new StaticText(); + st.setEscape(false); + st.setText(p.getDescricao()); + pg.getChildren().add(st); + gridPosto.getChildren().add(pg); + + } } public String butGravarPlano_action() { @@ -814,8 +792,8 @@ public class EditarPlano extends AbstractPageBean { // TODO: Process the action. Return value is a navigation // case name where null will return to the same page. System.out.println("BUT NEXT RISCO"); - Risco r = getNextRisco(getSessionBean1().getPlanoId()); - fillRisco(r); + //Risco r = getNextRisco(getSessionBean1().getPlanoId()); + //fillRisco(r); return null; } diff --git a/trunk/PlanosActuacao/src/java/planosactuacao/ListaPlanos.java b/trunk/PlanosActuacao/src/java/planosactuacao/ListaPlanos.java index ad0377a7..5af89806 100644 --- a/trunk/PlanosActuacao/src/java/planosactuacao/ListaPlanos.java +++ b/trunk/PlanosActuacao/src/java/planosactuacao/ListaPlanos.java @@ -10,21 +10,22 @@ 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.entidades.Area; +import db.entidades.Medida; import db.entidades.PlanoActuacao; +import db.entidades.PostoTrabalho; +import db.entidades.Risco; import db.providers.UtilizadoresDataProvider; import db.entidades.Utilizador; +import db.entidades.Valor; import db.providers.PlanosDataProvider; import global.Global; import java.util.ArrayList; import java.util.Calendar; import java.util.Date; -import java.util.Iterator; import java.util.List; import javax.faces.FacesException; import javax.faces.context.FacesContext; -import siprp.database.cayenne.objects.HsRelatorio; -import siprp.database.cayenne.objects.HsRelatorioMedida; -import siprp.database.cayenne.objects.HsRelatorioRisco; import siprp.database.cayenne.providers.PlanoActuacaoDAO; import tabledataproviders.PlanosActualDataProvider; import utils.JSFUtils; @@ -233,7 +234,10 @@ public class ListaPlanos extends AbstractPageBean { // TODO: Process the action. Return value is a navigation // case name where null will return to the same page. PlanoActuacao p = getTableActivosRowData(); - getSessionBean1().setPlanoActuacao(p); + getSessionBean1().setPlanoActuacao(p); + + + showPlano(p); //dummy //getSessionBean1().setFase(2); return "editar_plano"; @@ -283,7 +287,7 @@ public class ListaPlanos extends AbstractPageBean { //// Integer id = es.getId(); // estabelecimento id ?? // } - PlanosActuacao planos = new PlanosActuacao(); + PlanosActuacao planos = new PlanosActuacao(u); List listPlanosActivos = planos.getPlanosActivos(u); getSessionBean1().getPlanosActualDataProvider().setList(listPlanosActivos); @@ -508,6 +512,62 @@ public class ListaPlanos extends AbstractPageBean { ArrayList list = (ArrayList) provider.getList(); PlanoActuacao p = (PlanoActuacao)list.get(k); return p; + } + + + + + + private void showPlano(PlanoActuacao p) + { + System.out.println("PLANO : " + p.getData_visita_str() + " | " + p.getFase_nome() + " | " + p.getNome_estabelecimento()); + System.out.println("================================================================="); + showAreas(p.getAreas()); + System.out.println("================================================================="); + } + + private void showAreas(List areas) + { + for(Area a : areas) + { + System.out.println(" " + a.getDescricao()); + showRiscos(a.getRiscos()); + } + } + + private void showRiscos(List riscos) + { + for(Risco r : riscos) + { + System.out.println(" " + r.getDescricao()); + showValores(r.getValores()); + } + } + + private void showValores(List valores) + { + for(Valor v : valores) + { + System.out.println(" " + v.getValor()); + showMedidas(v.getMedidas()); + } + } + + private void showMedidas(List medidas) + { + for(Medida m : medidas) + { + System.out.println(" " + m.getDescricao()); + showPostos(m.getPostos()); + } + } + + private void showPostos(List postos) + { + for(PostoTrabalho p : postos) + { + System.out.println(" " + p.getDescricao()); + } } } diff --git a/trunk/PlanosActuacao/src/java/planosactuacao/PlanosActuacao.java b/trunk/PlanosActuacao/src/java/planosactuacao/PlanosActuacao.java index d18001d9..33610258 100644 --- a/trunk/PlanosActuacao/src/java/planosactuacao/PlanosActuacao.java +++ b/trunk/PlanosActuacao/src/java/planosactuacao/PlanosActuacao.java @@ -5,9 +5,15 @@ package planosactuacao; +import db.entidades.Area; +import db.entidades.Medida; import db.entidades.PlanoActuacao; +import db.entidades.PostoTrabalho; +import db.entidades.Risco; import db.entidades.Utilizador; +import db.entidades.Valor; import db.providers.PlanosDataProvider; +import db.providers.RelatoriosDataProvider; import global.Global; import java.util.ArrayList; import java.util.Date; @@ -22,16 +28,29 @@ import siprp.database.cayenne.providers.PlanoActuacaoDAO; */ public class PlanosActuacao { PlanosDataProvider pdp = new PlanosDataProvider(); + RelatoriosDataProvider rdp; List planosList; List planosOnlineList; PlanoActuacaoDAO pa = new PlanoActuacaoDAO(); - public PlanosActuacao(){ - List planosOnlineList = getPlanosOnline(); - List listRelatorios = getRelatorios(planosOnlineList); - putPlanosOnline(listRelatorios); - + public PlanosActuacao(Utilizador u){ + try + { + rdp = new RelatoriosDataProvider(); + Integer estabelecimentoId = null; + if(u.getTipo().intValue() != Global.TECNICO_HS ) + { + estabelecimentoId = u.getEstabelecimento_id(); + } + List planosOnlineList = getPlanosOnline(); + List listRelatorios = getRelatorios(planosOnlineList, estabelecimentoId); + putPlanosOnline(listRelatorios); + } + catch(Exception ex) + { + ex.printStackTrace(); + } } private List getPlanosOnline() @@ -43,14 +62,14 @@ public class PlanosActuacao { } catch(Exception ex) { - + ex.printStackTrace(); } return list; } - private List getRelatorios(List list) + private List getRelatorios(List list, Integer estabelecimentoId) { - List listRelatorios = pa.getRelatoriosNotIn(list); + List listRelatorios = pa.getRelatoriosNotIn(list, estabelecimentoId); return listRelatorios; } @@ -62,22 +81,85 @@ public class PlanosActuacao { while(iter.hasNext()) { HsRelatorio relatorio = iter.next(); - PlanoActuacao p = new PlanoActuacao(); - p.setData_visita(relatorio.getToHsMarcacoesEstabelecimento().getData()); - p.setFase(new Integer(Global.FASE_SEGURANCA_PREENCHIMENTO)); - p.setEstabelecimento_id(relatorio.getToHsMarcacoesEstabelecimento().getToEstabelecimentos().getId()); - p.setNome_estabelecimento(relatorio.getToHsMarcacoesEstabelecimento().getToEstabelecimentos().getNome()); + try { - pdp.createPlano(p); + PlanoActuacao p = createPlano(relatorio); + + //showPlano(p); } catch(Exception ex) { ex.printStackTrace(); + System.out.println("ERRO NA CRIACAO DOS PLANOS : " + ex.getMessage()); } } } + private PlanoActuacao createPlano(HsRelatorio relatorio) throws Exception + { + PlanoActuacao p = new PlanoActuacao(); + p.setData_visita(relatorio.getToHsMarcacoesEstabelecimento().getData()); + p.setFase(new Integer(Global.FASE_SEGURANCA_PREENCHIMENTO)); + p.setEstabelecimento_id(relatorio.getToHsMarcacoesEstabelecimento().getToEstabelecimentos().getId()); + p.setNome_estabelecimento(relatorio.getToHsMarcacoesEstabelecimento().getToEstabelecimentos().getNome()); + p = rdp.getFullPlano(p, relatorio.getId()); + + p.setId(pdp.createPlano(p)); + createAreas(p.getId(), p.getAreas()); + + return p; + } + + private void createAreas(Integer plano_id, List areas) throws Exception + { + for(Area a : areas) + { + a.setPlano_id(plano_id); + a.setId(pdp.createArea(a)); + createRiscos(a.getId(), a.getRiscos()); + } + } + + private void createRiscos(Integer area_id, List riscos) throws Exception + { + for(Risco r : riscos) + { + r.setArea_id(area_id); + r.setId(pdp.createRisco(r)); + createValores(r.getId(), r.getValores()); + } + } + + private void createValores(Integer risco_id, List valores) throws Exception + { + for(Valor v : valores) + { + v.setRisco_id(risco_id); + v.setId(pdp.createValor(v)); + createMedidas(v.getId(), v.getMedidas()); + } + } + + private void createMedidas(Integer valor_id, List medidas) throws Exception + { + for(Medida m : medidas) + { + m.setValor_id(valor_id); + m.setId(pdp.createMedida(m)); + createPostos(m.getId(), m.getPostos()); + } + } + + private void createPostos(Integer medida_id, List postos) throws Exception + { + for(PostoTrabalho p : postos) + { + p.setMedida_id(medida_id); + pdp.createPostoTrabalho(p); + } + } + public List getPlanosActivos(Utilizador u) { ArrayList list = new ArrayList(); @@ -118,5 +200,59 @@ public class PlanosActuacao { } return list; - } + } + + + + private void showPlano(PlanoActuacao p) + { + System.out.println("================================================"); + System.out.println("PLANO : " + p.getData_visita_str() + " | " + p.getDescricao() + " | " + p.getFase_nome() + " | " + p.getNome_estabelecimento()); + showAreas(p.getAreas()); + System.out.println("================================================"); + } + + private void showAreas(List areas) + { + for(Area a : areas) + { + System.out.println(" " + a.getDescricao()); + showRiscos(a.getRiscos()); + } + } + + private void showRiscos(List riscos) + { + for(Risco r : riscos) + { + System.out.println(" " + r.getDescricao()); + showValores(r.getValores()); + } + } + + private void showValores(List valores) + { + for(Valor v : valores) + { + System.out.println(" " + v.getValor()); + showMedidas(v.getMedidas()); + } + } + + private void showMedidas(List medidas) + { + for(Medida m : medidas) + { + System.out.println(" " + m.getDescricao()); + showPostos(m.getPostos()); + } + } + + private void showPostos(List postos) + { + for(PostoTrabalho p : postos) + { + System.out.println(" " + p.getDescricao()); + } + } } diff --git a/trunk/PlanosActuacao/web/EditarPlano.jsp b/trunk/PlanosActuacao/web/EditarPlano.jsp index e87afe26..7d2051f0 100644 --- a/trunk/PlanosActuacao/web/EditarPlano.jsp +++ b/trunk/PlanosActuacao/web/EditarPlano.jsp @@ -102,7 +102,7 @@ - +