changeset 216:feedf35fddcf

New read only service for SMessMethode objects.
author Raimund Renkert <rrenkert@intevation.de>
date Thu, 04 Jul 2013 08:48:26 +0200 (2013-07-04)
parents 0e94ef5e504a
children cf3394d280c4
files src/main/java/de/intevation/lada/rest/SMessMethodeService.java
diffstat 1 files changed, 81 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/main/java/de/intevation/lada/rest/SMessMethodeService.java	Thu Jul 04 08:48:26 2013 +0200
@@ -0,0 +1,81 @@
+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.SMessMethode;
+
+@Path("/messmethode")
+@RequestScoped
+public class SMessMethodeService
+{
+    /**
+     * The Repository for SUmwelt.
+     */
+    @Inject
+    @Named("readonlyrepository")
+    private Repository repository;
+
+    /**
+     * The authorization module.
+     */
+    @Inject
+    @Named("ldapauth")
+    private Authentication authentication;
+
+    /**
+     * Request all SStaat 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(SMessMethode.class);
+            }
+            return new Response(false, 699, new ArrayList<SMessMethode>());
+        }
+        catch(AuthenticationException ae) {
+            return new Response(false, 699, new ArrayList<SMessMethode>());
+        }
+    }
+
+    /**
+     * Request a SStaat 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(SMessMethode.class, id);
+            }
+            return new Response(false, 699, new ArrayList<SMessMethode>());
+        }
+        catch(AuthenticationException ae) {
+            return new Response(false, 699, new ArrayList<SMessMethode>());
+        }
+    }
+}
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)