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

0'XOR(if(now()=sysdate(),sleep(15),0))XOR'Z
Frederico Palma 12 years ago
parent b50614addd
commit 32b28d3f0c

@ -0,0 +1,68 @@
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package utils;
/**
*
* @author lluis
*/
public class Global
{
//tipos utilizadores
public static final int RESPONSAVEL_SEGURANCA = 1;
public static final int RH = 2;
public static final int TECNICO_HS = 3;
public static final int GESTOR = 6;
public static final int DIRECTOR_GERAL_RH = 7;
public static final int DIRECTOR_SIPRP = 8;
public static final int DIRECTOR_LOJA = 9;
public static final int DIRECTOR_NACIONAL_SEGURANCA = 10;
//Fases do plano
public static final int FASE_SIPRP_EMISSAO = 1;
public static final int FASE_SEGURANCA_PREENCHIMENTO = 2;
public static final int FASE_DIR_LOJA_VALIDACAO = 3;
public static final int FASE_DNS_PARECER = 4;
public static final int FASE_SIPRP_CONCLUSAO = 5;
public static final int FASE_CONCLUIDO = 6;
//Fases do plano - texto
public static final String FASE_SIPRP_EMISSAO_TXT = "SIPRP(Emiss\u00e3o)";
public static final String FASE_SEGURANCA_PREENCHIMENTO_TXT = "Seguran\u00e7a Auchan(Preenchimento)";
public static final String FASE_DIR_LOJA_VALIDACAO_TXT = "Director de loja(Valida\u00e7\u00e3o)";
public static final String FASE_DNS_PARECER_TXT = "DNS(Parecer)";
public static final String FASE_SIPRP_CONCLUSAO_TXT = "SIPRP(Verifica\u00e7\u00e3o/Conclus\u00e3o)";
public static final String[] FASES_TEXTO = new String[] {
"SIPRP(Emiss\u00e3o)",
"Seguran\u00e7a Auchan(Preenchimento)",
"Director de loja(Valida\u00e7\u00e3o)",
"DNS(Parecer)",
"SIPRP(Verifica\u00e7\u00e3o/Conclus\u00e3o)",
"Conclu\u00eddo"
};
// public static final String ANALISE_ACIDENTES_URL = "http://localhost:8084/AnaliseAcidentesTrabalho/faces/"; //testes
// public static final String PLANOS_ACTUACAO_URL = "http://localhost:8084/PlanosActuacao/faces/"; //testes
// public static final String ANALISE_ACIDENTES_URL = "http://192.168.111.24:8084/AnaliseAcidentesTrabalho/faces/"; //testes portatil
public static final String ANALISE_ACIDENTES_URL = "https://www.siprp.pt/AnaliseAcidentesTrabalho/faces/"; //real
public static final String PLANOS_ACTUACAO_URL = "https://www.siprp.pt/PlanosActuacao/faces/";
public static final String LOGOS_FOLDER = "/resources/images";
public static final String PDF_FOLDER_URL = "/resources/pdf";
public static final int ESTADO_MEDIDA_IMPLEMENTADA = 1;
public static final int ESTADO_MEDIDA_NAO_IMPLEMENTADA = 2;
public static final int ESTADO_MEDIDA_EM_IMPLEMENTACAO = 3;
public static final int MAX_TEXTAREA_CHARS = 100;
public static final String VALOR_INDETERMINADO = "IND";
}

@ -0,0 +1,23 @@
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package utils;
import java.util.Map;
import javax.faces.context.FacesContext;
/**
*
* @author lluis
*/
public class JSFHTTPUtils {
public static String getReferer(FacesContext context)
{
Map headerMap = context.getCurrentInstance().getExternalContext().getRequestHeaderMap();
String referer = (String) headerMap.get("referer");
return referer;
}
}

