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 public boolean hasChildren() {
50 return currSession
.getRootNode().hasNodes();
53 } catch (RepositoryException re
) {
54 throw new ArgeoException(
55 "Unexpected error while checking children node existence",
60 /** Override normal behaviour to initialize display of the workspace */
62 public synchronized Object
[] getChildren() {
64 return super.getChildren();
66 // initialize current object
68 if (currSession
== null)
71 // Retrieve already existing distribution
72 Query groupQuery
= currSession
77 + SlcTypes
.SLC_MODULAR_DISTRIBUTION
78 + "]", Query
.JCR_SQL2
);
79 NodeIterator distributions
= groupQuery
.execute()
81 distribs
: while (distributions
.hasNext()) {
82 Node currDist
= distributions
.nextNode();
83 Node distBase
= currDist
.getParent().getParent();
84 if (!distBase
.isNodeType(SlcTypes
.SLC_ARTIFACT_BASE
))
86 String groupId
= distBase
.getProperty(
87 SlcNames
.SLC_GROUP_ID
).getString();
88 String artifactId
= distBase
.getProperty(
89 SlcNames
.SLC_ARTIFACT_ID
).getString();
93 if (ModularDistBaseElem
.AETHER_BINARIES_TYPE
94 .equals(artifactId
)) {
96 type
= ModularDistBaseElem
.AETHER_BINARIES_TYPE
;
99 type
= ModularDistBaseElem
.AETHER_DEP_TYPE
;
101 if (getChildByName(name
) == null)
102 addChild(new ModularDistBaseElem(
103 WorkspaceElem
.this, name
, distBase
, type
));
105 // Add empty group base that have been marked as relevant
106 groupQuery
= currSession
111 + SlcTypes
.SLC_RELEVANT_CATEGORY
112 + "]", Query
.JCR_SQL2
);
113 distributions
= groupQuery
.execute().getNodes();
114 while (distributions
.hasNext()) {
115 Node distBase
= distributions
.nextNode();
116 String groupBaseId
= distBase
.getProperty(
117 SlcNames
.SLC_GROUP_BASE_ID
).getString();
118 if (getChildByName(groupBaseId
) == null)
119 addChild(new ModularDistBaseElem(
120 WorkspaceElem
.this, groupBaseId
, distBase
,
121 ModularDistBaseElem
.AETHER_BINARIES_TYPE
));
124 return super.getChildren();
125 } catch (RepositoryException e
) {
126 throw new ArgeoException(
127 "Cannot initialize WorkspaceNode UI object."
134 public synchronized void dispose() {
135 JcrUtils
.logoutQuietly(currSession
);