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 9, 2025
1 parent 5eadddf commit 4ac3c75
Show file tree
Hide file tree
Showing 10 changed files with 85 additions and 29 deletions.
3 changes: 3 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 @@ -54,6 +55,8 @@ Specifiers can contribute dedicated AQL services for this feature using implemen
- [charts] Make the npm package `sirius-components-charts` use the strict version of our TypeScript configuration
- [trees] Make the npm package `sirius-components-trees` use the strict version of our TypeScript configuration
- https://github.com/eclipse-sirius/sirius-web/issues/1047[#1047] [sirius-web] In the _Domain_ diagram, when using direct-edit on a relatin edge, the initial text now only includes the name of the relation (without the cardinality)
- 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 @@ -63,7 +63,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
@@ -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 @@ -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,25 +73,31 @@ 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();

this.logger.debug("Loading the editing context {}", project.getId());

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
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 @@ -25,6 +25,7 @@
import org.eclipse.sirius.web.domain.boundedcontexts.project.Project;
import org.eclipse.sirius.web.domain.boundedcontexts.representationdata.RepresentationMetadata;
import org.eclipse.sirius.web.domain.boundedcontexts.representationdata.services.api.IRepresentationMetadataSearchService;
import org.eclipse.sirius.web.domain.boundedcontexts.semanticdata.services.api.ISemanticDataSearchService;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.Pageable;
Expand All @@ -44,15 +45,20 @@ public class RepresentationApplicationService implements IRepresentationApplicat

private final IRepresentationMetadataMapper representationMetadataMapper;

public RepresentationApplicationService(IRepresentationMetadataSearchService representationMetadataSearchService, IRepresentationMetadataMapper representationMetadataMapper) {
private final ISemanticDataSearchService semanticDataSearchService;

public RepresentationApplicationService(IRepresentationMetadataSearchService representationMetadataSearchService, IRepresentationMetadataMapper representationMetadataMapper, ISemanticDataSearchService semanticDataSearchService) {
this.representationMetadataSearchService = Objects.requireNonNull(representationMetadataSearchService);
this.representationMetadataMapper = Objects.requireNonNull(representationMetadataMapper);
this.semanticDataSearchService = Objects.requireNonNull(semanticDataSearchService);
}

@Override
@Transactional(readOnly = true)
public Page<RepresentationMetadataDTO> findAllByEditingContextId(String editingContextId, Pageable pageable) {
var representationMetadata = new UUIDParser().parse(editingContextId)
.flatMap(this.semanticDataSearchService::findById)
.map(semanticData -> semanticData.getProject().getId())
.map(AggregateReference::<Project, UUID>to)
.map(this.representationMetadataSearchService::findAllMetadataByProject)
.orElse(List.of())
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 Down Expand Up @@ -43,8 +43,23 @@ public Optional<SemanticData> findByProject(AggregateReference<Project, UUID> pr
return this.semanticDataRepository.findByProjectId(project.getId());
}

@Override
public Optional<SemanticData> findByProjectId(UUID projectId) {
return this.semanticDataRepository.findByProjectId(projectId);
}

@Override
public Optional<SemanticData> findById(UUID semanticDataId) {
return this.semanticDataRepository.findById(semanticDataId);
}

@Override
public List<SemanticData> findAllByDomains(List<String> domainUris) {
return this.semanticDataRepository.findAllByDomains(domainUris);
}

@Override
public boolean existsById(UUID semanticDataId) {
return this.semanticDataRepository.existsById(semanticDataId);
}
}
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 @@ -27,7 +27,13 @@
*/
public interface ISemanticDataSearchService {

Optional<SemanticData> findById(UUID semanticDataId);

Optional<SemanticData> findByProject(AggregateReference<Project, UUID> project);

Optional<SemanticData> findByProjectId(UUID projectId);

List<SemanticData> findAllByDomains(List<String> domainUris);

boolean existsById(UUID semanticDataId);
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2024 CEA LIST.
* Copyright (c) 2024, 2025 CEA LIST.
* 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 @@ -153,7 +153,7 @@ private Optional<Project> createProject(IRepresentationInput representationInput
var viewToSerialize = getViewDescriptionAsString(representationDescription.get(), sourceElementId);

if (viewToSerialize.isPresent() && project.isPresent() && project.get().getId() != null) {
var semanticData = this.semanticDataSearchService.findByProject(AggregateReference.to(project.get().getId()));
/*var semanticData = this.semanticDataSearchService.findByProject(AggregateReference.to(project.get().getId()));
if (semanticData.isPresent() && semanticData.get().getId() != null) {
String semanticProjectId = semanticData.get().getId().toString();
Expand All @@ -180,7 +180,7 @@ private Optional<Project> createProject(IRepresentationInput representationInput
this.jdbcClient.updateRepresentationContentDescriptionId(representationInput, representationDescriptionId, newDescriptionId, sourceId, documentId.toString());
return project;
}
}*/
}
}
return Optional.empty();
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 Down Expand Up @@ -38,6 +38,8 @@
import org.eclipse.sirius.web.application.editingcontext.EditingContext;
import org.eclipse.sirius.web.domain.boundedcontexts.project.Nature;
import org.eclipse.sirius.web.domain.boundedcontexts.project.services.api.IProjectSearchService;
import org.eclipse.sirius.web.domain.boundedcontexts.semanticdata.SemanticData;
import org.eclipse.sirius.web.domain.boundedcontexts.semanticdata.services.api.ISemanticDataSearchService;
import org.springframework.stereotype.Service;

/**
Expand All @@ -50,13 +52,19 @@ public class FlowEditingContextInitializer implements IEditingContextProcessor {

private final IProjectSearchService projectSearchService;

public FlowEditingContextInitializer(IProjectSearchService projectSearchService) {
private final ISemanticDataSearchService semanticDataSearchService;

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

@Override
public void preProcess(IEditingContext editingContext) {
//TODO modify all xxxContextInitializer
var isFlowProject = new UUIDParser().parse(editingContext.getId())
.flatMap(this.semanticDataSearchService::findById)
.map(semanticData -> semanticData.getProject().getId())
.flatMap(this.projectSearchService::findById)
.filter(project -> project.getNatures().stream()
.map(Nature::name)
Expand Down

0 comments on commit 4ac3c75

Please sign in to comment.