# HG changeset patch # User Torsten Irländer # Date 1376403960 -7200 # Node ID f4701a64e8a332ad6f595483b4ea6df224c86c3c # Parent 7cd0f953651dbb9f288b684db6c83c4ab35d9d51 Added upload function to the ProbenService. Must be implemented. diff -r 7cd0f953651d -r f4701a64e8a3 pom.xml --- 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 @@ test - org.jboss.resteasy - resteasy-jaxrs - 2.2.2.GA - test + org.jboss.resteasy + resteasy-jaxrs + 2.2.2.GA + provided + + + org.jboss.resteasy + resteasy-jaxb-provider + 2.3.1.GA + provided + + + + org.jboss.resteasy + resteasy-multipart-provider + 2.3.1.GA + + + + commons-io + commons-io + 2.0.1 org.apache.httpcomponents diff -r 7cd0f953651d -r f4701a64e8a3 src/main/java/de/intevation/lada/rest/LProbeService.java --- 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()); } } + /** + * 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); + } + } }