]> 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/GroupElem.java
Do not clean OSGi runtime
[gpl/argeo-slc.git] / plugins / org.argeo.slc.client.ui.dist / src / main / java / org / argeo / slc / client / ui / dist / model / GroupElem.java
1 package org.argeo.slc.client.ui.dist.model;
2
3 import java.security.AccessControlException;
4 import java.util.ArrayList;
5 import java.util.List;
6
7 import javax.jcr.Repository;
8 import javax.jcr.RepositoryException;
9 import javax.jcr.Session;
10
11 import org.argeo.jcr.JcrUtils;
12 import org.argeo.slc.SlcException;
13
14 /**
15 * Abstracts a group of distribution, that is a bunch of workspaces with same
16 * prefix.
17 */
18 public class GroupElem extends DistParentElem {
19 private RepoElem repoElem;
20 private String name;
21
22 public GroupElem(RepoElem repoElem, String prefix) {
23 super(repoElem.inHome(), repoElem.isReadOnly());
24 this.repoElem = repoElem;
25 this.name = prefix;
26 }
27
28 public Object[] getChildren() {
29 Session session = null;
30 try {
31 Repository repository = repoElem.getRepository();
32 session = repository.login(repoElem.getCredentials());
33
34 String[] workspaceNames = session.getWorkspace()
35 .getAccessibleWorkspaceNames();
36 List<WorkspaceElem> distributionElems = new ArrayList<WorkspaceElem>();
37 buildWksp: for (String workspaceName : workspaceNames) {
38
39 // Filter non-public workspaces for user anonymous.
40 if (repoElem.getRepoNode() == null) {
41 Session tmpSession = null;
42 try {
43 tmpSession = repository.login(workspaceName);
44 Boolean res = true;
45 try {
46 tmpSession.checkPermission("/", "read");
47 } catch (AccessControlException e) {
48 res = false;
49 }
50 if (!res)
51 continue buildWksp;
52 } catch (RepositoryException e) {
53 throw new SlcException(
54 "Cannot list workspaces for anonymous user", e);
55 } finally {
56 JcrUtils.logoutQuietly(tmpSession);
57 }
58 }
59
60 // filter technical workspaces
61 if (workspaceName.startsWith(name)) {
62 distributionElems.add(new WorkspaceElem(repoElem,
63 workspaceName));
64 }
65 }
66 return distributionElems.toArray();
67 } catch (RepositoryException e) {
68 throw new SlcException("Cannot list workspaces for prefix " + name,
69 e);
70 } finally {
71 JcrUtils.logoutQuietly(session);
72 }
73 }
74
75 public String getLabel() {
76 return name;
77 }
78
79 public String toString() {
80 return getLabel();
81 }
82
83 public void dispose() {
84 }
85
86 public RepoElem getRepoElem() {
87 return repoElem;
88 }
89
90 }