Work around issue with remote Jackrabbit default workspace.
authorMathieu Baudier <mbaudier@argeo.org>
Mon, 12 Sep 2016 07:20:43 +0000 (07:20 +0000)
committerMathieu Baudier <mbaudier@argeo.org>
Mon, 12 Sep 2016 07:20:43 +0000 (07:20 +0000)
git-svn-id: https://svn.argeo.org/slc/trunk@9112 4cfe0d0a-d680-48aa-b62c-e0a02a3f76cc

org.argeo.slc.client.ui.dist/META-INF/spring/osgi.xml
org.argeo.slc.client.ui.dist/src/org/argeo/slc/client/ui/dist/model/RepoElem.java
org.argeo.slc.client.ui.dist/src/org/argeo/slc/client/ui/dist/wizards/RegisterRepoWizard.java

index 590f3c37f2e9b65092ca264c0f287a02e9cbf58e..bacb25cd97ad903752d8bad181bef1bd58fc3e06 100644 (file)
@@ -15,7 +15,7 @@
        <reference id="keyring" interface="org.argeo.util.security.CryptoKeyring" />\r
 \r
        <reference id="nodeRepository" interface="javax.jcr.Repository"\r
-               filter="(argeo.jcr.repository.alias=node)" />\r
+               filter="(argeo.jcr.repository.alias=home)" />\r
 \r
        <reference id="slcRepoManager" interface="org.argeo.slc.repo.SlcRepoManager" />\r
 </beans:beans>
