git-svn-id: https://svn.coded.pt/svn/SIPRP@1819 bb69d46d-e84e-40c8-a05a-06db0d633741

lxbfYeaa
Frederico Palma 12 years ago
parent 7b5b59b025
commit 510d2b5dfb

@ -0,0 +1,413 @@
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package db.providers;
import com.evolute.entity.ProviderInterface;
import com.evolute.entity.ProviderRegistry;
import com.evolute.entity.evo.EvoDataException;
import com.evolute.entity.evo.EvoDataObject;
import com.evolute.entity.evo.EvoDataProvider;
import com.evolute.entity.evo.EvoDataProviderFactory;
import com.evolute.entity.utils.ConnectionIdentity;
import com.evolute.utils.Singleton;
import com.evolute.utils.db.DBException;
import com.evolute.utils.db.DBManager;
import com.evolute.utils.db.Executer;
import com.evolute.utils.db.JDBCManager;
import com.evolute.utils.error.ErrorLogger;
import com.evolute.utils.jdbc.DBStatementExecuter;
import com.evolute.utils.jdbc.StatementExecuterFactory;
import com.evolute.utils.sql.SQLQuery;
import com.evolute.utils.sql.backend.BackendProvider;
import com.evolute.utils.strings.UnicodeChecker;
import db.DBConstants;
import db.DBPropertiesLoader;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import javax.faces.context.ExternalContext;
import javax.faces.context.FacesContext;
import javax.servlet.http.HttpSession;
/**
*
* @author dneves
*/
public class EvoBaseProvider
{
private static EvoBaseProvider INSTANCE = null;
private ProviderInterface< EvoDataObject< ? >, EvoDataException > providerInterface;
private DBManager dbManager;
private ProviderInterface< EvoDataObject< ? >, EvoDataException > localProviderInterface;
private DBManager localDBManager;
private String url;
private String username;
private String password;
private String url_local;
private String username_local;
private String password_local;
private EvoBaseProvider() throws DBException
{
init();
}
public static synchronized EvoBaseProvider getInstance() throws DBException
{
if ( INSTANCE == null )
{
INSTANCE = new EvoBaseProvider();
}
return INSTANCE;
}
private void init() throws DBException
{
// System.out.println( "EvoBaseProvider . init() : " );
String server = DBPropertiesLoader.getInstance().findProperty( DBConstants.SERVER_SIPRP );
int port = DBPropertiesLoader.getInstance().findProperty( DBConstants.PORT_SIPRP, -1 );
String dbname = DBPropertiesLoader.getInstance().findProperty( DBConstants.DATABASE_SIPRP );
username = DBPropertiesLoader.getInstance().findProperty( DBConstants.USERNAME_SIPRP );
password = DBPropertiesLoader.getInstance().findProperty( DBConstants.PASSWORD_SIPRP );
// System.out.println( "\t" + server + " : " + port + " : " + dbname + " : " + username + " : " + password );
String server_local = DBPropertiesLoader.getInstance().findProperty( DBConstants.SERVER_SIPRP_LOCAL );
int port_local = DBPropertiesLoader.getInstance().findProperty( DBConstants.PORT_SIPRP_LOCAL, -1 );
String dbname_local = DBPropertiesLoader.getInstance().findProperty( DBConstants.DATABASE_SIPRP_LOCAL );
username_local = DBPropertiesLoader.getInstance().findProperty( DBConstants.USERNAME_SIPRP_LOCAL );
password_local = DBPropertiesLoader.getInstance().findProperty( DBConstants.PASSWORD_SIPRP_LOCAL );
// System.out.println( "\t" + server_local + " : " + port_local + " : " + dbname_local + " : " + username_local + " : " + password_local );
init( DBConstants.DB.SIPRP, server, port, dbname, username, password );
init( DBConstants.DB.SIPRP_LOCAL, server_local, port_local, dbname_local, username_local, password_local );
}
private void init( DBConstants.DB db, String dbServer, Integer dbPort, String dbName, String dbUsername, String dbPassword )
throws DBException
{
String dbUrl = "jdbc:postgresql://" + dbServer + ":" + dbPort + "/" + dbName + "?prepareThreshold=2";
if ( DBConstants.DB.SIPRP.equals( db ) )
{
Singleton.setInstance( DBConstants.CONNECTION_URL, dbUrl );
url = dbUrl;
}
else if ( DBConstants.DB.SIPRP_LOCAL.equals( db ) )
{
Singleton.setInstance( DBConstants.LOCAL_CONNECTION_URL, dbUrl );
url_local = dbUrl;
}
createDBManager( db, dbUsername, dbPassword );
initProviderConnection( db, dbUsername, dbPassword );
}
private void createDBManager( DBConstants.DB db, String username, String password )
throws DBException
{
if ( DBConstants.DB.SIPRP.equals( db ) )
{
if( dbManager != null )
{
dbManager.close();
}
String dbUrl = ( String ) Singleton.getInstance( DBConstants.CONNECTION_URL );
DBManager manager = new JDBCManager( dbUrl, username, password , 14, 7, 7, new SQLQuery[] { } );
StatementExecuterFactory.initialize( new DBStatementExecuter( manager.getSharedExecuter( EvoBaseProvider.class ) ) );
UnicodeChecker.setUseDoubleSlash( true );
// Insert.setDefaultKeyRetriever( PostgresqlAutoKeyRetriever.RETRIEVER );
dbManager = manager;
// Singleton.setInstance( Singleton.DEFAULT_DBMANAGER, dbManager );
// System.out.println( "\nDBManager : " + dbManager );
}
else if ( DBConstants.DB.SIPRP_LOCAL.equals( db ) )
{
if( localDBManager != null )
{
localDBManager.close();
}
String dbUrl = ( String ) Singleton.getInstance( DBConstants.LOCAL_CONNECTION_URL );
DBManager manager = new JDBCManager( dbUrl, username, password , 14, 7, 7, new SQLQuery[] { } );
StatementExecuterFactory.initialize( new DBStatementExecuter( manager.getSharedExecuter( EvoBaseProvider.class ) ) );
UnicodeChecker.setUseDoubleSlash( true );
// Insert.setDefaultKeyRetriever( PostgresqlAutoKeyRetriever.RETRIEVER );
localDBManager = manager;
Singleton.setInstance( Singleton.DEFAULT_DBMANAGER, localDBManager );
// System.out.println( "\nLocalDBManager : " + localDBManager );
}
}
private void initProviderConnection( DBConstants.DB db, String username, String password )
{
if ( DBConstants.DB.SIPRP.equals( db ) )
{
String dbUrl = ( String ) Singleton.getInstance( DBConstants.CONNECTION_URL );
providerInterface = createInstance( db, dbUrl, username, password );
BackendProvider.getBackend( dbUrl ).setEscapeUnicode( false );
}
else if ( DBConstants.DB.SIPRP_LOCAL.equals( db ) )
{
String dbUrl = ( String ) Singleton.getInstance( DBConstants.LOCAL_CONNECTION_URL );
localProviderInterface = createInstance( db, dbUrl, username, password );
}
}
private static ProviderInterface< EvoDataObject< ? >, EvoDataException > createInstance( DBConstants.DB db, String url, String user, String password )
{
ProviderRegistry.registerDefaultProviderFactory( new EvoDataProviderFactory() );
ConnectionIdentity conn = new ConnectionIdentity( url, user );
ProviderRegistry.registerDefaultConnection( conn );
ProviderInterface< EvoDataObject< ? >, EvoDataException > provider =
( ProviderInterface< EvoDataObject< ? >, EvoDataException > ) ProviderRegistry.getDefaultProvider( conn );
( ( EvoDataProvider ) provider ).setIsUsingCache( Boolean.FALSE );
if ( DBConstants.DB.SIPRP.equals( db ) )
{
Singleton.setInstance( DBConstants.DEFAULT_PROVIDER, provider );
}
else if ( DBConstants.DB.SIPRP_LOCAL.equals( db ) )
{
Singleton.setInstance( DBConstants.LOCAL_PROVIDER, provider );
Singleton.setInstance( Singleton.DEFAULT_EVO_DATA_PROVIDER, provider );
Singleton.setInstance( Singleton.DEFAULT_OBJECT_PROVIDER, provider );
}
conn.setPassword( password );
return provider;
}
public ProviderInterface< EvoDataObject< ? >, EvoDataException > getProvider()
{
return getProvider( DBConstants.DB.SIPRP );
}
public ProviderInterface< EvoDataObject< ? >, EvoDataException > getProvider( DBConstants.DB db )
{
ProviderInterface< EvoDataObject< ? >, EvoDataException > provider = null;
if ( DBConstants.DB.SIPRP.equals( db ) )
{
provider = providerInterface;
}
else if ( DBConstants.DB.SIPRP_LOCAL.equals( db ) )
{
provider = localProviderInterface;
}
return provider;
}
public DBManager getDbManager()
{
return getDbManager( DBConstants.DB.SIPRP );
}
public DBManager getDbManager( DBConstants.DB db )
{
DBManager manager = null;
if ( DBConstants.DB.SIPRP.equals( db ) )
{
manager = dbManager;
}
else if ( DBConstants.DB.SIPRP_LOCAL.equals( db ) )
{
manager = localDBManager;
}
return manager;
}
public Executer getExecuter() throws DBException
{
return getExecuter( this );
}
private Executer getExecuter( Object clazz ) throws DBException
{
if ( getDbManager() == null )
{
init();
}
// DBManager dbm = ( DBManager ) Singleton.getInstance( DBConstants.DEFAULT_DBMANAGER );
// return dbm.getSharedExecuter( this );
DBManager dbm = getDbManager( DBConstants.DB.SIPRP );
if ( dbm != null )
{
return dbm.getSharedExecuter( this );
}
return null;
}
public Executer getLocalExecuter() throws DBException
{
return getLocalExecuter( this );
}
private Executer getLocalExecuter( Object clazz ) throws DBException
{
if ( getDbManager( DBConstants.DB.SIPRP_LOCAL ) == null )
{
init();
}
// DBManager dbm = ( DBManager ) Singleton.getInstance( DBConstants.LOCAL_DBMANAGER );
// return dbm.getSharedExecuter( this );
DBManager dbm = getDbManager( DBConstants.DB.SIPRP_LOCAL );
if ( dbm != null )
{
return dbm.getSharedExecuter( this );
}
return null;
}
@Deprecated
public Statement createStatement()
{
String connectionURL = ( String ) Singleton.getInstance( DBConstants.CONNECTION_URL );
String username = DBPropertiesLoader.getInstance().findProperty( DBConstants.USERNAME_SIPRP );
String password = DBPropertiesLoader.getInstance().findProperty( DBConstants.PASSWORD_SIPRP );
return getStatement( DBConstants.DB.SIPRP, connectionURL, username, password );
}
@Deprecated
public Statement createLocalStatement()
{
String connectionURL = ( String ) Singleton.getInstance( DBConstants.LOCAL_CONNECTION_URL );
String username = DBPropertiesLoader.getInstance().findProperty( DBConstants.USERNAME_SIPRP_LOCAL );
String password = DBPropertiesLoader.getInstance().findProperty( DBConstants.PASSWORD_SIPRP_LOCAL );
return getStatement( DBConstants.DB.SIPRP_LOCAL, connectionURL, username, password );
}
private Statement getStatement( DBConstants.DB db, String connectionURL, String username, String password )
{
Statement stm = null;
try
{
Connection connection = getConnection( db, connectionURL, username, password );
if ( connection != null )
{
stm = connection.createStatement( ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY );
}
}
catch ( Exception e )
{
ErrorLogger.logException( e );
}
return stm;
}
private Connection getConnection( DBConstants.DB db, String connectionURL, String username, String password ) throws Exception
{
Connection connection = null;
// System.out.println( "\nEvoBaseProvider . getConnection( " + connectionURL + ", " + username + " ) : " );
FacesContext fc = FacesContext.getCurrentInstance();
// System.out.println( "\tFacesContext : " + fc );
if ( fc != null )
{
ExternalContext ec = fc.getExternalContext();
// System.out.println( "\tExternalContext : " + ec );
if ( ec != null )
{
HttpSession session = ( HttpSession ) ec.getSession( false );
// System.out.println( "\tSession : " + session );
if ( session != null )
{
if ( DBConstants.DB.SIPRP.equals( db ) )
{
connection = ( Connection ) session.getAttribute( DBConstants.SESSION_CONNECTION );
if ( connection == null )
{
// System.out.println( "\n-> Creating new SIPRP connection ..." );
Class.forName( "org.postgresql.Driver" ).newInstance();
connection = DriverManager.getConnection( connectionURL, username, password );
session.setAttribute( DBConstants.SESSION_CONNECTION, connection );
}
}
else if ( DBConstants.DB.SIPRP_LOCAL.equals( db ) )
{
connection = ( Connection ) session.getAttribute( DBConstants.SESSION_CONNECTION_LOCAL );
if ( connection == null )
{
// System.out.println( "\n-> Creating new SIPRP_LOCAL connection ..." );
Class.forName( "org.postgresql.Driver" ).newInstance();
connection = DriverManager.getConnection( connectionURL, username, password );
session.setAttribute( DBConstants.SESSION_CONNECTION_LOCAL, connection );
}
}
}
}
}
if ( connection == null )
{
connection = ( Connection ) Singleton.getInstance( "CONNECTION_OBJECT" );
if ( connection == null )
{
// System.out.println( "\nEvoBaseProvider . getConnection() : session is null !" );
if ( DBConstants.DB.SIPRP.equals( db ) )
{
// System.out.println( "\t-> Creating new SIPRP connection ..." );
Class.forName( "org.postgresql.Driver" ).newInstance();
connection = DriverManager.getConnection( connectionURL, username, password );
}
else if ( DBConstants.DB.SIPRP_LOCAL.equals( db ) )
{
// System.out.println( "\t-> Creating new SIPRP_LOCAL connection ..." );
Class.forName( "org.postgresql.Driver" ).newInstance();
connection = DriverManager.getConnection( connectionURL, username, password );
}
Singleton.setInstance( "CONNECTION_OBJECT", connection );
}
}
// System.out.println( "<-- getConnection() : " + connection );
return connection;
}
public String getUrl()
{
return url;
}
public String getUsername()
{
return username;
}
public String getPassword()
{
return password;
}
public String getUrl_local()
{
return url_local;
}
public String getUsername_local()
{
return username_local;
}
public String getPassword_local()
{
return password_local;
}
}

