]> git.aero2k.de Git - tmp/jakarta-migration.git/commitdiff
CSPACE-4814: Imports now report total records imported, number of records imported...
authorAron Roberts <aron@socrates.berkeley.edu>
Mon, 9 Apr 2012 19:11:09 +0000 (12:11 -0700)
committerAron Roberts <aron@socrates.berkeley.edu>
Mon, 9 Apr 2012 19:11:09 +0000 (12:11 -0700)
services/imports/service/src/main/java/org/collectionspace/services/imports/ImportsResource.java
services/imports/service/src/main/java/org/collectionspace/services/imports/nuxeo/ImportCommand.java

index 482e768c41e8e82145fb084ca16cb2c096316c87..8fe6b217f375c339e0c0b6f7cb8965d005d83a3b 100644 (file)
@@ -181,7 +181,7 @@ public class ImportsResource extends AbstractCollectionSpaceResourceImpl {
         try {
             String report = "NORESULTS";
             report = importCommand.run(outputDir, destWorkspaces);
-            result = "<?xml version=\"1.0\"?><import><msg>SUCCESS</msg><report>"+report+"</report></import>";
+            result = "<?xml version=\"1.0\"?><import><msg>SUCCESS</msg>"+report+"</import>";
         } catch (Exception e){
             result =  "<?xml version=\"1.0\"?><import><msg>ERROR</msg><report>"+Tools.errorToString(e, true)+"</report></import>";
         }
@@ -204,7 +204,7 @@ public class ImportsResource extends AbstractCollectionSpaceResourceImpl {
          try {
             String report = "NORESULTS";
             report = importCommand.run(outputDir, destWorkspaces);
-            result = "<?xml version=\"1.0\"?><import><msg>SUCCESS</msg><report>"+report+"</report></import>";
+            result = "<?xml version=\"1.0\"?><import><msg>SUCCESS</msg>"+report+"</import>";
          } catch (Exception e){
             result = "<?xml version=\"1.0\"?><import><msg>ERROR</msg><report>"+Tools.errorToString(e, true)+"</report></import>";
          }
index b68ef11a3fe438447c8e41d440b7cd1a226d9171..255ba79f760854e0230bf8c63905c03c7d9876f0 100644 (file)
@@ -1,7 +1,9 @@
 package org.collectionspace.services.imports.nuxeo;\r
 \r
 import java.io.File;\r
+import java.util.HashMap;\r
 import java.util.Map;\r
+import java.util.TreeSet;\r
 import org.apache.commons.logging.Log;\r
 import org.apache.commons.logging.LogFactory;\r
 import org.collectionspace.services.client.PoxPayloadIn;\r
@@ -46,7 +48,10 @@ public class ImportCommand {
         DocumentModel docModel = null;\r
         DocumentRef keyDocRef, valueDocRef;\r
         String docType;\r
-        StringBuffer dump = new StringBuffer("NO RESULTS");\r
+        StringBuffer dump = new StringBuffer();\r
+        Map<String,Integer> recordsImportedForDocType = new HashMap<String,Integer>();\r
+        Integer numRecordsImportedForDocType = new Integer(0);\r
+        int totalRecordsImported = 0;\r
         try {\r
             System.out.println("importTree reading file: "+file+(file!=null ? " exists? "+file.exists() : " file param is null"));\r
             reader = new LoggedXMLDirectoryReader(file);  //our overload of XMLDirectoryReader.\r
@@ -60,13 +65,6 @@ public class ImportCommand {
             // potential workaround\r
             DocumentTranslationMap dtm = pipe.run();\r
             Map<DocumentRef,DocumentRef> documentRefs = dtm.getDocRefMap();\r
-            if (documentRefs.size() > 0) {\r
-                dump.setLength(0);\r
-                // Assumes that every import request must necessarily\r
-                // be attempting to import at least one record.\r
-            } else {\r
-                throw new Exception("No records were successfully imported");\r
-            }\r
             dump.append("<importedRecords>");\r
             for (Map.Entry entry: documentRefs.entrySet()) {\r
                 keyDocRef = (DocumentRef) entry.getKey();\r
@@ -76,7 +74,7 @@ public class ImportCommand {
                 }\r
                 // System.out.println("value="+entry.getValue());\r
                 // System.out.println("key="+entry.getKey());\r
-                \r
+\r
                 docModel = repoSession.getDocument((DocumentRef) entry.getValue());\r
                 // System.out.println("value doctype="+docModel.getDocumentType().toString());\r
 \r
@@ -85,15 +83,30 @@ public class ImportCommand {
                 docType = docModel.getDocumentType().getName();\r
                 // System.out.println(docType);\r
                 dump.append("<doctype>"+docType+"</doctype>");\r
-                dump.append("<csid>"+keyDocRef.toString()+"</id>");\r
+                dump.append("<csid>"+keyDocRef.toString()+"</csid>");\r
                 dump.append("</importedRecord>");\r
                 // System.out.println(dump.toString());\r
-\r
+                if (recordsImportedForDocType.containsKey(docType)) {\r
+                    numRecordsImportedForDocType = (Integer) recordsImportedForDocType.get(docType);\r
+                    numRecordsImportedForDocType = Integer.valueOf(numRecordsImportedForDocType.intValue() + 1);\r
+                    recordsImportedForDocType.put(docType, numRecordsImportedForDocType);\r
+                } else {\r
+                    recordsImportedForDocType.put(docType, 1);\r
+                }\r
+                totalRecordsImported++;\r
             }\r
             dump.append("</importedRecords>");\r
         } catch (Exception e) {\r
             throw e;\r
         } finally {\r
+            dump.append("<totalRecordsImported>"+totalRecordsImported+"</totalRecordsImported>");\r
+            dump.append("<numRecordsImportedByDocType>");\r
+            TreeSet<String> keys = new TreeSet<String>(recordsImportedForDocType.keySet());\r
+            for (String key : keys) {\r
+                dump.append("<docType>"+key+"</docType>");\r
+                dump.append("<numRecords>"+recordsImportedForDocType.get(key).intValue()+"</numRecords>");\r
+            }\r
+            dump.append("</numRecordsImportedByDocType>");\r
             if (reader != null) {\r
                 dump.append("<report>"+(((LoggedXMLDirectoryReader)reader).report())+"</report>");\r
                 reader.close();\r