]> git.aero2k.de Git - tmp/jakarta-migration.git/commitdiff
CSPACE-3560 getting temp directory on mac to be readable by sax InputSource, now...
authorLaramie Crocker <laramie@berkeley.edu>
Thu, 14 Apr 2011 06:51:31 +0000 (06:51 +0000)
committerLaramie Crocker <laramie@berkeley.edu>
Thu, 14 Apr 2011 06:51:31 +0000 (06:51 +0000)
services/build.xml
services/imports/build.xml
services/imports/service/src/main/java/org/collectionspace/services/imports/ImportsResource.java
services/imports/service/src/test/resources/requests/collectionobject-request.xml

index b1176efc16cde68fcda43cb2daa379ed9a035b88..3c04a329ef4f3c2d97067da91ced0109b5797690 100644 (file)
         <ant antfile="note/build.xml" target="deploy" inheritAll="false"/>\r
         <ant antfile="collectionobject/build.xml" target="deploy" inheritAll="false"/>\r
         <ant antfile="intake/build.xml" target="deploy" inheritAll="false"/>\r
+        <ant antfile="imports/build.xml" target="deploy" inheritAll="false"/>\r
         <ant antfile="loanin/build.xml" target="deploy" inheritAll="false"/>\r
         <ant antfile="loanout/build.xml" target="deploy" inheritAll="false"/>\r
         <ant antfile="objectexit/build.xml" target="deploy" inheritAll="false"/>\r
index 59ec3f0ee8cbd15974d0be7a7f1aabceaa0c7f82..315cd675fd02b873e9c48ee28d40c2fd702e8acf 100755 (executable)
     <target name="deploy" depends="install"
     description="deploy imports service">
         <ant antfile="3rdparty/build.xml" target="deploy" inheritall="false"/>
-        <copy todir="${jboss.server.cspace}/cspace/config/resources/templates">
+        <copy todir="${jboss.server.cspace}/cspace/config/services/resources/templates">
             <fileset dir="${basedir}/service/src/main/resources/templates"/>
         </copy>
     </target>
index 15e393261135c7d7ce0cec7dfcf0d78056a85dff..f339f1b13acc4cd6ae4ec03fc1ea18597bc759c1 100755 (executable)
@@ -23,6 +23,8 @@
  */
 package org.collectionspace.services.imports;
 
+import org.collectionspace.services.client.PoxPayloadIn;
+import org.collectionspace.services.client.PoxPayloadOut;
 import org.collectionspace.services.common.FileUtils;
 import org.collectionspace.services.common.ResourceBase;
 import org.collectionspace.services.common.ServiceMain;
@@ -33,6 +35,7 @@ import org.collectionspace.services.common.api.ZipTools;
 
 // The modified Nuxeo ImportCommand from nuxeo's shell:
 import org.collectionspace.services.common.config.TenantBindingConfigReaderImpl;
+import org.collectionspace.services.common.context.ServiceContext;
 import org.collectionspace.services.imports.nuxeo.ImportCommand;
 import org.jboss.resteasy.plugins.providers.multipart.InputPart;
 import org.jboss.resteasy.plugins.providers.multipart.MultipartFormDataInput;
@@ -46,7 +49,10 @@ import javax.ws.rs.Path;
 import javax.ws.rs.Produces;
 import javax.ws.rs.QueryParam;
 import javax.ws.rs.core.Context;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.UriInfo;
 import java.io.File;
+import java.io.FileInputStream;
 import java.io.FileNotFoundException;
 import java.io.InputStream;
 import java.util.List;
@@ -109,6 +115,14 @@ public class ImportsResource extends ResourceBase {
         return _templateDir;
     }
 
