Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Star Restaurant ( Spring Boot + Microservices ) 1 . 0 Introduction 1 . 0 Functional Requirements Star Restaurant is one of the leading restaurants,
Star Restaurant Spring Boot Microservices
Introduction
Functional Requirements
Star Restaurant is one of the leading restaurants, that has branches all over India. It pioneered the concept of "Unlimited Food for the Customer". The Price chart is fixed for the Adults and Kids years under vegetarian and nonvegetarian categories. They are in need of a separate online portal that should support the below business activities.
Book a Table
Calculate Bill
Report
Statistics
The client wishes to have restful webservices for booking a table, calculating bill, viewing the booking done on a particular date, finding the star rated customer.
Help them to automate the above process by developing Rest Service using Maven and incorporate microservices for the same.
Technical Specifications
The provided RestaurantController which is a RestController, should be created with the below services:
Services:
Request Method
Post
book
Method in Controller
bookATable
Description
T
This service should book a table for the customer by using the bookATable method of the Restaurant Servicelmpl class
Put
Request Url
calculatebookingld
calculateBill
This service calculates the bill of customer for the given Get
viewBookingdateRequired
booking Id and should return the booking information with the updated amount, by using the calculateBill method of the RestaurantServicelmpl class
view Booking OnAParticular Date
This service should retrieve the List of bookings by using the viewBooking OnAParticular Date method of the RestuarantServiceImpl class based on data required
Note:
Get
starRated
findStarRated Customer
The date parameter obtained as String in the format yyyy MMdd should be converted to LocalDate in the RestController before invoking the service
This service should retrieve the list of mobile numbers of the customer who have done maximum bookings by using the findStarRatedCustomer method of the RestaurantServicelmpl class.
There can be more than one customer who have done maximum booking. Mobile Number should be taken as the unique value and not the customer Name.
For example, if a Customer with mobile number has made bookings another customer with mobile number has made bookings and another customer has made bookings, then customer with mobile number is considered as star rated customer
The Controller class should have the below attribute:
IRestaurantService service;
It should be injected in the Controller via annotation.
Microservice Specification:
Spring boot application should contain all the REST services implementation as per the case study specification.
The Spring rest service application should have the application name as "restaurantapp" in the application.properties.
Register the spring rest service application with the Eureka server which should run in port
API Gateway Server:
Implement API Gateway using ZUUL proxy server
Must contain a routing information for the below URI mapping to the actual service implementation that is running in the port
book URI mapping,
calculate URI mapping
viewBookingdateRequired URI mapping and
starRated URI.
The API gate way server port must be specified in the "application.properties" file. The service must be accessible through API gateway using smallcase url.
Do not specify absolute url of the rest service in the Gateway properties file. Rather use serviceid to
The API gate way server port must be specified in the "application.properties" file.
The service must be accessible through API gateway using smallcase uri.
Note:
Do not specify absolute url of the rest service in the Gateway properties file. Rather use serviceid to specify the name of the applicationRest service That is in Gateway, to specify the application name use the below property in application.properties.
zuul.routes.restaurantapp.serviceidrestaurantapp
Service Layer
Refer to the IRestaurantService interface provided as part of the code skeleton. The RestaurantServicelmpl class which is provided as part of the code skeleton has to realize all the methods in the IRestaurantService interface.
RestaurantServicelmpl class should be configured via annotation as Service
RestaurantServiceImpl
Attribute Name
Booklist
Attribute Type
List
Requirements
Requirement
Method in Service
bookATable
Description
Exception
This method should add the booking details to the bookList and return the book Table object. Use SLFJ and log the success message as "Customer with id
The mobile number of the customer should contain exactly digits and it should start with any digit from to If the above condition is not met then throw a user defined exception
booked
specify the name of the applicationBest septicel That in
Note:
Requirement
calculateBill
This method should iterate the booklist and calculate the total bill amount of the customer for the given booking Id based on the business rules Please refer the Business Rules section and set the total amount. This method should then return the booking information of the customer with the calculated total amount Use SLFJ and log the success message as "Transaction completed successfully"
Book TableInvalidException with the message "Enter a valid mobile number". Use SLFJ and log this as error message
Requirement
viewBooking On A Particular
quirement
viewBookingOnAParticularDate
This method accepts the booking date as parameter. It should iterate the bookList and
If no bookings are done in the given date, then throw Book TableInvalidException with the message No
return the list of bookings made on the particular date.
Use SLFJ and log the success message as "View booking on a particular date is successfully done"
bookings available on the given date"
Use SLFJ and log this as error message
Requirement
findStarRated Customer
This method should iterate the booklist and returns the list of mobile numbers who have done maximum bookings.
Assumption there can be more than one customer who have done maximum booking. Mobile Number should be taken as the unique value and not the customer Name.
Use SLFJ and log the success message as "Find star rated customer is successful
Business Rules
The Price chart is fixed for the Adults and Kids years under vegetarian and nonvegetarian categories.
Business Rules
The Price chart is fixed for the Adults and Kids years under vegetarian and nonvegetarian categories.
Categories
Cost for each category in Rs
Adult
Kids
Vegetarian
Non
vegetarian
For example:
adultVegCount kidsVegCount adult NonVegCount kidsNonVeg Count
totalCost
Exception Class
Refer to the Book TableException class provided as part of the code skeleton. This class should extend the Exception class. Provide the needed annotation so that it handies HttpStatus as NOT FOUND
Model class
Refer to the Book Table class provided as part of the code skeleton.
Attributes
bookingld
DataType
customerName
String
mobNumber
String
String
totalGuestCount
Integer
totalAdultVegCount
Integer
totalAdult NonVegCount
Integer
totalKids Veg Count
Integer
totalKidsNonVegCount
Integer
booking Date
LocalDate
totalBillAmount
Double
bookingDate will be in yyyyMMdd format. Set this format for Json.
Note:
Use Lombok to generate getters and setters for the attributes
Do not change the allargument constructor and no argument constructor provided as part of the code skeleton
Do not change the datatype or the attribute name provided as part of the code skeleton
Business Validation
Inbuilt Validation
Rule
customerName should not be null
Total adult veg count should not be negative
Total adult non veg count should not be negative
Total kids veg count should not be negative
Total kids non veg count should not be negative
The date format should be yyyyMMdd
Message when validation fails
Provide value for customer name
Provide value greater than or equal to zero
Provide value greater than or equal to zero
Provide value greater than or equal to zero
Provide value greater than or equal to zero
Provide correct format
Perform the above Validations using annotations that are available in javax.validation.constraints package
Custom Validation
Also perform Custom validation for the totalGuestCount attribute.
Rule
Message when validation fails
A
totalGuestCount value should be equal to the sum of totalAdultVegCount and totalAdultNonVegCount and totalKidsVegCount and totalKidsNonVegCount.
Provide correct value for the totalGuestCount
booking Date must not be past date
Booking date cannot be the past date
For this you are provided with RestaurantValidator class. This class should be configured via annotation as Component.
Incorporate Exception and validations as ResponseEntity
To incorporate the messages related to Exception and validationsboth custom and inbuilt validations as
ResponseEntity, you are provided with the below classes Make use of Exception Response class that is already provided as part of the code skeleton to send the customized response error message.
CustomizedResponse EntityExceptionHandler class to handle all the exceptions that has occurred in the applicationboth user defined and pre defined
Method Name
Explanation
handleAllExceptions
This method should generally handle
all the exceptions
handleNotFoundException
This method should handle and provide customized error message using Exception Response class
handleNotFoundException
handleMethodArgumentNotValid
This method should handle and provide customized error message using Exception Response class for user defined exception Book TableInvalid Exception
This method should handle and provide customized error message using Exception Response class for both predefined and user defined validations
Note:
In CustomizedResponse Entity ExceptionHandler class, log all the error messages usingClient invokes the required service.
Controller invokes the method of the RestaurantServicelmpl.
RestaurantServicelmpl performs the service and returns the data back.
IRestaurantService has to be injected into the RestaurantController.
RestaurantValidator has to be injected into the RestaurantController.
To perform Custom validation, you are provided with a class RestaurantValidator. Provide the necessary annotation and implement the validate method
Use appropriate annotations for performing the predefined validations.
To perform logging you are provided with logjxml file. Do not change the contents of the logjxml file provided as part of the code skeleton
Use Lombok to create getters and setters in BookTable. Do not alter the constructors provided as part of the code skeleton.
Configure logging using Slfj annotation with Lombok in RestaurantService and CustomizedResponse EntityExceptionHandler class.
When multiple validation fails, concatenate all messages as a single string and store it in details attribute of ExceptionResponse object.
Microservices implementation Guidelines
For Microservices implementation, we will be implementing projects.
Spring Cloud EurekaServer for service registry and discovery
Spring Boot for REST service creation
Spring Cloud gateway for API Gateway
Project :
This project should be the EurekaServer acting as the registry. Run this server in port
spring Eureka
System Status
Environment
Data center
test
default
Current time
Uptime
Lease expira
Renews thre
DS Replicas
Renews last
Project :
This project should be a spring boot application containing all the REST services implemented as per the requirements stated in the case study.
These services must be registered with EurekaServer.
These services must be registered with EurekaServer.
Run the services in port Services should get automatically registered with the Eureka Registry After the service is registered
Applicationname should be given as restaurantapp as specified in the case study.
Eureka Registry should run only in port
You can change application port number ie if required.
Project :
This must be a Spring cloud gateway project that contains the routing implementation to the actual services running in port Run this in port
Overall Design Constraints
Do not change the property name given in the application.properties files, you can change the value and you can include additional property if needed.
In the pom.xml you are provided with all the dependencies needed for developing the application. Do not change or add new dependencies
Use the service type and the service names as expected in the specification
Adhere to the design specifications mentioned in the case study.
Do not change or delete the classmethod names or return types which are provided to you as a part of the base code skeleton.
Developer will create applications:
Spring Boot Name of the application Should be RestaurantService
Spring Cloud EurekaServer, springcloudstartereurekaserverName of the application Should be RestaurantRegistry
Spring Cloud API GateWayspringcloudstartergatewayName of the application Should be RestaurantRouter
CORS related issues need to be handled at the application level.
Services can be tested using external tools like postman by the associate.
Eureka Registry should run only in port You can change the port number of the
application spring rest or the Gateway Router if required
Application should be configured in the GatewayRouter only by using serviceid and not
by using absolute url. ie in Gateway properties use the below properties to configure the service
zuul.routes.restaurantapp.serviceidrestaurantapp
To run the microservice, the order of execution of the applications are:
Restaurant Registry
RestaurantService
RestaurantRouter
Please make sure that your code does not have any compilation errors while submitting your case study solution.
PART II INTER MICROSERVICE CONFIGURATION
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started