renamed base class for all vamsas document objects (now org.vamsas.client.Vobject)
[vamsas.git] / src / org / vamsas / test / simpleclient / ArchiveWriter.java
index a4b2255..1a9bae9 100644 (file)
@@ -7,6 +7,7 @@ import java.io.PrintWriter;
 import java.text.DateFormat;
 import java.util.Date;
 import java.util.Hashtable;
+import java.util.Vector;
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
@@ -17,36 +18,17 @@ import org.vamsas.objects.core.Entry;
 import org.vamsas.objects.core.Provenance;
 import org.vamsas.objects.core.VAMSAS;
 import org.vamsas.objects.core.VamsasDocument;
+import org.vamsas.objects.utils.ProvenanceStuff;
 
 public class ArchiveWriter {
   
   /**
    * Test program for writing archive files.
+   * form is ArchiveWriter new/modified argive command list
    */
   
-  static Log log = LogFactory.getLog("org.vamsas.test.simpleclient.ArchiveWriter");
-  
-  /**
-   * @param action
-   *          text for action entry
-   * @return new Provenance entry for ArchiveWriter created docs.
-   * TODO: Verify and move to SimpleClient class for provenance handling
-   */
-  public static Entry newProvenanceEntry(String user, String action) { 
-    log.debug("Adding ProvenanceEntry("+user+","+action+")");
-    Entry e = new Entry();
-    e.setAction(action);
-    e.setUser(user);
-    e.setDate(new org.exolab.castor.types.Date(new Date()));
-    return e;
-  }
-  
-  public static Provenance newProvenance() {
-    Provenance list = new Provenance();
-    list.addEntry(newProvenanceEntry("ArchiveWriter", "Created new Vamsas Document"));
-    return list;
-  }
-  
+  static Log log = LogFactory.getLog(ArchiveWriter.class);
+    
   private static void mergeVecs(Object[] destvec, Object[] svec1, Object[] svec2) {
     int i;
     for (i=0; i<svec1.length; i++)
@@ -64,7 +46,7 @@ public class ArchiveWriter {
       if (!ht.containsKey(appdatas[i].getUrn())) {
         Hashtable aphash = new Hashtable();
         ht.put(appdatas[i].getUrn(), aphash);
-        aphash.put(appdatas[i], appdatas[i].getAppDataChoice().getDataReference());
+        aphash.put(appdatas[i], appdatas[i].getDataReference());
       } else {
         // ensure urns and references are unique
         
@@ -77,7 +59,7 @@ public class ArchiveWriter {
   /**
    * safely copies an appData from one archive to another.
    * @param darc destination archive
-   * @param dest destination document object
+   * @param dest destination document Vobject
    * @param sarc source archive reader
    * @param entry application data to be copied from source archive
    */
@@ -120,7 +102,7 @@ public class ArchiveWriter {
     /** TODO: LATER: should verify that all ids really are unique in newly merged document. If not then what ?
      *  investigate possibility of having an id translation between appDatas and the core document - 
      *  the mapping is stored when an external application performs a merge, but when the owning 
-     *  Application accesses the object, the vorba_id is updated to the new one when it writes its 
+     *  Application accesses the Vobject, the vorba_id is updated to the new one when it writes its 
      *  references in to its appdata again
      */
     if (source.getApplicationDataCount()>0) {
@@ -136,6 +118,14 @@ public class ArchiveWriter {
     return true; // success    
   }
   
+  private static CommandProcessor cproc;
+  static {
+    cproc.addCommand("new", 0, "no args");
+    cproc.addCommand("add", 1, "Need another vamsas document archive filename as argument.");    
+    cproc.addCommand("repair", 0, "no args");
+    cproc.addCommand("list", 0, "no args");    
+    cproc.addCommand("monitor", 0, "no args");    
+  }
   
   public static void main(String argv[]) {
     /**
@@ -152,7 +142,7 @@ public class ArchiveWriter {
       VamsasArchive varc = new VamsasArchive(newarch, true);
       VamsasDocument docroot;
       docroot = new VamsasDocument();
-      docroot.setProvenance(newProvenance());
+      docroot.setProvenance(ProvenanceStuff.newProvenance("ArchiveWriter", "Created new Vamsas Document"));
       while (++argpos<argv.length) {
         File archive = new File(argv[argpos]);
         InputStream istream;
@@ -171,7 +161,7 @@ public class ArchiveWriter {
               if ((istream = vdoc.getVamsasXmlStream())!=null) {
                 // make a new vamsas document from the vamsas.xml entry
                 VAMSAS root = VAMSAS.unmarshal(new InputStreamReader(istream)); // TODO: verify only one VAMSAS element per vamsas.xml entry.
-                docroot.getProvenance().addEntry(newProvenanceEntry("user", "added vamsas.xml from "+argv[argpos-1]));
+                docroot.getProvenance().addEntry(ProvenanceStuff.newProvenanceEntry("user", "added vamsas.xml from "+argv[argpos-1]));
                 docroot.addVAMSAS(root);
               }
           }