0% found this document useful (0 votes)
32 views74 pages

Finalrep NO1

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
32 views74 pages

Finalrep NO1

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 74

1.

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

Class Diagram for Package Controller:


Class Diagram for package entity

Class Diagram for package repository


1.3. Class Design
1.3.1. Controller Package

1.3.1.1. Class “BaseController”


<SampleClass1 class image in UML>
Table 1. Example of attribute design

# Name Data type Default value Description


1 view BaseScreenHandler N/A Reference to the view associated with this
controller.

2 user User N/A Reference to the user interacting with the


application.

Table 2. Example of operation design

# Name Return type Description (purpose)


1 initialize void Initializes the controller with the view and user data.

2 setView void Sets the view for the controller.

3 getView BaseScreenHandler Retrieves the current view associated with the


controller.

4 getUser User Returns the current user interacting with the application.

Operation 1: initialize(view: BaseScreenHandler, user: User) : void

 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.

Operation 2: setView(view: BaseScreenHandler) : void

 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.

Operation 3: getView() : BaseScreenHandler

 Parameter:
o None.
 Exception:
o None.
 Method:
o Return the current view associated with the controller.

Operation 4: getUser() : User

 Parameter:
o None.
 Exception:
o None.
 Method:
o Return the user attribute, providing access to user-related data.

1.3.1.2. Class “PaymentController”

Table 3. Attribute design

# Name Data type Default value Description


1 paymentService IPayment N/A The payment service
used to handle
payment transactions
(e.g., VNPay).

2 amount int N/A The total amount to


be paid for the order.

3 orderInfo String N/A Information related


to the order being
processed (e.g., order
details).

4 paymentTransactionRepository PaymentTransaction N/A Repository


responsible for
Repository
saving payment
transaction data to
the database.

Table 4. Example of operation design

# Name Return type Description (purpose)


1 payOrder(int, String) void Initiates the payment process by
invoking the payOrder method of the
payment service.

2 onTransactionCompleted(PaymentTransaction) void Handles the completion of a payment


transaction. It processes the result and
performs actions based on success or
failure.

3 emptyCart() void Empties the shopping cart after a


successful payment.
1. Operation: payOrder(int amount, String orderInfo)
Parameters:
 amount: The total amount to be paid (in integer form).
 orderInfo: A string containing the details of the order.
Return Type:
void
Method:
 This method initiates the payment process by calling the payOrder() method of the
paymentService (which implements IPayment).
 It takes the total payment amount and the order details as arguments and delegates the
responsibility to the external payment service to generate a payment URL or process
the payment.
 The actual payment service (like VNPay) is responsible for handling the payment via
external systems.

2. Operation: onTransactionCompleted(PaymentTransaction transactionResult)


Parameters:
 transactionResult: A PaymentTransaction object that contains the result of the
transaction.
Return Type:
void
Method:
 This method is called when the payment transaction is completed.
 If the transaction is successful, it saves the transaction details into the database using
the paymentTransactionRepository and clears the cart using the emptyCart() method.
 If the transaction fails, it logs the failure message (either from the transactionResult
object or a generic error message).
 This method is part of the TransactionResultListener interface and is used as a
callback after the payment is processed.

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.

1.3.1.3. Class “PlaceOrderController”

Table 5. Example of attribute design

# Name Data type Default value Description


1 LOGGER Logger N/A Logger for logging messages and debugging
information.
Table 6. Example of operation design

# Name Return type Description (purpose)


1 placeOrder() void Initiates the order placement process by checking
product availability.

2 createOrder() Order Creates and returns a new Order object based on


the cart's media items.

3 createInvoice() Invoice Creates an invoice for the given order.

4 processDeliveryInfo() void Validates and processes delivery information. If


the data is valid, it proceeds with the order
placement process.

5 validateDeliveryInfo() void Validates the delivery fields (name, phone


number, and address) and throws an exception if
they are invalid.

6 validatePhoneNumber() boolean Validates the phone number format (must be 10


digits or start with +84).

7 validateName() boolean Validates the name format (letters and spaces


only, with a maximum length of 30 characters).

8 validateAddress() boolean Validates the address format (letters, numbers,


and punctuation, with a maximum length of 100
characters).

9 calculateShippingFee() int Calculates the shipping fee based on the heaviest


item's weight and delivery city.

10 calculateShippingFeeForItems() int Helper function that calculates shipping fees


based on weight and whether the delivery is
within a city or not.

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.

Operation 3: createInvoice(Order order)


 Parameter:
o Order order: The order for which the invoice is created.
 Return Type:
o Invoice: Returns an Invoice object created based on the given order.
 Method:
o Creates a new Invoice object using the provided Order and returns it.

Operation 4: processDeliveryInfo(HashMap<String, String> info)


 Parameter:
o info: A HashMap containing the delivery information (name, phone, address).
 Exception:
o Throws IOException if an I/O error occurs during processing.
 Method:
o Logs the delivery information and calls validateDeliveryInfo() to validate the
delivery details.

Operation 5: validateDeliveryInfo(HashMap<String, String> info)


 Parameter:
o info: A HashMap containing the delivery information to be validated (name,
phone, address).
 Exception:
o Throws InvalidDeliveryInfoException if any of the delivery fields are invalid
(name, phone, or address).
 Method:
o Validates the name, phone number, and address using regular expressions. If
any field is invalid, it throws an exception.

Operation 6: validatePhoneNumber(String phoneNumber)


 Parameter:
o phoneNumber: The phone number to be validated.
 Return Type:
o boolean: Returns true if the phone number matches the valid format, otherwise
false.
 Method:
o Uses a regular expression to validate that the phone number starts with "0" or
"+84" and is followed by 9 digits.

Operation 7: validateName(String name)


 Parameter:
o name: The name to be validated.
 Return Type:
o boolean: Returns true if the name matches the valid format (letters and spaces
only, max 30 characters), otherwise false.
 Method:
o Uses a regular expression to validate the name format.

Operation 8: validateAddress(String address)


 Parameter:
o address: The address to be validated.
 Return Type:
o boolean: Returns true if the address matches the valid format (letters, numbers,
and common punctuation, max 100 characters), otherwise false.
 Method:
o Uses a regular expression to validate the address format.

Operation 9: calculateShippingFee(Order order)


 Parameter:
o order: The order for which the shipping fee is calculated.
 Return Type:
o int: Returns the calculated shipping fee for the order.
 Method:
o Calculates the shipping fee based on the heaviest item in the order and the city
(inner city or elsewhere). Discounts apply if the order value exceeds a certain
threshold.

