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%2Fmodel%2FWkspGroupElem.java;h=66434d71a81a378b2c8236dfeffbe5442917d049;hb=32337de479444ceb5050207fdd2e7e5e6340c42a;hp=685a8e053c27cb81f405e8ec5ec8b0746e5edc52;hpb=d4c3cf9cebb405ae97e8b5d0c793bf695bfa88ac;p=gpl%2Fargeo-slc.git diff --git a/plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/model/WkspGroupElem.java b/plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/model/WkspGroupElem.java index 685a8e053..66434d71a 100644 --- a/plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/model/WkspGroupElem.java +++ b/plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/model/WkspGroupElem.java @@ -1,92 +1,53 @@ package org.argeo.slc.client.ui.dist.model; -import java.security.AccessControlException; -import java.util.ArrayList; -import java.util.List; - -import javax.jcr.Repository; import javax.jcr.RepositoryException; import javax.jcr.Session; +import org.argeo.ArgeoException; import org.argeo.jcr.JcrUtils; -import org.argeo.slc.SlcException; /** * Abstract set of similar workspaces, that is a bunch of workspaces with same * prefix. */ public class WkspGroupElem extends DistParentElem { - private RepoElem repoElem; - private String name; - public WkspGroupElem(RepoElem repoElem, String prefix) { - super(repoElem.inHome(), repoElem.isReadOnly()); - this.repoElem = repoElem; - this.name = prefix; - } + private Session defaultSession; - public Object[] getChildren() { - Session session = null; + public WkspGroupElem(RepoElem repoElem, String prefix) { + super(prefix, repoElem.inHome(), repoElem.isReadOnly()); + setParent(repoElem); + // Directly adds children upon creation try { - Repository repository = repoElem.getRepository(); - session = repository.login(repoElem.getCredentials()); - - String[] workspaceNames = session.getWorkspace() + defaultSession = repoElem.repositoryLogin(null); + String[] wkpNames = defaultSession.getWorkspace() .getAccessibleWorkspaceNames(); - List distributionElems = new ArrayList(); - buildWksp: for (String workspaceName : workspaceNames) { - - // Filter non-public workspaces for user anonymous. - if (repoElem.getRepoNode() == null) { - Session tmpSession = null; - try { - tmpSession = repository.login(workspaceName); - Boolean res = true; - try { - tmpSession.checkPermission("/", "read"); - } catch (AccessControlException e) { - res = false; - } - if (!res) - continue buildWksp; - } catch (RepositoryException e) { - throw new SlcException( - "Cannot list workspaces for anonymous user", e); - } finally { - JcrUtils.logoutQuietly(tmpSession); - } - } - - // filter technical workspaces - if (workspaceName.startsWith(name) - && workspaceName.substring(0, - workspaceName.lastIndexOf(VERSION_SEP)).equals( - name)) { - distributionElems.add(new WorkspaceElem(repoElem, - workspaceName)); - } + for (String wkpName : wkpNames) { + if (prefix.equals(getPrefix(wkpName)) + // if (wkpName.startsWith(prefix) + && repoElem.isWorkspaceVisible(wkpName)) + addChild(new WorkspaceElem(WkspGroupElem.this, repoElem, + wkpName)); } - return distributionElems.toArray(); } catch (RepositoryException e) { - throw new SlcException("Cannot list workspaces for prefix " + name, - e); - } finally { - JcrUtils.logoutQuietly(session); + throw new ArgeoException("Cannot retrieve workspace names", e); } } - public String getLabel() { - return name; - } - - public String toString() { - return getLabel(); + // FIXME - we rely on a "hard coded" convention : Workspace name must have + // this format: name-major.minor + // We might expose this method as static public, to be used among others by + // the RepoElem parent objects when building its children + private String getPrefix(String workspaceName) { + if (workspaceName.lastIndexOf(VERSION_SEP) > 0) + return workspaceName.substring(0, + workspaceName.lastIndexOf(VERSION_SEP)); + else + return workspaceName; } public void dispose() { - } - - public RepoElem getRepoElem() { - return repoElem; + JcrUtils.logoutQuietly(defaultSession); + super.dispose(); } } \ No newline at end of file