<commit_before>/*******************************************************************************
 * Copyright (c) 2008-2011 Chair for Applied Software Engineering,
 * Technische Universitaet Muenchen.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 * 
 * Contributors:
 ******************************************************************************/
package org.eclipse.emf.emfstore.client.model.controller;

import java.util.Date;

import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.emf.emfstore.client.common.UnknownEMFStoreWorkloadCommand;
import org.eclipse.emf.emfstore.client.model.Configuration;
import org.eclipse.emf.emfstore.client.model.Usersession;
import org.eclipse.emf.emfstore.client.model.WorkspaceManager;
import org.eclipse.emf.emfstore.client.model.connectionmanager.ServerCall;
import org.eclipse.emf.emfstore.client.model.impl.ProjectSpaceBase;
import org.eclipse.emf.emfstore.client.model.observers.LoginObserver;
import org.eclipse.emf.emfstore.client.model.observers.ShareObserver;
import org.eclipse.emf.emfstore.server.exceptions.EmfStoreException;
import org.eclipse.emf.emfstore.server.model.ProjectInfo;
import org.eclipse.emf.emfstore.server.model.versioning.LogMessage;
import org.eclipse.emf.emfstore.server.model.versioning.VersioningFactory;

/**
 * Shares a project.
 * 
 * @author ovonwesen
 * @author emueller
 */
public class ShareController extends ServerCall<Void> {

	/**
	 * Constructor.
	 * 
	 * @param projectSpace
	 *            the project space to be shared
	 * @param session
	 *            the session to use during share
	 * @param monitor
	 *            a progress monitor that is used to indicate the progress of the share
	 */
	public ShareController(ProjectSpaceBase projectSpace, Usersession session, IProgressMonitor monitor) {
		super(projectSpace);

		// if session is null, session will be injected by sessionmanager
		setUsersession(session);
		setProgressMonitor(monitor);
	}

	@Override
	protected Void run() throws EmfStoreException {
		doRun();
		return null;
	}