Operation 10: calculateShippingFeeForItems(Order order, boolean isInnerCity)


 Parameter:
o order: The order for which the shipping fee is calculated.
o isInnerCity: A boolean indicating whether the delivery is within the city (true
for inner city, false otherwise).
 Return Type:
o int: Returns the calculated shipping fee based on the heaviest item's weight
and the city.
 Method:
o Calculates the shipping fee depending on the weight of the heaviest item and
whether the destination is within an inner city or elsewhere.
1.3.1.4. Class “PlaceRushOrderController”

Table 7. Example of attribute design

# Name Data type Default value Description


1 LOGGER Logger - Logger for debugging and logging
purposes.

2 order Order - The Order object representing the current


order to be processed.

3 lstRushOrderMedia List<OrderMedia> - A list that stores media items eligible for


rush orders.

Table 8. Example of operation design

# Name Return Type Description

1 updateOrderForRush(Order order) Order Updates the order to mark it as a rush


order, handles media eligibility, and
calculates shipping fees.

2 createInvoice(Order order) Invoice Creates an invoice based on the rush


order.

3 validateAddress(String address) boolean Validates the delivery address for the


rush order (checks if the address is "Hà
Nội" or "Hồ Chí Minh").

4 validateEligible(List<OrderMedia> boolean Validates whether any media items in


lstOrderMedia) the order are eligible for rush order.

5 calculateRegularShippingFee(Order order) int Calculates the regular shipping fee for


the order.

6 calculateRegularShippingFeeForItems(Orde int Calculates the regular shipping fee


r order, boolean isInnerCity) based on the heaviest item’s weight and
the delivery city.

7 calculateRushOrderShippingFee(Order int Calculates the rush order shipping fee,


order) including an additional charge for rush
items.

8 calculateRushShippingFeeForItems(Order int Calculates the rush shipping fee based


order, boolean isInnerCity) on the heaviest item’s weight and the
delivery city.

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 Marks the order as a 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.

Operator: createInvoice(Order order)


 Parameters:
o order: The Order object for which the invoice will be created.

 Method:
o Creates and returns a new Invoice object based on the provided order.

Operator: validateAddress(String address)


 Parameters:
o address: The delivery address string to validate.

 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 isInnerCity: A boolean indicating if the delivery is within the specified inner


cities.
 Method:
o Determines the heaviest item’s weight and calculates the shipping fee based
on the item’s weight and the delivery city (either inner city or elsewhere).
Operator: calculateRushOrderShippingFee(Order order)
 Parameters:
o order: The Order object for which the rush order shipping fee needs to be
calculated.
 Method:
o Calculates the total value of the rush order.

o Computes the additional fee for rush items.

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.

o isInnerCity: A boolean indicating if the delivery is within the specified inner


cities.
 Method:
o Determines the heaviest item’s weight in the rush order and calculates the
rush shipping fee based on the item’s weight and delivery city.

1.3.1.5. Class “ViewCartController”

Table 9. Example of attribute design

# Name Data type Default value Description


1 cart Cart N/A A reference to the cart that stores the user's
products.

Table 10. Example of operation design

# Name Return type Description (purpose)


1 checkAvailabilityOfProduct() void Checks the availability of the products in the cart.

2 getCartSubtotal() int Calculates and returns the subtotal for the


products in the cart.

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”

Table 11. Example of attribute design

# Name Data Type Default Value Description

1 mediaRepository MediaRepositor MediaRePositoryImpl An instance of MediaRepository for


y interacting with media data.

Table 12. Example of operation design

# Name Return Type Description

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.3.2. View Package


1.3.2.1. Class “CartForm”

Table 2. Operation design

# Name Return Type Description

1 getLabelAmount() Label Gets the label displaying the total cart amount.

2 getLabelSubtotal() Label Gets the label displaying the subtotal of the


cart items.

3 getBController() ViewCartController Gets the controller responsible for managing


the cart.

4 requestToPlaceOrder() void Handles the request to place an order.

5 requestToViewCart(prevScreen) void Handles the request to view the cart from the
previous screen.

6 updateCart() void Updates the cart and checks product


availability.

7 updateCartAmount() void Updates the cart values, including subtotal,


VAT, and amount.

8 displayCartWithMediaAvailability() void Displays the cart with available media items.

Method Details:

 Operation: requestToPlaceOrder() : void


o Parameters: None.
o Exceptions:
 SQLException, IOException: If there is an error while placing the
order.
o Method:

 Checks the availability of media items in the cart.


 If available items exist, places the order and navigates to the shipping
screen.
 If any errors occur, displays an error message.
 Operation: requestToViewCart(prevScreen: BaseForm) : void
o Parameters: prevScreen: The previous screen that navigated to the cart.
o Exceptions: None.
o Method:

 Sets up the cart screen and checks product availability.


 Displays the cart after checking availability.
 Operation: updateCart() : void
o Parameters: None.
o Exceptions: SQLException if the product availability check fails.
o Method:

 Checks the availability of the products in the cart.


 Updates the cart after checking availability.
 Operation: updateCartAmount() : void
o Parameters: None.
o Exceptions: None.
o Method:

 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:

 Iterates through the list of cart media and checks availability.


 Displays the available media items in the cart and updates the cart
values accordingly.
1.3.2.2. Class “InvoiceForm”

Table 2. Operation design

# Name Return Type Description

1 InvoiceForm(Stage, String, - Constructor to initialize the form with stage, layout


Invoice) path, and an invoice object.

2 getInvoice() Invoice Returns the invoice object associated with this form.

3 setInvoiceInfo(Invoice) void Configures UI components with the details of the


provided invoice object.

4 selectRegularOrder() void Handles the selection of regular orders and updates


the UI and invoice accordingly.

5 selectRushOrder() void Handles the selection of rush orders and updates the
UI and invoice accordingly.

6 placeRushOrder() void Processes rush order logic, including creating a new


invoice for rush delivery.

7 updateInvoiceForRegularOrder() void Updates the invoice and UI for regular orders.

8 requestToPayOrder() void Initiates the payment process for the invoice.

9 updateInvoiceTotals() void Recalculates and updates the totals for the invoice.

10 refreshItemsDisplay() void Refreshes the displayed items in the UI after


modifications.

11 notifyError(String) void Displays an error message to the user.

12 showRegular() void Shows the regular order section in the UI.

13 showRush() void Shows the rush order section in the UI.

14 goBackToPrevious(MouseEvent) void Navigates back to the previous screen, typically the


DeliveryForm.

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.

 Operation: onItemDeleted(OrderMedia media)


o Parameters:
media: The media item to be removed from the invoice.
o Exceptions:
 IllegalArgumentException: Thrown if the deletion operation fails.
o Method:
 Removes the specified OrderMedia from the invoice's order.
 Recalculates totals and updates the UI.
 Refreshes the item display to reflect changes.
 Operation:: updateInvoiceTotals()
Parameters: None.
Exceptions: None.
Method:
 Calculates subtotal and shipping fees for the order.
 Updates the UI labels for shipping fees, subtotal, and total amounts.
 Operation: refreshItemsDisplay()
Parameters: None.
Exceptions: None.
Method:
 Clears the current list of displayed items in the UI.
 Repopulates the display with updated invoice information.
 Operation: showRegular()
Parameters: None.
Exceptions: None.
Method:
 Displays the grid containing regular order details.
 Hides the rush order grid.
 Operation: showRush()
Parameters: None.
Exceptions: None.
Method:
 Displays grids containing both regular and rush order details.
 Operation: goBackToPrevious(MouseEvent event)
Parameters:
event: The mouse click event triggering the action.
Exceptions: None.
Method:
 Navigates back to the previous screen (DeliveryForm).
 Logs a warning if no previous screen is available.
 Operation: selectDeliveryMethod()
Parameters: None.
Exceptions:
 IOException, SQLException: Issues selecting the delivery method.
Method:
 Simulates a choice between regular and rush delivery.
 Invokes placeRushOrder() if rush delivery is selected.
 Operation: notifyError(String errorMessage)
Parameters:
errorMessage: The error message to display.
Exceptions: None.
Method:
 Displays the provided error message in the UI's errorLabel.

1.3.2.3. Class “BaseForm”

Table 2. Operation design

# Name Return Type Description

1 setPreviousScreen(prev: BaseForm) void Sets the previous screen (form) for


navigation purposes.

2 getPreviousScreen() BaseForm Retrieves the previous screen (form).

3 show() void Displays the current form in the stage.

4 setScreenTitle(title: String) void Sets the title of the current form's


window.

5 setBController(bController: BaseController) void Sets the controller for this form.

6 getBController() BaseController Retrieves the controller associated with


this form.
7 forward(messages: Hashtable) void Forwards the messages to be handled by
this form.

8 setHomeScreenHandler(homeScreenHandler: void Sets the handler for the home screen


HomeForm) form.
Operation Details:
 Operation: setPreviousScreen(prev: BaseForm) : void
o Parameters: prev: The previous screen that navigated to this form.

o Method: Stores the previous screen for future navigation.

 Operation: getPreviousScreen() : BaseForm


o Parameters: None.

o Method: Returns the previous screen that navigated to the current one.

 Operation: show() : void


o Parameters: None.

o Method: Displays the form in the associated stage. If the scene is not already set, it
creates a new scene and displays it.

 Operation: setScreenTitle(title: String) : void


o Parameters: title: The title for the window (form).

o Method: Sets the title of the window (stage).

 Operation: setBController(bController: BaseController) : void


o Parameters: bController: The controller to be set for this form.

o Method: Sets the controller that will handle the business logic of this form.

 Operation: getBController() : BaseController


o Parameters: None.

o Method: Returns the controller associated with this form.

 Operation: forward(messages: Hashtable) : void


o Parameters: messages: A Hashtable containing messages to be forwarded.

o Method: Stores the messages for further processing in this form.

 Operation: setHomeScreenHandler(homeScreenHandler: HomeForm) : void


o Parameters: homeScreenHandler: The handler for the home screen form.

o Method: Sets the handler that can manage the home screen navigation.
1.3.2.4. Class “FXMLForm”

Table 2. Operation design

# Name Return Type Description

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.

4 setImage(imv: void Sets an image to an ImageView from the specified file


ImageView, path: String) path.

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.3.2.5. Class “SplashForm”

Table 2. Operation design

# Name Return Type Description

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:

 location: The location of the FXML file.


 resources: The resource bundle containing any resources for the
FXML.
o Method:

 This method is called automatically when the form is initialized.


 It loads an image from a file path
(src/main/resources/isd/aims/main/fxml/images/Logo.png) and sets it
to the logo ImageView.

1.3.2.6. Class “VNPay”

Table 2. Operation design

# Name Return Type Description

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)

