[Lada-commits] [PATCH 4 of 4] Added services for stammdaten and updated models

Wald Commits scm-commit at wald.intevation.org
Fri Jan 8 12:10:31 CET 2016


# HG changeset patch
# User Raimund Renkert <raimund.renkert at intevation.de>
# Date 1452251409 -3600
# Node ID 313bd1d227f1f9903744b17987473115ead33308
# Parent  075f511243d5f83fb639858a5ae336b1635cbe3f
Added services for stammdaten and updated models.

diff -r 075f511243d5 -r 313bd1d227f1 src/main/java/de/intevation/lada/model/stamm/DatensatzErzeuger.java
--- a/src/main/java/de/intevation/lada/model/stamm/DatensatzErzeuger.java	Fri Jan 08 12:09:12 2016 +0100
+++ b/src/main/java/de/intevation/lada/model/stamm/DatensatzErzeuger.java	Fri Jan 08 12:10:09 2016 +0100
@@ -5,6 +5,8 @@
 
 import javax.persistence.Column;
 import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.GenerationType;
 import javax.persistence.Id;
 import javax.persistence.Table;
 
@@ -19,6 +21,8 @@
     private static final long serialVersionUID = 1L;
 
     @Id
+    @GeneratedValue(strategy=GenerationType.IDENTITY)
+    @Column(name="id", unique=true, nullable=false)
     private Integer id;
 
     private String bezeichnung;
diff -r 075f511243d5 -r 313bd1d227f1 src/main/java/de/intevation/lada/model/stamm/MessprogrammKategorie.java
--- a/src/main/java/de/intevation/lada/model/stamm/MessprogrammKategorie.java	Fri Jan 08 12:09:12 2016 +0100
+++ b/src/main/java/de/intevation/lada/model/stamm/MessprogrammKategorie.java	Fri Jan 08 12:10:09 2016 +0100
@@ -5,6 +5,8 @@
 
 import javax.persistence.Column;
 import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.GenerationType;
 import javax.persistence.Id;
 import javax.persistence.Table;
 
@@ -19,6 +21,8 @@
     private static final long serialVersionUID = 1L;
 
     @Id
+    @GeneratedValue(strategy=GenerationType.IDENTITY)
+    @Column(name="id", unique=true, nullable=false)
     private Integer id;
 
     private String bezeichnung;
diff -r 075f511243d5 -r 313bd1d227f1 src/main/java/de/intevation/lada/model/stamm/Ort.java
--- a/src/main/java/de/intevation/lada/model/stamm/Ort.java	Fri Jan 08 12:09:12 2016 +0100
+++ b/src/main/java/de/intevation/lada/model/stamm/Ort.java	Fri Jan 08 12:10:09 2016 +0100
@@ -5,6 +5,8 @@
 
 import javax.persistence.Column;
 import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.GenerationType;
 import javax.persistence.Id;
 import javax.persistence.Table;
 
@@ -19,6 +21,8 @@
     private static final long serialVersionUID = 1L;
 
     @Id
+    @GeneratedValue(strategy=GenerationType.IDENTITY)
+    @Column(name="id", unique=true, nullable=false)
     private Integer id;
 
     private String aktiv;
diff -r 075f511243d5 -r 313bd1d227f1 src/main/java/de/intevation/lada/model/stamm/Probenehmer.java
--- a/src/main/java/de/intevation/lada/model/stamm/Probenehmer.java	Fri Jan 08 12:09:12 2016 +0100
+++ b/src/main/java/de/intevation/lada/model/stamm/Probenehmer.java	Fri Jan 08 12:10:09 2016 +0100
@@ -5,6 +5,8 @@
 
 import javax.persistence.Column;
 import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.GenerationType;
 import javax.persistence.Id;
 
 
@@ -17,6 +19,8 @@
     private static final long serialVersionUID = 1L;
 
     @Id
+    @GeneratedValue(strategy=GenerationType.IDENTITY)
+    @Column(name="id", unique=true, nullable=false)
     private Integer id;
 
     private String bearbeiter;