	@SuppressWarnings("unchecked")
	private void doRun() throws EmfStoreException {

		getProgressMonitor().beginTask("Sharing Project", 100);
		getProgressMonitor().worked(1);
		getProgressMonitor().subTask("Preparing project for sharing");

		final LogMessage logMessage = VersioningFactory.eINSTANCE.createLogMessage();
		logMessage.setAuthor(getUsersession().getUsername());
		logMessage.setClientDate(new Date());
		logMessage.setMessage("Initial commit");
		ProjectInfo createdProject = null;

		getProjectSpace().stopChangeRecording();
		Configuration.setAutoSave(false);

		getProgressMonitor().worked(10);
		if (getProgressMonitor().isCanceled()) {
			Configuration.setAutoSave(true);
			getProjectSpace().save();
			getProjectSpace().startChangeRecording();
			getProgressMonitor().done();
		}
		getProgressMonitor().subTask("Sharing project with server");

		// make sure, current state of caches is written to resource
		getProjectSpace().save();

		createdProject = new UnknownEMFStoreWorkloadCommand<ProjectInfo>(getProgressMonitor()) {
			@Override
			public ProjectInfo run(IProgressMonitor monitor) throws EmfStoreException {
				return WorkspaceManager
					.getInstance()
					.getConnectionManager()
					.createProject(
						getUsersession().getSessionId(),
						getProjectSpace().getProjectName() == null ? "Project@" + new Date() : getProjectSpace()
							.getProjectName(),
						getProjectSpace().getProjectDescription() == null ? "" : getProjectSpace()
							.getProjectDescription(), logMessage, getProjectSpace().getProject());
			}
		}.execute();

		getProgressMonitor().worked(30);
		getProgressMonitor().subTask("Finalizing share");

		// set attributes after server call
		getProgressMonitor().subTask("Setting attributes");
		this.setUsersession(getUsersession());
		WorkspaceManager.getObserverBus().register(getProjectSpace(), LoginObserver.class);

		Configuration.setAutoSave(Configuration.isAutoSaveEnabled());
		getProjectSpace().save();
		getProjectSpace().startChangeRecording();
		getProjectSpace().setBaseVersion(createdProject.getVersion());<commit_msg>disabled switching of autosave during share<commit_after>/*******************************************************************************
 * Copyright (c) 2008-2011 Chair for Applied Software Engineering,
 * Technische Universitaet Muenchen.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 * 
 * Contributors:
 ******************************************************************************/
package org.eclipse.emf.emfstore.client.model.controller;

import java.util.Date;

import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.emf.emfstore.client.common.UnknownEMFStoreWorkloadCommand;
import org.eclipse.emf.emfstore.client.model.Usersession;
import org.eclipse.emf.emfstore.client.model.WorkspaceManager;
import org.eclipse.emf.emfstore.client.model.connectionmanager.ServerCall;
import org.eclipse.emf.emfstore.client.model.impl.ProjectSpaceBase;
import org.eclipse.emf.emfstore.client.model.observers.LoginObserver;
import org.eclipse.emf.emfstore.client.model.observers.ShareObserver;
import org.eclipse.emf.emfstore.server.exceptions.EmfStoreException;
import org.eclipse.emf.emfstore.server.model.ProjectInfo;
import org.eclipse.emf.emfstore.server.model.versioning.LogMessage;
import org.eclipse.emf.emfstore.server.model.versioning.VersioningFactory;

/**
 * Shares a project.
 * 
 * @author ovonwesen
 * @author emueller
 */
public class ShareController extends ServerCall<Void> {

	/**
	 * Constructor.
	 * 
	 * @param projectSpace
	 *            the project space to be shared
	 * @param session
	 *            the session to use during share
	 * @param monitor
	 *            a progress monitor that is used to indicate the progress of the share
	 */
	public ShareController(ProjectSpaceBase projectSpace, Usersession session, IProgressMonitor monitor) {
		super(projectSpace);

		// if session is null, session will be injected by sessionmanager
		setUsersession(session);
		setProgressMonitor(monitor);
	}

	@Override
	protected Void run() throws EmfStoreException {
		doRun();
		return null;
	}

	@SuppressWarnings("unchecked")
	private void doRun() throws EmfStoreException {

		getProgressMonitor().beginTask("Sharing Project", 100);
		getProgressMonitor().worked(1);
		getProgressMonitor().subTask("Preparing project for sharing");

		final LogMessage logMessage = VersioningFactory.eINSTANCE.createLogMessage();
		logMessage.setAuthor(getUsersession().getUsername());
		logMessage.setClientDate(new Date());
		logMessage.setMessage("Initial commit");
		ProjectInfo createdProject = null;

		getProjectSpace().stopChangeRecording();

		getProgressMonitor().worked(10);
		if (getProgressMonitor().isCanceled()) {
			getProjectSpace().save();
			getProjectSpace().startChangeRecording();
			getProgressMonitor().done();
		}
		getProgressMonitor().subTask("Sharing project with server");

		// make sure, current state of caches is written to resource
		getProjectSpace().save();

		createdProject = new UnknownEMFStoreWorkloadCommand<ProjectInfo>(getProgressMonitor()) {
			@Override
			public ProjectInfo run(IProgressMonitor monitor) throws EmfStoreException {
				return WorkspaceManager
					.getInstance()
					.getConnectionManager()
					.createProject(
						getUsersession().getSessionId(),
						getProjectSpace().getProjectName() == null ? "Project@" + new Date() : getProjectSpace()
							.getProjectName(),
						getProjectSpace().getProjectDescription() == null ? "" : getProjectSpace()
							.getProjectDescription(), logMessage, getProjectSpace().getProject());
			}
		}.execute();

		getProgressMonitor().worked(30);
		getProgressMonitor().subTask("Finalizing share");

		// set attributes after server call
		getProgressMonitor().subTask("Setting attributes");
		this.setUsersession(getUsersession());
		WorkspaceManager.getObserverBus().register(getProjectSpace(), LoginObserver.class);

		getProjectSpace().save();
		getProjectSpace().startChangeRecording();
		getProjectSpace().setBaseVersion(createdProject.getVersion());
{'fraction_non_alphanumeric': 0.14366197183098592, 'fraction_numerical': 0.004694835680751174, 'mean_word_length': 5.321216617210682, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2149930', 'n_tokens_mistral': 2522, 'n_tokens_neox': 2253, 'n_words': 485}