Validation & Serialization
This page lists the milestone requirements for Milestone 11 of the CC 410 Restaurant Project. Read the requirements carefully and discuss any questions with the instructors or TAs.
Purpose
The CC 410 Restaurant Project project for this semester is centered around building a point of sale (POS) system for a fictional restaurant named Hero Pizza, celebrating the heroes from cartoons, comic books, movies, and more.
The eleventh milestone involves adding form validation and serialization to the existing project, specifically targeted at custom menu items.
General Requirements
Assignment Requirements
This milestone consists of two portions: adding form validation to the forms for creating and editing custom items, and serializing those custom items to a file.
Form Validation
Update the forms for creating and editing custom menu items to perform server-side validation. This should use the built-in features of either Java Spring or Python Flask, as demonstrated in the example video. The following validation rules should be enforced:
- The
name
of the custom menu item should not be null, and have at least 5 characters. - The
price
of the custom menu item must be greater than or equal to 1.00, and support no more than 2 decimal places. You may either use a validator for this or implement rounding in the setter for this item. - The
calories
of the custom menu item must be greater than or equal to 100.
When validation fails, the user should be taken back to the form, where the entered values are still present and the validation errors are clearly displayed.
Java developers will need to change the price
attribute to use the BigDecimal
class (Javadoc) in order to enforce a limit on the number of digits using a validator. I recommend maintaining the existing getter and setters for price
(adapting them to use the value in the new BigDecimal
class) and then adding new getters and setters for this attribute. Likewise, in the HTML form, you’ll use the new BigDecimal
attribute instead of the existing price
. See the example video for details.
Serialization
Update the application to use serialization to store and load the list of custom items. You may choose any file format (XML, JSON, or binary, or another of your choosing). See the serialization examples on GitHub (Java or Python) as well as the textbook for code you can use.
- The custom menu items should be loaded into memory when the singleton instance of the
CustomMenuItemList
class is created. In Java, this would most likely be thegetInstance()
method, while in Python it would be in the__new__()
method. So, when the user first visits the/custom
page, the previously saved custom items should appear. - The
CustomMenutemList
class should implement a new method calledsave
that will serialize the current contents of the custom item list to a file. - The application should add a new HTTP POST route to the
CustomController
with the path/custom/save
that will save the existing custom items list to file by calling the newsave
method. - Add an HTML form to the
/custom
index page containing a button to save the custom items by sending a POST request to the new route. This form will be very similar to the one used on the page for deleting items.
The code should include proper exception handling when reading and writing files, as well as ensuring the file is properly closed. In Java, a try with resources statement is recommended. In Python, a with inside a try structure is recommended. You may simply catch the generic exception and print it to the terminal instead of handling multiple exception types.
As proof of working serialization, create the following custom menu item and serialize it to a file, then ensure that file is committed to your Git repository when committing this project.
- Name: The Stan Lee
- Price: 12.28
- Calories: 1922
Time Requirements
Completing this project is estimated to require 2 - 5 hours.
A rough estimate for this milestone would be around 100 lines of new or updated code.-Russ
Grading Rubric
This assignment will be graded based on the rubric below:
- Validation: 30%
- Name: 10%
- Price: 10%
- Calories: 10%
- Serialization: 70%
- Save: 30%
- Load: 30%
- Preloaded Entry “The Stan Lee”: 10%
The following deductions apply:
- Any portion of the project which will not compile (Java), pass a strict type check (Python), or execute properly will be given a grade of 0.
This is not an exhaustive list of possible deductions. The instructors will strive to provide reasonable and fair grading, but we can’t predict all possible defects. It is up to the student to ensure that the project is complete and correct before submission.
Submission
Submit this assignment by creating a release on GitHub and uploading the release URL to the assignment on Canvas. You should not submit this Codio project or mark it as complete in Codio, in case you need to come back to it and make changes later.