comparison src/main/java/de/intevation/lada/rest/importer/LafImportService.java @ 612:23ab3247b36e

Added REST services for Im-/Export for laf files.
author Raimund Renkert <raimund.renkert@intevation.de>
date Thu, 16 Apr 2015 15:50:02 +0200
parents
children 8086664d1629
comparison
equal deleted inserted replaced
611:8782e3a00b71 612:23ab3247b36e
1 /* Copyright (C) 2013 by Bundesamt fuer Strahlenschutz
2 * Software engineering by Intevation GmbH
3 *
4 * This file is Free Software under the GNU GPL (v>=3)
5 * and comes with ABSOLUTELY NO WARRANTY! Check out
6 * the documentation coming with IMIS-Labordaten-Application for details.
7 */
8 package de.intevation.lada.rest.importer;
9
10 import java.util.HashMap;
11 import java.util.Map;
12
13 import javax.enterprise.context.RequestScoped;
14 import javax.inject.Inject;
15 import javax.servlet.http.HttpServletRequest;
16 import javax.ws.rs.Consumes;
17 import javax.ws.rs.POST;
18 import javax.ws.rs.Path;
19 import javax.ws.rs.Produces;
20 import javax.ws.rs.core.Context;
21 import javax.ws.rs.core.MediaType;
22
23 import org.apache.log4j.Logger;
24
25 import de.intevation.lada.importer.ImportConfig;
26 import de.intevation.lada.importer.ImportFormat;
27 import de.intevation.lada.importer.Importer;
28 import de.intevation.lada.util.annotation.AuthorizationConfig;
29 import de.intevation.lada.util.auth.Authorization;
30 import de.intevation.lada.util.auth.AuthorizationType;
31 import de.intevation.lada.util.auth.UserInfo;
32 import de.intevation.lada.util.rest.Response;
33
34 /**
35 * This class produces a RESTful service to interact with probe objects.
36 *
37 * @author <a href="mailto:rrenkert@intevation.de">Raimund Renkert</a>
38 */
39 @Path("import")
40 @RequestScoped
41 public class LafImportService {
42
43 /* The logger used in this class.*/
44 @Inject
45 private Logger logger;
46
47 @Inject
48 @ImportConfig(format=ImportFormat.LAF)
49 private Importer importer;
50
51 @Inject
52 @AuthorizationConfig(type=AuthorizationType.OPEN_ID)
53 private Authorization authorization;
54
55 /**
56 * Import a file in the LAF format.
57 *
58 * @param input MulitpartFormDataInput containing the file to upload.
59 * @param header The HTTP header containing authorization information.
60 * @return Response object.
61 */
62 @POST
63 @Path("/laf")
64 @Produces(MediaType.APPLICATION_JSON)
65 @Consumes(MediaType.TEXT_PLAIN)
66 public Response upload(
67 String content,
68 @Context HttpServletRequest request) {
69 UserInfo userInfo = authorization.getInfo(request);
70
71 logger.debug(content);
72 importer.doImport(content, userInfo);
73 Map<String, Object> respData = new HashMap<String,Object>();
74 respData.put("errors", importer.getErrors());
75 respData.put("warnings", importer.getWarnings());
76 int code = 200;
77 Response response = new Response(importer.getErrors().isEmpty(), code, respData);
78 importer.reset();
79 return response;
80 }
81 }
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)