]> git.argeo.org Git - gpl/argeo-slc.git/blobdiff - org.argeo.slc.client.ui.dist/src/org/argeo/slc/client/ui/dist/commands/MergeWorkspaces.java
Remove old license headers
[gpl/argeo-slc.git] / org.argeo.slc.client.ui.dist / src / org / argeo / slc / client / ui / dist / commands / MergeWorkspaces.java
index e3190072648437086e0e3a1e53288abc00283ecb..70c3d7a1283ed23e2b1a206794881aac7161ae10 100644 (file)
@@ -1,18 +1,3 @@
-/*
- * Copyright (C) 2007-2012 Argeo GmbH
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *         http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
 package org.argeo.slc.client.ui.dist.commands;
 
 import javax.jcr.Credentials;
@@ -27,13 +12,13 @@ import javax.jcr.query.QueryResult;
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
-import org.argeo.ArgeoMonitor;
-import org.argeo.eclipse.ui.EclipseArgeoMonitor;
+import org.argeo.api.security.Keyring;
+import org.argeo.eclipse.ui.EclipseJcrMonitor;
+import org.argeo.jcr.JcrMonitor;
 import org.argeo.jcr.JcrUtils;
 import org.argeo.slc.SlcException;
 import org.argeo.slc.client.ui.dist.DistPlugin;
 import org.argeo.slc.repo.RepoUtils;
-import org.argeo.util.security.Keyring;
 import org.eclipse.core.commands.AbstractHandler;
 import org.eclipse.core.commands.ExecutionEvent;
 import org.eclipse.core.commands.ExecutionException;
@@ -69,16 +54,12 @@ public class MergeWorkspaces extends AbstractHandler {
                try {
                        nodeSession = nodeRepository.login();
                        Node srcRepoNode = nodeSession.getNode(sourceRepoPath);
-                       Repository srcRepository = RepoUtils.getRepository(
-                                       repositoryFactory, keyring, srcRepoNode);
-                       Credentials srcCredentials = RepoUtils.getRepositoryCredentials(
-                                       keyring, srcRepoNode);
+                       Repository srcRepository = RepoUtils.getRepository(repositoryFactory, keyring, srcRepoNode);
+                       Credentials srcCredentials = RepoUtils.getRepositoryCredentials(keyring, srcRepoNode);
 
                        Node targetRepoNode = nodeSession.getNode(targetRepoPath);
-                       Repository targetRepository = RepoUtils.getRepository(
-                                       repositoryFactory, keyring, targetRepoNode);
-                       Credentials targetCredentials = RepoUtils.getRepositoryCredentials(
-                                       keyring, targetRepoNode);
+                       Repository targetRepository = RepoUtils.getRepository(repositoryFactory, keyring, targetRepoNode);
+                       Credentials targetCredentials = RepoUtils.getRepositoryCredentials(keyring, targetRepoNode);
 
                        // String msg = "Are you sure you want to merge distribution ["
                        // + sourceWkspName + "] in distribution [" + targetWkspName
@@ -91,35 +72,27 @@ public class MergeWorkspaces extends AbstractHandler {
                        // Open sessions here since the background thread
                        // won't necessarily be authenticated.
                        // Job should close the sessions.
-                       Session sourceSession = srcRepository.login(srcCredentials,
-                                       sourceWkspName);
+                       Session sourceSession = srcRepository.login(srcCredentials, sourceWkspName);
                        Session targetSession;
                        try {
-                               targetSession = targetRepository.login(targetCredentials,
-                                               targetWkspName);
+                               targetSession = targetRepository.login(targetCredentials, targetWkspName);
                        } catch (NoSuchWorkspaceException e) {
-                               Session defaultSession = targetRepository
-                                               .login(targetCredentials);
+                               Session defaultSession = targetRepository.login(targetCredentials);
                                try {
-                                       defaultSession.getWorkspace().createWorkspace(
-                                                       targetWkspName);
+                                       defaultSession.getWorkspace().createWorkspace(targetWkspName);
                                } catch (Exception e1) {
-                                       throw new SlcException("Cannot create new workspace "
-                                                       + targetWkspName, e);
+                                       throw new SlcException("Cannot create new workspace " + targetWkspName, e);
                                } finally {
                                        JcrUtils.logoutQuietly(defaultSession);
                                }
-                               targetSession = targetRepository.login(targetCredentials,
-                                               targetWkspName);
+                               targetSession = targetRepository.login(targetCredentials, targetWkspName);
                        }
 
-                       Job workspaceMergeJob = new WorkspaceMergeJob(sourceSession,
-                                       targetSession);
+                       Job workspaceMergeJob = new WorkspaceMergeJob(sourceSession, targetSession);
                        workspaceMergeJob.setUser(true);
                        workspaceMergeJob.schedule();
                } catch (RepositoryException re) {
-                       throw new SlcException(
-                                       "Unexpected error while merging workspaces.", re);
+                       throw new SlcException("Unexpected error while merging workspaces.", re);
                } finally {
                        JcrUtils.logoutQuietly(nodeSession);
                }
@@ -140,34 +113,28 @@ public class MergeWorkspaces extends AbstractHandler {
                protected IStatus run(IProgressMonitor eclipseMonitor) {
                        long begin = System.currentTimeMillis();
                        try {
-                               Query countQuery = sourceSession
-                                               .getWorkspace()
-                                               .getQueryManager()
-                                               .createQuery("select file from [nt:file] as file",
-                                                               Query.JCR_SQL2);
+                               Query countQuery = sourceSession.getWorkspace().getQueryManager()
+                                               .createQuery("select file from [nt:file] as file", Query.JCR_SQL2);
                                QueryResult result = countQuery.execute();
                                Long expectedCount = result.getNodes().getSize();
                                if (log.isDebugEnabled())
                                        log.debug("Will copy " + expectedCount + " files...");
 
-                               ArgeoMonitor monitor = new EclipseArgeoMonitor(eclipseMonitor);
-                               eclipseMonitor
-                                               .beginTask("Copy files", expectedCount.intValue());
+                               JcrMonitor monitor = new EclipseJcrMonitor(eclipseMonitor);
+                               eclipseMonitor.beginTask("Copy files", expectedCount.intValue());
 
-                               Long count = JcrUtils.copyFiles(sourceSession.getRootNode(),
-                                               targetSession.getRootNode(), true, monitor);
+                               Long count = JcrUtils.copyFiles(sourceSession.getRootNode(), targetSession.getRootNode(), true, monitor,
+                                               true);
 
                                monitor.done();
                                long duration = (System.currentTimeMillis() - begin) / 1000;// in
                                                                                                                                                        // s
                                if (log.isDebugEnabled())
-                                       log.debug("Copied " + count + " files in "
-                                                       + (duration / 60) + "min " + (duration % 60) + "s");
+                                       log.debug("Copied " + count + " files in " + (duration / 60) + "min " + (duration % 60) + "s");
 
                                return Status.OK_STATUS;
                        } catch (RepositoryException e) {
-                               return new Status(IStatus.ERROR, DistPlugin.PLUGIN_ID,
-                                               "Cannot merge", e);
+                               return new Status(IStatus.ERROR, DistPlugin.PLUGIN_ID, "Cannot merge", e);
                        } finally {
                                JcrUtils.logoutQuietly(sourceSession);
                                JcrUtils.logoutQuietly(targetSession);