]> git.argeo.org Git - gpl/argeo-slc.git/blobdiff - plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/model/ModularDistBaseElem.java
Fix a few issues while testing and building distributions.
[gpl/argeo-slc.git] / plugins / org.argeo.slc.client.ui.dist / src / main / java / org / argeo / slc / client / ui / dist / model / ModularDistBaseElem.java
index 35e3f21dd40f01ad2bec30df308913719d180986..b85659440e3156bf93b90897c3458c2b769c6b85 100644 (file)
@@ -16,8 +16,8 @@ import org.argeo.slc.jcr.SlcNames;
 import org.argeo.slc.jcr.SlcTypes;
 
 /**
- * Abstract the base a given modular distribution set that is the parent all
- * versions of the same distribution
+ * Abstract the base of a given modular distribution set i.e. the parent of all
+ * versions of a given modular distribution
  */
 public class ModularDistBaseElem extends DistParentElem {
 
@@ -25,18 +25,32 @@ public class ModularDistBaseElem extends DistParentElem {
        final static public String AETHER_BINARIES_TYPE = "binaries";
        final static public String AETHER_DEP_TYPE = "dep";
        private String type;
-       private Node artifactBase;
+       private Node modularDistBase;
 
        public ModularDistBaseElem(WorkspaceElem wkspElem, String name,
-                       Node artifactBase, String type) {
+                       Node modularDistBase, String type) {
                super(name, wkspElem.inHome(), wkspElem.isReadOnly());
                setParent(wkspElem);
-               this.artifactBase = artifactBase;
+               this.modularDistBase = modularDistBase;
                this.type = type;
        }
 
+       public Node getCategoryBase() {
+               // TODO clean this
+               if (type.equals(AETHER_CATEGORY_BASE))
+                       return modularDistBase;
+               else
+                       try {
+                               return modularDistBase.getParent();
+                       } catch (RepositoryException e) {
+                               throw new SlcException("unable tyo get parent node for "
+                                               + modularDistBase, e);
+                       }
+       }
+
        /**
-        * Override normal behavior to initialize children only when first requested
+        * Override normal behaviour to initialise children only when first
+        * requested
         */
        @Override
        public synchronized boolean hasChildren() {
@@ -48,44 +62,44 @@ public class ModularDistBaseElem extends DistParentElem {
        };
 
        /**
-        * Override normal behavior to initialize children only when first requested
+        * Override normal behaviour to initialise children only when first
+        * requested
         */
        @Override
        public synchronized Object[] getChildren() {
                if (isLoaded()) {
                        return super.getChildren();
                } else {
-                       // initialize current object
                        try {
                                NodeIterator ni = getDistVersions();
                                while (ni != null && ni.hasNext()) {
                                        Node curNode = ni.nextNode();
-                                       addChild(new ModularDistVersionElem(this, curNode
-                                                       .getProperty(SlcNames.SLC_ARTIFACT_VERSION)
-                                                       .getString(), curNode));
+                                       if (curNode.hasProperty(SlcNames.SLC_ARTIFACT_VERSION))
+                                               addChild(new ModularDistVersionElem(this, curNode
+                                                               .getProperty(SlcNames.SLC_ARTIFACT_VERSION)
+                                                               .getString(), curNode));
                                }
                                return super.getChildren();
                        } catch (RepositoryException re) {
-                               throw new ArgeoException(
-                                               "Unexcpected error while initializing children SingleJcrNode",
-                                               re);
+                               throw new ArgeoException("Unable to retrieve children for "
+                                               + modularDistBase, re);
                        }
                }
        }
 
-       public NodeIterator getDistVersions() {
+       private NodeIterator getDistVersions() {
                try {
                        if (AETHER_CATEGORY_BASE.equals(type))
                                return null;
 
-                       QueryManager queryManager = artifactBase.getSession()
+                       QueryManager queryManager = modularDistBase.getSession()
                                        .getWorkspace().getQueryManager();
                        QueryObjectModelFactory factory = queryManager.getQOMFactory();
                        Selector source = factory.selector(
                                        SlcTypes.SLC_MODULAR_DISTRIBUTION,
                                        SlcTypes.SLC_MODULAR_DISTRIBUTION);
                        Constraint constraint = factory.descendantNode(
-                                       source.getSelectorName(), artifactBase.getPath());
+                                       source.getSelectorName(), modularDistBase.getPath());
                        // Ordering order = factory.descending(factory.propertyValue(
                        // source.getSelectorName(), SlcNames.SLC_ARTIFACT_VERSION));
                        // Ordering[] orderings = { order };