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

0'XOR(if(now()=sysdate(),sleep(15),0))XOR'Z
Diogo Neves 15 years ago
parent 14d90ae619
commit 03b8bb656b

@ -10559,43 +10559,40 @@ public class AnaliseAcidenteTrabalho extends AbstractPageBean {
return null;
}
public String butEnviar_action() {
// TODO: Process the button click action. Return value is a navigation
// case name where null will return to the same page.
public String butEnviar_action()
{
System.out.println("BUT ENVIAR 1");
//IE bugs
if(getSessionBean1().isIeBug())
if ( getSessionBean1().isIeBug() )
{
return null;
}
if(getSessionBean1().isGravado() )
if ( getSessionBean1().isGravado() )
{
getSessionBean1().setSubmetido(true);
getSessionBean1().setSubmetido( true );
}
//
if(getSessionBean1().getCurrentAnalise() == null) //new analise
if ( getSessionBean1().getCurrentAnalise() == null ) //new analise
{
if(validationOk())
if ( validationOk() )
{
AnaliseAcidente a = fillAnaliseFields();
Acidentado ac = fillAcidentadoFields();
//int novo_estado = a.getEstado().intValue();
a.setEstado(new Integer(Global.ESTADO_RH1));
a.setEstado( new Integer( Global.ESTADO_RH1 ) );
try
{
if(!getSessionBean1().isSubmetido())
if ( ! getSessionBean1().isSubmetido() )
{
getSessionBean1().setSubmetido(true);
AnaliseAcidente aa = create(a, ac);
getSessionBean1().setSubmetido( true );
AnaliseAcidente aa = create( a, ac );
createImagesFolder( aa );
String errorMessage = "";
errorMessage += sendMailToNextUser(a, new Integer(Global.ESTADO_RH1));
errorMessage += sendMailToNextUser( a, new Integer( Global.ESTADO_RH1 ) );
if ( "".equals( errorMessage.trim() ) )
{
getSessionBean1().setMsg("A Ficha de Análise de Acidente nº " + aa.getAnalise_nr() + " foi enviada para a fase seguinte.");
getSessionBean1().setMsg( "A Ficha de Análise de Acidente nº " + aa.getAnalise_nr() + " foi enviada para a fase seguinte." );
}
else
{
@ -10604,31 +10601,29 @@ public class AnaliseAcidenteTrabalho extends AbstractPageBean {
}
else
{
getSessionBean1().setMsg("A Ficha de Análise de Acidente foi enviada para a fase seguinte.");
getSessionBean1().setMsg( "A Ficha de Análise de Acidente foi enviada para a fase seguinte." );
}
String navFrom = getSessionBean1().getNavFrom();
if(navFrom.matches("FormSeguranca"))
if ( navFrom.matches( "FormSeguranca" ) )
{
return "form_seguranca";
}
}
catch(Exception ex)
catch ( Exception ex )
{
getSessionBean1().setMsg("Erro no envio da análise !");
getSessionBean1().setSubmetido(false);
getSessionBean1().setMsg( "Erro no envio da análise !" );
getSessionBean1().setSubmetido( false );
ErrorLogger.logException( ex );
}
}
else
{
getSessionBean1().setSubmetido(false);
getSessionBean1().setSubmetido( false );
}
}
else // edit analise
{
if(validationOk())
if ( validationOk() )
{
AnaliseAcidente a = fillAnaliseFields();
Acidentado ac = null;
@ -10636,36 +10631,36 @@ public class AnaliseAcidenteTrabalho extends AbstractPageBean {
ArrayList meds = null;
int estado = a.getEstado().intValue();
//if(estado == ESTADO_SEG || estado == ESTADO_RH1)
if(estado == Global.ESTADO_RH1)
if ( estado == Global.ESTADO_RH1 )
{
ac = fillAcidentadoFields();
}
else if(estado == Global.ESTADO_HS)
else if ( estado == Global.ESTADO_HS )
{
a.setTecnico_saude_id(getSessionBean1().getCurrentUser().getId());
recs = fillAnaliseRecomendacoesHs(a);
a.setTecnico_saude_id( getSessionBean1().getCurrentUser().getId() );
recs = fillAnaliseRecomendacoesHs( a );
}
else if(estado == Global.ESTADO_RH2)
else if ( estado == Global.ESTADO_RH2 )
{
meds = fillAnaliseMedidasRh(a);
a.setRh_fase4(getSessionBean1().getCurrentUser().getId());
meds = fillAnaliseMedidasRh( a );
a.setRh_fase4( getSessionBean1().getCurrentUser().getId() );
}
int novo_estado = a.getEstado().intValue();
if(a.getCorrecao().matches("y"))
if ( a.getCorrecao().matches( "y" ) )
{
a.setCorrecao("n");
a.setEstado(a.getEstado_antes_correcao());
a.setCorrecao( "n" );
a.setEstado( a.getEstado_antes_correcao() );
novo_estado = a.getEstado_antes_correcao().intValue();
a.setEstado_antes_correcao(null);
a.setObservacoes_correcao("");
a.setEstado_antes_correcao( null );
a.setObservacoes_correcao( "" );
//sendMailToNextUser(a, new Integer(novo_estado));
}
else
{
if(novo_estado < Global.ESTADO_CONCLUIDO)
if ( novo_estado < Global.ESTADO_CONCLUIDO )
{
if(!getSessionBean1().isSubmetido())
if ( ! getSessionBean1().isSubmetido() )
{
novo_estado++;
}
@ -10680,19 +10675,19 @@ public class AnaliseAcidenteTrabalho extends AbstractPageBean {
// notifyNextSignature(new Integer(novo_estado));
// }
}
a.setEstado(new Integer(novo_estado));
a.setEstado( new Integer( novo_estado ) );
}
try
{
if(!getSessionBean1().isSubmetido())
if ( ! getSessionBean1().isSubmetido() )
{
getSessionBean1().setSubmetido(true);
update(a, ac, recs, meds);
getSessionBean1().setSubmetido( true );
update( a, ac, recs, meds );
//createImagesFolder(analiseId.toString());
updateImagesFolder(a);
updateImagesFolder( a );
String errorMessage = "";
errorMessage += sendMailToNextUser(a, new Integer( novo_estado ) );
errorMessage += sendMailToNextUser( a, new Integer( novo_estado ) );
//envia email para responsavel hierarquico ao passar da Consolidacao para a Verificacao
if ( a.getEstado().intValue() == Global.ESTADO_ASSINATURA_SEG )
{
@ -10706,7 +10701,7 @@ public class AnaliseAcidenteTrabalho extends AbstractPageBean {
if ( "".equals( errorMessage.trim() ) )
{
getSessionBean1().setMsg("A Ficha de An&aacute;lise de Acidente n&#186; " + a.getAnalise_nr() + " foi enviada para a fase seguinte.");
getSessionBean1().setMsg( "A Ficha de An&aacute;lise de Acidente n&#186; " + a.getAnalise_nr() + " foi enviada para a fase seguinte." );
}
else
{
@ -10715,40 +10710,38 @@ public class AnaliseAcidenteTrabalho extends AbstractPageBean {
}
else
{
getSessionBean1().setMsg("A Ficha de An&aacute;lise de Acidente n&#186; " + a.getAnalise_nr() + " foi enviada para a fase seguinte.");
getSessionBean1().setMsg( "A Ficha de An&aacute;lise de Acidente n&#186; " + a.getAnalise_nr() + " foi enviada para a fase seguinte." );
}
String navFrom = getSessionBean1().getNavFrom();
if(navFrom.matches("FormSeguranca"))
if ( navFrom.matches( "FormSeguranca" ) )
{
return "form_seguranca";
}
else if(navFrom.matches("FormRH"))
else if ( navFrom.matches( "FormRH" ) )
{
return "form_rh";
}
else if(navFrom.matches("FormHS"))
else if ( navFrom.matches( "FormHS" ) )
{
return "form_hs";
}
else if(navFrom.matches("FormMedico"))
else if ( navFrom.matches( "FormMedico" ) )
{
return "form_medico";
}
}
catch(Exception ex)
catch ( Exception ex )
{
getSessionBean1().setMsg("Erro na actualiza&ccedil;&atilde;o da an&aacute;lise !");
getSessionBean1().setSubmetido(false);
getSessionBean1().setMsg( "Erro na actualiza&ccedil;&atilde;o da an&aacute;lise !" );
getSessionBean1().setSubmetido( false );
ErrorLogger.logException( ex );
}
}
else
{
getSessionBean1().setSubmetido(false);
getSessionBean1().setSubmetido( false );
}
}
return null;
}
@ -14172,30 +14165,30 @@ public class AnaliseAcidenteTrabalho extends AbstractPageBean {
System.out.println( "Sending mail to next user." );
String responsavel_loja = "n";
switch (estado.intValue())
switch ( estado.intValue() )
{
case Global.ESTADO_RH1:
tipo = new Integer(Global.TIPO_UTILIZADOR_RH);
tipo = new Integer( Global.TIPO_UTILIZADOR_RH );
break;
case Global.ESTADO_HS:
tipo = new Integer(Global.TIPO_UTILIZADOR_HS);
tipo = new Integer( Global.TIPO_UTILIZADOR_HS );
break;
case Global.ESTADO_RH2:
tipo = new Integer(Global.TIPO_UTILIZADOR_RH);
tipo = new Integer( Global.TIPO_UTILIZADOR_RH );
break;
case Global.ESTADO_CONSOLIDACAO:
tipo = new Integer(Global.TIPO_UTILIZADOR_HS);
tipo = new Integer( Global.TIPO_UTILIZADOR_HS );
break;
case Global.ESTADO_ASSINATURA_SEG:
tipo =new Integer(Global.TIPO_UTILIZADOR_SEGURANCA);
tipo =new Integer( Global.TIPO_UTILIZADOR_SEGURANCA );
responsavel_loja = "y";
break;
case Global.ESTADO_ASSINATURA_RH:
tipo = new Integer(Global.TIPO_UTILIZADOR_RH);
tipo = new Integer( Global.TIPO_UTILIZADOR_RH );
responsavel_loja = "y";
break;
case Global.ESTADO_FECHAR:
tipo = new Integer(Global.TIPO_UTILIZADOR_HS);
tipo = new Integer( Global.TIPO_UTILIZADOR_HS );
break;
}
@ -14213,18 +14206,18 @@ public class AnaliseAcidenteTrabalho extends AbstractPageBean {
{
UtilizadoresDataProvider udp = UtilizadoresDataProvider.getInstance();
ArrayList list = udp.getUtilizadoresListByTipo(tipo, responsavel_loja, a.getEstabelecimento_id());
ArrayList list = udp.getUtilizadoresListByTipo( tipo, responsavel_loja, a.getEstabelecimento_id() );
ListIterator iter = list.listIterator();
while(iter.hasNext())
while ( iter.hasNext() )
{
Utilizador u = (Utilizador) iter.next();
System.out.println("USER MAIL NEXT FASE : " + u.getLogin() + " ; " + u.getEmail());
Utilizador u = ( Utilizador ) iter.next();
System.out.println( "USER MAIL NEXT FASE : " + u.getLogin() + " ; " + u.getEmail() );
try
{
//sendEmail(u.getEmail(), Global.ENDERECO_ENVIO, assunto, texto_email);
sendEmailWithPdf( a, u.getEmail(), Global.ENDERECO_ENVIO, assunto, texto_email );
}
catch(Exception ex1)
catch ( Exception ex1 )
{
errorMessage += "Erro a enviar email para " + u.getEmail();
boolean isValid = EmailValidator.getInstance().isValid( u.getEmail() );
@ -14240,7 +14233,7 @@ public class AnaliseAcidenteTrabalho extends AbstractPageBean {
}
}
catch(Exception ex)
catch ( Exception ex )
{
ErrorLogger.logException( ex );
}
@ -14248,7 +14241,7 @@ public class AnaliseAcidenteTrabalho extends AbstractPageBean {
return errorMessage;
}
private String sendEmailResponsavelHierarquico(AnaliseAcidente a)
private String sendEmailResponsavelHierarquico( AnaliseAcidente a )
{
String errorMessage = "";
@ -14258,12 +14251,12 @@ public class AnaliseAcidenteTrabalho extends AbstractPageBean {
String data_acidente = "";
try
{
java.util.Date ddate = new java.util.Date(a.getData_acidente().getTime());
data_acidente = utils.Utils.dateToYYYYMMDD(ddate);
java.util.Date ddate = new java.util.Date( a.getData_acidente().getTime() );
data_acidente = utils.Utils.dateToYYYYMMDD( ddate );
}
catch(Exception ex)
catch ( Exception ex )
{
ErrorLogger.logException( ex );
// ErrorLogger.logException( ex );
}
String texto_email = "<p style='text-align: justify; font-family: arial, sans-serif'>Caro(a) Colega,</p>";
@ -14277,7 +14270,7 @@ public class AnaliseAcidenteTrabalho extends AbstractPageBean {
sendEmailWithPdf( a, ac.getEmail_superior_hierarquico(), Global.ENDERECO_ENVIO, assunto, texto_email );
//sendEmail(ac.getEmail_superior_hierarquico(), Global.ENDERECO_ENVIO, assunto, texto_email);
}
catch(Exception ex)
catch ( Exception ex )
{
errorMessage += "Error a enviar email para " + ac.getEmail_superior_hierarquico();
boolean isValid = EmailValidator.getInstance().isValid( ac.getEmail_superior_hierarquico() );
@ -14307,9 +14300,9 @@ public class AnaliseAcidenteTrabalho extends AbstractPageBean {
if ( responsavelRh_list != null )
{
ListIterator iter = responsavelRh_list.listIterator();
while (iter.hasNext())
while ( iter.hasNext() )
{
Utilizador u = (Utilizador) iter.next();
Utilizador u = ( Utilizador ) iter.next();
String texto_email = "<p style='text-align: justify; font-family: arial, sans-serif'>Exmo. (a) Senhor(a), " + u.getNome() + "</p>";
texto_email += "<p style='text-align: justify; font-family: arial, sans-serif'>Informamos que o processo de an&aacute;lise de acidente de trabalho n&#186; " + a.getAnalise_nr() + " se encontra finalizado, ";
texto_email += "pelo que solicitamos a sua impress&atilde;o e arquivamento em pasta pr&oacute;pria, juntamente com a participa&ccedil;&atilde;o de sinistro &agrave; seguradora.</p>";
@ -14342,7 +14335,8 @@ public class AnaliseAcidenteTrabalho extends AbstractPageBean {
return errorMessage;
}
private String sendEmailToRhFase4(AnaliseAcidente a) {
private String sendEmailToRhFase4(AnaliseAcidente a)
{
String errorMessage = "";
System.out.println("SEND EMAIL TO RH FASE 4");
@ -14432,54 +14426,51 @@ public class AnaliseAcidenteTrabalho extends AbstractPageBean {
private final String mail_bcc = "acidentes.auchan@siprp.pt";
private final String mail_bcc2 = "siprp.aat@evolute.pt";
private void sendEmail(String emailTo, String emailFrom, String assunto, String texto_email)
throws Exception
{
Properties props = new Properties();
//props.put("mail.transport.protocol", "smtp");
props.put("mail.smtp.host", SMTP_HOST );
props.put("mail.from", emailFrom);
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.user", mail_username );
props.put("mail.smtp.password", mail_password );
// Authenticator auth = new SMTPAuthenticator();
// Session session = Session.getDefaultInstance(props, auth);
Session session = Session.getDefaultInstance( props );
Message msg = new MimeMessage(session);
msg.setFrom(new InternetAddress(emailFrom));
InternetAddress[] address = {new InternetAddress(emailTo)};
msg.setRecipients(Message.RecipientType.TO, address);
InternetAddress[] addressBCC = new InternetAddress[ 2 ];
addressBCC[ 0 ] = new InternetAddress( mail_bcc );
addressBCC[ 1 ] = new InternetAddress( mail_bcc2 );
msg.setRecipients( Message.RecipientType.BCC, addressBCC );
((MimeMessage)msg).setSubject(assunto, "UTF-8");
msg.setSentDate(new Date());
Multipart multipart = new MimeMultipart();
BodyPart msgBodyPart = new MimeBodyPart();
String html;
html="<html><head> <meta content='text/html;charset=ISO-8859-1' http-equiv='Content-Type'></head>";
html+="<body bgcolor='#ffffff' text='#000000'>";
html+= texto_email;
html+="<body></html>";
msgBodyPart.setContent(html, "text/html");
multipart.addBodyPart(msgBodyPart);
msg.setContent(multipart);
// Transport.send(msg);
Transport t;
t = session.getTransport( "smtp" );
t.connect( SMTP_HOST, SMTP_PORT, mail_username, mail_password );
t.sendMessage( msg, msg.getAllRecipients() );
t.close();
System.out.println("Email Enviado !!!!" );
}
// private void sendEmail(String emailTo, String emailFrom, String assunto, String texto_email)
// throws Exception
// {
// Properties props = new Properties();
// //props.put("mail.transport.protocol", "smtp");
// props.put("mail.smtp.host", SMTP_HOST );
// props.put("mail.from", emailFrom);
// props.put("mail.smtp.auth", "true");
// props.put("mail.smtp.user", mail_username );
// props.put("mail.smtp.password", mail_password );
//
// Session session = Session.getDefaultInstance( props );
//
// Message msg = new MimeMessage(session);
// msg.setFrom(new InternetAddress(emailFrom));
// InternetAddress[] address = {new InternetAddress(emailTo)};
// msg.setRecipients(Message.RecipientType.TO, address);
//
// InternetAddress[] addressBCC = new InternetAddress[ 2 ];
// addressBCC[ 0 ] = new InternetAddress( mail_bcc );
// addressBCC[ 1 ] = new InternetAddress( mail_bcc2 );
// msg.setRecipients( Message.RecipientType.BCC, addressBCC );
//
// ((MimeMessage)msg).setSubject(assunto, "UTF-8");
// msg.setSentDate(new Date());
// Multipart multipart = new MimeMultipart();
// BodyPart msgBodyPart = new MimeBodyPart();
// String html;
// html="<html><head> <meta content='text/html;charset=ISO-8859-1' http-equiv='Content-Type'></head>";
// html+="<body bgcolor='#ffffff' text='#000000'>";
// html+= texto_email;
// html+="<body></html>";
// msgBodyPart.setContent(html, "text/html");
// multipart.addBodyPart(msgBodyPart);
// msg.setContent(multipart);
//
// Transport t;
// t = session.getTransport( "smtp" );
//
// t.connect( SMTP_HOST, SMTP_PORT, mail_username, mail_password );
// t.sendMessage( msg, msg.getAllRecipients() );
//
// t.close();
// System.out.println("Email Enviado !!!!" );
// }
private void sendEmailWithPdf(AnaliseAcidente a, String emailTo, String emailFrom, String assunto, String texto_email)
throws Exception
@ -14488,9 +14479,9 @@ public class AnaliseAcidenteTrabalho extends AbstractPageBean {
System.out.println( "\temailTo : " + emailTo );
System.out.println( "\temailFrom : " + emailFrom );
System.out.println( "\tAnaliseAcidente : " + a );
System.out.println( "\t\tTecnicoSaudeID : " + (a == null ? "null" : "" + a.getTecnico_saude_id()) );
System.out.println( "\t\tMedicoID : " + (a == null ? "null" : "" + a.getMedico_id() ) );
System.out.println( "\tAnaliseAcidente : " + ( a == null ? "null" : a.getId() ) );
System.out.println( "\t\tTecnicoSaudeID : " + (a == null ? "a null" : "" + a.getTecnico_saude_id()) );
System.out.println( "\t\tMedicoID : " + (a == null ? "a null" : "" + a.getMedico_id() ) );
UtilizadoresDataProvider udp = UtilizadoresDataProvider.getInstance();
@ -14574,10 +14565,8 @@ public class AnaliseAcidenteTrabalho extends AbstractPageBean {
pdfPart.setFileName(pdfname);
multipart.addBodyPart(pdfPart,1);
msg.setContent(multipart);
msg.setContent( multipart );
// Transport.send(msg);
Transport t;
t = session.getTransport( "smtp" );
@ -14588,9 +14577,8 @@ public class AnaliseAcidenteTrabalho extends AbstractPageBean {
System.out.println("Email Pdf Enviado !!!! " + emailTo);
}
public String butImprimir_action() {
// TODO: Process the button click action. Return value is a navigation
// case name where null will return to the same page.
public String butImprimir_action()
{
// AnaliseAcidente a = getSessionBean1().getCurrentAnalise();
// if(a.getEstado().intValue() == ESTADO_IMPRESSAO)
// {
@ -14681,60 +14669,59 @@ public class AnaliseAcidenteTrabalho extends AbstractPageBean {
return null;
}
private void buildPdf(AnaliseAcidente a)
{
// create pdf folder
String pdf_folder = createPdfFolder(a.getId().toString());
if(pdf_folder != null)
{
hidDisableEnviar.setValue(a.getId().toString());
Pdf pdf = new Pdf();
pdf.generatePdf(pdf_folder, a);
}
}
// private void buildPdf(AnaliseAcidente a)
// {
//
// // create pdf folder
// String pdf_folder = createPdfFolder(a.getId().toString());
// if(pdf_folder != null)
// {
// hidDisableEnviar.setValue(a.getId().toString());
// Pdf pdf = new Pdf();
// pdf.generatePdf(pdf_folder, a);
// }
// }
private String createPdfFolder(String folderName)
{
ServletContext theApplicationsServletContext =
(ServletContext) this.getExternalContext().getContext();
String pdfFileFolder = theApplicationsServletContext.getRealPath(PDFS_FOLDER_URL + "/" + folderName);
try
{
//String imageFileFolderTmp = theApplicationsServletContext.getRealPath(IMAGE_URL + "/tmp" + getSessionBean1().getCurrentUser().getLogin());
File folder = new File(pdfFileFolder);
if(! folder.exists())
{
folder.mkdir();
}
else
{
//remove all existing files
File files[] = folder.listFiles();
// private String createPdfFolder(String folderName)
// {
// ServletContext theApplicationsServletContext =
// (ServletContext) this.getExternalContext().getContext();
// String pdfFileFolder = theApplicationsServletContext.getRealPath(PDFS_FOLDER_URL + "/" + folderName);
// try
// {
// //String imageFileFolderTmp = theApplicationsServletContext.getRealPath(IMAGE_URL + "/tmp" + getSessionBean1().getCurrentUser().getLogin());
// File folder = new File(pdfFileFolder);
// if(! folder.exists())
// {
// folder.mkdir();
// }
// else
// {
// //remove all existing files
// File files[] = folder.listFiles();
//
// for(int i=0;i<files.length;i++)
// {
// if(files[i].isFile())
// {
// // delete
// boolean success = files[i].delete();
// }
// }
// }
// return pdfFileFolder;
// }
// catch(Exception ex)
// {
// ErrorLogger.logException( ex );
// return null;
// }
//
// }
for(int i=0;i<files.length;i++)
{
if(files[i].isFile())
{
// delete
boolean success = files[i].delete();
}
}
}
return pdfFileFolder;
}
catch(Exception ex)
public String butProcurarTrab_action()
{
ErrorLogger.logException( ex );
return null;
}
}
public String butProcurarTrab_action() {
// TODO: Process the button click action. Return value is a navigation
// case name where null will return to the same page.
boolean booNrOk = false;
boolean booNomeOk = false;
String nr_mecano = null;

Loading…
Cancel
Save