Coder Social home page Coder Social logo

purduecs180's Introduction

EasyChat Documentation

Team 84

Purdue CS 180

May 3rd, 2021

Contributors: Felix Liu, Jiaqi Chen, Paul Fang, Silvia Yang, Teresa Huang.

Submission

  • Xiaoyu Liu Submitted code on Vocareum
  • Teresa Huang Submitted Report on Brightspace
  • Ziyang Fang Submitted Presentation on Brightspace

Compile and Run

Download and Compile

  1. Download the source code.
  2. Compile in an IDE of your choice.

Run the Code

1.RunMessageServerMaster.java.

2.RunMessageClient.javaand allow the program to run in parallel so that multiple clients can run at the same time.

Quit the application

  1. Click on the "X" on the upper right corner to end the client.
  2. Click on the red square in IntelliJ (or an IDE of your choice) to terminate MessageServerMaster.

Detailed Description of Each Class

System Classes

ServerMaster

This class ensures that every user has their own thread to connect to the server.

ServerWorker

This class will define what type of request is first and then sign the local variable“response” to it. Once the system finds it, it will go to find the corresponding response method. Next, the system will find the needed information and call the method from the message system to realize its objective. After collecting the information from the message system, it will send a response back to the client with the needed data.

Database

This class will save all the messages from the Message System, check if there is a txt, read the data and save it into a hashmap, then refresh the file, wait for the next message from the Message System, and it should have a function that can let Message System use the information which saves in the hashmap easily.

MessageSystem

This class contains many methods which are used to realize the specific implementation from the server and give a value back to the server.

MessageClient

This class contains the graphical user interface and functions for clients. There are four inner classes in MessageClient. TheMessageClientclass includes the main method and invokes the Window class. Thewindowclass contains the components in the graphical user interface, and the action listeners. TheClientWorkerfetches data from the server and processes data when the users do action. ClientWorker sends requests to the server and receives corresponding responses in order to implement the specified action. TheListDisplayis used by the JList for real-time updates to display conversations and messages.

Data Structure Classes

public class Conversation

The class stores the information of a conversation.

  • String nameThe name of the conversation.

  • UUID[] userUUIDsAn ArrayList containing the UUIDs of the members.

  • UUID adminUUIDThe UUID of the administrator.

  • UUID[] messageUUIDsAn ArrayList of the UUIDs of the messages.

public class Message

The class stores the information of a message.

  • UUID senderUUIDThe UUID of the message sender.

  • Date timeThe time that the message is sent.

  • String contentThe content of the message.

  • UUID conversationUUIDThe UUID of the conversation that the message belongs.

public class User

The class stores the information of the user.

  • Credential credentialThe credential of the user.

  • Profile profileThe profile of the user.

public class Credential

The class stores the credential of the user.

  • String usrNameThe username of the user.

  • String passwdThe password of the user.

public class Profile

The class stores the profile of the user.

  • String nameThe name of the user.

  • int ageThe age of the user

public abstract class Storable

The class stores UUIDs.

  • UUID uuidA unique and exclusive used to identify objects.

public class EventBag

The class stores the event that is used for live-update

  • ArrayList<User> newUsersnewly created users.

  • ArrayList<Conversation> newConversationsnewly created conversations.

  • HashMap<UUID, Arraylist<Message>> newMessagesnewly created messages.

  • ArrayList<User> users updatedUserspreviously existed users who changed their profile.

  • ArrayList<Conversation> updatedConversationspreviously existed conversations that are edited.

  • ArrayList<Message> updatedMessagespreviously existed messages that are edited.

  • ArrayList<UUID> removedUsersusers that are removed.

  • ArrayList<UUID> removedConversationsconversations that are removed.

  • ArrayList<UUID> removedMessagesmessages that are removed.

Exception Classes

RequestFailedException extends Exception

This exception could be called anyway, anything incorrect could be concluded as the request failed.

AuthorizationException extends RequestFailedException

This exception will be thrown if the user tries to action that is outside their authority such as deleting a message that is not created by the user.

ConversationNotFoundException extends RequestFailedException

