*
* @author jimp
*
- * (it's VORBA, not CORBA!)
+ * @note (it's VORBA, not CORBA!)
+ * @history added additional sessionName argument for openAsNewSessionIClient method (v0.2)
*/
public interface IClientFactory {
/**
* Create a new session and import an existing vamsas document into it.
- *
+ * Session name will inherit from vamsasDocument path.
* @param applicationHandle
* @param vamsasDocument
* @return
File vamsasDocument) throws InvalidSessionDocumentException;
/**
+ * Create a new session and import an existing vamsas document into it.
+ *
+ * @param applicationHandle
+ * @param vamsasDocument
+ * @param sessionName - preferred session name (may be null)
+ * @return
+ */
+ IClient openAsNewSessionIClient(ClientHandle applicationHandle,
+ File vamsasDocument, String sessionName) throws InvalidSessionDocumentException;
+
+ /**
* Create a new session as a particular user and import an existing vamsas
* document into it.
*
*/
IClient openAsNewSessionIClient(ClientHandle applicationHandle,
UserHandle userId, File vamsasDocument)
- throws InvalidSessionDocumentException;
-
+ throws InvalidSessionDocumentException;
+ /**
+ * Create a new session as a particular user and import an existing vamsas
+ * document into it.
+ *
+ * @param applicationHandle
+ * @param userId
+ * @param vamsasDocument
+ * @param sessionName - preferred session name (may be null)
+ * @return
+ */
+ IClient openAsNewSessionIClient(ClientHandle applicationHandle,
+ UserHandle userId, File vamsasDocument, String sessionName)
+ throws InvalidSessionDocumentException;
/**
* enumerate the active sessions this IClientFactory instance knows about. Can
* be used by caller to pick a session on catching a
* applicationHandle, vamsasSession);
*/
client = this.initClient(sessionDirectory, userId, applicationHandle,
- null);
+ null,null);
} catch (MalformedURLException e) {
log.error("error while creating new IClient: incorrect session urn", e);
client = null;
* @param vamsasDocument
* null or a document to pass to SimpleCLient to write into the
* sessdir
+ * @param preferredName - name to use instead of vamsasDocument path when creating new session URN
* @return the client
* @throws IOException
* if there are problems in session or client creation or if the
* for a malformed sessdir
*/
private IClient initClient(File sessdir, UserHandle userId,
- ClientHandle clientHandle, File vamsasDocument) throws IOException,
+ ClientHandle clientHandle, File vamsasDocument, String preferredName) throws IOException,
InvalidSessionUrnException, InvalidSessionDocumentException {
IClient client = null;
// create session
if (vamsasDocument == null) {
vamsasSession = new VamsasSession(sessdir);
} else {
- vamsasSession = new VamsasSession(sessdir, vamsasDocument);
+ vamsasSession = new VamsasSession(sessdir, vamsasDocument,preferredName);
}
getSessionManager().addSession(vamsasSession.getSessionUrn());
if (userId == null) {
}
// no session available - create a new one
try {
- client = clientInNewSession(userId, clientHandle, null);
+ client = clientInNewSession(userId, clientHandle, null,null);
} catch (Exception e) {
throw new Error(
"IMPLEMENTATION ERROR: unexpected exception when creating a new session to connect to.",
* @param clientHandle
* @param vamsasDocument
* null or a document file to copy into the new session
+ * @param preferredName - name to be used as base for the new session URN
* @return null or a valid IClient instance
*/
private IClient clientInNewSession(UserHandle userId,
- ClientHandle clientHandle, File vamsasDocument)
+ ClientHandle clientHandle, File vamsasDocument, String preferredName)
throws InvalidSessionDocumentException, InvalidSessionUrnException {
IClient client = null;
// try and make a friendly session name
String sesspref = "";
if (vamsasDocument != null) {
- sesspref = vamsasDocument.getName().replaceAll(
- "([^-A-Za-z0-9]|\\.vdj)", "");
+ if (preferredName!=null)
+ {
+ sesspref = preferredName.replaceAll(
+ "([^-A-Za-z0-9]|\\.vdj)", "");
+ } else {
+ sesspref = vamsasDocument.getName().replaceAll(
+ "([^-A-Za-z0-9]|\\.vdj)", "");
+ }
}
sesspref += (new java.util.Date()).toString().replaceAll("[^-A-Za-z0-9]",
"_");
log.debug("Creating new session directory");
if (!(sessdir.delete() && sessdir.mkdir()))
throw new IOException("Could not make session directory " + sessdir);
- client = initClient(sessdir, userId, clientHandle, vamsasDocument);
+ client = initClient(sessdir, userId, clientHandle, vamsasDocument, preferredName);
} catch (IOException e) {
log.error("error while creating new IClient", e);
} catch (InvalidSessionUrnException e) {
public IClient getNewSessionIClient(ClientHandle applicationHandle) {
try {
- return clientInNewSession(null, applicationHandle, null);
+ return clientInNewSession(null, applicationHandle, null,null);
} catch (Exception e) {
log.error("Failed to create new session for app with default user.", e);
}
public IClient getNewSessionIClient(ClientHandle applicationHandle,
UserHandle userId) {
try {
- return clientInNewSession(userId, applicationHandle, null);
+ return clientInNewSession(userId, applicationHandle, null,null);
} catch (Exception e) {
log.error("Failed to create new session for app and user.", e);
}
File vamsasDocument) throws InvalidSessionDocumentException {
checkImportedDocument(vamsasDocument);
try {
- return clientInNewSession(null, applicationHandle, vamsasDocument);
+ return clientInNewSession(null, applicationHandle, vamsasDocument,null);
} catch (InvalidSessionUrnException e) {
throw new InvalidSessionDocumentException("Unexpected exception", e);
}
throws InvalidSessionDocumentException {
checkImportedDocument(vamsasDocument);
try {
- return clientInNewSession(userId, applicationHandle, vamsasDocument);
+ return clientInNewSession(userId, applicationHandle, vamsasDocument,null);
+ } catch (InvalidSessionUrnException e) {
+ throw new InvalidSessionDocumentException("Unexpected exception", e);
+ }
+ }
+
+ public IClient openAsNewSessionIClient(ClientHandle applicationHandle,
+ File vamsasDocument, String sessionName)
+ throws InvalidSessionDocumentException {
+ checkImportedDocument(vamsasDocument);
+ try {
+ return clientInNewSession(null, applicationHandle, vamsasDocument, sessionName);
+ } catch (InvalidSessionUrnException e) {
+ throw new InvalidSessionDocumentException("Unexpected exception", e);
+ }
+ }
+
+ public IClient openAsNewSessionIClient(ClientHandle applicationHandle,
+ UserHandle userId, File vamsasDocument, String sessionName)
+ throws InvalidSessionDocumentException {
+ checkImportedDocument(vamsasDocument);
+ try {
+ return clientInNewSession(userId, applicationHandle, vamsasDocument, sessionName);
} catch (InvalidSessionUrnException e) {
throw new InvalidSessionDocumentException("Unexpected exception", e);
}
\r
import uk.ac.vamsas.client.ClientHandle;\r
import uk.ac.vamsas.client.Events;\r
+import uk.ac.vamsas.client.InvalidSessionUrnException;\r
import uk.ac.vamsas.client.UserHandle;\r
\r
/**\r
* new data into session in this way)\r
*/\r
protected VamsasSession(File sessionDir1, File extVamDoc) throws IOException {\r
+ this(sessionDir1,extVamDoc,null);\r
+ }\r
+ /**\r
+ * sets up the vamsas session files and watchers in sessionDir1\r
+ * \r
+ * @param sessionDir1\r
+ * @param extVamDoc\r
+ * null or an existing archive to initialise the session with\r
+ * @param preferredName - optional string to use to generate a new session URI\r
+ * @throws any\r
+ * IOExceptions from creating session directory and files.\r
+ * @throws error\r
+ * if both extVamDoc and sessionDir1 already exist (cannot import\r
+ * new data into session in this way)\r
+ * MalformedURI if preferredName cannot be used to derive a URI of the form simpleclient::preferredName\r
+ */\r
+ public VamsasSession(File sessionDir1, File extVamDoc, String preferredName) throws IOException {\r
// TODO: refactor to separate extVamDoc path from session URN - enables non-local URLs to be locally bound to sessions.\r
if (sessionDir1 == null)\r
throw new Error("Null directory for VamsasSession.");\r
}\r
}\r
this.sessionDir = sessionDir1;\r
- if (extVamDoc==null) {\r
- sessionHandle = new SimpleSessionHandle(new SessionUrn(sessionDir).getSessionUrn(),sessionDir);\r
- } else {\r
+ // construct session URN\r
+ SessionUrn sessUrn = new SessionUrn(sessionDir);\r
+ if (extVamDoc!=null) {\r
// Construct Session URN from the original vamsas document.\r
- sessionHandle = new SimpleSessionHandle(new SessionUrn(extVamDoc).getSessionUrn(),sessionDir);\r
+ sessUrn = new SessionUrn(extVamDoc);\r
}\r
+ if (preferredName!=null) {\r
+ try {\r
+ sessUrn = new SessionUrn(preferredName);\r
+ } catch (InvalidSessionUrnException e) {\r
+ throw new Error("Malformed URI : preferredName = "+preferredName,e);\r
+ }\r
+ }\r
+ // create the session handle\r
+ sessionHandle = new SimpleSessionHandle(sessUrn.getSessionUrn(),sessionDir);\r
initSessionObjects();\r
if (existingSession) {\r
slog.debug("Initialising additional VamsasSession instance");\r
log.debug("Initialised VamsasSession in " + sessionDir1);\r
}\r
\r
+\r
/**\r
* tests presence of existing sessionfiles files in dir\r
* \r