/** Accept the representation of a mail received from a sender, and create it. */
  @Override
  public void acceptRepresentation(Representation entity) throws ResourceException {
    final Form form = new Form(entity);
    final Mail mail = new Mail();
    mail.setStatus(Mail.STATUS_RECEIVED);

    // Look for an existing contact or create it.
    final String senderAddress = form.getFirstValue("senderAddress");
    final String senderName = form.getFirstValue("senderName");

    Contact contact = getObjectsFacade().lookForContact(senderAddress, this.mailbox);
    if (contact == null) {
      contact = new Contact();
      contact.setMailAddress(senderAddress);
      contact.setName(senderName);
    }
    mail.setSender(contact);

    mail.setMessage(form.getFirstValue("message"));
    mail.setSubject(form.getFirstValue("subject"));
    // form2.add("sendingDate", mail.getSendingDate().toString());
    final Series<Parameter> recipients = form.subList("recipient");
    for (final Parameter recipient : recipients) {
      contact = getObjectsFacade().lookForContact(recipient.getValue(), this.mailbox);
      if (contact == null) {
        contact = new Contact();
        final String[] recipientValues = recipient.getValue().split("\\$");
        contact.setMailAddress(recipientValues[0]);
        contact.setName(recipientValues[1]);
      }
      mail.getRecipients().add(contact);
    }
    getObjectsFacade().createMail(this.mailbox, mail);
  }
Exemple #2
0
  @Override
  public Contact getContactById(String contactId) {
    final Contact prototype = new Contact();
    prototype.setId(contactId);

    return getContact(prototype);
  }
Exemple #3
0
  @Override
  public Contact createContact(Contact contact) {
    contact.setId(Long.toString(new Date().getTime()));
    this.objectContainer.store(contact);
    this.objectContainer.commit();

    return contact;
  }