This exception will be thrown if the provided conversationUUID could not be found.

IllegalContentExceptionx extends RequestFailedException

This exception will be thrown if there are special characters in the content.

InvalidConversationNameException extends RequestFailedExceptioin

This exception will be thrown if the name of the conversation is invalid.

InvalidPasswordException extends RequestFailedExceptioin

This exception will be thrown if the provided password does not match the credential in the system.

InvalidUsernameException extends RequestFailedExceptioin

This exception will be thrown if the provided username could not be found.

LoggedInException extends RequestFailedExceptioin

This exception will be thrown when the user tries to log in to the same account multiple times while the account is already logged in.

MessageNotFoundException extends RequestFailedExceptioin

This exception will be thrown if the provided message could not be found.

NotLoggedInException extends RequestFailedExceptioin

This exception will be thrown when the user is not logged in and tries to do action.

UserExistsException extends RequestFailedExceptioin

This exception will be thrown when the user tries to register for an account, but the username entered has been already taken.

UserNotFoundException extends RequestFailedExceptioin

This exception will be thrown when the provided user does not exist.

RequestParsingException extends Exception

This exception will be thrown if any failure occurs when parsing the request to a specific request.

Communication Classes

public abstract Request implements Serializable

The most basic request type. All requests extend this class.

  • UUID uuidthe universally unique identifier of the request.

public Response extends Request

The most basic response type. All responses extend this class.

  • boolean statewhether the request successes or fails.

  • String msgsome message to be passed.

  • UUID requestUUIDUUID of the corresponding request.

  • equestFailedException exceptionIfstate==false, this is the exception that caused the failure. Otherwise, it'snull.


AuthenticateRequest

This request is for logging in. If you are not logged in, you have no permission to perform other operations except register.

  • Credential credentiallogin credentials, including a username and a password.

→ The Response if the request is successful

  • Response

This is the most basic Response with no special fields. The following are all subclasses of Response.

  • Boolean statustrue means success, false means failure.

  • String msgmessage. Can benull.

  • UUID requestUUIDThe UUID for the request.

!! Possible Exceptions for a failed request

  • UserNotFoundExceptionusername does not exist

  • InvalidPasswordExceptionpassword is incorrect

  • InvalidUsernameExceptionThe username is invalid

  • LoggedInExceptionYou are already logged in, you cannot log in again

GetUserByNameRequest

Get the user's UUID by the username.

  • String NameThe user's username.

→ The Response if the request is successful

  • GetUserByNameResponse

The specific response that allows the users to get usernames.

  • UUID userUUIDThe corresponding UUID of the user

!! Possible Exceptions for a failed request

  • UserNotFoundExceptionThe provided username does not exist.

EditProfileRequest

Change the userprofile.

  • Profile profilenew profile

→ The Response if the request is successful

  • Response

The basic response.

!! Possible Exceptions for a failed request

  • NotLoggedInExceptionThe user tries to edit the profile but is logged out.

RegisterRequest

Registration.

  • Credential credential

  • Profile profile

→ The Response if the request is successful

RegisterResponse

  • UUID uuidYour ownUUID.

!! Possible Exceptions for a failed request

  • UserExistsExceptionUser already exists

  • InvalidUsernameExceptionThe username is invalid

  • InvalidPasswordExceptionThe password is invalid

DeleteAccountRequest

Delete the current account.

  • Credential credential

→ The Response if the request is successful

  • response

The basic response.

!! Possible Exceptions for a failed request

  • AuthorizationExceptioncredential error

  • UserNotFoundExceptionuser does not exist

LogOutRequest

Log out.

→ The Response if the request is successful

  • response

The basic response.

!! Possible Exceptions for a failed request

  • NotLoggedInExceptionYou are not currently logged in

PostMessageRequest

Sends a message.

  • UUID conversationUUID

  • Message messageNote: Onlymessage.contentis used. Other fields are neglected / auto-generated by the system.

→ The Response if the request is successful

  • PostMessageResponse

  • UUID messageUUID

  • Date dateThe time when the message was actually sent successfully.

!! Possible Exceptions for a failed request

  • NotLoggedInExceptionNot logged in.

  • ConversationNotFoundExceptionThe group chat does not exist or does not belong to you.

  • AuthorizationExceptionYou do not have permission to change this group chat.

  • IllegalContentExceptionThe content of the message is illegal. It is too long or contains illegal characters.

EditMessageRequest

Edit a message of your own.

  • UUID messageUUIDThe message's UUID being edited

  • String contentThe new content

→ The Response if the request is successful

  • EditMessageResponse

  • Date dateEditedThe actual time of successful modification

!! Possible Exceptions for a failed request

  • NotLoggedInExceptionNot logged in.

  • MessageNotFoundExceptionThe message does not exist, or you should not see it.

  • AuthorizationExceptionDoes not have permission to change this information (probably because it belongs to someone else)

  • IllegalContentExceptionThe content of the message is illegal. It is too long or contains illegal characters.

DeleteMessageRequest

Delete a message.

  • UUID messageUUIDThe message's UUID being deleted

→ The Response if the request is successful

  • response

The basic response.

!! Possible Exceptions for a failed request

  • NotLoggedInExceptionNot logged in.

  • MessageNotFoundExceptionThe message does not exist, or you should not see it.

  • AuthorizationExceptionDoes not have permission to change this information (probably because it belongs to someone else)

CreateConversationRequest

Creates a new group chat.

  • String name

  • UUID[] userUUIDs(If it is empty, create a single chat)

→ The Response if the request is successful

  • CreateConversationRsponse

The specific response to create a conversation.

  • UUID conversationUUIDThe UUID of the conversation

!! Possible Exceptions for a failed request

  • NotLoggedInExceptionNot logged in

  • InvalidConversationNameExceptionConversation name not valid

  • UserNotFoundExceptionThe invited users do not exist

DeleteConversationRequest

Delete the group chat.

  • UUID conversationUUIDThe UUID of the conversation you would like to delete

→ The Response if the request is successful

  • response

The basic response.

!! Possible Exceptions for a failed request

  • NotLoggedInExceptionNot logged in

  • ConversationNotFoundExceptionThe conversation does not exist.

RenameConversationRequest

Rename the group chat.

  • UUID conversationUUIDThe UUID of the conversation

  • String nameThe name of the conversation

→ The Response if the request is successful

  • response

The basic response.

!! Possible Exceptions for a failed request

  • NotLoggedInExceptionNot logged in

  • InvalidConversationNameExceptionConversation name not valid

  • ConversationNotFoundExceptionThe conversation does not exist.

AddUser2ConversationRequest

Pulls the user into the group chat.

  • UUID userUUIDThe invited user's UUID

  • UUID conversationUUIDThe conversation UUID

→ The Response if the request is successful

  • response

The basic response.

!! Possible Exceptions for a failed request

  • NotLoggedInExceptionNot logged in

  • ConversationNotFoundExceptionThe conversation does not exist.

  • UserNotFoundExceptionThe invited users do not exist

  • AuthorizationExceptionYou are not the administrator of the conversation

RemoveUserFromConversationRequest

Remove the user from the group chat.

  • UUID userUUIDThe user's UUID you want to remove

  • UUID conversationUUIDThe conversation UUID

→ The Response if the request is successful

  • response

The basic response.

!! Possible Exceptions for a failed request

  • NotLoggedInExceptionNot logged in

  • ConversationNotFoundExceptionThe conversation does not exist, or you do not belong to the group chat.

  • UserNotFoundExceptionThe user does not exist

  • AuthorizationExceptionYou are not the administrator of the conversation and cannot remove others.

  • RequestFailedExceptionYou cannot remove yourself.

SetConversationAdminRequest

Set the group chat administrator.

  • UUID userUUIDThe user's UUID you want to remove

  • UUID conversationUUIDThe conversation UUID

→ The Response if the request is successful

  • response

The basic response.

!! Possible Exceptions for a failed request

  • NotLoggedInExceptionNot logged in

  • ConversationNotFoundExceptionThe conversation does not exist, or you do not belong to the group chat.

  • UserNotFoundExceptionThe user does not exist

  • AuthorizationExceptionYou don't have permission to set admin.

