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%2FWorkspaceElem.java;h=a163974072607d43659a534c250c200e7479c6d2;hb=524221f25edad4b09aac22555450164e587b304a;hp=52acdac7d7e0ba1e85c33c3734baca3673e29c27;hpb=706b98df2c68382d7bd501fa05cb128f329087ee;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/WorkspaceElem.java b/plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/model/WorkspaceElem.java index 52acdac7d..a16397407 100644 --- a/plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/model/WorkspaceElem.java +++ b/plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/model/WorkspaceElem.java @@ -1,11 +1,13 @@ package org.argeo.slc.client.ui.dist.model; +import javax.jcr.Node; import javax.jcr.NodeIterator; import javax.jcr.RepositoryException; import javax.jcr.Session; import javax.jcr.query.Query; import org.argeo.ArgeoException; +import org.argeo.jcr.JcrUtils; import org.argeo.slc.jcr.SlcNames; import org.argeo.slc.jcr.SlcTypes; @@ -13,7 +15,7 @@ import org.argeo.slc.jcr.SlcTypes; public class WorkspaceElem extends DistParentElem { private final RepoElem repoElem; private String workspaceName; - private Session defaultSession; + private Session currSession; public WorkspaceElem(WkspGroupElem parent, RepoElem repoElem, String workspaceName) { @@ -32,22 +34,22 @@ public class WorkspaceElem extends DistParentElem { } public Boolean isConnected() { - if (defaultSession != null && defaultSession.isLive()) + if (currSession != null && currSession.isLive()) return true; else return false; } public void login() { - defaultSession = repoElem.repositoryLogin(getName()); + currSession = repoElem.repositoryLogin(getName()); } public boolean hasChildren() { try { if (isConnected()) - return defaultSession.getRootNode().hasNodes(); + return currSession.getRootNode().hasNodes(); else - return false; + return true; } catch (RepositoryException re) { throw new ArgeoException( "Unexpected error while checking children node existence", @@ -63,24 +65,60 @@ public class WorkspaceElem extends DistParentElem { } else { // initialize current object try { - if (defaultSession == null) - return null; - else { - Query groupQuery = defaultSession - .getWorkspace() - .getQueryManager() - .createQuery( - "select * from [" + SlcTypes.SLC_GROUP_BASE - + "] as group order by group.[" - + SlcNames.SLC_GROUP_BASE_ID + "]", - Query.JCR_SQL2); - NodeIterator groups = groupQuery.execute().getNodes(); - while (groups.hasNext()) { - addChild(new GroupBaseElem(WorkspaceElem.this, groups - .nextNode() - .getProperty(SlcNames.SLC_GROUP_BASE_ID) - .getString())); + // Lazy connect the first time we retrieve children + if (currSession == null) + login(); + + // Retrieve already existing distribution + Query groupQuery = currSession + .getWorkspace() + .getQueryManager() + .createQuery( + "select * from [" + + SlcTypes.SLC_MODULAR_DISTRIBUTION + + "]", Query.JCR_SQL2); + NodeIterator distributions = groupQuery.execute().getNodes(); + distribs: while (distributions.hasNext()) { + Node currDist = distributions.nextNode(); + Node distBase = currDist.getParent().getParent(); + if (!distBase.isNodeType(SlcTypes.SLC_ARTIFACT_BASE)) + continue distribs; + String groupId = distBase + .getProperty(SlcNames.SLC_GROUP_ID).getString(); + String artifactId = distBase.getProperty( + SlcNames.SLC_ARTIFACT_ID).getString(); + + String name; + String type; + if (ModularDistBaseElem.AETHER_BINARIES_TYPE + .equals(artifactId)) { + name = groupId; + type = ModularDistBaseElem.AETHER_BINARIES_TYPE; + } else { + name = artifactId; + type = ModularDistBaseElem.AETHER_DEP_TYPE; } + if (getChildByName(name) == null) + addChild(new ModularDistBaseElem(WorkspaceElem.this, + name, distBase, type)); + } + // Add empty group base that have been marked as relevant + groupQuery = currSession + .getWorkspace() + .getQueryManager() + .createQuery( + "select * from [" + + SlcTypes.SLC_RELEVANT_CATEGORY + "]", + Query.JCR_SQL2); + distributions = groupQuery.execute().getNodes(); + while (distributions.hasNext()) { + Node distBase = distributions.nextNode(); + String groupBaseId = distBase.getProperty( + SlcNames.SLC_GROUP_BASE_ID).getString(); + if (getChildByName(groupBaseId) == null) + addChild(new ModularDistBaseElem(WorkspaceElem.this, + groupBaseId, distBase, + ModularDistBaseElem.AETHER_CATEGORY_BASE)); } return super.getChildren(); } catch (RepositoryException e) { @@ -90,4 +128,10 @@ public class WorkspaceElem extends DistParentElem { } } } + + @Override + public synchronized void dispose() { + JcrUtils.logoutQuietly(currSession); + super.dispose(); + } }