org.chorem.vradi.services.managers
Class MailingManager

java.lang.Object
  extended by org.chorem.vradi.services.managers.MailingManager

public class MailingManager
extends Object

Mailing manager.

Handle:

Author:
Yolpo, kmorin, chatellier

Field Summary
protected  org.nuiton.util.ApplicationConfig config
           
protected  FileService fileService
           
protected  FormTypeManager formTypeManager
           
protected static String SSL_FACTORY
           
protected  org.nuiton.wikitty.WikittyProxy wikittyProxy
           
 
Constructor Summary
MailingManager(org.nuiton.util.ApplicationConfig config, org.nuiton.wikitty.WikittyProxy wikittyProxy, FormTypeManager formTypeManager)
           
 
Method Summary
protected  String formatSessionLog(List<String> logs)
           
protected  List<File> generateFilledDocumentInPDF(File template, List<Form> forms, Map<String,String> fieldBindings, boolean replace)
          Generate offer PDF form given forms with specified template.
protected  File generateFilledDocumentInPDF(TemplateManager templateManager, Form form, Map<String,String[]> fieldBindings, boolean replace)
          Generate a single pdf file for specified form.
 String generatePDF(String formId, boolean force)
           
 void generatePDFForSession(String sessionId)
          Generate all the PDFs needed to send a session.
 File getGeneratedPdfFile(Form form)
          Return generated pdf file path containing form wikitty id and form version.
protected  String getHeaderValueInContent(String headerName, String content)
          Find a header definition in mail content.
protected  String getMineType(File file)
           
protected static Sending getSendingByMessageID(String messageID, org.nuiton.wikitty.WikittyProxy proxy)
          Find first sending entity with given messageID.
protected  String getStreamContent(InputStream inputStream)
          Convert an input stream to String.
 String postMail(String recipient, String subject, String message, List<Form> forms, boolean receptionProof, Collection<File> attachedFiles)
          Sends an email to the specified recipient with the specified subject and the specified message and the specified forms PDF.
 void receiveMails()
          Receives the emails and check if some are error emails or reception proofs and treat them in consequence.
 String sendMessage(String sendingId, String sessionParagraph, String email, boolean reSend, Collection<File> filesToAttach)
           
 String sendMessages(String sessionId)
           
protected  void setValidEmailForUser(Sending sending)
          Set User.FQ_FIELD_USER_VALIDEMAIL attribute for User associated with sending.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SSL_FACTORY

protected static final String SSL_FACTORY
See Also:
Constant Field Values

config

protected org.nuiton.util.ApplicationConfig config

wikittyProxy

protected org.nuiton.wikitty.WikittyProxy wikittyProxy

fileService

protected FileService fileService

formTypeManager

protected FormTypeManager formTypeManager
Constructor Detail

MailingManager

public MailingManager(org.nuiton.util.ApplicationConfig config,
                      org.nuiton.wikitty.WikittyProxy wikittyProxy,
                      FormTypeManager formTypeManager)
Method Detail

postMail

public String postMail(String recipient,
                       String subject,
                       String message,
                       List<Form> forms,
                       boolean receptionProof,
                       Collection<File> attachedFiles)
                throws VradiException
Sends an email to the specified recipient with the specified subject and the specified message and the specified forms PDF.

Parameters:
recipient - the email address of the recipient
subject - mail subject
message - mail content
forms - the list of forms to add to the mail
receptionProof - if true, ask for a reception proof
attachedFiles - files to attach
Returns:
the message id of the email sent
Throws:
VradiException

receiveMails

public void receiveMails()
                  throws VradiException
Receives the emails and check if some are error emails or reception proofs and treat them in consequence.

Throws:
VradiException

setValidEmailForUser

protected void setValidEmailForUser(Sending sending)
Set User.FQ_FIELD_USER_VALIDEMAIL attribute for User associated with sending.

Parameters:
sending -

getStreamContent

protected String getStreamContent(InputStream inputStream)
                           throws IOException
Convert an input stream to String.

Parameters:
inputStream -
Returns:
Throws:
IOException

getHeaderValueInContent

protected String getHeaderValueInContent(String headerName,
                                         String content)
Find a header definition in mail content.

Exemple:

 Original-Message-ID: <1833582695.1.1272991628810.JavaMail.chatellier@genux>
 Diagnostic-Code: smtp; 550 5.1.1 : Recipient address
      rejected: User unknown in local recipient table
 Message-ID: <804992706.5.1272991629788.JavaMail.chatellier@genux>
 

Parameters:
headerName -
content -
Returns:

getSendingByMessageID

protected static Sending getSendingByMessageID(String messageID,
                                               org.nuiton.wikitty.WikittyProxy proxy)
Find first sending entity with given messageID.

Parameters:
messageID - message id to find sending
proxy - wikitty proxy
Returns:
Sending or null if none found

getGeneratedPdfFile

public File getGeneratedPdfFile(Form form)
Return generated pdf file path containing form wikitty id and form version.

Parameters:
form - form
Returns:
generated pdf files

getMineType

protected String getMineType(File file)
                      throws IOException,
                             SAXException,
                             org.apache.tika.exception.TikaException
Throws:
IOException
SAXException
org.apache.tika.exception.TikaException

generatePDFForSession

public void generatePDFForSession(String sessionId)
                           throws VradiException
Generate all the PDFs needed to send a session.

Parameters:
sessionId - the session wikitty id
Throws:
VradiException

generatePDF

public String generatePDF(String formId,
                          boolean force)
                   throws VradiException
Throws:
VradiException

generateFilledDocumentInPDF

protected List<File> generateFilledDocumentInPDF(File template,
                                                 List<Form> forms,
                                                 Map<String,String> fieldBindings,
                                                 boolean replace)
                                          throws VradiException
Generate offer PDF form given forms with specified template.

Parameters:
template - template to use to generate PDF
forms - to to generate
fieldBindings - map between template field name and form fields names
replace - replace already existing generated forms
Returns:
generated pdf files
Throws:
VradiException - for various possible errors

generateFilledDocumentInPDF

protected File generateFilledDocumentInPDF(TemplateManager templateManager,
                                           Form form,
                                           Map<String,String[]> fieldBindings,
                                           boolean replace)
                                    throws VradiException
Generate a single pdf file for specified form.

Parameters:
templateManager - pdf template manager
form - form to get pdf
fieldBindings - association between field name and form fields (couple extension name, extension field)
replace - replace already existing pdf
Returns:
the pdf file associated with pdf
Throws:
VradiException - for various possible errors

sendMessages

public String sendMessages(String sessionId)
                    throws VradiException
Throws:
VradiException

formatSessionLog

protected String formatSessionLog(List<String> logs)

sendMessage

public String sendMessage(String sendingId,
                          String sessionParagraph,
                          String email,
                          boolean reSend,
                          Collection<File> filesToAttach)
                   throws VradiException
Throws:
VradiException


Copyright © 2009-2011 CodeLutin. All Rights Reserved.