\ No newline at end of file
index 28841c8695aaf51195a6fe881e7af9756ba3dfd6..14446d3f58207310fc3e23274e9f952cc7755c88 100644 (file)
@@ -53,8 +53,7 @@ public class RepoElem extends DistParentElem {
         * initialisation
         * 
         */
-       public RepoElem(RepositoryFactory repoFactory, Keyring keyring,
-                       Node repoNode, String alias) {
+       public RepoElem(RepositoryFactory repoFactory, Keyring keyring, Node repoNode, String alias) {
                super(alias);
                this.label = alias;
                // label = repoNode.isNodeType(NodeType.MIX_TITLE) ? repoNode
@@ -65,8 +64,7 @@ public class RepoElem extends DistParentElem {
                this.keyring = keyring;
                try {
                        // Initialize this repo information
-                       setInHome(RepoConstants.DEFAULT_JAVA_REPOSITORY_ALIAS
-                                       .equals(repoNode.getName()));
+                       setInHome(RepoConstants.DEFAULT_JAVA_REPOSITORY_ALIAS.equals(repoNode.getName()));
                        if (inHome())
                                // Directly log and retrieve children for local repository
                                login();
@@ -86,37 +84,33 @@ public class RepoElem extends DistParentElem {
                if (repository == null)
                        if (repoNode == null)
                                // Anonymous
-                               repository = ArgeoJcrUtils.getRepositoryByUri(
-                                               repositoryFactory, uri);
+                               repository = ArgeoJcrUtils.getRepositoryByUri(repositoryFactory, uri);
                        else {
-                               repository = RepoUtils.getRepository(repositoryFactory,
-                                               keyring, repoNode);
-                               credentials = RepoUtils.getRepositoryCredentials(keyring,
-                                               repoNode);
+                               repository = RepoUtils.getRepository(repositoryFactory, keyring, repoNode);
+                               credentials = RepoUtils.getRepositoryCredentials(keyring, repoNode);
                        }
 
                try {
-                       defaultSession = repository.login(credentials);
+                       // FIXME make it more generic
+                       String defaultWorkspace = "main";
+                       defaultSession = repository.login(credentials, defaultWorkspace);
                        refreshChildren();
                } catch (RepositoryException e) {
-                       throw new SlcException("Cannot login repository " + label
-                                       + " with credential " + credentials, e);
+                       throw new SlcException("Cannot login repository " + label + " with credential " + credentials, e);
                }
        }
 
        protected void refreshChildren() {
                try {
                        // TODO also remove deleted children (only adds for the time being
-                       String[] workspaceNames = defaultSession.getWorkspace()
-                                       .getAccessibleWorkspaceNames();
+                       String[] workspaceNames = defaultSession.getWorkspace().getAccessibleWorkspaceNames();
                        buildWksp: for (String workspaceName : workspaceNames) {
                                if (!isWorkspaceVisible(workspaceName))
                                        continue buildWksp;
 
                                String prefix = getPrefix(workspaceName);
                                if (getChildByName(prefix) == null) {
-                                       WkspGroupElem wkspGpElem = new WkspGroupElem(RepoElem.this,
-                                                       prefix);
+                                       WkspGroupElem wkspGpElem = new WkspGroupElem(RepoElem.this, prefix);
                                        addChild(wkspGpElem);
                                }
                        }
@@ -135,8 +129,7 @@ public class RepoElem extends DistParentElem {
                // Here is the tricks - we rely on a "hard coded" convention
                // Workspace name should be like: name-major.minor
                if (workspaceName.lastIndexOf(VERSION_SEP) > 0)
-                       return workspaceName.substring(0,
-                                       workspaceName.lastIndexOf(VERSION_SEP));
+                       return workspaceName.substring(0, workspaceName.lastIndexOf(VERSION_SEP));
                else
                        return workspaceName;
        }
@@ -158,8 +151,7 @@ public class RepoElem extends DistParentElem {
                                        result = false;
                                }
                        } catch (RepositoryException e) {
-                               throw new SlcException(
-                                               "Cannot list workspaces for anonymous user", e);
+                               throw new SlcException("Cannot list workspaces for anonymous user", e);
                        } finally {
                                JcrUtils.logoutQuietly(tmpSession);
                        }
@@ -180,10 +172,11 @@ public class RepoElem extends DistParentElem {
         */
        protected Session repositoryLogin(String workspaceName) {
                try {
+                       if (workspaceName == null)
+                               workspaceName = "main";// FIXME make it more generic
                        return repository.login(credentials, workspaceName);
                } catch (RepositoryException e) {
-                       throw new SlcException("Cannot login repository " + label
-                                       + " with credential " + credentials, e);
+                       throw new SlcException("Cannot login repository " + label + " with credential " + credentials, e);
                }
        }
 
@@ -206,8 +199,7 @@ public class RepoElem extends DistParentElem {
                        try {
                                return repoNode.getPath();
                        } catch (RepositoryException e) {
-                               throw new SlcException("Cannot get node path for repository "
-                                               + label, e);
+                               throw new SlcException("Cannot get node path for repository " + label, e);
                        }
        }
 
index d5a59d2841288a54ce93feddfb83f68374167059..ead05c4cfd2756fca84f05ff8eb11d8c05533ca4 100644 (file)
@@ -80,8 +80,7 @@ public class RegisterRepoWizard extends Wizard {
        private final static String DEFAULT_USER_NAME = "anonymous";
        private final static boolean DEFAULT_ANONYMOUS = true;
 
-       public RegisterRepoWizard(Keyring keyring,
-                       RepositoryFactory repositoryFactory, Repository nodeRepository) {
+       public RegisterRepoWizard(Keyring keyring, RepositoryFactory repositoryFactory, Repository nodeRepository) {
                super();
                this.keyring = keyring;
                this.repositoryFactory = repositoryFactory;
@@ -107,42 +106,32 @@ public class RegisterRepoWizard extends Wizard {
                Session nodeSession = null;
                try {
                        nodeSession = nodeRepository.login();
-                       String reposPath = UserJcrUtils.getUserHome(nodeSession).getPath()
-                                       + RepoConstants.REPOSITORIES_BASE_PATH;
+                       String reposPath = UserJcrUtils.getUserHome(nodeSession).getPath() + RepoConstants.REPOSITORIES_BASE_PATH;
 
                        Node repos = nodeSession.getNode(reposPath);
                        String repoNodeName = JcrUtils.replaceInvalidChars(name.getText());
                        if (repos.hasNode(repoNodeName))
-                               throw new SlcException(
-                                               "There is already a remote repository named "
-                                                               + repoNodeName);
+                               throw new SlcException("There is already a remote repository named " + repoNodeName);
 
                        // check if the same URI has already been registered
                        NodeIterator ni = repos.getNodes();
                        while (ni.hasNext()) {
                                Node node = ni.nextNode();
-                               if (node.isNodeType(ArgeoTypes.ARGEO_REMOTE_REPOSITORY)
-                                               && node.hasProperty(ArgeoNames.ARGEO_URI)
-                                               && node.getProperty(ArgeoNames.ARGEO_URI).getString()
-                                                               .equals(uri.getText()))
-                                       throw new SlcException(
-                                                       "This URI "
-                                                                       + uri.getText()
-                                                                       + " is already registered, "
-                                                                       + "for the time being, only one instance of a single "
-                                                                       + "repository at a time is implemented.");
+                               if (node.isNodeType(ArgeoTypes.ARGEO_REMOTE_REPOSITORY) && node.hasProperty(ArgeoNames.ARGEO_URI)
+                                               && node.getProperty(ArgeoNames.ARGEO_URI).getString().equals(uri.getText()))
+                                       throw new SlcException("This URI " + uri.getText() + " is already registered, "
+                                                       + "for the time being, only one instance of a single "
+                                                       + "repository at a time is implemented.");
                        }
 
-                       Node repoNode = repos.addNode(repoNodeName,
-                                       ArgeoTypes.ARGEO_REMOTE_REPOSITORY);
+                       Node repoNode = repos.addNode(repoNodeName, ArgeoTypes.ARGEO_REMOTE_REPOSITORY);
                        repoNode.setProperty(ArgeoNames.ARGEO_URI, uri.getText());
                        repoNode.setProperty(ArgeoNames.ARGEO_USER_ID, username.getText());
                        repoNode.addMixin(NodeType.MIX_TITLE);
                        repoNode.setProperty(Property.JCR_TITLE, name.getText());
                        nodeSession.save();
                        if (saveInKeyring.getSelection()) {
-                               String pwdPath = repoNode.getPath() + '/'
-                                               + ArgeoNames.ARGEO_PASSWORD;
+                               String pwdPath = repoNode.getPath() + '/' + ArgeoNames.ARGEO_PASSWORD;
                                keyring.set(pwdPath, password.getText().toCharArray());
                                nodeSession.save();
                        }
@@ -169,16 +158,14 @@ public class RegisterRepoWizard extends Wizard {
                        // main layout
                        Composite composite = new Composite(parent, SWT.NONE);
                        composite.setLayout(new GridLayout(2, false));
-                       composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true,
-                                       false));
+                       composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
 
                        // Create various fields
                        // setMessage("Login to remote repository", IMessageProvider.NONE);
                        name = createLT(composite, "Name", DEFAULT_NAME);
                        uri = createLT(composite, "URI", DEFAULT_URI);
 
-                       final Button anonymousLogin = createLC(composite,
-                                       "Log as anonymous", true);
+                       final Button anonymousLogin = createLC(composite, "Log as anonymous", true);
                        anonymousLogin.addSelectionListener(new SelectionListener() {
                                private static final long serialVersionUID = 4874716406036981039L;
 
@@ -210,8 +197,7 @@ public class RegisterRepoWizard extends Wizard {
                        }
 
                        Button test = createButton(composite, "Test");
-                       GridData gd = new GridData(SWT.CENTER, SWT.CENTER, false, false, 2,
-                                       1);
+                       GridData gd = new GridData(SWT.CENTER, SWT.CENTER, false, false, 2, 1);
                        gd.widthHint = 140;
                        test.setLayoutData(gd);
 
@@ -237,8 +223,7 @@ public class RegisterRepoWizard extends Wizard {
                }
 
                /** Creates label and check. */
-               protected Button createLC(Composite parent, String label,
-                               Boolean initial) {
+               protected Button createLC(Composite parent, String label, Boolean initial) {
                        new Label(parent, SWT.RIGHT).setText(label);
                        Button check = new Button(parent, SWT.CHECK);
                        check.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
@@ -258,8 +243,7 @@ public class RegisterRepoWizard extends Wizard {
                /** Creates label and password field */
                protected Text createLP(Composite parent, String label) {
                        new Label(parent, SWT.NONE).setText(label);
-                       Text text = new Text(parent, SWT.SINGLE | SWT.LEAD | SWT.BORDER
-                                       | SWT.PASSWORD);
+                       Text text = new Text(parent, SWT.SINGLE | SWT.LEAD | SWT.BORDER | SWT.PASSWORD);
                        text.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
                        return text;
                }
@@ -274,29 +258,23 @@ public class RegisterRepoWizard extends Wizard {
                                String checkedUriStr = checkedUri.toString();
                                Hashtable<String, String> params = new Hashtable<String, String>();
                                params.put(ArgeoJcrConstants.JCR_REPOSITORY_URI, checkedUriStr);
-                               Repository repository = ArgeoJcrUtils.getRepositoryByUri(
-                                               repositoryFactory, checkedUriStr);
+                               Repository repository = ArgeoJcrUtils.getRepositoryByUri(repositoryFactory, checkedUriStr);
+                               // FIXME make it more generic
+                               String defaultWorkspace = "main";
                                if (username.getText().trim().equals("")) {// anonymous
-                                       session = repository.login();
+                                       session = repository.login(defaultWorkspace);
                                } else {
-                                       // FIXME use getTextChars() when upgrading to 3.7
-                                       // see
-                                       // https://bugs.eclipse.org/bugs/show_bug.cgi?id=297412
-                                       char[] pwd = password.getText().toCharArray();
-                                       SimpleCredentials sc = new SimpleCredentials(
-                                                       username.getText(), pwd);
-                                       session = repository.login(sc);
+                                       char[] pwd = password.getTextChars();
+                                       SimpleCredentials sc = new SimpleCredentials(username.getText(), pwd);
+                                       session = repository.login(sc, defaultWorkspace);
                                }
                        } else {// alias
-                               Repository repository = ArgeoJcrUtils.getRepositoryByAlias(
-                                               repositoryFactory, uri.getText());
+                               Repository repository = ArgeoJcrUtils.getRepositoryByAlias(repositoryFactory, uri.getText());
                                session = repository.login();
                        }
-                       MessageDialog.openInformation(getShell(), "Success",
-                                       "Connection to '" + uri.getText() + "' successful");
+                       MessageDialog.openInformation(getShell(), "Success", "Connection to '" + uri.getText() + "' successful");
                } catch (Exception e) {
-                       ErrorFeedback
-                                       .show("Connection test failed for " + uri.getText(), e);
+                       ErrorFeedback.show("Connection test failed for " + uri.getText(), e);
                } finally {
                        JcrUtils.logoutQuietly(session);
                }