Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.travelagency.rest.resources;
- import io.swagger.annotations.Api;
- import io.swagger.annotations.ApiOperation;
- import io.swagger.annotations.ApiParam;
- import io.swagger.annotations.ApiResponse;
- import io.swagger.annotations.ApiResponses;
- import java.util.List;
- import javax.ws.rs.BeanParam;
- import javax.ws.rs.GET;
- import javax.ws.rs.Path;
- import javax.ws.rs.Produces;
- import javax.ws.rs.core.MediaType;
- import javax.ws.rs.core.Response;
- import com.travelagency.business.StatisticService;
- import com.travelagency.model.business.Statistic;
- import com.travelagency.rest.errorhandling.DataNotFoundException;
- import com.travelagency.rest.resources.beans.StatisticFilterBean;
- /**
- * Defines the REST requests of the stastic resource.
- *
- */
- @Path("/statistics")
- @Api(value = "/statistics")
- public class StatisticResource {
- StatisticService statisticService = new StatisticService();
- /**
- * Defines the GET request for the statistic resource. The statistic can be
- * selected via query parameters.
- *
- * @param filterBean Filter parameter.
- * @return Result of the statistic.
- */
- @ApiOperation(
- value = "Get all statistics",
- response = Statistic.class
- )
- @ApiResponses(value = {
- @ApiResponse(code = 200, message = "All statistics fetched")
- ,
- @ApiResponse(code = 500, message = "Internal server error")
- ,
- @ApiResponse(code = 404, message = "Statistic method not found")
- })
- @GET
- @Produces(MediaType.APPLICATION_JSON)
- public Response getStatistics(@ApiParam(value = "statistic method that needs to be fetched", required = false) @BeanParam StatisticFilterBean filterBean) {
- Statistic statistic = statisticService.getStatistic();
- if (filterBean.getFind().toLowerCase() == "mostvisitedcountries") {
- return Response.status(200).entity(statistic.getMostVisitedCountries()).build();
- }
- else if (filterBean.getFind().toLowerCase() == "mostvisistedcities") {
- return Response.status(200).entity(statistic.getMostVisitedCities()).build();
- }
- else if (filterBean.getFind().toLowerCase() == "mostbookedaccomodations") {
- return Response.status(200).entity(statistic.getMostBookedAccomodations()).build();
- }
- else if (filterBean.getFind().toLowerCase() == "mostbookedactivities") {
- return Response.status(200).entity(statistic.getMostBookedAccomodations()).build();
- }
- else if (filterBean.getFind() != null) {
- throw new DataNotFoundException("the statistic " + filterBean.getFind() + " does not exist");
- }
- else
- return Response.status(500).entity(statistic).build();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement