Skip to content

Commit

Permalink
[2889] Stop loading every view models anytime we need to query them
Browse files Browse the repository at this point in the history
Bug: #2889
Signed-off-by: Stéphane Bégaudeau <stephane.begaudeau@obeo.fr>
  • Loading branch information
sbegaudeau committed Jan 9, 2024
1 parent 9053f7a commit 726cca4
Show file tree
Hide file tree
Showing 27 changed files with 180 additions and 228 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.adoc
Expand Up @@ -76,6 +76,9 @@ The GraphQL type `NodeDescription` has a new field `childNodeDescriptionIds`, re
The GraphQL type `NodeDescription` has a new field `borderNodeDescriptionIds`, returning a list of Ids and replacing the field `borderNodeDescriptions` which has been deleted.
- https://github.com/eclipse-sirius/sirius-web/issues/2872[#2872] [diagram] Change the signature of the node converters in order to leverage the diagram description to resolve the reuse descriptions.
Additional changes to this interface will propably occur in the near future in order to support more complex use cases.
- https://github.com/eclipse-sirius/sirius-web/issues/2889[#2889] [emf] Remove the default implementation of the editing context from the `sirius-components-emf` module.
The default implementation of the editing context for Sirius Web, which had Sirius Web specific code already, will be owned by `sirius-web-services`.
This default implementation will now also contain all the view models properly loaded which should be considered during the lifecycle of the editing context.

=== Dependency update

Expand Down Expand Up @@ -142,6 +145,9 @@ This is a preliminary work to add some proper support for outside labels in the
- https://github.com/eclipse-sirius/sirius-web/issues/2889[#2889] [emf] Add the `IEMFEditingContext` interface in order to let any editing context be an EMF aware one.
After this change, we will be able to delete the `EditingContext` class from `sirius-components-emf` and add new interfaces to describe the various capabilities of an editing context.
Among those capabilities, we should find the list of view models to consider during the lifecycle of the editing context.
- https://github.com/eclipse-sirius/sirius-web/issues/2889[#2889] [view] Load view models only once during the lifecycle of the editing context.
This change makes the editing context the single source of truth for the state of the view models.


== v2023.12.0

