Advertisement
Guest User

Untitled

a guest
Jan 22nd, 2017
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.62 KB | None | 0 0
  1.  
  2.  
  3. /**
  4. * Defines the query parameter for the statistic resource.
  5. *
  6. */
  7. public class StatisticFilterBean {
  8.  
  9. private @QueryParam("find")
  10. String find;
  11.  
  12. /**
  13. * Get the find query parameter.
  14. *
  15. * @return Query parameter.
  16. */
  17. public String getFind() {
  18. return find;
  19. }
  20.  
  21. /**
  22. * Set the find query parameter.
  23. *
  24. * @param find Query parameter.
  25. */
  26. public void setFind(String find) {
  27. this.find = find;
  28. }
  29. }
  30.  
  31.  
  32.  
  33.  
  34.  
  35.  
  36. ===================================================
  37.  
  38. /**
  39. * Defines the REST requests of the stastic resource.
  40. *
  41. */
  42. @Path("/statistics")
  43. @Api(value = "/statistics")
  44. public class StatisticResource {
  45.  
  46. StatisticService statisticService = new StatisticService();
  47.  
  48. /**
  49. * Defines the GET request for the statistic resource. The statistic can be
  50. * selected via query parameters.
  51. *
  52. * @param filterBean Filter parameter.
  53. * @return Result of the statistic.
  54. */
  55. @ApiOperation(
  56. value = "Get all statistics",
  57. response = Statistic.class
  58. )
  59. @ApiResponses(value = {
  60. @ApiResponse(code = 200, message = "All statistics fetched")
  61. ,
  62. @ApiResponse(code = 500, message = "Internal server error")
  63. ,
  64. @ApiResponse(code = 404, message = "Statistic method not found")
  65. })
  66. @GET
  67. @Produces(MediaType.APPLICATION_JSON)
  68. public Response getStatistics(@ApiParam(value = "statistic method that needs to be fetched", required = false) @BeanParam StatisticFilterBean filterBean) {
  69. Statistic statistic = statisticService.getStatistic();
  70. if (filterBean.getFind().toLowerCase() == "mostvisitedcountries") {
  71. return Response.status(200).entity(statistic.getMostVisitedCountries()).build();
  72. }
  73. else if (filterBean.getFind().toLowerCase() == "mostvisistedcities") {
  74. return Response.status(200).entity(statistic.getMostVisitedCities()).build();
  75. }
  76. else if (filterBean.getFind().toLowerCase() == "mostbookedaccomodations") {
  77. return Response.status(200).entity(statistic.getMostBookedAccomodations()).build();
  78. }
  79. else if (filterBean.getFind().toLowerCase() == "mostbookedactivities") {
  80. return Response.status(200).entity(statistic.getMostBookedAccomodations()).build();
  81. }
  82. else if (filterBean.getFind() != null) {
  83. throw new DataNotFoundException("the statistic " + filterBean.getFind() + " does not exist");
  84. }
  85. else
  86. return Response.status(500).entity(statistic).build();
  87. }
  88. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement