Skip to content

Commit

Permalink
[4418] Change type of project_id from UUID to String
Browse files Browse the repository at this point in the history
Bug: #4418
Signed-off-by: Michaël Charfadi <[email protected]>
  • Loading branch information
mcharfadi committed Jan 16, 2025
1 parent 689cf68 commit 8b9a114
Show file tree
Hide file tree
Showing 92 changed files with 397 additions and 405 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@

=== Breaking changes

- https://github.com/eclipse-sirius/sirius-web/issues/4418[#4418] [sirius-web] Change type of project_id from UUID to String


=== Dependency update

Expand Down Expand Up @@ -92,6 +94,7 @@ Note that you can retrieve the URL of a page in the response header of `GET /api
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/4381[#4381] [trees] Set activeFilterIds variable in DefaultExpandAllTreePathHandler.
- https://github.com/eclipse-sirius/sirius-web/issues/3533[#3553] [diagram] Add a dedicated component to handle diagram subscription
- https://github.com/eclipse-sirius/sirius-web/issues/4418[#4418] [sirius-web] Change type of project_id from UUID to String


== v2025.1.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,12 @@
* @author arichard
*/
@Schema(name = "Identified", description = "Identified represents an Object through its ID and type.")
public record Identified(@JsonProperty("@id") UUID id) {
public record Identified(@JsonProperty("@id") String id) {
public Identified {
Objects.requireNonNull(id);
}

public Identified(UUID id) {
this(id.toString());
}
}
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 @@ -14,7 +14,6 @@

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.springframework.stereotype.Service;
Expand All @@ -37,8 +36,6 @@ public EditingContextApplicationService(IProjectSearchService projectSearchServi
@Override
@Transactional(readOnly = true)
public boolean existsById(String editingContextId) {
return new UUIDParser().parse(editingContextId)
.map(this.projectSearchService::existsById)
.orElse(false);
return this.projectSearchService.existsById(editingContextId);
}
}
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 @@ -14,7 +14,6 @@

import java.util.List;
import java.util.Objects;
import java.util.UUID;

import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.sirius.components.core.api.IEditingContextProcessor;
Expand Down Expand Up @@ -60,7 +59,7 @@ public EditingContextLoader(ISemanticDataSearchService semanticDataSearchService
this.migrationParticipantPredicates = Objects.requireNonNull(migrationParticipantPredicates);
}

public void load(EditingContext editingContext, UUID projectId) {
public void load(EditingContext editingContext, String projectId) {
this.editingContextProcessors.forEach(processor -> processor.preProcess(editingContext));

this.semanticDataSearchService.findByProject(AggregateReference.to(projectId))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,13 @@
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;

import org.eclipse.sirius.components.core.api.IEditingContext;
import org.eclipse.sirius.components.core.api.IEditingContextPersistenceService;
import org.eclipse.sirius.components.emf.services.api.IEMFEditingContext;
import org.eclipse.sirius.components.events.ICause;
import org.eclipse.sirius.web.application.UUIDParser;
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;
Expand Down Expand Up @@ -77,26 +75,24 @@ 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)
.ifPresent(project -> {
var documentData = emfEditingContext.getDomain().getResourceSet().getResources().stream()
.filter(resource -> IEMFEditingContext.RESOURCE_SCHEME.equals(resource.getURI().scheme()))
.filter(resource -> this.persistenceFilters.stream().allMatch(filter -> filter.shouldPersist(resource)))
.map(resource -> this.resourceToDocumentService.toDocument(resource, applyMigrationParticipants))
.flatMap(Optional::stream)
.collect(Collectors.toSet());

var documents = new LinkedHashSet<Document>();
var domainUris = new LinkedHashSet<String>();

documentData.forEach(data -> {
documents.add(data.document());
domainUris.addAll(data.ePackageEntries().stream().map(EPackageEntry::nsURI).toList());
});

this.semanticDataUpdateService.updateDocuments(cause, project, documents, domainUris);
});
AggregateReference<Project, String> projectId = AggregateReference.to(editingContext.getId());

var documentData = emfEditingContext.getDomain().getResourceSet().getResources().stream()
.filter(resource -> IEMFEditingContext.RESOURCE_SCHEME.equals(resource.getURI().scheme()))
.filter(resource -> this.persistenceFilters.stream().allMatch(filter -> filter.shouldPersist(resource)))
.map(resource -> this.resourceToDocumentService.toDocument(resource, applyMigrationParticipants))
.flatMap(Optional::stream)
.collect(Collectors.toSet());

var documents = new LinkedHashSet<Document>();
var domainUris = new LinkedHashSet<String>();

documentData.forEach(data -> {
documents.add(data.document());
domainUris.addAll(data.ePackageEntries().stream().map(EPackageEntry::nsURI).toList());
});

this.semanticDataUpdateService.updateDocuments(cause, projectId, documents, domainUris);
}

long end = System.currentTimeMillis();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import org.eclipse.emf.edit.domain.AdapterFactoryEditingDomain;
import org.eclipse.sirius.components.core.api.IEditingContext;
import org.eclipse.sirius.components.core.api.IEditingContextSearchService;
import org.eclipse.sirius.web.application.UUIDParser;
import org.eclipse.sirius.web.application.editingcontext.EditingContext;
import org.eclipse.sirius.web.application.editingcontext.services.api.IEditingContextLoader;
import org.eclipse.sirius.web.application.editingcontext.services.api.IEditingDomainFactory;
Expand Down Expand Up @@ -68,16 +67,13 @@ public EditingContextSearchService(IProjectSearchService projectSearchService, I
@Override
@Transactional(readOnly = true)
public boolean existsById(String editingContextId) {
return new UUIDParser().parse(editingContextId)
.map(this.projectSearchService::existsById)
.orElse(false);
return this.projectSearchService.existsById(editingContextId);
}

@Override
@Transactional(readOnly = true)
public Optional<IEditingContext> findById(String editingContextId) {
return new UUIDParser().parse(editingContextId)
.flatMap(this.projectSearchService::findById)
return this.projectSearchService.findById(editingContextId)
.map(this::toEditingContext);
}

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,8 +12,6 @@
*******************************************************************************/
package org.eclipse.sirius.web.application.editingcontext.services.api;

import java.util.UUID;

import org.eclipse.sirius.web.application.editingcontext.EditingContext;

/**
Expand All @@ -23,6 +21,6 @@
*/
public interface IEditingContextLoader {

void load(EditingContext editingContext, UUID projectId);
void load(EditingContext editingContext, String projectId);

}
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 @@ -65,8 +65,7 @@ public IPayload get(DataFetchingEnvironment environment) throws Exception {
.flatMap(new UUIDParser()::parse);

var optionalProjectId = Optional.ofNullable(inputArgument.get(PROJECT_ID))
.map(Object::toString)
.flatMap(new UUIDParser()::parse);
.map(Object::toString);

var optionalLabel = Optional.ofNullable(inputArgument.get(LABEL))
.filter(String.class::isInstance)
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 @@ -26,7 +26,7 @@
*/
public record UploadImageInput(
@NotNull UUID id,
@NotNull UUID projectId,
@NotNull String projectId,
@NotNull String label,
@NotNull UploadFile file) implements IInput {
}
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 @@ -72,7 +72,7 @@ public Optional<ProjectImage> findById(UUID id) {

@Override
@Transactional(readOnly = true)
public Page<ImageMetadata> findAll(UUID projectId, Pageable pageable) {
public Page<ImageMetadata> findAll(String projectId, Pageable pageable) {
return this.projectImageSearchService.findAll(projectId, pageable).map(this.projectImageMapper::toDTO);
}

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 @@ -33,7 +33,7 @@ public interface IProjectImageApplicationService {

Optional<ProjectImage> findById(UUID id);

Page<ImageMetadata> findAll(UUID projectId, Pageable pageable);
Page<ImageMetadata> findAll(String projectId, Pageable pageable);

IPayload uploadImage(UploadImageInput input);

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 @@ -13,7 +13,6 @@
package org.eclipse.sirius.web.application.project.controllers;

import java.util.Objects;
import java.util.UUID;

import org.eclipse.sirius.web.application.project.services.api.IProjectExportService;
import org.eclipse.sirius.web.domain.boundedcontexts.project.services.api.IProjectSearchService;
Expand Down Expand Up @@ -58,7 +57,7 @@ public ProjectDownloadController(IProjectSearchService projectSearchService, IPr

@ResponseBody
@GetMapping(path = "/{projectId}")
public ResponseEntity<Resource> downloadProject(@PathVariable UUID projectId) {
public ResponseEntity<Resource> downloadProject(@PathVariable String projectId) {
var optionalProject = this.projectSearchService.findById(projectId);
if (optionalProject.isPresent()) {
var project = optionalProject.get();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ public ResponseEntity<List<RestProject>> getProjects(@RequestParam(name = "page[
int limit = pageSize.orElse(DEFAULT_PAGE_SIZE);
var window = this.projectApplicationService.findAll(position, limit);
var restProjects = window
.map(project -> new RestProject(project.id(), DEFAULT_CREATED, new Identified(project.id()), null, project.name()))
.toList();
.map(project -> new RestProject(project.id(), DEFAULT_CREATED, new Identified(project.id()), null, project.name()))
.toList();
var headers = this.handleLinkResponseHeader(restProjects, position, window.hasNext(), limit);
return new ResponseEntity<>(restProjects, headers, HttpStatus.OK);
}
Expand All @@ -112,22 +112,20 @@ public ResponseEntity<List<RestProject>> getProjects(@RequestParam(name = "page[
@ApiResponse(responseCode = "404", description = "Not Found", content = { @Content() })
})
@GetMapping(path = "/{projectId}")
public ResponseEntity<RestProject> getProjectById(@PathVariable UUID projectId) {
public ResponseEntity<RestProject> getProjectById(@PathVariable String projectId) {
var restProject = this.projectApplicationService.findById(projectId)
.map(project -> new RestProject(project.id(), DEFAULT_CREATED, new Identified(project.id()), null, project.name()));
.map(project -> new RestProject(project.id(), DEFAULT_CREATED, new Identified(project.id()), null, project.name()));

if (restProject.isPresent()) {
return new ResponseEntity<>(restProject.get(), HttpStatus.OK);
}
return restProject.map(project -> new ResponseEntity<>(project, HttpStatus.OK))
.orElseGet(() -> new ResponseEntity<>(null, HttpStatus.NOT_FOUND));

return new ResponseEntity<>(null, HttpStatus.NOT_FOUND);
}

@Operation(description = "Create a new project with the given name and description (optional).")
@ApiResponses(value = {
@ApiResponse(responseCode = "201", description = "Created", content = {
@Content(mediaType = "application/json", schema = @Schema(implementation = RestProject.class))
})
})
})
@PostMapping
public ResponseEntity<RestProject> createProject(@RequestParam String name, @RequestParam Optional<String> description) {
Expand All @@ -151,7 +149,7 @@ public ResponseEntity<RestProject> createProject(@RequestParam String name, @Req
@ApiResponse(responseCode = "404", description = "Not Found", content = { @Content() })
})
@PutMapping(path = "/{projectId}")
public ResponseEntity<RestProject> updateProject(@PathVariable UUID projectId, @RequestParam Optional<String> name, @RequestParam Optional<String> description, @RequestParam Optional<RestBranch> branch) {
public ResponseEntity<RestProject> updateProject(@PathVariable String projectId, @RequestParam Optional<String> name, @RequestParam Optional<String> description, @RequestParam Optional<RestBranch> branch) {
if (name.isPresent()) {
var renameProjectInput = new RenameProjectInput(UUID.randomUUID(), projectId, name.get());
var renamedProjectPayload = this.projectApplicationService.renameProject(renameProjectInput);
Expand All @@ -168,11 +166,11 @@ public ResponseEntity<RestProject> updateProject(@PathVariable UUID projectId, @
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "OK", content = {
@Content(mediaType = "application/json", schema = @Schema(implementation = RestProject.class))
}),
}),
@ApiResponse(responseCode = "204", description = "No content", content = { @Content() })
})
@DeleteMapping(path = "/{projectId}")
public ResponseEntity<RestProject> deleteProject(@PathVariable UUID projectId) {
public ResponseEntity<RestProject> deleteProject(@PathVariable String projectId) {
var restProject = this.projectApplicationService.findById(projectId)
.map(project -> new RestProject(project.id(), DEFAULT_CREATED, new Identified(project.id()), null, project.name()))
.orElse(null);
Expand Down Expand Up @@ -203,7 +201,7 @@ private MultiValueMap<String, String> handleLinkResponseHeader(List<RestProject>
private String createHeaderLink(List<RestProject> projects, int limit, String beforeOrAfterPage, String relationType) {
var header = new StringBuilder();
var lastProject = projects.get(Math.min(projects.size() - 1, limit - 1));
var cursorId = new Relay().toGlobalId("Project", lastProject.id().toString());
var cursorId = new Relay().toGlobalId("Project", lastProject.id());
UriComponents uriComponents = ServletUriComponentsBuilder.fromCurrentRequestUri()
.queryParam("page[" + beforeOrAfterPage + "]", cursorId)
.queryParam("page[size]", limit)
Expand All @@ -215,4 +213,4 @@ private String createHeaderLink(List<RestProject> projects, int limit, String be
header.append("\"");
return header.toString();
}
}
}
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 @@ -16,7 +16,6 @@

import org.eclipse.sirius.components.annotations.spring.graphql.QueryDataFetcher;
import org.eclipse.sirius.components.graphql.api.IDataFetcherWithFieldCoordinates;
import org.eclipse.sirius.web.application.UUIDParser;
import org.eclipse.sirius.web.application.project.services.api.IProjectApplicationService;
import org.eclipse.sirius.web.application.project.dto.ProjectDTO;

Expand All @@ -41,6 +40,6 @@ public ViewerProjectDataFetcher(IProjectApplicationService projectApplicationSer
@Override
public ProjectDTO get(DataFetchingEnvironment environment) throws Exception {
String projectId = environment.getArgument(PROJECT_ID_ARGUMENT);
return new UUIDParser().parse(projectId).flatMap(this.projectApplicationService::findById).orElse(null);
return this.projectApplicationService.findById(projectId).orElse(null);
}
}
Loading

0 comments on commit 8b9a114

Please sign in to comment.