From 727ec5078b48a2951a20575fc9335fe9b9a6c616 Mon Sep 17 00:00:00 2001 From: Aron Roberts Date: Thu, 15 Mar 2012 19:23:42 -0700 Subject: [PATCH] CSPACE-4866,CSPACE-4818: In Imports service, allow multipart/form-data upload of XML files using 'text/xml' MIME type, as well as 'application/xml', to support upload form functionality of that service. Minor cleanup of error and success messages, and of the HTML upload form. --- .../services/imports/ImportsResource.java | 39 +++++++++++++++---- 1 file changed, 31 insertions(+), 8 deletions(-) diff --git a/services/imports/service/src/main/java/org/collectionspace/services/imports/ImportsResource.java b/services/imports/service/src/main/java/org/collectionspace/services/imports/ImportsResource.java index 5e96b150b..3ca85110d 100644 --- a/services/imports/service/src/main/java/org/collectionspace/services/imports/ImportsResource.java +++ b/services/imports/service/src/main/java/org/collectionspace/services/imports/ImportsResource.java @@ -165,13 +165,14 @@ public class ImportsResource extends ResourceBase { ImportCommand importCommand = new ImportCommand(); // String destWorkspaces = "/default-domain/workspaces"; String destWorkspaces = getWorkspaces(); - String report = "NORESULTS"; + String result = ""; try { + String report = "NORESULTS"; report = importCommand.run(outputDir, destWorkspaces); + result = "SUCCESS"+report+""; } catch (Exception e){ - report = "ERROR"+Tools.errorToString(e, true)+""; + result = "ERROR"+Tools.errorToString(e, true)+""; } - String result = "SUCCESS"+report+""; return result; } @@ -187,8 +188,14 @@ public class ImportsResource extends ResourceBase { ImportCommand importCommand = new ImportCommand(); // String destWorkspaces = "/default-domain/workspaces"; String destWorkspaces = getWorkspaces(); - String report = importCommand.run(outputDir, destWorkspaces); - String result = "SUCCESS"+report+""; + String result = ""; + try { + String report = "NORESULTS"; + report = importCommand.run(outputDir, destWorkspaces); + result = "SUCCESS"+report+""; + } catch (Exception e){ + result = "ERROR"+Tools.errorToString(e, true)+""; + } return result; } @@ -288,7 +295,7 @@ public class ImportsResource extends ResourceBase { for (InputPart part : fileParts){ String mediaType = part.getMediaType().toString(); System.out.println("Media type is:" + mediaType); - if (mediaType.equalsIgnoreCase(MediaType.APPLICATION_XML)){ + if (mediaType.equalsIgnoreCase(MediaType.APPLICATION_XML) || mediaType.equalsIgnoreCase(MediaType.TEXT_XML)){ InputSource inputSource = new InputSource(part.getBody(InputStream.class, null)); String result = createFromInputSource(inputSource); resultBuf.append(result); @@ -323,8 +330,24 @@ public class ImportsResource extends ResourceBase { return response; } - String page = "
" - + "Choose a file to import:
"; + String page = "\n" + + "\n" + + " \n" + + " CollectionSpace Import\n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + "
\n" + + " Choose a file to import:" + + " \n" + + "
\n" + + " \n" + + "
\n" + + " \n" + + "\n"; @GET @Produces("text/html") public String getInputForm(@QueryParam("form") String form) { -- 2.47.3