Class DiscountApprovalService
java.lang.Object
com.university.bookstore.chain.DiscountApprovalService
Service for managing discount approval using the Chain of Responsibility pattern.
Builds and manages the approval chain and processes discount requests.
This service demonstrates the Chain of Responsibility pattern by creating a hierarchy of approval handlers and processing requests through the chain.
- Since:
- 2024-09-15
- Version:
- 3.0
- Author:
- Navid Mohaghegh
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classStatistics class for approval analysis. -
Constructor Summary
ConstructorsConstructorDescriptionCreates a new discount approval service with the default chain.Creates a new discount approval service with a custom chain. -
Method Summary
Modifier and TypeMethodDescriptiondoublecalculateFinalPrice(DiscountRequest request) Calculates the final price for an approved discount request.voidClears all processed requests.Gets approval statistics.Gets approved discount requests.Gets the approval chain information.Gets all processed discount requests.Gets rejected discount requests.getRequestsForCustomer(String customerId) Gets discount requests for a specific customer.getRequestsForMaterial(Material material) Gets discount requests for a specific material.requestDiscount(Material material, double discountPercent, String customerId, String reason) Processes a discount request through the approval chain.toString()
-
Constructor Details
-
DiscountApprovalService
public DiscountApprovalService()Creates a new discount approval service with the default chain. -
DiscountApprovalService
Creates a new discount approval service with a custom chain.- Parameters:
chain- the approval chain to use
-
-
Method Details
-
requestDiscount
public DiscountRequest requestDiscount(Material material, double discountPercent, String customerId, String reason) Processes a discount request through the approval chain.- Parameters:
material- the material for which discount is requesteddiscountPercent- the discount percentage (0.0 to 100.0)customerId- the customer requesting the discountreason- the reason for the discount request- Returns:
- the processed discount request
-
calculateFinalPrice
Calculates the final price for an approved discount request.- Parameters:
request- the discount request- Returns:
- the final price
-
getProcessedRequests
Gets all processed discount requests.- Returns:
- list of processed requests
-
getApprovedRequests
Gets approved discount requests.- Returns:
- list of approved requests
-
getRejectedRequests
Gets rejected discount requests.- Returns:
- list of rejected requests
-
getRequestsForCustomer
Gets discount requests for a specific customer.- Parameters:
customerId- the customer ID- Returns:
- list of requests for the customer
-
getRequestsForMaterial
Gets discount requests for a specific material.- Parameters:
material- the material- Returns:
- list of requests for the material
-
getApprovalStats
Gets approval statistics.- Returns:
- approval statistics
-
clearRequests
public void clearRequests()Clears all processed requests. -
getChainInfo
-
toString
-