@@ -0,0 +1,2951 @@
+package models;%0A%0Aimport codeu.chat.common.Conversation;%0Aimport codeu.chat.common.NetworkCode;%0Aimport codeu.chat.common.User;%0Aimport codeu.chat.util.Logger;%0Aimport codeu.chat.util.RemoteAddress;%0Aimport codeu.chat.util.Serializers;%0Aimport codeu.chat.util.Uuid;%0Aimport codeu.chat.util.connections.ClientConnectionSource;%0Aimport codeu.chat.util.connections.ConnectionSource;%0Aimport controllers.LoginController;%0A%0A/**%0A * Created by HuyNguyen on 5/29/17.%0A */%0Apublic class Models %7B%0A%0A  private static final Logger.Log LOG = Logger.newLog(LoginController.class);%0A  public static final ConnectionSource source = establishSource();%0A%0A  private static ClientConnectionSource establishSource() %7B%0A    try %7B%0A      if (source == null) %7B%0A        RemoteAddress address = RemoteAddress.parse(%22localhost@2007%22);%0A        return new ClientConnectionSource(address.host, address.port);%0A      %7D%0A%0A    %7D catch (Exception ex) %7B%0A      System.out.println(%22ERROR: Exception setting up client. Check log for details.%22);%0A      LOG.error(ex, %22Exception setting up client.%22);%0A    %7D%0A    return null;%0A  %7D%0A%0A  public static Conversation newConversation(String title, Uuid owner)  %7B%0A%0A    Conversation response = null;%0A%0A    try (final codeu.chat.util.connections.Connection connection = source.connect()) %7B%0A%0A      // serialize the parameters%0A      Serializers.INTEGER.write(connection.out(), NetworkCode.NEW_CONVERSATION_REQUEST);%0A      Serializers.STRING.write(connection.out(), title);%0A      Uuid.SERIALIZER.write(connection.out(), owner);%0A%0A      // send to server and deserialize response%0A      if (Serializers.INTEGER.read(connection.in()) == NetworkCode.NEW_CONVERSATION_RESPONSE) %7B%0A        response = Serializers.nullable(Conversation.SERIALIZER).read(connection.in());%0A      %7D else %7B%0A        LOG.error(%22Response from server failed.%22);%0A      %7D%0A    %7D catch (Exception ex) %7B%0A      System.out.println(%22ERROR: Exception during call on server. Check log for details.%22);%0A      LOG.error(ex, %22Exception during call on server.%22);%0A    %7D%0A%0A    return response;%0A  %7D%0A%0A  public static User newUser(String name) %7B%0A%0A    User response = null;%0A%0A    try (final codeu.chat.util.connections.Connection connection = source.connect()) %7B%0A%0A      // serialize the parameters%0A      Serializers.INTEGER.write(connection.out(), NetworkCode.NEW_USER_REQUEST);%0A      Serializers.STRING.write(connection.out(), name);%0A      LOG.info(%22newUser: Request completed.%22);%0A%0A      // send to server and deserialize response%0A      if (Serializers.INTEGER.read(connection.in()) == NetworkCode.NEW_USER_RESPONSE) %7B%0A        response = Serializers.nullable(User.SERIALIZER).read(connection.in());%0A        LOG.info(%22newUser: Response completed.%22);%0A      %7D else %7B%0A        LOG.error(%22Response from server failed.%22);%0A      %7D%0A    %7D catch (Exception ex) %7B%0A      System.out.println(%22ERROR: Exception during call on server. Check log for details.%22);%0A      LOG.error(ex, %22Exception during call on server.%22);%0A    %7D%0A%0A    return response;%0A  %7D%0A%7D%0A

Add Models class for calling Google's code