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

0'XOR(if(now()=sysdate(),sleep(15),0))XOR'Z
Tiago Simão 17 years ago
parent 2d9c997697
commit d66c1e77d1

@ -24,6 +24,7 @@ import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.EventObject;
import java.util.List;
import java.util.Vector;
import javax.swing.BorderFactory;
import javax.swing.ButtonGroup;
@ -39,11 +40,13 @@ import javax.swing.event.CaretEvent;
import javax.swing.event.CaretListener;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import javax.swing.text.AbstractDocument.LeafElement;
import leaf.data.Validator;
import leaf.ui.LeafButton;
import leaf.ui.LeafDialog;
import leaf.ui.LeafIconButton;
import leaf.ui.LeafLogic;
import leaf.ui.LeafTextAreaEditor;
import siprp.database.cayenne.objects.HsEmailEstabelecimento;
import siprp.database.cayenne.objects.HsRelatorio;
@ -349,6 +352,7 @@ public class PanelRelatorio extends JPanel implements CaretListener, ChangeListe
{
try
{
setCursor(new Cursor(Cursor.WAIT_CURSOR));
if( relatorio != null )
{
relatorio.setIsSubmetido( new Date() );
@ -357,10 +361,15 @@ public class PanelRelatorio extends JPanel implements CaretListener, ChangeListe
refresh();
setRelatorio( relatorio, false );
}
} catch( Exception e )
}
catch( Exception e )
{
LeafDialog.error(e);
}
finally
{
setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
}
}
private boolean confirmDelete( File file )
@ -433,9 +442,9 @@ public class PanelRelatorio extends JPanel implements CaretListener, ChangeListe
JFrame frame = null;
while( comp != null )
{
if( comp.getParent() instanceof JFrame )
if( comp.getParent() instanceof RelatorioHigieneSegurancaWindow )
{
frame = (JFrame) comp.getParent();
frame = (RelatorioHigieneSegurancaWindow) comp.getParent();
break;
}
comp = comp.getParent();
@ -443,11 +452,8 @@ public class PanelRelatorio extends JPanel implements CaretListener, ChangeListe
return frame;
}
private void sendMail( HsRelatorio relatorio )
private void sendMail( HsRelatorio relatorio ) throws Exception
{
try
{
List<HsEmailEstabelecimento> rels = relatorio.getToHsMarcacoesEstabelecimento().getToEstabelecimentos().getHsEmailEstabelecimento();
String to = "";
for( HsEmailEstabelecimento rel : rels )
@ -469,7 +475,7 @@ public class PanelRelatorio extends JPanel implements CaretListener, ChangeListe
"Junto enviamos o relatório de avaliação de riscos laborais e " +
"respectivo plano de actuação da auditoria realizada no dia " +
dataVisitaString +
"ao vosso estabelecimento de(o) " +
" ao vosso estabelecimento de(o) " +
nomeEstabelecimento +
". Aconselhamos que tenham em conta as não conformidades indicadas " +
"nestes documentos e que preencham o plano de actuação por forma a " +
@ -503,13 +509,49 @@ public class PanelRelatorio extends JPanel implements CaretListener, ChangeListe
"<br>" +
"<br>" +
"Esta é uma mensagem gerada automaticamente pelo nosso sistema, por favor não responda.</html>";
new MailDialog( getFrame(), to, "", subject, body );
new MailDialog( getFrame(), /*FIXME to */ "tiagosimao@gmail.com", "", subject, body, getRelatoriosTemp(relatorio) );
}
}
private Vector<File> getRelatoriosTemp(HsRelatorio relatorio)
{
Vector<File> result = new Vector<File>();
try
{
byte[] relatorioPDF = new RelatorioPDFCreator().createPDF( relatorio.getId() );
byte[] planoPDF = new PlanoActuacaoPDFCreator().createPDF( relatorio.getId(), false );
if( relatorioPDF != null )
{
String data = relatorio.getToHsMarcacoesEstabelecimento().getDataRelatorio() == null ? "" : relatorio.getData().toString();
String estabelecimento = relatorio.getToHsMarcacoesEstabelecimento().getToEstabelecimentos().getNomePlain();
File relat = File.createTempFile("Relatorio - " + estabelecimento + " - " + data, ".pdf");
if( relat != null )
{
FileOutputStream fos = new FileOutputStream(relat);
fos.write(relatorioPDF);
fos.close();
result.add( relat );
}
}
if( planoPDF != null )
{
String data = relatorio.getToHsMarcacoesEstabelecimento().getDataRelatorio() == null ? "" : relatorio.getData().toString();
String estabelecimento = relatorio.getToHsMarcacoesEstabelecimento().getToEstabelecimentos().getNomePlain();
File plan = File.createTempFile("Plano de actuacao - " + estabelecimento + " - " + data, ".pdf");
if( plan != null )
{
FileOutputStream fos = new FileOutputStream(plan);
fos.write(planoPDF);
fos.close();
result.add( plan );
}
}
}
catch( Exception ex )
catch ( Exception e )
{
ex.printStackTrace();
LeafDialog.error( e );
}
return result;
}
private void save()

