001         package com.croftsoft.apps.chat.server;
002    
003         import com.croftsoft.core.lang.NullArgumentException;
004         import com.croftsoft.core.security.Authentication;
005    
006         import com.croftsoft.apps.chat.request.CreateUserRequest;
007         import com.croftsoft.apps.chat.response.CreateUserResponse;
008         import com.croftsoft.apps.chat.user.User;
009         import com.croftsoft.apps.chat.user.UserId;
010         import com.croftsoft.apps.chat.user.UserStore;
011    
012         /*********************************************************************
013         * Creates a User.
014         *
015         * @version
016         *   2003-06-11
017         * @since
018         *   2003-06-11
019         * @author
020         *   <a href="https://www.croftsoft.com/">David Wallace Croft</a>
021         *********************************************************************/
022    
023         public final class  CreateUserServer
024         //////////////////////////////////////////////////////////////////////
025         //////////////////////////////////////////////////////////////////////
026         {
027    
028         private final UserStore  userStore;
029    
030         //////////////////////////////////////////////////////////////////////
031         //////////////////////////////////////////////////////////////////////
032    
033         public  CreateUserServer ( UserStore  userStore )
034         //////////////////////////////////////////////////////////////////////
035         {
036           NullArgumentException.check ( this.userStore = userStore );
037         }
038    
039         //////////////////////////////////////////////////////////////////////
040         //////////////////////////////////////////////////////////////////////
041    
042         public Object  serve ( CreateUserRequest  createUserRequest )
043         //////////////////////////////////////////////////////////////////////
044         {
045           Authentication  authentication
046             = createUserRequest.getAuthentication ( );
047    
048           try
049           {
050             UserId  userId = userStore.createUser ( authentication );
051    
052             return new CreateUserResponse ( userId );
053           }
054           catch ( IllegalArgumentException  ex )
055           {
056             return new CreateUserResponse ( true, null, true );
057           }
058         }
059    
060         //////////////////////////////////////////////////////////////////////
061         //////////////////////////////////////////////////////////////////////
062         }