1 package org
.argeo
.slc
.client
.ui
.dist
.model
;
4 import javax
.jcr
.NodeIterator
;
5 import javax
.jcr
.RepositoryException
;
6 import javax
.jcr
.Session
;
7 import javax
.jcr
.query
.InvalidQueryException
;
8 import javax
.jcr
.query
.QueryManager
;
9 import javax
.jcr
.query
.qom
.QueryObjectModel
;
10 import javax
.jcr
.query
.qom
.QueryObjectModelFactory
;
11 import javax
.jcr
.query
.qom
.Selector
;
13 import org
.argeo
.jcr
.JcrUtils
;
14 import org
.argeo
.slc
.SlcException
;
15 import org
.argeo
.slc
.jcr
.SlcNames
;
16 import org
.argeo
.slc
.jcr
.SlcTypes
;
18 /** Abstract a workspace that contains a software distribution */
19 public class WorkspaceElem
extends DistParentElem
{
20 private final RepoElem repoElem
;
21 private String workspaceName
;
22 private Session currSession
;
24 public WorkspaceElem(WkspGroupElem parent
, RepoElem repoElem
,
25 String workspaceName
) {
26 super(workspaceName
, repoElem
.inHome(), repoElem
.isReadOnly());
27 this.repoElem
= repoElem
;
28 this.workspaceName
= workspaceName
;
32 public String
getWorkspaceName() {
36 public RepoElem
getRepoElem() {
40 public Boolean
isConnected() {
41 if (currSession
!= null && currSession
.isLive())
48 currSession
= repoElem
.repositoryLogin(getName());
51 /** Utility to create a new Session with correct credential in this context */
52 public Session
getNewSession() {
53 return repoElem
.repositoryLogin(getName());
56 public boolean hasChildren() {
59 return currSession
.getRootNode().hasNodes();
62 } catch (RepositoryException re
) {
63 throw new SlcException(
64 "Unexpected error while checking children node existence",
69 /** Override normal behaviour to initialize display of the workspace */
71 public synchronized Object
[] getChildren() {
73 return super.getChildren();
75 // initialize current object
77 // Lazy connect the first time we retrieve children
78 if (currSession
== null)
81 // Retrieve already existing distribution
83 // Use QOM rather than SQL2 - it seems more robust for remoting
84 // with JCR 2.2 (might also be some model refresh issue with the
86 QueryManager queryManager
= currSession
.getWorkspace()
88 QueryObjectModelFactory factory
= queryManager
.getQOMFactory();
89 Selector selector
= factory
.selector(
90 SlcTypes
.SLC_MODULAR_DISTRIBUTION
,
91 SlcTypes
.SLC_MODULAR_DISTRIBUTION
);
92 // Curiously this works...
93 // Selector selector = factory.selector(
94 // SlcTypes.SLC_JAR_FILE,
95 // SlcTypes.SLC_JAR_FILE);
97 QueryObjectModel query
= factory
.createQuery(selector
, null,
100 // Query groupQuery = currSession
102 // .getQueryManager()
105 // + SlcTypes.SLC_MODULAR_DISTRIBUTION
106 // + "]", Query.JCR_SQL2);
107 NodeIterator distributions
= null;
109 distributions
= query
.execute().getNodes();
110 } catch (InvalidQueryException iqe
) {
111 // For legacy only does not throw an exception while
113 // legacy repositories that does not know
114 // SLC_MODULAR_DISTRIBUTION type
116 distribs
: while (distributions
!= null
117 && distributions
.hasNext()) {
118 Node currDist
= distributions
.nextNode();
119 Node distBase
= currDist
.getParent().getParent();
120 if (!distBase
.isNodeType(SlcTypes
.SLC_ARTIFACT_BASE
))
122 String groupId
= distBase
123 .getProperty(SlcNames
.SLC_GROUP_ID
).getString();
124 String artifactId
= distBase
.getProperty(
125 SlcNames
.SLC_ARTIFACT_ID
).getString();
129 if (ModularDistVersionBaseElem
.AETHER_BINARIES_TYPE
130 .equals(artifactId
)) {
132 type
= ModularDistVersionBaseElem
.AETHER_BINARIES_TYPE
;
135 type
= ModularDistVersionBaseElem
.AETHER_DEP_TYPE
;
137 if (getChildByName(name
) == null)
138 addChild(new ModularDistVersionBaseElem(
139 WorkspaceElem
.this, name
, distBase
, type
));
141 return super.getChildren();
142 } catch (RepositoryException e
) {
143 throw new SlcException(
144 "Cannot initialize WorkspaceNode UI object."
151 public synchronized void dispose() {
152 JcrUtils
.logoutQuietly(currSession
);