changeset 351:1feba681ffee

Export LAF via POST. The service now takes url encoded form data with multiple probe ids.
author Raimund Renkert <rrenkert@intevation.de>
date Wed, 04 Sep 2013 10:01:22 +0200
parents 7228478999d1
children 2cb9ee38fd1b
files src/main/java/de/intevation/lada/data/exporter/Exporter.java src/main/java/de/intevation/lada/data/exporter/LAFExporter.java src/main/java/de/intevation/lada/rest/LAFExportService.java
diffstat 3 files changed, 26 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- a/src/main/java/de/intevation/lada/data/exporter/Exporter.java	Mon Sep 02 13:13:29 2013 +0200
+++ b/src/main/java/de/intevation/lada/data/exporter/Exporter.java	Wed Sep 04 10:01:22 2013 +0200
@@ -1,14 +1,12 @@
 package de.intevation.lada.data.exporter;
 
-import java.io.File;
 import java.io.InputStream;
 import java.util.List;
-import java.util.Map;
 
 import de.intevation.lada.auth.AuthenticationResponse;
 
 
 public interface Exporter
 {
-    public InputStream export(String probe, AuthenticationResponse auth);
+    public InputStream export(List<String> proben, AuthenticationResponse auth);
 }
--- a/src/main/java/de/intevation/lada/data/exporter/LAFExporter.java	Mon Sep 02 13:13:29 2013 +0200
+++ b/src/main/java/de/intevation/lada/data/exporter/LAFExporter.java	Wed Sep 04 10:01:22 2013 +0200
@@ -25,11 +25,13 @@
 
     @Override
     public InputStream export(
-        String probe,
+        List<String> proben,
         AuthenticationResponse auth
     ) {
         String laf = "";
-        laf += creator.create(probe);
+        for (String probeId: proben) {
+            laf += creator.create(probeId);
+        }
         InputStream in = new ByteArrayInputStream(laf.getBytes());
         try {
             in.close();
--- a/src/main/java/de/intevation/lada/rest/LAFExportService.java	Mon Sep 02 13:13:29 2013 +0200
+++ b/src/main/java/de/intevation/lada/rest/LAFExportService.java	Wed Sep 04 10:01:22 2013 +0200
@@ -1,13 +1,15 @@
 package de.intevation.lada.rest;
 
 import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.List;
 
 import javax.enterprise.context.RequestScoped;
 import javax.inject.Inject;
 import javax.inject.Named;
-import javax.ws.rs.GET;
+import javax.ws.rs.Consumes;
+import javax.ws.rs.POST;
 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;
@@ -51,26 +53,35 @@
      * @param header    The HTTP header containing authorization information.
      * @return Response object.
      */
-    @GET
-    @Path("/laf/{id}")
+    @POST
+    @Path("/laf")
+    @Consumes("application/x-www-form-urlencoded")
     @Produces("text/plain")
     public Response download(
-        @PathParam("id") String probeId,
+        String proben,
         @Context HttpHeaders header
     ) {
         try {
+            String[] raw = proben.split("&");
+            List<String> probeIds = new ArrayList<String>();
+            for (int i = 0; i < raw.length; i++) {
+                String[] probe = raw[i].split("=");
+                probeIds.add(probe[1]);
+            }
             String fileName = "export.laf";
             AuthenticationResponse auth = authentication.authorizedGroups(header);
             if (!authentication.isAuthorizedUser(header)) {
                 ResponseBuilder response = Response.status(Status.FORBIDDEN);
                 return response.build();
             }
-            if (!authentication.hasAccess(header, probeId) &&
-                !authorization.isReadOnly(probeId)) {
-                ResponseBuilder response = Response.status(Status.FORBIDDEN);
-                return response.build();
+            for (int i = 0; i < probeIds.size(); i++) {
+                String probeId = probeIds.get(i);
+                if (!authentication.hasAccess(header, probeId) &&
+                    !authorization.isReadOnly(probeId)) {
+                    probeIds.remove(probeId);
+                }
             }
-            InputStream exported = exporter.export(probeId, auth);
+            InputStream exported = exporter.export(probeIds, auth);
             ResponseBuilder response = Response.ok((Object)exported);
             response.header(
                 "Content-Disposition",
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)