# HG changeset patch # User Raimund Renkert # Date 1372942539 -7200 # Node ID a1c1ec27224a4336d2fc318973a6cb4d72bc9251 # Parent c9a1da2e159d4653b5c4d642bf2d46ce31b71aad New service for SMessgroesse objects. diff -r c9a1da2e159d -r a1c1ec27224a src/main/java/de/intevation/lada/rest/SMessgroesseService.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/de/intevation/lada/rest/SMessgroesseService.java Thu Jul 04 14:55:39 2013 +0200 @@ -0,0 +1,86 @@ +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.PathParam; +import javax.ws.rs.Produces; +import javax.ws.rs.core.Context; +import javax.ws.rs.core.HttpHeaders; + +import de.intevation.lada.authentication.Authentication; +import de.intevation.lada.authentication.AuthenticationException; +import de.intevation.lada.data.Repository; +import de.intevation.lada.model.SMessgroesse; + +/** + * This class produces a RESTful service to read SMessgroesse objects. + * + * @author Raimund Renkert + */ +@Path("/messgroesse") +@RequestScoped +public class SMessgroesseService +{ + /** + * The Repository for SMessMethode. + */ + @Inject + @Named("readonlyrepository") + private Repository repository; + + /** + * The authorization module. + */ + @Inject + @Named("ldapauth") + private Authentication authentication; + + /** + * Request all SMessMethode objects. + * + * @param headers The HTTP header containing authorization information. + * @return Response object. + */ + @GET + @Produces("text/json") + public Response findAll(@Context HttpHeaders headers) { + try { + if (authentication.isAuthorizedUser(headers)) { + return repository.findAll(SMessgroesse.class); + } + return new Response(false, 699, new ArrayList()); + } + catch(AuthenticationException ae) { + return new Response(false, 699, new ArrayList()); + } + } + + /** + * Request a SMessMethode object via its id. + * + * @param id The object id. + * @param headers The HTTP header containing authorization information. + * @return Response object. + */ + @GET + @Path("/{id:[0-9][0-9]*}") + @Produces("text/json") + public Response findById( + @PathParam("id") String id, + @Context HttpHeaders headers) { + try { + if (authentication.isAuthorizedUser(headers)) { + return repository.findById(SMessgroesse.class, id); + } + return new Response(false, 699, new ArrayList()); + } + catch(AuthenticationException ae) { + return new Response(false, 699, new ArrayList()); + } + } +}