Mercurial > lada > lada-server
view src/main/java/de/intevation/lada/rest/QueryService.java @ 266:2e86f535f290
Added basic query configuration sekeleton
author | Torsten Irländer <torsten.irlaender@intevation.de> |
---|---|
date | Wed, 24 Jul 2013 10:57:18 +0200 |
parents | 6c26e6474c0f |
children | df168246a4d2 |
line wrap: on
line source
package de.intevation.lada.rest; import java.util.ArrayList; import javax.enterprise.context.RequestScoped; import javax.inject.Inject; import javax.inject.Named; import javax.ws.rs.GET; import javax.ws.rs.Path; import javax.ws.rs.Produces; import javax.ws.rs.core.Context; import javax.ws.rs.core.HttpHeaders; import javax.ws.rs.core.UriInfo; import de.intevation.lada.auth.Authentication; import de.intevation.lada.auth.AuthenticationException; import de.intevation.lada.model.LOrt; /** * This class produces a RESTful service to read, write and update * LOrt objects. * * @author <a href="mailto:torsten.irlaender@intevation.de">Torsten Irländer</a> */ @Path("/query") @RequestScoped public class QueryService { /** * The authorization module. */ @Inject @Named("ldapauth") private Authentication authentication; /** * Request SQL-Queries * * Query parameters are used for the filter in form of key-value pairs. * * @param info The URL query parameters. * @param headers The HTTP header containing authorization information. * @return Response object. */ @GET @Produces("text/json") public Response filter( @Context UriInfo info, @Context HttpHeaders headers ) { try { if (!authentication.isAuthorizedUser(headers)) { return new Response(false, 699, new ArrayList<LOrt>()); } String queries = this.loadQueryConfig(); Response response = new Response(true, 200, queries); return response; } catch(AuthenticationException ae) { return new Response(false, 699, new ArrayList<LOrt>()); } } private String loadQueryConfig() { String query = "[" + "{" + "\"id\": \"1\"," + "\"description\": \"Beschreibung für Query 1\"," + "\"sql\": \"SELECT * FROM l_probe;\"," + "\"filters\": [\"mst\"]," + "\"results\": [" + "{\"field\": \"\", \"label\": \"\", \"type\": \"\"}" + "]" + "}" + "]"; return query; } }