forked from Coded/SIPRP
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
263 lines
9.6 KiB
263 lines
9.6 KiB
/*
|
|
* 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 global.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;
|
|
// }
|
|
}
|