From 523580c4bd6fc2725934d1c08bd3409a186bd0a7 Mon Sep 17 00:00:00 2001 From: jprocter Date: Mon, 8 Jun 2009 12:29:19 +0000 Subject: [PATCH] locate simpleclientsession handle for any session URN git-svn-id: https://svn.lifesci.dundee.ac.uk/svn/repository/trunk@502 be28352e-c001-0410-b1a7-c7978e42abec --- .../client/simpleclient/SimpleClientFactory.java | 35 ++++++++++++++++---- 1 file changed, 29 insertions(+), 6 deletions(-) diff --git a/src/uk/ac/vamsas/client/simpleclient/SimpleClientFactory.java b/src/uk/ac/vamsas/client/simpleclient/SimpleClientFactory.java index 43cc4b6..58e9160 100644 --- a/src/uk/ac/vamsas/client/simpleclient/SimpleClientFactory.java +++ b/src/uk/ac/vamsas/client/simpleclient/SimpleClientFactory.java @@ -147,15 +147,40 @@ public class SimpleClientFactory implements IClientFactory { } + /** + * try to locate the sessionUrn within the simpleclient session arena + * @param sessionUrn + * @return + * @throws InvalidSessionUrnException + */ private File convertSessionUrnToFile(String sessionUrn) throws InvalidSessionUrnException { if (sessionUrn == null) { log.debug("Incorrect URN: can not open session."); - throw new InvalidSessionUrnException(); + throw new InvalidSessionUrnException("SessionUrn was null"); } SessionUrn urn = new SessionUrn(sessionUrn); - return urn.asFile(); + SimpleSessionHandle[] sh = null; + try { + sh = getSessionManager().getSessionFor(urn); + } catch (IOException e) + { + log.warn("Ignored IO Exception when trying to access sessionlist.",e); + } + File sesfile = null; + if (sh!=null) + { + if (sh.length==1) + { + sesfile = new File(sh[0].getPhysLoc()); + sh[0] = null; + } else { + log.error("Raising exception for multiple session files corresponding to single URN (was : "+sessionUrn+")"); + throw new InvalidSessionUrnException("IMPLEMENTATION ERROR: Multiple session files available for URN ("+sessionUrn+")"); + } + } + return sesfile; } @@ -178,7 +203,7 @@ public class SimpleClientFactory implements IClientFactory { // 3. if it is - locate the file and pass to new VamsasSession try { - File sessionDirectory = this.convertSessionUrnToFile(sessionUrn); + File sessionDirectory = convertSessionUrnToFile(sessionUrn); // create session log .debug("found session directory " @@ -246,9 +271,7 @@ public class SimpleClientFactory implements IClientFactory { } else { vamsasSession = new VamsasSession(sessdir, vamsasDocument); } - - this.getSessionManager().addSession( - new SessionHandle(new SessionUrn(vamsasSession).getSessionUrn())); + getSessionManager().addSession(vamsasSession.getSessionUrn()); if (userId == null) { // create a default userHandle // userId = new UserHandle(System.getProperty("user.name", -- 1.7.10.2