Collaborative API Overview

The main purpose of Sirius collaborative features is to allow users to collaborate in real-time around semantic models and representations. Although Sirius provides default behavior and UI for collaboration, you are totally free to use Sirius as a platform and build your own features upon it, or customize existing behaviors.

The following documentation will give you an overview of the Collaborative API provided by Sirius. Feel free to consult the common collaborative use case documentation and the advanced collaborative use case documentation to see examples of Collaborative features use and customization.

1. Collaborative Plugins hierarchy

Sirius collaborative features are based on the CDO technology (please refer to CDO documentation for additional information).

These features are defined in the following plugins:

  • The fr.obeo.dsl.viewpoint.collab plugin contains all the non-UI collaborative behavior (API for connecting to CDO Repositories, lock/unlock elements, customize authentication and lock strategies…).

  • The fr.obeo.dsl.viewpoint.collab.ui plugin contains all UI related to collaborative features (decoration of locked elements, Lock/Unlock Actions, Collaborative Wizards…).

  • The fr.obeo.dsl.viewpoint.collab.ui.diagram, fr.obeo.dsl.viewpoint.collab.ui.table and fr.obeo.dsl.viewpoint.collab.ui.tree plugins contain all UI specific to each kind of representation.

The user profile optional feature is defined in the following set of optional plugins:

  • The fr.obeo.dsl.viewpoint.collab.user.profile plugin contains a metamodel extension of the security metamodel from CDO to define ConcreteObjectPermission. This plugin also contains the viewpoint collaborative specific user profile manager defined by collab and the user profile model import/export API as explained below.

  • The fr.obeo.dsl.viewpoint.collab.user.profile.edit plugin is the edit part of the user profile metamodel. It contains the icons, label and content providers.

  • The fr.obeo.dsl.viewpoint.collab.ui.user.profile.design plugin contains the user profile model editor and import/export wizards as shown in Collaborative Modeling Administrator

Viewpoint also provides a Collaborative Test Framework through the fr.obeo.dsl.viewpoint.tests.collab.* plugins.

2. API overview

2.1. The CollaborativeSession interface: additional behavior for a SiriusSession

The fr.obeo.dsl.viewpoint.collab.api.remotesession.CollaborativeSession interface represents any Sirius Session able to reference semantic resources or representations located on a remote CDO Repository.

When the collaborative mode is active (i.e. if CDOSiriusPreferenceKeys.COLLABORATIVE_MODE_ACTIVATED is true), all Sirius Sessions created by calling org.eclipse.sirius.business.api.session.factory.SessionFactory or through the org.eclipse.sirius.business.api.session.SessionManager will implement this interface.

This interface provides collaborative behavior for Sirius sessions.

2.1.1. Connect a Collaborative Session to a CDO Repository

You will be able to connect a Collaborative Session to a CDO repository. This will create a new CDOTransaction on the described repository. Consequently, when the user tries to add a remote CDO model or representation to this session, the repository location will be pre-filled.

Notice that as soon as a Remote Semantic Resource or Representation is referenced by the Collaborative Session, the session will connect itself to the corresponding CDO Repository. So you should use the connect(RepositoryConfig) method only if you want a Collaborative Session to be connected by default (even if empty) to a certain repository.

// Step 1: create the RepositoryConfig describing my repository location
RepositoryConfig repositoryConfig = CDOConfigFactory.eINSTANCE.createRepositoryConfig();
repositoryConfig.setHostLocation("localhost:2036");
repositoryConfig.setRepositoryName("myRepo");

// Step 2: connect my Session to this repository
session.connect(repositoryConfig);

2.1.2. Get the CDORepositoryManager associated to a Collaborative Session

If a Collaborative Session has been connected (explicitly or automatically) to a CDO Repository, you can easily get the RepositoryManager associated to this session: simply call session.getRepositoryManager().

2.1.3. Customize the behavior of the Save action

When a user saves his session, if the modifications are impacting elements located on a CDO Repository, we can:

  • Commit the modifications on the repository

  • Save the modifications locally inside a file (please refer to the documentation of CDOPushTransaction for additional information). Such modifications saved locally will be kept local until the user actually commits them.

The default behavior is to check the Collaborative preferences:

Thanks to the session.setCommitOnSave(boolean) method, you can specify whether the next call to session.save() will commit the changes (if the parameter is true) or same them locally (if false).