diff -r 075f511243d5 -r 313bd1d227f1 src/main/java/de/intevation/lada/rest/stamm/DatensatzErzeugerService.java
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/main/java/de/intevation/lada/rest/stamm/DatensatzErzeugerService.java	Fri Jan 08 12:10:09 2016 +0100
@@ -0,0 +1,176 @@
+/* Copyright (C) 2013 by Bundesamt fuer Strahlenschutz
+ * Software engineering by Intevation GmbH
+ *
+ * This file is Free Software under the GNU GPL (v>=3)
+ * and comes with ABSOLUTELY NO WARRANTY! Check out
+ * the documentation coming with IMIS-Labordaten-Application for details.
+ */
+package de.intevation.lada.rest.stamm;
+
+import javax.enterprise.context.RequestScoped;
+import javax.inject.Inject;
+import javax.servlet.http.HttpServletRequest;
+import javax.ws.rs.DELETE;
+import javax.ws.rs.GET;
+import javax.ws.rs.POST;
+import javax.ws.rs.PUT;
+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 javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.UriInfo;
+
+import de.intevation.lada.model.stamm.DatensatzErzeuger;
+import de.intevation.lada.util.annotation.AuthorizationConfig;
+import de.intevation.lada.util.annotation.RepositoryConfig;
+import de.intevation.lada.util.auth.Authorization;
+import de.intevation.lada.util.auth.AuthorizationType;
+import de.intevation.lada.util.data.Repository;
+import de.intevation.lada.util.data.RepositoryType;
+import de.intevation.lada.util.rest.RequestMethod;
+import de.intevation.lada.util.rest.Response;
+
+/**
+ * REST service for DatensatzErzeuger objects.
+ * <p>
+ * The services produce data in the application/json media type.
+ * A typical response holds information about the action performed and the data.
+ * <pre>
+ * <code>
+ * {
+ *  "success": [boolean];
+ *  "message": [string],
+ *  "data":[{
+ *      "id": [number],
+ *      "bezeichnung": [string],
+ *      "daErzeugerId": [string],
+ *      "letzteAenderung": [timestamp],
+ *      "mstId": [string],
+ *      "netzbetreiberId": [string]
+ *  }],
+ *  "errors": [object],
+ *  "warnings": [object],
+ *  "readonly": [boolean],
+ *  "totalCount": [number]
+ * }
+ * </code>
+ * </pre>
+ *
+ * @author <a href="mailto:rrenkert at intevation.de">Raimund Renkert</a>
+ */
+ at Path("rest/datensatzerzeuger")
+ at RequestScoped
+public class DatensatzErzeugerService {
+
+    /**
+     * The data repository granting read access.
+     */
+    @Inject
+    @RepositoryConfig(type=RepositoryType.RW)
+    private Repository repository;
+
+    @Inject
+    @AuthorizationConfig(type=AuthorizationType.HEADER)
+    private Authorization authorization;
+
+    /**
+     * Get all Datenbasis objects.
+     * <p>
+     * Example: http://example.com/datenbasis
+     *
+     * @return Response object containing all Datenbasis objects.
+     */
+    @GET
+    @Path("/")
+    @Produces(MediaType.APPLICATION_JSON)
+    public Response get(
+        @Context HttpHeaders headers,
+        @Context UriInfo info
+    ) {
+        return repository.getAll(DatensatzErzeuger.class, "stamm");
+    }
+
+    /**
+     * Get a single Datenbasis object by id.
+     * <p>
+     * The id is appended to the URL as a path parameter.
+     * <p>
+     * Example: http://example.com/datenbasis/{id}
+     *
+     * @return Response object containing a single Datenabasis.
+     */
+    @GET
+    @Path("/{id}")
+    @Produces(MediaType.APPLICATION_JSON)
+    public Response getById(
+        @Context HttpHeaders headers,
+        @PathParam("id") String id
+    ) {
+        return repository.getById(
+            DatensatzErzeuger.class,
+            Integer.valueOf(id),
+            "stamm");
+    }
+
+    @POST
+    @Path("/")
+    @Produces(MediaType.APPLICATION_JSON)
+    public Response create(
+        @Context HttpServletRequest request,
+        DatensatzErzeuger datensatzerzeuger
+    ) {
+        if (!authorization.isAuthorized(
+            request,
+            datensatzerzeuger,
+            RequestMethod.POST,
+            DatensatzErzeuger.class)
+        ) {
+            return new Response(false, 699, datensatzerzeuger);
+        }
+
+        return repository.create(datensatzerzeuger, "stamm");
+    }
+
+    @PUT
+    @Path("/{id}")
+    @Produces(MediaType.APPLICATION_JSON)
+    public Response update(
+        @Context HttpServletRequest request,
+        DatensatzErzeuger datensatzerzeuger
+    ) {
+        if (!authorization.isAuthorized(
+            request,
+            datensatzerzeuger,
+            RequestMethod.PUT,
+            DatensatzErzeuger.class)
+        ) {
+            return new Response(false, 699, datensatzerzeuger);
+        }
+
+        return repository.update(datensatzerzeuger, "stamm");
+    }
+
+    @DELETE
+    @Path("/{id}")
+    @Produces(MediaType.APPLICATION_JSON)
+    public Response delete(
+        @Context HttpServletRequest request,
+        @PathParam("id") String id
+    ) {
+        DatensatzErzeuger datensatzerzeuger = repository.getByIdPlain(
+            DatensatzErzeuger.class, Integer.valueOf(id), "stamm");
+        if (datensatzerzeuger == null ||
+            !authorization.isAuthorized(
+                request,
+                datensatzerzeuger,
+                RequestMethod.DELETE,
+                DatensatzErzeuger.class
+            )
+        ) {
+            return new Response(false, 699, null);
+        }
+        return repository.delete(datensatzerzeuger, "stamm");
+    }
+}
diff -r 075f511243d5 -r 313bd1d227f1 src/main/java/de/intevation/lada/rest/stamm/LocationService.java
--- a/src/main/java/de/intevation/lada/rest/stamm/LocationService.java	Fri Jan 08 12:09:12 2016 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,231 +0,0 @@
-/* Copyright (C) 2013 by Bundesamt fuer Strahlenschutz
- * Software engineering by Intevation GmbH
- *
- * This file is Free Software under the GNU GPL (v>=3)
- * and comes with ABSOLUTELY NO WARRANTY! Check out
- * the documentation coming with IMIS-Labordaten-Application for details.
- */
-package de.intevation.lada.rest.stamm;
-
-import javax.enterprise.context.RequestScoped;
-import javax.inject.Inject;
-import javax.ws.rs.DELETE;
-import javax.ws.rs.GET;
-import javax.ws.rs.POST;
-import javax.ws.rs.PUT;
-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 javax.ws.rs.core.MediaType;
-import javax.ws.rs.core.MultivaluedMap;
-import javax.ws.rs.core.UriInfo;
-
-import de.intevation.lada.model.stamm.Ort;
-import de.intevation.lada.util.annotation.RepositoryConfig;
-import de.intevation.lada.util.data.QueryBuilder;
-import de.intevation.lada.util.data.Repository;
-import de.intevation.lada.util.data.RepositoryType;
-import de.intevation.lada.util.rest.Response;
-
-/**
- * REST service for SOrt objects.
- * <p>
- * The services produce data in the application/json media type.
- * A typical response holds information about the action performed and the data.
- * <pre>
- * <code>
- * {
- *  "success": [boolean];
- *  "message": [string],
- *  "data":[{
- *      "id": [number],
- *      "beschreibung": [string],
- *      "bezeichnung": [string],
- *      "hoeheLand": [number],
- *      "koordXExtern": [string],
- *      "koordYExtern": [string],
- *      "latitude": [number],
- *      "letzteAenderung": [timestamp],
- *      "longitude": [number],
- *      "nutsCode": [string],
- *      "unscharf": [string],
- *      "koordinatenartId": [number],
- *      "netzbetreiberId": [number],
- *      "staatId": [number],
- *      "verwaltungseinheitId": [string],
- *      "otyp": [string]
- *  }],
- *  "errors": [object],
- *  "warnings": [object],
- *  "readonly": [boolean],
- *  "totalCount": [number]
- * }
- * </code>
- * </pre>
- *
- * @author <a href="mailto:rrenkert at intevation.de">Raimund Renkert</a>
- */
- at Path("rest/ort")
- at RequestScoped
-public class LocationService {
-
-    /**
-     * The data repository granting read/write access.
-     */
-    @Inject
-    @RepositoryConfig(type=RepositoryType.RW)
-    private Repository defaultRepo;
-
-    /**
-     * Get all SOrt objects.
-     * <p>
-     * The requested objects can be filtered using a URL parameter named
-     * ortId.
-     * <p>
-     * Example: http://example.com/location?ortId=[ID]
-     *
-     * @return Response object containing all (filtered) SOrt objects.
-     */
-    @GET
-    @Path("/")
-    @Produces(MediaType.APPLICATION_JSON)
-    public Response get(
-        @Context HttpHeaders headers,
-        @Context UriInfo info
-    ) {
-        MultivaluedMap<String, String> params = info.getQueryParameters();
-        if (params.isEmpty() || !params.containsKey("ortId")) {
-            return defaultRepo.getAll(Ort.class, "stamm");
-        }
-        String ortId = params.getFirst("ortId");
-        QueryBuilder<Ort> builder =
-            new QueryBuilder<Ort>(
-                defaultRepo.entityManager("stamm"),
-                Ort.class);
-        builder.and("id", ortId);
-        return defaultRepo.filter(builder.getQuery(), "stamm");
-    }
-
-    /**
-     * Get a single SOrt object by id.
-     * <p>
-     * The id is appended to the URL as a path parameter.
-     * <p>
-     * Example: http://example.com/location/{id}
-     *
-     * @return Response object containing a single SOrt.
-     */
-    @GET
-    @Path("/{id}")
-    @Produces(MediaType.APPLICATION_JSON)
-    public Response getById(
-        @Context HttpHeaders headers,
-        @PathParam("id") String id
-    ) {
-        return defaultRepo.getById(
-            Ort.class,
-            Integer.valueOf(id),
-            "stamm");
-    }
-
-    /**
-     * Create a SOrt object.
-     * <p>
-     * The new object is embedded in the post data as JSON formatted string.
-     * <p>
-     * <pre>
-     * <code>
-     * {
-     *  "bezeichnung": [string],
-     *  "beschreibung": [string],
-     *  "unscharf": [string],
-     *  "nutsCode": [string],
-     *  "koordXExtern": [string],
-     *  "koordYExtern": [string],
-     *  "hoeheLand": [string],
-     *  "longitude": [number],
-     *  "latitude": [number],
-     *  "staatId": [number],
-     *  "verwaltungseinheitId": [string],
-     *  "otyp": [string],
-     *  "letzteAenderung": [date]
-     * }
-     * </code>
-     * </pre>
-     * @return A response object containing the created SOrt.
-     */
-    @POST
-    @Path("/")
-    @Produces(MediaType.APPLICATION_JSON)
-    public Response create(
-        @Context HttpHeaders headers,
-        Ort ort
-    ) {
-        /* Persist the new object*/
-        return defaultRepo.create(ort, "stamm");
-    }
-
-    /**
-     * Update an existing SOrt object.
-     * <p>
-     * The object to update should come as JSON formatted string.
-     * <pre>
-     * <code>
-     * {
-     *  "id": [number],
-     *  "bezeichnung": [string],
-     *  "beschreibung": [string],
-     *  "unscharf": [string],
-     *  "nutsCode": [string],
-     *  "koordXExtern": [string],
-     *  "koordYExtern": [string],
-     *  "hoeheLand": [number],
-     *  "longitude": [number],
-     *  "latitude": [number],
-     *  "staatId": [number],
-     *  "verwaltungseinheitId": [string],
-     *  "otyp": [string],
-     *  "letzteAenderung": [date]
-     * }
-     * </code>
-     * </pre>
-     *
-     * @return Response object containing the updated SOrt object.
-     */
-    @PUT
-    @Path("/{id}")
-    @Produces(MediaType.APPLICATION_JSON)
-    public Response update(@Context HttpHeaders headers, Ort ort) {
-        Response response = defaultRepo.update(ort, "stamm");
-        Response updated = defaultRepo.getById(
-            Ort.class,
-            ((Ort)response.getData()).getId(), "stamm");
-        return updated;
-    }
-
-    /**
-     * Delete an existing SOrt object by id.
-     * <p>
-     * The id is appended to the URL as a path parameter.
-     * <p>
-     * Example: http://example.com/location/{id}
-     *
-     * @return Response object.
-     */
-    @DELETE
-    @Path("/{id}")
-    @Produces(MediaType.APPLICATION_JSON)
-    public Response delete(
-        @Context HttpHeaders headers,
-        @PathParam("id") String id
-    ) {
-        /* Get the object by id*/
-        Response object =
-            defaultRepo.getById(Ort.class, Integer.valueOf(id), "stamm");
-        Ort ortObj = (Ort)object.getData();
-        /* Delete the object*/
-        return defaultRepo.delete(ortObj, "stamm");
-    }
-}
diff -r 075f511243d5 -r 313bd1d227f1 src/main/java/de/intevation/lada/rest/stamm/MessprogrammKategorieService.java
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/main/java/de/intevation/lada/rest/stamm/MessprogrammKategorieService.java	Fri Jan 08 12:10:09 2016 +0100
@@ -0,0 +1,177 @@
+/* Copyright (C) 2013 by Bundesamt fuer Strahlenschutz
+ * Software engineering by Intevation GmbH
+ *
+ * This file is Free Software under the GNU GPL (v>=3)
+ * and comes with ABSOLUTELY NO WARRANTY! Check out
+ * the documentation coming with IMIS-Labordaten-Application for details.
+ */
+package de.intevation.lada.rest.stamm;
+
+import javax.enterprise.context.RequestScoped;
+import javax.inject.Inject;
+import javax.servlet.http.HttpServletRequest;
+import javax.ws.rs.DELETE;
+import javax.ws.rs.GET;
+import javax.ws.rs.POST;
+import javax.ws.rs.PUT;
+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 javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.UriInfo;
+
+import de.intevation.lada.model.stamm.DatensatzErzeuger;
+import de.intevation.lada.model.stamm.MessprogrammKategorie;
+import de.intevation.lada.util.annotation.AuthorizationConfig;
+import de.intevation.lada.util.annotation.RepositoryConfig;
+import de.intevation.lada.util.auth.Authorization;
+import de.intevation.lada.util.auth.AuthorizationType;
+import de.intevation.lada.util.data.Repository;
+import de.intevation.lada.util.data.RepositoryType;
+import de.intevation.lada.util.rest.RequestMethod;
+import de.intevation.lada.util.rest.Response;
+
+/**
+ * REST service for DatensatzErzeuger objects.
+ * <p>
+ * The services produce data in the application/json media type.
+ * A typical response holds information about the action performed and the data.
+ * <pre>
+ * <code>
+ * {
+ *  "success": [boolean];
+ *  "message": [string],
+ *  "data":[{
+ *      "id": [number],
+ *      "bezeichnung": [string],
+ *      "daErzeugerId": [string],
+ *      "letzteAenderung": [timestamp],
+ *      "mstId": [string],
+ *      "netzbetreiberId": [string]
+ *  }],
+ *  "errors": [object],
+ *  "warnings": [object],
+ *  "readonly": [boolean],
+ *  "totalCount": [number]
+ * }
+ * </code>
+ * </pre>
+ *
+ * @author <a href="mailto:rrenkert at intevation.de">Raimund Renkert</a>
+ */
+ at Path("rest/messprogrammkategorie")
+ at RequestScoped
+public class MessprogrammKategorieService {
+
+    /**
+     * The data repository granting read access.
+     */
+    @Inject
+    @RepositoryConfig(type=RepositoryType.RW)
+    private Repository repository;
+
+    @Inject
+    @AuthorizationConfig(type=AuthorizationType.HEADER)
+    private Authorization authorization;
+
+    /**
+     * Get all Datenbasis objects.
+     * <p>
+     * Example: http://example.com/messprogrammkategorie
+     *
+     * @return Response object containing all objects.
+     */
+    @GET
+    @Path("/")
+    @Produces(MediaType.APPLICATION_JSON)
+    public Response get(
+        @Context HttpHeaders headers,
+        @Context UriInfo info
+    ) {
+        return repository.getAll(MessprogrammKategorie.class, "stamm");
+    }
+
+    /**
+     * Get a single object by id.
+     * <p>
+     * The id is appended to the URL as a path parameter.
+     * <p>
+     * Example: http://example.com/messprogrammkategorie/{id}
+     *
+     * @return Response object containing a single object.
+     */
+    @GET
+    @Path("/{id}")
+    @Produces(MediaType.APPLICATION_JSON)
+    public Response getById(
+        @Context HttpHeaders headers,
+        @PathParam("id") String id
+    ) {
+        return repository.getById(
+            MessprogrammKategorie.class,
+            Integer.valueOf(id),
+            "stamm");
+    }
+
+    @POST
+    @Path("/")
+    @Produces(MediaType.APPLICATION_JSON)
+    public Response create(
+        @Context HttpServletRequest request,
+        MessprogrammKategorie kategorie
+    ) {
+        if (!authorization.isAuthorized(
+            request,
+            kategorie,
+            RequestMethod.POST,
+            MessprogrammKategorie.class)
+        ) {
+            return new Response(false, 699, kategorie);
+        }
+
+        return repository.create(kategorie, "stamm");
+    }
+
+    @PUT
+    @Path("/{id}")
+    @Produces(MediaType.APPLICATION_JSON)
+    public Response update(
+        @Context HttpServletRequest request,
+        MessprogrammKategorie kategorie
+    ) {
+        if (!authorization.isAuthorized(
+            request,
+            kategorie,
+            RequestMethod.PUT,
+            MessprogrammKategorie.class)
+        ) {
+            return new Response(false, 699, kategorie);
+        }
+
+        return repository.update(kategorie, "stamm");
+    }
+
+    @DELETE
+    @Path("/{id}")
+    @Produces(MediaType.APPLICATION_JSON)
+    public Response delete(
+        @Context HttpServletRequest request,
+        @PathParam("id") String id
+    ) {
+        MessprogrammKategorie kategorie = repository.getByIdPlain(
+            MessprogrammKategorie.class, Integer.valueOf(id), "stamm");
+        if (kategorie == null ||
+            !authorization.isAuthorized(
+                request,
+                kategorie,
+                RequestMethod.DELETE,
+                MessprogrammKategorie.class
+            )
+        ) {
+            return new Response(false, 699, null);
+        }
+        return repository.delete(kategorie, "stamm");
+    }
+}
diff -r 075f511243d5 -r 313bd1d227f1 src/main/java/de/intevation/lada/rest/stamm/OrtService.java
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/main/java/de/intevation/lada/rest/stamm/OrtService.java	Fri Jan 08 12:10:09 2016 +0100
@@ -0,0 +1,266 @@
+/* Copyright (C) 2013 by Bundesamt fuer Strahlenschutz
+ * Software engineering by Intevation GmbH
+ *
+ * This file is Free Software under the GNU GPL (v>=3)
+ * and comes with ABSOLUTELY NO WARRANTY! Check out
+ * the documentation coming with IMIS-Labordaten-Application for details.
+ */
+package de.intevation.lada.rest.stamm;
+
+import javax.enterprise.context.RequestScoped;
+import javax.inject.Inject;
+import javax.servlet.http.HttpServletRequest;
+import javax.ws.rs.DELETE;
+import javax.ws.rs.GET;
+import javax.ws.rs.POST;
+import javax.ws.rs.PUT;
+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 javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.MultivaluedMap;
+import javax.ws.rs.core.UriInfo;
+
+import de.intevation.lada.model.stamm.Ort;
+import de.intevation.lada.util.annotation.AuthorizationConfig;
+import de.intevation.lada.util.annotation.RepositoryConfig;
+import de.intevation.lada.util.auth.Authorization;
+import de.intevation.lada.util.auth.AuthorizationType;
+import de.intevation.lada.util.data.QueryBuilder;
+import de.intevation.lada.util.data.Repository;
+import de.intevation.lada.util.data.RepositoryType;
+import de.intevation.lada.util.rest.RequestMethod;
+import de.intevation.lada.util.rest.Response;
+
+/**
+ * REST service for SOrt objects.
+ * <p>
+ * The services produce data in the application/json media type.
+ * A typical response holds information about the action performed and the data.
+ * <pre>
+ * <code>
+ * {
+ *  "success": [boolean];
+ *  "message": [string],
+ *  "data":[{
+ *      "id": [number],
+ *      "beschreibung": [string],
+ *      "bezeichnung": [string],
+ *      "hoeheLand": [number],
+ *      "koordXExtern": [string],
+ *      "koordYExtern": [string],
+ *      "latitude": [number],
+ *      "letzteAenderung": [timestamp],
+ *      "longitude": [number],
+ *      "nutsCode": [string],
+ *      "unscharf": [string],
+ *      "koordinatenartId": [number],
+ *      "netzbetreiberId": [number],
+ *      "staatId": [number],
+ *      "verwaltungseinheitId": [string],
+ *      "otyp": [string]
+ *  }],
+ *  "errors": [object],
+ *  "warnings": [object],
+ *  "readonly": [boolean],
+ *  "totalCount": [number]
+ * }
+ * </code>
+ * </pre>
+ *
+ * @author <a href="mailto:rrenkert at intevation.de">Raimund Renkert</a>
+ */
+ at Path("rest/ort")
+ at RequestScoped
+public class OrtService {
+
+    /**
+     * The data repository granting read/write access.
+     */
+    @Inject
+    @RepositoryConfig(type=RepositoryType.RW)
+    private Repository defaultRepo;
+
+    @Inject
+    @AuthorizationConfig(type=AuthorizationType.HEADER)
+    private Authorization authorization;
+
+    /**
+     * Get all SOrt objects.
+     * <p>
+     * The requested objects can be filtered using a URL parameter named
+     * ortId.
+     * <p>
+     * Example: http://example.com/location?ortId=[ID]
+     *
+     * @return Response object containing all (filtered) SOrt objects.
+     */
+    @GET
+    @Path("/")
+    @Produces(MediaType.APPLICATION_JSON)
+    public Response get(
+        @Context HttpHeaders headers,
+        @Context UriInfo info
+    ) {
+        MultivaluedMap<String, String> params = info.getQueryParameters();
+        if (params.isEmpty() || !params.containsKey("ortId")) {
+            return defaultRepo.getAll(Ort.class, "stamm");
+        }
+        String ortId = params.getFirst("ortId");
+        QueryBuilder<Ort> builder =
+            new QueryBuilder<Ort>(
+                defaultRepo.entityManager("stamm"),
+                Ort.class);
+        builder.and("id", ortId);
+        return defaultRepo.filter(builder.getQuery(), "stamm");
+    }
+
+    /**
+     * Get a single SOrt object by id.
+     * <p>
+     * The id is appended to the URL as a path parameter.
+     * <p>
+     * Example: http://example.com/location/{id}
+     *
+     * @return Response object containing a single SOrt.
+     */
+    @GET
+    @Path("/{id}")
+    @Produces(MediaType.APPLICATION_JSON)
+    public Response getById(
+        @Context HttpHeaders headers,
+        @PathParam("id") String id
+    ) {
+        return defaultRepo.getById(
+            Ort.class,
+            Integer.valueOf(id),
+            "stamm");
+    }
+
+    /**
+     * Create a SOrt object.
+     * <p>
+     * The new object is embedded in the post data as JSON formatted string.
+     * <p>
+     * <pre>
+     * <code>
+     * {
+     *  "bezeichnung": [string],
+     *  "beschreibung": [string],
+     *  "unscharf": [string],
+     *  "nutsCode": [string],
+     *  "koordXExtern": [string],
+     *  "koordYExtern": [string],
+     *  "hoeheLand": [string],
+     *  "longitude": [number],
+     *  "latitude": [number],
+     *  "staatId": [number],
+     *  "verwaltungseinheitId": [string],
+     *  "otyp": [string],
+     *  "letzteAenderung": [date]
+     * }
+     * </code>
+     * </pre>
+     * @return A response object containing the created SOrt.
+     */
+    @POST
+    @Path("/")
+    @Produces(MediaType.APPLICATION_JSON)
+    public Response create(
+        @Context HttpServletRequest request,
+        Ort ort
+    ) {
+        if (!authorization.isAuthorized(
+            request,
+            ort,
+            RequestMethod.DELETE,
+            Ort.class)
+        ) {
+            return new Response(false, 699, ort);
+        }
+        /* Persist the new object*/
+        return defaultRepo.create(ort, "stamm");
+    }
+
+    /**
+     * Update an existing SOrt object.
+     * <p>
+     * The object to update should come as JSON formatted string.
+     * <pre>
+     * <code>
+     * {
+     *  "id": [number],
+     *  "bezeichnung": [string],
+     *  "beschreibung": [string],
+     *  "unscharf": [string],
+     *  "nutsCode": [string],
+     *  "koordXExtern": [string],
+     *  "koordYExtern": [string],
+     *  "hoeheLand": [number],
+     *  "longitude": [number],
+     *  "latitude": [number],
+     *  "staatId": [number],
+     *  "verwaltungseinheitId": [string],
+     *  "otyp": [string],
+     *  "letzteAenderung": [date]
+     * }
+     * </code>
+     * </pre>
+     *
+     * @return Response object containing the updated SOrt object.
+     */
+    @PUT
+    @Path("/{id}")
+    @Produces(MediaType.APPLICATION_JSON)
+    public Response update(
+        @Context HttpServletRequest request,
+        Ort ort
+    ) {
+        if (!authorization.isAuthorized(
+            request,
+            ort,
+            RequestMethod.DELETE,
+            Ort.class)
+        ) {
+            return new Response(false, 699, ort);
+        }
+        Response response = defaultRepo.update(ort, "stamm");
+        Response updated = defaultRepo.getById(
+            Ort.class,
+            ((Ort)response.getData()).getId(), "stamm");
+        return updated;
+    }
+
+    /**
+     * Delete an existing SOrt object by id.
+     * <p>
+     * The id is appended to the URL as a path parameter.
+     * <p>
+     * Example: http://example.com/location/{id}
+     *
+     * @return Response object.
+     */
+    @DELETE
+    @Path("/{id}")
+    @Produces(MediaType.APPLICATION_JSON)
+    public Response delete(
+        @Context HttpServletRequest request,
+        @PathParam("id") String id
+    ) {
+        /* Get the object by id*/
+        Ort ort =
+            defaultRepo.getByIdPlain(Ort.class, Integer.valueOf(id), "stamm");
+        if (!authorization.isAuthorized(
+            request,
+            ort,
+            RequestMethod.DELETE,
+            Ort.class)
+        ) {
+            return new Response(false, 699, ort);
+        }
+        /* Delete the object*/
+        return defaultRepo.delete(ort, "stamm");
+    }
+}
diff -r 075f511243d5 -r 313bd1d227f1 src/main/java/de/intevation/lada/rest/stamm/ProbenehmerService.java
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/main/java/de/intevation/lada/rest/stamm/ProbenehmerService.java	Fri Jan 08 12:10:09 2016 +0100
@@ -0,0 +1,174 @@
+/* Copyright (C) 2013 by Bundesamt fuer Strahlenschutz
+ * Software engineering by Intevation GmbH
+ *
+ * This file is Free Software under the GNU GPL (v>=3)
+ * and comes with ABSOLUTELY NO WARRANTY! Check out
+ * the documentation coming with IMIS-Labordaten-Application for details.
+ */
+package de.intevation.lada.rest.stamm;
+
+import javax.enterprise.context.RequestScoped;
+import javax.inject.Inject;
+import javax.servlet.http.HttpServletRequest;
+import javax.ws.rs.DELETE;
+import javax.ws.rs.GET;
+import javax.ws.rs.POST;
+import javax.ws.rs.PUT;
+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 javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.UriInfo;
+
+import de.intevation.lada.model.stamm.DatensatzErzeuger;
+import de.intevation.lada.model.stamm.Probenehmer;
+import de.intevation.lada.util.annotation.AuthorizationConfig;
+import de.intevation.lada.util.annotation.RepositoryConfig;
+import de.intevation.lada.util.auth.Authorization;
+import de.intevation.lada.util.auth.AuthorizationType;
+import de.intevation.lada.util.data.Repository;
+import de.intevation.lada.util.data.RepositoryType;
+import de.intevation.lada.util.rest.RequestMethod;
+import de.intevation.lada.util.rest.Response;
+
+/**
+ * REST service for Probenehmer objects.
+ * <p>
+ * The services produce data in the application/json media type.
+ * A typical response holds information about the action performed and the data.
+ * <pre>
+ * <code>
+ * {
+ *  "success": [boolean];
+ *  "message": [string],
+ *  "data":[{
+ *      "id": [number],
+ *      "mstId": [string],
+ *      "netzbetreiberId": [string]
+ *  }],
+ *  "errors": [object],
+ *  "warnings": [object],
+ *  "readonly": [boolean],
+ *  "totalCount": [number]
+ * }
+ * </code>
+ * </pre>
+ *
+ * @author <a href="mailto:rrenkert at intevation.de">Raimund Renkert</a>
+ */
+ at Path("rest/probenehmer")
+ at RequestScoped
+public class ProbenehmerService {
+
+    /**
+     * The data repository granting read access.
+     */
+    @Inject
+    @RepositoryConfig(type=RepositoryType.RW)
+    private Repository repository;
+
+    @Inject
+    @AuthorizationConfig(type=AuthorizationType.HEADER)
+    private Authorization authorization;
+
+    /**
+     * Get all Probenehmer objects.
+     * <p>
+     * Example: http://example.com/probenehmer
+     *
+     * @return Response object containing all objects.
+     */
+    @GET
+    @Path("/")
+    @Produces(MediaType.APPLICATION_JSON)
+    public Response get(
+        @Context HttpHeaders headers,
+        @Context UriInfo info
+    ) {
+        return repository.getAll(Probenehmer.class, "stamm");
+    }
+
+    /**
+     * Get a single Datenbasis object by id.
+     * <p>
+     * The id is appended to the URL as a path parameter.
+     * <p>
+     * Example: http://example.com/probenehmer/{id}
+     *
+     * @return Response object containing a single object.
+     */
+    @GET
+    @Path("/{id}")
+    @Produces(MediaType.APPLICATION_JSON)
+    public Response getById(
+        @Context HttpHeaders headers,
+        @PathParam("id") String id
+    ) {
+        return repository.getById(
+            Probenehmer.class,
+            Integer.valueOf(id),
+            "stamm");
+    }
+
+    @POST
+    @Path("/")
+    @Produces(MediaType.APPLICATION_JSON)
+    public Response create(
+        @Context HttpServletRequest request,
+        Probenehmer probenehmer
+    ) {
+        if (!authorization.isAuthorized(
+            request,
+            probenehmer,
+            RequestMethod.POST,
+            Probenehmer.class)
+        ) {
+            return new Response(false, 699, probenehmer);
+        }
+
+        return repository.create(probenehmer, "stamm");
+    }
+
+    @PUT
+    @Path("/{id}")
+    @Produces(MediaType.APPLICATION_JSON)
+    public Response update(
+        @Context HttpServletRequest request,
+        Probenehmer probenehmer
+    ) {
+        if (!authorization.isAuthorized(
+            request,
+            probenehmer,
+            RequestMethod.PUT,
+            Probenehmer.class)
+        ) {
+            return new Response(false, 699, probenehmer);
+        }
+
+        return repository.update(probenehmer, "stamm");
+    }
+
+    @DELETE
+    @Path("/{id}")
+    @Produces(MediaType.APPLICATION_JSON)
+    public Response delete(
+        @Context HttpServletRequest request,
+        @PathParam("id") String id
+    ) {
+        Probenehmer probenehmer = repository.getByIdPlain(
+            Probenehmer.class, Integer.valueOf(id), "stamm");
+        if (probenehmer == null ||
+            !authorization.isAuthorized(
+                request,
+                probenehmer,
+                RequestMethod.DELETE,
+                Probenehmer.class
+            )
+        ) {
+            return new Response(false, 699, null);
+        }
+        return repository.delete(probenehmer, "stamm");
+    }
+}


More information about the Lada-commits mailing list