Class MaterialService
java.lang.Object
com.university.bookstore.service.MaterialService
Domain service that orchestrates business logic for material management.
Demonstrates hexagonal architecture by coordinating between domain logic and infrastructure.
This service encapsulates business rules and coordinates between the domain layer and the repository layer, maintaining clean separation of concerns.
- Since:
- 2024-09-15
- Version:
- 3.0
- Author:
- Navid Mohaghegh
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classException thrown when a material is invalid according to business rules.static classException thrown when a requested material is not found. -
Constructor Summary
ConstructorsConstructorDescriptionMaterialService(MaterialRepository repository) Creates a new material service with the specified repository. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddMaterial(Material material) Adds a material to the system with business logic validation.voidClears all materials from the system.findMaterial(String id) Finds a material by its ID.Finds a material by its ID, returning Optional.Gets all materials in the system.longGets the total number of materials in the system.booleanmaterialExists(String id) Checks if a material exists in the system.booleanremoveMaterial(String id) Removes a material from the system.voidupdateMaterial(Material material) Updates an existing material with business logic validation.
-
Constructor Details
-
MaterialService
Creates a new material service with the specified repository.- Parameters:
repository- the material repository to use
-
-
Method Details
-
addMaterial
Adds a material to the system with business logic validation.- Parameters:
material- the material to add- Throws:
MaterialService.InvalidMaterialException- if the material is invalid
-
updateMaterial
Updates an existing material with business logic validation.- Parameters:
material- the material to update- Throws:
MaterialService.InvalidMaterialException- if the material is invalidMaterialService.MaterialNotFoundException- if the material doesn't exist
-
findMaterial
Finds a material by its ID.- Parameters:
id- the material ID- Returns:
- the material if found
- Throws:
MaterialService.MaterialNotFoundException- if the material doesn't exist
-
findMaterialOptional
-
getAllMaterials
-
removeMaterial
Removes a material from the system.- Parameters:
id- the material ID to remove- Returns:
- true if the material was removed, false if not found
-
materialExists
Checks if a material exists in the system.- Parameters:
id- the material ID- Returns:
- true if the material exists
-
getMaterialCount
public long getMaterialCount()Gets the total number of materials in the system.- Returns:
- the material count
-
clearAllMaterials
public void clearAllMaterials()Clears all materials from the system.
-