|
|
|
@ -76,6 +76,7 @@ import javax.servlet.http.HttpServletRequest;
|
|
|
|
import org.apache.commons.validator.EmailValidator;
|
|
|
|
import org.apache.commons.validator.EmailValidator;
|
|
|
|
import pagestate.AnaliseAcidenteTrabalhoState;
|
|
|
|
import pagestate.AnaliseAcidenteTrabalhoState;
|
|
|
|
import pdf.PdfGenerator;
|
|
|
|
import pdf.PdfGenerator;
|
|
|
|
|
|
|
|
import shst.companydataloaders.SIPRPPropertiesLoader;
|
|
|
|
import utils.Utils;
|
|
|
|
import utils.Utils;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
@ -11189,9 +11190,10 @@ public class AnaliseAcidenteTrabalho extends AbstractPageBean
|
|
|
|
{
|
|
|
|
{
|
|
|
|
System.out.println( "BUT GRAVAR" );
|
|
|
|
System.out.println( "BUT GRAVAR" );
|
|
|
|
|
|
|
|
|
|
|
|
if ( getSessionBean1().getCurrentAnalise() == null ) //new analise
|
|
|
|
AnaliseAcidente analise = getSessionBean1().getCurrentAnalise();
|
|
|
|
|
|
|
|
if ( analise == null ) //new analise
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if ( validateDataOcorrencia() )
|
|
|
|
if ( validateDataOcorrencia( analise ) )
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if ( validationDepartmentSectionOk() )
|
|
|
|
if ( validationDepartmentSectionOk() )
|
|
|
|
{
|
|
|
|
{
|
|
|
|
@ -11240,11 +11242,10 @@ public class AnaliseAcidenteTrabalho extends AbstractPageBean
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else // edit analise
|
|
|
|
else // edit analise
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if ( validateDataOcorrencia() )
|
|
|
|
if ( validateDataOcorrencia( analise ) )
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if ( fieldsLenOk() )
|
|
|
|
if ( fieldsLenOk() )
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
AnaliseAcidente a = fillAnaliseFields();
|
|
|
|
AnaliseAcidente a = fillAnaliseFields();
|
|
|
|
Acidentado ac = null;
|
|
|
|
Acidentado ac = null;
|
|
|
|
ArrayList recs = null;
|
|
|
|
ArrayList recs = null;
|
|
|
|
@ -12826,9 +12827,9 @@ public class AnaliseAcidenteTrabalho extends AbstractPageBean
|
|
|
|
return a;
|
|
|
|
return a;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private boolean validateDataOcorrencia()
|
|
|
|
private boolean validateDataOcorrencia( AnaliseAcidente analise )
|
|
|
|
{
|
|
|
|
{
|
|
|
|
Date d = getCalDataOcorrencia();
|
|
|
|
Date d = analise == null ? getCalDataOcorrencia() : analise.getData_acidente();
|
|
|
|
if ( d == null )
|
|
|
|
if ( d == null )
|
|
|
|
{
|
|
|
|
{
|
|
|
|
getSessionBean1().setMsg( "Falta data da ocorrência!" );
|
|
|
|
getSessionBean1().setMsg( "Falta data da ocorrência!" );
|
|
|
|
@ -13213,22 +13214,22 @@ public class AnaliseAcidenteTrabalho extends AbstractPageBean
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
AnaliseAcidente analise = getSessionBean1().getCurrentAnalise();
|
|
|
|
int estado = 0;
|
|
|
|
int estado = 0;
|
|
|
|
int estado_assinatura = 0;
|
|
|
|
int estado_assinatura = 0;
|
|
|
|
if ( getSessionBean1().getCurrentAnalise() == null )
|
|
|
|
if ( analise == null )
|
|
|
|
{
|
|
|
|
{
|
|
|
|
estado = Global.ESTADO_SEG;
|
|
|
|
estado = Global.ESTADO_SEG;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
else
|
|
|
|
{
|
|
|
|
{
|
|
|
|
AnaliseAcidente a = getSessionBean1().getCurrentAnalise();
|
|
|
|
estado = analise.getEstado().intValue();
|
|
|
|
estado = a.getEstado().intValue();
|
|
|
|
estado_assinatura = analise.getEstado_assinatura().intValue();
|
|
|
|
estado_assinatura = a.getEstado_assinatura().intValue();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if ( estado == Global.ESTADO_SEG )
|
|
|
|
if ( estado == Global.ESTADO_SEG )
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if ( ! validateDataOcorrencia() )
|
|
|
|
if ( ! validateDataOcorrencia( analise ) )
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@ -15231,109 +15232,114 @@ public class AnaliseAcidenteTrabalho extends AbstractPageBean
|
|
|
|
// t.close();
|
|
|
|
// t.close();
|
|
|
|
// System.out.println("Email Enviado !!!!" );
|
|
|
|
// System.out.println("Email Enviado !!!!" );
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
private void sendEmailWithPdf( AnaliseAcidente a, String emailTo, String emailFrom, String assunto, String texto_email )
|
|
|
|
private void sendEmailWithPdf( AnaliseAcidente a, String emailTo, String emailFrom, String assunto, String texto_email )
|
|
|
|
throws Exception
|
|
|
|
throws Exception
|
|
|
|
{
|
|
|
|
{
|
|
|
|
System.out.println( "\nSEND EMAIL WITH PDF" );
|
|
|
|
boolean isDebug = SIPRPPropertiesLoader.getInstance().findProperty( "debug", false );
|
|
|
|
|
|
|
|
System.out.println( "\nAnaliseAcidenteTrabalho . sendEmailWithPdf() : debug ? " + isDebug );
|
|
|
|
|
|
|
|
|
|
|
|
System.out.println( "\temailTo : " + emailTo );
|
|
|
|
if ( ! isDebug )
|
|
|
|
System.out.println( "\temailFrom : " + emailFrom );
|
|
|
|
{
|
|
|
|
System.out.println( "\tAnaliseAcidente : " + ( a == null ? "null" : a.getId() ) );
|
|
|
|
System.out.println( "\temailTo : " + emailTo );
|
|
|
|
System.out.println( "\t\tTecnicoSaudeID : " + ( a == null ? "a null" : "" + a.getTecnico_saude_id() ) );
|
|
|
|
System.out.println( "\temailFrom : " + emailFrom );
|
|
|
|
System.out.println( "\t\tMedicoID : " + ( a == null ? "a 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();
|
|
|
|
UtilizadoresDataProvider udp = UtilizadoresDataProvider.getInstance();
|
|
|
|
|
|
|
|
|
|
|
|
Utilizador ut = udp.getUtilizador( a.getTecnico_saude_id() );
|
|
|
|
Utilizador ut = udp.getUtilizador( a.getTecnico_saude_id() );
|
|
|
|
Utilizador um = udp.getUtilizador( a.getMedico_id() );
|
|
|
|
Utilizador um = udp.getUtilizador( a.getMedico_id() );
|
|
|
|
// AnalisesDataProvider adp = new AnalisesDataProvider();
|
|
|
|
// AnalisesDataProvider adp = new AnalisesDataProvider();
|
|
|
|
AnalisesDataProvider adp = AnalisesDataProvider.getInstance();
|
|
|
|
AnalisesDataProvider adp = AnalisesDataProvider.getInstance();
|
|
|
|
|
|
|
|
|
|
|
|
Acidentado ac = adp.getAcidentado( a.getAcidentado_id() );
|
|
|
|
Acidentado ac = adp.getAcidentado( a.getAcidentado_id() );
|
|
|
|
Estabelecimento e = new Estabelecimento();
|
|
|
|
Estabelecimento e = new Estabelecimento();
|
|
|
|
e.setId( a.getEstabelecimento_id() );
|
|
|
|
e.setId( a.getEstabelecimento_id() );
|
|
|
|
e.setNome( adp.getEstabelecimentoNome( a.getEstabelecimento_id() ) );
|
|
|
|
e.setNome( adp.getEstabelecimentoNome( a.getEstabelecimento_id() ) );
|
|
|
|
Seccao s = adp.getSeccao( a.getSeccao_id() );
|
|
|
|
Seccao s = adp.getSeccao( a.getSeccao_id() );
|
|
|
|
Causa c = adp.getCausa( a.getCausas() );
|
|
|
|
Causa c = adp.getCausa( a.getCausas() );
|
|
|
|
ArrayList recList = adp.getRecomendacoesByAnalise( a.getId() );
|
|
|
|
ArrayList recList = adp.getRecomendacoesByAnalise( a.getId() );
|
|
|
|
Recomendacao[] recArray = new Recomendacao[ recList.size() ];
|
|
|
|
Recomendacao[] recArray = new Recomendacao[ recList.size() ];
|
|
|
|
ListIterator iter = recList.listIterator();
|
|
|
|
ListIterator iter = recList.listIterator();
|
|
|
|
int i = 0;
|
|
|
|
int i = 0;
|
|
|
|
while ( iter.hasNext() )
|
|
|
|
while ( iter.hasNext() )
|
|
|
|
{
|
|
|
|
{
|
|
|
|
Recomendacao rec = ( Recomendacao ) iter.next();
|
|
|
|
Recomendacao rec = ( Recomendacao ) iter.next();
|
|
|
|
recArray[i] = rec;
|
|
|
|
recArray[i] = rec;
|
|
|
|
i++;
|
|
|
|
i++;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
//Recomendacao recArray[] = (Recomendacao)recList.toArray();
|
|
|
|
|
|
|
|
ArrayList medList = adp.getMedidasByAnalise( a.getId() );
|
|
|
|
|
|
|
|
//Medida medArray[] = (Medida)medList.toArray();
|
|
|
|
|
|
|
|
Medida[] medArray = new Medida[ medList.size() ];
|
|
|
|
|
|
|
|
iter = medList.listIterator();
|
|
|
|
|
|
|
|
i = 0;
|
|
|
|
|
|
|
|
while ( iter.hasNext() )
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
Medida med = ( Medida ) iter.next();
|
|
|
|
|
|
|
|
medArray[i] = med;
|
|
|
|
|
|
|
|
i++;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
PdfGenerator pdf = new PdfGenerator( Global.IMAGE_FOLDER, e, ut, um, a, ac, s, recArray, medArray, c );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ByteArrayDataSource ds = new ByteArrayDataSource( pdf.generatePdf(), "application/pdf" );
|
|
|
|
|
|
|
|
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 += "<div>" + texto_email + "</div>";
|
|
|
|
|
|
|
|
html += "<body></html>";
|
|
|
|
|
|
|
|
msgBodyPart.setContent( html, "text/html" );
|
|
|
|
|
|
|
|
multipart.addBodyPart( msgBodyPart );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
MimeBodyPart pdfPart = new MimeBodyPart();
|
|
|
|
|
|
|
|
//pdfPart.setContent(ds,"application/pdf");
|
|
|
|
|
|
|
|
pdfPart.setDataHandler( new DataHandler( ds ) );
|
|
|
|
|
|
|
|
pdfPart.setHeader( "Content-Transfer-Encoding", "base64" );
|
|
|
|
|
|
|
|
pdfPart.setHeader( "Content-Disposition", "attachment" );
|
|
|
|
|
|
|
|
String pdfname = "Analise" + a.getAnalise_nr();
|
|
|
|
|
|
|
|
pdfPart.setFileName( pdfname );
|
|
|
|
|
|
|
|
multipart.addBodyPart( pdfPart, 1 );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 Pdf Enviado !!!! " + emailTo );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//Recomendacao recArray[] = (Recomendacao)recList.toArray();
|
|
|
|
|
|
|
|
ArrayList medList = adp.getMedidasByAnalise( a.getId() );
|
|
|
|
|
|
|
|
//Medida medArray[] = (Medida)medList.toArray();
|
|
|
|
|
|
|
|
Medida[] medArray = new Medida[ medList.size() ];
|
|
|
|
|
|
|
|
iter = medList.listIterator();
|
|
|
|
|
|
|
|
i = 0;
|
|
|
|
|
|
|
|
while ( iter.hasNext() )
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
Medida med = ( Medida ) iter.next();
|
|
|
|
|
|
|
|
medArray[i] = med;
|
|
|
|
|
|
|
|
i++;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
PdfGenerator pdf = new PdfGenerator( Global.IMAGE_FOLDER, e, ut, um, a, ac, s, recArray, medArray, c );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ByteArrayDataSource ds = new ByteArrayDataSource( pdf.generatePdf(), "application/pdf" );
|
|
|
|
|
|
|
|
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 += "<div>" + texto_email + "</div>";
|
|
|
|
|
|
|
|
html += "<body></html>";
|
|
|
|
|
|
|
|
msgBodyPart.setContent( html, "text/html" );
|
|
|
|
|
|
|
|
multipart.addBodyPart( msgBodyPart );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
MimeBodyPart pdfPart = new MimeBodyPart();
|
|
|
|
|
|
|
|
//pdfPart.setContent(ds,"application/pdf");
|
|
|
|
|
|
|
|
pdfPart.setDataHandler( new DataHandler( ds ) );
|
|
|
|
|
|
|
|
pdfPart.setHeader( "Content-Transfer-Encoding", "base64" );
|
|
|
|
|
|
|
|
pdfPart.setHeader( "Content-Disposition", "attachment" );
|
|
|
|
|
|
|
|
String pdfname = "Analise" + a.getAnalise_nr();
|
|
|
|
|
|
|
|
pdfPart.setFileName( pdfname );
|
|
|
|
|
|
|
|
multipart.addBodyPart( pdfPart, 1 );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 Pdf Enviado !!!! " + emailTo );
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public String butImprimir_action()
|
|
|
|
public String butImprimir_action()
|
|
|
|
|