Notice that committing changes or saving them locally has an impact on lock releasing.

2.1.4. Define where new representations should be created

The session.setDefaultRepresentationContainer(URI danalysisURI) method allows you to specify in which DAnalysis new representations should be stored. Using this method, you can force all new representations to be created on the repository.

// Step 1: get all the Remote DAnalysis associated to our current session
Iterable<CDOResource> remoteDAnalyses = Iterables.filter(collaborativeSession.getAllSessionResources(), CDOResource.class);

// Step 2: we say that all new representations should be created
// in the first Remote DAnalysis we found
if (remoteDAnalyses.iterator().hasNext()){
	collaborativeSession.setDefaultRepresentationContainer(remoteDAnalyses.iterator().next().getURI());
}

2.2. The CDORepositoryManager: handles the CDOTransactions and CDOSessions lifecycle

2.2.1. Overview

The fr.obeo.dsl.viewpoint.collab.api.CDORepositoryManager handles the lifecycle of CDOTransactions and CDOSessions. You should not open your own CDOTransactions, but rely on the CDORepositoryManager to do so.

The fundamental rules of the CDORepositoryManager are:

  • There is only one CDORepositoryManager per CDORepository

  • There is only one CDOSession per CDORepository

  • It internally handles the lifecycle of the CDOSessions

2.2.2. Dealing with Exception

Each CDORepositoryManager provides, through the getRemoteExceptionHandler() method, a ISiriusRemoteExceptionHandler used to deal with Remote Exceptions (such as Network Breakdown, invalid credentials…).

You can provide your own ISiriusRemoteExceptionHandler through the fr.obeo.dsl.viewpoint.collab.exceptionhandler extension point. It is advised to extend the UISiriusRemoteExceptionHandler and call the super implementation in all overridden methods, to benefit from the default behavior.

2.2.3. The CDORepositoryManagerRegistry: handles CDORepositoryManager life-cycles

The fr.obeo.dsl.viewpoint.collab.api.CDORepositoryManagerRegistry is in charge of creating and deleting CDORepositoryManager when needed.

2.2.4. Get the CDOTransaction associated to a Collaborative Session

You can get the CDOTransaction associated to a Collaborative session:

// Step 1: get the CDORepositoryManager
// using the repository configuration
CDORepositoryManager manager = CDORepositoryManagerRegistry.getRepositoryManager(repositoryConfig);

// using directly the session:
CDORepositoryManager manager = CDORepositoryManagerRegistry.getRepositoryManager(session);
// or
CDORepositoryManager manager = session.getRepositoryManager();

// Step 2: get the CDOTransaction associated to the session
CDOTransaction transaction = manager.getOrCreateTransaction(session);

2.2.5. Open and close CDOTransactions

Notice that the CDORepositoryManager already handles CDOTransactions lifecycle: CDOTransactions are opened when a Collaborative Session referencing a CDORepository is opened and close when this session is closed.

However, you may need to open or close CDOTransactions that are not linked to any viewpoint session, to make some modifications to the CDO Repository.

// Step 1: creating a resource set for my transaction
ResourceSet rs = new ResourceSetImpl();

// Step 2: open a transaction on this resourceSet
CDORepositoryManager manager = CDORepositoryManagerRegistry.getRepositoryManager(config);
CDOTransaction transaction = manager.getOrCreateTransaction(rs);

// Step 3: using the transaction to modify the repository content
transaction.getOrCreateResource("myNewResource");
transaction.commit();

// Step 4: close the transaction
// this will also close the CDOSession
// and dispose the CDORepositoryManager
manager.closeTransaction(transaction);

2.3. The CDOLockManager: allows locking and unlocking elements

2.3.1. Get the lock status of remote elements

The CDOLockManager allows you to determine whether an element is:

  • locked by me (i.e., the current user has placed a CDOWriteLock on it)

  • locked by others (i.e., any other user has placed a CDOWriteLock on it)

  • unlocked (locked by no one)

You can use the boolean isLockedByOthers(EObject element), boolean isLockedByAny and boolean isUnlocked(EObject element) methods to determine the lock status of an element.

2.3.2. Explicit locking

An explicit lock is a lock placed explicitly on remote elements (by the user through an Action or programmatically). Such locks are not released when the Transaction gets committed (contrary to Implicit locks).

