* 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);
}