From aafef36a03deb8a344c45c5a11f9d5d8b5f3c81a Mon Sep 17 00:00:00 2001 From: jprocter Date: Fri, 14 Sep 2007 13:49:19 +0000 Subject: [PATCH] tidied command line interface (a bit) and implement test for session document import into a new session. git-svn-id: https://svn.lifesci.dundee.ac.uk/svn/repository/trunk@467 be28352e-c001-0410-b1a7-c7978e42abec --- src/uk/ac/vamsas/test/ExampleApplication.java | 55 ++++++++++++++++++++++--- 1 file changed, 50 insertions(+), 5 deletions(-) diff --git a/src/uk/ac/vamsas/test/ExampleApplication.java b/src/uk/ac/vamsas/test/ExampleApplication.java index df95ec8..2fb20a3 100644 --- a/src/uk/ac/vamsas/test/ExampleApplication.java +++ b/src/uk/ac/vamsas/test/ExampleApplication.java @@ -378,14 +378,16 @@ public class ExampleApplication { } public String Usage = "ExampleApplication :/n [-arena ][-session ] [+]\n" - + " is one of :\n\tsave,update,close,watch"; + + " is one of :\n\tsave,new,watch\n"+ + "-arena and -session are not yet supported"; // TODO for release String sess = null; String importFile = null; String outputFile = null; - + boolean newSession=false; + boolean imported=false; private boolean parseArgs(String args[]) { if (args.length == 0) { return false; @@ -393,8 +395,15 @@ public class ExampleApplication { int cpos = 0; boolean parsed = false; while (!parsed && cpos < args.length) { - if (args[cpos].toLowerCase().equals("load") && cpos + 1 < args.length) { + // TODO: note importDocument not yet supported. + //if (args[cpos].toLowerCase().equals("load") && cpos + 1 < args.length) { + // importFile = args[cpos + 1]; + // cpos += 2; + // continue; + //} + if (args[cpos].toLowerCase().equals("new") && cpos + 1 < args.length) { importFile = args[cpos + 1]; + newSession=true; cpos += 2; continue; } @@ -456,14 +465,42 @@ public class ExampleApplication { // get an Iclient with session data app = new ClientHandle("uk.ac.vamsas.test.ExampleApplication", "0.1"); user = new UserHandle("arnolduser", "deathsdoor"); + if (sess!=null && importFile!=null) + { + System.err.println("Import of an existing document into an existing session is not fully supported yet."); + System.exit(3); + } try { if (sess != null) { System.out.println("Connecting to " + sess); vorbaclient = clientfactory.getIClient(app, user, sess); } else { - vorbaclient = clientfactory.getIClient(app, user); + if (newSession) + { + if (importFile==null) + { + System.out.println("Connecting to a new VAMSAS Session."); + vorbaclient = clientfactory.getNewSessionIClient(app, user); + } else { + System.out.println("Connecting to a new VAMSAS Session to share data in existing document:"+importFile); + File vfile = new File(importFile); + vorbaclient = clientfactory.openAsNewSessionIClient(app, user, vfile); + System.out.println("Succesfully imported document into new session."); + imported = true; + importFile=null; + } + } else { + vorbaclient = clientfactory.getIClient(app, user); + } } - } catch (NoDefaultSessionException e) { + } + catch (InvalidSessionDocumentException e) { + System.err.println("Failed to create a session to share "+importFile); + System.err.println("Sorry it didn't work out. This is what went wrong:"); + e.printStackTrace(System.err); + System.exit(3); + } + catch (NoDefaultSessionException e) { System.err .println("There appear to be several sessions to choose from :"); String[] sessions = clientfactory.getCurrentSessions(); @@ -485,6 +522,7 @@ public class ExampleApplication { File vfile = new File(importFile); try { vorbaclient.importDocument(vfile); + imported=true; } catch (Exception e) { System.err.println("Failed to import file " + importFile); System.err.println("Exception received was " + e); @@ -506,6 +544,13 @@ public class ExampleApplication { // get document data try { IClientDocument cdoc = vorbaclient.getClientDocument(); + if (imported) + { + if (cdoc.getVamsasRoots()==null || cdoc.getVamsasRoots()[0].getDataSetCount()<1) + { + System.err.println("Imported an Empty vamsas document. Is this correct ?"); + } + } processVamsasDocument(cdoc); } catch (Exception e) { System.err -- 1.7.10.2