]> git.argeo.org Git - gpl/argeo-slc.git/blob - WorkspaceElem.java
6f6a93a3a83b5d3b3cd96db6f50fbab284ff83d6
[gpl/argeo-slc.git] / WorkspaceElem.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.Session;
7 import javax.jcr.query.Query;
8
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;
13
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;
19
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;
25 setParent(parent);
26 }
27
28 public String getWorkspaceName() {
29 return workspaceName;
30 }
31
32 public RepoElem getRepoElem() {
33 return repoElem;
34 }
35
36 public Boolean isConnected() {
37 if (currSession != null && currSession.isLive())
38 return true;
39 else
40 return false;
41 }
42
43 public void login() {
44 currSession = repoElem.repositoryLogin(getName());
45 }
46
47 public boolean hasChildren() {
48 try {
49 if (isConnected())
50 return currSession.getRootNode().hasNodes();
51 else
52 return false;
53 } catch (RepositoryException re) {
54 throw new ArgeoException(
55 "Unexpected error while checking children node existence",
56 re);
57 }
58 }
59
60 /** Override normal behaviour to initialize display of the workspace */
61 @Override
62 public synchronized Object[] getChildren() {
63 if (isLoaded()) {
64 return super.getChildren();
65 } else {
66 // initialize current object
67 try {
68 if (currSession == null)
69 return null;
70 else {
71 // Retrieve already existing distribution
72 Query groupQuery = currSession
73 .getWorkspace()
74 .getQueryManager()
75 .createQuery(
76 "select * from ["
77 + SlcTypes.SLC_MODULAR_DISTRIBUTION
78 + "]", Query.JCR_SQL2);
79 NodeIterator distributions = groupQuery.execute()
80 .getNodes();
81 distribs: while (distributions.hasNext()) {
82 Node currDist = distributions.nextNode();
83 Node distBase = currDist.getParent().getParent();
84 if (!distBase.isNodeType(SlcTypes.SLC_ARTIFACT_BASE))
85 continue distribs;
86 String groupId = distBase.getProperty(
87 SlcNames.SLC_GROUP_ID).getString();
88 String artifactId = distBase.getProperty(
89 SlcNames.SLC_ARTIFACT_ID).getString();
90
91 String name;
92 String type;
93 if (ModularDistBaseElem.AETHER_BINARIES_TYPE
94 .equals(artifactId)) {
95 name = groupId;
96 type = ModularDistBaseElem.AETHER_BINARIES_TYPE;
97 } else {
98 name = artifactId;
99 type = ModularDistBaseElem.AETHER_DEP_TYPE;
100 }
101 if (getChildByName(name) == null)
102 addChild(new ModularDistBaseElem(
103 WorkspaceElem.this, name, distBase, type));
104 }
105 // Add empty group base that have been marked as relevant
106 groupQuery = currSession
107 .getWorkspace()
108 .getQueryManager()
109 .createQuery(
110 "select * from ["
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));
122 }
123 }
124 return super.getChildren();
125 } catch (RepositoryException e) {
126 throw new ArgeoException(
127 "Cannot initialize WorkspaceNode UI object."
128 + getName(), e);
129 }
130 }
131 }
132
133 @Override
134 public synchronized void dispose() {
135 JcrUtils.logoutQuietly(currSession);
136 super.dispose();
137 }
138 }