[Lada-commits] [PATCH 7 of 8] Added REST interface for deskriptoren

Wald Commits scm-commit at wald.intevation.org
Tue May 12 15:20:09 CEST 2015


# HG changeset patch
# User Raimund Renkert <raimund.renkert at intevation.de>
# Date 1431436770 -7200
# Node ID 1a008800cd927c162c02bccf5cd867e56f6708ec
# Parent  55af47529ebd1286ab348732163f280d6ffa3e02
Added REST interface for deskriptoren.

diff -r 55af47529ebd -r 1a008800cd92 src/main/java/de/intevation/lada/rest/stamm/DeskriptorService.java
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/main/java/de/intevation/lada/rest/stamm/DeskriptorService.java	Tue May 12 15:19:30 2015 +0200
@@ -0,0 +1,161 @@
+/* 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 java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import javax.enterprise.context.RequestScoped;
+import javax.inject.Inject;
+import javax.servlet.http.HttpServletRequest;
+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 javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.MultivaluedMap;
+import javax.ws.rs.core.UriInfo;
+
+import de.intevation.lada.model.stamm.Deskriptoren;
+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 Probe objects.
+ * <p>
+ * The services produce data in the application/json media type.
+ * All HTTP methods use the authorization module to determine if the user is
+ * allowed to perform the requested action.
+ * A typical response holds information about the action performed and the data.
+ * <pre>
+ * <code>
+ * {
+ *  "success": [boolean];
+ *  "message": [string],
+ *  "data":[{
+ *      "id":[number],
+ *      "baId": [string],
+ *      "datenbasisId": [number],
+ *      "letzteAenderung": [timestamp],
+ *      "media": [string],
+ *      "mediaDesk": [string],
+ *      "mittelungsdauer": [number],
+ *      "mstId": [string],
+ *      "netzbetreiberId":[string],
+ *      "probeentnahmeBeginn": [timestamp],
+ *      "probeentnahmeEnde": [timestamp],
+ *      "probenartId": [number],
+ *      "test": [boolean],
+ *      "umwId": [string],
+ *      "hauptprobenNr": [string],
+ *      "erzeugerId": [string],
+ *      "mpKat": [string],
+ *      "mplId": [number],
+ *      "mprId": [number],
+ *      "probeNehmerId": [number],
+ *      "solldatumBeginn": [timestamp],
+ *      "solldatumEnde": [timestamp],
+ *      "treeModified": [timestamp],
+ *      "readonly": [boolean],
+ *      "owner": [boolean],
+ *      "probeIdAlt": [string]
+ *  }],
+ *  "errors": [object],
+ *  "warnings": [object],
+ *  "readonly": [boolean],
+ *  "totalCount": [number]
+ * }
+ * </code>
+ * </pre>
+ *
+ * @author <a href="mailto:rrenkert at intevation.de">Raimund Renkert</a>
+ */
+ at Path("deskriptor")
+ at RequestScoped
+public class DeskriptorService {
+
+    /**
+     * The data repository granting read/write access.
+     */
+    @Inject
+    @RepositoryConfig(type=RepositoryType.RO)
+    private Repository repository;
+
+    /**
+     * Get all Deskriptor objects.
+     * <p>
+     * The requested objects can be filtered using the following URL
+     * parameters:<br>
+     *  <br>
+     *  The response data contains a stripped set of Probe objects. The returned fields
+     *  are defined in the query used in the request.
+     * <p>
+     * Example:
+     * http://example.com/deskriptor?layer=[LAYER]
+     *
+     * @return Response object containing all Deskriptor objects.
+     */
+    @GET
+    @Path("/")
+    @Produces("application/json")
+    public Response get(
+        @Context HttpHeaders headers,
+        @Context UriInfo info,
+        @Context HttpServletRequest request
+    ) {
+        MultivaluedMap<String, String> params = info.getQueryParameters();
+        if (params.isEmpty() ||
+            !params.containsKey("layer")) {
+            return repository.getAll(Deskriptoren.class, "stamm");
+        }
+        QueryBuilder<Deskriptoren> builder = new QueryBuilder<Deskriptoren>(
+            repository.entityManager("stamm"),
+            Deskriptoren.class);
+        if (params.containsKey("layer") &&
+            !params.containsKey("parents")) {
+            String layer = params.getFirst("layer");
+            builder.and("ebene", layer);
+        }
+        else {
+            String layer = params.getFirst("layer");
+            String parents = params.getFirst("parents");
+            builder.and("ebene", layer);
+            List<String> parentList = new ArrayList<String>();
+            String[] parentArray = parents.split(", ");
+            parentList = Arrays.asList(parentArray);
+            builder.andIn("vorgaenger", parentList);
+        }
+        return repository.filter(builder.getQuery(), "stamm");
+    }
+
+    /**
+     * Get a single Deskriptor object by id.
+     * <p>
+     * The id is appended to the URL as a path parameter.
+     * <p>
+     * Example: http://example.com/deskriptor/{id}
+     *
+     * @return Response object containing a single Deskriptor.
+     */
+    @GET
+    @Path("/{id}")
+    @Produces(MediaType.APPLICATION_JSON)
+    public Response getById(
+        @Context HttpHeaders headers,
+        @PathParam("id") String id,
+        @Context HttpServletRequest request
+    ) {
+        return repository.getById(Deskriptoren.class, Integer.valueOf(id), "stamm");
+    }
+}


More information about the Lada-commits mailing list