Esempio n. 1
0
  @POST
  @Produces("application/json")
  @Consumes("application/json")
  @Path("/v1/json/{id}/addrating")
  public Response addRatingsForProvider(Rating rating, @PathParam("id") String id) {
    long start = System.currentTimeMillis();

    try {
      getProviderService().addRatingForProvider(id, rating);
      ResponsePojo res = new ResponsePojo();
      res.setSuccess(true);
      res.setMessage("");
      res.setData("Saved rating");
      long end = System.currentTimeMillis();
      res.setTimeInSecs(String.valueOf((end - start) / 1000));
      return Response.ok().entity(res).build();
    } catch (UnknownHostException e) {
      e.printStackTrace();
      ResponsePojo res = new ResponsePojo();
      res.setSuccess(false);
      res.setMessage(e.getMessage());
      long end = System.currentTimeMillis();
      res.setTimeInSecs(String.valueOf((end - start) / 1000));
      return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(res).build();
    }
  }
Esempio n. 2
0
  @GET
  @Produces("application/json")
  @Path("/v1/json/providernumber/{number}")
  public Response getProviderByProviderId(@PathParam("id") Integer number) {
    long start = System.currentTimeMillis();

    try {
      Provider provider = getProviderService().getProviderByProviderId(number);
      if (provider != null) {
        ResponsePojo res = new ResponsePojo();
        res.setSuccess(true);
        res.setMessage("");
        res.setData(provider);
        long end = System.currentTimeMillis();
        res.setTimeInSecs(String.valueOf((end - start) / 1000));
        return Response.ok().entity(res).build();
      } else {
        ResponsePojo res = new ResponsePojo();
        res.setSuccess(false);
        res.setMessage("Provider not found with this provider number");
        long end = System.currentTimeMillis();
        res.setTimeInSecs(String.valueOf((end - start) / 1000));
        return Response.status(Response.Status.NOT_FOUND).entity(res).build();
      }
    } catch (UnknownHostException e) {
      e.printStackTrace();
      ResponsePojo res = new ResponsePojo();
      res.setSuccess(false);
      res.setMessage(e.getMessage());
      long end = System.currentTimeMillis();
      res.setTimeInSecs(String.valueOf((end - start) / 1000));
      return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(res).build();
    }
  }
Esempio n. 3
0
  @GET
  @Produces("application/json")
  @Path("/v1/json/{id}/cities")
  public Response getCitiesForProvider(@PathParam("id") String id) {
    long start = System.currentTimeMillis();

    try {
      List<String> cities = getProviderService().getApplicableCitiesForProvider(id);
      if (cities != null) {
        ResponsePojo res = new ResponsePojo();
        res.setSuccess(true);
        res.setMessage("");
        res.setData(cities);
        long end = System.currentTimeMillis();
        res.setTimeInSecs(String.valueOf((end - start) / 1000));
        return Response.ok().entity(res).build();
      } else {
        ResponsePojo res = new ResponsePojo();
        res.setSuccess(false);
        res.setMessage("No Ratings for this provider yet");
        long end = System.currentTimeMillis();
        res.setTimeInSecs(String.valueOf((end - start) / 1000));
        return Response.status(Response.Status.NOT_FOUND).entity(res).build();
      }
    } catch (UnknownHostException e) {
      e.printStackTrace();
      ResponsePojo res = new ResponsePojo();
      res.setSuccess(false);
      res.setMessage(e.getMessage());
      long end = System.currentTimeMillis();
      res.setTimeInSecs(String.valueOf((end - start) / 1000));
      return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(res).build();
    }
  }