QuitConversationRequest

The user voluntarily leaves the group chat. If the user is currently an administrator, the system will automatically set an administrator randomly. If the user is the last user in the group chat, then the group chat will be deleted.

  • UUID conversationUUIDThe conversation UUID

→ The Response if the request is successful

  • response

The basic response.

!! Possible Exceptions for a failed request

  • NotLoggedInExceptionNot logged in

  • ConversationNotFoundExceptionThe conversation does not exist, or you do not belong to the group chat.

ListAllUsersRequest

List the UUIDs of all users

→ The Response if the request is successful

  • ListAllUsersResponse

List all the user's UUIDs.

  • UUID[] userUUIDsThe UUIDs of all the users

!! Possible Exceptions for a failed request

  • NotLoggedInExceptionNot logged in

ListAllConversationsRequest

List all group chat UUIDs, including only the group chats that the user has participated in

→ The Response if the request is successful

  • ListAllUserConversationsResponse

The specific response to the request.

  • UUID[] conversationUUIDsThe UUIDs of all the conversations

!! Possible Exceptions for a failed request

  • NotLoggedInExceptionNot logged in

ListAllMessagesRequest

List all the message UUIDs of a group chat.

  • UUID conversationUUIDThe UUID of the conversation

→ The Response if the request is successful

  • ListAllMessagesResponse

The specific response to list all messages.

  • Messages[] userMessagesAn array of messages sent by all users in this conversation

!! Possible Exceptions for a failed request

  • NotLoggedInExceptionNot logged in

  • ConversationNotFoundExceptionThe conversation does not exist, or you do not belong to the group chat.

GetUserRequest

Pull a user by the user's UUID, but cannot see the password

  • UUID userUUIDThe UUID of the user

→ The Response if the request is successful

  • GetUserResponse

The specific response to get the user.

  • User userThe corresponding user.

!! Possible Exceptions for a failed request

  • NotLoggedInExceptionNot logged in

  • UserNotFoundExceptionThe user does not exist

GetConversationRequest

Pull a group chat by the conversation's UUID

  • UUID conversationUUIDThe UUID of the conversation

→ The Response if the request is successful

  • GetConversationResponse

The specific response to get the conversation

  • Conversation conversationThe corresponding conversation

!! Possible Exceptions for a failed request

  • NotLoggedInExceptionNot logged in

  • ConversationNotFoundExceptionThe conversation does not exist, or you do not belong to the group chat.

GetMessageRequest

Pull a message by the message's UUID

  • UUID messageUUIDThe UUID of the message

→ The Response if the request is successful

  • GetMessageResponse

    The specific response to get the message

  • Message message

    The corresponding message

!! Possible Exceptions for a failed request

  • NotLoggedInException

    Not logged in

  • MessageNotFoundException

    The message does not exist

GetMessageHistoryRequest

Pull the chat history of a group chat.

  • UUID conversationUUIDThe UUID of the conversation

→ The Response if the request is successful

  • GetMessageHistoryResponse

The specific response to get the message history

  • Message[] messagesAll the messages in the corresponding conversation

!! Possible Exceptions for a failed request

  • NotLoggedInExceptionNot logged in

  • ConversationNotFoundExceptionThe conversation does not exist, or you do not belong to the group chat.

GetEventFeedRequest

Update new users, group chats,and messages. Used to implement the live update. The client should request a new event every time. Incidents include:

-Add

-Rename/Edit

-Delete

→ The Response if the request is successful

  • GetEventFeedResponse The specific response containing all the updated information.

  • User[] newUsersNew users.

  • Conversation[] newConversationsNew group chat.

  • ashMap<UUID, Message[] newMessagesAll new messages for each group chat.

  • User[] updatedUsers usersUsers who existed before, but were edited.

  • Conversation[] updatedConversationsA group chat that existed before but was edited.

  • Message[] updatedMessagesMessages that existed before, but were edited.

  • UUID[] removedUsersThe users who are removed from a conversation

  • UUID[] removedConversationsThe conversations that are removed

  • UUID[] removedMessagesThe messages that are removed

