/** {@inheritDoc} */
 @Override
 public boolean addContactByEmail(IUser user, String email) {
   boolean added = false;
   IContact contact = contactService.getByEmail(email);
   if (user != null && contact != null) {
     user.getContacts().add(contact);
     update(user);
     added = true;
   }
   return added;
 }
 /** {@inheritDoc} */
 @Override
 public boolean addContactByName(IUser user, String name) {
   boolean added = false;
   IContact contact = contactService.getByName(name);
   if (user != null) {
     user.getContacts().add(contact);
     update(user);
     added = true;
   }
   return added;
 }
 /** {@inheritDoc} */
 @Override
 public boolean removeContactById(IUser user, String contactId) {
   boolean result = false;
   if (user != null && contactId != null) {
     IContact contact = contactService.getById(contactId);
     if (contact.getId() != null) {
       user.getContacts().remove(contact);
       update(user);
       result = true;
     }
   }
   return result;
 }
 /** {@inheritDoc} */
 @Override
 public boolean delete(String id) {
   boolean deleted = false;
   IUser user = userRepository.findById(id);
   if (user != null) {
     IContact contact = user.getContact();
     if (contact != null && contact.getId() != null) {
       contactService.delete(contact.getId());
     }
     userRepository.delete(user);
     deleted = true;
   }
   return deleted;
 }
 /** {@inheritDoc} */
 @Override
 public boolean logout(String name, String password) {
   boolean disconnected = false;
   IUser user = getByNameAndPassword(name, password);
   if (user != null) {
     if (user.getContact() != null && user.getContact().isOnline()) {
       user.getContact().setOnline(false);
       connectionService.delete(user.getContact().getConnection().getId());
       user.getContact().setConnection(null);
       contactService.update(user.getContact());
       disconnected = true;
     }
   }
   return disconnected;
 }
 @Override
 public IUser login(String name, String password) {
   IUser user = userRepository.findByNameAndPassword(name, password);
   if (user != null) {
     if (user.getContact() != null && user.getContact().getId() != null) {
       user.getContact().setOnline(true);
       IConnection connection = connectionService.createConnection();
       user.getContact().setConnection(connection);
       contactService.update(user.getContact());
     }
   } else {
     user = createInstance();
     user.getContact().setOnline(false);
   }
   return user;
 }