2 goBackToPrevious(MouseEvent event) void Navigates back to the previous screen, typically


the invoice form.

3 handleUrlChanged(String newValue) void Handles the URL change when the payment
page redirects after payment completion.
Processes the payment response.

4 showResultScreen(PaymentTransaction void Displays the result screen with the transaction


transactionResult) result (success or failure).

5 simulatePaymentSuccess() void Simulates a successful payment transaction for


testing purposes.

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.3.2.7. Class “ResultForm”

Table 2. Operation design

# Name Return Type Description

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”

Table 2. Operation design

# Name Return Type Description

1 MediaInvoiceForm(String void Constructor that initializes the form with the


screenPath, specified screen path and delete handler.
InvoiceForm.InvoiceUpdateHandler
deleteHandler)

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.

4 setMediaInfo() void Configures the UI components with details from


the OrderMedia object.

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.

1.3.2.9. Class “MediaForm” (Cart package)

Table 2. Operation design


# Name Return Type Description

1 MediaForm(screenPath, - Constructor that initializes the MediaForm with the given


cartScreen) FXML screen path and parent screen.

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.

2. Operation: setCartMedia(CartMedia cartMedia)


 Parameters:
o cartMedia: A CartMedia object containing the media's details.
 Method:
o Assigns the provided cartMedia object to the class attribute.
o Calls setMediaInfo() to update the UI with the media's details.

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”

Table 2. Operation design

# Name Return Type Description

1 PopupForm(Stage stage) - Constructor for initializing the pop-up form


with a given stage.

2 popup(String, String, Boolean) PopupForm Creates a new pop-up form with the specified
message, image, and style.

3 success(String message) void Displays a success pop-up with a green tick


icon.

4 error(String message) void Displays an error pop-up with a red error icon.

5 loading(String message) PopupForm Creates a loading pop-up with a spinner icon.

6 setImage(String path) void Sets the icon image for the pop-up using the
specified path.

7 show(Boolean autoclose) void Displays the pop-up and optionally closes it


automatically.

8 show(double time) void Displays the pop-up and closes it after a


specified duration.

9 close(double time) void Closes the pop-up after a specified duration.

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. Operation: popup(String message, String imagePath, Boolean undecorated)


Parameters:
 message: The message to display in the pop-up.
 imagePath: Path to the icon image for the pop-up.
 undecorated: Whether the pop-up should be displayed without window
decorations.
Return Type:
 PopupForm: A configured instance of PopupForm.
