Skip to content

Instantly share code, notes, and snippets.

@jdc18
Created June 18, 2015 17:45

Revisions

  1. @astro-jdc astro-jdc created this gist Jun 18, 2015.
    43 changes: 43 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,43 @@
    @GET
    @Produces("application/json")
    @NoCache
    public List<UsuarioJS> getUsuarios(@QueryParam("min") String min,
    @QueryParam("results") String results) {
    // Just to show how to user info from access token in REST endpoint
    KeycloakSecurityContext securityContext = (KeycloakSecurityContext) httpRequest
    .getAttribute(KeycloakSecurityContext.class.getName());
    AccessToken accessToken = securityContext.getToken();

    // Chequeamos que le valor min y max sea valido
    // La diferencia entre min y max no puede ser mayor a 20
    int minInt, maxInt;
    try {
    minInt = Integer.parseInt(min);
    } catch (NumberFormatException nfe) {
    minInt = 0;
    }
    try {
    maxInt = Integer.parseInt(results);
    } catch (NumberFormatException nfe) {
    maxInt = 10;
    }
    if (minInt < 0) {
    minInt = 0;
    }
    if (maxInt > 20) {
    maxInt = 20;
    }

    // TODO registro
    List<Usuario> usuarios = usuarioDao.obtenerUsuarios(minInt, maxInt,
    "ASC");
    List<UsuarioJS> finalUsuario = new ArrayList<UsuarioJS>();

    for (Usuario usuario : usuarios) {
    // System.out.println(temp);
    UsuarioJS usuarioJS = new UsuarioJS(usuario);
    finalUsuario.add(usuarioJS);
    }

    return finalUsuario;
    }