If the CDOSiriusPreferenceKeys.PREF_ENABLE_DURABLE_LOCKING is true, then the locks will be persistent, event if the Collaborative Session is closed. They will last until the user explicitly unlocks the locked elements (through an Action or programmatically).

An explicit lock can be performed recursively (i.e., all the children of locked elements are also locked). Notice that you can lock both semantic or graphical elements (DDiagrams, DTree items, DLines of a DTable…).

// Step 1: getting a remote semantic element
EObject rootElementToLock = session.getSemanticResources().iterator().next().getContents().get(0);
Collection<EObject> elementsToLock = Lists.newArrayList(rootElementToLock);

// Step 2: locking the element and all its children
CDOLockManager.INSTANCE.acquireLock(elementsToLock, true, true);

// Element is now locked:
// CDOLockManager.INSTANCE.isLockedByMe(rootElementToLock)     : true
// CDOLockManager.INSTANCE.isLockedByOthers(rootElementToLock) : false
// CDOLockManager.INSTANCE.isUnlocked(rootElementToLock)       : false

// Step 3: unlocking the element and all its children
CDOLockManager.INSTANCE.releaseExplicitLocks(elementsToLock, true);

// Element is now unlocked:
// CDOLockManager.INSTANCE.isLockedByMe(rootElementToLock)     : false
// CDOLockManager.INSTANCE.isLockedByOthers(rootElementToLock) : false
// CDOLockManager.INSTANCE.isUnlocked(rootElementToLock)       : true

2.3.3. Implicit locks: define your own lock strategies

Sirius relies on a pessimistic lock mechanism: any time a user makes a modification, all the elements impacted by this modification are automatically locked, to prevent from any conflict.

Such locks are called implicit locks, as they have been placed automatically. As their only purpose is to avoid conflicts, they are released when the user commits to the repository. Notice that if the save action should save local changes and not commit them, then implicit locks will not be released until a commit is performed.

To determine the elements to lock when a modification is made, Sirius uses a default lock strategy. The platform allows you to define your own lock strategies.

2.4. Upload and Download models

Sirius provide API for uploading and downloading models on/from the CDO Repository, through the fr.obeo.dsl.viewpoint.collab.api.CDOImporter and fr.obeo.dsl.viewpoint.collab.api.CDOExporter.

2.4.1. Upload a local model on the CDORepository

The Set<String> importLocalFilesOnRepository(Set<URI> urisOfLocalFilesToImport, CDORepositoryManager repositoryManager, boolean replaceExistingCDOResources, boolean exportWorkspaceImages, IProgressMonitor monitor) method of the CDOImporter allows you to upload a set of local models on a CDORepository.

2.4.2. Download a remote model locally

The Set<String> exportFilesFromRepository(Set<URI> resourceURIs, CDORepositoryManager repositoryManager, boolean replaceExistingResources, boolean importWorkspaceImages, IProgressMonitor monitor) method of the CDOExporter allows you to download a set of remote models inside the Eclipse workspace.

2.5. Customize authentication

Sirius API allows you to customize your authentication policy. If your CDOServer has an authentication mechanism, you may want to customize the way authentication is handled inside Sirius.

To do so, you can provide your own fr.obeo.dsl.viewpoint.collab.api.CDOAuthenticationManager and register it in the fr.obeo.dsl.viewpoint.collab.api.CDOAuthenticationManagerRegistry.

Please refer to the advanced collaborative use case documentation to get an example of authentication customization.

2.6. Import/Export user profile model

To import a user profile model from a CDO repository to a local user profile resource :

URI remoteUserProfileModelResourceURI = URI.createURI(CDONet4jUtil.PROTOCOL_TCP + "://<existing user login>:<password>@localhost:8080/repo1/users.userprofile");
URI localUserProfileModelResourceURI = URI.createPlatformResourceURI("/LocalProject/users.userprofile");
UserProfileModelImporter userProfileModelImporter = new UserProfileModelImporter(remoteUserProfileModelResourceURI, localUserProfileModelResourceURI);
UserProfileModelImporter.process(new NullProgressMonitor());

To export a local user profile model resource to a CDO repository :

URI remoteUserProfileModelResourceURI = URI.createURI(CDONet4jUtil.PROTOCOL_TCP + "://<existing user login>:<password>@localhost:8080/repo1/users.userProfile");
URI localUserProfileModelResourceURI = URI.createPlatformResourceURI("/LocalProject/users.userprofile");
UserProfileModelExporter userProfileModelExporter = new UserProfileModelExporter(localUserProfileModelResourceURI, remoteUserProfileModelResourceURI);
Diagnostic diagnostic = userProfileModelExporter.process(new NullProgressMonitor());

If the export fails, a Diagnostic is returned holding the cause of the failure.

2.7. Customize User Profile editor

It is possible to override the default implementation of creation, update and deletion of a user profile in the User Profile editor. You must use the extension point fr.obeo.dsl.viewpoint.collab.ui.user.profile.manager with an implementation of fr.obeo.dsl.viewpoint.collab.ui.user.profile.design.api.extension.IUserProfileManager.

3. Collaborative preferences

You can change the Collaborative preferences to customize Sirius behavior:

  • fr.obeo.dsl.viewpoint.collab.api.preferences.CDOSiriusPreferenceKeys.COLLABORATIVE_MODE_ACTIVATED: Set it to false will disable all Sirius Collaborative features. Users will not be able to connect to any CDO Repository.

  • fr.obeo.dsl.viewpoint.collab.api.preferences.CDOSiriusPreferenceKeys.PREF_ENABLE_DURABLE_LOCKING: Indicates whether explicit locks should be persistent, event if the Collaborative Session is closed. If true, the locks will last until the locked elements are explicitly unlocked. If false, they will be released anyway when the Collaborative Session is closed. This preference has impacts on save and commit decorellation.

  • fr.obeo.dsl.viewpoint.collab.api.preferences.CDOSiriusPreferenceKeys.PREF_ENABLE_SAVE_AND_COMMIT_DECORELATION: If false, then calling session.save() will always commit. If true, then the fr.obeo.dsl.viewpoint.collab.api.preferences.CDOSiriusPreferenceKeys.PREF_BY_DEFAULT_COMMIT_ON_SAVE preference will be considered if a commit should be performed.

  • fr.obeo.dsl.viewpoint.collab.api.preferences.CDOSiriusPreferenceKeys.PREF_BY_DEFAULT_COMMIT_ON_SAVE: Indicates if calling session.save() should commit the changes or save the changes locally. The user can modify this preference through the Collaborative preference page.

  • fr.obeo.dsl.viewpoint.collab.api.preferences.CDOSiriusPreferenceKeys.PREF_DEFAULT_REPOSITORY_NAME: The default repository name (for example 'repo1') that will be displayed to the user inside wizards.This preference can be modified by the user through the Collaborative preference page.

  • fr.obeo.dsl.viewpoint.collab.api.preferences.CDOSiriusPreferenceKeys.PREF_DEFAULT_REPOSITORY_LOCATION: The default repository location (for example 'localhost') that will be displayed to the user inside wizards.This preference can be modified by the user through the Collaborative preference page.

  • fr.obeo.dsl.viewpoint.collab.api.preferences.CDOSiriusPreferenceKeys.PREF_DEFAULT_REPOSITORY_PORT: The default repository location (for example, '2036') that will be displayed to the user inside wizards. The user can modify this preference through the Collaborative preference page.

If Permissions are activated and that you want to allow/forbid the creation of specific kind of Permission Rules inside the User Profiles Editor, you can use the following preferences:

  • fr.obeo.dsl.viewpoint.collab.ui.user.profile.design.preferences.AdminPermissionPreferenceKeys.PREF_ENABLE_CLASS_PERMISSION_CREATION allows allowing/forbidding the creation of org.eclipse.emf.cdo.security.ClassPermission,

  • fr.obeo.dsl.viewpoint.collab.ui.user.profile.design.preferences.AdminPermissionPreferenceKeys.PREF_ENABLE_PACKAGE_PERMISSION_CREATION allows allowing/forbidding the creation of org.eclipse.emf.cdo.security.PackagePermission,

  • fr.obeo.dsl.viewpoint.collab.ui.user.profile.design.preferences.AdminPermissionPreferenceKeys.PREF_ENABLE_OBJECT_PERMISSION_CREATION allows allowing/forbidding the creation of fr.obeo.dsl.viewpoint.collab.user.profile.ConcreteObjectPermission,

  • fr.obeo.dsl.viewpoint.collab.ui.user.profile.design.preferences.AdminPermissionPreferenceKeys.PREF_ENABLE_RESOURCE_PERMISSION_CREATION allows allowing/forbidding the creation of org.eclipse.emf.cdo.security.ResourcePermission.