@ -0,0 +1,122 @@
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package db.providers;
import com.evolute.entity.ProviderInterface;
import com.evolute.entity.evo.EvoDataException;
import com.evolute.entity.evo.EvoDataObject;
import com.evolute.utils.db.DBException;
import com.evolute.utils.db.Executer;
import com.evolute.utils.error.ErrorLogger;
import db.DBConstants;
import java.sql.ResultSet;
import java.sql.Statement;
public abstract class GenericDataProvider
{
private ProviderInterface< EvoDataObject< ? >, EvoDataException > provider = null;
private Executer executer = null;
private ProviderInterface< EvoDataObject< ? >, EvoDataException > localProvider = null;
private Executer localExecuter = null;
protected GenericDataProvider() throws Exception
{
provider = EvoBaseProvider.getInstance().getProvider( DBConstants.DB.SIPRP );
executer = EvoBaseProvider.getInstance().getExecuter();
localProvider = EvoBaseProvider.getInstance().getProvider( DBConstants.DB.SIPRP_LOCAL );
localExecuter = EvoBaseProvider.getInstance().getLocalExecuter();
}
public Executer getExecuter()
{
return executer;
}
public Executer getLocalExecuter()
{
return localExecuter;
}
public ProviderInterface< EvoDataObject< ? >, EvoDataException > getProvider()
{
return provider;
}
public ProviderInterface< EvoDataObject< ? >, EvoDataException > getLocalProvider()
{
return localProvider;
}
// public void checkConnection()
// {
// Db db = Db.getInstance();
// if ( db.getConnection() == null )
// {
// try
// {
// db.connect();
// }
// catch ( Exception ex )
// {
// ErrorLogger.logException( ex );
// }
// }
// }
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);
}
}
protected Statement createStatement()
{
try
{
// Db db = Db.getInstance();
// return db.createStatement();
return EvoBaseProvider.getInstance().createStatement();
}
catch ( DBException ex )
{
ErrorLogger.logException( ex );
}
return null;
}
protected Statement createLocalStatement()
{
try
{
return EvoBaseProvider.getInstance().createLocalStatement();
}
catch ( DBException ex )
{
ErrorLogger.logException( ex );
}
return null;
}
}

