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
.Query
;
9 import org
.argeo
.ArgeoException
;
10 import org
.argeo
.jcr
.JcrUtils
;
11 import org
.argeo
.slc
.jcr
.SlcNames
;
12 import org
.argeo
.slc
.jcr
.SlcTypes
;
14 /** Abstract a workspace that contains a software distribution */
15 public class WorkspaceElem
extends DistParentElem
{
16 private final RepoElem repoElem
;
17 private String workspaceName
;
18 private Session currSession
;
20 public WorkspaceElem(WkspGroupElem parent
, RepoElem repoElem
,
21 String workspaceName
) {
22 super(workspaceName
, repoElem
.inHome(), repoElem
.isReadOnly());
23 this.repoElem
= repoElem
;
24 this.workspaceName
= workspaceName
;
28 public String
getWorkspaceName() {
32 public RepoElem
getRepoElem() {
36 public Boolean
isConnected() {
37 if (currSession
!= null && currSession
.isLive())
44 currSession
= repoElem
.repositoryLogin(getName());
47 /** Utility to create a new Session with correct credential in this context */
48 public Session
getNewSession() {
49 return repoElem
.repositoryLogin(getName());
52 public boolean hasChildren() {
55 return currSession
.getRootNode().hasNodes();
58 } catch (RepositoryException re
) {
59 throw new ArgeoException(
60 "Unexpected error while checking children node existence",
65 /** Override normal behaviour to initialize display of the workspace */
67 public synchronized Object
[] getChildren() {
69 return super.getChildren();
71 // initialize current object
73 // Lazy connect the first time we retrieve children
74 if (currSession
== null)
77 // Retrieve already existing distribution
78 Query groupQuery
= currSession
83 + SlcTypes
.SLC_MODULAR_DISTRIBUTION
84 + "]", Query
.JCR_SQL2
);
85 NodeIterator distributions
= groupQuery
.execute().getNodes();
86 distribs
: while (distributions
.hasNext()) {
87 Node currDist
= distributions
.nextNode();
88 Node distBase
= currDist
.getParent().getParent();
89 if (!distBase
.isNodeType(SlcTypes
.SLC_ARTIFACT_BASE
))
91 String groupId
= distBase
92 .getProperty(SlcNames
.SLC_GROUP_ID
).getString();
93 String artifactId
= distBase
.getProperty(
94 SlcNames
.SLC_ARTIFACT_ID
).getString();
98 if (ModularDistBaseElem
.AETHER_BINARIES_TYPE
99 .equals(artifactId
)) {
101 type
= ModularDistBaseElem
.AETHER_BINARIES_TYPE
;
104 type
= ModularDistBaseElem
.AETHER_DEP_TYPE
;
106 if (getChildByName(name
) == null)
107 addChild(new ModularDistBaseElem(WorkspaceElem
.this,
108 name
, distBase
, type
));
110 // Add empty group base that have been marked as relevant
111 groupQuery
= currSession
116 + SlcTypes
.SLC_CATEGORY
+ "]",
118 distributions
= groupQuery
.execute().getNodes();
119 while (distributions
.hasNext()) {
120 Node distBase
= distributions
.nextNode();
121 String groupBaseId
= distBase
.getProperty(
122 SlcNames
.SLC_GROUP_BASE_ID
).getString();
123 if (getChildByName(groupBaseId
) == null)
124 addChild(new ModularDistBaseElem(WorkspaceElem
.this,
125 groupBaseId
, distBase
,
126 ModularDistBaseElem
.AETHER_CATEGORY_BASE
));
128 return super.getChildren();
129 } catch (RepositoryException e
) {
130 throw new ArgeoException(
131 "Cannot initialize WorkspaceNode UI object."
138 public synchronized void dispose() {
139 JcrUtils
.logoutQuietly(currSession
);