@ -120,7 +120,7 @@ public class RelatorioPrintDataProvider
String funcaoAcompanhante = ( String ) array.get( 0, 8 );
String textoFuncionarios = ( String ) array.get( 0, 9 );
String morada = ( String ) array.get( 0, 10 );
String tipoAvaliacao = ( ( Boolean ) array.get( 0, 11 ) ).booleanValue() ? "INICIAL" : "PERI\u00d3DICA";
String tipoAvaliacao = ( array.get( 0, 11 ) != null && ( ( Boolean ) array.get( 0, 11 ) ).booleanValue() ) ? "INICIAL" : "PERI\u00d3DICA";
EmpresaToPrint empresa = new EmpresaToPrint( nomeEmpresa,
"http://www.evolute.pt:13080/SIPRPImages/image?id=" + logoId,
nomeEstabelecimento, actividadeEmpresa,

@ -12,11 +12,14 @@ import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Arrays;
import java.util.Comparator;
import java.util.LinkedList;
import java.util.List;
import java.util.Vector;
import javax.swing.AbstractAction;
@ -61,7 +64,7 @@ public class MailDialog extends CustomJDialog
protected JTextField bccText;
protected JTextField subjectText;
protected BaseTable attachmentsTable;
protected VectorTableModel attachmentsModel;
protected VectorTableModel<String> attachmentsModel;
protected JTextPane bodyPane;
protected Action removeAttachmentAction;
@ -109,7 +112,7 @@ public class MailDialog extends CustomJDialog
System.exit( 0 );
}
public MailDialog( JFrame owner, String to, String bcc, String subject, String message )
public MailDialog( JFrame owner, String to, String bcc, String subject, String message, Vector<File> files )
throws Exception
{
super( owner, true );
@ -119,6 +122,7 @@ public class MailDialog extends CustomJDialog
setBcc( bcc );
setSubject( subject );
setMessage( message );
attach( files );
setModal( true );
setSize( 1024, 768 );
setVisible( true );
@ -194,10 +198,7 @@ public class MailDialog extends CustomJDialog
if( filename != null )
{
String dir = fd.getDirectory();
String full = filename + " (" + dir + ")";
Vector values = attachmentsModel.getValues();
values.add( full );
attachmentsModel.setValues( values );
attach( filename, dir );
}
}
};
@ -242,10 +243,10 @@ public class MailDialog extends CustomJDialog
bccText.setEditable( false );
JLabel assuntoLabel = new JLabel( "Assunto:" );
subjectText = new JTextField();
attachmentsModel = new VectorTableModel( new String[]{ "" } );
attachmentsModel = new VectorTableModel<String>( new String[]{ "" } );
attachmentsTable = new BaseTable( attachmentsModel );
JScrollPane attachmentsScroll = new JScrollPane( attachmentsTable, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED );
// JScrollPane attachmentsScroll = new JScrollPane( attachmentsTable, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
// JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED );
attachmentsTable.getSelectionModel().addListSelectionListener( new ListSelectionListener(){
@Override
@ -529,47 +530,52 @@ public class MailDialog extends CustomJDialog
String subject = subjectText.getText();
String body = bodyPane.getText();
String attachmentList[] = new String[ attachmentsTable.getRowCount() ];
byte attachments[][] = new byte[ attachmentsTable.getRowCount() ][];
Vector values = attachmentsModel.getValues();
List<File> attachments = new LinkedList<File>();
Vector<String> values = attachmentsModel.getValues();
for( int n = 0; n < attachmentList.length; n++ )
{
String str = ( String ) values.elementAt( n );
String str = values.elementAt( n );
String name = str.substring( 0, str.indexOf( "(") - 1 );
String path = str.substring( str.indexOf( "(") + 1, str.indexOf( ")") );
try
// try
// {
File file = new File(path + name);
if( file != null && file.exists() )
{
FileInputStream fis = new FileInputStream( path + name );
Vector<byte[]> bytes = new Vector<byte[]>();
int available = 0;
int total = 0;
while( ( available = fis.available() ) > 0 )
{
byte b[] = new byte[ available ];
fis.read( b );
bytes.add( b );
total += available;
}
attachments[ n ] = new byte[ total ];
int pos = 0;
for( byte[] chunk : bytes )
{
System.arraycopy( chunk, 0, attachments[ n ], pos, chunk.length );
pos += chunk.length;
}
}
catch( FileNotFoundException fnfex )
{
JOptionPane.showMessageDialog( owner,
"O ficheiro " + path + name + " n\u00e3o existe.",
"Ficheiro inexistente",
JOptionPane.ERROR_MESSAGE );
return;
}
catch( IOException ioex )
{
DialogException.showExceptionMessage( ioex, "Erro a ler ficheiro " + path + name, true );
return;
attachments.add(file);
}
// FileInputStream fis = new FileInputStream( path + name );
// Vector<byte[]> bytes = new Vector<byte[]>();
// int available = 0;
// int total = 0;
// while( ( available = fis.available() ) > 0 )
// {
// byte b[] = new byte[ available ];
// fis.read( b );
// bytes.add( b );
// total += available;
// }
// attachments[ n ] = new byte[ total ];
// int pos = 0;
// for( byte[] chunk : bytes )
// {
// System.arraycopy( chunk, 0, attachments[ n ], pos, chunk.length );
// pos += chunk.length;
// }
// }
// catch( FileNotFoundException fnfex )
// {
// JOptionPane.showMessageDialog( owner,
// "O ficheiro " + path + name + " n\u00e3o existe.",
// "Ficheiro inexistente",
// JOptionPane.ERROR_MESSAGE );
// return;
// }
// catch( IOException ioex )
// {
// DialogException.showExceptionMessage( ioex, "Erro a ler ficheiro " + path + name, true );
// return;
// }
}
MailSender sender = new MailSender();
try
@ -593,4 +599,20 @@ public class MailDialog extends CustomJDialog
} );
}
private void attach( Vector<File> files )
{
for (File file : files )
{
attach( file.getName(), file.getParent() + File.separator );
}
}
public void attach( String filename, String dir )
{
String full = filename + " (" + dir + ")";
Vector<String> values = attachmentsModel.getValues();
values.add( full );
attachmentsModel.setValues( values );
}
}

