@Override
 public void deleteContact(MailingList mailingList, String contactUuid) throws BusinessException {
   MailingListContact contactToDelete = findContact(contactUuid);
   mailingList.deleteMailingListContact(contactToDelete);
   listRepository.update(mailingList);
   contactRepository.delete(contactToDelete);
 }
  /** Mailing list management. */
  @Override
  public MailingList createList(MailingList mailingList, User owner) throws BusinessException {
    // check if list identifier is unique (do not already exist)
    if (listRepository.findByIdentifier(owner, mailingList.getIdentifier()) == null) {
      // Setting extra fields.
      mailingList.setOwner(owner);
      mailingList.setDomain(owner.getDomain());
      MailingList createdList = listRepository.create(mailingList);

      return createdList;
    } else {
      String msg =
          "The current list you are trying to create already exists : "
              + mailingList.getIdentifier();
      logger.error(msg);
      throw new BusinessException(BusinessErrorCode.LIST_ALDREADY_EXISTS, msg);
    }
  }
 @Override
 public MailingList findByUuid(String uuid) throws BusinessException {
   MailingList mailingList = listRepository.findByUuid(uuid);
   if (mailingList == null) {
     String msg = "The current mailing list do not exist : " + uuid;
     logger.error(msg);
     throw new BusinessException(BusinessErrorCode.LIST_DO_NOT_EXIST, msg);
   }
   return mailingList;
 }
 @Override
 public void addContact(MailingList mailingList, MailingListContact contact)
     throws BusinessException {
   if (!mailingList.getMailingListContact().contains(contact)) {
     mailingList.addMailingListContact(contact);
     contactRepository.create(contact);
     listRepository.update(mailingList);
   } else {
     logger.debug("Concact already present : " + contact.getMail());
   }
 }
 @Override
 public void updateList(MailingList updatedMailingList) throws BusinessException {
   MailingList entity = findByUuid(updatedMailingList.getUuid());
   String newIdentifier = updatedMailingList.getIdentifier();
   if (!entity.getIdentifier().equals(newIdentifier)) {
     // The identifier was changed.
     // check if new list identifier is unique (do not already exist)
     if (listRepository.findByIdentifier(entity.getOwner(), newIdentifier) != null) {
       String msg = "Update failed : current list identifier  already exists : " + newIdentifier;
       logger.error(msg);
       throw new BusinessException(BusinessErrorCode.LIST_ALDREADY_EXISTS, msg);
     }
   }
   entity.setIdentifier(newIdentifier);
   entity.setDescription(updatedMailingList.getDescription());
   entity.setPublic(updatedMailingList.isPublic());
   if (updatedMailingList.getDomain() != null) entity.setDomain(updatedMailingList.getDomain());
   if (updatedMailingList.getOwner() != null) entity.setOwner(updatedMailingList.getOwner());
   listRepository.update(entity);
 }
 /** Mailing list contacts management. */
 @Override
 public MailingListContact findContactWithMail(String listUuid, String mail)
     throws BusinessException {
   MailingList list = listRepository.findByUuid(listUuid);
   MailingListContact contact = contactRepository.findByMail(list, mail);
   if (contact == null) {
     String msg = "The current contact you are trying to find do not exist : " + mail;
     logger.error(msg);
     throw new BusinessException(BusinessErrorCode.CONTACT_LIST_DO_NOT_EXIST, msg);
   }
   return contact;
 }
 @Override
 public List<MailingList> findAllList() {
   return listRepository.findAll();
 }
 @Override
 public void deleteList(String uuid) throws BusinessException {
   MailingList listToDelete = findByUuid(uuid);
   logger.debug("List to delete: " + uuid);
   listRepository.delete(listToDelete);
 }
 @Override
 public List<MailingList> findAllMyList(User user) {
   return listRepository.findAllListWhereOwner(user);
 }
 @Override
 public List<MailingList> searchListByUser(User user, String input) {
   return listRepository.searchListWithInput(user, input);
 }
 @Override
 public List<MailingList> findAllListByVisibility(User owner, boolean isPublic) {
   return listRepository.searchListByVisibility(owner, isPublic);
 }
 @Override
 public List<MailingList> searchListByVisibility(User owner, boolean isPublic, String input) {
   return listRepository.searchWithInputByVisibility(owner, isPublic, input);
 }
 @Override
 public MailingList findByIdentifier(User owner, String identifier) {
   return listRepository.findByIdentifier(owner, identifier);
 }