Mercurial > dive4elements > river
annotate flys-artifacts/src/main/java/de/intevation/flys/artifacts/services/FileUploadService.java @ 4837:9e25c7523485
Fixed calculation of effective width in MINFO SQ relation.
* Get all (including empty datasets) from db.
* Filter empty datasets when processing data of the same date.
* Added debug outputs.
author | Raimund Renkert <rrenkert@intevation.de> |
---|---|
date | Wed, 23 Jan 2013 11:14:41 +0100 |
parents | 442fbb290fa8 |
children | 7c8ce0a95a64 |
rev | line source |
---|---|
2639 | 1 package de.intevation.flys.artifacts.services; |
2 | |
4656
442fbb290fa8
Introduce river mapfile generation (WARNING: Changes in config xml files required!).
Christian Lins <christian.lins@intevation.de>
parents:
3084
diff
changeset
|
3 import de.intevation.artifacts.CallMeta; |
442fbb290fa8
Introduce river mapfile generation (WARNING: Changes in config xml files required!).
Christian Lins <christian.lins@intevation.de>
parents:
3084
diff
changeset
|
4 import de.intevation.artifacts.GlobalContext; |
442fbb290fa8
Introduce river mapfile generation (WARNING: Changes in config xml files required!).
Christian Lins <christian.lins@intevation.de>
parents:
3084
diff
changeset
|
5 import de.intevation.artifacts.common.ArtifactNamespaceContext; |
442fbb290fa8
Introduce river mapfile generation (WARNING: Changes in config xml files required!).
Christian Lins <christian.lins@intevation.de>
parents:
3084
diff
changeset
|
6 import de.intevation.artifacts.common.utils.FileTools; |
442fbb290fa8
Introduce river mapfile generation (WARNING: Changes in config xml files required!).
Christian Lins <christian.lins@intevation.de>
parents:
3084
diff
changeset
|
7 import de.intevation.artifacts.common.utils.XMLUtils; |
442fbb290fa8
Introduce river mapfile generation (WARNING: Changes in config xml files required!).
Christian Lins <christian.lins@intevation.de>
parents:
3084
diff
changeset
|
8 import de.intevation.artifacts.common.utils.XMLUtils.ElementCreator; |
442fbb290fa8
Introduce river mapfile generation (WARNING: Changes in config xml files required!).
Christian Lins <christian.lins@intevation.de>
parents:
3084
diff
changeset
|
9 import de.intevation.flys.utils.FLYSUtils; |
442fbb290fa8
Introduce river mapfile generation (WARNING: Changes in config xml files required!).
Christian Lins <christian.lins@intevation.de>
parents:
3084
diff
changeset
|
10 |
2639 | 11 import java.io.File; |
12 import java.io.FileOutputStream; | |
13 import java.io.IOException; | |
14 | |
4656
442fbb290fa8
Introduce river mapfile generation (WARNING: Changes in config xml files required!).
Christian Lins <christian.lins@intevation.de>
parents:
3084
diff
changeset
|
15 import org.apache.commons.codec.binary.Base64; |
2639 | 16 import org.apache.log4j.Logger; |
17 import org.w3c.dom.Document; | |
18 import org.w3c.dom.Element; | |
19 | |
20 /** | |
21 * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> | |
22 */ | |
23 public class FileUploadService extends FLYSService { | |
24 | |
25 /** The logger used in this service.*/ | |
26 private static Logger logger = Logger.getLogger(FileUploadService.class); | |
27 | |
28 /** XPath that points to the artifact uuid.*/ | |
29 public static final String XPATH_ARTIFACT_UUID = | |
30 "/upload/artifact-uuid/text()"; | |
31 | |
32 /** XPath that points to the base64 encoded data.*/ | |
33 public static final String XPATH_DATA = "/upload/data/text()"; | |
34 | |
35 public FileUploadService() { | |
36 } | |
37 | |
38 | |
39 @Override | |
40 protected Document doProcess( | |
41 Document data, | |
42 GlobalContext context, | |
43 CallMeta callMeta | |
44 ) { | |
45 logger.debug("FileUploadService.process"); | |
46 | |
47 String uuid = extractUuid(data); | |
48 | |
49 byte[] fileData = extractData(data); | |
50 if (fileData != null) { | |
51 try { | |
52 String shapePath = FLYSUtils.getXPathString( | |
4656
442fbb290fa8
Introduce river mapfile generation (WARNING: Changes in config xml files required!).
Christian Lins <christian.lins@intevation.de>
parents:
3084
diff
changeset
|
53 FLYSUtils.XPATH_FLOODMAP_SHAPEFILE_DIR); |
2639 | 54 |
55 File artifactDir = FileTools.getDirectory(shapePath, uuid); | |
56 FileOutputStream fos = | |
2641
2bad13107161
Make file upload cross platform.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2640
diff
changeset
|
57 new FileOutputStream( |
2bad13107161
Make file upload cross platform.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2640
diff
changeset
|
58 new File(artifactDir, "user-rgd.zip")); |
2bad13107161
Make file upload cross platform.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2640
diff
changeset
|
59 try { |
2bad13107161
Make file upload cross platform.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2640
diff
changeset
|
60 fos.write(fileData); |
2bad13107161
Make file upload cross platform.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2640
diff
changeset
|
61 } |
2bad13107161
Make file upload cross platform.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2640
diff
changeset
|
62 finally { |
2bad13107161
Make file upload cross platform.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2640
diff
changeset
|
63 fos.close(); |
2bad13107161
Make file upload cross platform.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2640
diff
changeset
|
64 } |
2639 | 65 } |
66 catch (IOException ioe) { | |
67 logger.warn(ioe, ioe); | |
68 } | |
69 } | |
70 else { | |
2640
b484318ca9c6
Make it compilable again.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2639
diff
changeset
|
71 logger.debug("No data in uploaded xml."); |
2639 | 72 } |
73 | |
74 Document doc = XMLUtils.newDocument(); | |
75 ElementCreator ec = new ElementCreator(doc, null, null); | |
76 Element resp = ec.create("response"); | |
77 doc.appendChild(resp); | |
78 | |
79 return doc; | |
80 } | |
81 | |
82 | |
83 protected String extractUuid(Document data) { | |
84 return XMLUtils.xpathString( | |
85 data, XPATH_ARTIFACT_UUID, ArtifactNamespaceContext.INSTANCE); | |
86 } | |
87 | |
88 | |
89 protected byte[] extractData(Document data) { | |
90 String b64Data = XMLUtils.xpathString( | |
91 data, XPATH_DATA, ArtifactNamespaceContext.INSTANCE); | |
92 | |
3084
d78b7c06e061
Fixed string comparision for identity.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3083
diff
changeset
|
93 if (b64Data != null && b64Data.length() > 0) { |
2639 | 94 byte[] fileData = Base64.decodeBase64(b64Data); |
95 return fileData; | |
96 } | |
97 return null; | |
98 } | |
99 } | |
3083
4bd3d8bbb60c
Added missing vim lines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2646
diff
changeset
|
100 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |