# HG changeset patch # User Torsten Irländer # Date 1374649797 -7200 # Node ID 6c26e6474c0fd94d7ee3b437490ee1d2b415c700 # Parent 543c2ae3bb39af65eeeb237b573a845d51a33f15 Added service to fetch sql query configurations. diff -r 543c2ae3bb39 -r 6c26e6474c0f src/main/java/de/intevation/lada/rest/QueryService.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/de/intevation/lada/rest/QueryService.java Wed Jul 24 09:09:57 2013 +0200 @@ -0,0 +1,68 @@ +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 Torsten Irländer + */ +@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()); + } + String queries = this.loadQueryConfig(); + Response response = new Response(true, 200, queries); + return response; + } + catch(AuthenticationException ae) { + return new Response(false, 699, new ArrayList()); + } + } + + private String loadQueryConfig() { + String query = "[]"; + return query; + } +}