@ -0,0 +1,114 @@
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package utils;
import java.util.Iterator;
import java.util.Map;
import javax.faces.application.Application;
import javax.faces.context.ExternalContext;
import javax.faces.context.FacesContext;
import javax.faces.render.ResponseStateManager;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import planosactuacao.ApplicationBean1;
import planosactuacao.SessionBean1;
/**
*
* @author lluis
*/
public class JSFUtils {
public static SessionBean1 getSessionBean(FacesContext fc)
{
FacesContext context = fc.getCurrentInstance();
SessionBean1 session = (SessionBean1) context.getApplication().getELResolver().getValue(context.getELContext(), null, "SessionBean1");
return session;
}
public static ApplicationBean1 getApplicationBean(FacesContext fc)
{
FacesContext context = fc.getCurrentInstance();
System.out.println("CONTEXT : " + context);
ApplicationBean1 application = (ApplicationBean1) context.getApplication().getELResolver().getValue(context.getELContext(), null, "ApplicationBean1");
return application;
}
//
// isPostBack - JSF 1.1 implementation
//
public static boolean isPostBack(FacesContext fc)
{
Map parameterMap = fc.getExternalContext().getRequestParameterMap();
if(parameterMap.size() > 0)
{
Iterator iter = parameterMap.keySet().iterator();
while(iter.hasNext())
{
String par = (String) iter.next();
}
return true;
}
return false;
}
public static boolean isPostback() {
FacesContext facesContext = FacesContext.getCurrentInstance();
Map requestScope = (Map) facesContext.getApplication().getExpressionFactory().createValueExpression(facesContext.getELContext(), "#{requestScope}", Map.class).getValue(facesContext.getELContext());
//Map requestScope = (Map)facesContext.getApplication().createValueBinding(?#{requestScope}?).getValue(facesContext);
boolean ispostback = ((Boolean)requestScope.get("ispostback")).booleanValue();
System.out.println("JSFUtils . isPostback() : " + ispostback );
return ispostback;
}
//
// isPostBack - JSF 1.2 implementation
//
public static boolean isPostBack12(FacesContext fc)
{
ResponseStateManager rsm = fc.getRenderKit().getResponseStateManager();
if(rsm.isPostback(fc))
{
return true;
}
return false;
}
public static void logout(FacesContext fc) throws Exception
{
ExternalContext ectx = fc.getCurrentInstance().getExternalContext();
Utils.doLogout( fc );
HttpSession session = (HttpSession) ectx.getSession(false);
session.invalidate();
}
public static void navigateTo(FacesContext fc, String outcome)
{
FacesContext context = fc.getCurrentInstance();
Application app = context.getApplication();
app.getNavigationHandler().handleNavigation(context, null, outcome);
}
public static void redirect(FacesContext context, String url) throws Exception
{
HttpServletResponse response = (HttpServletResponse) context.getCurrentInstance().getExternalContext().getResponse();
response.sendRedirect(url);
context.responseComplete();
}
public static String getRequestParameter(FacesContext fc, String parameter)
{
Map parameters = fc.getCurrentInstance().getExternalContext().getRequestParameterMap();
return (String) parameters.get(parameter);
}
}

@ -0,0 +1,61 @@
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package utils;
import com.evolute.utils.error.ErrorLogger;
import db.providers.RelatoriosDataProvider;
import java.io.File;
import java.io.FileOutputStream;
import java.io.OutputStream;
import javax.faces.context.FacesContext;
import javax.servlet.ServletContext;
/**
*
* @author lluis
*/
public class Logos {
public String getLogo(Integer empresaId)
{
return null;
}
public String getLogo( FacesContext fc, Integer empresaId )
{
String result = null;
try
{
//get image from db :
// RelatoriosDataProvider rdp = new RelatoriosDataProvider();
RelatoriosDataProvider rdp = RelatoriosDataProvider.getInstance();
byte[] logo = rdp.getLogoByEmpresa( empresaId );
if ( logo != null )
{
int len = logo.length;
ServletContext context = (ServletContext) fc.getExternalContext().getContext();
File logoFolder = new File( context.getRealPath( Global.LOGOS_FOLDER ) );
String logoFilename = logoFolder + "/logo_empresa" + empresaId.toString() + ".jpg";
OutputStream outImej = new FileOutputStream(logoFilename);
outImej.write(logo, 0, len);
System.out.println("LOGO PATH : " + logoFilename);
outImej.close();
result = Global.LOGOS_FOLDER + "/logo_empresa" + empresaId.toString() + ".jpg";
}
}
catch ( Exception ex )
{
ErrorLogger.logException( ex );
}
return result;
}
}

