changeset 5009:7c8ce0a95a64

flys/#657: Shapefile upload service returns success or failure to client (i18n tbd)
author Christian Lins <christian.lins@intevation.de>
date Mon, 18 Feb 2013 16:33:13 +0100
parents 04ccec566689
children 255898799ed9 a9243df307b1
files flys-artifacts/src/main/java/de/intevation/flys/artifacts/services/FileUploadService.java
diffstat 1 files changed, 23 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/services/FileUploadService.java	Mon Feb 18 16:29:37 2013 +0100
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/services/FileUploadService.java	Mon Feb 18 16:33:13 2013 +0100
@@ -18,6 +18,7 @@
 import org.w3c.dom.Element;
 
 /**
+ * Service that receives XML-packed Shapefile bundles from the client.
  * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a>
  */
 public class FileUploadService extends FLYSService {
@@ -35,7 +36,6 @@
     public FileUploadService() {
     }
 
-
     @Override
     protected Document doProcess(
         Document data,
@@ -44,6 +44,13 @@
     ) {
         logger.debug("FileUploadService.process");
 
+        Document doc = XMLUtils.newDocument();
+        ElementCreator ec = new ElementCreator(doc, null, null);
+        Element resp   = ec.create("response");
+        Element status = ec.create("status");
+        resp.appendChild(status);
+        doc.appendChild(resp);
+
         String uuid = extractUuid(data);
 
         byte[] fileData = extractData(data);
@@ -58,6 +65,9 @@
                     new File(artifactDir, "user-rgd.zip"));
                 try {
                     fos.write(fileData);
+
+                    // Write operation successful
+                    status.setTextContent("Upload erfolgreich!"); // TODO: i18n
                 }
                 finally {
                     fos.close();
@@ -65,27 +75,32 @@
             }
             catch (IOException ioe) {
                 logger.warn(ioe, ioe);
+                status.setTextContent("Upload fehlgeschlagen!");
             }
         }
         else {
             logger.debug("No data in uploaded xml.");
+            status.setTextContent("Upload fehlgeschlagen!");
         }
 
-        Document doc = XMLUtils.newDocument();
-        ElementCreator ec = new ElementCreator(doc, null, null);
-        Element resp = ec.create("response");
-        doc.appendChild(resp);
-
         return doc;
     }
 
-
+    /**
+     * Extracts the UUID from the XML document.
+     * @param data
+     * @return
+     */
     protected String extractUuid(Document data) {
         return XMLUtils.xpathString(
             data, XPATH_ARTIFACT_UUID, ArtifactNamespaceContext.INSTANCE);
     }
 
-
+    /**
+     * Extracts the base64 encoded ZIP file from the XML document.
+     * @param data
+     * @return
+     */
     protected byte[] extractData(Document data) {
         String b64Data = XMLUtils.xpathString(
             data, XPATH_DATA, ArtifactNamespaceContext.INSTANCE);

http://dive4elements.wald.intevation.org