]> 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/commands/PublishWorkspace.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 / commands / PublishWorkspace.java
1 /*
2 * Copyright (C) 2007-2012 Argeo GmbH
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16 package org.argeo.slc.client.ui.dist.commands;
17
18 import javax.jcr.Credentials;
19 import javax.jcr.Node;
20 import javax.jcr.Repository;
21 import javax.jcr.RepositoryException;
22 import javax.jcr.RepositoryFactory;
23 import javax.jcr.Session;
24 import javax.jcr.security.Privilege;
25
26 import org.argeo.ArgeoException;
27 import org.argeo.jcr.JcrUtils;
28 import org.argeo.slc.client.ui.dist.DistPlugin;
29 import org.argeo.slc.repo.RepoUtils;
30 import org.argeo.util.security.Keyring;
31 import org.eclipse.core.commands.AbstractHandler;
32 import org.eclipse.core.commands.ExecutionEvent;
33 import org.eclipse.core.commands.ExecutionException;
34 import org.eclipse.jface.dialogs.MessageDialog;
35
36 /**
37 * Publish the current workspace by giving REOD_ONLY rights to anonymous.
38 */
39
40 public class PublishWorkspace extends AbstractHandler {
41 // private static final Log log = LogFactory.getLog(PublishWorkspace.class);
42 public final static String ID = DistPlugin.ID + ".publishWorkspace";
43 public final static String DEFAULT_LABEL = "Publish workspace";
44 public final static String DEFAULT_ICON_PATH = "icons/publish.gif";
45 public final static String PARAM_WORKSPACE_NAME = "workspaceName";
46 public final static String PARAM_TARGET_REPO_PATH = "targetRepoPath";
47
48 // DEPENDENCY INJECTION
49 private RepositoryFactory repositoryFactory;
50 private Keyring keyring;
51 private Repository nodeRepository;
52
53 private String publicRole = "anonymous";
54
55 public Object execute(ExecutionEvent event) throws ExecutionException {
56 String targetRepoPath = event.getParameter(PARAM_TARGET_REPO_PATH);
57 String workspaceName = event.getParameter(PARAM_WORKSPACE_NAME);
58
59 Session nodeSession = null;
60 Session session = null;
61
62 try {
63 nodeSession = nodeRepository.login();
64 Node repoNode = nodeSession.getNode(targetRepoPath);
65 Repository repository = RepoUtils.getRepository(repositoryFactory,
66 keyring, repoNode);
67 Credentials credentials = RepoUtils.getRepositoryCredentials(
68 keyring, repoNode);
69
70 String msg = "Are you sure you want to publish this distribution: "
71 + workspaceName + " ?";
72 boolean result = MessageDialog.openConfirm(DistPlugin.getDefault()
73 .getWorkbench().getDisplay().getActiveShell(),
74 "Confirm publication", msg);
75
76 if (result) {
77
78 session = repository.login(credentials, workspaceName);
79 JcrUtils.addPrivilege(session, "/", publicRole,
80 Privilege.JCR_READ);
81 session.save();
82
83 JcrUtils.logoutQuietly(session);
84 // CommandHelpers.callCommand(RefreshDistributionsView.ID);
85 }
86 } catch (RepositoryException re) {
87 throw new ArgeoException(
88 "Unexpected error while publishing workspace "
89 + workspaceName, re);
90 } finally {
91 JcrUtils.logoutQuietly(session);
92 JcrUtils.logoutQuietly(nodeSession);
93 }
94 return null;
95 }
96
97 /* DEPENDENCY INJECTION */
98 public void setNodeRepository(Repository nodeRepository) {
99 this.nodeRepository = nodeRepository;
100 }
101
102 public void setRepositoryFactory(RepositoryFactory repositoryFactory) {
103 this.repositoryFactory = repositoryFactory;
104 }
105
106 public void setKeyring(Keyring keyring) {
107 this.keyring = keyring;
108 }
109 }