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