Skip to content

Commit

Permalink
[4372] Use semantic_data_id as editing context id
Browse files Browse the repository at this point in the history
Bug: #4372
Signed-off-by: Michaël Charfadi <[email protected]>
  • Loading branch information
mcharfadi committed Jan 14, 2025
1 parent 8aeb563 commit 9406d58
Show file tree
Hide file tree
Showing 42 changed files with 473 additions and 205 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

=== Breaking changes

- https://github.com/eclipse-sirius/sirius-web/issues/4372[#4372] [sirius-web] The editing context id is now the semantic_data_id instead of the project_id

=== Dependency update

Expand Down Expand Up @@ -82,6 +83,7 @@ page[after]=MTYxODg2MTQ5NjYzMnwyMDEwOWY0MC00ODI1LTQxNmEtODZmNi03NTA4YWM0MmEwMjE&
page[size]=3` will ask for the 3 projects following the one identified by the URL of the page succeeding the page being requested `MTYxODg2MTQ5NjYzMnwyMDEwOWY0MC00ODI1LTQxNmEtODZmNi03NTA4YWM0MmEwMjE`.
Note that you can retrieve the URL of a page in the response header of `GET /api/rest/projects`.
Note that you may need to encode special characters like `[`(by `%5B`) and `]` (by `%5D`) in your requests.
- https://github.com/eclipse-sirius/sirius-web/issues/4372[#4372] [sirius-web] Lower the coupling between project and editing context, the editing context id is now the semantic_data_id instead of the project_id


== v2025.1.0
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2024 Obeo.
* Copyright (c) 2024, 2025 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 @@ -22,6 +22,7 @@

import graphql.execution.DataFetcherResult;
import graphql.schema.DataFetchingEnvironment;
import org.eclipse.sirius.web.domain.boundedcontexts.semanticdata.services.api.ISemanticDataSearchService;

/**
* Data fetcher for the field Project#currentEditingContext.
Expand All @@ -30,10 +31,17 @@
*/
@QueryDataFetcher(type = "Project", field = "currentEditingContext")
public class ProjectCurrentEditingContextDataFetcher implements IDataFetcherWithFieldCoordinates<DataFetcherResult<String>> {

private final ISemanticDataSearchService semanticDataSearchService;

public ProjectCurrentEditingContextDataFetcher(ISemanticDataSearchService semanticDataSearchService) {
this.semanticDataSearchService = semanticDataSearchService;
}

@Override
public DataFetcherResult<String> get(DataFetchingEnvironment environment) throws Exception {
ProjectDTO project = environment.getSource();
String editingContextId = project.id().toString();
String editingContextId = this.semanticDataSearchService.findByProjectId(project.id()).map(semanticData -> semanticData.getId().toString()).orElse("");
Map<String, Object> localContext = new HashMap<>();
localContext.put(LocalContextConstants.EDITING_CONTEXT_ID, editingContextId);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2024 Obeo.
* Copyright (c) 2024, 2025 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 @@ -12,14 +12,14 @@
*******************************************************************************/
package org.eclipse.sirius.web.application.editingcontext.services;

import java.util.Objects;

import org.eclipse.sirius.web.application.UUIDParser;
import org.eclipse.sirius.web.application.editingcontext.services.api.IEditingContextApplicationService;
import org.eclipse.sirius.web.domain.boundedcontexts.project.services.api.IProjectSearchService;
import org.eclipse.sirius.web.domain.boundedcontexts.semanticdata.services.api.ISemanticDataSearchService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Objects;

/**
* Used to interact with editing contexts.
*
Expand All @@ -28,17 +28,17 @@
@Service
public class EditingContextApplicationService implements IEditingContextApplicationService {

private final IProjectSearchService projectSearchService;
private final ISemanticDataSearchService semanticDataSearchService;

public EditingContextApplicationService(IProjectSearchService projectSearchService) {
this.projectSearchService = Objects.requireNonNull(projectSearchService);
public EditingContextApplicationService(ISemanticDataSearchService semanticDataSearchService) {
this.semanticDataSearchService = Objects.requireNonNull(semanticDataSearchService);
}

@Override
@Transactional(readOnly = true)
public boolean existsById(String editingContextId) {
return new UUIDParser().parse(editingContextId)
.map(this.projectSearchService::existsById)
.map(this.semanticDataSearchService::existsById)
.orElse(false);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2024 Obeo.
* Copyright (c) 2024, 2025 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 @@ -29,7 +29,6 @@
import org.eclipse.sirius.web.domain.boundedcontexts.semanticdata.services.api.ISemanticDataSearchService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.data.jdbc.core.mapping.AggregateReference;
import org.springframework.stereotype.Service;

/**
Expand Down Expand Up @@ -63,7 +62,7 @@ public EditingContextLoader(ISemanticDataSearchService semanticDataSearchService
public void load(EditingContext editingContext, UUID projectId) {
this.editingContextProcessors.forEach(processor -> processor.preProcess(editingContext));

this.semanticDataSearchService.findByProject(AggregateReference.to(projectId))
this.semanticDataSearchService.findById(UUID.fromString(editingContext.getId()))
.ifPresent(semanticData -> this.loadSemanticData(editingContext, semanticData));

this.representationDescriptionProviders.forEach(representationDescriptionProvider -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.UUID;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;

Expand All @@ -28,8 +27,9 @@
import org.eclipse.sirius.web.application.editingcontext.services.api.IEditingContextMigrationParticipantPredicate;
import org.eclipse.sirius.web.application.editingcontext.services.api.IEditingContextPersistenceFilter;
import org.eclipse.sirius.web.application.editingcontext.services.api.IResourceToDocumentService;
import org.eclipse.sirius.web.domain.boundedcontexts.project.Project;
import org.eclipse.sirius.web.domain.boundedcontexts.project.services.api.IProjectSearchService;
import org.eclipse.sirius.web.domain.boundedcontexts.semanticdata.Document;
import org.eclipse.sirius.web.domain.boundedcontexts.semanticdata.services.api.ISemanticDataSearchService;
import org.eclipse.sirius.web.domain.boundedcontexts.semanticdata.services.api.ISemanticDataUpdateService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -58,15 +58,22 @@ public class EditingContextPersistenceService implements IEditingContextPersiste

private final List<IEditingContextMigrationParticipantPredicate> migrationParticipantPredicates;

private final ISemanticDataSearchService semanticDataSearchService;

private final IProjectSearchService projectSearchService;


private final Timer timer;

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

public EditingContextPersistenceService(ISemanticDataUpdateService semanticDataUpdateService, IResourceToDocumentService resourceToDocumentService, List<IEditingContextPersistenceFilter> persistenceFilters, List<IEditingContextMigrationParticipantPredicate> migrationParticipantPredicates, MeterRegistry meterRegistry) {
public EditingContextPersistenceService(ISemanticDataUpdateService semanticDataUpdateService, IResourceToDocumentService resourceToDocumentService, List<IEditingContextPersistenceFilter> persistenceFilters, List<IEditingContextMigrationParticipantPredicate> migrationParticipantPredicates, ISemanticDataSearchService semanticDataSearchService, IProjectSearchService projectSearchService, MeterRegistry meterRegistry) {
this.semanticDataUpdateService = Objects.requireNonNull(semanticDataUpdateService);
this.resourceToDocumentService = Objects.requireNonNull(resourceToDocumentService);
this.persistenceFilters = Objects.requireNonNull(persistenceFilters);
this.migrationParticipantPredicates = Objects.requireNonNull(migrationParticipantPredicates);
this.semanticDataSearchService = Objects.requireNonNull(semanticDataSearchService);
this.projectSearchService = Objects.requireNonNull(projectSearchService);
this.timer = Timer.builder(TIMER_NAME).register(meterRegistry);
}

Expand All @@ -78,7 +85,9 @@ public void persist(ICause cause, IEditingContext editingContext) {
if (editingContext instanceof IEMFEditingContext emfEditingContext) {
var applyMigrationParticipants = this.migrationParticipantPredicates.stream().anyMatch(predicate -> predicate.test(emfEditingContext));
new UUIDParser().parse(editingContext.getId())
.map(AggregateReference::<Project, UUID>to)
.flatMap(this.semanticDataSearchService::findById)
.map(semanticData -> semanticData.getProject().getId())
.flatMap(this.projectSearchService::findById)
.ifPresent(project -> {
var documentData = emfEditingContext.getDomain().getResourceSet().getResources().stream()
.filter(resource -> IEMFEditingContext.RESOURCE_SCHEME.equals(resource.getURI().scheme()))
Expand All @@ -95,7 +104,7 @@ public void persist(ICause cause, IEditingContext editingContext) {
domainUris.addAll(data.ePackageEntries().stream().map(EPackageEntry::nsURI).toList());
});

this.semanticDataUpdateService.updateDocuments(cause, project, documents, domainUris);
this.semanticDataUpdateService.updateDocuments(cause, AggregateReference.to(project.getId()), documents, domainUris);
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import org.eclipse.sirius.web.application.editingcontext.services.api.IEditingDomainFactory;
import org.eclipse.sirius.web.domain.boundedcontexts.project.Project;
import org.eclipse.sirius.web.domain.boundedcontexts.project.services.api.IProjectSearchService;
import org.eclipse.sirius.web.domain.boundedcontexts.semanticdata.services.api.ISemanticDataSearchService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
Expand All @@ -50,6 +51,8 @@ public class EditingContextSearchService implements IEditingContextSearchService

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

private final ISemanticDataSearchService semanticDataSearchService;

private final IProjectSearchService projectSearchService;

private final IEditingDomainFactory editingDomainFactory;
Expand All @@ -58,7 +61,8 @@ public class EditingContextSearchService implements IEditingContextSearchService

private final Timer timer;

public EditingContextSearchService(IProjectSearchService projectSearchService, IEditingDomainFactory editingDomainFactory, IEditingContextLoader editingContextLoader, MeterRegistry meterRegistry) {
public EditingContextSearchService(ISemanticDataSearchService semanticDataSearchService, IProjectSearchService projectSearchService, IEditingDomainFactory editingDomainFactory, IEditingContextLoader editingContextLoader, MeterRegistry meterRegistry) {
this.semanticDataSearchService = Objects.requireNonNull(semanticDataSearchService);
this.projectSearchService = Objects.requireNonNull(projectSearchService);
this.editingDomainFactory = Objects.requireNonNull(editingDomainFactory);
this.editingContextLoader = Objects.requireNonNull(editingContextLoader);
Expand All @@ -69,23 +73,29 @@ public EditingContextSearchService(IProjectSearchService projectSearchService, I
@Transactional(readOnly = true)
public boolean existsById(String editingContextId) {
return new UUIDParser().parse(editingContextId)
.map(this.projectSearchService::existsById)
.map(this.semanticDataSearchService::existsById)
.orElse(false);
}

@Override
@Transactional(readOnly = true)
public Optional<IEditingContext> findById(String editingContextId) {
return new UUIDParser().parse(editingContextId)
.flatMap(this.projectSearchService::findById)
.map(this::toEditingContext);
var optionalUUID = new UUIDParser().parse(editingContextId);
if (optionalUUID.isPresent()) {
var optionalSemanticData = this.semanticDataSearchService.findById(optionalUUID.get());
if (optionalSemanticData.isPresent() && optionalSemanticData.get().getId() != null) {
return this.projectSearchService.findById(optionalSemanticData.get().getProject().getId())
.map(project -> this.toEditingContext(project, optionalSemanticData.get().getId().toString()));
}
}
return Optional.empty();
}

private IEditingContext toEditingContext(Project project) {
private IEditingContext toEditingContext(Project project, String semanticDataId) {
long start = System.currentTimeMillis();

AdapterFactoryEditingDomain editingDomain = this.editingDomainFactory.createEditingDomain(project);
EditingContext editingContext = new EditingContext(project.getId().toString(), editingDomain, new HashMap<>(), new ArrayList<>());
EditingContext editingContext = new EditingContext(semanticDataId, editingDomain, new HashMap<>(), new ArrayList<>());
this.editingContextLoader.load(editingContext, project.getId());

long end = System.currentTimeMillis();
Expand Down
Loading

0 comments on commit 9406d58

Please sign in to comment.