Skip to content

Commit a9e4c3b

Browse files
gdanielAxelRICHARD
authored andcommitted
[2094] Ensure library documents are read-only
Bug: #2094 Signed-off-by: Gwendal Daniel <gwendal.daniel@obeosoft.com>
1 parent 2d4f785 commit a9e4c3b

4 files changed

Lines changed: 30 additions & 1 deletion

File tree

CHANGELOG.adoc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ As a result, the following GraphQL mutations have been removed `exposeRequiremen
2222
=== Bug fixes
2323

2424
- https://github.com/eclipse-syson/syson/issues/2045[#2045] [diagrams] In Interconnection View diagrams, fix an issue where the `parts` compartment of a `PartDefinition` graphical node was incorrectly revealed when creating a `PartUsage` from the `PartDefinition` graphical node, even if the `interconnection` compartment was already visible.
25+
- https://github.com/eclipse-syson/syson/issues/2094[#2094] [libraries] Ensure library documents are read-only.
2526

2627
=== Improvements
2728

backend/application/syson-application-configuration/src/main/java/org/eclipse/syson/application/publication/SysONSysMLLibraryPublisher.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import org.eclipse.sirius.components.core.api.IEditingContext;
3030
import org.eclipse.sirius.components.core.api.IPayload;
3131
import org.eclipse.sirius.components.core.api.SuccessPayload;
32+
import org.eclipse.sirius.components.emf.ResourceMetadataAdapter;
3233
import org.eclipse.sirius.components.emf.services.api.IEMFEditingContext;
3334
import org.eclipse.sirius.components.events.ICause;
3435
import org.eclipse.sirius.components.representations.Message;
@@ -242,6 +243,14 @@ protected Optional<SemanticData> publishAsLibrary(final ICause parentCause, fina
242243
// should be determined by its import kind (reference or copy), and not whether it was imported from a textual
243244
// SysML file in the first place.
244245
resources.forEach(resource -> ElementUtil.setIsImported(resource, false));
246+
// Ensure all the resources are flagged as read-only
247+
for (Resource resource : resources) {
248+
resource.eAdapters().stream()
249+
.filter(ResourceMetadataAdapter.class::isInstance)
250+
.map(ResourceMetadataAdapter.class::cast)
251+
.findFirst()
252+
.ifPresent(resourceMetadataAdapter -> resourceMetadataAdapter.setIsReadOnly(true));
253+
}
245254

246255
final ICause cause = new SysONPublishedLibrarySemanticDataCreationRequested(parentCause, libraryNamespace, libraryName, libraryVersion, libraryDescription);
247256
return this.createSemanticData(cause, resources, dependencies);

backend/application/syson-application/src/test/java/org/eclipse/syson/application/libraries/publication/SysONLibraryPublicationTests.java

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
import org.eclipse.syson.application.publication.SysONLibraryPublicationHandler;
5353
import org.eclipse.syson.application.publication.SysONLibraryPublicationListener;
5454
import org.eclipse.syson.sysml.SysmlPackage;
55+
import org.eclipse.syson.sysml.util.ElementUtil;
5556
import org.junit.jupiter.api.BeforeEach;
5657
import org.junit.jupiter.api.DisplayName;
5758
import org.junit.jupiter.api.Test;
@@ -124,11 +125,25 @@ public void givenProjectWhenLibraryIsPublishedThenLibraryExistsAndHasCorrectMeta
124125
TestTransaction.end();
125126
TestTransaction.start();
126127

127-
assertThat(this.librarySearchService.findByNamespaceAndNameAndVersion(SimpleProjectElementsTestProjectData.PROJECT_ID, SimpleProjectElementsTestProjectData.PROJECT_NAME, LIBRARY_VERSION))
128+
Optional<Library> optionalLibrary = this.librarySearchService.findByNamespaceAndNameAndVersion(SimpleProjectElementsTestProjectData.PROJECT_ID, SimpleProjectElementsTestProjectData.PROJECT_NAME, LIBRARY_VERSION);
129+
assertThat(optionalLibrary)
128130
.isPresent()
129131
.hasValueSatisfying(library -> assertThat(library.getName()).isEqualTo(SimpleProjectElementsTestProjectData.PROJECT_NAME))
130132
.hasValueSatisfying(library -> assertThat(library.getVersion()).isEqualTo(LIBRARY_VERSION))
131133
.hasValueSatisfying(library -> assertThat(library.getDescription()).isEqualTo(LIBRARY_DESCRIPTION));
134+
135+
// Load the editing context manually, we can't use ExecuteEditingContextFunctionInput because the editing context dispatcher doesn't allow mutations on libraries
136+
Optional<IEditingContext> optionalEditingContext = this.editingContextSearchService.findById(optionalLibrary.get().getSemanticData().getId().toString());
137+
assertThat(optionalEditingContext).isPresent();
138+
IEditingContext editingContext = optionalEditingContext.get();
139+
if (editingContext instanceof IEMFEditingContext emfEditingContext) {
140+
List<Resource> properLibraryResources = emfEditingContext.getDomain().getResourceSet().getResources().stream()
141+
.filter(resource -> !ElementUtil.isStandardLibraryResource(resource))
142+
.toList();
143+
assertThat(properLibraryResources).hasSize(1);
144+
assertThat(properLibraryResources.getFirst().eAdapters())
145+
.anyMatch(adapter -> adapter instanceof ResourceMetadataAdapter resourceMetadataAdapter && resourceMetadataAdapter.isReadOnly());
146+
}
132147
}
133148

134149
@Test

doc/content/modules/user-manual/pages/release-notes/2026.5.0.adoc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@
1414

1515
** In _Interconnection View_ diagrams, fix an issue where the `parts` compartment of `PartDefinition` graphical node was incorrectly revealed when creating a `PartUsage` from the `PartDefinition` graphical node, even if the `interconnection` compartment was already visible.
1616

17+
* In _Details_ view:
18+
19+
** Fix an issue that allowed to edit library objects via the _Details_ view.
20+
1721
== Improvements
1822

1923
== Technical details

0 commit comments

Comments
 (0)