X-Git-Url: http://git.argeo.org/?a=blobdiff_plain;f=plugins%2Forg.argeo.slc.client.ui.dist%2Fsrc%2Fmain%2Fjava%2Forg%2Fargeo%2Fslc%2Fclient%2Fui%2Fdist%2Fviews%2FDistributionsView.java;h=03461829141f88f2d3c086489be2409dc7e72a0a;hb=ea38a0fb11dcbbf094046dbf09222d4e8d5b0eac;hp=acb50335028f4f70f81ed5dc8d7a6962045b44b2;hpb=4e018c19b89557ff54b6d78890c8cf4698cbeeba;p=gpl%2Fargeo-slc.git diff --git a/plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/views/DistributionsView.java b/plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/views/DistributionsView.java index acb503350..034618291 100644 --- a/plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/views/DistributionsView.java +++ b/plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/views/DistributionsView.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2007-2012 Mathieu Baudier + * Copyright (C) 2007-2012 Argeo GmbH * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -30,6 +30,8 @@ import javax.jcr.RepositoryException; import javax.jcr.RepositoryFactory; import javax.jcr.Session; import javax.jcr.nodetype.NodeType; +import javax.jcr.query.Query; +import javax.jcr.query.QueryResult; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -184,19 +186,17 @@ public class DistributionsView extends ViewPart implements SlcNames, ArgeoNames Object firstElement = ((IStructuredSelection) viewer.getSelection()) .getFirstElement(); - if (firstElement instanceof TreeParent) { - TreeParent tp = (TreeParent) firstElement; - String wsName = tp.getName(); + if (firstElement instanceof TreeParent + || firstElement instanceof RepoElem) { + String wsName = null; // Build conditions depending on element type (repo or distribution // for the time being) boolean isDistribElem = false; // , isRepoElem = false; - // if (tp instanceof RepositoryElem){ - // isRepoElem = true; - // } else - if (tp instanceof DistributionElem) { + if (firstElement instanceof DistributionElem) { isDistribElem = true; + wsName = ((DistributionElem) firstElement).getName(); } // create workspace @@ -374,10 +374,15 @@ public class DistributionsView extends ViewPart implements SlcNames, ArgeoNames String[] workspaceNames = session.getWorkspace() .getAccessibleWorkspaceNames(); List distributionElems = new ArrayList(); - for (String workspace : workspaceNames) - distributionElems.add(new DistributionElem(this, workspace, - credentials)); - // FIXME remove deleted workspaces + for (String workspaceName : workspaceNames) { + Node workspaceNode = repoNode.hasNode(workspaceName) ? repoNode + .getNode(workspaceName) : repoNode + .addNode(workspaceName); + repoNode.getSession().save(); + distributionElems.add(new DistributionElem(this, + workspaceNode)); + // FIXME remove deleted workspaces + } return distributionElems.toArray(); } catch (RepositoryException e) { throw new SlcException( @@ -406,32 +411,22 @@ public class DistributionsView extends ViewPart implements SlcNames, ArgeoNames connect(); return repository; } + + public Credentials getCredentials() { + return credentials; + } + } /** Abstracts a distribution, that is a workspace */ private static class DistributionElem extends TreeParent { private final RepoElem repoElem; private final Node workspaceNode; - private final String workspaceName; - private final Credentials credentials; - public DistributionElem(RepoElem repoElem, String workspaceName, - Credentials credentials) { - super(workspaceName); + public DistributionElem(RepoElem repoElem, Node workspaceNode) { + super(JcrUtils.getNameQuietly(workspaceNode)); this.repoElem = repoElem; - try { - // TODO move it to repo elem - this.workspaceNode = repoElem.getRepoNode().hasNode( - workspaceName) ? repoElem.getRepoNode().getNode( - workspaceName) : repoElem.getRepoNode().addNode( - workspaceName); - repoElem.getRepoNode().getSession().save(); - } catch (RepositoryException e) { - throw new SlcException("Cannot get or add workspace node " - + workspaceName, e); - } - this.workspaceName = workspaceName; - this.credentials = credentials; + this.workspaceNode = workspaceNode; } public Node getWorkspaceNode() { @@ -439,7 +434,7 @@ public class DistributionsView extends ViewPart implements SlcNames, ArgeoNames } public String getWorkspaceName() { - return workspaceName; + return JcrUtils.getNameQuietly(workspaceNode); } public String getWorkspacePath() { @@ -447,7 +442,7 @@ public class DistributionsView extends ViewPart implements SlcNames, ArgeoNames return workspaceNode.getPath(); } catch (RepositoryException e) { throw new SlcException("Cannot get or add workspace path " - + workspaceName, e); + + getWorkspaceName(), e); } } @@ -456,7 +451,7 @@ public class DistributionsView extends ViewPart implements SlcNames, ArgeoNames return workspaceNode.getParent().getPath(); } catch (RepositoryException e) { throw new SlcException("Cannot get or add workspace path " - + workspaceName, e); + + getWorkspaceName(), e); } } @@ -465,7 +460,7 @@ public class DistributionsView extends ViewPart implements SlcNames, ArgeoNames } public Credentials getCredentials() { - return credentials; + return repoElem.getCredentials(); } } @@ -586,15 +581,13 @@ public class DistributionsView extends ViewPart implements SlcNames, ArgeoNames protected IStatus run(IProgressMonitor eclipseMonitor) { long begin = System.currentTimeMillis(); try { - // Not implemented in Davex Jackrabbit v2.2 - // Query countQuery = sourceSession.getWorkspace() - // .getQueryManager() - // .createQuery("//element(*, nt:file)", Query.XPATH); - // QueryResult result = countQuery.execute(); - // Long expectedCount = result.getNodes().getSize(); - - Long expectedCount = JcrUtils.countFiles(sourceSession - .getRootNode()); + Query countQuery = sourceSession + .getWorkspace() + .getQueryManager() + .createQuery("select file from [nt:file] as file", + Query.JCR_SQL2); + QueryResult result = countQuery.execute(); + Long expectedCount = result.getNodes().getSize(); if (log.isDebugEnabled()) log.debug("Will copy " + expectedCount + " files..."); @@ -649,72 +642,4 @@ public class DistributionsView extends ViewPart implements SlcNames, ArgeoNames } } } - - // - // try { - // nodeSession = nodeRepository.login(); - // NodeIterator repos = JcrUtils.mkdirs( - // nodeSession, - // UserJcrUtils.getUserHome(nodeSession).getPath() - // + RepoConstants.REPOSITORIES_BASE_PATH).getNodes(); - // while (repos.hasNext()) { - // Node repository = repos.nextNode(); - // String label = null; - // if (repository.isNodeType(NodeType.MIX_TITLE)) { - // label = repository.getProperty(Property.JCR_TITLE) - // .getString(); - // } - // - // if (repository.isNodeType(ArgeoTypes.ARGEO_REMOTE_REPOSITORY)) { - // String uri = repository.getProperty(ARGEO_URI).getString(); - // Credentials credentials = null; - // if (repository.hasProperty(ARGEO_USER_ID)) { - // String userId = repository.getProperty(ARGEO_USER_ID) - // .getString(); - // credentials = new SimpleCredentials(userId, - // "".toCharArray()); - // } - // Repository remoteRepository = ArgeoJcrUtils - // .getRepositoryByUri(repositoryFactory, uri); - // if (label == null) - // label = repository.getName(); - // repositories.add(new RepositoryElem(label, - // remoteRepository, credentials)); - // } - // } - // } catch (RepositoryException e) { - // throw new ArgeoException("Cannot read registered repositories", e); - // } - - // Remote - // String uri = null; - // Credentials credentials = null; - // Repository remoteRepository = null; - - // try { - // uri = "http://dev.argeo.org/org.argeo.jcr.webapp/pub/java"; - // credentials = new GuestCredentials(); - // remoteRepository = - // ArgeoJcrUtils.getRepositoryByUri(repositoryFactory, uri); - // repositories.add(new RepositoryElem("anonymous@dev.argeo.org//java", - // remoteRepository, credentials)); - // } catch (Exception e) { - // e.printStackTrace(); - // } - - // uri = "http://localhost:7070/org.argeo.jcr.webapp/pub/java"; - // credentials = new GuestCredentials(); - // remoteRepository = - // ArgeoJcrUtils.getRepositoryByUri(repositoryFactory, uri); - // repositories.add(new RepositoryElem("anonymous@localhost//java", - // remoteRepository, credentials)); - - // uri = "http://localhost:7070/org.argeo.jcr.webapp/remoting/java"; - // credentials = new SimpleCredentials(System.getProperty("user.name"), - // "".toCharArray()); - // remoteRepository = - // ArgeoJcrUtils.getRepositoryByUri(repositoryFactory, uri); - // repositories.add(new RepositoryElem("@localhost//java", - // remoteRepository, credentials)); - } \ No newline at end of file