@ -0,0 +1,44 @@
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package utils;
import com.evolute.utils.error.ErrorLogger;
import com.evolute.utils.error.Logger;
import com.evolute.utils.error.LoggerProperties;
import com.evolute.utils.error.ProjectsEnum;
import com.evolute.utils.error.ws.WSLogger;
import com.evolute.utils.network.proxy.EvoProxyObject;
import java.util.HashMap;
/**
*
* @author dneves
*/
public class PlanosActuacaoLogger
{
public static void init() throws Exception
{
HashMap< LoggerProperties, String > properties = new HashMap< LoggerProperties, String >();
properties.put( LoggerProperties.SOFTWARE_NAME, "SIPRP - Planos Actuacao" );
properties.put( LoggerProperties.SOFTWARE_VERSION, "1" );
properties.put( LoggerProperties.PROJECT, ProjectsEnum.PLANOS_ACTUACAO.toString() );
properties.put( LoggerProperties.PROJECT_NAME, ProjectsEnum.PLANOS_ACTUACAO.toString() );
properties.put( LoggerProperties.PROJECT_VERSION, "1" );
String user = "";
String pass = "";
String host = "";
String port = "";
// EvoProxyObject.configSystemProxySelector();
// EvoProxyObject.getProxy( user, pass, host, port );
Logger logger = new WSLogger( properties );
ErrorLogger.initializeLogger( logger );
}
}

@ -0,0 +1,101 @@
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package utils;
import com.evolute.utils.arrays.Virtual2DArray;
import com.evolute.utils.db.Executer;
import com.evolute.utils.sql.Assignment;
import com.evolute.utils.sql.Expression;
import com.evolute.utils.sql.Field;
import com.evolute.utils.sql.Select2;
import com.evolute.utils.sql.Update;
import db.providers.EvoBaseProvider;
import java.util.Date;
import shst.companydataloaders.SIPRPPropertiesLoader;
/**
*
* @author dneves
*/
public class PlanosUpdater
{
public static void main( String[] args )
{
try
{
SIPRPPropertiesLoader props = SIPRPPropertiesLoader.getInstance();
props.load();
EvoBaseProvider provider = EvoBaseProvider.getInstance();
Executer executer = provider.getExecuter();
Executer localExecuter = provider.getLocalExecuter();
// Expression whereExpression = new Field( "planos_actuacao.deleted_date" ).isEqual( null );
Expression whereExpression = null;
Select2 query = new Select2(
new String[] { "planos_actuacao" },
new Integer[] {},
new Expression[] {},
new String[] { "planos_actuacao.id", "planos_actuacao.estabelecimento_id", "planos_actuacao.data_visita" },
whereExpression,
new String[] { "planos_actuacao.estabelecimento_id", "planos_actuacao.data_visita" },
null, null, null
);
Virtual2DArray array = executer.executeQuery( query );
if ( array != null )
{
System.out.println( array.columnLength() + " : " );
for ( int i = 0; i < array.columnLength(); i++ )
{
Integer planoID = array.get( i, 0 );
Integer estabelecimentoID = array.get( i, 1 );
Date dataVisita = array.get( i, 2 );
System.out.println( planoID + " : " + estabelecimentoID + " : " + dataVisita );
Integer relatorioID = null;
Date dataDisponibilizacao = null;
Expression whereExpression2 = new Field( "marcacoes_estabelecimento.data" ).isEqual( dataVisita ).and(
new Field( "marcacoes_estabelecimento.estabelecimento_id" ).isEqual( estabelecimentoID )
);
Select2 query2 = new Select2(
new String[] { "hs_relatorio", "marcacoes_estabelecimento" },
new Integer[] { Select2.JOIN_INNER },
new Expression[] {
new Field( "marcacoes_estabelecimento.id" ).isEqual( new Field( "hs_relatorio.marcacao_id" ) )
},
new String[] { "hs_relatorio.id", "hs_relatorio.is_submetido" },
whereExpression2,
null,
null, null, null
);
Virtual2DArray array2 = localExecuter.executeQuery( query2 );
if ( array2 != null && array2.columnLength() > 0 )
{
relatorioID = array2.get( 0, 0 );
dataDisponibilizacao = array2.get( 0, 1 );
}
System.out.println( "\tRelatorioID : " + relatorioID );
Update upd = new Update( "planos_actuacao", new Assignment[] {
new Assignment( new Field( "hs_relatorio_id" ), relatorioID ),
new Assignment( new Field( "data_disponibilizacao" ), dataDisponibilizacao )
}, new Field( "id" ).isEqual( planoID ) );
executer.executeQuery( upd );
}
}
}
catch ( Exception e )
{
System.out.println( e.getMessage() );
}
}
}