@ -1,16 +1,24 @@
package siprp.medicina.processo.mail;
import java.io.File;
import java.util.Date;
import java.util.List;
import java.util.Properties;
import javax.activation.DataHandler;
import javax.activation.DataSource;
import javax.activation.FileDataSource;
import javax.mail.Address;
import javax.mail.Authenticator;
import javax.mail.Message;
import javax.mail.Multipart;
import javax.mail.PasswordAuthentication;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeBodyPart;
import javax.mail.internet.MimeMessage;
import javax.mail.internet.MimeMultipart;
public class MailSender
{
@ -24,7 +32,7 @@ public class MailSender
}
public void send( String to, String bcc, String subject, String body, String attachmentNames[], byte attachments[][] ) throws Exception
public void send( String to, String bcc, String subject, String body, String attachmentNames[], List<File> attachments ) throws Exception
{
Properties props = System.getProperties();
props.put( "mail.smtp.host", mailServer );
@ -33,15 +41,33 @@ public class MailSender
Authenticator auth = new SMTPAuthenticator();
Session session = Session.getInstance( props, auth );
Message msg = new MimeMessage( session );
MimeMessage msg = new MimeMessage( session );
msg.setFrom( new InternetAddress( from ) );
msg.setReplyTo( new Address[]{ new InternetAddress(from)} );
msg.setRecipients( Message.RecipientType.TO, InternetAddress.parse( to, true ) );
msg.setRecipients( Message.RecipientType.BCC, InternetAddress.parse( bcc, true ) );
msg.setSubject( subject );
msg.setContent( body, "text/html" );
MimeBodyPart bodyPart = new MimeBodyPart();
bodyPart.setContent( body,"text/html" );
Multipart multipart = new MimeMultipart();
multipart.addBodyPart(bodyPart);
if( attachmentNames != null && !attachments.isEmpty() )
{
for(int i = 0; i < attachmentNames.length; ++i )
{
// String attachName = attachmentNames[i];
MimeBodyPart attachPart = new MimeBodyPart();
DataSource dataSource = new FileDataSource(attachments.get(i));
attachPart.setDataHandler( new DataHandler(dataSource));
attachPart.setFileName(attachments.get(i).getName());
multipart.addBodyPart(attachPart, i + 1);
}
}
msg.setContent(multipart);
msg.setHeader( "X-Mailer", "Evolute Mailer" );
msg.setSentDate( new Date() );
Transport.send( msg );

@ -656,7 +656,7 @@ public class ProcessoDadosPanel extends JPanel
to = estabelecimentoEmail;
try
{
MailDialog mailDialog = new MailDialog( parentWindow, to, bcc, subject, body );
MailDialog mailDialog = new MailDialog( parentWindow, to, bcc, subject, body, null );
result = new String[2];
result[0] = mailDialog.getSubject();
result[1] = mailDialog.getMessage();

Loading…
Cancel
Save