components/src/test/java/eu/internetofus/common/components/personal_context_builder/WeNetPersonalContextBuilderSimulatorMocker.java
/**
   * Handler for get closest users into a location.
   *
   * @return the handler to manage the closest users.
   */
Handler for get closest users into a location.
@return the handler to manage the closest users.
Handler for get closest users into a location . @return the handler to manage the closest users .
protected Handler<RoutingContext> createGetClosest() {
    return ctx -> {
      try {
        final var latitude = Double.parseDouble(ctx.queryParam("latitude").get(0));
        final var longitude = Double.parseDouble(ctx.queryParam("longitude").get(0));
        final var numAgents = Integer.parseInt(ctx.queryParam("nb_user_max").get(0));
        final var usersDistances = new ArrayList<UserDistance>();
        final var max = this.locations.size();
        for (var i = 0; i < max; i++) {
          final var location = this.locations.get(i);
          final var userDistance = new UserDistance();
          userDistance.userId = location.userId;
          userDistance.distance = UserDistance.calculateDistance(latitude, longitude, location.latitude,
              location.longitude);
          usersDistances.add(userDistance);
        }
        usersDistances.sort((o1, o2) -> Double.compare(o1.distance, o2.distance));
        final var response = ctx.response();
        response.setStatusCode(Status.OK.getStatusCode());
        response
            .end(Model.toJsonArray(usersDistances.subList(0, Math.min(numAgents, usersDistances.size()))).toBuffer());
      } catch (final Throwable throwable) {
        final var response = ctx.response();
        response.setStatusCode(Status.BAD_REQUEST.getStatusCode());
        response.end(new ErrorMessage("bad_request", throwable.getMessage()).toBuffer());
      }
    };
  }
protected Handler < RoutingContext > createGetClosest ( ) { return ctx -> { try { final var latitude = Double . parseDouble ( ctx . queryParam ( "latitude" ) . get ( 0 ) ) ; final var longitude = Double . parseDouble ( ctx . queryParam ( "longitude" ) . get ( 0 ) ) ; final var numAgents = Integer . parseInt ( ctx . queryParam ( "nb_user_max" ) . get ( 0 ) ) ; final var usersDistances = new ArrayList < UserDistance > ( ) ; final var max = this . locations . size ( ) ; for ( var i = 0 ; i < max ; i ++ ) { final var location = this . locations . get ( i ) ; final var userDistance = new UserDistance ( ) ; userDistance . userId = location . userId ; userDistance . distance = UserDistance . calculateDistance ( latitude , longitude , location . latitude , location . longitude ) ; usersDistances . add ( userDistance ) ; } usersDistances . sort ( ( o1 , o2 ) -> Double . compare ( o1 . distance , o2 . distance ) ) ; final var response = ctx . response ( ) ; response . setStatusCode ( Status . OK . getStatusCode ( ) ) ; response . end ( Model . toJsonArray ( usersDistances . subList ( 0 , Math . min ( numAgents , usersDistances . size ( ) ) ) ) . toBuffer ( ) ) ; } catch ( final Throwable throwable ) { final var response = ctx . response ( ) ; response . setStatusCode ( Status . BAD_REQUEST . getStatusCode ( ) ) ; response . end ( new ErrorMessage ( "bad_request" , throwable . getMessage ( ) ) . toBuffer ( ) ) ; } } ; }
Handler for get closest users into a location.
Handler for get closest users into a location .