@ -0,0 +1,488 @@
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package db.providers;
import com.evolute.utils.error.ErrorLogger;
import db.data.siprp_local.outer.EmpresasData;
import db.data.siprp_local.outer.ImageData;
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.LinkedList;
import java.util.List;
import utils.Utils;
/**
*
* @author lluis
*/
public class RelatoriosDataProvider extends GenericDataProvider
{
// private DbLocal dblocal = DbLocal.getInstance();
private static RelatoriosDataProvider INSTANCE = null;
private RelatoriosDataProvider() throws Exception
{
super();
// dblocal.connect();
}
public static synchronized RelatoriosDataProvider getInstance() throws Exception
{
if ( INSTANCE == null )
{
INSTANCE = new RelatoriosDataProvider();
}
return INSTANCE;
}
public PlanoActuacao getFullPlano(PlanoActuacao plano, Integer relatorioId)
{
try
{
plano = getAreasByPlano(plano, relatorioId);
}
catch(Exception ex)
{
ErrorLogger.logException( ex );
}
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 LinkedList< Area >();
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 !!!!");
ErrorLogger.logException( ex );
a.setRiscos(null);
}
areas.add(a);
}
}while(rs.next());
plano.setAreas(areas);
}
return plano;
}
private List<Risco> getRiscosByArea(Area a) throws Exception
{
// Statement st = dblocal.createStatement();
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 LinkedList< Risco >();
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.setValorQuantitativo(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 = dblocal.createStatement();
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 LinkedList< Valor >();
Integer valor = null;
if(rs.isBeforeFirst())
{
rs.first();
do
{
Valor v = new Valor();
Object oValor = rs.getObject("valor");
if(oValor == null)
{
v.setValorQuantitativo(null);
//r.setValorQuantitativo(null);
valor = null;
}
else
{
v.setValorQuantitativo((Integer) oValor);
//r.setValorQuantitativo((Integer) oValor);
valor = (Integer) oValor;
}
// System.out.println("RISCO : " + r.getId().toString() + "VALOR : " + oValor.toString());
//int valor = rs.getInt("valor");
//v.setValorQuantitativo(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.getValorQuantitativo() + " ";
// 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.setValorQuantitativo(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 = dblocal.createStatement();
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.getValorQuantitativo() + " ";
sql += "order by subquery.medida_id, valor";
System.out.println("MEDIDAS BY RISCO SQL : " + sql);
ResultSet rs = st.executeQuery(sql);
List< Medida > medidas = new LinkedList< Medida >();
if ( rs.isBeforeFirst() )
{
rs.first();
do
{
Medida m = new Medida();
//int valor = rs.getInt("valor");
//m.setValorQuantitativo(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.getValorQuantitativo();
// 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 = dblocal.createStatement();
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.getValorQuantitativo();
System.out.println("POSTOS BY MEDIDA SQL : " + sql);
ResultSet rs = st.executeQuery(sql);
List< PostoTrabalho > postos = new LinkedList< PostoTrabalho >();
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 = dblocal.createStatement();
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 = dblocal.createStatement();
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 String getEmpresaNome(Integer empresa_id) throws Exception
{
String nome = "";
EmpresasData empresaData = getLocalProvider().load( EmpresasData.class, empresa_id, EmpresasData.ID );
if ( empresaData != null )
{
nome = Utils.unicodeToHTML( empresaData.getDesignacao_social() );
}
return nome;
// 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;
}
public byte[] getLogoByEmpresa( Integer empresaId )
throws Exception
{
byte[] logo = null;
EmpresasData empresaData = getLocalProvider().load( EmpresasData.class, empresaId, EmpresasData.ID );
if ( empresaData != null )
{
Integer logoID = empresaData.getEmpresa_logo_id();
logo = getLogo( logoID );
}
return logo;
// Statement st = createLocalStatement();
//
// String sql = "select empresa_logo_id from empresas where id = " + empresaId;
// ResultSet rslocal = st.executeQuery(sql);
// if ( rslocal.isBeforeFirst() )
// {
// rslocal.first();
// Integer logoId = new Integer( rslocal.getInt("empresa_logo_id") );
// byte[] logo = getLogo( logoId );
// return logo;
// }
//
// return null;
}
public byte[] getLogo( Integer logoID ) throws Exception
{
byte[] logo = null;
ImageData imageData = getLocalProvider().load( ImageData.class, logoID, ImageData.ID );
if ( imageData != null )
{
logo = imageData.getImage_data();
}
System.out.println( "\nRelatoriosDataProvider . getLogo( " + logoID + " ) : " + ( logo == null ? "null" : "size = " + logo.length ) );
return logo;
}
// public byte[] getLogo(Integer logoId) throws Exception
// {
// Statement st = createLocalStatement();
//
// String sql = "select image_data from image where id = " + logoId;
// ResultSet rslocal = st.executeQuery(sql);
// rslocal.first();
// byte[] logo = rslocal.getBytes("image_data");
// System.out.println("LOGO SIZE : " + logo.length);
// return logo;
// }
}

@ -0,0 +1,171 @@
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package db.providers;
import com.evolute.utils.error.ErrorLogger;
import db.data.siprp.outer.PlanoValoresQualitativosData;
import db.entidades.Medida;
import db.entidades.Risco;
import db.entidades.Utilizador;
import utils.Global;
import java.util.Date;
import java.util.List;
/**
*
* @author dneves
*/
public class RiscoLogic
{
private static RiscoLogic INSTANCE = null;
private RiscoLogic()
{
}
public static synchronized RiscoLogic getInstance()
{
if ( INSTANCE == null )
{
INSTANCE = new RiscoLogic();
}
return INSTANCE;
}
private boolean hasValue( Object obj )
{
boolean result = false;
if ( obj != null )
{
if ( obj instanceof String )
{
result = ! "".equals( ( ( String ) obj ).trim() );
}
else if ( obj instanceof Date )
{
result = true;
}
}
return result;
}
private boolean isRiscoTratado( Risco r )
{
boolean result = false;
String responsavelExecucao = r.getResponsavel_execucao();
String por = r.getPor();
String recursosNecessarios = r.getRecursos_necessarios();
Date dataInicio = r.getData_inicio();
Date dataFim = r.getData_fim();
result = hasValue( responsavelExecucao ) && hasValue( por ) && hasValue( recursosNecessarios )
&& hasValue( dataInicio ) && hasValue( dataFim );
return result;
}
public boolean isRiscoTratado( Risco risco, Utilizador user, boolean forceCheck )
{
boolean isTratado = false;
if ( risco != null && user == null )
{
isTratado = isRiscoTratado( risco );
}
else if ( risco != null && user != null )
{
int userType = user.getTipo() == null ? -1 : user.getTipo().intValue();
switch ( userType )
{
case Global.RESPONSAVEL_SEGURANCA :
{
String resp = risco.getResponsavel_execucao();
String por = risco.getPor();
String rec = risco.getRecursos_necessarios();
Date dataInicio = risco.getData_inicio();
Date dataFim = risco.getData_fim();
isTratado = hasValue( resp ) && hasValue( por ) && hasValue( rec ) && hasValue( dataInicio ) && hasValue( dataFim );
break;
}
case Global.DIRECTOR_LOJA :
{
String parecer = risco.getParecer_dl();
isTratado = forceCheck ? hasValue( parecer ) : true;
break;
}
case Global.DIRECTOR_NACIONAL_SEGURANCA :
{
String parecer = risco.getParecer_dns();
isTratado = forceCheck ? hasValue( parecer ) : true;
break;
}
case Global.TECNICO_HS :
{
isTratado = true;
if ( forceCheck )
{
String verify = risco.getVerificacao_siprp();
isTratado = hasValue( verify );
List< Medida > medidas = risco.getMedidas();
for ( int i = 0; i < medidas.size() && isTratado; i++ )
{
Medida m = medidas.get( i );
Integer estadoMedida = m.getValidarMedidaId();
isTratado &= estadoMedida != null;
}
}
break;
}
}
}
return isTratado;
}
public String getValor( Risco r )
{
String result = null;
if ( r.getValorQuantitativo() != null )
{
result = r.getValorQuantitativo().toString();
}
else if ( r.getValorQualitativoID() != null )
{
result = getValorQualitativoByID( r.getValorQualitativoID() );
}
return result == null ? Global.VALOR_INDETERMINADO : result;
}
private String getValorQualitativoByID( Integer id )
{
String result = null;
try
{
PlanoValoresQualitativosData valor = PlanosDataProvider.getInstance().loadValorQualitativoByID( id );
if ( valor != null )
{
result = valor.getDescricao();
}
}
catch ( Exception e )
{
ErrorLogger.logException( e );
}
return result;
}
}

@ -0,0 +1,262 @@
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package db.providers;
import com.evolute.utils.arrays.Virtual2DArray;
import com.evolute.utils.sql.Expression;
import com.evolute.utils.sql.Field;
import com.evolute.utils.sql.Select2;
import db.data.siprp.outer.UtilizadoresData;
import db.entidades.Utilizador;
import utils.Global;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.LinkedList;
import java.util.List;
/**
*
* @author lluis
*/
public class UtilizadoresDataProvider extends GenericDataProvider
{
private static UtilizadoresDataProvider INSTANCE = null;
private UtilizadoresDataProvider() throws Exception
{
super();
}
public static synchronized UtilizadoresDataProvider getInstance() throws Exception
{
if ( INSTANCE == null )
{
INSTANCE = new UtilizadoresDataProvider();
}
return INSTANCE;
}
public Utilizador getUtilizador( String login ) throws Exception
{
Utilizador user = null;
Select2 query = new Select2(
new String[] { "utilizadores" },
new Integer[] {},
new Expression[] {},
new String[] { "utilizadores.id" },
new Field( "utilizadores.apagado" ).isEqual( "n" ).and(
new Field( "LOWER( utilizadores.login )" ).isEqual( login.toLowerCase() )
),
new String[] {},
null, null, null
);
Virtual2DArray result = getExecuter().executeQuery( query );
if ( result != null && result.columnLength() > 0 )
{
Integer userID = result.get( 0, 0 );
user = getUtilizador( userID );
}
return user;
}
public Utilizador getUtilizador( Integer userID ) throws Exception
{
Utilizador user = null;
UtilizadoresData userData = getProvider().load( UtilizadoresData.class, userID );
user = copyFrom( userData );
return user;
}
private Utilizador copyFrom( UtilizadoresData userData )
{
Utilizador user = null;
if ( userData != null )
{
user = new Utilizador();
user.setId( userData.getId() );
user.setLogin( userData.getLogin() );
user.setPassword( userData.getPassword() );
user.setData_password( userData.getData_password() );
user.setEmail( userData.getEmail() );
user.setEmpresa_id( userData.getEmpresa_id() );
user.setEstabelecimento_id( userData.getEstabelecimento_id() );
user.setAdministrador( userData.getAdministrador() );
user.setTipo( userData.getTipo() );
user.setNumero_cedula( userData.getNumero_cedula() );
user.setCap( userData.getCap() );
user.setNome( userData.getNome() );
user.setMedico_id( userData.getMedico_id() );
user.setFuncionario_hst_id( userData.getFuncionario_hst_id() );
user.setActivo( userData.getActivo() );
user.setResponsavel_loja( userData.getResponsavel_loja() );
user.setGestor_geral( userData.getGestor_geral() );
user.setApagado( userData.getApagado() );
}
return user;
}
// public Utilizador getUtilizador( Integer id ) throws Exception
// {
// Utilizador u = null;
// Statement st = createStatement();
// String sql = "SELECT * FROM utilizadores WHERE id = " + id;
// ResultSet rs = st.executeQuery( sql );
// if ( rs.first() )
// {
// u = new Utilizador();
// u.setId(new Integer(rs.getInt("id")));
// u.setLogin(rs.getString("login"));
// u.setPassword(rs.getString("password"));
// u.setData_password(rs.getDate("data_password"));
// u.setEmail(rs.getString("email"));
// u.setEmpresa_id(new Integer(rs.getInt("empresa_id")));
// u.setEstabelecimento_id(new Integer(rs.getInt("estabelecimento_id")));
// u.setAdministrador(rs.getString("administrador"));
// u.setTipo(new Integer(rs.getInt("tipo")));
// u.setNumero_cedula(rs.getString("numero_cedula"));
// u.setCap(rs.getString("cap"));
// u.setNome(rs.getString("nome"));
// u.setMedico_id(new Integer(rs.getInt("medico_id")));
// u.setFuncionario_hst_id(new Integer(rs.getInt("funcionario_hst_id")));
// u.setActivo(rs.getString("activo"));
// u.setResponsavel_loja(rs.getString("responsavel_loja"));
// u.setGestor_geral(rs.getString("gestor_geral"));
// u.setApagado(rs.getString("apagado"));
// }
// return u;
// }
public List< Utilizador > getUtilizadoresListByTipo( Integer tipo, String responsavel_loja, Integer estabelecimento_id )
throws Exception
{
List< Utilizador > list = new LinkedList< Utilizador >();
int type = tipo.intValue();
Expression where = new Field( UtilizadoresData.ACTIVO_FULL ).isEqual( "y" );
where = where.and( new Field( UtilizadoresData.APAGADO_FULL ).isEqual( "n" ) );
where = where.and( new Field( UtilizadoresData.TIPO_FULL ).isEqual( type ) );
if ( type == Global.RESPONSAVEL_SEGURANCA || type == Global.DIRECTOR_LOJA )
{
where = where.and( new Field( UtilizadoresData.ESTABELECIMENTO_ID_FULL ).isEqual( estabelecimento_id ) );
}
if ( type == Global.RESPONSAVEL_SEGURANCA && "y".equals( responsavel_loja ) )
{
where = where.and( new Field( UtilizadoresData.RESPONSAVEL_LOJA_FULL ).isEqual( "y" ) );
}
if ( type == Global.DIRECTOR_LOJA || type == Global.TECNICO_HS || type == Global.DIRECTOR_NACIONAL_SEGURANCA
|| ( type == Global.RESPONSAVEL_SEGURANCA && "y".equals( responsavel_loja ) ) )
{
System.out.println( "\nUtilizadoresDataProvider . getUtilizadoresListByTipo( " + tipo + ", " + responsavel_loja + ", " + estabelecimento_id + " ) : " );
System.out.println( "\tSQL : SELECT * FROM utilizadores WHERE " + where.toString() );
List< UtilizadoresData > listData = getProvider().listLoad(
UtilizadoresData.class, where, new String[] { UtilizadoresData.NOME }, null );
for ( UtilizadoresData userData : listData )
{
list.add( copyFrom( userData ) );
}
}
// String sql = "";
// String estabelecimento_constraint = "";
// if ( type == Global.DIRECTOR_LOJA || type == Global.RESPONSAVEL_SEGURANCA || type == Global.DIRECTOR_NACIONAL_SEGURANCA )
// {
// estabelecimento_constraint = " AND estabelecimento_id = " + estabelecimento_id;
// }
// if ( type == Global.RESPONSAVEL_SEGURANCA && responsavel_loja.matches( "y" ) )
// {
// sql = "SELECT * FROM utilizadores WHERE activo = 'y' AND apagado = 'n' AND tipo = " + tipo + estabelecimento_constraint + " AND responsavel_loja = 'y'";
// }
// else if ( type == Global.DIRECTOR_LOJA || type == Global.TECNICO_HS || type == Global.DIRECTOR_NACIONAL_SEGURANCA )
// {
// sql = "SELECT * FROM utilizadores WHERE activo = 'y' AND apagado = 'n' AND tipo = " + tipo + estabelecimento_constraint;
// }
//
// System.out.println( "UTILIZADORES LIST BY TIPO SQL : " + sql );
// Statement st = createStatement();
// ResultSet rs = st.executeQuery( sql );
// if ( rs.isBeforeFirst() )
// {
// rs.first();
// do
// {
// Utilizador u = new Utilizador();
// u.setId( new Integer( rs.getInt( "id" ) ) );
// u.setLogin( rs.getString( "login" ) );
// u.setPassword( rs.getString( "password" ) );
// u.setData_password( rs.getDate( "data_password" ) );
// u.setEmail( rs.getString( "email" ) );
// u.setEmpresa_id( new Integer( rs.getInt( "empresa_id" ) ) );
// u.setEstabelecimento_id( new Integer( rs.getInt( "estabelecimento_id" ) ) );
// u.setAdministrador( rs.getString( "administrador" ) );
// u.setTipo( new Integer( rs.getInt( "tipo" ) ) );
// u.setNumero_cedula( rs.getString( "numero_cedula" ) );
// u.setCap( rs.getString( "cap" ) );
// u.setNome( rs.getString( "nome" ) );
// u.setMedico_id( new Integer( rs.getInt( "medico_id" ) ) );
// u.setFuncionario_hst_id( new Integer( rs.getInt( "funcionario_hst_id" ) ) );
// u.setActivo( rs.getString( "activo" ) );
// u.setResponsavel_loja( rs.getString( "responsavel_loja" ) );
// list.add( u );
// }
// while ( rs.next() );
// }
return list;
}
public List< Utilizador > getUtilizadoresList() throws Exception
{
List< Utilizador > list = new LinkedList< Utilizador >();
Expression where = new Field( UtilizadoresData.ACTIVO_FULL ).isEqual( "y" ).and(
new Field( UtilizadoresData.APAGADO_FULL ).isEqual( "n" ) );
List< UtilizadoresData > listData = getProvider().listLoad( UtilizadoresData.class, where, new String[] { UtilizadoresData.NOME }, null );
for ( UtilizadoresData userData : listData )
{
list.add( copyFrom( userData ) );
}
return list;
}
// public ArrayList getUtilizadoresList() throws Exception
// {
// ArrayList list = new ArrayList();
// Statement st = createStatement();
// String sql = "select * from utilizadores where activo = 'y' and apagado = 'n'";
//
// ResultSet rs = st.executeQuery(sql);
// rs.first();
// do
// {
// Utilizador u = new Utilizador();
// u.setId(new Integer(rs.getInt("id")));
// u.setLogin(rs.getString("login"));
// u.setPassword(rs.getString("password"));
// u.setData_password(rs.getDate("data_password"));
// u.setEmail(rs.getString("email"));
// u.setEmpresa_id(new Integer(rs.getInt("empresa_id")));
// u.setEstabelecimento_id(new Integer(rs.getInt("estabelecimento_id")));
// u.setAdministrador(rs.getString("administrador"));
// u.setTipo(new Integer(rs.getInt("tipo")));
// u.setNumero_cedula(rs.getString("numero_cedula"));
// u.setCap(rs.getString("cap"));
// u.setNome(rs.getString("nome"));
// u.setMedico_id(new Integer(rs.getInt("medico_id")));
// u.setFuncionario_hst_id(new Integer(rs.getInt("funcionario_hst_id")));
// u.setActivo(rs.getString("activo"));
// u.setResponsavel_loja(rs.getString("responsavel_loja"));
// list.add(u);
// }while(rs.next());
// return list;
// }
}

@ -0,0 +1,47 @@
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package db.providers;
import com.evolute.utils.error.ErrorLogger;
import db.entidades.Utilizador;
/**
*
* @author dneves
*/
public class UtilizadoresLogic
{
private static UtilizadoresLogic INSTANCE = null;
private UtilizadoresLogic()
{
}
public static synchronized UtilizadoresLogic getInstance()
{
if ( INSTANCE == null )
{
INSTANCE = new UtilizadoresLogic();
}
return INSTANCE;
}
public String getNomeUtilizadorByID( Integer userID )
{
String nome = "";
try
{
Utilizador userValidacao = UtilizadoresDataProvider.getInstance().getUtilizador( userID );
nome = userValidacao == null ? "" : userValidacao.getNome();
}
catch ( Exception e )
{
ErrorLogger.logException( e );
}
return nome;
}
}
Loading…
Cancel
Save