[Lada-commits] [PATCH 3 of 7] Moved and updated the query service
Wald Commits
scm-commit at wald.intevation.org
Wed Jan 27 15:57:38 CET 2016
# HG changeset patch
# User Raimund Renkert <raimund.renkert at intevation.de>
# Date 1453902764 -3600
# Node ID 35bbaf423128908fbcf35f6bcaa0d24034cefad9
# Parent cafeadbeed5b61ed07b647c525be6bd7dde08d82
Moved and updated the query service.
diff -r cafeadbeed5b -r 35bbaf423128 src/main/java/de/intevation/lada/rest/QueryService.java
--- a/src/main/java/de/intevation/lada/rest/QueryService.java Wed Jan 27 14:51:10 2016 +0100
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,82 +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;
-
-import javax.enterprise.context.RequestScoped;
-import javax.ws.rs.GET;
-import javax.ws.rs.Path;
-import javax.ws.rs.Produces;
-
-import de.intevation.lada.query.QueryTools;
-import de.intevation.lada.util.rest.Response;
-
-
-/**
- * REST-Service for preconfigured queries.
- * <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": [string],
- * "name": [string],
- * "description": [string],
- * "sql": [string],
- * "filters": [array],
- * "results": [array]
- * }],
- * "errors": [object],
- * "warnings": [object],
- * "readonly": [boolean],
- * "totalCount": [number]
- * }
- * </code>
- * </pre>
- *
- * @author <a href="mailto:rrenkert at intevation.de">Raimund Renkert</a>
- */
- at Path("rest/query")
- at RequestScoped
-public class QueryService {
-
- /**
- * Request all configured probe queries.
- */
- @GET
- @Path("/probe")
- @Produces("application/json")
- public Response getProbe() {
- return new Response(true, 200, QueryTools.getProbeConfig());
- }
-
- /**
- * Request all configured messprogramm queries.
- */
- @GET
- @Path("/messprogramm")
- @Produces("application/json")
- public Response getMessprogramm() {
- return new Response(true, 200, QueryTools.getMessprogrammConfig());
- }
-
- /**
- * Request all configured stammdaten queries.
- */
- @GET
- @Path("/stammdaten")
- @Produces("application/json")
- public Response getStammdaten() {
- return new Response(true, 200, QueryTools.getStammdatenConfig());
- }
-}
diff -r cafeadbeed5b -r 35bbaf423128 src/main/java/de/intevation/lada/rest/stamm/QueryService.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/main/java/de/intevation/lada/rest/stamm/QueryService.java Wed Jan 27 14:52:44 2016 +0100
@@ -0,0 +1,110 @@
+/* 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.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+
+import de.intevation.lada.model.stamm.Query;
+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 preconfigured queries.
+ * <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": [string],
+ * "name": [string],
+ * "description": [string],
+ * "sql": [string],
+ * "filters": [array],
+ * "results": [array]
+ * }],
+ * "errors": [object],
+ * "warnings": [object],
+ * "readonly": [boolean],
+ * "totalCount": [number]
+ * }
+ * </code>
+ * </pre>
+ *
+ * @author <a href="mailto:rrenkert at intevation.de">Raimund Renkert</a>
+ */
+ at Path("rest/query")
+ at RequestScoped
+public class QueryService {
+
+ @Inject
+ @RepositoryConfig(type=RepositoryType.RO)
+ private Repository repository;
+
+ /**
+ * Request all configured probe queries.
+ */
+ @GET
+ @Path("/probe")
+ @Produces("application/json")
+ public Response getProbe() {
+ QueryBuilder<Query> builder = new QueryBuilder<Query>(
+ repository.entityManager("stamm"),
+ Query.class
+ );
+ builder.and("type", "probe");
+ return repository.filter(builder.getQuery(), "stamm");
+ //return new Response(true, 200, QueryTools.getProbeConfig());
+ }
+
+ /**
+ * Request all configured messprogramm queries.
+ */
+ @GET
+ @Path("/messprogramm")
+ @Produces("application/json")
+ public Response getMessprogramm() {
+ QueryBuilder<Query> builder = new QueryBuilder<Query>(
+ repository.entityManager("stamm"),
+ Query.class
+ );
+ builder.and("type", "messprogramm");
+ return repository.filter(builder.getQuery(), "stamm");
+ }
+
+ /**
+ * Request all configured stammdaten queries.
+ */
+ @GET
+ @Path("/stammdaten")
+ @Produces("application/json")
+ public Response getStammdaten() {
+ QueryBuilder<Query> builder = new QueryBuilder<Query>(
+ repository.entityManager("stamm"),
+ Query.class
+ );
+ builder.or("type", "ort");
+ builder.or("type", "probenehmer");
+ builder.or("type", "datensatzerzeuger");
+ builder.or("type", "messprogrammkategorie");
+ return repository.filter(builder.getQuery(), "stamm");
+ }
+}
More information about the Lada-commits
mailing list