!! Possible Exceptions for a failed request

  • NotLoggedInExceptionNot logged in

Testing

AutomaticTesting

All the automatic tests are conducted with JUnit 4. And for each method in Database and MessageSystem, one successful case and one exception expected case are provided.

Test for Database

The Database test is included in DatabaseTest.java, which contains a write method test. The write method contains all the methods that been used in the Database. So successful running of the write method will automatically mean that other methods are running without problems.

Note: this test case can be found atDatabaseTest.javain the root folder.

Test for MessageSystem

The MessageSystem test is more complicated than the database test. It is in the MessageSystemTest.java. Also, the adding, remove and edit method of each field had been tested with different Test methods. For instance, the test method for getUser included the addUser and deleteUser method so successful running of the getUserTest will approve that addUser and deleteUser could run in that situation. Another addUserExceptionExpected test method, which included throwing an expected exception when certain invalid input is provided, is also written in the test class. Every method in the MessageSystem contains an exception expected test case and a successfully running test case, to make sure the program didn't crash even invalid input is provided.

Note: this test case can be found atMessageSystemTest.javain the root folder.

Manual Testing

User’s action Expected response Test response
Start Client and Server. Show the sign-in page. Successfully shows.
Click the register button. Show the register page. Successfully shows.
Sign in with a non-exist username. Proper exception prompt shows. Exception prompt shows as expected.
While registering, enter valid input for name, age, username, and password. Create an account successfully. Successfully creates.
While registering, enter valid input for name, username, and password, but entering an invalid value for age. (Entered -1) Proper exception prompt shows. Exception prompt shows as expected.
While registering, enter valid input for name, username, and password, but entering an invalid value for age. (Entered “a”) Proper exception prompt shows. Exception prompt shows as expected.
While registering, enter valid input for name, age, and password, but entering a username that already exists. Proper exception prompt shows. Exception prompt shows as expected.
After registering, sign in with the proper username and password. Show the chatting room. Successfully shows.
After registering, sign in with the proper username but enter the wrong password. Proper exception prompt shows. Exception prompt shows as expected.
The main menu will be visible after signing in, then a new chat could be set up with the proper group name and invited users. Enter a valid group name and invite nobody. Show the group chatting room. Successfully shows.
Enter a valid group name and invite another user to use a username. Show the group chatting room with that person. Successfully shows.
Invite a person that does not exist. Proper exception prompt shows. Exception prompt shows as expected.
Sending a message in group chat. Show the conversation with the current date and time. Successfully shows.
Click setting and change profile, enter valid name and age. Shows edited profile in the My profile section. Successfully shows.
Click setting and change profile, enter the valid name but invalid age. Proper exception prompt shows. Exception prompt shows as expected.
Delete current account, and back to the log-in section, trying to log-in with that account. Proper exception prompt shows. Exception prompt shows as expected.
A creates a conversation and adds B to the conversation. The conversation appears in B's conversation list. Successfully shows.
One person sends a message. All the members in the conversation see the message within seconds. Successfully shows.
A sends a message and B tries to edit the message. Proper exception prompt shows. Exception prompt shows as expected.
A sends a message and B tries to delete the message. Proper exception prompt shows. Exception prompt shows as expected.
Edit the message then export. The file shows edited messages. Successfully shows.
Delete the message then export. The file does not show the deleted message. The deleted message was not shown.
Create a new conversation, send a message, exit the conversation, then re-enter the conversation. The sent message is retained. Successfully shows.
Create some conversations, log out, then log back in. The conversation history is retained. Successfully shows.
Log out then log back in, enter the conversation. The message history is retained. Successfully shows.
Delete a conversation from A's list. The deletion does not impact B's conversation list. Successfully shows.

Contributors: Felix Liu, Jiaqi Chen, Paul Fang, Silvia Yang, Teresa Huang.

purduecs180's People

Contributors

ysw2000 avatar feliconut avatar tsa5522 avatar fang296 avatar jacky-jq avatar

Stargazers

 avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.