From 7cd19d45b73dd3b862cc0c67d18ce976240ac636 Mon Sep 17 00:00:00 2001 From: jprocter Date: Mon, 16 Jan 2006 09:37:30 +0000 Subject: [PATCH] debug as far as test marshalling - a vorbaIdFactory is now required. git-svn-id: https://svn.lifesci.dundee.ac.uk/svn/repository/trunk@134 be28352e-c001-0410-b1a7-c7978e42abec --- .../vamsas/client/simpleclient/VamsasArchive.java | 15 +++--- src/org/vamsas/objects/utils/Seq.java | 1 + .../vamsas/test/simpleclient/VamsasArchive.java | 53 ++++++++++++++++++-- 3 files changed, 55 insertions(+), 14 deletions(-) diff --git a/src/org/vamsas/client/simpleclient/VamsasArchive.java b/src/org/vamsas/client/simpleclient/VamsasArchive.java index fab9ef2..ec42a33 100644 --- a/src/org/vamsas/client/simpleclient/VamsasArchive.java +++ b/src/org/vamsas/client/simpleclient/VamsasArchive.java @@ -155,7 +155,6 @@ public class VamsasArchive { if (!virginArchive) { makeBackup(); return ((original!=null) ? originalBackup : null); - } return null; } @@ -174,7 +173,7 @@ public class VamsasArchive { */ protected boolean isDocumentWritten() { if (newarchive==null) - log.warn("isDocumentWritten called for unopened archive."); + log.warn("isDocumentWritten() called for unopened archive."); if (entries!=null) { if (entries.containsKey(getDocumentJarEntry())) return true; @@ -266,7 +265,7 @@ public class VamsasArchive { * @throws IOException */ public AppDataOutputStream getAppDataStream(String appdataReference) throws IOException { - if (newarchive!=null) + if (newarchive==null) openArchive(); if (addValidEntry(appdataReference)) { return new AppDataOutputStream(newarchive); @@ -276,7 +275,7 @@ public class VamsasArchive { /** * Stops any current write to archive, and reverts to the backup if it exists. - * All existing locks on the original will be released. + * All existing locks on the original will be released. All backup files are removed. */ public boolean cancelArchive() { if (newarchive!=null) { @@ -306,15 +305,11 @@ public class VamsasArchive { return false; } } - // original is untouched - // just delete temp files - - } } else { log.info("cancelArchive called before archive("+original.getAbsolutePath()+") has been opened!"); } - closeAndReset(); + closeAndReset(); // tidy up and release locks. return true; } @@ -420,6 +415,8 @@ public class VamsasArchive { /** * Tidies up and closes archive, removing any backups that were created. * NOTE: It is up to the caller to delete the original archive backup obtained from backupFile() + * TODO: ensure all extant AppDataReference jar entries are transferred to new Jar + * TODO: provide convenient mechanism for generating new unique AppDataReferences and adding them to the document */ public void closeArchive() throws IOException { if (newarchive!=null) { diff --git a/src/org/vamsas/objects/utils/Seq.java b/src/org/vamsas/objects/utils/Seq.java index ca83223..7564f1d 100644 --- a/src/org/vamsas/objects/utils/Seq.java +++ b/src/org/vamsas/objects/utils/Seq.java @@ -87,6 +87,7 @@ public class Seq { if ((start-end)!=Sequence.length()) seq.setEnd(end+Sequence.length()); } + seq.getVorbaId(); return seq; } public static AlignmentSequence newAlignmentSequence(String name, String alSequence, Sequence refseq, int start, int end) { diff --git a/src/org/vamsas/test/simpleclient/VamsasArchive.java b/src/org/vamsas/test/simpleclient/VamsasArchive.java index 1e96cc9..e820c52 100644 --- a/src/org/vamsas/test/simpleclient/VamsasArchive.java +++ b/src/org/vamsas/test/simpleclient/VamsasArchive.java @@ -4,21 +4,28 @@ import java.io.BufferedInputStream; import java.io.File; import java.io.InputStream; import java.io.InputStreamReader; +import java.io.ObjectOutputStream; +import java.io.PrintWriter; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.vamsas.client.SimpleClient; import org.vamsas.client.simpleclient.*; +import org.vamsas.objects.core.AppDataChoice; +import org.vamsas.objects.core.ApplicationData; +import org.vamsas.objects.core.User; import org.vamsas.objects.core.VAMSAS; import org.vamsas.objects.core.VamsasDocument; +import org.vamsas.test.objects.Core; public class VamsasArchive { /** * test the org.vamsas.simpleclient.vamsasArchive class */ static Log log = LogFactory.getLog("org.vamsas.test.simpleclient.vamsasArchive"); - + public static void main(String args[]) { - + try { File av; if (args.length>0) @@ -44,12 +51,48 @@ public class VamsasArchive { log.info(av+" is a New Archive."); else log.info(av+" has been backed up as "+backup); - varchive.cancelArchive(); if (backup!=null) { - log.info("Backup "+backup+" is being deleted."); + log.info("Backup "+backup+" is being written to."); + // open another and... + ApplicationData appdata = new ApplicationData(); + appdata.setName("org.vamsas.test.simpleclient.VamsasArchive"); + appdata.setAppDataChoice(new AppDataChoice()); + appdata.getAppDataChoice().setData(new String("this is some test data.").getBytes()); + User apuser = new User(); + apuser.setFullname("arnold Bugger esq"); + apuser.setOrganization("disOrganised"); + String appdata_ref = "vamsas:org.vamsas.test.simpleclient.VamsasArchive/"+apuser.getOrganization()+"/"+apuser.getFullname(); + org.vamsas.client.simpleclient.VamsasArchive va = new org.vamsas.client.simpleclient.VamsasArchive(backup, true); + VamsasArchiveReader vread = va.getOriginalArchiveReader(); + if (vread.getAppdataStream(appdata_ref)!=null) { + int i=0; + while (vread.getAppdataStream(appdata_ref+"/"+Integer.toString(++i))!=null) + ; + appdata_ref+="/"+Integer.toString(i); + } + log.info("Writing an apdata reference using AppDataStream interface."); + apuser.setAppDataChoice(new AppDataChoice()); + apuser.getAppDataChoice().setDataReference(appdata_ref); + ObjectOutputStream apdos = new ObjectOutputStream(va.getAppDataStream(appdata_ref)); + apdos.writeObject(appdata_ref); + apdos.writeObject(apuser); // some random content + apdos.close(); // this should *not* close the archive! + log.info("Preparing to write new document."); + doc.addApplicationData(appdata); + doc.addVAMSAS(Core.getDemoVamsas()); + PrintWriter vxml = varchive.getDocumentOutputStream(); + doc.marshal(vxml); + // TODO: verify that the vxml stream close method overridden ? + va.closeArchive(); + log.info("Dump of new vamsas document :"); + va = new org.vamsas.client.simpleclient.VamsasArchive(backup, true); // TODO - refactor Reader class to have deserializing helpers + ArchiveReports.reportDocument(va.getVamsasDocument(), va.getOriginalArchiveReader(), true); backup.delete(); // tidy up } - } catch (Exception e) { + log.info("Cancelling write to original archive "+av); + varchive.cancelArchive(); + + } catch (Exception e) { e.printStackTrace(System.err); } } -- 1.7.10.2