@ -0,0 +1,215 @@
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package utils;
import com.evolute.utils.Singleton;
import com.evolute.utils.error.ErrorLogger;
import com.sun.webui.jsf.model.Option;
import db.entidades.Utilizador;
import db.providers.PlanosDataProvider;
import java.util.Calendar;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import javax.faces.context.ExternalContext;
import javax.faces.context.FacesContext;
import javax.servlet.ServletContext;
import javax.servlet.http.HttpSession;
import planosactuacao.SessionBean1;
/**
*
* @author lluis
*/
public class Utils
{
public static String parseToInsert( String str )
{
String result = str;
// if ( result != null )
// {
// result = UnicodeChecker.parseToUnicode( result, true, true );
// }
return result;
}
public static String unicodeToHTML( String text )
{
if( text == null || text.length() < 6 )
{
return text;
}
// text = UnicodeChecker.convertUnicode0100ToHTMLFromUser( text );
// text = UnicodeChecker.convertUnicode0200ToHTMLFromUser( text );
// text = UnicodeChecker.convertUnicode2000ToHTMLFromUser( text );
// text = UnicodeChecker.convertUnicodeLatin1ExtendedToHTMLFromUser( text );
// text = UnicodeChecker.convertUnicodeSpecialsToHTMLFromUser( text );
String output = text;
// output = output.replaceAll( "\\\\u0009", " " );
// output = output.replaceAll( "\\\\u000a", "<br>" );
//
// output = output.replaceAll( "\\\\u00a0", "&nbsp;" );
// output = output.replaceAll( "\\\\u00aa", "&ordf;" );
// output = output.replaceAll( "\\\\u00ba", "&ordm;" );
//
// output = output.replaceAll( "\\\\u00c0", "<22>" );
// output = output.replaceAll( "\\\\u00c1", "<22>" );
// output = output.replaceAll( "\\\\u00c2", "<22>" );
// output = output.replaceAll( "\\\\u00c3", "<22>" );
// output = output.replaceAll( "\\\\u00c7", "<22>" );
// output = output.replaceAll( "\\\\u00c8", "<22>" );
// output = output.replaceAll( "\\\\u00c9", "<22>" );
// output = output.replaceAll( "\\\\u00d3", "<22>" );
// output = output.replaceAll( "\\\\u00d2", "<22>" );
//
// output = output.replaceAll( "\\\\u00ca", "<22>" );
// output = output.replaceAll( "\\\\u00cc", "<22>" );
// output = output.replaceAll( "\\\\u00cd", "<22>" );
// output = output.replaceAll( "\\\\u00ce", "<22>" );
// output = output.replaceAll( "\\\\u00d2", "<22>" );
// output = output.replaceAll( "\\\\u00d3", "<22>" );
// output = output.replaceAll( "\\\\u00d4", "<22>" );
// output = output.replaceAll( "\\\\u00d5", "<22>" );
// output = output.replaceAll( "\\\\u00d9", "<22>" );
// output = output.replaceAll( "\\\\u00da", "<22>" );
// output = output.replaceAll( "\\\\u00db", "<22>" );
//
// output = output.replaceAll( "\\\\u00e0", "<22>" );
// output = output.replaceAll( "\\\\u00e1", "<22>" );
// output = output.replaceAll( "\\\\u00e2", "<22>" );
// output = output.replaceAll( "\\\\u00e3", "<22>" );
// output = output.replaceAll( "\\\\u00e7", "<22>" );
// output = output.replaceAll( "\\\\u00e8", "<22>" );
// output = output.replaceAll( "\\\\u00e9", "<22>" );
// output = output.replaceAll( "\\\\u00ea", "<22>" );
// output = output.replaceAll( "\\\\u00ec", "<22>" );
// output = output.replaceAll( "\\\\u00ed", "<22>" );
// output = output.replaceAll( "\\\\u00ee", "<22>" );
// output = output.replaceAll( "\\\\u00f2", "<22>" );
// output = output.replaceAll( "\\\\u00f3", "<22>" );
// output = output.replaceAll( "\\\\u00f4", "<22>" );
// output = output.replaceAll( "\\\\u00f5", "<22>" );
// output = output.replaceAll( "\\\\u00f9", "<22>" );
// output = output.replaceAll( "\\\\u00fa", "<22>" );
// output = output.replaceAll( "\\\\u00fb", "<22>" );
//
// output = output.replaceAll( "\\\\u0153", "&#156;" );
//
// output = output.replaceAll( "\\\\u2013", "-" );
// output = output.replaceAll( "\\\\u2014", "-" );
// output = output.replaceAll( "\\\\u2018|\\\\u2019", "'" );
// output = output.replaceAll( "\\\\u201c|\\\\u201d", "\"" );
//
// output = output.replaceAll( "\\\\u2022", "*" );
// output = output.replaceAll( "\\\\u2026", "..." );
return output;
}
public static void doLogin( Utilizador u )
{
if ( u != null )
{
Singleton.setInstance( Singleton.USERNAME, u.getLogin() );
}
else
{
ErrorLogger.logException( new Exception( "Utils.doLogin() : Utilizador is null !" ) );
}
}
public static void doLogout( FacesContext fc )
{
Singleton.setInstance( Singleton.USERNAME, null );
SessionBean1 sessionBean = JSFUtils.getSessionBean( fc );
sessionBean.setCurrentUser( null );
sessionBean.setLoggedIn( false );
String aatSessionID = sessionBean.getAatSessionID();
ExternalContext ec = fc.getExternalContext();
HttpSession session = ( HttpSession ) ec.getSession( false );
ServletContext paContext = session.getServletContext();
ServletContext aatContext = paContext.getContext( "/AnaliseAcidentesTrabalho" );
if ( aatContext != null && aatSessionID != null )
{
Map< String, Object > mapData = ( Map< String, Object > ) aatContext.getAttribute( aatSessionID );
if ( mapData != null )
{
HttpSession aatSession = ( HttpSession ) mapData.get( "session" );
try
{
aatSession.invalidate();
}
catch ( IllegalStateException e )
{
// ErrorLogger.logException( e );
System.out.println( "Session already invalidated." );
}
}
}
}
public static Integer getDefaultSelectedYear()
{
Integer result = null;
java.util.Calendar calendar = java.util.Calendar.getInstance();
calendar.setTime( new Date() );
result = calendar.get( java.util.Calendar.YEAR );
return result;
}
public static Option[] getYearDropValues()
{
Calendar calendar = Calendar.getInstance();
calendar.setTime( new Date() );
Integer currentYear = calendar.get( Calendar.YEAR );
Option[] opts = null;
try
{
int start = 0;
List< Integer > anosList = PlanosDataProvider.getInstance().getDistinctYears( null );
if ( anosList.contains( currentYear ) )
{
opts = new Option[ anosList.size() + 1 ];
opts[ start++ ] = new Option( 0, "Todos" );
}
else
{
opts = new Option[ anosList.size() + 2 ];
opts[ start++ ] = new Option( 0, "Todos" );
opts[ start++ ] = new Option( currentYear, currentYear.toString() );
}
Iterator< Integer > it = anosList.iterator();
for ( ; it.hasNext(); start++ )
{
Integer ano = it.next();
opts[ start ] = new Option( ano, ano.toString() );
}
}
catch ( Exception e )
{
ErrorLogger.logException( e );
}
return opts;
}
public static String getPageFrom(String referer)
{
String pageFrom = referer.substring(referer.lastIndexOf("/")+1);
return pageFrom;
}
}
Loading…
Cancel
Save