portfolio/src/main/java/com/google/sps/servlets/MarkerServlet.java
@Override
  public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException {
    double lat = Double.parseDouble(request.getParameter("lat"));
    double lng = Double.parseDouble(request.getParameter("lng"));
    Grid grid = Grid.createFromLatLng(lat, lng);

    Result resultEnum = new Result();

    /** Checks for valid coordinates (limited area covered). */
    if((lat < LAT_SOUTH_LIMIT || lat > LAT_NORTH_LIMIT) || (lng < LNG_WEST_LIMIT || lng > LNG_EAST_LIMIT)){
      System.out.println("Coordinates outside of bounds");
      return;
    }

    /**
     * Use to ensure that end-user provided HTML contains only elements and attributes that you are
     * expecting; no junk
     */
    try {
      String crime = Jsoup.clean(request.getParameter("crimeType"), Whitelist.none());
      String crimeDate = Jsoup.clean(request.getParameter("date"), Whitelist.none());
      String crimeTime = Jsoup.clean(request.getParameter("time"), Whitelist.none());
      String crimeAddress = Jsoup.clean(request.getParameter("address"), Whitelist.none());
      String crimeDescription = Jsoup.clean(request.getParameter("description"), Whitelist.none());
      if (!validateMarker(lat, lng, crimeDate, crimeTime, crime)) {
        resultEnum.setStatus(StoreStatus.FAILURE);
        resultEnum.setFailureType(StoreFailureType.REPEAT);
      }
      else {
        resultEnum.setStatus(StoreStatus.SUCCESS);
        Marker marker =
            new Marker(lat, lng, crime, crimeDate, crimeTime, crimeAddress, crimeDescription, grid.row, grid.col);
        storeMarker(marker);
      }
    } catch (Error error) {
        resultEnum.setStatus(StoreStatus.FAILURE);
        resultEnum.setFailureType(StoreFailureType.UNKNOWN);
      System.out.println(error);
    }

    response.getWriter().println(gson.toJson(resultEnum));
  }
/** Accepts a POST request containing a new marker. */
Accepts a POST request containing a new marker.
Accepts a POST request containing a new marker .
@Override
  public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException {
    double lat = Double.parseDouble(request.getParameter("lat"));
    double lng = Double.parseDouble(request.getParameter("lng"));
    Grid grid = Grid.createFromLatLng(lat, lng);
    Result resultEnum = new Result();
    /** Checks for valid coordinates (limited area covered). */
    if((lat < LAT_SOUTH_LIMIT || lat > LAT_NORTH_LIMIT) || (lng < LNG_WEST_LIMIT || lng > LNG_EAST_LIMIT)){
      System.out.println("Coordinates outside of bounds");
      return;
    }
    /**
     * Use to ensure that end-user provided HTML contains only elements and attributes that you are
     * expecting; no junk
     */
    try {
      String crime = Jsoup.clean(request.getParameter("crimeType"), Whitelist.none());
      String crimeDate = Jsoup.clean(request.getParameter("date"), Whitelist.none());
      String crimeTime = Jsoup.clean(request.getParameter("time"), Whitelist.none());
      String crimeAddress = Jsoup.clean(request.getParameter("address"), Whitelist.none());
      String crimeDescription = Jsoup.clean(request.getParameter("description"), Whitelist.none());
      if (!validateMarker(lat, lng, crimeDate, crimeTime, crime)) {
        resultEnum.setStatus(StoreStatus.FAILURE);
        resultEnum.setFailureType(StoreFailureType.REPEAT);
      }
      else {
        resultEnum.setStatus(StoreStatus.SUCCESS);
        Marker marker =
            new Marker(lat, lng, crime, crimeDate, crimeTime, crimeAddress, crimeDescription, grid.row, grid.col);
        storeMarker(marker);
      }
    } catch (Error error) {
        resultEnum.setStatus(StoreStatus.FAILURE);
        resultEnum.setFailureType(StoreFailureType.UNKNOWN);
      System.out.println(error);
    }
    response.getWriter().println(gson.toJson(resultEnum));
  }
@ Override public void doPost ( HttpServletRequest request , HttpServletResponse response ) throws IOException { double lat = Double . parseDouble ( request . getParameter ( "lat" ) ) ; double lng = Double . parseDouble ( request . getParameter ( "lng" ) ) ; Grid grid = Grid . createFromLatLng ( lat , lng ) ; Result resultEnum = new Result ( ) ; /** Checks for valid coordinates (limited area covered). */ if ( ( lat < LAT_SOUTH_LIMIT || lat > LAT_NORTH_LIMIT ) || ( lng < LNG_WEST_LIMIT || lng > LNG_EAST_LIMIT ) ) { System . out . println ( "Coordinates outside of bounds" ) ; return ; } /**
     * Use to ensure that end-user provided HTML contains only elements and attributes that you are
     * expecting; no junk
     */ try { String crime = Jsoup . clean ( request . getParameter ( "crimeType" ) , Whitelist . none ( ) ) ; String crimeDate = Jsoup . clean ( request . getParameter ( "date" ) , Whitelist . none ( ) ) ; String crimeTime = Jsoup . clean ( request . getParameter ( "time" ) , Whitelist . none ( ) ) ; String crimeAddress = Jsoup . clean ( request . getParameter ( "address" ) , Whitelist . none ( ) ) ; String crimeDescription = Jsoup . clean ( request . getParameter ( "description" ) , Whitelist . none ( ) ) ; if ( ! validateMarker ( lat , lng , crimeDate , crimeTime , crime ) ) { resultEnum . setStatus ( StoreStatus . FAILURE ) ; resultEnum . setFailureType ( StoreFailureType . REPEAT ) ; } else { resultEnum . setStatus ( StoreStatus . SUCCESS ) ; Marker marker = new Marker ( lat , lng , crime , crimeDate , crimeTime , crimeAddress , crimeDescription , grid . row , grid . col ) ; storeMarker ( marker ) ; } } catch ( Error error ) { resultEnum . setStatus ( StoreStatus . FAILURE ) ; resultEnum . setFailureType ( StoreFailureType . UNKNOWN ) ; System . out . println ( error ) ; } response . getWriter ( ) . println ( gson . toJson ( resultEnum ) ) ; }
Accepts a POST request containing a new marker.
Accepts a POST request containing a new marker .