Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Defines the query parameter for the statistic resource.
- *
- */
- public class StatisticFilterBean {
- private @QueryParam("find")
- String find;
- /**
- * Get the find query parameter.
- *
- * @return Query parameter.
- */
- public String getFind() {
- return find;
- }
- /**
- * Set the find query parameter.
- *
- * @param find Query parameter.
- */
- public void setFind(String find) {
- this.find = find;
- }
- }
- ===================================================
- /**
- * 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