Method:
Creates and configures a pop-up with the specified message, image, and style. If
undecorated is true, the pop-up uses a borderless style.

3. Operation: success(String message)


Parameters:
 message: The success message to display.
Method:
Displays a success pop-up with a green tick icon and automatically closes after
0.8 seconds.

4. Operation: error(String message)


Parameters:
 message: The error message to display.
Method:
Displays an error pop-up with a red error icon. This pop-up requires manual
closure.

5. Operation: loading(String message)


Parameters:
 message: The loading message to display.
Return Type:
 PopupForm: A configured instance of PopupForm displaying a
loading spinner.
Method:
Creates a loading pop-up with a spinner icon. This pop-up remains open until
manually closed.

6. Operation: setImage(String path)


Parameters:
 path: The path to the image to set as the pop-up icon.
Method:
Sets the image for the tickicon component using the provided path.

7. Operation: show(Boolean autoclose)


Parameters:
 autoclose: A flag indicating whether the pop-up should close
automatically.
Method:
Displays the pop-up. If autoclose is true, the pop-up closes automatically after
0.8 seconds.

8. Operation: show(double time)


Parameters:
 time: The duration (in seconds) to display the pop-up before
closing.
Method:
Displays the pop-up and schedules it to close after the specified time.

9. Operation: close(double time)


Parameters:
 time: The duration (in seconds) before the pop-up closes.
Method:
Schedules the pop-up to close after the given duration using a PauseTransition.

1.3.2.11. Class “MediaForm”(Home package)

Table 2. Operation design

# Name Return Type Description

1 MediaForm(String, - Constructor to initialize the form and configure its


Media, HomeForm) components.

2 getMedia() Media Returns the media item associated with this form.

3 setMediaInfo() void Configures the UI components with details of the media


item.

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.

Table 2. Operation design

# Name Return Type Description

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.

4 show() void Updates cart information and displays the 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:

 Returns the HomeController instance, which is responsible for managing the


media data and interactions.
4. Operation: show()
Parameters: None
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:

 Calls setBController(new HomeController()) to initialize the controller.


 Loads media data through the controller and converts each media item into a
MediaForm object for display.
 Configures event handlers for UI elements like logo and cart image.
6. Operation: setImage()
Parameters: None
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.3.2.12. Class “DeliveryForm”

Table 2. Operation design

# Name Return Type Description

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.

3 submitDeliveryInfo(MouseEven void Handles the submission of the delivery


t event) information. Validates the info, calculates
shipping fees, and generates the invoice screen.

4 getBController() PlaceOrderController Returns the PlaceOrderController instance


responsible for processing the delivery info and
managing the order.

5 notifyError(String void Displays an error message in the errorLabel if


errorMessage) there is an issue with the delivery information

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:

 Returns the PlaceOrderController instance associated with the form. This


controller is responsible for handling business logic related to placing an
order.
5. Operation: notifyError(String errorMessage)
Parameters:
 errorMessage: The error message to be displayed to the user.
Method:
 Displays an error message in the errorLabel if there is an issue with the
delivery information. The error label becomes visible to alert the user to
correct the information.

1.3.3. Class Design Package Entity


1.3.3.1. Class “CartMedia”

Table 13. Example of attribute design

# Name Data type Default value Description


1 connection Connection N/A Represents the database connection.

2 statement Statement N/A Represents a SQL statement for executing


queries.

3 resultSet ResultSet N/A Holds the results returned from executing a


query.

Table 14. Example of operation design

# Name Return type Description (purpose)


1 getMedia Media Returns the media item in the cart.

2 setMedia void Sets the media item in the cart.

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.

5 getPrice int Returns the price of the media item.

6 setPrice void Sets the price of the media item.

7 toString String Returns a string representation of the CartMedia object.


1.3.3.2. Class “Cart”

Table 15. Attribute design

# Name Data type Default value Description


1 lstCartMedia List<CartMedia - List that holds the media items added to the
> cart.

2 cartInstance Cart - Singleton instance of the Cart class.

Table 16. Operation design

# Name Return type Description (purpose)


1 getCart Cart Returns the singleton instance of the Cart class.

2 addCartMedia void Adds a CartMedia object to the cart.

3 removeCartMedia void Removes a CartMedia object from the cart.

4 getListMedia List<CartMedia> Returns the list of media items in the cart.

5 emptyCart void Clears the cart by removing all CartMedia objects.

6 getTotalMedia int Returns the total quantity of media items in the cart.

7 calSubtotal int Calculates and returns the subtotal price of the


media items in the cart.

8 checkAvailabilityOfProduc void Checks if all products in the cart are available.


t Throws an exception if any item is unavailable.

9 checkMediaInCart CartMedia Checks if a media item is already in the cart by its


mediaId. If found, returns the CartMedia object;
otherwise, returns null.
Operation 1: getCart() : Cart
 Description: Returns the singleton instance of the Cart class.
 Parameters: None
 Exception: None
 Method:
If cartInstance is null, create a new Cart object and return it. If cartInstance is already
initialized, return the existing instance.

Operation 2: addCartMedia(cm: CartMedia) : void


 Description: Adds a CartMedia object to the cart.
 Parameters:
o cm: A CartMedia object representing the media and its quantity/price to be
added to the cart.
 Exception: None
 Method:
Adds the given CartMedia object to the lstCartMedia list.

Operation 3: removeCartMedia(cm: CartMedia) : void


 Description: Removes a CartMedia object from the cart.
 Parameters:
o cm: A CartMedia object representing the media to be removed from the cart.
 Exception: None
 Method:
Removes the given CartMedia object from the lstCartMedia list.

Operation 4: getListMedia() : List<CartMedia>


 Description: Returns the list of all CartMedia objects in the cart.
 Parameters: None
 Exception: None
 Method:
Returns the lstCartMedia list containing all the media items added to the cart.
Operation 5: emptyCart() : void
 Description: Clears all items in the cart.
 Parameters: None
 Exception: None
 Method:
Clears the lstCartMedia list by calling the clear() method, removing all cart items.

Operation 6: getTotalMedia() : int


 Description: Calculates and returns the total number of media items in the cart.
 Parameters: None
 Exception: None
 Method:
Iterates through the lstCartMedia list, summing the quantities of all items to calculate
the total.

Operation 7: calSubtotal() : int


 Description: Calculates and returns the subtotal price of all media items in the cart.
 Parameters: None
 Exception: None
 Method:
Iterates through the lstCartMedia list, calculating the subtotal by multiplying the price
of each item by its quantity, and summing the results.

