# HG changeset patch # User Christian Lins # Date 1361201593 -3600 # Node ID 7c8ce0a95a6462d47d355cdd3d884d6eed40ab24 # Parent 04ccec566689afcb8d75448ead1e9b32df00c3c2 flys/#657: Shapefile upload service returns success or failure to client (i18n tbd) diff -r 04ccec566689 -r 7c8ce0a95a64 flys-artifacts/src/main/java/de/intevation/flys/artifacts/services/FileUploadService.java --- 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 Raimund Renkert */ 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);