Software编程讲解、辅导c/c++,CSS,Python程序设计
2021-05-13
Full Stack Development/Software Workshop 2Assignment 2Marks available: 50% of the module markIntroductionFor this assignment you will add the final components to the database server that was created for Assignment1 to create a full stack application. There is a completed version of Assignment 1 available for youto download from Canvas. It has been enhanced from the version that you completed for Assignment 1 soyou should download the new version rather than using your own. The enhancements are described below,where they are applicable.There are two main components that you will build for Assignment 2. Since there are two people to eachgroup, it makes sense for each student to complete one of the components. This will be discussed in moredetail below.The two components you must create are the client and the server for the Jabber platform. The client willhave a GUI developed using JavaFX and a controller. The server is a Java application that serves data toclients from the database. The client and server are connected to each other via sockets on localhost. Youmust use the port number that is specified below.The client and server should be developed as two separate projects. Do not put the clientand server code in the same project. It must be possible to run both the client and the serverindependently, i.e. not at the same time. Part of the testing of your submission will involveconnecting a separate client (developed by Ian, not yours) to your server and connectingyour client to a separate server (developed by Ian, not yours).The next section of this document will specify the requirements for your application. You should try andensure that all of the functionality described is present.There is no specified look or layout required of your GUI. You can design it to look however you want.However, it must allow the functionality that is described below.You must use the class JabberMessage and the protocol outlined below exactly as stated, and must uselocalhost and port 44444 for the connection. Apart from those, you may name your classes, etc. howeveryou wish.Make sure you have watched the final ‘wrap-up’ video before attempting this assignment.The only person you can share your code with in any way at all is your other team member.1Requirements of the Jabber social media applicationYour application should have the following functionality. Each GUI element that is referred to below hasbeen given a code such as T1, B1, etc. Note that as long as your GUI has the required functionality,you don’t need to use these specific types of GUI controls. You can use any other GUI controls you wantprovided they allow for the following functionality. The marks available for each correctly implementedrequirement are also shown. RQ1. Users should be able to sign in to the application by entering their username in a text field T1and by pressing a button B1 marked ‘Sign In’ to send the username to the server. Once the user issuccessfully signed in the GUI should somehow indicate this. [4 marks] RQ2. If the user enters an invalid username, i.e. a username that does not already exist in thedatabase, then the GUI should present an error dialog E1 advising the user that the usernameis invalid. The error dialog should be closable allowing the user further attempts to enter theirusername. [3 marks] RQ3. The user should be able to register for the application by entering their new username in thetext field T1 and by pressing a button B2 marked ‘Register’. The GUI should somehow indicate thatthe user has successfully registered. The new user should be signed in by the server without the userhaving to do this as a separate step. [4 marks] RQ4. The user should be able to sign out by pressing button B3 (which could be the same buttonas B1). This should disconnect the user from the server and close the client application. [2 marks] RQ5. Once the user is signed in, the application should present that user’s timeline in pane P1.This pane should have a header label saying ‘Timeline’. The format of each jab in the timelineshould be as shown below (it doesn’t need to actually look like this. It just needs to contain thisinformation). The ‘heart’ image you can see can look differently to that but some kind of image mustbe present there. The ‘heart’ here is the ‘like’ button (see RQ6). Note that in the enhanced versionJabberDatabase on Canvas, there is a new method called getTimelineOfUserEx() which retrievesall of the information you need for each jab, i.e. it returns the username of the user who posted thejab, the jab text, and the number of likes that jab has in total. This method also returns the jabidof each jab in the timeline but you should not display that. [7 marks]Figure 1: This jab has so far received 2 likes. RQ6. The user should be able to click a button to ‘like’ a jab that is in their timeline. There is onebutton B4a, B4b, ... for each jab. In the image above the button uses a ‘heart’ icon. If a user clickedthe heart button on the jab in figure 1 (and they have not already liked the jab1), the number shownnext to the heart button should change to 3 because there is now one more ‘like’ of this jab. Userscan’t ‘unlike’ a jab. [4 marks]1There is no need to check for this. The database will reject a second like by the same user of the same jab.2 RQ7. Once the user is signed in, the application should also present a list of registered users whothe signed-in user is not following in pane P2. This pane should have a header label saying ‘Whoto follow’. There is a new method in the JabberDatabase class for this: getUsersNotFollowed().The format of each user in this list should be as shown below (again, it doesn’t literally need to looklike this). [7 marks] RQ8 Each line of the list of ‘who to follow’ in P2 has the username of the user that could be followedand a button B5a, B5b, ... (shown here with a ‘+’ image), one for each user, that when clickedmakes the signed-in user follow the user listed. Once a user has been followed, their jabs should beimmediately (or very quickly) added to the timeline that is being displayed in P1. [5 marks]Figure 2: Pressing the ‘+’ image (button) makes the signed-in user follow ‘kim’. RQ9. Users should be able to post their own jab. For this there should be a text field T2 in whichthey enter the jab text and a button B6 that sends the jab to the server. Once posted the jab shouldappear in the user’s timeline2. [4 marks] RQ10. Each of the actions above must be reflected in the client of any affected users. For example,if users A and B are signed in, and user A follows user B, when user B posts a new jab it must alsoappear in the timeline of user A. This applies to all other operations. Where actions affect otherusers they must be reflected in the client of those users3. [10 marks]Items to download from CanvasMake sure you download all of the following files from Canvas. JabberDatabase.java. For Assignment 1, this file was called JabberServer.java. You should usethis new version. You should not need to change this file. You may do so if you wish but make sureyou don’t break it. JabberMessage.java. You must use this class in order to transfer data across the network. Notethat this class is supplied complete and does not need to be changed or added to. This class shouldbe used in the client and the server. You can simply put copies of this file in each of the two projects. The updated Jabber SQL files.ImplementationThe most important point to grasp in the first instance is that you and your partner must create twoseparate applications: the client and the server. These two applications must be developed in separateprojects in your chosen IDE (Eclipse, IntelliJ, etc.).2The SQL data has been updated since Assignment 1 to ensure that every user follows themselves.3One relatively easy way of achieving this is to set a timer in the client that automatically gets the timeline and user dataevery, say, one second.3The clients and the server will communicate with each other using sockets. The sockets must use theaddress ‘localhost’ and port 44444 for the connection.You should use the class JabberDatabase as your database class. This has all the methods you need to getthe data you need from the database. You may need to change the postgres password specified in the file foryour own system. It is best to create an instance of JabberDatabase for each separate client that connects.To exchange messages between client and server, both client and server must use the class JabberMessagethat can be downloaded from Canvas (simply copy it into both projects). JabberMessage has a ‘message’and ‘data’. The format of the messages required is specified in the section on the Jabber protocol below.You must use the protocol exactly as stated. No other messages are required. Make sure you have readand understood the final lecture (‘wrap up’ (under Week 11 on Canvas) before using this class).You should use the Model-View-Controller pattern to implement your client. This means that your shouldhave a class for your GUI (which is the view) and another class for a controller. The GUI class should notitself communicate directly with the server.The server application should be threaded in such a way as to allow multiple clients to connect at the sametime. Again, make sure you have read and understood the final lecture under Week 11 on Canvas.The Jabber client/server protocolYour client and server must adhere to the following protocol. All strings must be used exactly as shown.Note that once the user is signed in the client does not need to send the username for other requests. Theserver will have established a connection to the client so will know which client the message is from. P1a. Signing in (successful).– Client message: signin[space]username (the string ‘username’ should be the username that theuser entered in the GUI.)– Server reply message: signedin– Server reply data: NONE.Example client message: “signin edballs”Server reply (message): “signedin” P1b. Signing in (unsuccessful).– Client message: signin[space]username (the string ‘username’ should be the username that theuser entered in the GUI.)– Server reply message: unknown-user– Server reply data: NONE.Example client message: “signin blahblah” (a user not previously registered)Server reply (message): “unknown-user” P2. Registering.4– Client message: register[space]username (the string ‘username’ should be the username that theuser entered in the GUI4.)– Server reply message: signedin– Server reply data: NONE.Example client message: “register todd” (a user not previously registered)Server reply (message): “signedin” P3. Signing out.– Client message: signout– Server reply: the server does not reply to this request. P4. Getting the timeline– Client message: timeline.– Server reply message: timeline– Server reply data: {username, jabtext, jabid, likes-count} (one row for each jab in the timeline)5.Example client message: “timeline”Server reply (message): “timeline”Example Server reply (data): [{“ted”,“excellent”, “56”, “3”}{“bill”, “dude”, “58”, “2”}] P5. Getting the users (who to follow)– Client message: users– Server reply message: users– Server reply data: {username} (one row for each user who is not being followed by the user.)Example client message: “users”Server reply (message): “users”Example Server reply (data): [{“todd”}{“wilma”}] P6. Posting a jab.– Client message: post[space]jabtext (where ‘jabtext’ is the text of the jab.)– Server reply message: postedExample client message: “post my first jab”Server reply (message): “posted”4You can assume the username is unique. Note that there is no need to get an email address off the user. The server can(unrealistically) invent one.5Note that jabid is returned but is not displayed by the client.5 P7. Liking a jab.– Client message: like[space]jabid (where ‘jabid’ is the id of the jab to like.6)– Server reply message: postedExample client message: “like 14”Server reply (message): “posted” P8. Following a user.– Client message: follow[space]username (where ‘username’ is the user to follow.)– Server reply message: postedExample client message: “follow todd”Server reply (message): “posted”Working togetherBecause this project has two distinct parts, that are connected only by a predefined protocol, getting thecode of the two team members to work together should be straightforward. Provided your client and serverboth understand the protocol above then they can work together.One approach would be to work through the requirements in the order they are stated in. Get ‘signingin’ working on both client and server together, before moving on to the other requirements. This will giveyou a model to use for implementing the rest of the protocol. The only difference will be for some of therequirements is that data must also be returned to the client.In terms of sharing your code with each other, you should agree a naming system so that you can matchversions together so that you don’t get out of sync with each other. For example, in zip files namedclientRQ1 and serverRQ1 for the versions that both implement signing in (RQ1), and so on.You will both need both projects in your IDE so that you can test your work as you go along, but you asan individual will only be working on one of them. Your partner will have to send you their latest versionsof the files (via email) to put into the relevant project.If you choose to use some sort of version control system, e.g. Github, you must set your repository toprivate and grant access only to the two members. Failure to do this will result in a mark of zero for bothmembers of the group. You will also receive zero if any other public means of communication is used, orif your files are uploaded to any third-party website that is public.SubmissionEach team member must submit all of the following in a single zip file. Your client project (all files including Eclipse/IntelliJ files). Your server project (all files including Eclipse/IntelliJ files).6Remember, the jabid was returned by the server with the timeline.6 A text file (.txt format) containing the following information:– The name and ID of the student who created the server. This is very important. If we don’tknow this, and something doesn’t work, both students will lose marks.– The name and ID of the student who created the client. This is very important. If we don’tknow this, and something doesn’t work, both students will lose marks.– The main class name in the server, i.e. the one we need to run.– The main class name in the client, i.e. the one we need to run.– Notes about anything we should be aware of when marking, special instructions, etc.MarkingAll students will receive a mark out of 50.The marks for each fully functioning requirement are shown in the requirements section above. If yourapplication has the functionality described for a given requirement, and it works fully, both students willget the marks shown for that requirement.If your functionality for a given requirement is not correct then you may receive partial marks for thatrequirement, depending on how far your functionality deviates from the required functionality.If your functionality for a given requirement is not correct, we will try and ascertain if the problem is causedby your client or server or both. If it is caused by only one of those, and we know which student createdeach application (and there is no doubt about that) the marks will be awarded to the student whose functionalityis correct. The other student in the pair will get zero marks for that requirement. This is why itis very important for us to know exactly who did what in each team. If we have any doubt over the authorshipof each application then both students will get the partial marks mentioned in the previous paragraph.If the functionality for a requirement is missing then both students in the group will receive zero for thatrequirement.If one of your applications does not work at all, e.g. it doesn’t compile or can’t be started, or when starteddoes not function, then the student who created that application will receive a mark of zero for the wholeassignment. The other application will be tested using either the client or server created by Ian.If one of your applications does not work but the other does, and we do not know exactly who createdwhich application, then both students will receive half of the marks that the working application wouldhave received.If both of your applications do not work at all, e.g. it don’t compile or can’t be started, or when starteddo not function, then both students in the group will get a mark of zero for the whole assignment.7