Operation 8: checkAvailabilityOfProduct() : void


 Description: Checks if all items in the cart are available in the required quantity.
 Parameters: None
 Exception:
Throws MediaNotAvailableException if any item in the cart is unavailable in the
required quantity.
 Method:
Iterates through each CartMedia object in the cart, checking if the required quantity is
less than or equal to the available quantity for each item. If not, throws a
MediaNotAvailableException.
Operation 9: checkMediaInCart(mediaId: int) : CartMedia
 Description: Checks if a media item with the specified ID is already in the cart.
 Parameters:
o mediaId: The unique ID of the media item to check in the cart.
 Exception: None
 Method:
Searches through the lstCartMedia list for a CartMedia object that matches the given
mediaId. If found, returns the corresponding CartMedia object, otherwise returns null.

1.3.3.3. Class “DBConnection”

Table 17. Attribute design

# Name Data type Default value Description


1 connect Connection null Singleton instance of the database connection.

2 lock Object - Lock object for synchronizing access to the


connection.

3 LOGGER Logger - Logger instance for logging connection details.

Table 2. Operation design

# Name Return Type Description

1 getConnection Connection Returns a singleton instance of the database connection.

2 main void Main method to initiate the connection (for testing).

Operation 1: getConnection() : Connection


 Description:
o This method returns a singleton instance of the database connection.
o If the connection has not been established yet, it will initialize a new
connection.
 Parameters: None
 Exception:
o If an error occurs while establishing the connection, it throws a
RuntimeException.
 Method:
o If the connect instance is null, a synchronized block is used to ensure thread
safety while the connection is being initialized.
o The SQLite JDBC driver is loaded, and the connection string for the SQLite
database is defined.
o A connection to the database is established, and a success message is logged.
o If any exception occurs, it is logged, and a RuntimeException is thrown to
indicate failure in connecting to the database.

Operation 2: main() : void


 Description:
o This is a testing entry point for the class to establish a database connection.
 Parameters: None
 Exception: None
 Method:
o Calls the getConnection() method to check if the connection is successfully
established.

1.3.3.4. Class “Invoice”

Table 18. Attribute design

# Name Data type Default value Description


1 order Order - The order associated with the invoice.

2 amount int 0 The total amount of the invoice.

Table 19. Operation design

# Name Return type Description (purpose)


1 getOrder Order Returns the order associated with this invoice.

2 setAmount void Sets the total amount for the invoice.

3 getAmount int Returns the total amount for the invoice.

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.

Operation 2: setAmount(amount: int) : void


 Description:
o This method sets the amount of the invoice to the given value.
 Parameters:
o amount: The total amount for the invoice.
 Exception: None
 Method:
o Sets the amount instance variable to the provided amount parameter.

Operation 3: getAmount() : int


 Description:
o This method returns the amount of the invoice.
 Parameters: None
 Exception: None
 Method:
o Simply returns the amount instance variable.

Operation 4: saveInvoice() : void


 Description:
o This method is intended to save the invoice to a database or other storage
(currently not implemented).
 Parameters: None
 Exception: None
 Method:
o The actual implementation of saving the invoice has not yet been provided.

1.3.3.5. Class “Book”

Table 20. Attribute design

# Name Data type Default value Description


1 author String - The author of the book.

2 coverType String - The type of cover (e.g., hardcover, paperback).

3 publisher String - The publisher of the book.

4 publishDate Date - The publication date of the book.

5 numOfPages int 0 The number of pages in the book.

6 language String - The language the book is written in.

7 bookCategory String - The category of the book (e.g., fiction, science).

Table 2. Operation design

# Name Return type Description (purpose)


1 getId int Returns the unique identifier of the book.

2 getMediaById Media Fetches the media (Book) by its ID from the repository.

3 toString String Returns a string representation of the book.


Operation 1: getId() : int
 Description:
o This method returns the unique identifier of the book.
 Parameters: None
 Exception: None
 Method:
o Simply returns the id attribute inherited from the Media class.

Operation 2: getMediaById(id: int) : Media


 Description:
o This method fetches the media (Book) by its ID from the BookRepository.
 Parameters:
o id: The ID of the book to be fetched.
 Exception:
o Throws SQLException if the operation fails.
 Method:
o Calls the findById() method in the BookRepository to get the Book instance
by its ID.

Operation 3: toString() : String


 Description:
o This method returns a string representation of the Book object, including all
the attributes inherited from the Media class and specific to the Book class.
 Parameters: None
 Exception: None
 Method:
o Combines the string representation of the Media superclass with the Book
specific attributes and returns the result.

1.3.3.6. Class “CD”


Table 21. Example of attribute design

# Name Data type Default value Description


1 artist String - The artist of the CD.

2 recordLabel String - The record label that released the CD.

3 musicType String - The type of music (e.g., pop, rock, classical).

4 releasedDate Date - The release date of the CD.

Table 22. Example of operation design

# Name Return type Description (purpose)


1 getId int Returns the unique identifier of the CD.

2 getMediaById Media Fetches the media (CD) by its ID from the repository.

3 toString String Returns a string representation of the CD.


Operation 1: getId() : int
 Description:
o This method returns the unique identifier of the CD.
 Parameters: None
 Exception: None
 Method:
o Simply returns the id attribute inherited from the Media class.

Operation 2: getMediaById(id: int) : Media


 Description:
o This method fetches the media (CD) by its ID from the CDRepository.
 Parameters:
o id: The ID of the CD to be fetched.
 Exception:
o Throws SQLException if the operation fails.
 Method:
o Calls the findById() method in the CDRepository to get the CD instance by its
ID.

Operation 3: toString() : String


 Description:
o This method returns a string representation of the CD object, including all the
attributes inherited from the Media class and specific to the CD class.
 Parameters: None
 Exception: None
 Method:
o Combines the string representation of the Media superclass with the CD
specific attributes and returns the result.

1.3.3.7. Class “DVD”


Table 23. Example of attribute design

# Name Data Type Default Value Description

1 discType String - The type of the disc (e.g., Blu-ray, DVD).

2 director String - The director of the movie.

3 runtime int - The runtime of the movie (in minutes).

4 studio String - The studio that produced the DVD.

5 subtitles String - The subtitles available for the DVD.

6 releasedDate Date - The release date of the DVD.

7 filmType String - The type of the film (e.g., action, drama).

Table 24. Example of operation design

# Name Return Type Description

1 getId int Returns the unique identifier of the DVD.

2 getMediaById Media Fetches the media (DVD) by its ID from the repository.

3 toString String Returns a string representation of the DVD.


Operation 1: getId() : int
 Description:
