]> git.argeo.org Git - gpl/argeo-slc.git/blobdiff - runtime/org.argeo.slc.repo/src/main/java/org/argeo/slc/repo/RepoUtils.java
remove superfluous logging
[gpl/argeo-slc.git] / runtime / org.argeo.slc.repo / src / main / java / org / argeo / slc / repo / RepoUtils.java
index 5f798c1444cc8af171af7469af7873e101c2ee90..591da8e47a0b92b009c7c5a4134583f52755eb41 100644 (file)
@@ -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.