Skip to content

Commit

Permalink
[4557] Fix an issue where targetObjectURI was not set during download
Browse files Browse the repository at this point in the history
Bug: #4557
Signed-off-by: Michaël Charfadi <[email protected]>
Signed-off-by: Guillaume Coutable <[email protected]>
  • Loading branch information
mcharfadi authored and sbegaudeau committed Feb 13, 2025
1 parent 73028b4 commit 8560312
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ Now they are executed for some data if the data was coming from a studio too.
- https://github.com/eclipse-sirius/sirius-web/issues/4530[#4530] [formdescriptioneditor] Ensure that the frontend will not crash while trying to display some nested structure
- https://github.com/eclipse-sirius/sirius-web/issues/4544[#4544] [diagram] Fix an issue where quicktools could be misaligned by ensuring now that all quick tools provided by Sirius Web are 24px in width and 24px in height
- https://github.com/eclipse-sirius/sirius-web/issues/4523[#4523] [diagram] Fix an issue that caused the palette to be unopenable during a fit view
- https://github.com/eclipse-sirius/sirius-web/issues/4557[#4557] [sirius-web] Fix an issue where targetObjectURI was not set in manifest.json during the download of a project


=== New Features
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 @@ -27,6 +27,7 @@
import org.eclipse.sirius.components.core.api.IEditingContextSearchService;
import org.eclipse.sirius.components.emf.services.api.IEMFEditingContext;
import org.eclipse.sirius.emfjson.resource.JsonResourceFactoryImpl;
import org.eclipse.sirius.web.application.editingcontext.services.EditingContextApplicationService;
import org.eclipse.sirius.web.application.project.services.api.IProjectExportParticipant;
import org.eclipse.sirius.web.application.representation.services.api.IRepresentationContentMigrationService;
import org.eclipse.sirius.web.domain.boundedcontexts.project.Project;
Expand Down Expand Up @@ -55,15 +56,18 @@ public class ProjectRepresentationDataExportParticipant implements IProjectExpor

private final IRepresentationContentMigrationService representationContentMigrationService;

private final EditingContextApplicationService editingContextApplicationService;

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

public ProjectRepresentationDataExportParticipant(IEditingContextSearchService editingContextSearchService, IRepresentationMetadataSearchService representationMetadataSearchService,
IRepresentationContentSearchService representationContentSearchService, ObjectMapper objectMapper, IRepresentationContentMigrationService representationContentMigrationService) {
IRepresentationContentSearchService representationContentSearchService, ObjectMapper objectMapper, IRepresentationContentMigrationService representationContentMigrationService, EditingContextApplicationService editingContextApplicationService) {
this.editingContextSearchService = Objects.requireNonNull(editingContextSearchService);
this.representationMetadataSearchService = Objects.requireNonNull(representationMetadataSearchService);
this.representationContentSearchService = Objects.requireNonNull(representationContentSearchService);
this.objectMapper = Objects.requireNonNull(objectMapper);
this.representationContentMigrationService = Objects.requireNonNull(representationContentMigrationService);
this.editingContextApplicationService = Objects.requireNonNull(editingContextApplicationService);
}

@Override
Expand All @@ -90,9 +94,11 @@ public Map<String, Object> exportData(Project project, ZipOutputStream outputStr

// Get TargetObjectURI
String uriFragment = "";
var optionalEditingContext = this.editingContextSearchService.findById(project.getId().toString())
var editingContextId = this.editingContextApplicationService.getCurrentEditingContextId(project.getId());
var optionalEditingContext = this.editingContextSearchService.findById(editingContextId)
.filter(IEMFEditingContext.class::isInstance)
.map(IEMFEditingContext.class::cast);

if (optionalEditingContext.isPresent()) {
var editingContext = optionalEditingContext.get();
String targetObjectId = representationMetadata.getTargetObjectId();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ public void givenStudioWhenTheDownloadOfProjectIsRequestedThenTheSemanticDataAre
@Test
@GivenSiriusWebServer
@DisplayName("Given a project, when the download of the project is requested, then the representation data are retrieved")
public void givenProjectWhenTheDownloadOfProjectIsRequestedThenTheRepresentationDataAreRetrieved() {
public void givenProjectWhenTheDownloadOfProjectIsRequestedThenTheRepresentationDataAreRetrieved2() {
this.givenCommittedTransaction.commit();

var response = this.download(TestIdentifiers.ECORE_SAMPLE_PROJECT);
Expand All @@ -169,6 +169,47 @@ public void givenProjectWhenTheDownloadOfProjectIsRequestedThenTheRepresentation
}
}

@Test
@GivenSiriusWebServer
@DisplayName("Given a project with representations, when the download of the project is requested, then the manifest is exported")
public void givenProjectWithRepresentationsWhenTheDownloadOfProjectIsRequestedThenTheManifestIsExported() {
this.givenCommittedTransaction.commit();

var response = this.download(TestIdentifiers.ECORE_SAMPLE_PROJECT);

try (ZipInputStream inputStream = new ZipInputStream(response.getBody().getInputStream())) {
HashMap<String, ByteArrayOutputStream> zipEntries = this.toZipEntries(inputStream);
assertThat(zipEntries).isNotEmpty().containsKey("Ecore Sample/manifest.json");

String manifestContentExpected = """
{
"natures": ["ecore"],
"documentIdsToName": { "48dc942a-6b76-4133-bca5-5b29ebee133d": "Ecore" },
"metamodels": ["domain://buck", "http://www.eclipse.org/emf/2002/Ecore"],
"representations": {
"05e44ccc-9363-443f-a816-25fc73e3e7f7": {
"descriptionURI": "69030a1b-0b5f-3c1d-8399-8ca260e4a672",
"type": "siriusComponents://representation?type=Portal",
"targetObjectURI": "sirius:///48dc942a-6b76-4133-bca5-5b29ebee133d#/"
},
"e81eec5c-42d6-491c-8bcc-9beb951356f8": {
"descriptionURI": "69030a1b-0b5f-3c1d-8399-8ca260e4a672",
"type": "siriusComponents://representation?type=Portal",
"targetObjectURI": "sirius:///48dc942a-6b76-4133-bca5-5b29ebee133d#/"
}
}
}
""";

String manifestContent = zipEntries.get("Ecore Sample/manifest.json").toString(StandardCharsets.UTF_8);
var objectMapper = new ObjectMapper();
System.out.println(objectMapper.readTree(manifestContent));
assertThat(objectMapper.readTree(manifestContent)).isEqualTo(objectMapper.readTree(manifestContentExpected));
} catch (IOException exception) {
fail(exception.getMessage());
}
}

private ResponseEntity<Resource> download(String projectId) {
var uri = "http://localhost:" + this.port + "/api/projects/" + projectId;

Expand Down

0 comments on commit 8560312

Please sign in to comment.