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=1d6a2ecc676aac7dde0491ea5047bebc2ce69e80;hp=7b901af43b8d658f1f44b9bf489a7942bb3a8ecc;hpb=420f8848873b1781e72d6bef0bab3b9d2d680fbe;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 7b901af43..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 @@ -388,7 +388,7 @@ public class RepoUtils implements ArgeoNames, SlcNames { } /** - * 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' . */ @@ -416,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.