changeset 289:f4701a64e8a3

Added upload function to the ProbenService. Must be implemented.
author Torsten Irländer <torsten.irlaender@intevation.de>
date Tue, 13 Aug 2013 16:26:00 +0200
parents 7cd0f953651d
children c6eeaca07eab
files pom.xml src/main/java/de/intevation/lada/rest/LProbeService.java
diffstat 2 files changed, 59 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/pom.xml	Fri Aug 09 12:07:54 2013 +0200
+++ b/pom.xml	Tue Aug 13 16:26:00 2013 +0200
@@ -147,10 +147,28 @@
             <scope>test</scope>
         </dependency>
         <dependency>
-               <groupId>org.jboss.resteasy</groupId>
-               <artifactId>resteasy-jaxrs</artifactId>
-               <version>2.2.2.GA</version>
-               <scope>test</scope>
+           <groupId>org.jboss.resteasy</groupId>
+           <artifactId>resteasy-jaxrs</artifactId>
+           <version>2.2.2.GA</version>
+           <scope>provided</scope>
+        </dependency>
+        <dependency>
+          <groupId>org.jboss.resteasy</groupId>
+          <artifactId>resteasy-jaxb-provider</artifactId>
+          <version>2.3.1.GA</version>
+          <scope>provided</scope>
+        </dependency>
+        <!-- Multipart support -->
+        <dependency>
+          <groupId>org.jboss.resteasy</groupId>
+          <artifactId>resteasy-multipart-provider</artifactId>
+          <version>2.3.1.GA</version>
+        </dependency>
+        <!-- For better I/O control -->
+        <dependency>
+          <groupId>commons-io</groupId>
+          <artifactId>commons-io</artifactId>
+          <version>2.0.1</version>
         </dependency>
         <dependency>
                <groupId>org.apache.httpcomponents</groupId>
--- a/src/main/java/de/intevation/lada/rest/LProbeService.java	Fri Aug 09 12:07:54 2013 +0200
+++ b/src/main/java/de/intevation/lada/rest/LProbeService.java	Tue Aug 13 16:26:00 2013 +0200
@@ -28,6 +28,8 @@
 import de.intevation.lada.model.LProbe;
 import de.intevation.lada.model.LProbeInfo;
 
+import org.jboss.resteasy.plugins.providers.multipart.MultipartFormDataInput;
+
 /**
 * This class produces a RESTful service to read, write and update
 * LProbe objects.
@@ -220,4 +222,39 @@
             return new Response(false, 699, new ArrayList<LProbeInfo>());
         }
     }
+    /**
+     * Import LProbe object.
+     * See
+     * http://howtodoinjava.com/2013/05/21/jax-rs-resteasy-file-upload-httpclient-example/
+     * for more details on the implementation.
+     *
+     * @param input MulitpartFormDataInput containing the file to upload.
+     * @param header    The HTTP header containing authorization information.
+     * @return Response object.
+     */
+    @POST
+    @Path("/import")
+    @Produces("application/json")
+    @Consumes("multipart/form-data")
+    public Response upload(MultipartFormDataInput input, @Context HttpHeaders header) {
+        try {
+            AuthenticationResponse auth = authentication.authorizedGroups(header);
+            // TODO: Check Authorisation. How should we check the
+            // authorisation while importing? I think we must differ between
+            // updating already existing proben and creating new proben. (ti)
+            // <2013-08-13 16:24> 
+            //if (auth.getNetzbetreiber().contains(probe.getNetzbetreiberId()) &&
+            //    auth.getMst().contains(probe.getMstId())) {
+            //    LProbe p = probe.toLProbe();
+            //    return repository.create(p);
+            //}
+            // TODO: Response must contain a "file" attribute with the name of
+            // the uploaded file.(ti) <2013-08-13 16:23> 
+            return new Response(true, 200, null);
+            //return new Response(false, 698, null);
+        }
+        catch(AuthenticationException ae) {
+            return new Response(false, 699, null);
+        }
+    }
 }
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)