Expand Down
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2023 Obeo.
* Copyright (c) 2023, 2024 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 Down Expand Up @@ -43,7 +43,7 @@
import org.eclipse.sirius.components.core.services.ComposedObjectService;
import org.eclipse.sirius.components.emf.services.DefaultObjectService;
import org.eclipse.sirius.components.emf.services.EMFKindService;
import org.eclipse.sirius.components.emf.services.EditingContext;
import org.eclipse.sirius.web.services.editingcontext.EditingContext;
import org.eclipse.sirius.components.emf.services.IDAdapter;
import org.eclipse.sirius.components.emf.services.LabelFeatureProviderRegistry;
import org.eclipse.sirius.components.emf.utils.EMFResourceUtils;
Expand Down Expand Up @@ -100,7 +100,7 @@ public void setup() {

editingDomain.setAdapterFactory(this.composedAdapterFactory);
editingDomain.getResourceSet().getPackageRegistry().put(FlowPackage.eNS_URI, FlowPackage.eINSTANCE);
this.editingContext = new EditingContext(UUID.randomUUID().toString(), editingDomain, Map.of());
this.editingContext = new EditingContext(UUID.randomUUID().toString(), editingDomain, Map.of(), List.of());

this.system = FlowFactory.eINSTANCE.createSystem();
this.system.setName("Robot");
Expand Down
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2022, 2023 Obeo.
* Copyright (c) 2022, 2024 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 Down Expand Up @@ -44,7 +44,7 @@
import org.eclipse.sirius.components.core.services.ComposedObjectService;
import org.eclipse.sirius.components.emf.services.DefaultObjectService;
import org.eclipse.sirius.components.emf.services.EMFKindService;
import org.eclipse.sirius.components.emf.services.EditingContext;
import org.eclipse.sirius.web.services.editingcontext.EditingContext;
import org.eclipse.sirius.components.emf.services.LabelFeatureProviderRegistry;
import org.eclipse.sirius.components.emf.services.messages.IEMFMessageService;
import org.eclipse.sirius.components.emf.utils.EMFResourceUtils;
Expand Down Expand Up @@ -104,7 +104,7 @@ public void setup() {

this.editingDomain.setAdapterFactory(composedAdapterFactory);
this.editingDomain.getResourceSet().getPackageRegistry().put(FlowPackage.eNS_URI, FlowPackage.eINSTANCE);
this.editingContext = new EditingContext(UUID.randomUUID().toString(), this.editingDomain, Map.of());
this.editingContext = new EditingContext(UUID.randomUUID().toString(), this.editingDomain, Map.of(), List.of());

this.view = this.loadFixture("ViewCompletionFixture.xmi");

Expand Down

This file was deleted.

@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2019, 2023 Obeo.
* Copyright (c) 2019, 2024 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 @@ -10,14 +10,16 @@
* Contributors:
* Obeo - initial API and implementation
*******************************************************************************/
package org.eclipse.sirius.components.emf.services;
package org.eclipse.sirius.web.services.editingcontext;

import java.util.List;
import java.util.Map;
import java.util.Objects;

import org.eclipse.emf.edit.domain.AdapterFactoryEditingDomain;
import org.eclipse.sirius.components.emf.services.api.IEMFEditingContext;
import org.eclipse.sirius.components.representations.IRepresentationDescription;
import org.eclipse.sirius.components.view.View;

/**
* Implementation of the editing context.
Expand All @@ -32,10 +34,13 @@ public class EditingContext implements IEMFEditingContext {

private final Map<String, IRepresentationDescription> representationDescriptions;

public EditingContext(String id, AdapterFactoryEditingDomain editingDomain, Map<String, IRepresentationDescription> representationDescriptions) {
private final List<View> views;

public EditingContext(String id, AdapterFactoryEditingDomain editingDomain, Map<String, IRepresentationDescription> representationDescriptions, List<View> views) {
this.id = Objects.requireNonNull(id);
this.editingDomain = Objects.requireNonNull(editingDomain);
this.representationDescriptions = Objects.requireNonNull(representationDescriptions);
this.views = Objects.requireNonNull(views);
}

@Override
Expand All @@ -52,4 +57,8 @@ public Map<String, IRepresentationDescription> getRepresentationDescriptions() {
return this.representationDescriptions;
}

public List<View> getViews() {
return this.views;
}

}
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2021, 2023 Obeo.
* Copyright (c) 2021, 2024 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 @@ -21,26 +21,29 @@
import java.util.Optional;
import java.util.concurrent.TimeUnit;

import org.eclipse.emf.ecore.EPackage;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.emf.ecore.util.BasicExtendedMetaData;
import org.eclipse.emf.edit.domain.AdapterFactoryEditingDomain;
import org.eclipse.emf.edit.domain.EditingDomain;
import org.eclipse.sirius.components.core.api.IEditingContext;
import org.eclipse.sirius.components.core.api.IEditingContextSearchService;
import org.eclipse.sirius.components.core.configuration.IRepresentationDescriptionRegistryConfigurer;
import org.eclipse.sirius.components.emf.ResourceMetadataAdapter;
import org.eclipse.sirius.components.emf.services.EditingContext;
import org.eclipse.sirius.components.emf.services.EditingContextCrossReferenceAdapter;
import org.eclipse.sirius.components.emf.services.JSONResourceFactory;
import org.eclipse.sirius.components.representations.IRepresentationDescription;
import org.eclipse.sirius.components.view.View;
import org.eclipse.sirius.components.view.emf.IViewConverter;
import org.eclipse.sirius.components.view.util.services.ColorPaletteService;
import org.eclipse.sirius.emfjson.resource.JsonResource;
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.eclipse.sirius.web.services.api.id.IDParser;
import org.eclipse.sirius.web.services.editingcontext.api.IDynamicRepresentationDescriptionService;
import org.eclipse.sirius.web.services.editingcontext.api.IEditingDomainFactoryService;
import org.eclipse.sirius.web.services.editingcontext.api.IViewLoader;
import org.eclipse.sirius.web.services.representations.RepresentationDescriptionRegistry;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -69,24 +72,27 @@ public class EditingContextSearchService implements IEditingContextSearchService

private final List<IRepresentationDescriptionRegistryConfigurer> configurers;

private final IDynamicRepresentationDescriptionService dynamicRepresentationDescriptionService;
private final IViewLoader viewLoader;

private final IViewConverter viewConverter;

private final Timer timer;

public EditingContextSearchService(IProjectRepository projectRepository, IDocumentRepository documentRepository, IEditingDomainFactoryService editingDomainFactoryService,
List<IRepresentationDescriptionRegistryConfigurer> configurers, IDynamicRepresentationDescriptionService dynamicRepresentationDescriptionService, MeterRegistry meterRegistry) {
List<IRepresentationDescriptionRegistryConfigurer> configurers, IViewLoader viewLoader, IViewConverter viewConverter, MeterRegistry meterRegistry) {
this.projectRepository = Objects.requireNonNull(projectRepository);
this.documentRepository = Objects.requireNonNull(documentRepository);
this.editingDomainFactoryService = Objects.requireNonNull(editingDomainFactoryService);
this.configurers = Objects.requireNonNull(configurers);
this.dynamicRepresentationDescriptionService = Objects.requireNonNull(dynamicRepresentationDescriptionService);
this.viewLoader = Objects.requireNonNull(viewLoader);
this.viewConverter = Objects.requireNonNull(viewConverter);

this.timer = Timer.builder(TIMER_NAME).register(meterRegistry);
}

@Override
public boolean existsById(String editingContextId) {
return new IDParser().parse(editingContextId).map(editingContextUUID -> this.projectRepository.existsById(editingContextUUID)).orElse(false);
return new IDParser().parse(editingContextId).map(this.projectRepository::existsById).orElse(false);
}

@Override
Expand Down Expand Up @@ -126,17 +132,36 @@ public Optional<IEditingContext> findById(String editingContextId) {

this.logger.debug("{} documents loaded for the editing context {}", resourceSet.getResources().size(), editingContextId);

var views = this.viewLoader.load();
Map<String, IRepresentationDescription> representationDescriptions = this.getRepresentationDescriptions(editingDomain, views);

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

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

private Map<String, IRepresentationDescription> getRepresentationDescriptions(EditingDomain editingDomain, List<View> views) {
Map<String, IRepresentationDescription> representationDescriptions = new LinkedHashMap<>();
var registry = new RepresentationDescriptionRegistry();
this.configurers.forEach(configurer -> configurer.addRepresentationDescriptions(registry));
registry.getRepresentationDescriptions().forEach(representationDescription -> representationDescriptions.put(representationDescription.getId(), representationDescription));
this.dynamicRepresentationDescriptionService.findDynamicRepresentationDescriptions(editingContextId, editingDomain)

List<EPackage> accessibleEPackages = this.getAccessibleEPackages(editingDomain);
this.viewConverter.convert(views, accessibleEPackages).stream()
.filter(Objects::nonNull)
.forEach(representationDescription -> representationDescriptions.put(representationDescription.getId(), representationDescription));

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

private List<EPackage> getAccessibleEPackages(EditingDomain editingDomain) {
var packageRegistry = editingDomain.getResourceSet().getPackageRegistry();

return Optional.of(new EditingContext(editingContextId, editingDomain, representationDescriptions));
return packageRegistry.values().stream()
.filter(EPackage.class::isInstance)
.map(EPackage.class::cast)
.toList();
}

}
Expand Up @@ -17,7 +17,6 @@

import org.eclipse.sirius.components.core.api.IEditingContext;
import org.eclipse.sirius.components.core.api.IRepresentationDescriptionSearchService;
import org.eclipse.sirius.components.emf.services.EditingContext;
import org.eclipse.sirius.components.representations.IRepresentationDescription;
import org.springframework.stereotype.Service;

Expand Down
Expand Up @@ -37,6 +37,7 @@
import org.eclipse.sirius.web.services.editingcontext.api.IViewLoader;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.io.ClassPathResource;
import org.springframework.stereotype.Service;

Expand All @@ -52,25 +53,30 @@ public class ViewLoader implements IViewLoader {

private final EPackage.Registry ePackageRegistry;

private final boolean isStudioDefinitionEnabled;

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

public ViewLoader(IDocumentRepository documentRepository, EPackage.Registry ePackageRegistry) {
public ViewLoader(IDocumentRepository documentRepository, EPackage.Registry ePackageRegistry, @Value("${org.eclipse.sirius.web.features.studioDefinition:false}") boolean isStudioDefinitionEnabled) {
this.documentRepository = Objects.requireNonNull(documentRepository);
this.ePackageRegistry = Objects.requireNonNull(ePackageRegistry);
this.isStudioDefinitionEnabled = isStudioDefinitionEnabled;
}


@Override
public List<View> load() {
List<View> views = new ArrayList<>();

var resourceSet = this.createResourceSet();
this.loadStudioColorPalettes(resourceSet);
if (this.isStudioDefinitionEnabled) {
var resourceSet = this.createResourceSet();
this.loadStudioColorPalettes(resourceSet);

this.documentRepository.findAllByType(ViewPackage.eNAME, ViewPackage.eNS_URI).forEach(documentEntity -> {
Resource resource = this.loadDocument(documentEntity, resourceSet);
views.addAll(this.getViewDefinitions(resource).toList());
});
this.documentRepository.findAllByType(ViewPackage.eNAME, ViewPackage.eNS_URI).forEach(documentEntity -> {
Resource resource = this.loadDocument(documentEntity, resourceSet);
views.addAll(this.getViewDefinitions(resource).toList());
});
}

return views;
}
Expand Down

0 comments on commit 726cca4

Please sign in to comment.