コード例 #1
0
 /**
  * Saves user.
  *
  * @param user {@link IUser}
  * @return result of operation
  */
 public boolean save(IUser user) {
   boolean saved = false;
   if (user != null && user.getContact() != null) {
     // TODO refine it
     user.getContact().setConnection(connectionService.createConnection());
     saved = super.save(user);
   }
   return saved;
 }
コード例 #2
0
 /** {@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;
 }
コード例 #3
0
 /** {@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;
 }
コード例 #4
0
 /** {@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;
 }
コード例 #5
0
 /** {@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;
 }
コード例 #6
0
 /** {@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;
 }
コード例 #7
0
 @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;
 }
コード例 #8
0
 /** {@inheritDoc} */
 @Override
 public IUser createInstance() {
   IUser user = new User();
   user.setContact(new Contact());
   return user;
 }