Finalrep NO1
Finalrep NO1
Class Design
1.1. General Class Diagram
<General class diagram which shows the whole class diagram of the software. This
diagram may have packages, subsystems and classes. Classes in this diagram may not have
all attributes and operations>
1.2. Class Diagrams
Class Diagram for Package View
4 getUser User Returns the current user interacting with the application.
Parameter:
o view: The view to be associated with the controller.
o user: The user interacting with the application.
Exception:
o Throws InitializationException if the initialization fails.
Method:
o Set the view and user attributes with the provided parameters to establish
context for the controller.
Parameter:
o view: The new view to be set for this controller.
Exception:
o None.
Method:
o Update the view attribute with the provided view.
Parameter:
o None.
Exception:
o None.
Method:
o Return the current view associated with the controller.
Parameter:
o None.
Exception:
o None.
Method:
o Return the user attribute, providing access to user-related data.
3. Operation: emptyCart()
Parameters:
None
Return Type:
void
Method:
This method empties the shopping cart by calling Cart.getCart().emptyCart().
It is invoked after a successful payment transaction to clear the cart, ensuring that the
user starts with an empty cart after completing a payment.
Operation 1: placeOrder()
Parameter:
o None.
Exception:
o Throws SQLException if there is an issue with accessing the database during
the availability check.
Method:
o Calls checkAvailabilityOfProduct() method in the Cart class to check if the
products in the cart are available before proceeding with the order placement.
Operation 2: createOrder()
Parameter:
o None.
Exception:
o Throws SQLException if there is an issue when interacting with the database
during order creation.
Return Type:
o Order: Returns an Order object created based on the products in the cart.
Method:
o Iterates through the media items in the cart, creates OrderMedia objects for
each item, and adds them to a new Order object, then returns the created
Order.
Operator Details:
Operator: updateOrderForRush(Order order)
Parameters:
o order: The Order object to be updated.
Method:
o Validates the address and the eligibility of items for rush order.
o Separates eligible rush items into a temporary list and then transfers them to
the LstRushOrderMedia.
o Removes rush items from the lstOrderMedia.
o Calculates both regular and rush shipping fees and updates the order.
Method:
o Creates and returns a new Invoice object based on the provided order.
Method:
o Checks if the delivery address is valid for rush orders. Only "Hà Nội" and
"Hồ Chí Minh" are considered valid.
Operator: validateEligible(List<OrderMedia> lstOrderMedia)
Parameters:
o lstOrderMedia: A list of OrderMedia objects.
Method:
o Checks if at least one OrderMedia item is eligible for a rush order. Returns
true if any eligible media is found.
Operator: calculateRegularShippingFee(Order order)
Parameters:
o order: The Order object for which the shipping fee needs to be calculated.
Method:
o Calculates the total value of the regular order.
o Determines if the order qualifies for free shipping (if total value exceeds
100,000 VND).
o Calculates the regular shipping fee based on the heaviest item’s weight and
the delivery city (inner city or elsewhere).
Operator: calculateRegularShippingFeeForItems(Order order, boolean isInnerCity)
Parameters:
o order: The Order object for which the shipping fee is to be calculated.
o Calculates the rush shipping fee using the heaviest item’s weight and the
delivery city, along with the additional rush fee.
o Returns the final rush shipping fee, including possible discounts for orders
over 100,000 VND.
Operator: calculateRushShippingFeeForItems(Order order, boolean isInnerCity)
Parameters:
o order: The Order object for which the rush shipping fee is to be calculated.
Operation Details
Operation 1: checkAvailabilityOfProduct()
Parameter:
o None.
Exception:
o Throws a SQLException if there is an issue with database access.
Method:
o Calls the checkAvailabilityOfProduct() method in the Cart class to check if
the products in the cart are available.
Operation 2: getCartSubtotal()
Parameter:
o None.
Return Type:
o int: Returns the subtotal amount of the products in the cart.
Method:
o Calls the calSubtotal() method of the Cart class to calculate the subtotal.
1.3.1.6. Class “HomeController”
1 getAllMedia() List<Media> Fetches all media records from the database and
returns them to be displayed.
Operation 1: getAllMedia()
Description: Fetches all media records from the database using the MediaRepository
and returns them to the Home screen for display.
Return Type:
o Returns a List<Media> containing all media objects retrieved from the
repository.
Exceptions:
o Throws SQLException if there is an error while fetching data from the
repository.
Method:
o Delegates the findAll operation to the MediaRepository instance to retrieve
media records.
o Suppresses unchecked warnings due to generic type handling.
1 getLabelAmount() Label Gets the label displaying the total cart amount.
5 requestToViewCart(prevScreen) void Handles the request to view the cart from the
previous screen.
Method Details:
Calculates the subtotal, VAT, and total amount for the cart.
Updates the labelSubtotal, labelVAT, and labelAmount labels with the
calculated values.
Operation: displayCartWithMediaAvailability() : void
o Parameters: None.
o Exceptions: IOException if media items cannot be displayed in the cart.
o Method:
2 getInvoice() Invoice Returns the invoice object associated with this form.
5 selectRushOrder() void Handles the selection of rush orders and updates the
UI and invoice accordingly.
9 updateInvoiceTotals() void Recalculates and updates the totals for the invoice.
Method Details:
Operation: setInvoiceInfo(invoice: Invoice) : void
o Parameters: invoice: The invoice object containing the details to display.
o Exceptions:
IOException, SQLException: If there's an issue loading the media
information.
ProcessInvoiceException: If there’s an error during invoice processing.
o Method:
Extracts the delivery information from the invoice and sets it to the
corresponding labels (name, province, address, instructions, subtotal,
etc.).
Calculates the total amount by adding the order amount and shipping
fees, then displays it.
Loops through the list of OrderMedia and displays each media item
using MediaInvoiceForm.
Operation: requestToPayOrder() : void
o Parameters: None.
o Exceptions:
IOException, SQLException: If there’s an issue during the payment
process.
o Method:
Creates an instance of VnPaySubsystem for payment processing.
Uses PaymentController to initiate the payment with the amount and
description.
Closes the current window (stage) once the payment is completed.
o Method: Returns the previous screen that navigated to the current one.
o Method: Displays the form in the associated stage. If the scene is not already set, it
creates a new scene and displays it.
o Method: Sets the controller that will handle the business logic of this form.
o Method: Sets the handler that can manage the home screen navigation.
1.3.2.4. Class “FXMLForm”
1 FXMLForm(screenPath: void Constructor that loads the FXML file and initializes the
String) content.
2 getContent() AnchorPane Returns the AnchorPane content loaded from the FXML
file.
3 getLoader() FXMLLoader Returns the FXMLLoader object used to load the FXML
file.
Operation Details:
Operation: FXMLForm(screenPath: String) : void
o Parameters: screenPath: The path to the FXML file to be loaded.
o Method: This constructor initializes the FXMLLoader, sets the
controller to the current instance, and loads the content into the
AnchorPane.
Operation: getContent() : AnchorPane
o Parameters: None.
o Method: Returns the AnchorPane content that was loaded from the
FXML file.
Operation: getLoader() : FXMLLoader
o Parameters: None.
o Method: Returns the FXMLLoader instance that was used to load the
FXML file.
Operation: setImage(imv: ImageView, path: String) : void
o Parameters:
imv: The ImageView to which the image will be set.
path: The path to the image file to be loaded.
o Method: Loads an image from the provided file path and sets it to the
given ImageView.
1 initialize(location: URL, void Initializes the logo image when the splash form is loaded.
resources:
ResourceBundle)
Operation Details:
Operation: initialize(location: URL, resources: ResourceBundle) : void
o Parameters:
1 VNPay(stage: Stage, screenPath: void Constructor to initialize the VNPay form and
String, paymentURL: String, listener: load the payment URL in a WebView.
TransactionResultListener)
3 handleUrlChanged(String newValue) void Handles the URL change when the payment
page redirects after payment completion.
Processes the payment response.
Operation Details:
Constructor: VNPay(Stage stage, String screenPath, String paymentURL,
TransactionResultListener listener, Order order)
Parameters:
o stage: The primary stage for the application window.
o screenPath: Path to the FXML layout of the current form.
o paymentURL: URL where the VNPay payment page is hosted.
o listener: A listener that handles the completion of the payment
transaction.
o order: The Order object linked to the current payment.
Functionality:
o Initializes the form by calling the parent constructor with stage and
screenPath.
o Loads the VNPay payment URL into a WebView to display the
payment interface.
o Sets up a listener to handle URL changes and detect when the payment
transaction has completed.
Operation: goBackToPrevious(MouseEvent event)
Parameters:
o event: The mouse event triggered when the user attempts to go back.
Method:
o Attempts to navigate back to the previous screen (likely the invoice
form) and displays it.
o If no previous screen exists, it logs a warning.
Operation: handleUrlChanged(String newValue)
Parameters:
o newValue: The new URL that the WebView has navigated to.
Method:
o This method is triggered when the URL changes (typically when
VNPay redirects after the payment process).
o If the URL contains the expected return URL
(VnPayConfig.vnp_ReturnUrl), it processes the payment response.
o It invokes the listener to notify that the transaction is complete and
updates the UI to show the result.
Operation: showResultScreen(PaymentTransaction transactionResult)
Parameters:
o transactionResult: The result of the payment transaction.
Method:
o Retrieves the result and message from the transactionResult.
o Creates an instance of ResultForm to show the payment result to the
user, including success status and a message.
o Displays the result screen with relevant details.
Operation: simulatePaymentSuccess()
Parameters: None
Method:
o Creates a dummy PaymentTransaction object with a success status.
o Simulates a successful payment by passing the dummy transaction to
the PaymentController and triggering the completion handler.
o Transitions to the result screen and displays the simulated result.
1 ResultForm(stage: Stage, void Constructor that initializes the ResultForm and sets the
screenPath: String, result: result and message.
boolean, message: String)
2 confirmPayment(event: void Handles the click event on the "OK" button to navigate
MouseEvent) back to the home screen.
Operation Details:
Operation: ResultForm(stage: Stage, screenPath: String, result: boolean,
message: String) : void
o Parameters:
stage: The current stage of the application.
screenPath: The path to the FXML screen.
result: The result of the payment transaction (SUCCESS or
FAILURE).
message: A message providing more details about the transaction.
o Method:
Initializes the result and message labels based on the transaction result.
If the result is true, the label shows "SUCCESS," otherwise it shows
"FAILURE."
Sets the behavior of the "OK" button to navigate back to the home
screen when clicked.
Operation: confirmPayment(event: MouseEvent) : void
o Parameters:
event: The mouse event that triggers the method.
o Method:
When the "OK" button is clicked, this method navigates to the home
screen. If the homeScreenHandler is not null, it shows the home
screen.
1.3.2.8. Class “MediaInvoiceForm”
2 setOrderMedia(OrderMedia void Sets the media information for the order and
orderMedia) prepares the UI.
3 removeOrderMedia(OrderMedia void Removes the OrderMedia from the invoice and
media) updates the UI.
Operation Details
1. Operation: setOrderMedia(OrderMedia orderMedia)
Parameters:
orderMedia: The OrderMedia object representing the specific media item
in the order.
Method:
Sets the OrderMedia object and updates the UI to display the media's title,
price, and quantity. Configures the remove button with an event handler to
remove the media item when clicked.
2. Operation: removeOrderMedia(OrderMedia media)
Parameters:
media: The OrderMedia item to be removed.
Method:
Removes the media's corresponding UI element (hboxMedia) from the
parent layout (AnchorPane) and notifies the delete handler to update the
invoice.
3. Operation: setMediaInfo()
Parameters: None.
Exceptions:
o SQLException: If there is an issue retrieving data related to the
media.
Method:
Displays the title, price, and quantity of the media item in the respective
UI components. It also sets the media image by loading it from the file
system. The image is resized to fit the designated space.
2 setCartMedia(cartMedia) void Assigns a CartMedia object to the form and updates the UI
with media details.
3 setMediaInfo() void Populates the form's UI components with details from the
assigned CartMedia object.
4 initializeSpinner() void Configures the quantity spinner and adds event handling
for user interactions.
Operation Details:
1. Constructor: MediaForm(String screenPath, CartForm cartScreen)
Parameters:
o screenPath: Path to the FXML file for this form.
o cartScreen: Reference to the parent cart screen (CartForm).
Method:
o Calls the FXMLForm constructor to initialize the form with the given
screen path.
o Aligns the hboxMedia to center.
3. Operation: setMediaInfo()
Parameters: None
Method:
o Updates the UI components (title, price, image) with the CartMedia
details.
o Configures the delete button to remove the item from the cart and
update the cart display.
o Calls initializeSpinner() to configure the quantity spinner.
4. Operation: initializeSpinner()
Parameters: None
Method:
o Configures a spinner with a range of 1 to 100 and initializes it with the
media's current quantity.
o Handles user interactions with the spinner:
Validates the desired quantity against the available stock.
Updates the cart's total price and quantity if the value changes.
o Updates the UI and notifies the parent cart screen (CartForm) of
changes.
1.3.2.10. Class “PopupForm”
2 popup(String, String, Boolean) PopupForm Creates a new pop-up form with the specified
message, image, and style.
4 error(String message) void Displays an error pop-up with a red error icon.
6 setImage(String path) void Sets the icon image for the pop-up using the
specified path.
Operation Details:
1. Constructor: PopupForm(Stage stage)
Parameters:
stage: The JavaFX stage where this pop-up will be displayed.
Method:
Initializes the PopupForm with the given stage and sets the layout using the
Configs.POPUP_PATH FXML file.
2 getMedia() Media Returns the media item associated with this form.
Operation Details:
1. Constructor: MediaForm(String screenPath, Media media, HomeForm home)
Parameters:
screenPath: The path to the FXML layout file for this form.
media: The media item to be displayed in this form.
home: Reference to the HomeForm that contains this media form.
Method:
Calls the FXMLForm constructor to initialize the form.
Assigns the provided media and home objects to class attributes.
Configures the addToCartBtn with an event listener that:
1. Validates the requested quantity against available stock.
2. Adds the media to the shopping cart or updates its quantity if already
in the cart.
3. Updates the UI (stock, cart total) and displays success or error
notifications using PopupForm.
2. Operation: getMedia()
Return Type:
Media: The media item associated with this form.
Method:
Returns the media item being displayed in this form.
3. Operation: setMediaInfo()
Parameters:
None
Method:
Configures the UI components of the form with the details of the assigned
Media object:
1. Sets the media's cover image using the image file path.
2. Displays the media's title, price, weight, and available stock.
3. Configures the spinner (spinnerChangeNumber) to allow selecting
a quantity between 0 and 100, with an initial value of 1.
1 HomeForm(Stage, String) - Constructor to initialize the form with a given stage and
FXML path.
2 getNumMediaCartLabel() Label Returns the Label displaying the number of items in the
cart.
3 getBController() HomeController Returns the business controller associated with this form.
5 initialize(URL, void Initializes the form, sets up media items, and attaches
ResourceBundle) event handlers.
6 setImage() void Sets the images for the application logo and cart icon.
7 addMenuItem(int, String, void Adds a menu item to the category dropdown menu.
MenuButton)
8 addMediaHome(List) void Populates the home screen with media items from a given
list.
Method Details:
2. Operation: getNumMediaCartLabel()
Return Type: Label
Method:
Returns the Label object that displays the number of media items in the cart.
3. Operation: getBController()
Return Type: HomeController
Method:
Displays the form and updates the number of media items in the cart by calling the
numMediaInCart.setText() method.
5. Operation: initialize(URL url, ResourceBundle rb)
Parameters:
url: The URL of the FXML resource.
rb: The resource bundle for internationalization.
Method:
Sets images for the application logo (aimsImage) and the cart icon (cartImage) by
loading image files.
7. Operation: addMenuItem(int position, String text, MenuButton menuButton)
Parameters:
position: The position in the menu where the item will be added.
text: The name of the media category (e.g., Book, DVD, CD).
menuButton: The MenuButton to which the item will be added.
Method:
Adds a menu item to the search filter, allowing users to filter media by category.
When a menu item is clicked, the media displayed is filtered according to the
selected category.
8. Operation: addMediaHome(List items)
Parameters:
items: The list of MediaForm objects to be displayed on the main screen.
Method:
Clears the existing media items in the hboxMedia container and updates it with
the filtered media items.
1 DeliveryForm(Stage stage, void Constructor for initializing the form with the
String screenPath, Order order) stage, screen path, and order.
2 initialize(URL url, void Initializes the form, setting up the focus behavior
ResourceBundle rb) and adding provinces to the combo box.
Operation Details:
2.Operation: initialize(URL url, ResourceBundle rb)
Parameters:
url: The URL of the FXML resource.
rb: The resource bundle for internationalization.
Method:
Sets the focus behavior on the name field when the form is loaded for the
first time. It ensures that focus is directed to the container if it's the first
time the form is loaded.
Adds a list of provinces to the province combo box from the
Configs.PROVINCES array.
3. Operation: submitDeliveryInfo(MouseEvent event)
Parameters:
event: The mouse event triggered when the user submits the form.
Method:
Collects all the delivery information entered by the user (name, phone,
address, instructions, and province) into a HashMap called messages.
Validates the delivery information using the processDeliveryInfo() method
from the controller (PlaceOrderController).
If the validation fails, an error message is displayed using the notifyError()
method.
Once the validation is successful, the shipping fees are calculated by
calling calculateShippingFee() on the controller and set in the order object.
Finally, an invoice is created using the createInvoice() method of the
controller, and the InvoiceForm is displayed to the user.
4. Operation: getBController()
Return Type: PlaceOrderController
Method:
3 getQuantity int Returns the quantity of the media item in the cart.
4 setQuantity void Sets the quantity of the media item in the cart.
6 getTotalMedia int Returns the total quantity of media items in the cart.
4 saveInvoice void Saves the invoice to the database (method not yet
implemented).
Operation 1: getOrder() : Order
Description:
o This method returns the Order object associated with the current invoice.
Parameters: None
Exception: None
Method:
o Simply returns the order instance variable.
2 getMediaById Media Fetches the media (Book) by its ID from the repository.
2 getMediaById Media Fetches the media (CD) by its ID from the repository.
2 getMediaById Media Fetches the media (DVD) by its ID from the repository.
Operation 3: updateMediaFieldById(tbname: String, id: int, field: String, value: Object) : void
Description: This method updates a specific field in the database for a given media item by
its ID.
Parameters:
o tbname (String): The name of the database table.
o id (int): The unique identifier of the media.
o field (String): The field to be updated.
o value (Object): The new value to set for the specified field.
Exception: Throws a SQLException if the operation fails.
Method:
o Executes an SQL UPDATE query to modify a specified field of the media in the
database.
1 getShippingFees() int Returns the total shipping fees for the order.
2 setShippingFees() void Sets the total shipping fees for the order.
6 getHeaviestItemWeight() double Returns the weight of the heaviest item in the order.
7 getRushOrderItems() int Returns the number of rush order items in the order.
Operation 1: getShippingFees() : int
Description: This method returns the total shipping fees for the order.
Parameters: None
Exception: None
Method:
o Returns the value of the shippingFees attribute.
1 media Media - The media item associated with the order (e.g., a
DVD, CD, etc.).
2 price int - The price of the media item per unit in the
order.
1 getMedia() Media Returns the Media object associated with the order.
2 getWeight() double Returns the weight of the media item associated with
the order.
3 setMedia() void Sets the Media object associated with the order.
6 getPrice() int Returns the price per unit of the media item.
7 setPrice() void Sets the price per unit of the media item.
8 isRushOrder() boolean Returns whether the media item is part of a rush order.
9 setRushOrder() void Sets whether the media item is part of a rush order.
Operation 8: isRushOrder() : boolean
Description: This method returns whether the media item is part of a rush order.
Parameters: None
Exception: None
Method:
o Returns the rushOrder attribute of the OrderMedia object.
1 buildPaymentURL(request String Builds and returns the full payment URL based on
: Request) the provided Request object.
2 buildParams(request: Map<String, String> Constructs the parameters for the payment URL.
Request) Includes transaction reference, amount, order details,
and other required fields.
3 buildHashData(params: String Generates the hash data string required for security
Map<String, String>) purposes, based on the provided parameters.
ResponseCode(String ResponseCode Constructor that initializes the enum with a code and its
code, associated exception supplier.
ExceptionSupplier
exceptionSupplier)
2 handle(String code) void Processes a given response code and throws the
associated exception if necessary.
Operation 1: findAll()
Description: Retrieves all media records (objects implementing the Media
interface) from the repository.
Parameters: None.
Exceptions: Throws SQLException if a database error occurs.
Method: Returns a list of Media objects retrieved from the database.
5 delete(id : int) void Deletes a CD media record from the repository based
on its ID.
2 findById(id : int) Media Retrieves a specific DVD record by its ID from the
repository.
3 save(media : Media) void Saves a new DVD media record to the repository,
including both Media and DVD table inserts.
5 delete(id : int) void Deletes a DVD media record from the repository based
on its ID.
1.3.4.4. Class “MediaRepositoryImpl”