Skip to content

Commit

Permalink
[241] Switch to EditingContextEventProcessor
Browse files Browse the repository at this point in the history
The ProjectEventProcessor and its registry have been made independent of Project.
It has also been renamed to EditingContextEventProcessor along with its registry.
Those concepts do not rely on a projectId but an editingContextId instead even if
in practice this variable still contain the value of projectId for now.

Bug: #241
Signed-off-by: Stéphane Bégaudeau <[email protected]>
  • Loading branch information
sbegaudeau committed Jan 18, 2021
1 parent 06daada commit bf84f51
Show file tree
Hide file tree
Showing 77 changed files with 435 additions and 505 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2019, 2020 Obeo.
* Copyright (c) 2019, 2021 Obeo.
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* which accompanies this distribution, and is available at
Expand All @@ -20,7 +20,7 @@
*
* @author sbegaudeau
*/
public interface IProjectEventHandler {
public interface IEditingContextEventHandler {
boolean canHandle(IInput input);

EventHandlerResponse handle(IEditingContext editingContext, IInput input);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
*
* @author sbegaudeau
*/
public interface IProjectEventProcessor {
UUID getProjectId();
public interface IEditingContextEventProcessor {
UUID getEditingContextId();

<T extends IRepresentationEventProcessor> Optional<T> acquireRepresentationEventProcessor(Class<T> representationEventProcessorClass, IRepresentationConfiguration configuration,
SubscriptionDescription subscriptionDescription);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,16 @@
import org.eclipse.sirius.web.core.api.IPayload;

/**
* Registry of all the project event handlers.
* Registry of all the editing context event handlers.
*
* @author sbegaudeau
*/
public interface IProjectEventProcessorRegistry {
List<IProjectEventProcessor> getProjectEventProcessors();
public interface IEditingContextEventProcessorRegistry {
List<IEditingContextEventProcessor> getEditingContextEventProcessors();

Optional<IPayload> dispatchEvent(UUID projectId, IInput input);
Optional<IPayload> dispatchEvent(UUID editingContextId, IInput input);

Optional<IProjectEventProcessor> getOrCreateProjectEventProcessor(UUID projectId);
Optional<IEditingContextEventProcessor> getOrCreateEditingContextEventProcessor(UUID editingContextId);

void dispose(UUID projectId);
void dispose(UUID editingContextId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import java.util.UUID;

/**
* Information used to perform some operations on the project.
* Used to contain the semantic data.
*
* @author sbegaudeau
*/
Expand All @@ -26,7 +26,7 @@ public interface IEditingContext {
*/
String EDITING_CONTEXT = "editingContext"; //$NON-NLS-1$

UUID getProjectId();
UUID getId();

Object getDomain();
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,11 @@
*******************************************************************************/
package org.eclipse.sirius.web.core.api;

import java.util.UUID;

/**
* Interface used to save the editing context when a change has been performed.
*
* @author sbegaudeau
*/
public interface IEditingContextPersistenceService {
void persist(UUID projectId, IEditingContext editingContext);
void persist(IEditingContext editingContext);
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2019, 2020 Obeo.
* Copyright (c) 2021 THALES GLOBAL SERVICES.
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* which accompanies this distribution, and is available at
Expand All @@ -12,13 +12,18 @@
*******************************************************************************/
package org.eclipse.sirius.web.core.api;

import java.util.Optional;
import java.util.UUID;

/**
* Service used to create the editing context of a project.
* Interface used to determine if an editing context exist and to retrieve it.
*
* @author sbegaudeau
*/
public interface IEditingContextFactory {
IEditingContext createEditingContext(UUID projectId);
public interface IEditingContextSearchService {

boolean existsById(UUID editingContextId);

Optional<IEditingContext> findById(UUID editingContextId);

}
4 changes: 4 additions & 0 deletions backend/sirius-web-emf/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-core</artifactId>
</dependency>
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-core</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import org.eclipse.sirius.emfjson.resource.JsonResource;
import org.eclipse.sirius.web.api.configuration.StereotypeDescription;
import org.eclipse.sirius.web.collaborative.api.services.EventHandlerResponse;
import org.eclipse.sirius.web.collaborative.api.services.IProjectEventHandler;
import org.eclipse.sirius.web.collaborative.api.services.IEditingContextEventHandler;
import org.eclipse.sirius.web.collaborative.api.services.Monitoring;
import org.eclipse.sirius.web.core.api.ErrorPayload;
import org.eclipse.sirius.web.core.api.IEditingContext;
Expand All @@ -49,7 +49,7 @@
* @author sbegaudeau
*/
@Service
public class CreateDocumentEventHandler implements IProjectEventHandler {
public class CreateDocumentEventHandler implements IEditingContextEventHandler {

private final Logger logger = LoggerFactory.getLogger(CreateDocumentEventHandler.class);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.emf.edit.domain.AdapterFactoryEditingDomain;
import org.eclipse.sirius.web.collaborative.api.services.EventHandlerResponse;
import org.eclipse.sirius.web.collaborative.api.services.IProjectEventHandler;
import org.eclipse.sirius.web.collaborative.api.services.IEditingContextEventHandler;
import org.eclipse.sirius.web.collaborative.api.services.Monitoring;
import org.eclipse.sirius.web.core.api.ErrorPayload;
import org.eclipse.sirius.web.core.api.IEditingContext;
Expand All @@ -43,7 +43,7 @@
* @author sbegaudeau
*/
@Service
public class DeleteDocumentEventHandler implements IProjectEventHandler {
public class DeleteDocumentEventHandler implements IEditingContextEventHandler {

private final IDocumentService documentService;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public EditingContext(UUID projectId, EditingDomain editingDomain) {
}

@Override
public UUID getProjectId() {
public UUID getId() {
return this.projectId;
}

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -66,15 +66,15 @@ public EditingContextPersistenceService(IDocumentRepository documentRepository,
}

@Override
public void persist(UUID projectId, IEditingContext editingContext) {
public void persist(IEditingContext editingContext) {
long start = System.currentTimeMillis();

Object domain = editingContext.getDomain();
if (domain instanceof EditingDomain) {
EditingDomain editingDomain = (EditingDomain) domain;
List<DocumentEntity> documentEntities = this.persist(editingDomain);
List<Document> documents = documentEntities.stream().map(new DocumentMapper()::toDTO).collect(Collectors.toList());
this.applicationEventPublisher.publishEvent(new DocumentsModifiedEvent(projectId, documents));
this.applicationEventPublisher.publishEvent(new DocumentsModifiedEvent(editingContext.getId(), documents));
}
// @formatter:off
var optionalDocuments = Optional.ofNullable(editingContext)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2019, 2020 Obeo.
* Copyright (c) 2021 Obeo.
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* which accompanies this distribution, and is available at
Expand All @@ -17,6 +17,7 @@
import java.text.MessageFormat;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.UUID;
import java.util.concurrent.TimeUnit;

Expand All @@ -30,27 +31,31 @@
import org.eclipse.emf.edit.provider.ComposedAdapterFactory;
import org.eclipse.sirius.emfjson.resource.JsonResource;
import org.eclipse.sirius.web.core.api.IEditingContext;
import org.eclipse.sirius.web.core.api.IEditingContextFactory;
import org.eclipse.sirius.web.core.api.IEditingContextSearchService;
import org.eclipse.sirius.web.persistence.entities.DocumentEntity;
import org.eclipse.sirius.web.persistence.repositories.IDocumentRepository;
import org.eclipse.sirius.web.persistence.repositories.IProjectRepository;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Service;

import io.micrometer.core.instrument.MeterRegistry;
import io.micrometer.core.instrument.Timer;

/**
* Service used to create a new editing context.
* Service used to find and retrieve editing contexts.
*
* @author sbegaudeau
*/
@Service
public class EditingContextFactory implements IEditingContextFactory {
public class EditingContextSearchService implements IEditingContextSearchService {

private static final String TIMER_NAME = "siriusweb_editingcontext_load"; //$NON-NLS-1$

private final Logger logger = LoggerFactory.getLogger(EditingContextFactory.class);
private final Logger logger = LoggerFactory.getLogger(EditingContextSearchService.class);

private final IProjectRepository projectRepository;

private final IDocumentRepository documentRepository;

Expand All @@ -60,7 +65,9 @@ public class EditingContextFactory implements IEditingContextFactory {

private final Timer timer;

public EditingContextFactory(IDocumentRepository documentRepository, ComposedAdapterFactory composedAdapterFactory, EPackage.Registry ePackageRegistry, MeterRegistry meterRegistry) {
public EditingContextSearchService(IProjectRepository projectRepository, IDocumentRepository documentRepository, ComposedAdapterFactory composedAdapterFactory, EPackage.Registry ePackageRegistry,
MeterRegistry meterRegistry) {
this.projectRepository = Objects.requireNonNull(projectRepository);
this.documentRepository = Objects.requireNonNull(documentRepository);
this.composedAdapterFactory = Objects.requireNonNull(composedAdapterFactory);
this.ePackageRegistry = Objects.requireNonNull(ePackageRegistry);
Expand All @@ -69,14 +76,20 @@ public EditingContextFactory(IDocumentRepository documentRepository, ComposedAda
}

@Override
public IEditingContext createEditingContext(UUID projectId) {
public boolean existsById(UUID editingContextId) {
String username = SecurityContextHolder.getContext().getAuthentication().getName();
return this.projectRepository.existsByIdAndIsVisibleBy(editingContextId, username);
}

@Override
public Optional<IEditingContext> findById(UUID editingContextId) {
long start = System.currentTimeMillis();

this.logger.debug(MessageFormat.format("Loading the editing context of the project \"{0}\"", projectId)); //$NON-NLS-1$
this.logger.debug(MessageFormat.format("Loading the editing context \"{0}\"", editingContextId)); //$NON-NLS-1$
ResourceSet resourceSet = new ResourceSetImpl();
resourceSet.setPackageRegistry(this.ePackageRegistry);

List<DocumentEntity> documentEntities = this.documentRepository.findAllByProjectId(projectId);
List<DocumentEntity> documentEntities = this.documentRepository.findAllByProjectId(editingContextId);
for (DocumentEntity documentEntity : documentEntities) {
URI uri = URI.createURI(documentEntity.getId().toString());
JsonResource resource = new SiriusWebJSONResourceFactoryImpl().createResource(uri);
Expand All @@ -91,12 +104,12 @@ public IEditingContext createEditingContext(UUID projectId) {
}

EditingDomain editingDomain = new AdapterFactoryEditingDomain(this.composedAdapterFactory, new BasicCommandStack(), resourceSet);
this.logger.debug(MessageFormat.format("{0} documents loaded for the project \"{1}\"", documentEntities.size(), projectId)); //$NON-NLS-1$
this.logger.debug(MessageFormat.format("{0} documents loaded for the editing context \"{1}\"", documentEntities.size(), editingContextId)); //$NON-NLS-1$

long end = System.currentTimeMillis();
this.timer.record(end - start, TimeUnit.MILLISECONDS);

return new EditingContext(projectId, editingDomain);
return Optional.of(new EditingContext(editingContextId, editingDomain));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.emf.edit.domain.AdapterFactoryEditingDomain;
import org.eclipse.sirius.web.collaborative.api.services.EventHandlerResponse;
import org.eclipse.sirius.web.collaborative.api.services.IProjectEventHandler;
import org.eclipse.sirius.web.collaborative.api.services.IEditingContextEventHandler;
import org.eclipse.sirius.web.collaborative.api.services.Monitoring;
import org.eclipse.sirius.web.core.api.ErrorPayload;
import org.eclipse.sirius.web.core.api.IEditingContext;
Expand All @@ -40,7 +40,7 @@
* @author fbarbin
*/
@Service
public class RenameDocumentEventHandler implements IProjectEventHandler {
public class RenameDocumentEventHandler implements IEditingContextEventHandler {

private final IDocumentService documentService;

Expand Down
Loading

0 comments on commit bf84f51

Please sign in to comment.