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

lxbfYeaa
Diogo Neves 15 years ago
parent a052e0bda6
commit bc72f0f7c9

@ -41,13 +41,15 @@ java.lang.String
java.sql.SQLException
java.lang.StringBuilder
java.sql.DriverManager
java.util.LinkedList
javax.servlet.http.HttpServletResponse
com.evolute.utils.arrays.ResultSet2DArray
java.lang.Class
java.util.List
java.util.Map
java.sql.Statement
java.lang.IllegalStateException
java.io.IOException
java.util.Vector
javax.servlet.ServletOutputStream
java.lang.StringBuffer
javax.servlet.http.HttpServletRequest
@ -68,6 +70,7 @@ javax.servlet.http.HttpServletResponse
com.evolute.utils.arrays.ResultSet2DArray
java.lang.Class
java.io.PrintStream
java.util.Map
java.sql.Statement
java.lang.IllegalStateException
java.io.IOException
@ -148,23 +151,6 @@ java.util.Properties
||:com.evolute.siprp.pagina.GlobalConstants
java.lang.Object
com.evolute.siprp.pagina.GlobalConstants
||:com.evolute.siprp.pagina.ScheduleServlet
javax.servlet.http.HttpSession
java.lang.StringBuilder
org.apache.velocity.app.Velocity
javax.servlet.http.HttpServletRequest
javax.servlet.ServletOutputStream
com.evolute.siprp.pagina.ScheduleServlet
java.util.Hashtable
java.io.StringWriter
[Ljava.lang.String;
java.io.IOException
java.util.Enumeration
org.apache.velocity.VelocityContext
java.lang.String
com.evolute.siprp.pagina.MailerServlet
java.lang.Exception
javax.servlet.http.HttpServletResponse
||:com.evolute.siprp.pagina.RecruitServlet
org.apache.commons.fileupload.FileItem
java.lang.StringBuilder
@ -184,6 +170,23 @@ org.apache.commons.fileupload.FileUploadException
org.apache.commons.fileupload.FileUpload
org.apache.commons.fileupload.DiskFileUpload
java.lang.String
||:com.evolute.siprp.pagina.ScheduleServlet
javax.servlet.http.HttpSession
java.lang.StringBuilder
org.apache.velocity.app.Velocity
javax.servlet.http.HttpServletRequest
javax.servlet.ServletOutputStream
com.evolute.siprp.pagina.ScheduleServlet
java.util.Hashtable
java.io.StringWriter
[Ljava.lang.String;
java.io.IOException
java.util.Enumeration
org.apache.velocity.VelocityContext
java.lang.String
com.evolute.siprp.pagina.MailerServlet
java.lang.Exception
javax.servlet.http.HttpServletResponse
||:com.evolute.siprp.pagina.doGetTrabalhador
java.sql.SQLException
java.lang.StringBuilder
@ -194,9 +197,9 @@ com.evolute.utils.arrays.ResultSet2DArray
java.lang.Class
com.evolute.siprp.pagina.doGetTrabalhador
java.util.Date
java.util.Map
java.sql.Statement
java.io.IOException
java.util.Vector
javax.servlet.ServletOutputStream
java.lang.StringBuffer
javax.servlet.http.HttpServletRequest
@ -221,12 +224,14 @@ java.sql.SQLException
java.lang.StringBuilder
com.evolute.siprp.pagina.doGetListaEstabelecimentos
java.sql.DriverManager
java.util.LinkedList
javax.servlet.http.HttpServletResponse
com.evolute.utils.arrays.ResultSet2DArray
java.lang.Class
java.util.List
java.util.Map
java.sql.Statement
java.io.IOException
java.util.Vector
javax.servlet.ServletOutputStream
java.lang.StringBuffer
javax.servlet.http.HttpServletRequest
@ -242,15 +247,17 @@ java.lang.StringBuilder
java.lang.System
java.sql.DriverManager
java.io.Serializable
java.util.LinkedList
javax.servlet.http.HttpServletResponse
com.evolute.utils.arrays.ResultSet2DArray
java.lang.Class
java.util.List
java.util.Date
java.io.PrintStream
com.evolute.siprp.pagina.doGetListaTrabalhadoresPendentes
java.util.Map
java.sql.Statement
com.evolute.siprp.pagina.doGetListaTrabalhadoresTudo
java.util.Vector
javax.servlet.ServletOutputStream
java.lang.StringBuffer
javax.servlet.http.HttpServletRequest
@ -305,16 +312,18 @@ javax.servlet.http.HttpServletResponse
com.evolute.utils.strings.StringConverter
com.evolute.utils.arrays.Virtual2DArray
com.evolute.utils.sql.Field
java.util.Hashtable
java.util.Map
javax.servlet.ServletContext
java.io.IOException
java.util.Iterator
javax.servlet.ServletOutputStream
com.evolute.siprp.pagina.GlobalConstants
java.util.Properties
javax.servlet.http.HttpServletRequest
com.evolute.utils.db.JDBCManager
java.util.HashMap
org.apache.velocity.app.Velocity
javax.servlet.http.HttpServlet
java.util.Enumeration
java.lang.Exception
com.evolute.utils.sql.SQLQuery
java.lang.Object
@ -322,3 +331,4 @@ java.io.StringWriter
java.lang.String
com.evolute.siprp.pagina.NewsServlet
com.evolute.utils.db.DBManager
java.util.Set

@ -6,7 +6,6 @@
package com.evolute.siprp.pagina;
import java.util.Map;
/**
*

@ -6,32 +6,42 @@
package com.evolute.siprp.pagina;
import java.io.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.sql.*;
import org.apache.velocity.*;
import org.apache.velocity.app.*;
import com.evolute.utils.*;
import com.evolute.utils.arrays.*;
import com.evolute.utils.db.*;
import com.evolute.utils.sql.*;
import com.evolute.utils.strings.*;
import java.io.IOException;
import java.io.StringWriter;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Properties;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.velocity.VelocityContext;
import org.apache.velocity.app.Velocity;
import com.evolute.utils.arrays.Virtual2DArray;
import com.evolute.utils.db.DBManager;
import com.evolute.utils.db.JDBCManager;
import com.evolute.utils.db.SQLExecuter;
import com.evolute.utils.sql.Field;
import com.evolute.utils.sql.SQLQuery;
import com.evolute.utils.sql.Select;
import com.evolute.utils.strings.StringConverter;
/**
*
* @author lflores
*/
public class NewsServlet extends HttpServlet
implements GlobalConstants
public class NewsServlet extends HttpServlet implements GlobalConstants
{
private static final long serialVersionUID = 1L;
private static DBManager DBM = null;
private static final Select SELECT = new Select( new String[]{ "not_noticias" },
new String[]{"data", "noticia"}, new Field( "id" ).in(
new Field( "( SELECT MAX( id ) FROM not_noticias )" ) ) );
private static final Select SELECT = new Select( new String[] { "not_noticias" }, new String[] { "data", "noticia" }, new Field( "id" ).in( new Field(
"( SELECT MAX( id ) FROM not_noticias )" ) ) );
private SQLExecuter executer = null;
@ -39,7 +49,7 @@ public class NewsServlet extends HttpServlet
public void init()
{
if( !velocityInit )
if ( !velocityInit )
{
try
{
@ -49,24 +59,23 @@ public class NewsServlet extends HttpServlet
props.setProperty( "file.resource.loader.path", TEMPLATE_DIR );
Velocity.init( props );
}
catch( Exception ex )
catch ( Exception ex )
{
ex.printStackTrace();
}
velocityInit = true;
}
if( DBM != null )
if ( DBM != null )
{
return;
}
try
{
DBM = new JDBCManager( bdUrl + "?prepareThreshold=1",
bdUsername, bdPassword , 8, 8, 0, new SQLQuery[] {} );
DBM = new JDBCManager( bdUrl + "?prepareThreshold=1", bdUsername, bdPassword, 8, 8, 0, new SQLQuery[] {} );
}
catch( Exception e )
catch ( Exception e )
{
e.printStackTrace();
}
@ -79,87 +88,67 @@ public class NewsServlet extends HttpServlet
DBM.close();
DBM = null;
}
catch( Exception ex )
catch ( Exception ex )
{
// we come here after an error
// so we discard this exception
}
}
private String getNews()
{
//System.err.println( "NEWS: BEGIN" );
try
{
if( executer == null )
if ( executer == null )
{
executer = ( SQLExecuter )DBM.getSharedExecuter( this );
executer = ( SQLExecuter ) DBM.getSharedExecuter( this );
}
Virtual2DArray array = executer.executeQuery( SELECT );
Object o[][] = array.getObjects();
if( o != null && o.length > 0 )
if ( o != null && o.length > 0 )
{
//System.err.println( "NEWS: " + o[ 0 ][ 0 ].toString() );
return
//o[ 0 ][ 0 ].toString() +
StringConverter.unicodeToHTML( o[ 0 ][ 1 ].toString() );
return StringConverter.unicodeToHTML( o[ 0 ][ 1 ].toString() );
}
}
catch( Exception ex )
catch ( Exception ex )
{
//System.err.println( "NEWS: EX" );
ex.printStackTrace();
close();
}
//System.err.println( "NEWS: END" );
return null;
}
public void doGet( HttpServletRequest req, HttpServletResponse res )
throws IOException
public void doGet( HttpServletRequest req, HttpServletResponse res ) throws IOException
{
//System.err.println( "NEWS: GET BEGIN" );
init();
//System.err.println( "NEWS: AF INIT" );
ServletOutputStream out = res.getOutputStream();
// String queryString = req.getQueryString();
res.setContentType( "text/html" );
String news = getNews();
Hashtable parameters = new Hashtable();
if( news == null )
{
parameters.put( "noticias", "" );
}
else
{
parameters.put( "noticias", news );
}
//System.err.println( "NEWS: BF SHOW" );
Map< String, Object > parameters = new HashMap< String, Object >();
parameters.put( "noticias", news == null ? "" : news );
out.println( showPage( "noticias/mostrar_noticias.html", parameters ) );
}
private String showPage( String page, Hashtable parameters )
private String showPage( String page, Map< String, Object > parameters )
{
VelocityContext context = new VelocityContext();
StringWriter output = new StringWriter();
try
{
if( parameters != null )
if ( parameters != null )
{
String key;
for( Enumeration e = parameters.keys(); e.hasMoreElements(); )
Iterator< String > it = parameters.keySet().iterator();
while ( it.hasNext() )
{
key = ( String ) e.nextElement();
String key = it.next();
context.put( key, parameters.get( key ) );
}
}
Velocity.mergeTemplate( page, Velocity.ENCODING_DEFAULT, context, output );
return output.toString();
}
catch( Exception e )
catch ( Exception e )
{
e.printStackTrace();
}

@ -1,118 +1,123 @@
package com.evolute.siprp.pagina;
import com.evolute.utils.arrays.*;
import com.evolute.utils.strings.*;
import java.io.*;
import java.util.*;
import java.sql.*;
import java.lang.reflect.Array;
import javax.servlet.*;
import javax.servlet.http.*;
import org.apache.velocity.*;
import org.apache.velocity.app.*;
import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import com.evolute.utils.arrays.ResultSet2DArray;
public class doGetListaEmpresas extends siprpServlet
{
private static final long serialVersionUID = 1L;
public doGetListaEmpresas( HttpServletRequest req, HttpServletResponse res ) throws IOException
{
ServletOutputStream out = res.getOutputStream();
Connection con = null ;
Statement stmt = null ;
Connection con = null;
Statement stmt = null;
ResultSet2DArray rs;
StringBuffer dbQuery;
String userRole="", temp="";
HttpSession session = req.getSession(false);
Vector links = new Vector();
Vector desc = new Vector();
String empresa_nome;
String userRole = "", temp = "";
HttpSession session = req.getSession( false );
List< String > links = new LinkedList< String >();
List< String > desc = new LinkedList< String >();
String empresa_nome;
try
{
userRole = (String)session.getAttribute(super.sessionUserRole);
empresa_nome = ( String ) session.getAttribute( sessionCompanyName );
userRole = ( String ) session.getAttribute( sessionUserRole );
empresa_nome = ( String ) session.getAttribute( sessionCompanyName );
if (userRole == null)
if ( userRole == null )
{
throw new IllegalStateException();
}
if ( userRole.equals ( super.superUserRole ) )
if ( userRole.equals( superUserRole ) )
{
empresa_nome = null;
Class.forName(super.bdDriver);
empresa_nome = null;
Class.forName( bdDriver );
con = DriverManager.getConnection( bdLocalUrl, bdLocalUsername, bdLocalPassword );
dbQuery = new StringBuffer();
dbQuery.append(
"SELECT id, designacao_social, designacao_social_plain " +
"FROM empresas " +
"WHERE " +
"inactivo <> 'y' " +
"AND data_cancelamento IS NULL " +
"ORDER BY designacao_social_plain" );
stmt = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
rs = new ResultSet2DArray( stmt.executeQuery( dbQuery.toString()) );
dbQuery.append( "SELECT id, designacao_social, designacao_social_plain " + "FROM empresas " + "WHERE " + "inactivo <> 'y' "
+ "AND data_cancelamento IS NULL " + "ORDER BY designacao_social_plain" );
stmt = con.createStatement( ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY );
rs = new ResultSet2DArray( stmt.executeQuery( dbQuery.toString() ) );
int index=0;
int index = 0;
int max = rs.columnLength();
while ( index < max )
{
String str = (String)rs.get(index,1);
if( str != null && str.trim().length() > 0 )
String str = ( String ) rs.get( index, 1 );
if ( str != null && str.trim().length() > 0 )
{
temp=""+rs.get(index,0); // converter de int para String
temp = "" + rs.get( index, 0 ); // converter de int para
// String
dbQuery = new StringBuffer();
dbQuery.append("/"+super.servletName+"/?"+temp); // contruir url
links.add(dbQuery.toString());
desc.add((String)rs.get(index,1));
dbQuery.append( "/" + servletName + "/?" + temp ); // contruir
// url
links.add( dbQuery.toString() );
desc.add( ( String ) rs.get( index, 1 ) );
}
++index;
}
stmt.close();
con.close();
session.setAttribute( sessionEstabelecimentoId, null );
session.setAttribute( sessionEstabelecimentoId, null );
HashMap hmValues = new HashMap();
//hmValues.put( "empresa_nome", session.getAttribute( sessionCompanyName ) );
hmValues.put( "empresa_nome", empresa_nome );
hmValues.put( "empresa_id", session.getAttribute( sessionEmpresaId ) );
hmValues.put( "estabelecimento_id", session.getAttribute( sessionEstabelecimentoId ) );
hmValues.put( "userRole", userRole );
hmValues.put( "userName", session.getAttribute( sessionUser ) );
hmValues.put( msgTemplate , super.msgListaEmpresas ) ;
hmValues.put( templateUserRole, userRole);
hmValues.put( templateQuery, super.queryStringEmpresas );
hmValues.put( templateVector1,links);
hmValues.put( templateVector2,desc);
hmValues.put( templateVector3,null);
out.println( mergeTemplate( hmValues, super.authenticatedUserTemplate));
Map< String, Object > hmValues = new HashMap< String, Object >();
// hmValues.put( "empresa_nome", session.getAttribute(
// sessionCompanyName ) );
hmValues.put( "empresa_nome", empresa_nome );
hmValues.put( "empresa_id", session.getAttribute( sessionEmpresaId ) );
hmValues.put( "estabelecimento_id", session.getAttribute( sessionEstabelecimentoId ) );
hmValues.put( "userRole", userRole );
hmValues.put( "userName", session.getAttribute( sessionUser ) );
hmValues.put( msgTemplate, msgListaEmpresas );
hmValues.put( templateUserRole, userRole );
hmValues.put( templateQuery, queryStringEmpresas );
hmValues.put( templateVector1, links );
hmValues.put( templateVector2, desc );
hmValues.put( templateVector3, null );
out.println( mergeTemplate( hmValues, authenticatedUserTemplate ) );
//out.println( mergeTemplate( super.msgListaEmpresas, userRole, super.queryStringEmpresas, links, desc, null, super.authenticatedUserTemplate) );
// out.println( mergeTemplate( super.msgListaEmpresas, userRole,
// super.queryStringEmpresas, links, desc, null,
// super.authenticatedUserTemplate) );
}
else
{
out.println( mergeTemplate( super.msgAcessoNegado , userRole, super.errorTemplate) );
out.println( mergeTemplate( msgAcessoNegado, userRole, errorTemplate ) );
}
}
catch ( IllegalStateException e ) // session timeout
{
e.printStackTrace();
out.println( mergeTemplate(msgSessionTimeout, super.errorTemplate) );
out.println( mergeTemplate( msgSessionTimeout, errorTemplate ) );
}
catch ( SQLException e )
{
e.printStackTrace();
out.println( mergeTemplate( super.msgErroBd , super.errorTemplate) );
out.println( mergeTemplate( msgErroBd, errorTemplate ) );
}
catch ( Exception e )
{
e.printStackTrace();
out.println( mergeTemplate( super.msgGenericError , userRole, super.errorTemplate) );
out.println( mergeTemplate( msgGenericError, userRole, errorTemplate ) );
}
}

@ -1,104 +1,118 @@
package com.evolute.siprp.pagina;
import com.evolute.utils.arrays.*;
import com.evolute.utils.strings.*;
import java.io.*;
import java.util.*;
import java.sql.*;
import java.lang.reflect.Array;
import javax.servlet.*;
import javax.servlet.http.*;
import org.apache.velocity.*;
import org.apache.velocity.app.*;
import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
public class doGetListaEstabelecimentos extends siprpServlet{
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
/** Creates a new instance of doGetListaEstabelecimentos */
public doGetListaEstabelecimentos(HttpServletRequest req, HttpServletResponse res) throws IOException
import com.evolute.utils.arrays.ResultSet2DArray;
public class doGetListaEstabelecimentos extends siprpServlet
{
private static final long serialVersionUID = 1L;
public doGetListaEstabelecimentos( HttpServletRequest req, HttpServletResponse res ) throws IOException
{
ServletOutputStream out = res.getOutputStream();
Connection con = null ;
Statement stmt = null ;
Connection con = null;
Statement stmt = null;
ResultSet2DArray rs;
StringBuffer dbQuery, sBuffer;
String userRole, empresaId, temp;
HttpSession session = req.getSession(false);
Vector links = new Vector();
Vector desc = new Vector();
HttpSession session = req.getSession( false );
List< String > links = new LinkedList< String >();
List< String > desc = new LinkedList< String >();
try
{
userRole = (String)session.getAttribute(super.sessionUserRole);
empresaId = (String)session.getAttribute(super.sessionEmpresaId);
userRole = ( String ) session.getAttribute( sessionUserRole );
empresaId = ( String ) session.getAttribute( sessionEmpresaId );
if ( userRole.equals ( super.superUserRole ) || userRole.equals ( empresaId ) )
if ( userRole.equals( superUserRole ) || userRole.equals( empresaId ) )
{
Class.forName(super.bdDriver);
Class.forName( bdDriver );
con = DriverManager.getConnection( bdLocalUrl, bdLocalUsername, bdLocalPassword );
dbQuery = new StringBuffer();
dbQuery.append( " SELECT id, nome, nome_plain FROM estabelecimentos WHERE inactivo <> 'y' AND empresa_id = '"+empresaId+"' order by nome_plain" );
stmt = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
rs = new ResultSet2DArray( stmt.executeQuery( dbQuery.toString()) );
dbQuery.append( " SELECT id, nome, nome_plain FROM estabelecimentos WHERE inactivo <> 'y' AND empresa_id = '" + empresaId
+ "' order by nome_plain" );
stmt = con.createStatement( ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY );
rs = new ResultSet2DArray( stmt.executeQuery( dbQuery.toString() ) );
int index=0;
int index = 0;
int max = rs.columnLength();
while ( index < max )
{
temp=""+rs.get(index,0); // converter de int para String
temp = "" + rs.get( index, 0 ); // converter de int para
// String
dbQuery = new StringBuffer();
dbQuery.append("/"+super.servletName+"/?"+empresaId+"/"+temp); // contruir url
links.add(dbQuery.toString());
desc.add((String)rs.get(index,1));
dbQuery.append( "/" + servletName + "/?" + empresaId + "/" + temp ); // contruir
// url
links.add( dbQuery.toString() );
desc.add( ( String ) rs.get( index, 1 ) );
++index;
}
sBuffer = new StringBuffer();
sBuffer.append("<b>"+super.nomeEmpresa(con,empresaId)+"</b>");
sBuffer.append( "<b>" + super.nomeEmpresa( con, empresaId ) + "</b>" );
if( userRole.equals( "manager" ) )
{
if ( userRole.equals( "manager" ) )
{
session.setAttribute( sessionCompanyName, nomeEmpresa( con, ( String ) session.getAttribute( sessionEmpresaId ) ) );
}
else
{
}
else
{
session.setAttribute( sessionCompanyName, nomeEmpresa( con, userRole ) );
}
}
session.setAttribute( sessionCompanyEmail, emailEmpresa( con, empresaId ) );
session.setAttribute( sessionCompanyEmail, emailEmpresa( con, empresaId ) );
session.setAttribute( sessionEstabelecimentoId, null );
session.setAttribute( sessionEstabelecimentoId, null );
HashMap hmValues = new HashMap();
hmValues.put( "empresa_nome", session.getAttribute( sessionCompanyName ) );
hmValues.put( "empresa_id", session.getAttribute( sessionEmpresaId ) );
hmValues.put( "estabelecimento_id", session.getAttribute( sessionEstabelecimentoId ) );
hmValues.put( "userRole", userRole );
hmValues.put( "userName", session.getAttribute( sessionUser ) );
hmValues.put( msgTemplate , sBuffer.toString() ) ;
hmValues.put( templateUserRole, userRole);
hmValues.put( templateQuery, super.queryStringEstabelecimentos );
hmValues.put( templateVector1,links);
hmValues.put( templateVector2,desc);
hmValues.put( templateVector3,null);
out.println( mergeTemplate( hmValues, super.authenticatedUserTemplate));
Map< String, Object > hmValues = new HashMap< String, Object >();
hmValues.put( "empresa_nome", session.getAttribute( sessionCompanyName ) );
hmValues.put( "empresa_id", session.getAttribute( sessionEmpresaId ) );
hmValues.put( "estabelecimento_id", session.getAttribute( sessionEstabelecimentoId ) );
hmValues.put( "userRole", userRole );
hmValues.put( "userName", session.getAttribute( sessionUser ) );
hmValues.put( msgTemplate, sBuffer.toString() );
hmValues.put( templateUserRole, userRole );
hmValues.put( templateQuery, queryStringEstabelecimentos );
hmValues.put( templateVector1, links );
hmValues.put( templateVector2, desc );
hmValues.put( templateVector3, null );
out.println( mergeTemplate( hmValues, authenticatedUserTemplate ) );
// out.println( mergeTemplate( sBuffer.toString(), userRole, super.queryStringEstabelecimentos, links, desc, null, super.authenticatedUserTemplate) );
// out.println( mergeTemplate( sBuffer.toString(), userRole,
// super.queryStringEstabelecimentos, links, desc, null,
// super.authenticatedUserTemplate) );
stmt.close();
con.close();
}
else
{
out.println( mergeTemplate( super.msgAcessoNegado , userRole, super.errorTemplate) );
out.println( mergeTemplate( msgAcessoNegado, userRole, errorTemplate ) );
}
}
catch ( SQLException e )
{
e.printStackTrace();
out.println( mergeTemplate( super.msgErroBd , super.errorTemplate) );
out.println( mergeTemplate( msgErroBd, errorTemplate ) );
}
catch ( Exception e )
{
e.printStackTrace();
out.println( mergeTemplate( super.msgGenericError , super.errorTemplate) );
out.println( mergeTemplate( msgGenericError, errorTemplate ) );
}
}

@ -1,18 +1,25 @@
package com.evolute.siprp.pagina;
import com.evolute.utils.arrays.*;
import com.evolute.utils.strings.*;
import java.io.*;
import java.util.*;
import java.sql.*;
import java.lang.reflect.Array;
import javax.servlet.*;
import javax.servlet.http.*;
import org.apache.velocity.*;
import org.apache.velocity.app.*;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import com.evolute.utils.arrays.ResultSet2DArray;
public class doGetListaTrabalhadores extends siprpServlet
{
private static final long serialVersionUID = 1L;
private ResultSet2DArray executeQuery( Connection con, String query ) throws Exception
{
@ -23,56 +30,62 @@ public class doGetListaTrabalhadores extends siprpServlet
return rs;
}
public doGetListaTrabalhadores(HttpServletRequest req, HttpServletResponse res, String query) throws Exception
public doGetListaTrabalhadores( HttpServletRequest req, HttpServletResponse res, String query ) throws Exception
{
boolean print = false;
if( query != null )
if ( query != null )
{
print = query.indexOf( "_print" ) != -1;
if( query.indexOf( "trabalhadores_tudo" ) == 0 )
if ( query.indexOf( "trabalhadores_tudo" ) == 0 )
{
new doGetListaTrabalhadoresTudo( req, res, print );
return;
}
else if( query.indexOf( "trabalhadores_pendentes" ) == 0 )
else if ( query.indexOf( "trabalhadores_pendentes" ) == 0 )
{
new doGetListaTrabalhadoresPendentes( req, res, print );
return;
}
}
ServletOutputStream out = res.getOutputStream();
Connection con = null ;
Statement stmt = null ;
Connection con = null;
Statement stmt = null;
ResultSet2DArray rs, rsTrab;
StringBuffer sBuffer;
String userRole, empresaId, estabelecimentoId, temp;
HttpSession session = req.getSession(false);
Vector links = new Vector();
Vector desc = new Vector();
Vector descAdicional = new Vector();
java.util.Date today = new java.util.Date();
String userRole;
String empresaId;
String estabelecimentoId;
HttpSession session = req.getSession( false );
List< String > links = new LinkedList< String >();
List< Map< String, Object > > desc = new LinkedList< Map< String, Object > >();
try
{
userRole = (String)session.getAttribute(super.sessionUserRole);
empresaId = (String)session.getAttribute(super.sessionEmpresaId);
estabelecimentoId = (String)session.getAttribute(super.sessionEstabelecimentoId);
userRole = ( String ) session.getAttribute( sessionUserRole );
empresaId = ( String ) session.getAttribute( sessionEmpresaId );
estabelecimentoId = ( String ) session.getAttribute( sessionEstabelecimentoId );
System.out.println( "\ndoGetListaTrabalhadores() . " );
System.out.println( "\tuserRole : " + userRole + " - " + super.superUserRole );
System.out.println( "\tuserRole : " + userRole + " - " + superUserRole );
System.out.println( "\tempresaID : " + empresaId );
System.out.println( "\testabelecimentoID : " + estabelecimentoId );
if ( userRole != null && ( userRole.equals( super.superUserRole ) || userRole.equals( empresaId ) ) )
if ( userRole != null && ( userRole.equals( superUserRole ) || userRole.equals( empresaId ) ) )
{
Class.forName(super.bdDriver);
Class.forName( bdDriver );
con = DriverManager.getConnection( bdLocalUrl, bdLocalUsername, bdLocalPassword );
if ( super.verificaEstabelecimento(con, empresaId, estabelecimentoId) ) // estabelecimento pertence 'a empresa ??
if ( verificaEstabelecimento( con, empresaId, estabelecimentoId ) ) // estabelecimento
// pertence
// 'a
// empresa
// ??
{
//Class.forName(super.bdDriver);
//con = DriverManager.getConnection( super.bdUrl, super.bdUsername, super.bdPassword );
String dbQuery = "SELECT id, nome, nome_plain FROM trabalhadores WHERE inactivo <> 'y' AND data_demissao IS NULL AND estabelecimento_id = '"+estabelecimentoId+"' ORDER BY nome_plain";
stmt = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
// Class.forName(super.bdDriver);
// con = DriverManager.getConnection( super.bdUrl,
// super.bdUsername, super.bdPassword );
String dbQuery = "SELECT id, nome, nome_plain FROM trabalhadores WHERE inactivo <> 'y' AND data_demissao IS NULL AND estabelecimento_id = '"
+ estabelecimentoId + "' ORDER BY nome_plain";
stmt = con.createStatement( ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY );
rsTrab = new ResultSet2DArray( stmt.executeQuery( dbQuery ) );
rsTrab.getObjects();
stmt.close();
@ -81,111 +94,115 @@ public class doGetListaTrabalhadores extends siprpServlet
for ( int index = 0; index < max; index++ )
{
Integer id = (Integer)rsTrab.get(index,0);
String link = "/"+super.servletName+"/?"+empresaId+"/"+estabelecimentoId+"/"+id;
links.add(link);
HashMap trabalhador = new HashMap();
trabalhador.put( "Nome", (String)rsTrab.get(index,1) );
Integer id = ( Integer ) rsTrab.get( index, 0 );
String link = "/" + servletName + "/?" + empresaId + "/" + estabelecimentoId + "/" + id;
links.add( link );
Map< String, Object > trabalhador = new HashMap< String, Object >();
trabalhador.put( "Nome", ( String ) rsTrab.get( index, 1 ) );
/** dados de consultas **/
// dbQuery = "SELECT id, data, estado FROM marcacoes_trabalhador "
// + "WHERE tipo = 1 and trabalhador_id = " + id
// + " ORDER BY data DESC";
// stmt = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
// rs = new ResultSet2DArray( stmt.executeQuery( dbQuery ) );
// rs.getObjects();
// stmt.close();
// if( rs.columnLength() > 0 )
// {
// java.util.Date dataConsulta2 = ( java.util.Date ) rs.get( 0, 1 );
// Integer estado2 = ( Integer ) rs.get( 0, 2 );
// java.util.Date dataConsulta1;
// Integer estado1;
// String realizada1 = "";
// String realizada2 = "";
// if( rs.columnLength() >= 2 )
// {
// dataConsulta1 = ( java.util.Date ) rs.get( 1, 1 );
// estado1 = ( Integer ) rs.get( 1, 2 );
// }
// else
// {
// dataConsulta1 = dataConsulta2;
// estado1 = estado2;
// }
// if( ESTADO_REALIZADO.equals( estado2 ) || ( dataConsulta2 != null && today.after( dataConsulta2 ) ) )
// {
// trabalhador.put( "ultima_consulta", dataConsulta2 );
// if( estado2.equals( ESTADO_POR_REALIZAR ) )
// {
// realizada2 = "n&atilde;o";
// }
// else if( estado2.equals( ESTADO_REALIZADO ) )
// {
// realizada2 = "sim";
// }
// trabalhador.put( "realizada", realizada2 );
// trabalhador.put( "proxima_consulta", "" );
// }
// else
// {
// try
// {
// for( int c = 1; c < rs.columnLength(); c++ )
// {
// java.util.Date dataTemp = ( java.util.Date ) rs.get( c, 1 );
// dataConsulta1 = dataTemp;
// estado1 = ( Integer ) rs.get( c, 2 );
// if( dataTemp.after( today ) )
// {
// dataConsulta2 = dataTemp;
// }
// else
// {
// break;
// }
// }
// }
// catch( Exception ex )
// {
// ex.printStackTrace();
// }
// trabalhador.put( "proxima_consulta", dataConsulta2 );
//
// if( !dataConsulta2.equals( dataConsulta1 ) )
// {
// if( estado1.equals( ESTADO_POR_REALIZAR ) )
// {
// realizada1 = "n&atilde;o";
// }
// else if( estado1.equals( ESTADO_REALIZADO ) )
// {
// realizada1 = "sim";
// }
// trabalhador.put( "realizada", realizada1 );
// trabalhador.put( "ultima_consulta", dataConsulta1 );
// }
// else
// {
// trabalhador.put( "ultima_consulta", "" );
// trabalhador.put( "realizada", null );
// }
// }
// }
// else
// {
// trabalhador.put( "ultima_consulta", "" );
// trabalhador.put( "realizada", null );
// trabalhador.put( "proxima_consulta", "" );
// }
// dbQuery =
// "SELECT id, data, estado FROM marcacoes_trabalhador "
// + "WHERE tipo = 1 and trabalhador_id = " + id
// + " ORDER BY data DESC";
// stmt =
// con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
// ResultSet.CONCUR_READ_ONLY);
// rs = new ResultSet2DArray( stmt.executeQuery( dbQuery
// ) );
// rs.getObjects();
// stmt.close();
// if( rs.columnLength() > 0 )
// {
// java.util.Date dataConsulta2 = ( java.util.Date )
// rs.get( 0, 1 );
// Integer estado2 = ( Integer ) rs.get( 0, 2 );
// java.util.Date dataConsulta1;
// Integer estado1;
// String realizada1 = "";
// String realizada2 = "";
// if( rs.columnLength() >= 2 )
// {
// dataConsulta1 = ( java.util.Date ) rs.get( 1, 1 );
// estado1 = ( Integer ) rs.get( 1, 2 );
// }
// else
// {
// dataConsulta1 = dataConsulta2;
// estado1 = estado2;
// }
// if( ESTADO_REALIZADO.equals( estado2 ) || (
// dataConsulta2 != null && today.after( dataConsulta2 )
// ) )
// {
// trabalhador.put( "ultima_consulta", dataConsulta2 );
// if( estado2.equals( ESTADO_POR_REALIZAR ) )
// {
// realizada2 = "n&atilde;o";
// }
// else if( estado2.equals( ESTADO_REALIZADO ) )
// {
// realizada2 = "sim";
// }
// trabalhador.put( "realizada", realizada2 );
// trabalhador.put( "proxima_consulta", "" );
// }
// else
// {
// try
// {
// for( int c = 1; c < rs.columnLength(); c++ )
// {
// java.util.Date dataTemp = ( java.util.Date ) rs.get(
// c, 1 );
// dataConsulta1 = dataTemp;
// estado1 = ( Integer ) rs.get( c, 2 );
// if( dataTemp.after( today ) )
// {
// dataConsulta2 = dataTemp;
// }
// else
// {
// break;
// }
// }
// }
// catch( Exception ex )
// {
// ex.printStackTrace();
// }
// trabalhador.put( "proxima_consulta", dataConsulta2 );
//
// if( !dataConsulta2.equals( dataConsulta1 ) )
// {
// if( estado1.equals( ESTADO_POR_REALIZAR ) )
// {
// realizada1 = "n&atilde;o";
// }
// else if( estado1.equals( ESTADO_REALIZADO ) )
// {
// realizada1 = "sim";
// }
// trabalhador.put( "realizada", realizada1 );
// trabalhador.put( "ultima_consulta", dataConsulta1 );
// }
// else
// {
// trabalhador.put( "ultima_consulta", "" );
// trabalhador.put( "realizada", null );
// }
// }
// }
// else
// {
// trabalhador.put( "ultima_consulta", "" );
// trabalhador.put( "realizada", null );
// trabalhador.put( "proxima_consulta", "" );
// }
dbQuery = "select id, data, estado " +
"from marcacoes_trabalhador " +
"where deleted_stamp is null and tipo = 1 and estado = 2 and trabalhador_id = " + id + " " +
"order by data desc " +
"limit 1";
dbQuery = "select id, data, estado " + "from marcacoes_trabalhador "
+ "where deleted_stamp is null and tipo = 1 and estado = 2 and trabalhador_id = " + id + " " + "order by data desc " + "limit 1";
rs = executeQuery( con, dbQuery );
java.util.Date dataUltimaConsultaRealizada = null;
@ -196,11 +213,9 @@ public class doGetListaTrabalhadores extends siprpServlet
consultaRealizada = "Sim";
}
dbQuery = "select id, data, estado " +
"from marcacoes_trabalhador " +
"where deleted_stamp is null and tipo = 1 and estado != 2 and data >= now() and trabalhador_id = " + id + " " +
"order by data desc " +
"limit 1";
dbQuery = "select id, data, estado " + "from marcacoes_trabalhador "
+ "where deleted_stamp is null and tipo = 1 and estado != 2 and data >= now() and trabalhador_id = " + id + " "
+ "order by data desc " + "limit 1";
rs = executeQuery( con, dbQuery );
java.util.Date dataProximaConsulta = null;
@ -214,13 +229,9 @@ public class doGetListaTrabalhadores extends siprpServlet
trabalhador.put( "proxima_consulta", dataProximaConsulta == null ? "" : dataProximaConsulta );
/** eof dados consulta **/
/** dados de exames **/
dbQuery = "select id, data, estado " +
"from marcacoes_trabalhador " +
"where deleted_stamp is null and tipo = 0 and estado = 2 and trabalhador_id = " + id +
" order by data desc " +
"limit 1";
dbQuery = "select id, data, estado " + "from marcacoes_trabalhador "
+ "where deleted_stamp is null and tipo = 0 and estado = 2 and trabalhador_id = " + id + " order by data desc " + "limit 1";
rs = executeQuery( con, dbQuery );
java.util.Date dataUltimoExameRealizado = null;
@ -232,11 +243,9 @@ public class doGetListaTrabalhadores extends siprpServlet
}
java.util.Date dataProximoExame = null;
dbQuery = "select id, data, estado " +
"from marcacoes_trabalhador " +
"where deleted_stamp is null and tipo = 0 and estado != 2 and data >= now() and trabalhador_id = " + id + " " +
"order by data desc " +
"limit 1";
dbQuery = "select id, data, estado " + "from marcacoes_trabalhador "
+ "where deleted_stamp is null and tipo = 0 and estado != 2 and data >= now() and trabalhador_id = " + id + " "
+ "order by data desc " + "limit 1";
rs = executeQuery( con, dbQuery );
if ( rs.columnLength() > 0 )
{
@ -247,129 +256,135 @@ public class doGetListaTrabalhadores extends siprpServlet
trabalhador.put( "realizado", realizado );
trabalhador.put( "proximo_exame", dataProximoExame == null ? "" : dataProximoExame );
// dbQuery = "SELECT id, data, estado FROM marcacoes_trabalhador "
// + "WHERE tipo = 0 and trabalhador_id = " + id
// + " ORDER BY data DESC";
// stmt = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
// rs = new ResultSet2DArray( stmt.executeQuery( dbQuery ) );
// rs.getObjects();
// stmt.close();
// if( rs.columnLength() > 0 )
// {
// java.util.Date dataConsulta2 = ( java.util.Date ) rs.get( 0, 1 );
// Integer estado2 = ( Integer ) rs.get( 0, 2 );
// Integer estado1;
// java.util.Date dataConsulta1;
// String realizada1 = "";
// String realizada2 = "";
// if( rs.columnLength() >= 2 )
// {
// dataConsulta1 = ( java.util.Date ) rs.get( 1, 1 );
// estado1 = ( Integer ) rs.get( 1, 2 );
// }
// else
// {
// dataConsulta1 = dataConsulta2;
// estado1 = estado2;
// }
// if( ESTADO_REALIZADO.equals( estado2 ) || today.after( dataConsulta2 ) )
// {
// trabalhador.put( "ultimo_exame", dataConsulta2 );
// if( estado2.equals( ESTADO_POR_REALIZAR ) )
// {
// realizada2 = "n&atilde;o";
// }
// else if( estado2.equals( ESTADO_REALIZADO ) )
// {
// realizada2 = "sim";
// }
// trabalhador.put( "realizado", realizada2 );
// trabalhador.put( "proximo_exame", "" );
// }
// else
// {
// trabalhador.put( "proximo_exame", dataConsulta2 );
// if( !dataConsulta2.equals( dataConsulta1 ) )
// {
// if( estado1.equals( ESTADO_POR_REALIZAR ) )
// {
// realizada1 = "n&atilde;o";
// }
// else if( estado1.equals( ESTADO_REALIZADO ) )
// {
// realizada1 = "sim";
// }
// trabalhador.put( "realizado", realizada1 );
// trabalhador.put( "ultimo_exame", dataConsulta1 );
// }
// else
// {
// trabalhador.put( "ultimo_exame", "" );
// trabalhador.put( "realizado", null );
// }
// }
// }
// else
// {
// trabalhador.put( "ultimo_exame", "" );
// trabalhador.put( "realizado", null );
// trabalhador.put( "proximo_exame", "" );
// }
// dbQuery =
// "SELECT id, data, estado FROM marcacoes_trabalhador "
// + "WHERE tipo = 0 and trabalhador_id = " + id
// + " ORDER BY data DESC";
// stmt =
// con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
// ResultSet.CONCUR_READ_ONLY);
// rs = new ResultSet2DArray( stmt.executeQuery( dbQuery
// ) );
// rs.getObjects();
// stmt.close();
// if( rs.columnLength() > 0 )
// {
// java.util.Date dataConsulta2 = ( java.util.Date )
// rs.get( 0, 1 );
// Integer estado2 = ( Integer ) rs.get( 0, 2 );
// Integer estado1;
// java.util.Date dataConsulta1;
// String realizada1 = "";
// String realizada2 = "";
// if( rs.columnLength() >= 2 )
// {
// dataConsulta1 = ( java.util.Date ) rs.get( 1, 1 );
// estado1 = ( Integer ) rs.get( 1, 2 );
// }
// else
// {
// dataConsulta1 = dataConsulta2;
// estado1 = estado2;
// }
// if( ESTADO_REALIZADO.equals( estado2 ) ||
// today.after( dataConsulta2 ) )
// {
// trabalhador.put( "ultimo_exame", dataConsulta2 );
// if( estado2.equals( ESTADO_POR_REALIZAR ) )
// {
// realizada2 = "n&atilde;o";
// }
// else if( estado2.equals( ESTADO_REALIZADO ) )
// {
// realizada2 = "sim";
// }
// trabalhador.put( "realizado", realizada2 );
// trabalhador.put( "proximo_exame", "" );
// }
// else
// {
// trabalhador.put( "proximo_exame", dataConsulta2 );
// if( !dataConsulta2.equals( dataConsulta1 ) )
// {
// if( estado1.equals( ESTADO_POR_REALIZAR ) )
// {
// realizada1 = "n&atilde;o";
// }
// else if( estado1.equals( ESTADO_REALIZADO ) )
// {
// realizada1 = "sim";
// }
// trabalhador.put( "realizado", realizada1 );
// trabalhador.put( "ultimo_exame", dataConsulta1 );
// }
// else
// {
// trabalhador.put( "ultimo_exame", "" );
// trabalhador.put( "realizado", null );
// }
// }
// }
// else
// {
// trabalhador.put( "ultimo_exame", "" );
// trabalhador.put( "realizado", null );
// trabalhador.put( "proximo_exame", "" );
// }
/** eof dados exames **/
desc.add( trabalhador );
}
sBuffer = new StringBuffer();
sBuffer.append("<b>"+super.nomeEmpresa(con,empresaId)+"</b><br><br><i>"
+super.nomeEstabelecimento(con, estabelecimentoId)+"</i>" );
sBuffer.append( "<b>" + nomeEmpresa( con, empresaId ) + "</b><br><br><i>" + nomeEstabelecimento( con, estabelecimentoId ) + "</i>" );
HashMap hmValues = new HashMap();
Map< String, Object > hmValues = new HashMap< String, Object >();
hmValues.put( "empresa_nome", session.getAttribute( sessionCompanyName ) );
hmValues.put( "empresa_id", session.getAttribute( sessionEmpresaId ) );
hmValues.put( "estabelecimento_nome", super.nomeEstabelecimento( con, estabelecimentoId ) );
hmValues.put( "estabelecimento_nome", nomeEstabelecimento( con, estabelecimentoId ) );
hmValues.put( "estabelecimento_id", estabelecimentoId );
hmValues.put( "userRole", userRole );
hmValues.put( "userName", session.getAttribute( sessionUser ) );
hmValues.put( msgTemplate , sBuffer.toString() ) ;
hmValues.put( templateUserRole, userRole);
hmValues.put( templateQuery, super.queryStringTrabalhadores );
hmValues.put( templateVector1,links);
hmValues.put( templateVector2,desc);
hmValues.put( templateVector3,null);
if( !print )
hmValues.put( msgTemplate, sBuffer.toString() );
hmValues.put( templateUserRole, userRole );
hmValues.put( templateQuery, queryStringTrabalhadores );
hmValues.put( templateVector1, links );
hmValues.put( templateVector2, desc );
hmValues.put( templateVector3, null );
if ( !print )
{
out.println( mergeTemplate( hmValues, super.authenticatedUserTemplate));
out.println( mergeTemplate( hmValues, authenticatedUserTemplate ) );
}
else
{
out.println( mergeTemplate( hmValues, super.authenticatedUserPrintTemplate));
out.println( mergeTemplate( hmValues, authenticatedUserPrintTemplate ) );
}
// out.println( mergeTemplate( sBuffer.toString(), userRole, super.queryStringTrabalhadores, links, desc, null, super.authenticatedUserTemplate) );
// out.println( mergeTemplate( sBuffer.toString(), userRole,
// super.queryStringTrabalhadores, links, desc, null,
// super.authenticatedUserTemplate) );
}
else // est nao pertence 'a empresa
else
// est nao pertence 'a empresa
{
out.println( mergeTemplate( super.msgLinkFormatError , userRole, super.errorTemplate) );
out.println( mergeTemplate( msgLinkFormatError, userRole, errorTemplate ) );
}
con.close();
}
else // Role nao permite ver esta informacao
else
// Role nao permite ver esta informacao
{
out.println( mergeTemplate( super.msgAcessoNegado , userRole, super.errorTemplate) );
out.println( mergeTemplate( msgAcessoNegado, userRole, errorTemplate ) );
}
}
catch ( SQLException e )
{
e.printStackTrace();
out.println( mergeTemplate( super.msgErroBd , super.errorTemplate) );
out.println( mergeTemplate( msgErroBd, errorTemplate ) );
}
catch ( Exception e )
{
e.printStackTrace();
out.println( mergeTemplate( super.msgGenericError , super.errorTemplate) );
out.println( mergeTemplate( msgGenericError, errorTemplate ) );
}
}

@ -6,22 +6,18 @@
package com.evolute.siprp.pagina;
import java.io.*;
import java.lang.reflect.Array;
import javax.servlet.*;
import javax.servlet.http.*;
import java.util.*;
import java.sql.SQLException;
import org.apache.velocity.*;
import org.apache.velocity.app.*;
import org.apache.velocity.runtime.parser.node.GetExecutor;
import com.evolute.utils.arrays.*;
import com.evolute.utils.data.*;
import com.evolute.utils.db.*;
import com.evolute.utils.sql.*;
import com.evolute.utils.strings.*;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import com.evolute.utils.arrays.Virtual2DArray;
import com.evolute.utils.sql.Select;
/**
*
@ -30,6 +26,8 @@ import com.evolute.utils.strings.*;
public class doGetListaTrabalhadoresPendentes
extends siprpServlet
{
private static final long serialVersionUID = 1L;
private static final String DEFAULT_TIPO = "Admissão/Periódico Inicial";
private static final Map< Integer, String > ESTADO_COR = new HashMap< Integer, String >();
@ -135,7 +133,7 @@ public class doGetListaTrabalhadoresPendentes
list.add( map );
}
HashMap hmValues = new HashMap();
Map< String, Object > hmValues = new HashMap< String, Object >();
hmValues.put( "empresa_nome", empresaNome );
hmValues.put( "empresa_id", empresaID );
hmValues.put( "estabelecimento_nome", estabelecimentoNome );
@ -153,12 +151,12 @@ public class doGetListaTrabalhadoresPendentes
}
else // est nao pertence 'a empresa
{
out.println( mergeTemplate( super.msgLinkFormatError, userRole, super.errorTemplate ) );
out.println( mergeTemplate( msgLinkFormatError, userRole, errorTemplate ) );
}
}
else // Role nao permite ver esta informacao
{
out.println( mergeTemplate( super.msgAcessoNegado, userRole, super.errorTemplate ) );
out.println( mergeTemplate( msgAcessoNegado, userRole, errorTemplate ) );
}
}

@ -6,26 +6,30 @@
package com.evolute.siprp.pagina;
import java.io.*;
import java.util.*;
import java.sql.*;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Date;
import java.lang.reflect.Array;
import javax.servlet.*;
import javax.servlet.http.*;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import org.apache.velocity.*;
import org.apache.velocity.app.*;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import com.evolute.utils.arrays.*;
import com.evolute.utils.db.*;
import com.evolute.utils.sql.*;
import com.evolute.utils.strings.*;
import com.evolute.utils.arrays.ResultSet2DArray;
import com.evolute.utils.arrays.Virtual2DArray;
public class doGetListaTrabalhadoresTudo extends siprpServlet implements GlobalConstants
{
private static final long serialVersionUID = 1L;
public doGetListaTrabalhadoresTudo( HttpServletRequest req, HttpServletResponse res, boolean print )
throws Exception
@ -56,7 +60,8 @@ public class doGetListaTrabalhadoresTudo extends siprpServlet implements GlobalC
" and t.inactivo != 'y' " +
" and t.data_demissao is null " +
" and t.estabelecimento_id = " + estabelecimentoID + " " +
"group by e.trabalhador_id, t.nome";
"group by e.trabalhador_id, t.nome " +
"order by t.nome";
Statement stmt = con.createStatement( ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY );
Virtual2DArray array = new ResultSet2DArray( stmt.executeQuery( query ) );
@ -92,28 +97,28 @@ public class doGetListaTrabalhadoresTudo extends siprpServlet implements GlobalC
hmValues.put( templateVector2, null );
hmValues.put( templateVector3, null );
out.println( mergeTemplate( hmValues, ! print ? super.authenticatedUserTemplate : super.authenticatedUserPrintTemplate ) );
out.println( mergeTemplate( hmValues, ! print ? authenticatedUserTemplate : authenticatedUserPrintTemplate ) );
}
else
{
out.println( mergeTemplate( super.msgLinkFormatError, userRole, super.errorTemplate ) );
out.println( mergeTemplate( msgLinkFormatError, userRole, errorTemplate ) );
}
con.close();
}
else
{
out.println( mergeTemplate( super.msgAcessoNegado, userRole, super.errorTemplate ) );
out.println( mergeTemplate( msgAcessoNegado, userRole, errorTemplate ) );
}
}
catch ( SQLException e )
{
e.printStackTrace();
out.println( mergeTemplate( super.msgErroBd, super.errorTemplate ) );
out.println( mergeTemplate( msgErroBd, errorTemplate ) );
}
catch ( Exception e )
{
e.printStackTrace();
out.println( mergeTemplate( super.msgGenericError, super.errorTemplate ) );
out.println( mergeTemplate( msgGenericError, errorTemplate ) );
}
}

@ -1,18 +1,24 @@
package com.evolute.siprp.pagina;
import com.evolute.utils.arrays.*;
import com.evolute.utils.strings.*;
import java.io.*;
import java.util.*;
import java.sql.*;
import java.lang.reflect.Array;
import javax.servlet.*;
import javax.servlet.http.*;
import org.apache.velocity.*;
import org.apache.velocity.app.*;
import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.HashMap;
import java.util.Map;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import com.evolute.utils.arrays.ResultSet2DArray;
public class doGetTrabalhador extends siprpServlet
{
private static final long serialVersionUID = 1L;
private ResultSet2DArray executeQuery( Connection con, String query ) throws Exception
{
@ -23,45 +29,42 @@ public class doGetTrabalhador extends siprpServlet
return rs;
}
public doGetTrabalhador(HttpServletRequest req, HttpServletResponse res) throws IOException
public doGetTrabalhador( HttpServletRequest req, HttpServletResponse res ) throws IOException
{
ServletOutputStream out = res.getOutputStream();
Connection con = null ;
Statement stmt = null ;
Connection con = null;
Statement stmt = null;
ResultSet2DArray rs;
StringBuffer dbQuery, sBuffer;
String userRole, empresaId, estabelecimentoId, trabalhadorId, temp;
HttpSession session = req.getSession(false);
Vector names = new Vector();
Vector values = new Vector();
java.util.Date today = new java.util.Date();
String userRole;
String empresaId;
String estabelecimentoId;
String trabalhadorId;
HttpSession session = req.getSession( false );
try
{
userRole = (String)session.getAttribute(super.sessionUserRole);
empresaId = (String)session.getAttribute(super.sessionEmpresaId);
estabelecimentoId = (String)session.getAttribute(super.sessionEstabelecimentoId);
trabalhadorId = (String)session.getAttribute(super.sessionTrabalhadorId);
userRole = ( String ) session.getAttribute( sessionUserRole );
empresaId = ( String ) session.getAttribute( sessionEmpresaId );
estabelecimentoId = ( String ) session.getAttribute( sessionEstabelecimentoId );
trabalhadorId = ( String ) session.getAttribute( sessionTrabalhadorId );
Class.forName(super.bdDriver);
Class.forName( bdDriver );
con = DriverManager.getConnection( bdLocalUrl, bdLocalUsername, bdLocalPassword );
if ( ( userRole.equals ( super.superUserRole ) || userRole.equals ( empresaId ) )
&& super.verificaEstabelecimento(con, empresaId, estabelecimentoId)
&& super.verificaTrabalhador(con, estabelecimentoId, trabalhadorId) )
if ( ( userRole.equals( superUserRole ) || userRole.equals( empresaId ) ) && verificaEstabelecimento( con, empresaId, estabelecimentoId )
&& verificaTrabalhador( con, estabelecimentoId, trabalhadorId ) )
{
dbQuery = new StringBuffer();
dbQuery.append( " SELECT sexo, categoria, data_nascimento, nome, numero_mecanografico "
+ "FROM trabalhadores where id='"+trabalhadorId+"'");
stmt = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
rs = new ResultSet2DArray( stmt.executeQuery( dbQuery.toString()) );
dbQuery.append( " SELECT sexo, categoria, data_nascimento, nome, numero_mecanografico " + "FROM trabalhadores where id='" + trabalhadorId
+ "'" );
stmt = con.createStatement( ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY );
rs = new ResultSet2DArray( stmt.executeQuery( dbQuery.toString() ) );
HashMap hmFuncionario = new HashMap();
if( rs.columnLength() > 0 )
Map< String, Object > hmFuncionario = new HashMap< String, Object >();
if ( rs.columnLength() > 0 )
{
String tmp;
hmFuncionario.put( "sexo", rs.get( 0, "sexo" ) );
hmFuncionario.put( "categoria", rs.get( 0, "categoria" ) );
hmFuncionario.put( "data_nascimento", rs.get( 0, "data_nascimento" ) );
@ -69,13 +72,9 @@ public class doGetTrabalhador extends siprpServlet
hmFuncionario.put( "numero", rs.get( 0, "numero_mecanografico" ) );
stmt.close();
/** dados de exames **/
String queryUltimo = "select id, data, estado " +
"from marcacoes_trabalhador " +
"where deleted_stamp is null and tipo = 0 and estado = 2 and trabalhador_id = " + trabalhadorId +
" order by data desc " +
"limit 1";
String queryUltimo = "select id, data, estado " + "from marcacoes_trabalhador "
+ "where deleted_stamp is null and tipo = 0 and estado = 2 and trabalhador_id = " + trabalhadorId + " order by data desc " + "limit 1";
rs = executeQuery( con, queryUltimo );
java.util.Date dataUltimoExameRealizado = null;
@ -87,11 +86,9 @@ public class doGetTrabalhador extends siprpServlet
}
java.util.Date dataProximoExame = null;
String queryProximo = "select id, data, estado " +
"from marcacoes_trabalhador " +
"where deleted_stamp is null and tipo = 0 and estado != 2 and data >= now() and trabalhador_id = " + trabalhadorId + " " +
"order by data desc " +
"limit 1";
String queryProximo = "select id, data, estado " + "from marcacoes_trabalhador "
+ "where deleted_stamp is null and tipo = 0 and estado != 2 and data >= now() and trabalhador_id = " + trabalhadorId + " "
+ "order by data desc " + "limit 1";
rs = executeQuery( con, queryProximo );
if ( rs.columnLength() > 0 )
{
@ -101,114 +98,42 @@ public class doGetTrabalhador extends siprpServlet
hmFuncionario.put( "ultimo_exame", dataUltimoExameRealizado == null ? "" : dataUltimoExameRealizado );
hmFuncionario.put( "realizado", realizado );
hmFuncionario.put( "proximo_exame", dataProximoExame == null ? "" : dataProximoExame );
// String query = "SELECT id, data, estado, data_relatorio FROM marcacoes_trabalhador "
// + "WHERE tipo = 0 and trabalhador_id = " + trabalhadorId
// + " ORDER BY data DESC";
// stmt = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
// rs = new ResultSet2DArray( stmt.executeQuery( query ) );
// if( rs.columnLength() > 0 )
// {
// java.util.Date dataExame2 = ( java.util.Date ) rs.get( 0, 1 );
// Integer estado1;
// Integer estado2 = ( Integer ) rs.get( 0, 2 );
// java.util.Date dataExame1;
// String realizado1 = "";
// String realizado2 = "";
// if( rs.columnLength() > 1 )
// {
// dataExame1 = ( java.util.Date ) rs.get( 1, 1 );
// estado1 = ( Integer ) rs.get( 1, 2 );
// }
// else
// {
// dataExame1 = dataExame2;
// estado1 = estado2;
// }
// if( ESTADO_REALIZADO.equals( estado2 ) || ESTADO_PARCIALMENTE_REALIZADO.equals( estado2 )
// || today.after( dataExame2 ) )
// {
// hmFuncionario.put( "ultimo_exame", dataExame2 );
// if( estado2.equals( ESTADO_REALIZADO ) || estado2.equals( ESTADO_PARCIALMENTE_REALIZADO ) )
// {
// realizado2 = "sim";
// }
// else
// {
// realizado2 = "n&atilde;o";
// }
// hmFuncionario.put( "realizado", realizado2 );
// hmFuncionario.put( "proximo_exame", null );
// }
// else
// {
// hmFuncionario.put( "proximo_exame", dataExame2 );
// if( !dataExame2.equals( dataExame1 ) )
// {
// hmFuncionario.put( "ultimo_exame", dataExame1 );
// if( estado1.equals( ESTADO_REALIZADO ) || estado1.equals( ESTADO_PARCIALMENTE_REALIZADO ) )
// {
// realizado1 = "sim";
// }
// else
// {
// realizado1 = "n&atilde;o";
// }
// hmFuncionario.put( "realizado", realizado1 );
// }
// else
// {
// hmFuncionario.put( "ultimo_exame", null );
// hmFuncionario.put( "realizado", null );
// }
// }
// }
// else
// {
// hmFuncionario.put( "ultimo_exame", null );
// hmFuncionario.put( "realizado", null );
// hmFuncionario.put( "proximo_exame", null );
// }
// stmt.close();
/** eof dados exames **/
String query = "SELECT MAX(id) FROM exames WHERE trabalhador_id = " + trabalhadorId + " AND inactivo <> 'y'";
stmt = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
stmt = con.createStatement( ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY );
rs = new ResultSet2DArray( stmt.executeQuery( query ) );
Integer fichaId = null;
if( rs.columnLength() > 0 )
if ( rs.columnLength() > 0 )
{
fichaId = ( Integer ) rs.get( 0, 0 );
}
stmt.close();
if( fichaId != null )
if ( fichaId != null )
{
query = "SELECT data, resultado FROM exames WHERE id = " + fichaId;
stmt = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
stmt = con.createStatement( ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY );
rs = new ResultSet2DArray( stmt.executeQuery( query ) );
Integer resultadoFicha = (Integer) rs.get( 0, 1 );
Integer resultadoFicha = ( Integer ) rs.get( 0, 1 );
stmt.close();
if( resultadoFicha != null )
if ( resultadoFicha != null )
{
switch( resultadoFicha.intValue() )
switch ( resultadoFicha.intValue() )
{
case 1:
case 1 :
hmFuncionario.put( "resultado", "Apto" );
break;
case 2:
case 2 :
hmFuncionario.put( "resultado", "Apto Condicionalmente" );
break;
case 3:
case 3 :
hmFuncionario.put( "resultado", "Inapto Temporariamente" );
break;
case 4:
case 4 :
hmFuncionario.put( "resultado", "Inapto Definitivamente" );
break;
default:
default :
hmFuncionario.put( "resultado", null );
}
}
@ -222,13 +147,10 @@ public class doGetTrabalhador extends siprpServlet
hmFuncionario.put( "resultado", null );
}
/** consulta dados **/
String queryUltima = "select id, data, estado " +
"from marcacoes_trabalhador " +
"where deleted_stamp is null and tipo = 1 and estado = 2 and trabalhador_id = " + trabalhadorId + " " +
"order by data desc " +
"limit 1";
String queryUltima = "select id, data, estado " + "from marcacoes_trabalhador "
+ "where deleted_stamp is null and tipo = 1 and estado = 2 and trabalhador_id = " + trabalhadorId + " " + "order by data desc "
+ "limit 1";
rs = executeQuery( con, queryUltima );
java.util.Date dataUltimaConsultaRealizada = null;
@ -239,11 +161,9 @@ public class doGetTrabalhador extends siprpServlet
consultaRealizada = "Sim";
}
String queryProxima = "select id, data, estado " +
"from marcacoes_trabalhador " +
"where deleted_stamp is null and tipo = 1 and estado != 2 and data >= now() and trabalhador_id = " + trabalhadorId + " " +
"order by data desc " +
"limit 1";
String queryProxima = "select id, data, estado " + "from marcacoes_trabalhador "
+ "where deleted_stamp is null and tipo = 1 and estado != 2 and data >= now() and trabalhador_id = " + trabalhadorId + " "
+ "order by data desc " + "limit 1";
rs = executeQuery( con, queryProxima );
java.util.Date dataProximaConsulta = null;
@ -255,109 +175,19 @@ public class doGetTrabalhador extends siprpServlet
hmFuncionario.put( "ultima_consulta", dataUltimaConsultaRealizada == null ? "" : dataUltimaConsultaRealizada );
hmFuncionario.put( "realizada", consultaRealizada );
hmFuncionario.put( "proxima_consulta", dataProximaConsulta == null ? "" : dataProximaConsulta );
// query = "SELECT id, data, estado FROM marcacoes_trabalhador "
// + "WHERE tipo = 1 and trabalhador_id = " + trabalhadorId
// + " ORDER BY data DESC";
// stmt = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
// rs = new ResultSet2DArray( stmt.executeQuery( query ) );
// if( rs.columnLength() > 0 )
// {
// java.util.Date dataConsulta2 = ( java.util.Date ) rs.get( 0, 1 );
// Integer estado1;
// Integer estado2 = ( Integer ) rs.get( 0, 2 );
// java.util.Date dataConsulta1;
// String realizada1 = "";
// String realizada2 = "";
// if( rs.columnLength() >= 2 )
// {
// dataConsulta1 = ( java.util.Date ) rs.get( 1, 1 );
// estado1 = ( Integer ) rs.get( 1, 2 );
// }
// else
// {
// dataConsulta1 = dataConsulta2;
// estado1 = estado2;
// }
// if( ESTADO_REALIZADO.equals( estado2 ) || today.after( dataConsulta2 ) )
// {
// hmFuncionario.put( "ultima_consulta", dataConsulta2 );
// if( estado2.equals( ESTADO_REALIZADO ) )
// {
// realizada2 = "sim";
// }
// else
// {
// realizada2 = "n&atilde;o";
// }
// hmFuncionario.put( "realizada", realizada2 );
// hmFuncionario.put( "proxima_consulta", null );
// }
// else
// {
// try
// {
// for( int c = 1; c < rs.columnLength(); c++ )
// {
// java.util.Date dataTemp = ( java.util.Date ) rs.get( c, 1 );
// dataConsulta1 = dataTemp;
// estado1 = ( Integer ) rs.get( c, 2 );
// if( dataTemp.after( today ) )
// {
// dataConsulta2 = dataTemp;
// }
// else
// {
// break;
// }
// }
// }
// catch( Exception ex )
// {
// ex.printStackTrace();
// }
// hmFuncionario.put( "proxima_consulta", dataConsulta2 );
// if( !dataConsulta2.equals( dataConsulta1 ) )
// {
// if( estado1.equals( ESTADO_REALIZADO ) )
// {
// realizada1 = "sim";
// }
// else
// {
// realizada1 = "n&atilde;o";
// }
// hmFuncionario.put( "realizada", realizada1 );
// hmFuncionario.put( "ultima_consulta", dataConsulta1 );
// }
// else
// {
// hmFuncionario.put( "ultima_consulta", null );
// hmFuncionario.put( "realizada", null );
// }
// }
// }
// else
// {
// hmFuncionario.put( "ultima_consulta", null );
// hmFuncionario.put( "realizada", null );
// hmFuncionario.put( "proxima_consulta", null );
// }
// stmt.close();
/** eof consulta dados **/
}
sBuffer = new StringBuffer();
sBuffer.append("<b>"+super.nomeEmpresa(con,empresaId)+"</b><br><br><i>"
+super.nomeEstabelecimento(con, estabelecimentoId)+"</i>" );
sBuffer.append( "<b>" + nomeEmpresa( con, empresaId ) + "</b><br><br><i>" + nomeEstabelecimento( con, estabelecimentoId ) + "</i>" );
HashMap hmValues = new HashMap();
Map< String, Object > hmValues = new HashMap< String, Object >();
hmValues.put( "empresa_nome", session.getAttribute( sessionCompanyName ) );
hmValues.put( "empresa_id", session.getAttribute( sessionEmpresaId ) );
hmValues.put( "estabelecimento_nome", super.nomeEstabelecimento( con, estabelecimentoId ) );
hmValues.put( "estabelecimento_nome", nomeEstabelecimento( con, estabelecimentoId ) );
/*Dados para marcacao de consulta/exame*/
/* Dados para marcacao de consulta/exame */
session.setAttribute( "session_estabelecimento_nome", hmValues.get( "estabelecimento_nome" ) );
session.setAttribute( "session_funcionario_nome", hmFuncionario.get( "nome" ) );
session.setAttribute( "session_funcionario_numero", hmFuncionario.get( "numero" ) );
@ -365,33 +195,27 @@ public class doGetTrabalhador extends siprpServlet
hmValues.put( "estabelecimento_id", estabelecimentoId );
hmValues.put( "userRole", userRole );
hmValues.put( "userName", session.getAttribute( sessionUser ) );
hmValues.put( msgTemplate , sBuffer.toString() ) ;
hmValues.put( templateUserRole, userRole);
hmValues.put( templateQuery, super.queryStringTrabalhador );
hmValues.put( msgTemplate, sBuffer.toString() );
hmValues.put( templateUserRole, userRole );
hmValues.put( templateQuery, queryStringTrabalhador );
hmValues.put( "funcionario", hmFuncionario );
//hmValues.put( templateVector1,names);
//hmValues.put( templateVector2,values);
//hmValues.put( templateVector3,null);
out.println( mergeTemplate( hmValues, super.authenticatedUserTemplate));
// out.println( mergeTemplate( sBuffer.toString(), userRole, super.queryStringTrabalhador, names, values, null, super.authenticatedUserTemplate) );
out.println( mergeTemplate( hmValues, authenticatedUserTemplate ) );
}
else
{
out.println( mergeTemplate( super.msgLinkFormatError , userRole, super.errorTemplate) );
out.println( mergeTemplate( msgLinkFormatError, userRole, errorTemplate ) );
}
con.close();
}
catch ( SQLException e )
{
e.printStackTrace();
out.println( mergeTemplate( super.msgErroBd , super.errorTemplate) );
out.println( mergeTemplate( msgErroBd, errorTemplate ) );
}
catch ( Exception e )
{
e.printStackTrace();
out.println( mergeTemplate( super.msgGenericError , super.errorTemplate) );
out.println( mergeTemplate( msgGenericError, errorTemplate ) );
}
}

@ -1,89 +1,88 @@
package com.evolute.siprp.pagina;
import com.evolute.utils.arrays.*;
import com.evolute.utils.strings.*;
import java.io.*;
import java.util.*;
import java.sql.*;
import java.lang.reflect.Array;
import javax.servlet.*;
import javax.servlet.http.*;
import org.apache.velocity.*;
import org.apache.velocity.app.*;
import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.HashMap;
import java.util.Map;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import com.evolute.utils.arrays.ResultSet2DArray;
public class doPostLogin extends siprpServlet
{
private static final long serialVersionUID = 1L;
/** Creates a new instance of doPostLogin */
public doPostLogin(HttpServletRequest req, HttpServletResponse res) throws IOException
public doPostLogin( HttpServletRequest req, HttpServletResponse res ) throws IOException
{
System.out.println( "doPostLogin()" );
ServletOutputStream out = res.getOutputStream();
StringBuffer dbQuery;
ResultSet2DArray rs;
Connection con = null ;
Statement stmt = null ;
Connection con = null;
Statement stmt = null;
String user, userRole, password;
try
{
user = req.getParameter("user");
password = req.getParameter("password");
user = req.getParameter( "user" );
password = req.getParameter( "password" );
if (user.equals(""))
if ( user.equals( "" ) )
{
String msgErro = msgErroNoUser.replace( '+', ' ' );
out.println( mergeTemplate( msgErro, indexTemplate ) );
// out.println( mergeTemplate( msgErroNoUser, errorTemplate) );
}
else
{
Class.forName( bdDriver );
con = DriverManager.getConnection( bdUrl, bdUsername, bdPassword );
dbQuery = new StringBuffer();
dbQuery.append( "SELECT password FROM users WHERE username = '"+user+"'");
dbQuery.append( "SELECT password FROM users WHERE username = '" + user + "'" );
stmt = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
rs = new ResultSet2DArray( stmt.executeQuery( dbQuery.toString()) );
stmt = con.createStatement( ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY );
rs = new ResultSet2DArray( stmt.executeQuery( dbQuery.toString() ) );
if ( rs.columnLength() > 0 && password.equals((String)rs.get(0,0)))
if ( rs.columnLength() > 0 && password.equals( ( String ) rs.get( 0, 0 ) ) )
{
// Obter Role
dbQuery = new StringBuffer();
dbQuery.append( "SELECT role FROM roles WHERE username = '"+user+"'");
stmt = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
dbQuery.append( "SELECT role FROM roles WHERE username = '" + user + "'" );
stmt = con.createStatement( ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY );
rs = new ResultSet2DArray( stmt.executeQuery( dbQuery.toString()) );
userRole = (String)rs.get(0,0);
rs = new ResultSet2DArray( stmt.executeQuery( dbQuery.toString() ) );
userRole = ( String ) rs.get( 0, 0 );
// UPDATE HTTP SESSION
HttpSession session = req.getSession(true);
session.setMaxInactiveInterval(sessionTimeout);
HttpSession session = req.getSession( true );
session.setMaxInactiveInterval( sessionTimeout );
session.setAttribute(sessionUser, user);
session.setAttribute(sessionUserRole, userRole);
session.setAttribute(sessionPassword, password);
session.setAttribute( sessionUser, user );
session.setAttribute( sessionUserRole, userRole );
session.setAttribute( sessionPassword, password );
HashMap hmValues = new HashMap();
Map< String, Object > hmValues = new HashMap< String, Object >();
session.setAttribute( sessionEmpresaId, userRole );
if( userRole.equals( "manager" ) )
if ( userRole.equals( "manager" ) )
{
// session.setAttribute( sessionCompanyName, nomeEmpresa( con, "" + session.getAttribute( sessionEmpresaId ) ) );
session.setAttribute( sessionCompanyName, null );
session.setAttribute( sessionEstabelecimentoId, null );
//hmValues.put( templateQuery, super.queryStringEmpresas );
new doGetListaEmpresas( req, res );
}
else
{
session.setAttribute( sessionCompanyName,
nomeEmpresa( DriverManager.getConnection( bdLocalUrl, bdLocalUsername, bdLocalPassword ),
session.setAttribute( sessionCompanyName, nomeEmpresa( DriverManager.getConnection( bdLocalUrl, bdLocalUsername, bdLocalPassword ),
userRole ) );
session.setAttribute( sessionEstabelecimentoId, "-1" );
//hmValues.put( templateQuery, super.queryStringEstabelecimentos );
new doGetListaEstabelecimentos( req, res );
}
stmt.close();
@ -94,19 +93,13 @@ public class doPostLogin extends siprpServlet
hmValues.put( "estabelecimento_id", session.getAttribute( sessionEstabelecimentoId ) );
hmValues.put( "userRole", userRole );
hmValues.put( "userName", user );
//out.println( mergeTemplate( hmValues, super.authenticatedUserTemplate));
//out.println( mergeTemplate( user, userRole, super.authenticatedUserTemplate));
}
else
{
String msgErro = msgErroAuthFail.replace( '+', ' ' );
out.println( mergeTemplate( msgErro, indexTemplate ) );
// out.println( mergeTemplate( msgErroAuthFail, super.errorTemplate) );
}
}
}
catch ( SQLException e )
{
@ -119,7 +112,6 @@ public class doPostLogin extends siprpServlet
{
ex.printStackTrace();
}
// out.println( mergeTemplate( msgErroBd , super.errorTemplate) );
}
catch ( IllegalStateException e ) // session timeout
{
@ -132,7 +124,6 @@ public class doPostLogin extends siprpServlet
{
ex.printStackTrace();
}
// out.println( mergeTemplate(msgSessionTimeout, super.errorTemplate) );
}
catch ( Exception e )
{
@ -145,7 +136,6 @@ public class doPostLogin extends siprpServlet
{
ex.printStackTrace();
}
// out.println( mergeTemplate( msgGenericError , super.errorTemplate) );
}
}

@ -40,65 +40,66 @@ public class siprpServlet extends HttpServlet implements GlobalConstants
public static final String msgGenericError = "Erro";
public static final String msgListaEmpresas = "Empresas";
public static final String msgAcessoNegado = "Acesso+Negado.";
public static final String msgLinkFormatError ="URL+inv&aacute;lido.";
public static final String msgLinkFormatError = "URL+inv&aacute;lido.";
public static final String msgLogin = "Login";
public static final String msgNovaPasswordErrada="Erro+ao+criar+a+nova+password,+nova+password+inv&aacute;lida.";
public static final String msgNovaPasswordErrada = "Erro+ao+criar+a+nova+password,+nova+password+inv&aacute;lida.";
public static final String msgButtonNotSuported = "funcionalidade+ainda+n&atilde;o+suportada.";
public static final String msgSessionTimeout = "Por+raz&otilde;es+de+seguran&ccedil;a+o+tempo+da+sua+sess&atilde;o+expirou<br>"
+ "Por+favor+efectue+novamente+o+seu+login.<br>";
// Templates - Nomes e valores
//public static final String loginTemplate = "login.html";
// public static final String loginTemplate = "login.html";
public static final String indexTemplate = "index.html";
public static final String authenticatedUserTemplate = "user.html";
public static final String authenticatedUserPrintTemplate = "user_print.html";
public static final String errorTemplate = "erro.html";
// public static final String errorTemplate = "frame_erro.html";
// public static final String innerErrorTemplate = "erro.html";
// public static final String errorTemplate = "frame_erro.html";
// public static final String innerErrorTemplate = "erro.html";
public static final String mainTemplate = "main.html";
//public static final String criticalErrorTemplate = "critical.html";
public static final String templateVector1 ="v1";
public static final String templateVector2 ="v2";
public static final String templateVector3 ="v3";
public static final String templateUserRole ="userRole";
public static final String msgTemplate ="msg";
public static final String templateQuery ="query";
public static final String buttonPressedTemplate ="buttonPressed";
// public static final String criticalErrorTemplate = "critical.html";
public static final String templateVector1 = "v1";
public static final String templateVector2 = "v2";
public static final String templateVector3 = "v3";
public static final String templateUserRole = "userRole";
public static final String msgTemplate = "msg";
public static final String templateQuery = "query";
public static final String buttonPressedTemplate = "buttonPressed";
// Query Strings , usadas para na template do velocity saber o que mostar
public static final String queryStringErro = "erro";
public static final String queryStringEmpresas = "empresas";
public static final String queryStringEstabelecimentos="estabelecimentos";
public static final String queryStringTrabalhadores ="trabalhadores";
public static final String queryStringTrabalhador ="trabalhador";
public static final String queryStringEstabelecimentos = "estabelecimentos";
public static final String queryStringTrabalhadores = "trabalhadores";
public static final String queryStringTrabalhador = "trabalhador";
//Botoes, saber qual o botao escholido, campo value dos forms
// Botoes, saber qual o botao escholido, campo value dos forms
public static final String botaoLogin = "Entrar";
public static final String botaoMarcarProximoExame = "Marcar Exame";
// Var da Session
public static final String sessionUser="user";
public static final String sessionUserRole="userRole";
public static final String sessionPassword="password";
public static final String sessionEmpresaId="empresaId";
public static final String sessionEstabelecimentoId="estabelecimentoId";
public static final String sessionTrabalhadorId="trabalhadorId";
public static final String sessionUser = "user";
public static final String sessionUserRole = "userRole";
public static final String sessionPassword = "password";
public static final String sessionEmpresaId = "empresaId";
public static final String sessionEstabelecimentoId = "estabelecimentoId";
public static final String sessionTrabalhadorId = "trabalhadorId";
public static final String sessionCompanyName = "sessionCompanyName";
public static final String sessionCompanyEmail = "sessionCompanyEmail";
public static final int sessionTimeout = 3600; // segundos
public static final String servletName="siprpWeb";
public static final String superUserRole="manager";
public static final String servletName = "siprpWeb";
public static final String superUserRole = "manager";
// // BD
// public static final String bdHost = "127.0.0.1";
// public static final String bdPort = "5436";
// public static final String bdUsername = "siprp";
// public static final String bdPassword = "";
// public static final String bdDriver = "org.postgresql.Driver";
// public static final String bdUrl = "jdbc:postgresql://" + bdHost + ":" + bdPort + "/siprp";
// // BD
// public static final String bdHost = "127.0.0.1";
// public static final String bdPort = "5436";
// public static final String bdUsername = "siprp";
// public static final String bdPassword = "";
// public static final String bdDriver = "org.postgresql.Driver";
// public static final String bdUrl = "jdbc:postgresql://" + bdHost + ":" +
// bdPort + "/siprp";
public static final String bdEmpresaIdRef = "id"; // campo que contem id da empresa
public static final String bdEmpresaNomeRef = "designacao_social"; // campo que contem nome da empresa
@ -112,97 +113,100 @@ public class siprpServlet extends HttpServlet implements GlobalConstants
protected static ServletContext CONTEXT;
// Arrays
public static final String[][] trabalhadorDescFields = new String [][]
{ // nome que o user ve, nome do campo na tabela
{"Nome", "nome"},
{"N\u00ba", "numero_mecanografico",},
{"\u00DAltimo Exame", "ultimo_exame"},
{"Realizado", "realizado"},
{"Pr\u00F3ximo Exame", "proximo_exame"},
{"\u00DAltima Consulta", "ultima_consulta"},
{"Realizada", "realizada"},
{"Pr\u00F3xima Consulta", "proxima_consulta"}
};
// nome que o user ve, nome do campo na tabela
public static final String[][] trabalhadorDescFields = new String[][] {
{ "Nome", "nome" }, { "N\u00ba", "numero_mecanografico", }, { "\u00DAltimo Exame", "ultimo_exame" }, { "Realizado", "realizado" },
{ "Pr\u00F3ximo Exame", "proximo_exame" }, { "\u00DAltima Consulta", "ultima_consulta" }, { "Realizada", "realizada" },
{ "Pr\u00F3xima Consulta", "proxima_consulta" } };
public void init()
{
try {
try
{
CONTEXT = this.getServletContext();
String TEMPLATE_DIR = this.getServletContext().getRealPath( "/" ) + "html/";
System.out.println( "DIR: " + TEMPLATE_DIR );
System.out.println( "DIR: " + TEMPLATE_DIR );
Properties props = new Properties();
props.setProperty( "file.resource.loader.path", TEMPLATE_DIR );
Velocity.init( props );
Class.forName(bdDriver);
Class.forName( bdDriver );
}
catch( Exception e )
catch ( Exception e )
{
e.printStackTrace();
}
}
public void doGet( HttpServletRequest req, HttpServletResponse res )
throws IOException
public void doGet( HttpServletRequest req, HttpServletResponse res ) throws IOException
{
String queryString = req.getQueryString();
String backUri = req.getRequestURI();
ServletOutputStream out = res.getOutputStream();
// res.setContentType( "text/html" );
// res.setContentType( "text/html" );
res.setContentType( "text/html" );
try
{
System.out.println( "query: " + queryString );
HttpSession session = req.getSession(true);
session.setMaxInactiveInterval(sessionTimeout);
System.out.println( "query: " + queryString );
HttpSession session = req.getSession( true );
session.setMaxInactiveInterval( sessionTimeout );
if ( queryString == null ) // Reload, 1a vez, etc ...
{
session.invalidate();
out.println( mergeTemplate ( "", indexTemplate ) ) ;
out.println( mergeTemplate( "", indexTemplate ) );
}
else if ( session.isNew() && !( queryString.indexOf(queryStringErro) == 0 ) ) // session timeout
else if ( session.isNew() && !( queryString.indexOf( queryStringErro ) == 0 ) ) // session
// timeout
{
session.invalidate();
String msgErro = msgSessionTimeout.replace( '+', ' ' );
out.println( mergeTemplate( msgErro, indexTemplate ) );
// doErro(queryString, out);
// doErro(queryString, out);
}
else if ( queryString.equals(queryStringEmpresas) ) // Listar Empresas
else if ( queryString.equals( queryStringEmpresas ) ) // Listar
// Empresas
{
new doGetListaEmpresas(req,res);
new doGetListaEmpresas( req, res );
}
else if ( queryString.indexOf(queryStringErro) == 0 ) // Listar Empresas
else if ( queryString.indexOf( queryStringErro ) == 0 ) // Listar
// Empresas
{
// System.out.println( "entrou" );
doErro(queryString, out);
// System.out.println( "entrou" );
doErro( queryString, out );
}
else // interpretar query string
else
// interpretar query string
{
String empresa = null, estabelecimento=null, trabalhador=null;
String empresa = null, estabelecimento = null, trabalhador = null;
String query = null;
int checkInt;
StringTokenizer sToken = new StringTokenizer(queryString,"/") ;
StringTokenizer sToken = new StringTokenizer( queryString, "/" );
empresa = sToken.nextToken(); // empresa ID
checkInt = Integer.parseInt(empresa); // check int, NumberFormatException
checkInt = Integer.parseInt( empresa ); // check int,
// NumberFormatException
if (sToken.hasMoreElements())
if ( sToken.hasMoreElements() )
{
estabelecimento = sToken.nextToken(); // estabelecimento ID
checkInt = Integer.parseInt(estabelecimento); // check int, NumberFormatException
if (sToken.hasMoreElements())
checkInt = Integer.parseInt( estabelecimento ); // check
// int,
// NumberFormatException
if ( sToken.hasMoreElements() )
{
trabalhador = sToken.nextToken(); // trabalhador ID
try
{
checkInt = Integer.parseInt(trabalhador); // check int, NumberFormatException
checkInt = Integer.parseInt( trabalhador ); // check
// int,
// NumberFormatException
}
catch( NumberFormatException nfex )
catch ( NumberFormatException nfex )
{
query = trabalhador;
if( query.indexOf( "trabalhadores_tudo" ) != 0 && query.indexOf( "trabalhadores_pendentes" ) != 0 &&
query.indexOf( "_print" ) == -1 )
if ( query.indexOf( "trabalhadores_tudo" ) != 0 && query.indexOf( "trabalhadores_pendentes" ) != 0
&& query.indexOf( "_print" ) == -1 )
{
throw nfex;
}
@ -212,141 +216,143 @@ System.out.println( "query: " + queryString );
if ( estabelecimento == null ) // empresa query
{
session.setAttribute(sessionEmpresaId, empresa); // update HTTP Session
session.setAttribute( sessionEmpresaId, empresa ); // update
// HTTP
// Session
new doGetListaEstabelecimentos(req,res);
new doGetListaEstabelecimentos( req, res );
//out.println( mergeTemplate ( empresa, loginTemplate ) ) ;
// out.println( mergeTemplate ( empresa, loginTemplate ) ) ;
}
else if ( trabalhador == null || query != null ) // estabelecimento query
else if ( trabalhador == null || query != null ) // estabelecimento
// query
{
session.setAttribute(sessionEmpresaId, empresa); // update HTTP Session
session.setAttribute(sessionEstabelecimentoId, estabelecimento);
session.setAttribute( sessionEmpresaId, empresa ); // update
// HTTP
// Session
session.setAttribute( sessionEstabelecimentoId, estabelecimento );
new doGetListaTrabalhadores(req,res, query);
new doGetListaTrabalhadores( req, res, query );
//out.println( mergeTemplate ( " chama oGetListaTrabalhadores", loginTemplate ) ) ;
// out.println( mergeTemplate (
// " chama oGeHashtabletListaTrabalhadores", loginTemplate )
// ) ;
}
else // trabalhador query
else
// trabalhador query
{
session.setAttribute(sessionEmpresaId, empresa); // update HTTP Session
session.setAttribute(sessionEstabelecimentoId, estabelecimento);
session.setAttribute(sessionTrabalhadorId, trabalhador);
session.setAttribute( sessionEmpresaId, empresa ); // update
// HTTP
// Session
session.setAttribute( sessionEstabelecimentoId, estabelecimento );
session.setAttribute( sessionTrabalhadorId, trabalhador );
new doGetTrabalhador(req,res);
new doGetTrabalhador( req, res );
//out.println( mergeTemplate ( trabalhador, loginTemplate ) ) ;
// out.println( mergeTemplate ( trabalhador, loginTemplate )
// ) ;
}
}
}
catch ( NumberFormatException e ) // argumentos invalidos
{
e.printStackTrace();
out.println( mergeTemplate( msgLinkFormatError, backUri, errorTemplate) );
out.println( mergeTemplate( msgLinkFormatError, backUri, errorTemplate ) );
}
catch ( IllegalStateException e ) // session timeout
{
e.printStackTrace();
out.println( mergeTemplate(msgSessionTimeout, errorTemplate) );
out.println( mergeTemplate( msgSessionTimeout, errorTemplate ) );
}
catch ( Exception e )
{
e.printStackTrace();
// out.println( mergeTemplate( msgGenericError , backUri, errorTemplate ) );
out.println( mergeTemplate( msgGenericError , errorTemplate ) );
// out.println( mergeTemplate( msgGenericError , backUri,
// errorTemplate ) );
out.println( mergeTemplate( msgGenericError, errorTemplate ) );
}
// System.out.println( "fim - " + queryString + " bu " + backUri );
// System.out.println( "fim - " + queryString + " bu " + backUri );
}
public void doPost(HttpServletRequest req, HttpServletResponse res)
throws IOException
public void doPost( HttpServletRequest req, HttpServletResponse res ) throws IOException
{
ServletOutputStream out = res.getOutputStream();
//StringBuffer dbQuery;
//ResultSet2DArray rs;
//Connection con = null ;
//Statement stmt = null ;
//String user, userRole, password;
String buttonPressed = req.getParameter("form");
// StringBuffer dbQuery;
// ResultSet2DArray rs;
// Connection con = null ;
// Statement stmt = null ;
// String user, userRole, password;
String buttonPressed = req.getParameter( "form" );
res.setContentType( "text/html" );
try
{
if ( buttonPressed.equals(botaoLogin))
if ( buttonPressed.equals( botaoLogin ) )
{
new doPostLogin(req,res);
new doPostLogin( req, res );
}
else
{
out.println( mergeTemplate( msgButtonNotSuported, errorTemplate) );
out.println( mergeTemplate( msgButtonNotSuported, errorTemplate ) );
}
}
/*catch ( SQLException e )
{
e.printStackTrace();
out.println( mergeTemplate( msgErroBd , criticalErrorTemplate) );
}*/
/*
* catch ( SQLException e ) { e.printStackTrace(); out.println(
* mergeTemplate( msgErroBd , criticalErrorTemplate) ); }
*/
catch ( IllegalStateException e ) // session timeout
{
e.printStackTrace();
out.println( mergeTemplate(msgSessionTimeout, errorTemplate) );
out.println( mergeTemplate( msgSessionTimeout, errorTemplate ) );
}
catch ( Exception e )
{
e.printStackTrace();
out.println( mergeTemplate( msgGenericError , errorTemplate) );
out.println( mergeTemplate( msgGenericError, errorTemplate ) );
}
}
public String mergeTemplate( Map values, String template )
public String mergeTemplate( Map< String, Object > values, String template )
{
VelocityContext context = new VelocityContext();
StringWriter output = new StringWriter();
try
{
for( Iterator i = values.keySet().iterator(); i.hasNext(); )
Iterator< String > it = values.keySet().iterator();
while ( it.hasNext() )
{
String key = ( String ) i.next();
context.put ( key, values.get( key ) ) ;
//fpalma
// Object value = values.get( key );
// context.put ( key, value != null ?
// UnicodeChecker.parseToUnicode( "&#x", 2, ";", value.toString(), true )
// : null );
String key = it.next();
context.put( key, values.get( key ) );
}
Velocity.mergeTemplate(template, Velocity.ENCODING_DEFAULT, context, output );
Velocity.mergeTemplate( template, Velocity.ENCODING_DEFAULT, context, output );
return output.toString();
}
catch( Exception e )
catch ( Exception e )
{
e.printStackTrace();
}
return null;
}
public String mergeTemplate (String msg, String template ) // #1
public String mergeTemplate( String msg, String template ) // #1
{
VelocityContext context = new VelocityContext();
StringWriter output = new StringWriter();
try
{
context.put ( msgTemplate , msg ) ;
Velocity.mergeTemplate(template, Velocity.ENCODING_DEFAULT, context, output );
context.put( msgTemplate, msg );
Velocity.mergeTemplate( template, Velocity.ENCODING_DEFAULT, context, output );
return output.toString();
}
catch( Exception e )
catch ( Exception e )
{
e.printStackTrace();
}
return null;
}
public String mergeTemplate (String msg, String userRole, String template ) // #1
public String mergeTemplate( String msg, String userRole, String template ) // #1
{
VelocityContext context = new VelocityContext();
@ -354,36 +360,35 @@ System.out.println( "query: " + queryString );
try
{
context.put ( msgTemplate , msg ) ;
context.put ( templateUserRole, userRole);
Velocity.mergeTemplate(template, Velocity.ENCODING_DEFAULT, context, output );
context.put( msgTemplate, msg );
context.put( templateUserRole, userRole );
Velocity.mergeTemplate( template, Velocity.ENCODING_DEFAULT, context, output );
return output.toString();
}
catch( Exception e )
catch ( Exception e )
{
e.printStackTrace();
}
return null;
}
public String mergeTemplate ( String msg, String userRole, String querySelected, Vector vector1, Vector vector2, Vector vector3, String template ) // #2
public String mergeTemplate( String msg, String userRole, String querySelected, Vector vector1, Vector vector2, Vector vector3, String template ) // #2
{
VelocityContext context = new VelocityContext();
StringWriter output = new StringWriter();
try
{
context.put ( msgTemplate , msg ) ;
context.put ( templateUserRole, userRole);
context.put ( templateQuery, querySelected );
context.put ( templateVector1,vector1);
context.put ( templateVector2,vector2);
context.put ( templateVector3,vector3);
Velocity.mergeTemplate(template, Velocity.ENCODING_DEFAULT, context, output );
context.put( msgTemplate, msg );
context.put( templateUserRole, userRole );
context.put( templateQuery, querySelected );
context.put( templateVector1, vector1 );
context.put( templateVector2, vector2 );
context.put( templateVector3, vector3 );
Velocity.mergeTemplate( template, Velocity.ENCODING_DEFAULT, context, output );
return output.toString();
}
catch( Exception e )
catch ( Exception e )
{
e.printStackTrace();
}
@ -394,47 +399,47 @@ System.out.println( "query: " + queryString );
{
}
public void handleSessionTimeout(HttpServletResponse res, String template)
throws IOException
public void handleSessionTimeout( HttpServletResponse res, String template ) throws IOException
{
ServletOutputStream out = res.getOutputStream();
try
{
out.println( mergeTemplate( msgSessionTimeout, template) );
out.println( mergeTemplate( msgSessionTimeout, template ) );
}
catch ( Exception e )
{
e.printStackTrace();
}
}
public boolean verificaEstabelecimento(Connection con, java.lang.String empresaId, java.lang.String estabelecimentoId)
public boolean verificaEstabelecimento( Connection con, java.lang.String empresaId, java.lang.String estabelecimentoId )
// verifica se o establecimento pertence 'a empresa
{
//Connection con = null ;
Statement stmt = null ;
// Connection con = null ;
Statement stmt = null;
Virtual2DArray rs;
String query;
try
{
//con = DriverManager.getConnection( bdUrl, bdUsername, bdPassword );
query = "SELECT empresa_id FROM estabelecimentos where id='"+estabelecimentoId+"'";
if( con != null )
// con = DriverManager.getConnection( bdUrl, bdUsername, bdPassword
// );
query = "SELECT empresa_id FROM estabelecimentos where id='" + estabelecimentoId + "'";
if ( con != null )
{
stmt = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
stmt = con.createStatement( ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY );
rs = new ResultSet2DArray( stmt.executeQuery( query ) );
}
else
{
rs = getExecuter().executeQuery( new Select( query ) );
}
String temp=""+rs.get(0,0); // converter de int para String
if( con != null )
String temp = "" + rs.get( 0, 0 ); // converter de int para String
if ( con != null )
{
stmt.close();
}
if ( empresaId.equals(temp) ) // estabelecimento pertence 'a empresa
if ( empresaId.equals( temp ) ) // estabelecimento pertence 'a
// empresa
{
return true;
}
@ -450,23 +455,25 @@ System.out.println( "query: " + queryString );
return false;
}
public boolean verificaTrabalhador(Connection con, java.lang.String estabelecimentoId, java.lang.String trabalhadorId)
public boolean verificaTrabalhador( Connection con, java.lang.String estabelecimentoId, java.lang.String trabalhadorId )
// verifica se o trabalhador pertence ao estabelecimento
{
//Connection con = null ;
Statement stmt = null ;
// Connection con = null ;
Statement stmt = null;
ResultSet2DArray rs;
StringBuffer dbQuery;
try
{
//con = DriverManager.getConnection( bdUrl, bdUsername, bdPassword );
// con = DriverManager.getConnection( bdUrl, bdUsername, bdPassword
// );
dbQuery = new StringBuffer();
dbQuery.append( "SELECT estabelecimento_id FROM trabalhadores where id='"+trabalhadorId+"'");
stmt = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
rs = new ResultSet2DArray( stmt.executeQuery( dbQuery.toString()) );
String temp=""+rs.get(0,0); // converter de int para String
dbQuery.append( "SELECT estabelecimento_id FROM trabalhadores where id='" + trabalhadorId + "'" );
stmt = con.createStatement( ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY );
rs = new ResultSet2DArray( stmt.executeQuery( dbQuery.toString() ) );
String temp = "" + rs.get( 0, 0 ); // converter de int para String
stmt.close();
if ( estabelecimentoId.equals(temp) ) // estabelecimento pertence 'a empresa
if ( estabelecimentoId.equals( temp ) ) // estabelecimento pertence
// 'a empresa
{
return true;
}
@ -482,11 +489,12 @@ System.out.println( "query: " + queryString );
return false;
}
public void closeSqlCon(Connection con)
public void closeSqlCon( Connection con )
{
try
{
if (con != null ) con.close();
if ( con != null )
con.close();
}
catch ( Exception e )
{
@ -495,9 +503,9 @@ System.out.println( "query: " + queryString );
}
public String emailEmpresa(Connection con, String empresaId)
public String emailEmpresa( Connection con, String empresaId )
{
Statement stmt = null ;
Statement stmt = null;
ResultSet2DArray rs;
StringBuffer dbQuery;
String returnString;
@ -505,13 +513,12 @@ System.out.println( "query: " + queryString );
try
{
dbQuery = new StringBuffer();
dbQuery.append( "SELECT email FROM empresas, contactos "
+ "WHERE empresas.id ='"+empresaId+"' AND empresas.contacto_1 = contactos.id");
stmt = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
rs = new ResultSet2DArray( stmt.executeQuery( dbQuery.toString()) );
if( rs.columnLength() > 0 )
dbQuery.append( "SELECT email FROM empresas, contactos " + "WHERE empresas.id ='" + empresaId + "' AND empresas.contacto_1 = contactos.id" );
stmt = con.createStatement( ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY );
rs = new ResultSet2DArray( stmt.executeQuery( dbQuery.toString() ) );
if ( rs.columnLength() > 0 )
{
returnString = (String)rs.get(0,0);
returnString = ( String ) rs.get( 0, 0 );
stmt.close();
return returnString;
}
@ -527,28 +534,28 @@ System.out.println( "query: " + queryString );
return null;
}
public String nomeEmpresa(Connection con, String empresaId)
public String nomeEmpresa( Connection con, String empresaId )
{
Statement stmt = null ;
Statement stmt = null;
Virtual2DArray rs;
String returnString;
try
{
String query = "SELECT designacao_social FROM empresas WHERE id ='"+empresaId+"'";
if( con != null )
String query = "SELECT designacao_social FROM empresas WHERE id ='" + empresaId + "'";
if ( con != null )
{
stmt = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
stmt = con.createStatement( ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY );
rs = new ResultSet2DArray( stmt.executeQuery( query ) );
}
else
{
rs = getExecuter().executeQuery( new Select( query ) );
}
if( rs.columnLength() > 0 )
if ( rs.columnLength() > 0 )
{
returnString = (String)rs.get(0,0);
if( con != null )
returnString = ( String ) rs.get( 0, 0 );
if ( con != null )
{
stmt.close();
}
@ -566,29 +573,29 @@ System.out.println( "query: " + queryString );
return null;
}
public String nomeEstabelecimento(Connection con, java.lang.String estabelecimentoId)
public String nomeEstabelecimento( Connection con, java.lang.String estabelecimentoId )
{
Statement stmt = null ;
Statement stmt = null;
Virtual2DArray rs;
StringBuffer dbQuery;
String returnString;
try
{
String query = "SELECT nome FROM estabelecimentos WHERE id ='"+estabelecimentoId+"'";
if( con != null )
String query = "SELECT nome FROM estabelecimentos WHERE id ='" + estabelecimentoId + "'";
if ( con != null )
{
stmt = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
stmt = con.createStatement( ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY );
rs = new ResultSet2DArray( stmt.executeQuery( query ) );
}
else
{
rs = getExecuter().executeQuery( new Select( query ) );
}
if( rs.columnLength() > 0 )
if ( rs.columnLength() > 0 )
{
returnString = (String)rs.get(0,0);
if( con != null )
returnString = ( String ) rs.get( 0, 0 );
if ( con != null )
{
stmt.close();
}
@ -606,9 +613,9 @@ System.out.println( "query: " + queryString );
return null;
}
public String nomeTrabalhador(Connection con, java.lang.String trabalhadorId)
public String nomeTrabalhador( Connection con, java.lang.String trabalhadorId )
{
Statement stmt = null ;
Statement stmt = null;
ResultSet2DArray rs;
StringBuffer dbQuery;
String returnString;
@ -616,12 +623,12 @@ System.out.println( "query: " + queryString );
try
{
dbQuery = new StringBuffer();
dbQuery.append( "SELECT nome FROM trabalhadores where id='"+trabalhadorId+"'");
stmt = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
rs = new ResultSet2DArray( stmt.executeQuery( dbQuery.toString()) );
if( rs.columnLength() > 0 )
dbQuery.append( "SELECT nome FROM trabalhadores where id='" + trabalhadorId + "'" );
stmt = con.createStatement( ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY );
rs = new ResultSet2DArray( stmt.executeQuery( dbQuery.toString() ) );
if ( rs.columnLength() > 0 )
{
returnString = (String)rs.get(0,0);
returnString = ( String ) rs.get( 0, 0 );
stmt.close();
return returnString;
}
@ -637,12 +644,11 @@ System.out.println( "query: " + queryString );
return null;
}
public void doErro( String queryString, ServletOutputStream out )
throws Exception
public void doErro( String queryString, ServletOutputStream out ) throws Exception
{
String split[] = queryString.split( "=" );
String err;
if( split.length > 1 )
if ( split.length > 1 )
{
err = split[ 1 ];
}
@ -651,21 +657,19 @@ System.out.println( "query: " + queryString );
err = "Erro";
}
err = err.replace( '+', ' ' );
// out.println( mergeTemplate( err, innerErrorTemplate) );
// out.println( mergeTemplate( err, innerErrorTemplate) );
out.println( mergeTemplate( err, errorTemplate ) );
}
protected Executer getExecuter()
throws Exception
protected Executer getExecuter() throws Exception
{
ServletContext context = CONTEXT;
DBManager dbm = ( DBManager ) context.getAttribute( Singleton.DEFAULT_DBMANAGER );
if( dbm == null )
if ( dbm == null )
{
dbm = new JDBCManager( bdLocalUrl, bdLocalUsername, bdLocalPassword , 500, 499, 1, null );
dbm = new JDBCManager( bdLocalUrl, bdLocalUsername, bdLocalPassword, 500, 499, 1, null );
context.setAttribute( Singleton.DEFAULT_DBMANAGER, dbm );
}
return dbm.getSharedExecuter( this );
}
}

Loading…
Cancel
Save