o This method returns the unique identifier of the DVD.
 Parameters: None
 Exception: None
 Method:
o Simply returns the id attribute inherited from the Media class.

Operation 2: getMediaById(id: int) : Media


 Description:
o This method fetches the media (DVD) by its ID from the DVDRepository.
 Parameters:
o id: The ID of the DVD to be fetched.
 Exception:
o Throws SQLException if the operation fails.
 Method:
o Calls the getDVDById() method in the DVDRepository (or a service class like
DVDService) to get the DVD instance by its ID.

Operation 3: toString() : String


 Description:
o This method returns a string representation of the DVD object, including all the
attributes inherited from the Media class and specific to the DVD class.
 Parameters: None
 Exception: None
 Method:
o Combines the string representation of the Media superclass with the DVD specific
attributes and returns the result.

1.3.3.8. Class “Media”


Table 25. Example of attribute design

# Name Data Type Default Value Description

1 id int - The unique identifier for the media item.

2 title String - The title of the media item.

3 category String - The category of the media item (e.g., movie,


music, book).

4 value int - The real price of the product (e.g., 450).

5 price int - The displayed price on the browser (e.g.,


500).

6 quantity int - The available quantity of the media item.

7 type String - The type of the media item (e.g., digital,


physical).

8 imageURL String - The URL of the media's image.

9 String double - The weight of the media item (could be


adjusted based on media type).

1 isRushOrderEligible boolean false Flag to indicate whether the media item is


0 eligible for rush orders.

Table 26. Example of operation design

# Name Return Type Description

1 getId() int Returns the unique identifier of the media item.

2 getQuantity() int Fetches the quantity of the media item.

3 updateMediaFieldById() void Updates a specific field in the database for a given


media item by its ID.
Operation 1: getId() : int
 Description: This method returns the unique identifier of the media item.
 Parameters: None
 Exception: None
 Method:
o Simply returns the id attribute, which is the unique identifier for each media instance.

Operation 2: getQuantity() : int


 Description: This method retrieves the available quantity of the media item.
 Parameters: None
 Exception: Throws a SQLException if a database error occurs.
 Method:
o Returns the quantity attribute representing the available stock of the media item.

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.

Operation 4: toString() : String


 Description: This method returns a string representation of the media item, including its
attributes.
 Parameters: None
 Exception: None
 Method:
o Returns a concatenated string containing the id, title, category, price, quantity, type,
weight, and isRushOrderEligible attributes, which provide a complete description of
the media item.

1.3.3.9. Class “Order”

Table 27. Example of attribute design

# Name Data Type Default Value Description

1 shippingFees int 0 The total shipping fees for the


order.

2 lstOrderMedia List<OrderMedia> [] A list of media items included in


the order.

3 lstRushOrderMedia List<OrderMedia> [] A list of media items eligible for


rush delivery.

4 deliveryInfo HashMap<String, {} Delivery-related information (e.g.,


String> address).

5 id Integer null The unique identifier of the order.

6 rushOrder boolean false Indicates whether the order is a


rush order or not.

7 deliveryLocation String - The location where the order


should be delivered.

8 priceCalculator OrderPriceCalculator - The calculator object responsible


for calculating the order's total
price.

9 regularOrderAmount int 0 The amount for the regular order,


excluding rush items.

1 rushOrderAmount int 0 The amount for the rush order


0 items.

1 regularOrderShippingFees int 0 Shipping fees for the regular


1 order.

1 rushOrderShippingFees int 0 Shipping fees for rush order


2 items.

Table 28. Example of operation design

# Name Return Type Description

1 getShippingFees() int Returns the total shipping fees for the order.

2 setShippingFees() void Sets the total shipping fees for the order.

3 addOrderMedia() void Adds an OrderMedia item to the order.

4 removeOrderMedia() void Removes an OrderMedia item from the order.

5 getAmount() int Calculates and returns the total order amount


(including rush items).

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.

Operation 2: setShippingFees(shippingFees: int) : void


 Description: This method sets the total shipping fees for the order.
 Parameters:
o shippingFees (int): The shipping fees to set.
 Exception: None
 Method:
o Assigns the value of shippingFees to the corresponding attribute.

Operation 3: addOrderMedia(om: OrderMedia) : void


 Description: This method adds an OrderMedia item to the order.
 Parameters:
o om (OrderMedia): The OrderMedia item to be added.
 Exception: None
 Method:
o Adds the OrderMedia object om to the lstOrderMedia list.

Operation 4: removeOrderMedia(om: OrderMedia) : void


 Description: This method removes an OrderMedia item from the order.
 Parameters:
o om (OrderMedia): The OrderMedia item to be removed.
 Exception: None
 Method:
o Removes the OrderMedia object om from the lstOrderMedia list.

Operation 5: getAmount() : int


 Description: This method calculates and returns the total amount for the order (including
regular and rush items).
 Parameters: None
 Exception: None
 Method:
o Uses the OrderPriceCalculator to calculate the total amount by invoking
calculateTotal() method.

Operation 6: getHeaviestItemWeight() : double


 Description: This method returns the weight of the heaviest item in the order.
 Parameters: None
 Exception: None
 Method:
o Iterates over the list of OrderMedia items and returns the weight of the heaviest item.

Operation 7: getRushOrderItems() : int


 Description: This method returns the number of rush order items in the order.
 Parameters: None
 Exception: None
 Method:
o Iterates over the lstOrderMedia list and counts how many of the items have the
rushOrder flag set to true.

1.3.3.10. Class “OrderMedia”

Table 29. Attribute design

# Name Data Type Default Value Description

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.

3 quantity int - The quantity of the media item ordered.

4 rushOrder boolean false Indicates whether the media item is part of a


rush order (default false).

Table 30. Operation design

# Name Return Type Description

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.

4 getQuantity() int Returns the quantity of the media item ordered.

5 setQuantity() void Sets the quantity of the media item ordered.

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.

Operation 9: setRushOrder(rushOrder: boolean) : void


 Description: This method sets whether the media item is part of a rush order.
 Parameters:
o rushOrder (boolean): The value to set for the rush order flag.
 Exception: None
 Method:
o Sets the rushOrder attribute of the OrderMedia object to the provided value.

1.3.3.11. Class “CreditCard”

Table 31. Attribute design

# Name Data Type Default Value Description

1 cardCode String - The credit card number, typically a 16-digit


string.

2 owner String - The name of the cardholder.

3 cvvCode int - The CVV (Card Verification Value) code,


typically 3 digits.

4 dateExpired String - The expiration date of the credit card, typically


in MM/YY format.
1.3.3.12. Class “PaymentTransaction”

Table 32. Example of attribute design

