]> git.argeo.org Git - gpl/argeo-slc.git/blob - org.argeo.slc.client.ui.dist/src/org/argeo/slc/client/ui/dist/model/ModularDistVersionBaseElem.java
Adapt to changes in Argeo Commons.
[gpl/argeo-slc.git] / org.argeo.slc.client.ui.dist / src / org / argeo / slc / client / ui / dist / model / ModularDistVersionBaseElem.java
1 package org.argeo.slc.client.ui.dist.model;
2
3 import javax.jcr.Node;
4 import javax.jcr.NodeIterator;
5 import javax.jcr.RepositoryException;
6 import javax.jcr.query.QueryManager;
7 import javax.jcr.query.QueryResult;
8 import javax.jcr.query.qom.Constraint;
9 import javax.jcr.query.qom.QueryObjectModel;
10 import javax.jcr.query.qom.QueryObjectModelFactory;
11 import javax.jcr.query.qom.Selector;
12
13 import org.argeo.slc.SlcException;
14 import org.argeo.slc.SlcNames;
15 import org.argeo.slc.SlcTypes;
16
17 /**
18 * Abstract the base of a given modular distribution set i.e. the parent of all
19 * versions of a given modular distribution
20 */
21 public class ModularDistVersionBaseElem extends DistParentElem {
22
23 // final static public String AETHER_CATEGORY_BASE = "categoryBase";
24 final static public String AETHER_BINARIES_TYPE = "binaries";
25 final static public String AETHER_DEP_TYPE = "dep";
26 private String type;
27 private Node modularDistVersionBase;
28
29 public ModularDistVersionBaseElem(WorkspaceElem wkspElem, String name,
30 Node modularDistVersionBase, String type) {
31 super(name, wkspElem.inHome(), wkspElem.isReadOnly());
32 setParent(wkspElem);
33 this.modularDistVersionBase = modularDistVersionBase;
34 this.type = type;
35 }
36
37 public Node getModularDistBase() {
38 // // TODO clean this
39 // if (type.equals(AETHER_CATEGORY_BASE))
40 // return modularDistVersionBase;
41 // else
42 try {
43 return modularDistVersionBase.getParent();
44 } catch (RepositoryException e) {
45 throw new SlcException("unable to get parent node for "
46 + modularDistVersionBase, e);
47 }
48 }
49
50 public WorkspaceElem getWkspElem() {
51 return (WorkspaceElem) getParent();
52 }
53
54 /**
55 * Override normal behaviour to initialise children only when first
56 * requested
57 */
58 @Override
59 public synchronized boolean hasChildren() {
60 if (isLoaded()) {
61 return super.hasChildren();
62 } else {
63 return true;
64 }
65 };
66
67 /**
68 * Override normal behaviour to initialise children only when first
69 * requested
70 */
71 @Override
72 public synchronized Object[] getChildren() {
73 if (isLoaded()) {
74 return super.getChildren();
75 } else {
76 try {
77 NodeIterator ni = getDistVersions();
78 while (ni != null && ni.hasNext()) {
79 Node curNode = ni.nextNode();
80 if (curNode.hasProperty(SlcNames.SLC_ARTIFACT_VERSION))
81 addChild(new ModularDistVersionElem(this, curNode
82 .getProperty(SlcNames.SLC_ARTIFACT_VERSION)
83 .getString(), curNode));
84 }
85 return super.getChildren();
86 } catch (RepositoryException re) {
87 throw new SlcException("Unable to retrieve children for "
88 + modularDistVersionBase, re);
89 }
90 }
91 }
92
93 private NodeIterator getDistVersions() {
94 try {
95 // if (AETHER_CATEGORY_BASE.equals(type))
96 // return null;
97
98 QueryManager queryManager = modularDistVersionBase.getSession()
99 .getWorkspace().getQueryManager();
100 QueryObjectModelFactory factory = queryManager.getQOMFactory();
101 Selector source = factory.selector(
102 SlcTypes.SLC_MODULAR_DISTRIBUTION,
103 SlcTypes.SLC_MODULAR_DISTRIBUTION);
104 Constraint constraint = factory.descendantNode(
105 source.getSelectorName(), modularDistVersionBase.getPath());
106 // Ordering order = factory.descending(factory.propertyValue(
107 // source.getSelectorName(), SlcNames.SLC_ARTIFACT_VERSION));
108 // Ordering[] orderings = { order };
109 QueryObjectModel query = factory.createQuery(source, constraint,
110 null, null);
111 QueryResult queryResult = query.execute();
112 return queryResult.getNodes();
113 } catch (RepositoryException e) {
114 throw new SlcException(
115 "Unable to version for modular distribution: " + getName(),
116 e);
117 }
118 }
119
120 public String getType() {
121 return type;
122 }
123 }