+    @POST
+    public Response create(@Context UriInfo ui, String xmlPayload) {
+        try {
+               return this.create(xmlPayload);
+        } catch (Exception e) {
+            throw bigReThrow(e, ServiceMessages.CREATE_FAILED);
+        }
+    }
     /** you can test this with something like:
      * curl -X POST http://localhost:8180/cspace-services/imports -i  -u "Admin@collectionspace.org:Administrator" -H "Content-Type: application/xml" -T in.xml
      * -T /src/trunk/services/imports/service/src/main/resources/templates/authority-request.xml
@@ -120,8 +134,10 @@ public class ImportsResource extends ResourceBase {
         String result;
         javax.ws.rs.core.Response.ResponseBuilder rb;
         try {
-            InputSource inputSource = payloadToInputSource(xmlPayload);
-            result = createFromInputSource(inputSource);
+            //InputSource inputSource = payloadToInputSource(xmlPayload);
+            //result = createFromInputSource(inputSource);
+            String inputFilename = payloadToFilename(xmlPayload);
+            result = createFromFilename(inputFilename);
             rb = javax.ws.rs.core.Response.ok();
            } catch (Exception e) {
             result = Tools.errorToString(e, true);
@@ -134,16 +150,39 @@ public class ImportsResource extends ResourceBase {
     public static String createFromInputSource(InputSource inputSource) throws Exception {
         // We must expand the request and wrap it with all kinds of Nuxeo baggage, which expandXmlPayloadToDir knows how to do.
         String outputDir = FileTools.createTmpDir("imports-").getCanonicalPath();
-        expandXmlPayloadToDir(inputSource, getTemplateDir(), outputDir);
+        File outpd = new File(outputDir);
+        outpd.mkdirs();
+        expandXmlPayloadToDir(inputSource, getTemplateDir(), outpd.getCanonicalPath());
 
         // Next, call the nuxeo import service, pointing it to our local directory that has the expanded request.
         ImportCommand importCommand = new ImportCommand();
         String destWorkspaces = "/default-domain/workspaces";
-        String report = importCommand.run(outputDir, destWorkspaces);
+        String report = "NORESULTS";
+        try {
+            report = importCommand.run(outputDir, destWorkspaces);
+        } catch (Exception e){
+            report =  "<?xml ?><import><msg>ERROR</msg><report></report>"+Tools.errorToString(e, true)+"</import>";
+        }
         String result = "<?xml ?><import><msg>SUCCESS</msg><report></report>"+report+"</import>";
         return result;
     }
 
+    public static String createFromFilename(String filename) throws Exception {
+         // We must expand the request and wrap it with all kinds of Nuxeo baggage, which expandXmlPayloadToDir knows how to do.
+         String outputDir = FileTools.createTmpDir("imports-").getCanonicalPath();
+         File outpd = new File(outputDir);
+         outpd.mkdirs();
+         expandXmlPayloadToDir(filename, getTemplateDir(), outpd.getCanonicalPath());
+
+         // Next, call the nuxeo import service, pointing it to our local directory that has the expanded request.
+         ImportCommand importCommand = new ImportCommand();
+         String destWorkspaces = "/default-domain/workspaces";
+         String report = importCommand.run(outputDir, destWorkspaces);
+         String result = "<?xml ?><import><msg>SUCCESS</msg><report></report>"+report+"</import>";
+         return result;
+     }
+
+
     /**  @param xmlPayload   A request file has a specific format, you can look at:
      *      trunk/services/imports/service/src/test/resources/requests/authority-request.xml
      */
@@ -159,6 +198,26 @@ public class ImportsResource extends ResourceBase {
         return inputSource;
     }
 
+    public static String payloadToFilename(String xmlPayload) throws Exception {
+        String requestDir = FileTools.createTmpDir("imports-request-").getCanonicalPath();
+        File requestFile = FileTools.saveFile(requestDir, "request.xml", xmlPayload, true);
+        if (requestFile == null){
+            throw new FileNotFoundException("Could not create file in requestDir: "+requestDir);
+        }
+        String requestFilename = requestFile.getCanonicalPath();
+        System.out.println("############## REQUEST_FILENAME: "+requestFilename);
+        return requestFilename;
+    }
+
+    public static void expandXmlPayloadToDir(String inputFilename, String templateDir, String outputDir) throws Exception {
+     System.out.println("############## TEMPLATE_DIR: "+templateDir);
+        System.out.println("############## OUTPUT_DIR:"+outputDir);
+        File file = new File(inputFilename);
+        FileInputStream is = new FileInputStream(file);
+        InputSource inputSource = new InputSource(is);
+        TemplateExpander.expandInputSource(templateDir, outputDir, inputSource, "/imports/import");
+    }
+
     /** This method may be called statically from outside this class; there is a test call in
      *   org.collectionspace.services.test.ImportsServiceTest
      *
@@ -172,6 +231,7 @@ public class ImportsResource extends ResourceBase {
         System.out.println("############## TEMPLATE_DIR: "+templateDir);
         System.out.println("############## OUTPUT_DIR:"+outputDir);
         TemplateExpander.expandInputSource(templateDir, outputDir, inputSource, "/imports/import");
+        //TemplateExpander.expandInputSource(templateDir, outputDir, inputFilename, "/imports/import");
     }
 
     /** you can test like this:
index 9e9a62ba1c8db118f53c0f9010d2d70edb8fed9a..9e4f549b7503ac82e13db85b247a3ae79ee9f18a 100755 (executable)
@@ -9,7 +9,7 @@
             <collectionobjects_naturalhistory:nh-date/>\r
          </schema>\r
          <schema xmlns:collectionobjects_common="http://collectionspace.org/collectionobject/" name="collectionobjects_common">\r
-            <collectionobjects_common:assocCulturalContextGroupListNONEXISTENT/>\r
+            <collectionobjects_common:assocCulturalContextGroupList/>\r
             <collectionobjects_common:assocCulturalContextGroupList/>\r
             <collectionobjects_common:assocObjectGroupList/>\r
             <collectionobjects_common:assocEventNameType></collectionobjects_common:assocEventNameType>\r