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=3be73b5e568fc6ee9f78d87c75e8e7c1dee630a5;hb=d19e5160d9bdc6ee3eea8eee0fd13fc126bd339f;hp=41ba6efe32fa6dd51d3a3b14e7732381652b4c48;hpb=702f1e0c7d73edeb739dd62cd4248f489e1420b7;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 41ba6efe3..3be73b5e5 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 @@ -4,7 +4,11 @@ import javax.jcr.Node; import javax.jcr.NodeIterator; import javax.jcr.RepositoryException; import javax.jcr.Session; -import javax.jcr.query.Query; +import javax.jcr.query.InvalidQueryException; +import javax.jcr.query.QueryManager; +import javax.jcr.query.qom.QueryObjectModel; +import javax.jcr.query.qom.QueryObjectModelFactory; +import javax.jcr.query.qom.Selector; import org.argeo.ArgeoException; import org.argeo.jcr.JcrUtils; @@ -44,12 +48,17 @@ public class WorkspaceElem extends DistParentElem { 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() { try { if (isConnected()) return currSession.getRootNode().hasNodes(); else - return false; + return true; } catch (RepositoryException re) { throw new ArgeoException( "Unexpected error while checking children node existence", @@ -65,45 +74,69 @@ public class WorkspaceElem extends DistParentElem { } else { // initialize current object try { + // Lazy connect the first time we retrieve children if (currSession == null) - return null; - else { - Query groupQuery = currSession.getWorkspace() - .getQueryManager() - // .createQuery( - // "select * from [" + SlcTypes.SLC_GROUP_BASE - // + "] as group order by group.[" - // + SlcNames.SLC_GROUP_BASE_ID + "]", - .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)); + login(); + + // Retrieve already existing distribution + + // Use QOM rather than SQL2 - it seems more robust for remoting + // with JCR 2.2 (might also be some model refresh issue with the + // remoting) + QueryManager queryManager = currSession.getWorkspace() + .getQueryManager(); + QueryObjectModelFactory factory = queryManager.getQOMFactory(); + Selector selector = factory.selector( + SlcTypes.SLC_MODULAR_DISTRIBUTION, + SlcTypes.SLC_MODULAR_DISTRIBUTION); + // Curiously this works... + // Selector selector = factory.selector( + // SlcTypes.SLC_JAR_FILE, + // SlcTypes.SLC_JAR_FILE); + + QueryObjectModel query = factory.createQuery(selector, null, + null, null); + + // Query groupQuery = currSession + // .getWorkspace() + // .getQueryManager() + // .createQuery( + // "select * from [" + // + SlcTypes.SLC_MODULAR_DISTRIBUTION + // + "]", Query.JCR_SQL2); + NodeIterator distributions = null; + try { + distributions = query.execute().getNodes(); + } catch (InvalidQueryException iqe) { + // For legacy only does not throw an exception while + // browsing + // legacy repositories that does not know + // SLC_MODULAR_DISTRIBUTION type + } + distribs: while (distributions != null + && 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 (ModularDistVersionBaseElem.AETHER_BINARIES_TYPE + .equals(artifactId)) { + name = groupId; + type = ModularDistVersionBaseElem.AETHER_BINARIES_TYPE; + } else { + name = artifactId; + type = ModularDistVersionBaseElem.AETHER_DEP_TYPE; } + if (getChildByName(name) == null) + addChild(new ModularDistVersionBaseElem( + WorkspaceElem.this, name, distBase, type)); } return super.getChildren(); } catch (RepositoryException e) { @@ -119,4 +152,4 @@ public class WorkspaceElem extends DistParentElem { JcrUtils.logoutQuietly(currSession); super.dispose(); } -} +} \ No newline at end of file