Skip to content

Instantly share code, notes, and snippets.

@jdc18
Created June 18, 2015 17:45
Show Gist options
  • Save jdc18/d6f60204a8184902480c to your computer and use it in GitHub Desktop.
Save jdc18/d6f60204a8184902480c to your computer and use it in GitHub Desktop.
@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;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment