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=0567b31939fd53410ec3481532497d7275e2fc81;hb=abc9e68ee9afc994feb923b40388aca83bdb050f;hp=9cf295c5f78e0839ae1f7aceadcaec1fec75e400;hpb=f66f6731733060ab796d7e2a7c0cdf49962d2c39;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 9cf295c5f..0567b3193 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,26 +1,28 @@ package org.argeo.slc.client.ui.dist.model; -/** Abstracts a workspace that contains a given distribution */ +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; + +/** Abstract a workspace that contains a software distribution */ public class WorkspaceElem extends DistParentElem { private final RepoElem repoElem; private String workspaceName; - private String label; - - // /** - // * Helper to display only version when the workspace name is well - // formatted - // */ - // private static String formatName(String name) { - // if (name != null && name.lastIndexOf(VERSION_SEP) > 0) - // return name.substring(name.lastIndexOf(VERSION_SEP) + 1); - // else - // return name; - // } - - public WorkspaceElem(RepoElem repoElem, String workspaceName) { + private Session currSession; + + public WorkspaceElem(WkspGroupElem parent, RepoElem repoElem, + String workspaceName) { + super(workspaceName, repoElem.inHome(), repoElem.isReadOnly()); this.repoElem = repoElem; this.workspaceName = workspaceName; - this.label = workspaceName; // formatName(workspaceName); + setParent(parent); } public String getWorkspaceName() { @@ -31,20 +33,110 @@ public class WorkspaceElem extends DistParentElem { return repoElem; } - public boolean isReadOnly() { - return repoElem.isReadOnly(); + public Boolean isConnected() { + if (currSession != null && currSession.isLive()) + return true; + else + return false; + } + + public void login() { + currSession = repoElem.repositoryLogin(getName()); + } + + /** Utility to create a new Session with correct credential in this context */ + public Session getNewSession() { + return repoElem.repositoryLogin(getName()); } public boolean hasChildren() { - return false; + try { + if (isConnected()) + return currSession.getRootNode().hasNodes(); + else + return true; + } catch (RepositoryException re) { + throw new ArgeoException( + "Unexpected error while checking children node existence", + re); + } } - public Object[] getChildren() { - return null; + /** Override normal behaviour to initialize display of the workspace */ + @Override + public synchronized Object[] getChildren() { + if (isLoaded()) { + return super.getChildren(); + } else { + // initialize current object + try { + // 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) { + throw new ArgeoException( + "Cannot initialize WorkspaceNode UI object." + + getName(), e); + } + } } @Override - public String getLabel() { - return label; + public synchronized void dispose() { + JcrUtils.logoutQuietly(currSession); + super.dispose(); } }