X-Git-Url: http://git.argeo.org/?a=blobdiff_plain;f=runtime%2Forg.argeo.slc.repo%2Fsrc%2Fmain%2Fjava%2Forg%2Fargeo%2Fslc%2Frepo%2FRepoUtils.java;h=591da8e47a0b92b009c7c5a4134583f52755eb41;hb=44e6ab563ede856f3e08034d56a55964a661de17;hp=5f798c1444cc8af171af7469af7873e101c2ee90;hpb=1f0e95374536f1e521eb7b29a6704c1a9d79b94c;p=gpl%2Fargeo-slc.git diff --git a/runtime/org.argeo.slc.repo/src/main/java/org/argeo/slc/repo/RepoUtils.java b/runtime/org.argeo.slc.repo/src/main/java/org/argeo/slc/repo/RepoUtils.java index 5f798c144..591da8e47 100644 --- a/runtime/org.argeo.slc.repo/src/main/java/org/argeo/slc/repo/RepoUtils.java +++ b/runtime/org.argeo.slc.repo/src/main/java/org/argeo/slc/repo/RepoUtils.java @@ -263,7 +263,7 @@ public class RepoUtils implements ArgeoNames, SlcNames { // probably not a jar, skipping if (log.isDebugEnabled()) { log.debug("Skipping because of " + e); - // e.printStackTrace(); + e.printStackTrace(); } } finally { IOUtils.closeQuietly(jarInputStream); @@ -385,11 +385,10 @@ public class RepoUtils implements ArgeoNames, SlcNames { throw new SlcException("Cannot connect to repository " + repoNode, e); } - } /** - * Reads credentials from node, using keyring if there is a password. Cann + * Reads credentials from node, using keyring if there is a password. Can * return null if no credentials needed (local repo) at all, but returns * {@link GuestCredentials} if user id is 'anonymous' . */ @@ -417,6 +416,42 @@ public class RepoUtils implements ArgeoNames, SlcNames { } } + /** + * Shortcut to retrieve a session given variable information: Handle the + * case where we only have an URI of the repository, that we want to connect + * as anonymous or the case of a identified connexion to a local or remote + * repository. + * + * Callers must close the session once it has been used + */ + public static Session getCorrespondingSession( + RepositoryFactory repositoryFactory, Keyring keyring, + Node repoNode, String uri, String workspaceName) { + try { + if (repoNode == null && uri == null) + throw new SlcException( + "At least one of repoNode and uri must be defined"); + Repository currRepo = null; + Credentials credentials = null; + // Anonymous URI only workspace + if (repoNode == null) + // Anonymous + currRepo = ArgeoJcrUtils.getRepositoryByUri(repositoryFactory, + uri); + else { + currRepo = RepoUtils.getRepository(repositoryFactory, keyring, + repoNode); + credentials = RepoUtils.getRepositoryCredentials(keyring, + repoNode); + } + return currRepo.login(credentials, workspaceName); + } catch (RepositoryException e) { + throw new SlcException("Cannot connect to workspace " + + workspaceName + " of repository " + repoNode + + " with URI " + uri, e); + } + } + /** * Write group indexes: 'binaries' lists all bundles and their versions, * 'sources' list theire sources, and 'sdk' aggregates both.