diff --git a/trunk/siprpWeb/dependenciesCache/dependencies.txt b/trunk/siprpWeb/dependenciesCache/dependencies.txt
index 26da37da..70089ba0 100644
--- a/trunk/siprpWeb/dependenciesCache/dependencies.txt
+++ b/trunk/siprpWeb/dependenciesCache/dependencies.txt
@@ -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
diff --git a/trunk/siprpWeb/src/com/evolute/siprp/pagina/GlobalConstants.java b/trunk/siprpWeb/src/com/evolute/siprp/pagina/GlobalConstants.java
index 9f1f87db..f66da726 100644
--- a/trunk/siprpWeb/src/com/evolute/siprp/pagina/GlobalConstants.java
+++ b/trunk/siprpWeb/src/com/evolute/siprp/pagina/GlobalConstants.java
@@ -6,7 +6,6 @@
package com.evolute.siprp.pagina;
-import java.util.Map;
/**
*
diff --git a/trunk/siprpWeb/src/com/evolute/siprp/pagina/NewsServlet.java b/trunk/siprpWeb/src/com/evolute/siprp/pagina/NewsServlet.java
index 5e5bd27e..db34801d 100644
--- a/trunk/siprpWeb/src/com/evolute/siprp/pagina/NewsServlet.java
+++ b/trunk/siprpWeb/src/com/evolute/siprp/pagina/NewsServlet.java
@@ -6,40 +6,50 @@
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
+ *
+ * @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;
-
+
private static boolean velocityInit = false;
-
+
public void init()
{
- if( !velocityInit )
+ if ( !velocityInit )
{
try
{
@@ -49,29 +59,28 @@ 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();
}
}
-
+
private void close()
{
try
@@ -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();
}
diff --git a/trunk/siprpWeb/src/com/evolute/siprp/pagina/doGetListaEmpresas.java b/trunk/siprpWeb/src/com/evolute/siprp/pagina/doGetListaEmpresas.java
index 9d572739..7d766746 100644
--- a/trunk/siprpWeb/src/com/evolute/siprp/pagina/doGetListaEmpresas.java
+++ b/trunk/siprpWeb/src/com/evolute/siprp/pagina/doGetListaEmpresas.java
@@ -1,119 +1,124 @@
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
{
-
- public doGetListaEmpresas( HttpServletRequest req, HttpServletResponse res ) throws IOException
- {
- ServletOutputStream out = res.getOutputStream();
- 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;
- try
- {
- userRole = (String)session.getAttribute(super.sessionUserRole);
-empresa_nome = ( String ) session.getAttribute( sessionCompanyName );
+ private static final long serialVersionUID = 1L;
+
+ public doGetListaEmpresas( HttpServletRequest req, HttpServletResponse res ) throws IOException
+ {
+ ServletOutputStream out = res.getOutputStream();
+ Connection con = null;
+ Statement stmt = null;
+ ResultSet2DArray rs;
+ StringBuffer dbQuery;
+ 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( sessionUserRole );
+ empresa_nome = ( String ) session.getAttribute( sessionCompanyName );
+
+ if ( userRole == null )
+ {
+ throw new IllegalStateException();
+ }
- if (userRole == null)
- {
- throw new IllegalStateException();
- }
-
- if ( userRole.equals ( super.superUserRole ) )
- {
-empresa_nome = null;
- Class.forName(super.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()) );
-
- int index=0;
- int max = rs.columnLength();
+ if ( userRole.equals( superUserRole ) )
+ {
+ 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() ) );
- while ( index < max )
- {
- String str = (String)rs.get(index,1);
- if( str != null && str.trim().length() > 0 )
- {
- 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));
- }
- ++index;
- }
- stmt.close();
- con.close();
+ int index = 0;
+ int max = rs.columnLength();
+ while ( index < max )
+ {
+ String str = ( String ) rs.get( index, 1 );
+ if ( str != null && str.trim().length() > 0 )
+ {
+ temp = "" + rs.get( index, 0 ); // converter de int para
+ // String
+ dbQuery = new StringBuffer();
+ 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) );
- }
+ }
+ else
+ {
+ out.println( mergeTemplate( msgAcessoNegado, userRole, errorTemplate ) );
+ }
+ }
+ catch ( IllegalStateException e ) // session timeout
+ {
+ e.printStackTrace();
+ out.println( mergeTemplate( msgSessionTimeout, errorTemplate ) );
+ }
+ catch ( SQLException e )
+ {
+ e.printStackTrace();
+ out.println( mergeTemplate( msgErroBd, errorTemplate ) );
+ }
+ catch ( Exception e )
+ {
+ e.printStackTrace();
+ out.println( mergeTemplate( msgGenericError, userRole, errorTemplate ) );
+ }
+ }
- }
- catch ( IllegalStateException e ) // session timeout
- {
- e.printStackTrace();
- out.println( mergeTemplate(msgSessionTimeout, super.errorTemplate) );
- }
- catch ( SQLException e )
- {
- e.printStackTrace();
- out.println( mergeTemplate( super.msgErroBd , super.errorTemplate) );
- }
- catch ( Exception e )
- {
- e.printStackTrace();
- out.println( mergeTemplate( super.msgGenericError , userRole, super.errorTemplate) );
- }
- }
-
}
diff --git a/trunk/siprpWeb/src/com/evolute/siprp/pagina/doGetListaEstabelecimentos.java b/trunk/siprpWeb/src/com/evolute/siprp/pagina/doGetListaEstabelecimentos.java
index 0050e732..0d080c93 100644
--- a/trunk/siprpWeb/src/com/evolute/siprp/pagina/doGetListaEstabelecimentos.java
+++ b/trunk/siprpWeb/src/com/evolute/siprp/pagina/doGetListaEstabelecimentos.java
@@ -1,105 +1,119 @@
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{
-
- /** Creates a new instance of doGetListaEstabelecimentos */
- public doGetListaEstabelecimentos(HttpServletRequest req, HttpServletResponse res) throws IOException
- {
- ServletOutputStream out = res.getOutputStream();
- 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();
- try
- {
- userRole = (String)session.getAttribute(super.sessionUserRole);
- empresaId = (String)session.getAttribute(super.sessionEmpresaId);
-
- if ( userRole.equals ( super.superUserRole ) || userRole.equals ( empresaId ) )
- {
- Class.forName(super.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()) );
-
- int index=0;
- int max = rs.columnLength();
-
- while ( index < max )
- {
- 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));
- ++index;
- }
- sBuffer = new StringBuffer();
- sBuffer.append(""+super.nomeEmpresa(con,empresaId)+"");
+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 doGetListaEstabelecimentos extends siprpServlet
-if( userRole.equals( "manager" ) )
-{
- session.setAttribute( sessionCompanyName, nomeEmpresa( con, ( String ) session.getAttribute( sessionEmpresaId ) ) );
-}
-else
{
- session.setAttribute( sessionCompanyName, nomeEmpresa( con, userRole ) );
-}
+ private static final long serialVersionUID = 1L;
+
+ public doGetListaEstabelecimentos( HttpServletRequest req, HttpServletResponse res ) throws IOException
+ {
+ ServletOutputStream out = res.getOutputStream();
+ Connection con = null;
+ Statement stmt = null;
+ ResultSet2DArray rs;
+ StringBuffer dbQuery, sBuffer;
+ String userRole, empresaId, temp;
+ HttpSession session = req.getSession( false );
+ List< String > links = new LinkedList< String >();
+ List< String > desc = new LinkedList< String >();
+ try
+ {
+ userRole = ( String ) session.getAttribute( sessionUserRole );
+ empresaId = ( String ) session.getAttribute( sessionEmpresaId );
+
+ if ( userRole.equals( superUserRole ) || userRole.equals( empresaId ) )
+ {
+ 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() ) );
+
+ int index = 0;
+ int max = rs.columnLength();
+
+ while ( index < max )
+ {
+ temp = "" + rs.get( index, 0 ); // converter de int para
+ // String
+ dbQuery = new StringBuffer();
+ dbQuery.append( "/" + servletName + "/?" + empresaId + "/" + temp ); // contruir
+ // url
+ links.add( dbQuery.toString() );
+ desc.add( ( String ) rs.get( index, 1 ) );
+ ++index;
+ }
+ sBuffer = new StringBuffer();
+ sBuffer.append( "" + super.nomeEmpresa( con, empresaId ) + "" );
+
+ if ( userRole.equals( "manager" ) )
+ {
+ session.setAttribute( sessionCompanyName, nomeEmpresa( con, ( String ) session.getAttribute( sessionEmpresaId ) ) );
+ }
+ else
+ {
+ session.setAttribute( sessionCompanyName, nomeEmpresa( con, userRole ) );
+ }
+
+ session.setAttribute( sessionCompanyEmail, emailEmpresa( con, empresaId ) );
+
+ session.setAttribute( sessionEstabelecimentoId, null );
-session.setAttribute( sessionCompanyEmail, emailEmpresa( con, empresaId ) );
+ 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 ) );
-session.setAttribute( sessionEstabelecimentoId, null );
+ // out.println( mergeTemplate( sBuffer.toString(), userRole,
+ // super.queryStringEstabelecimentos, links, desc, null,
+ // super.authenticatedUserTemplate) );
+ stmt.close();
+ con.close();
+ }
+ else
+ {
+ out.println( mergeTemplate( msgAcessoNegado, userRole, errorTemplate ) );
+ }
+ }
+ catch ( SQLException e )
+ {
+ e.printStackTrace();
+ out.println( mergeTemplate( msgErroBd, errorTemplate ) );
+ }
+ catch ( Exception e )
+ {
+ e.printStackTrace();
+ out.println( mergeTemplate( msgGenericError, errorTemplate ) );
+ }
+ }
-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));
-
-// 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) );
- }
- }
- catch ( SQLException e )
- {
- e.printStackTrace();
- out.println( mergeTemplate( super.msgErroBd , super.errorTemplate) );
- }
- catch ( Exception e )
- {
- e.printStackTrace();
- out.println( mergeTemplate( super.msgGenericError , super.errorTemplate) );
- }
- }
-
}
diff --git a/trunk/siprpWeb/src/com/evolute/siprp/pagina/doGetListaTrabalhadores.java b/trunk/siprpWeb/src/com/evolute/siprp/pagina/doGetListaTrabalhadores.java
index 67524140..2522aadd 100644
--- a/trunk/siprpWeb/src/com/evolute/siprp/pagina/doGetListaTrabalhadores.java
+++ b/trunk/siprpWeb/src/com/evolute/siprp/pagina/doGetListaTrabalhadores.java
@@ -1,19 +1,26 @@
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
{
Statement stmt = con.createStatement( ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY );
@@ -22,355 +29,363 @@ public class doGetListaTrabalhadores extends siprpServlet
stmt.close();
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 ;
- 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();
- try
- {
- userRole = (String)session.getAttribute(super.sessionUserRole);
- empresaId = (String)session.getAttribute(super.sessionEmpresaId);
- estabelecimentoId = (String)session.getAttribute(super.sessionEstabelecimentoId);
-
- System.out.println( "\ndoGetListaTrabalhadores() . " );
- System.out.println( "\tuserRole : " + userRole + " - " + super.superUserRole );
- System.out.println( "\tempresaID : " + empresaId );
- System.out.println( "\testabelecimentoID : " + estabelecimentoId );
-
- if ( userRole != null && ( userRole.equals( super.superUserRole ) || userRole.equals( empresaId ) ) )
- {
- Class.forName(super.bdDriver);
- con = DriverManager.getConnection( bdLocalUrl, bdLocalUsername, bdLocalPassword );
- if ( super.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);
- rsTrab = new ResultSet2DArray( stmt.executeQuery( dbQuery ) );
- rsTrab.getObjects();
- stmt.close();
-
- final int max = rsTrab.columnLength();
-
- 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) );
-
-
- /** 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ã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ã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";
- rs = executeQuery( con, dbQuery );
-
- java.util.Date dataUltimaConsultaRealizada = null;
- String consultaRealizada = "";
- if ( rs.columnLength() > 0 )
- {
- dataUltimaConsultaRealizada = ( java.util.Date ) rs.get( 0, 1 );
- 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";
- rs = executeQuery( con, dbQuery );
-
- java.util.Date dataProximaConsulta = null;
- if ( rs.columnLength() > 0 )
- {
- dataProximaConsulta = ( java.util.Date ) rs.get( 0, 1 );
- }
-
- trabalhador.put( "ultima_consulta", dataUltimaConsultaRealizada == null ? "" : dataUltimaConsultaRealizada );
- trabalhador.put( "realizada", consultaRealizada );
- trabalhador.put( "proxima_consulta", dataProximaConsulta == null ? "" : dataProximaConsulta );
- /** eof dados consulta **/
+ ServletOutputStream out = res.getOutputStream();
+ Connection con = null;
+ Statement stmt = null;
+ ResultSet2DArray rs, rsTrab;
+ StringBuffer sBuffer;
+ 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( sessionUserRole );
+ empresaId = ( String ) session.getAttribute( sessionEmpresaId );
+ estabelecimentoId = ( String ) session.getAttribute( sessionEstabelecimentoId );
+
+ System.out.println( "\ndoGetListaTrabalhadores() . " );
+ System.out.println( "\tuserRole : " + userRole + " - " + superUserRole );
+ System.out.println( "\tempresaID : " + empresaId );
+ System.out.println( "\testabelecimentoID : " + estabelecimentoId );
+
+ if ( userRole != null && ( userRole.equals( superUserRole ) || userRole.equals( empresaId ) ) )
+ {
+ Class.forName( bdDriver );
+ con = DriverManager.getConnection( bdLocalUrl, bdLocalUsername, bdLocalPassword );
+ 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 );
+ rsTrab = new ResultSet2DArray( stmt.executeQuery( dbQuery ) );
+ rsTrab.getObjects();
+ stmt.close();
+ final int max = rsTrab.columnLength();
- /** 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";
- rs = executeQuery( con, dbQuery );
-
- java.util.Date dataUltimoExameRealizado = null;
- String realizado = "";
- if ( rs.columnLength() > 0 )
- {
- dataUltimoExameRealizado = ( java.util.Date ) rs.get( 0, 1 );
- realizado = "Sim";
- }
+ for ( int index = 0; index < max; index++ )
+ {
+ 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 ) );
- 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";
- rs = executeQuery( con, dbQuery );
- if ( rs.columnLength() > 0 )
- {
- dataProximoExame = ( java.util.Date ) rs.get( 0, 1 );
- }
-
- trabalhador.put( "ultimo_exame", dataUltimoExameRealizado == null ? "" : dataUltimoExameRealizado );
- 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ã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ã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(""+super.nomeEmpresa(con,empresaId)+"
"
- +super.nomeEstabelecimento(con, estabelecimentoId)+"" );
+ /** dados de consultas **/
- HashMap hmValues = new HashMap();
- 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_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 )
+ // 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ã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ã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";
+ rs = executeQuery( con, dbQuery );
+
+ java.util.Date dataUltimaConsultaRealizada = null;
+ String consultaRealizada = "";
+ if ( rs.columnLength() > 0 )
{
- out.println( mergeTemplate( hmValues, super.authenticatedUserTemplate));
+ dataUltimaConsultaRealizada = ( java.util.Date ) rs.get( 0, 1 );
+ consultaRealizada = "Sim";
}
- else
+
+ 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;
+ if ( rs.columnLength() > 0 )
+ {
+ dataProximaConsulta = ( java.util.Date ) rs.get( 0, 1 );
+ }
+
+ trabalhador.put( "ultima_consulta", dataUltimaConsultaRealizada == null ? "" : dataUltimaConsultaRealizada );
+ trabalhador.put( "realizada", consultaRealizada );
+ 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";
+ rs = executeQuery( con, dbQuery );
+
+ java.util.Date dataUltimoExameRealizado = null;
+ String realizado = "";
+ if ( rs.columnLength() > 0 )
{
- out.println( mergeTemplate( hmValues, super.authenticatedUserPrintTemplate));
+ dataUltimoExameRealizado = ( java.util.Date ) rs.get( 0, 1 );
+ realizado = "Sim";
}
-// out.println( mergeTemplate( sBuffer.toString(), userRole, super.queryStringTrabalhadores, links, desc, null, super.authenticatedUserTemplate) );
- }
- else // est nao pertence 'a empresa
- {
- out.println( mergeTemplate( super.msgLinkFormatError , userRole, super.errorTemplate) );
- }
- con.close();
- }
- else // Role nao permite ver esta informacao
- {
- out.println( mergeTemplate( super.msgAcessoNegado , userRole, super.errorTemplate) );
- }
- }
- catch ( SQLException e )
- {
- e.printStackTrace();
- out.println( mergeTemplate( super.msgErroBd , super.errorTemplate) );
- }
- catch ( Exception e )
- {
- e.printStackTrace();
- out.println( mergeTemplate( super.msgGenericError , super.errorTemplate) );
- }
- }
-
+
+ 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";
+ rs = executeQuery( con, dbQuery );
+ if ( rs.columnLength() > 0 )
+ {
+ dataProximoExame = ( java.util.Date ) rs.get( 0, 1 );
+ }
+
+ trabalhador.put( "ultimo_exame", dataUltimoExameRealizado == null ? "" : dataUltimoExameRealizado );
+ 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ã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ã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( "" + nomeEmpresa( con, empresaId ) + "
" + nomeEstabelecimento( con, estabelecimentoId ) + "" );
+
+ 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", 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, queryStringTrabalhadores );
+ hmValues.put( templateVector1, links );
+ hmValues.put( templateVector2, desc );
+ hmValues.put( templateVector3, null );
+ if ( !print )
+ {
+ out.println( mergeTemplate( hmValues, authenticatedUserTemplate ) );
+ }
+ else
+ {
+ out.println( mergeTemplate( hmValues, authenticatedUserPrintTemplate ) );
+ }
+ // out.println( mergeTemplate( sBuffer.toString(), userRole,
+ // super.queryStringTrabalhadores, links, desc, null,
+ // super.authenticatedUserTemplate) );
+ }
+ else
+ // est nao pertence 'a empresa
+ {
+ out.println( mergeTemplate( msgLinkFormatError, userRole, errorTemplate ) );
+ }
+ con.close();
+ }
+ else
+ // Role nao permite ver esta informacao
+ {
+ out.println( mergeTemplate( msgAcessoNegado, userRole, errorTemplate ) );
+ }
+ }
+ catch ( SQLException e )
+ {
+ e.printStackTrace();
+ out.println( mergeTemplate( msgErroBd, errorTemplate ) );
+ }
+ catch ( Exception e )
+ {
+ e.printStackTrace();
+ out.println( mergeTemplate( msgGenericError, errorTemplate ) );
+ }
+ }
+
}
diff --git a/trunk/siprpWeb/src/com/evolute/siprp/pagina/doGetListaTrabalhadoresPendentes.java b/trunk/siprpWeb/src/com/evolute/siprp/pagina/doGetListaTrabalhadoresPendentes.java
index a9626367..82c2cced 100644
--- a/trunk/siprpWeb/src/com/evolute/siprp/pagina/doGetListaTrabalhadoresPendentes.java
+++ b/trunk/siprpWeb/src/com/evolute/siprp/pagina/doGetListaTrabalhadoresPendentes.java
@@ -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 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 org.apache.velocity.runtime.parser.node.GetExecutor;
+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.data.*;
-import com.evolute.utils.db.*;
-import com.evolute.utils.sql.*;
-import com.evolute.utils.strings.*;
+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 ) );
}
}
diff --git a/trunk/siprpWeb/src/com/evolute/siprp/pagina/doGetListaTrabalhadoresTudo.java b/trunk/siprpWeb/src/com/evolute/siprp/pagina/doGetListaTrabalhadoresTudo.java
index 473e308d..c123c430 100644
--- a/trunk/siprpWeb/src/com/evolute/siprp/pagina/doGetListaTrabalhadoresTudo.java
+++ b/trunk/siprpWeb/src/com/evolute/siprp/pagina/doGetListaTrabalhadoresTudo.java
@@ -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 ) );
}
}
diff --git a/trunk/siprpWeb/src/com/evolute/siprp/pagina/doGetTrabalhador.java b/trunk/siprpWeb/src/com/evolute/siprp/pagina/doGetTrabalhador.java
index 5172e050..f82f9451 100644
--- a/trunk/siprpWeb/src/com/evolute/siprp/pagina/doGetTrabalhador.java
+++ b/trunk/siprpWeb/src/com/evolute/siprp/pagina/doGetTrabalhador.java
@@ -1,19 +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.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
{
Statement stmt = con.createStatement( ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY );
@@ -22,62 +28,55 @@ public class doGetTrabalhador extends siprpServlet
stmt.close();
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" ) );
hmFuncionario.put( "nome", rs.get( 0, "nome" ) );
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;
String realizado = "";
if ( rs.columnLength() > 0 )
@@ -85,130 +84,56 @@ public class doGetTrabalhador extends siprpServlet
dataUltimoExameRealizado = ( java.util.Date ) rs.get( 0, 1 );
realizado = "Sim";
}
-
+
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 )
{
dataProximoExame = ( java.util.Date ) rs.get( 0, 1 );
}
-
+
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ã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ã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 );
}
}
@@ -221,16 +146,13 @@ 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;
String consultaRealizada = "";
if ( rs.columnLength() > 0 )
@@ -238,126 +160,34 @@ public class doGetTrabalhador extends siprpServlet
dataUltimaConsultaRealizada = ( java.util.Date ) rs.get( 0, 1 );
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;
if ( rs.columnLength() > 0 )
{
dataProximaConsulta = ( java.util.Date ) rs.get( 0, 1 );
}
-
+
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ã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ã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(""+super.nomeEmpresa(con,empresaId)+"
"
- +super.nomeEstabelecimento(con, estabelecimentoId)+"" );
+ sBuffer.append( "" + nomeEmpresa( con, empresaId ) + "
" + nomeEstabelecimento( con, estabelecimentoId ) + "" );
- 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 ) );
}
}
diff --git a/trunk/siprpWeb/src/com/evolute/siprp/pagina/doPostLogin.java b/trunk/siprpWeb/src/com/evolute/siprp/pagina/doPostLogin.java
index 0685cf77..f57915b5 100644
--- a/trunk/siprpWeb/src/com/evolute/siprp/pagina/doPostLogin.java
+++ b/trunk/siprpWeb/src/com/evolute/siprp/pagina/doPostLogin.java
@@ -1,152 +1,142 @@
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
{
-
- /** Creates a new instance of doPostLogin */
- 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 ;
- String user, userRole, password;
-
- try
- {
- user = req.getParameter("user");
- password = req.getParameter("password");
-
- 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+"'");
-
- 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)))
- {
- // 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);
-
- rs = new ResultSet2DArray( stmt.executeQuery( dbQuery.toString()) );
- userRole = (String)rs.get(0,0);
-
- // UPDATE HTTP SESSION
- HttpSession session = req.getSession(true);
- session.setMaxInactiveInterval(sessionTimeout);
-
- session.setAttribute(sessionUser, user);
- session.setAttribute(sessionUserRole, userRole);
- session.setAttribute(sessionPassword, password);
-
- HashMap hmValues = new HashMap();
- session.setAttribute( sessionEmpresaId, userRole );
- 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 ),
- userRole ) );
- session.setAttribute( sessionEstabelecimentoId, "-1" );
- //hmValues.put( templateQuery, super.queryStringEstabelecimentos );
- new doGetListaEstabelecimentos( req, res );
- }
- stmt.close();
- con.close();
-
- 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", 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 )
- {
- e.printStackTrace();
- try
- {
- doErro( "erro=" + msgErroBd, out );
- }
- catch ( Exception ex )
- {
- ex.printStackTrace();
- }
-// out.println( mergeTemplate( msgErroBd , super.errorTemplate) );
- }
- catch ( IllegalStateException e ) // session timeout
- {
- e.printStackTrace();
- try
- {
- doErro( "erro=" + msgSessionTimeout, out );
- }
- catch ( Exception ex )
- {
- ex.printStackTrace();
- }
-// out.println( mergeTemplate(msgSessionTimeout, super.errorTemplate) );
- }
- catch ( Exception e )
- {
- e.printStackTrace();
- try
- {
- doErro( "erro=" + msgGenericError, out );
- }
- catch ( Exception ex )
- {
- ex.printStackTrace();
- }
-// out.println( mergeTemplate( msgGenericError , super.errorTemplate) );
- }
- }
-
+ private static final long serialVersionUID = 1L;
+
+ 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;
+ String user, userRole, password;
+
+ try
+ {
+ user = req.getParameter( "user" );
+ password = req.getParameter( "password" );
+
+ if ( user.equals( "" ) )
+ {
+ String msgErro = msgErroNoUser.replace( '+', ' ' );
+ out.println( mergeTemplate( msgErro, indexTemplate ) );
+ }
+ else
+ {
+ Class.forName( bdDriver );
+ con = DriverManager.getConnection( bdUrl, bdUsername, bdPassword );
+ dbQuery = new StringBuffer();
+ 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() ) );
+
+ 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 );
+
+ rs = new ResultSet2DArray( stmt.executeQuery( dbQuery.toString() ) );
+ userRole = ( String ) rs.get( 0, 0 );
+
+ // UPDATE HTTP SESSION
+ HttpSession session = req.getSession( true );
+ session.setMaxInactiveInterval( sessionTimeout );
+
+ session.setAttribute( sessionUser, user );
+ session.setAttribute( sessionUserRole, userRole );
+ session.setAttribute( sessionPassword, password );
+
+ Map< String, Object > hmValues = new HashMap< String, Object >();
+ session.setAttribute( sessionEmpresaId, userRole );
+ if ( userRole.equals( "manager" ) )
+ {
+ session.setAttribute( sessionCompanyName, null );
+ session.setAttribute( sessionEstabelecimentoId, null );
+ new doGetListaEmpresas( req, res );
+ }
+ else
+ {
+ session.setAttribute( sessionCompanyName, nomeEmpresa( DriverManager.getConnection( bdLocalUrl, bdLocalUsername, bdLocalPassword ),
+ userRole ) );
+ session.setAttribute( sessionEstabelecimentoId, "-1" );
+ new doGetListaEstabelecimentos( req, res );
+ }
+ stmt.close();
+ con.close();
+
+ 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", user );
+ }
+ else
+ {
+ String msgErro = msgErroAuthFail.replace( '+', ' ' );
+ out.println( mergeTemplate( msgErro, indexTemplate ) );
+ }
+ }
+ }
+ catch ( SQLException e )
+ {
+ e.printStackTrace();
+ try
+ {
+ doErro( "erro=" + msgErroBd, out );
+ }
+ catch ( Exception ex )
+ {
+ ex.printStackTrace();
+ }
+ }
+ catch ( IllegalStateException e ) // session timeout
+ {
+ e.printStackTrace();
+ try
+ {
+ doErro( "erro=" + msgSessionTimeout, out );
+ }
+ catch ( Exception ex )
+ {
+ ex.printStackTrace();
+ }
+ }
+ catch ( Exception e )
+ {
+ e.printStackTrace();
+ try
+ {
+ doErro( "erro=" + msgGenericError, out );
+ }
+ catch ( Exception ex )
+ {
+ ex.printStackTrace();
+ }
+ }
+ }
+
}
diff --git a/trunk/siprpWeb/src/com/evolute/siprp/pagina/siprpServlet.java b/trunk/siprpWeb/src/com/evolute/siprp/pagina/siprpServlet.java
index c47d7fc9..18bf1b73 100644
--- a/trunk/siprpWeb/src/com/evolute/siprp/pagina/siprpServlet.java
+++ b/trunk/siprpWeb/src/com/evolute/siprp/pagina/siprpServlet.java
@@ -32,617 +32,623 @@ import com.evolute.utils.sql.Select;
public class siprpServlet extends HttpServlet implements GlobalConstants
{
private static final long serialVersionUID = 1L;
-
+
// MSG
- public static final String msgErroNoUser = "Tem+de+especificar+um+utilizador.";
- public static final String msgErroAuthFail = "Utilizador+inexistente+e/ou+Password+errada.";
- public static final String msgErroBd = "Erro+na+ligaç&atiolde;o+à+base+de+dados.";
- 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álido.";
- public static final String msgLogin = "Login";
- public static final String msgNovaPasswordErrada="Erro+ao+criar+a+nova+password,+nova+password+inválida.";
- public static final String msgButtonNotSuported = "funcionalidade+ainda+não+suportada.";
- public static final String msgSessionTimeout = "Por+razões+de+segurança+o+tempo+da+sua+sessão+expirou
"
- + "Por+favor+efectue+novamente+o+seu+login.
";
-
- // Templates - Nomes e valores
- //public static final String loginTemplate = "login.html";
+ public static final String msgErroNoUser = "Tem+de+especificar+um+utilizador.";
+ public static final String msgErroAuthFail = "Utilizador+inexistente+e/ou+Password+errada.";
+ public static final String msgErroBd = "Erro+na+ligaç&atiolde;o+à+base+de+dados.";
+ 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álido.";
+ public static final String msgLogin = "Login";
+ public static final String msgNovaPasswordErrada = "Erro+ao+criar+a+nova+password,+nova+password+inválida.";
+ public static final String msgButtonNotSuported = "funcionalidade+ainda+não+suportada.";
+ public static final String msgSessionTimeout = "Por+razões+de+segurança+o+tempo+da+sua+sessão+expirou
"
+ + "Por+favor+efectue+novamente+o+seu+login.
";
+
+ // Templates - Nomes e valores
+ // 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 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";
-
- // 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";
-
- //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 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";
-
-// // 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
- public static final String bdEstIdRef = "id"; // campo que contem nome do estabelecimento
- public static final String bdEstNomeRef = "nome"; // campo que contem nome do estabelecimento
- public static final String bdTrabIdRef = "id"; // campo que contem id do trabalhador
- public static final String bdTrabNomeRef = "nome"; // campo que contem nome do trabalhador
- public static final String bdNullString = ""; // String a mostrar quando o campo lido da BD e' null
- public static final String bdEmailEmpresa = "email"; // campo que contem email da empresa
-
- 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"}
- };
-
- public void init()
- {
-
- try {
- CONTEXT = this.getServletContext();
- String TEMPLATE_DIR = this.getServletContext().getRealPath( "/" ) + "html/";
-System.out.println( "DIR: " + TEMPLATE_DIR );
- Properties props = new Properties();
- props.setProperty( "file.resource.loader.path", TEMPLATE_DIR );
- Velocity.init( props );
- Class.forName(bdDriver);
- }
- catch( Exception e )
- {
- e.printStackTrace();
- }
- }
-
- 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" );
- try
- {
-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 ) ) ;
- }
- else if ( session.isNew() && !( queryString.indexOf(queryStringErro) == 0 ) ) // session timeout
- {
- session.invalidate();
- String msgErro = msgSessionTimeout.replace( '+', ' ' );
+ // 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";
+
+ // 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";
+
+ // 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 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";
+
+ // // 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
+ public static final String bdEstIdRef = "id"; // campo que contem nome do estabelecimento
+ public static final String bdEstNomeRef = "nome"; // campo que contem nome do estabelecimento
+ public static final String bdTrabIdRef = "id"; // campo que contem id do trabalhador
+ public static final String bdTrabNomeRef = "nome"; // campo que contem nome do trabalhador
+ public static final String bdNullString = ""; // String a mostrar quando o campo lido da BD e' null
+ public static final String bdEmailEmpresa = "email"; // campo que contem email da empresa
+
+ protected static ServletContext CONTEXT;
+
+ // Arrays
+ // 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
+ {
+ CONTEXT = this.getServletContext();
+ String TEMPLATE_DIR = this.getServletContext().getRealPath( "/" ) + "html/";
+ System.out.println( "DIR: " + TEMPLATE_DIR );
+ Properties props = new Properties();
+ props.setProperty( "file.resource.loader.path", TEMPLATE_DIR );
+ Velocity.init( props );
+ Class.forName( bdDriver );
+ }
+ catch ( Exception e )
+ {
+ e.printStackTrace();
+ }
+ }
+
+ 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" );
+ try
+ {
+ 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 ) );
+ }
+ else if ( session.isNew() && !( queryString.indexOf( queryStringErro ) == 0 ) ) // session
+ // timeout
+ {
+ session.invalidate();
+ String msgErro = msgSessionTimeout.replace( '+', ' ' );
out.println( mergeTemplate( msgErro, indexTemplate ) );
-// doErro(queryString, out);
- }
- else if ( queryString.equals(queryStringEmpresas) ) // Listar Empresas
- {
- new doGetListaEmpresas(req,res);
- }
- else if ( queryString.indexOf(queryStringErro) == 0 ) // Listar Empresas
- {
-// System.out.println( "entrou" );
- doErro(queryString, out);
- }
- else // interpretar query string
- {
- String empresa = null, estabelecimento=null, trabalhador=null;
+ // doErro(queryString, out);
+ }
+ else if ( queryString.equals( queryStringEmpresas ) ) // Listar
+ // Empresas
+ {
+ new doGetListaEmpresas( req, res );
+ }
+ else if ( queryString.indexOf( queryStringErro ) == 0 ) // Listar
+ // Empresas
+ {
+ // System.out.println( "entrou" );
+ doErro( queryString, out );
+ }
+ else
+ // interpretar query string
+ {
+ String empresa = null, estabelecimento = null, trabalhador = null;
String query = null;
- int checkInt;
-
- StringTokenizer sToken = new StringTokenizer(queryString,"/") ;
- empresa = sToken.nextToken(); // empresa ID
- checkInt = Integer.parseInt(empresa); // check int, NumberFormatException
-
- if (sToken.hasMoreElements())
- {
- estabelecimento = sToken.nextToken(); // estabelecimento ID
- checkInt = Integer.parseInt(estabelecimento); // check int, NumberFormatException
- if (sToken.hasMoreElements())
- {
- trabalhador = sToken.nextToken(); // trabalhador ID
+ int checkInt;
+
+ StringTokenizer sToken = new StringTokenizer( queryString, "/" );
+ empresa = sToken.nextToken(); // empresa ID
+ checkInt = Integer.parseInt( empresa ); // check int,
+ // NumberFormatException
+
+ if ( sToken.hasMoreElements() )
+ {
+ estabelecimento = sToken.nextToken(); // estabelecimento ID
+ 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;
}
}
- }
- }
-
+ }
+ }
+
if ( estabelecimento == null ) // empresa query
- {
- session.setAttribute(sessionEmpresaId, empresa); // update HTTP Session
-
- new doGetListaEstabelecimentos(req,res);
-
- //out.println( mergeTemplate ( empresa, loginTemplate ) ) ;
- }
- else if ( trabalhador == null || query != null ) // estabelecimento query
- {
- session.setAttribute(sessionEmpresaId, empresa); // update HTTP Session
- session.setAttribute(sessionEstabelecimentoId, estabelecimento);
-
- new doGetListaTrabalhadores(req,res, query);
-
- //out.println( mergeTemplate ( " chama oGetListaTrabalhadores", loginTemplate ) ) ;
- }
- else // trabalhador query
- {
- session.setAttribute(sessionEmpresaId, empresa); // update HTTP Session
- session.setAttribute(sessionEstabelecimentoId, estabelecimento);
- session.setAttribute(sessionTrabalhadorId, trabalhador);
-
- new doGetTrabalhador(req,res);
-
- //out.println( mergeTemplate ( trabalhador, loginTemplate ) ) ;
- }
- }
- }
- catch ( NumberFormatException e ) // argumentos invalidos
- {
- e.printStackTrace();
- out.println( mergeTemplate( msgLinkFormatError, backUri, errorTemplate) );
- }
- catch ( IllegalStateException e ) // session timeout
- {
- e.printStackTrace();
- out.println( mergeTemplate(msgSessionTimeout, errorTemplate) );
- }
- catch ( Exception e )
- {
- e.printStackTrace();
-// out.println( mergeTemplate( msgGenericError , backUri, errorTemplate ) );
- out.println( mergeTemplate( msgGenericError , errorTemplate ) );
- }
-// System.out.println( "fim - " + queryString + " bu " + backUri );
- }
-
- 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");
- res.setContentType( "text/html" );
- try
- {
- if ( buttonPressed.equals(botaoLogin))
- {
- new doPostLogin(req,res);
- }
- else
- {
- out.println( mergeTemplate( msgButtonNotSuported, errorTemplate) );
- }
- }
- /*catch ( SQLException e )
- {
- e.printStackTrace();
- out.println( mergeTemplate( msgErroBd , criticalErrorTemplate) );
- }*/
- catch ( IllegalStateException e ) // session timeout
- {
- e.printStackTrace();
- out.println( mergeTemplate(msgSessionTimeout, errorTemplate) );
- }
- catch ( Exception e )
- {
- e.printStackTrace();
- out.println( mergeTemplate( msgGenericError , errorTemplate) );
- }
- }
-
-
- public String mergeTemplate( Map values, String template )
- {
- VelocityContext context = new VelocityContext();
- StringWriter output = new StringWriter();
-
- try
- {
- for( Iterator i = values.keySet().iterator(); i.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( "", 2, ";", value.toString(), true )
-// : null );
- }
-
- Velocity.mergeTemplate(template, Velocity.ENCODING_DEFAULT, context, output );
- return output.toString();
- }
- catch( Exception e )
- {
- e.printStackTrace();
- }
- return null;
- }
-
-
-
- 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 );
- return output.toString();
- }
- catch( Exception e )
- {
- e.printStackTrace();
- }
- return null;
- }
-
- public String mergeTemplate (String msg, String userRole, String template ) // #1
- {
-
- VelocityContext context = new VelocityContext();
- StringWriter output = new StringWriter();
-
- try
- {
- context.put ( msgTemplate , msg ) ;
- context.put ( templateUserRole, userRole);
- Velocity.mergeTemplate(template, Velocity.ENCODING_DEFAULT, context, output );
- return output.toString();
- }
- 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
- {
-
- 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 );
- return output.toString();
- }
- catch( Exception e )
- {
- e.printStackTrace();
- }
- return null;
- }
-
- public void destroy()
- {
- }
-
- public void handleSessionTimeout(HttpServletResponse res, String template)
- throws IOException
- {
- ServletOutputStream out = res.getOutputStream();
- try
- {
- out.println( mergeTemplate( msgSessionTimeout, template) );
- }
- catch ( Exception e )
- {
- e.printStackTrace();
-
- }
- }
-
- 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 ;
- Virtual2DArray rs;
- String query;
- try
- {
- //con = DriverManager.getConnection( bdUrl, bdUsername, bdPassword );
- query = "SELECT empresa_id FROM estabelecimentos where id='"+estabelecimentoId+"'";
- if( con != null )
+ {
+ session.setAttribute( sessionEmpresaId, empresa ); // update
+ // HTTP
+ // Session
+
+ new doGetListaEstabelecimentos( req, res );
+
+ // out.println( mergeTemplate ( empresa, loginTemplate ) ) ;
+ }
+ else if ( trabalhador == null || query != null ) // estabelecimento
+ // query
+ {
+ session.setAttribute( sessionEmpresaId, empresa ); // update
+ // HTTP
+ // Session
+ session.setAttribute( sessionEstabelecimentoId, estabelecimento );
+
+ new doGetListaTrabalhadores( req, res, query );
+
+ // out.println( mergeTemplate (
+ // " chama oGeHashtabletListaTrabalhadores", loginTemplate )
+ // ) ;
+ }
+ else
+ // trabalhador query
+ {
+ session.setAttribute( sessionEmpresaId, empresa ); // update
+ // HTTP
+ // Session
+ session.setAttribute( sessionEstabelecimentoId, estabelecimento );
+ session.setAttribute( sessionTrabalhadorId, trabalhador );
+
+ new doGetTrabalhador( req, res );
+
+ // out.println( mergeTemplate ( trabalhador, loginTemplate )
+ // ) ;
+ }
+ }
+ }
+ catch ( NumberFormatException e ) // argumentos invalidos
+ {
+ e.printStackTrace();
+ out.println( mergeTemplate( msgLinkFormatError, backUri, errorTemplate ) );
+ }
+ catch ( IllegalStateException e ) // session timeout
+ {
+ e.printStackTrace();
+ out.println( mergeTemplate( msgSessionTimeout, errorTemplate ) );
+ }
+ catch ( Exception e )
+ {
+ e.printStackTrace();
+ // out.println( mergeTemplate( msgGenericError , backUri,
+ // errorTemplate ) );
+ out.println( mergeTemplate( msgGenericError, errorTemplate ) );
+ }
+ // System.out.println( "fim - " + queryString + " bu " + backUri );
+ }
+
+ 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" );
+ res.setContentType( "text/html" );
+ try
+ {
+ if ( buttonPressed.equals( botaoLogin ) )
+ {
+ new doPostLogin( req, res );
+ }
+ else
+ {
+ out.println( mergeTemplate( msgButtonNotSuported, errorTemplate ) );
+ }
+ }
+ /*
+ * catch ( SQLException e ) { e.printStackTrace(); out.println(
+ * mergeTemplate( msgErroBd , criticalErrorTemplate) ); }
+ */
+ catch ( IllegalStateException e ) // session timeout
+ {
+ e.printStackTrace();
+ out.println( mergeTemplate( msgSessionTimeout, errorTemplate ) );
+ }
+ catch ( Exception e )
+ {
+ e.printStackTrace();
+ out.println( mergeTemplate( msgGenericError, errorTemplate ) );
+ }
+ }
+
+ public String mergeTemplate( Map< String, Object > values, String template )
+ {
+ VelocityContext context = new VelocityContext();
+ StringWriter output = new StringWriter();
+
+ try
+ {
+ Iterator< String > it = values.keySet().iterator();
+ while ( it.hasNext() )
{
- stmt = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
+ String key = it.next();
+ context.put( key, values.get( key ) );
+ }
+ Velocity.mergeTemplate( template, Velocity.ENCODING_DEFAULT, context, output );
+ return output.toString();
+ }
+ catch ( Exception e )
+ {
+ e.printStackTrace();
+ }
+ return null;
+ }
+
+ 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 );
+ return output.toString();
+ }
+ catch ( Exception e )
+ {
+ e.printStackTrace();
+ }
+ return null;
+ }
+
+ public String mergeTemplate( String msg, String userRole, String template ) // #1
+ {
+
+ VelocityContext context = new VelocityContext();
+ StringWriter output = new StringWriter();
+
+ try
+ {
+ context.put( msgTemplate, msg );
+ context.put( templateUserRole, userRole );
+ Velocity.mergeTemplate( template, Velocity.ENCODING_DEFAULT, context, output );
+ return output.toString();
+ }
+ 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
+ {
+ 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 );
+ return output.toString();
+ }
+ catch ( Exception e )
+ {
+ e.printStackTrace();
+ }
+ return null;
+ }
+
+ public void destroy()
+ {
+ }
+
+ public void handleSessionTimeout( HttpServletResponse res, String template ) throws IOException
+ {
+ ServletOutputStream out = res.getOutputStream();
+ try
+ {
+ out.println( mergeTemplate( msgSessionTimeout, template ) );
+ }
+ catch ( Exception e )
+ {
+ e.printStackTrace();
+ }
+ }
+
+ 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;
+ Virtual2DArray rs;
+ String query;
+ try
+ {
+ // 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 );
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
+ {
+ return true;
+ }
+ else
+ {
+ return false;
+ }
+ }
+ catch ( Exception e )
+ {
+ e.printStackTrace();
+ }
+ return false;
+ }
+
+ 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;
+ ResultSet2DArray rs;
+ StringBuffer dbQuery;
+ try
+ {
+ // 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
+ stmt.close();
+ if ( estabelecimentoId.equals( temp ) ) // estabelecimento pertence
+ // 'a empresa
+ {
+ return true;
+ }
+ else
+ {
+ return false;
+ }
+ }
+ catch ( Exception e )
+ {
+ e.printStackTrace();
+ }
+ return false;
+ }
+
+ public void closeSqlCon( Connection con )
+ {
+ try
+ {
+ if ( con != null )
+ con.close();
+ }
+ catch ( Exception e )
+ {
+ e.printStackTrace();
+ }
+
+ }
+
+ public String emailEmpresa( Connection con, String empresaId )
+ {
+ Statement stmt = null;
+ ResultSet2DArray rs;
+ StringBuffer dbQuery;
+ String returnString;
+
+ 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 )
{
+ returnString = ( String ) rs.get( 0, 0 );
stmt.close();
+ return returnString;
}
- if ( empresaId.equals(temp) ) // estabelecimento pertence 'a empresa
- {
- return true;
- }
- else
- {
- return false;
- }
- }
- catch ( Exception e )
- {
- e.printStackTrace();
- }
- return false;
- }
-
- 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 ;
- ResultSet2DArray rs;
- StringBuffer dbQuery;
- try
- {
- //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
- stmt.close();
- if ( estabelecimentoId.equals(temp) ) // estabelecimento pertence 'a empresa
- {
- return true;
- }
- else
- {
- return false;
- }
- }
- catch ( Exception e )
- {
- e.printStackTrace();
- }
- return false;
- }
-
- public void closeSqlCon(Connection con)
- {
- try
- {
- if (con != null ) con.close();
- }
- catch ( Exception e )
- {
- e.printStackTrace();
- }
-
- }
-
- public String emailEmpresa(Connection con, String empresaId)
- {
- Statement stmt = null ;
- ResultSet2DArray rs;
- StringBuffer dbQuery;
- String returnString;
-
- 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 )
- {
- returnString = (String)rs.get(0,0);
- stmt.close();
- return returnString;
- }
- else
- {
- return null;
- }
- }
- catch ( Exception e )
- {
- e.printStackTrace();
- }
- return null;
- }
-
- public String nomeEmpresa(Connection con, String empresaId)
- {
- Statement stmt = null ;
- Virtual2DArray rs;
- String returnString;
-
- try
- {
- String query = "SELECT designacao_social FROM empresas WHERE id ='"+empresaId+"'";
- if( con != null )
+ else
+ {
+ return null;
+ }
+ }
+ catch ( Exception e )
+ {
+ e.printStackTrace();
+ }
+ return null;
+ }
+
+ public String nomeEmpresa( Connection con, String empresaId )
+ {
+ Statement stmt = null;
+ Virtual2DArray rs;
+ String returnString;
+
+ try
+ {
+ 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 )
- {
- returnString = (String)rs.get(0,0);
- if( con != null )
+ if ( rs.columnLength() > 0 )
{
- stmt.close();
+ returnString = ( String ) rs.get( 0, 0 );
+ if ( con != null )
+ {
+ stmt.close();
+ }
+ return returnString;
}
- return returnString;
- }
- else
- {
- return null;
- }
- }
+ else
+ {
+ return null;
+ }
+ }
catch ( Exception e )
- {
- e.printStackTrace();
- }
- return null;
- }
-
- public String nomeEstabelecimento(Connection con, java.lang.String estabelecimentoId)
- {
- Statement stmt = null ;
- Virtual2DArray rs;
- StringBuffer dbQuery;
- String returnString;
-
- try
- {
- String query = "SELECT nome FROM estabelecimentos WHERE id ='"+estabelecimentoId+"'";
- if( con != null )
+ {
+ e.printStackTrace();
+ }
+ return null;
+ }
+
+ public String nomeEstabelecimento( Connection con, java.lang.String estabelecimentoId )
+ {
+ Statement stmt = null;
+ Virtual2DArray rs;
+ StringBuffer dbQuery;
+ String returnString;
+
+ try
+ {
+ 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 )
- {
- returnString = (String)rs.get(0,0);
- if( con != null )
+ if ( rs.columnLength() > 0 )
+ {
+ returnString = ( String ) rs.get( 0, 0 );
+ if ( con != null )
+ {
+ stmt.close();
+ }
+ return returnString;
+ }
+ else
+ {
+ return null;
+ }
+ }
+ catch ( Exception e )
+ {
+ e.printStackTrace();
+ }
+ return null;
+ }
+
+ public String nomeTrabalhador( Connection con, java.lang.String trabalhadorId )
+ {
+ Statement stmt = null;
+ ResultSet2DArray rs;
+ StringBuffer dbQuery;
+ String returnString;
+
+ 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 )
{
+ returnString = ( String ) rs.get( 0, 0 );
stmt.close();
+ return returnString;
}
- return returnString;
- }
- else
- {
- return null;
- }
- }
- catch ( Exception e )
- {
- e.printStackTrace();
- }
- return null;
- }
-
- public String nomeTrabalhador(Connection con, java.lang.String trabalhadorId)
- {
- Statement stmt = null ;
- ResultSet2DArray rs;
- StringBuffer dbQuery;
- String returnString;
-
- 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 )
- {
- returnString = (String)rs.get(0,0);
- stmt.close();
- return returnString;
- }
- else
- {
- return null;
- }
- }
- catch ( Exception e )
- {
- e.printStackTrace();
- }
- return null;
- }
-
- public void doErro( String queryString, ServletOutputStream out )
- throws Exception
+ else
+ {
+ return null;
+ }
+ }
+ catch ( Exception e )
+ {
+ e.printStackTrace();
+ }
+ return null;
+ }
+
+ 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, errorTemplate ) );
+ // 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 );
}
}
-