# Name Data Type Default Value Description

1 errorCode String - The error code returned by the payment


processor, if any.

2 transactionId String - The unique identifier for the payment


transaction.

3 transactionConten String - A description or content related to the


t transaction.

4 amount int - The total amount for the transaction.

5 orderID Integer - The ID of the order associated with the


payment (optional).

6 createdAt Date - The date and time when the payment


transaction was created.

Table 33. Example of operation design

# Name Return Type Description

1 isSuccess() boolean Returns whether the payment transaction was


successful or not.

2 getMessage() String Returns a message indicating the result of the payment


transaction.

3 getCreatedAt() Date Returns the creation timestamp of the payment


transaction.

4 getTransactionContent() String Returns the content/description of the transaction.

5 getAmount() int Returns the amount involved in the payment


transaction.
Operation 1: isSuccess() : boolean
 Description: This method checks whether the transaction was successful.
 Parameters: None
 Exception: None
 Method:
o Returns true if the errorCode is null or equals "00", indicating a successful
transaction.
o Returns false otherwise.

Operation 2: getMessage() : String


 Description: This method returns a message indicating the result of the transaction.
 Parameters: None
 Exception: None
 Method:
o If the transaction is successful, returns "Payment was successful."
o If the transaction failed, returns a message with the error code (e.g., "Payment failed
with error code: [errorCode]").

Operation 3: getCreatedAt() : Date


 Description: This method returns the creation date and time of the payment transaction.
 Parameters: None
 Exception: None
 Method:
o Returns the createdAt attribute of the PaymentTransaction object.

Operation 4: getTransactionContent() : String


 Description: This method returns the content or description associated with the transaction.
 Parameters: None
 Exception: None
 Method:
o Returns the transactionContent attribute of the PaymentTransaction object.

Operation 5: getAmount() : int


 Description: This method returns the amount involved in the payment transaction.
 Parameters: None
 Exception: None
 Method:
o Returns the amount attribute of the PaymentTransaction object.

1.3.3.13. Class “Request”

Table 34. Example of attribute design

# Name Data Type Default Value Description

1 money int - The amount of money involved in the request.

2 orderInfo String - The information related to the order associated


with the request.

Table 35. Example of operation design

# Name Return Type Description

1 getMoney() int Returns the amount of money involved in the request.

2 getOrderInfo() String Returns the order information associated with the


request.
Operation 1: getMoney() : int
 Description: This method returns the money involved in the request.
 Parameters: None
 Exception: None
 Method:
o Returns the money attribute of the Request object.

Operation 2: getOrderInfo() : String


 Description: This method returns the order information associated with the request.
 Parameters: None
 Exception: None
 Method:
o Returns the orderInfo attribute of the Request object.

1.3.3.14. Class “UrlBuilder”

Table 36. Operation design

# Name Return Type Description

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.

4 buildQueryString(params: String Creates the query string portion of the URL by


Map<String, String>) encoding the parameters in the correct format.
Operation 1: buildPaymentURL(request: Request)
 Description: This method constructs the full URL for the payment request by:
1. Calling buildParams to create the payment parameters.
2. Calling buildHashData to generate the security hash.
3. Calling buildQueryString to assemble the query string.
4. Returning the full URL by concatenating the query string and hash data.
 Parameters:
o request: The request object that contains the necessary payment and order
details.
 Exceptions:
o Throws IOException if there is an issue with encoding or URL creation.
 Method:
o Uses helper methods buildParams, buildHashData, and buildQueryString to
assemble the final URL for payment.

Operation 2: buildParams(request: Request)


 Description: This method constructs the parameters that need to be included in the
payment URL. It includes transaction reference (vnp_TxnRef), order information
(vnp_OrderInfo), amount, currency, and other required fields.
 Parameters:
o request: The Request object containing the amount and order information.
 Exceptions:
o None
 Method:
o The method uses VnPayConfig for static configuration values, such as
merchant code and secret keys.
o The amount is multiplied by 100 to convert to the smallest currency unit (e.g.,
VND cents).
o The vnp_CreateDate and vnp_ExpireDate are set based on the current time
and expiration time.
Operation 3: buildHashData(params: Map<String, String>)
 Description: This method generates a secure hash string that will be used for the
vnp_SecureHash parameter. It creates a string of sorted parameters and their values,
and then URL-encodes them before concatenating them.
 Parameters:
o params: A map of parameter names and values that will be included in the
URL.
 Exceptions:
o Throws IOException if there is an issue with URL encoding.
 Method:
o Iterates through the sorted parameters and URL-encodes their values.
o Constructs the hash data string that is later used for generating the secure hash.

Operation 4: buildQueryString(params: Map<String, String>)


 Description: This method creates the query string for the URL. It sorts the parameters
and URL-encodes them, ensuring that each parameter is in the correct format for
inclusion in the URL.
 Parameters:
o params: A map of parameters that are to be included in the query string.
 Exceptions:
o Throws IOException if there is an issue with URL encoding.
 Method:
o Sorts the parameter names in lexicographical order.
o URL-encodes the parameter names and values and concatenates them into the
final query string format.
1.3.3.15. Class “Response”

Table 37. Operation design

# Name Data Type Default Value Description

1 vnp_BankCode String - The bank code associated with the


transaction.

2 vnp_PayDate String - The date the payment was processed.

3 vnp_TransactionNo String - The transaction number from the payment


system.

4 vnp_TmnCode String - The terminal code for the transaction.

5 vnp_SecureHash String - The secure hash of the transaction for


verification.

6 vnp_OrderInfo String - The order information associated with the


transaction.

7 vnp_TxnRef String - The reference number for the transaction.

8 vnp_Amount String - The amount of the transaction.

9 vnp_CardType String - The type of card used in the transaction.

1 vnp_TransactionStatus String - The status of the transaction


0 (success/failure).

1 vnp_BankTranNo String - The bank transaction number.


1

1 vnp_ResponseCode String - The response code indicating the result of


2 the transaction.
1.3.3.16. Class “ResponseCode”

Table 38. Example of attribute design

# Name Data Type Default Value Description

1 code String - The response code representing the


outcome of the transaction.

2 exceptionSupplier ExceptionSupplier - A functional interface that provides the


exception to be thrown for a specific
response code.

Table 39. Example of operation design

# Name Return Type Description

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.

3 ExceptionSupplier interface A functional interface used to create an exception based


on the response cod
Operation 1: ResponseCode(String code, ExceptionSupplier exceptionSupplier)
 Description: The constructor is used by the enum values to initialize each response
code with a corresponding exception. This is done when the enum is declared.
o Parameters:
 code: A string representing the response code.
 exceptionSupplier: A functional interface used to supply an exception
when the response code requires one.
o Exceptions: None.
o Method: The constructor initializes the enum constants with the provided
code and exceptionSupplier.

Operation 2: handle(String code


 Description: This static method handles the response code by searching through the
enum constants and taking the appropriate action:
o If the code matches an enum constant, the method checks if an exception is
associated with it. If an exception is present, it is thrown; otherwise, the
method simply returns.
o If no matching response code is found, an UnrecognizedException is thrown.
o Parameters:
 code: The response code that needs to be processed.
o Exceptions:
 Throws the associated exception for the response code, or an
UnrecognizedException if the code is unrecognized.
o Method: The method iterates over the enum constants, matching the code. If a
match is found, it throws the exception associated with that code or returns if
no exception is needed.

1.3.3.17. Class “User”


Table 40. Example of attribute design

# Name Data Type Default Value Description

1 id int - The unique identifier for the user.

2 name String - The name of the user.

3 email String - The email address of the user.

4 address String - The address of the user.

5 phone String - The phone number of the user.

1.3.4. Class Design Package


1.3.4.1. Class “MediaRepository”

Table 41. Example of attribute design

# Name Data Type Default Value Description

Table 42. Example of operation design

# Name Return Type Description

1 findAll() List<Media> Retrieves all media records from the repository.

2 findById(id : int) Media Retrieves a specific media record by its ID.

3 save(media : Media) void Saves a new media record to the repository.

4 update(media : Media) void Updates an existing media record in the repository.

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.

Operation 2: findById(int id)


 Description: Retrieves a Media record by its ID from the repository.
 Parameters: id: The ID of the media to retrieve.
 Exceptions: Throws SQLException if the media with the specified ID is not
found.
 Method: Searches for a media record with the given ID and returns it if found.

Operation 3: save(Media media)


 Description: Saves a new Media record to the repository.
 Parameters: media: A Media object to be saved.
 Exceptions: Throws SQLException if the saving operation fails.
 Method: Inserts the provided Media object into the repository.

Operation 4: update(Media media)


 Description: Updates an existing Media record in the repository.
 Parameters: media: A Media object with the updated values.
 Exceptions: Throws SQLException if the update operation fails.
 Method: Modifies the existing media record with the updated values in the
repository.

Operation 5: delete(int id)


 Description: Deletes a Media record from the repository based on its ID.
 Parameters: id: The ID of the media to delete.
 Exceptions: None.
 Method: Removes the media record with the given ID from the repository.

1.3.4.2. Class “BookRepository”

Table 43. Example of attribute design

# Name Data Type Default Value Description

1 dbConnection DBConnection - The database connection object used to


interact with the database.

Table 44. Example of operation design

# Name Return Type Description

1 findAll() List<Media> Retrieves all CD records from the repository, including


common media information.
2 findById(id : int) Media Retrieves a specific CD record by its ID from the
repository.

3 save(media : Media) void Saves a new CD media record to the repository.

4 update(media : Media) void Updates an existing CD media record in the repository.

5 delete(id : int) void Deletes a CD media record from the repository based
on its ID.

1.3.4.3. Class “DVDRepository”

Table 45. Example of attribute design

# Name Data Type Default Value Description

1 dbConnection DBConnection - The database connection object used to


interact with the database.

Table 46. Example of operation design

# Name Return Type Description

1 findAll() List<Media> Retrieves all DVD records from the repository,


combining the common media information.

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.

4 update(media : Media) void Updates an existing DVD media record in the


repository.

5 delete(id : int) void Deletes a DVD media record from the repository based
on its ID.
1.3.4.4. Class “MediaRepositoryImpl”

Table 47. Example of attribute design

# Name Data Type Default Description


Value

1 dbConnection DBConnection - The database connection object


used to interact with the database.

Table 48. Example of operation design

# Name Return Type Description

1 findAll() List<Media> Retrieves all Media records from the repository.

2 findById(id : int) Media Retrieves a specific Media record by its ID from


the repository.

3 save(media : void Saves a new Media record to the repository.


Media)

4 update(media : void Updates an existing Media record in the


Media) repository.

5 delete(id : int) void Deletes a Media record from the repository


based on its ID.

1.3.4.5. Class “PaymentTransactionRepository”

Table 49. Example of attribute design

# Name Data Type Default Description


Value

1 dbConnection DBConnection - The database connection object


used to interact with the database.

Table 50. Example of operation design

# Name Return Type Description

1 save(transaction : void Saves a new PaymentTransaction


PaymentTransaction, orderId : record into the repository.
int)

2 checkPaymentByOrderId(orderI int Checks whether a payment transaction


d : int) exists for the given orderId, returning
the count of records.
Operation 1: save(PaymentTransaction transaction, int orderId)
 Description: Saves a new PaymentTransaction to the repository, associating it
with a given order.
 Parameters:
o transaction: The PaymentTransaction object containing the details of the
payment.
o orderId: The ID of the associated order.
 Exceptions:
o Throws SQLException if there is an issue executing the SQL query.
 Method:
o Prepares an INSERT SQL query to insert a new transaction into the
"Transaction" table, using the orderId, transaction creation date, and
content.
o After executing the query, the payment transaction is successfully saved to
the database.
Operation 2: checkPaymentByOrderId(int orderId)
 Description: Checks if a payment transaction exists for a specific order, returning
the count of such transactions.
 Parameters:
o orderId: The ID of the order to check.
 Return Type:
o Returns an int representing the number of payment transactions found for
the given orderId.
 Exceptions:
o Throws SQLException if there is an issue executing the SQL query.
 Method:
o Executes a SELECT COUNT(*) SQL query to check the number of
payment transactions linked to the specified orderId.
o Returns the count from the query result.

1.3.4.6. Class “OrderRepository”

Table 51. Example of attribute design

# Name Data Type Default Description


Value
Table 52. Example of operation design

# Name Return Type Description

1 save(order : void Saves a new Order record to the repository,


Order) using the delivery information and shipping fees.

Operation 1: save(Order order)


 Description: Saves a new Order record to the repository.
 Parameters:
o order: The Order object to be saved. The order contains details like
delivery information and shipping fees.
 Exceptions:
o Throws SQLException if there is an issue executing the SQL query.
 Method:
o This method prepares an INSERT SQL query to insert a new order into the
"Order" table with the values taken from the Order object, such as email,
delivery information (address, phone), userID, and shipping fees.
o The shipping_fee is computed by summing the regular and rush order
shipping fees.
o After executing the query, the new order is inserted into the database.

You might also like