CS 185C/286 - Homework 8

In this assignment, you will add a server component to my (not your) solution of homework 3, extending the work from the last lab.

Be sure to change the package name to edu.sjsu.cs175.hw08, also in the manifest.

First make a way of adding a quiz to the server, using a POST. Use POST because this the RESTful way of updating the database. Specifically, make a POST to http://localhost:8080/testbank/rest/quiz/add with form parameter questions, a string with multiple lines, where questions are separated by blank lines and correct responses start with a *. Here is the code to send a file with questions to the server. It uses the Apache HTTP components, which you can download from here. To compile and run, use

javac -Xlint:deprecation -cp path/to/httpcomponents-client-4.3.1/lib/\*:. AddQuestions.java
java -cp path/to/httpcomponents-client-4.3.1/lib/\*:. AddQuestions < questions.txt

You only need to use that classpath for the AddQuestions program, which is not an Android program. In Android, simply import the classes.

In the QuestionService class from the lab, remove the init method. Really remove it. Also remove the makeQuestion helper method (unless you use it).

Next make the GET query http://localhost:8080/testbank/rest/quiz/latest return the quiz with the largest ID number. You won't know what's in the database that is used for testing, so be sure to implement this correctly. You can make a MAX query in JPQL.

You'll only need one additional GET query, http://localhost:8080/testbank/rest/quiz/questions/id, where the ID is returned from the preceding query. That was already done as part of the lab. (Complete the lab if you haven't.) Use JAXB to turn the query result into XML. It won't quite be the same XML as in homework 3, so adapt the client.

Also add a POST query to send the user's reply to the server when the user has made a selection. The server should track how many times each choice was chosen. Add a count field to the Choice class and annotate it so that the preceding GET query will show the updates. Use JPQL to locate the Choice object that needs to be updated, and simply increment the count. You need not do anything else to get the new value in the database—session bean methods are transactional and automatically store any changes. Also, don't show the count in the Android client. The grader will just run the GET query to see that you did it right.

Put report.txt into the hw08 directory.

  1. Explain how you find the quiz with the largest ID
  2. Explain what changes you had to make to the XML parser of my solution to homework 3, and to any domain classes in the client.
  3. Explain how you designed the POST query. How did you decide what information to send back to the server? How did you figure out the JPQL code for finding the Choice object? What did you have to do to update the count?
  4. Describe which websites you visited for help, and which problems they helped you solve. Describe at least two such problems. Extra credit for each question that you asked. (Provide the URLs.)

Submit your work in two subfolders client and testbank of the hw08 directory.

Notes:

Due date: Wed. Dec 4 18:00