diff --git a/CHANGELOG.adoc b/CHANGELOG.adoc index 0973d172d7..e69f16dfc4 100644 --- a/CHANGELOG.adoc +++ b/CHANGELOG.adoc @@ -90,8 +90,9 @@ More existing APIs will be migrated to this new common pattern. image:doc/screenshots/insideLabelPositions.png[Inside label positions, 70%] - https://github.com/eclipse-sirius/sirius-web/issues/3574[#3574] [diagram] Add a loading indicator during execution of an arrange-all - https://github.com/eclipse-sirius/sirius-web/issues/3586[#3586] [diagram] Fix an issue with keypress listener attached to the palette -- https://github.com/eclipse-sirius/sirius-web/issues/3623[#3623] [form] Remove unused form payload -- https://github.com/eclipse-sirius/sirius-web/issues/3627[#3627] [form] Remove unused mutation in form +- https://github.com/eclipse-sirius/sirius-web/issues/3623[#3623] [form] Remove unused form payload +- https://github.com/eclipse-sirius/sirius-web/issues/3627[#3627] [form] Remove unused mutation in form +- https://github.com/eclipse-sirius/sirius-web/issues/3606[#3606] [test] Improve error handling in ExecuteEditingContextFunctionRunner and ExecuteEditingContextFunctionEventHandler == v2024.5.0 diff --git a/packages/sirius-web/backend/sirius-web/src/test/java/org/eclipse/sirius/web/application/controllers/documents/DocumentControllerIntegrationTests.java b/packages/sirius-web/backend/sirius-web/src/test/java/org/eclipse/sirius/web/application/controllers/documents/DocumentControllerIntegrationTests.java index e3f87cd7e2..47d87d88b4 100644 --- a/packages/sirius-web/backend/sirius-web/src/test/java/org/eclipse/sirius/web/application/controllers/documents/DocumentControllerIntegrationTests.java +++ b/packages/sirius-web/backend/sirius-web/src/test/java/org/eclipse/sirius/web/application/controllers/documents/DocumentControllerIntegrationTests.java @@ -22,10 +22,12 @@ import java.util.Map; import java.util.Optional; import java.util.UUID; -import java.util.function.Function; +import java.util.function.BiFunction; import java.util.function.Predicate; import org.eclipse.sirius.components.core.api.IEditingContext; +import org.eclipse.sirius.components.core.api.IInput; +import org.eclipse.sirius.components.core.api.IPayload; import org.eclipse.sirius.components.emf.ResourceMetadataAdapter; import org.eclipse.sirius.components.emf.services.api.IEMFEditingContext; import org.eclipse.sirius.components.graphql.api.UploadFile; @@ -178,19 +180,24 @@ private void createDocument(String editingContextId, String stereotypeId, String String typename = JsonPath.read(result, "$.data.createDocument.__typename"); assertThat(typename).isEqualTo(CreateDocumentSuccessPayload.class.getSimpleName()); - Function function = editingContext -> Optional.of(editingContext) - .filter(IEMFEditingContext.class::isInstance) - .map(IEMFEditingContext.class::cast) - .map(emfEditingContext -> emfEditingContext.getDomain().getResourceSet().getResources().stream() - .anyMatch(resource -> resource.eAdapters().stream() - .filter(ResourceMetadataAdapter.class::isInstance) - .map(ResourceMetadataAdapter.class::cast) - .map(ResourceMetadataAdapter::getName) - .anyMatch(name::equals))) - .orElse(false); + BiFunction function = (editingContext, executeEditingContextFunctionInput) -> { + var resourceFound = Optional.of(editingContext) + .filter(IEMFEditingContext.class::isInstance) + .map(IEMFEditingContext.class::cast) + .map(emfEditingContext -> emfEditingContext.getDomain().getResourceSet().getResources().stream() + .anyMatch(resource -> resource.eAdapters().stream() + .filter(ResourceMetadataAdapter.class::isInstance) + .map(ResourceMetadataAdapter.class::cast) + .map(ResourceMetadataAdapter::getName) + .anyMatch(name::equals))) + .orElse(false); + return new ExecuteEditingContextFunctionSuccessPayload(executeEditingContextFunctionInput.id(), resourceFound); + }; var mono = this.executeEditingContextFunctionRunner.execute(new ExecuteEditingContextFunctionInput(UUID.randomUUID(), editingContextId, function)); - Predicate predicate = payload -> Optional.of(payload) + Predicate predicate = payload -> Optional.of(payload) + .filter(ExecuteEditingContextFunctionSuccessPayload.class::isInstance) + .map(ExecuteEditingContextFunctionSuccessPayload.class::cast) .map(ExecuteEditingContextFunctionSuccessPayload::result) .filter(Boolean.class::isInstance) .map(Boolean.class::cast) @@ -218,19 +225,24 @@ private void uploadDocument(String editingContextId, String name, String content String report = JsonPath.read(result, "$.data.uploadDocument.report"); assertThat(report).isEqualTo("This is a test report"); - Function function = editingContext -> Optional.of(editingContext) - .filter(IEMFEditingContext.class::isInstance) - .map(IEMFEditingContext.class::cast) - .map(emfEditingContext -> emfEditingContext.getDomain().getResourceSet().getResources().stream() - .anyMatch(resource -> resource.eAdapters().stream() - .filter(ResourceMetadataAdapter.class::isInstance) - .map(ResourceMetadataAdapter.class::cast) - .map(ResourceMetadataAdapter::getName) - .anyMatch(name::equals))) - .orElse(false); + BiFunction function = (editingContext, executeEditingContextFunctionInput) -> { + var resourceFound = Optional.of(editingContext) + .filter(IEMFEditingContext.class::isInstance) + .map(IEMFEditingContext.class::cast) + .map(emfEditingContext -> emfEditingContext.getDomain().getResourceSet().getResources().stream() + .anyMatch(resource -> resource.eAdapters().stream() + .filter(ResourceMetadataAdapter.class::isInstance) + .map(ResourceMetadataAdapter.class::cast) + .map(ResourceMetadataAdapter::getName) + .anyMatch(name::equals))) + .orElse(false); + return new ExecuteEditingContextFunctionSuccessPayload(executeEditingContextFunctionInput.id(), resourceFound); + }; var mono = this.executeEditingContextFunctionRunner.execute(new ExecuteEditingContextFunctionInput(UUID.randomUUID(), editingContextId, function)); - Predicate predicate = payload -> Optional.of(payload) + Predicate predicate = payload -> Optional.of(payload) + .filter(ExecuteEditingContextFunctionSuccessPayload.class::isInstance) + .map(ExecuteEditingContextFunctionSuccessPayload.class::cast) .map(ExecuteEditingContextFunctionSuccessPayload::result) .filter(Boolean.class::isInstance) .map(Boolean.class::cast) diff --git a/packages/sirius-web/backend/sirius-web/src/test/java/org/eclipse/sirius/web/application/controllers/trees/ExplorerExpandAllControllerTests.java b/packages/sirius-web/backend/sirius-web/src/test/java/org/eclipse/sirius/web/application/controllers/trees/ExplorerExpandAllControllerTests.java index 2df6041745..941e7b34ab 100644 --- a/packages/sirius-web/backend/sirius-web/src/test/java/org/eclipse/sirius/web/application/controllers/trees/ExplorerExpandAllControllerTests.java +++ b/packages/sirius-web/backend/sirius-web/src/test/java/org/eclipse/sirius/web/application/controllers/trees/ExplorerExpandAllControllerTests.java @@ -25,22 +25,24 @@ import java.util.Spliterators; import java.util.UUID; import java.util.concurrent.atomic.AtomicReference; +import java.util.function.BiFunction; import java.util.function.Consumer; -import java.util.function.Function; import java.util.stream.StreamSupport; import org.eclipse.emf.ecore.EObject; import org.eclipse.emf.ecore.resource.Resource; import org.eclipse.sirius.components.collaborative.api.ChangeDescription; import org.eclipse.sirius.components.collaborative.api.ChangeKind; -import org.eclipse.sirius.components.collaborative.api.IEditingContextEventProcessorRegistry; import org.eclipse.sirius.components.collaborative.trees.dto.TreeEventInput; import org.eclipse.sirius.components.collaborative.trees.dto.TreeRefreshedEventPayload; import org.eclipse.sirius.components.core.api.IEditingContext; import org.eclipse.sirius.components.core.api.IIdentityService; +import org.eclipse.sirius.components.core.api.IInput; +import org.eclipse.sirius.components.core.api.IPayload; import org.eclipse.sirius.components.emf.services.api.IEMFEditingContext; import org.eclipse.sirius.components.graphql.tests.ExecuteEditingContextFunctionInput; import org.eclipse.sirius.components.graphql.tests.ExecuteEditingContextFunctionRunner; +import org.eclipse.sirius.components.graphql.tests.ExecuteEditingContextFunctionSuccessPayload; import org.eclipse.sirius.components.trees.Tree; import org.eclipse.sirius.components.trees.tests.graphql.ExpandAllTreePathQueryRunner; import org.eclipse.sirius.components.trees.tests.graphql.TreeEventSubscriptionRunner; @@ -81,9 +83,6 @@ public class ExplorerExpandAllControllerTests extends AbstractIntegrationTests { @Autowired private ExecuteEditingContextFunctionRunner executeEditingContextFunctionRunner; - @Autowired - private IEditingContextEventProcessorRegistry editingContextEventProcessorRegistry; - @Autowired private PapayaViewInjector papayaViewInjector; @@ -121,34 +120,31 @@ public void givenStudioWhenWeAskForTheTreePathOfAnObjectThenItsPathInTheExplorer var createViewInput = new ExecuteEditingContextFunctionInput(UUID.randomUUID(), StudioIdentifiers.EMPTY_STUDIO_PROJECT.toString(), this.papayaViewInjector); this.executeEditingContextFunctionRunner.execute(createViewInput).block(); - Function getObjectIdFunction = editingContext -> Optional.of(editingContext) - .filter(IEMFEditingContext.class::isInstance) - .map(IEMFEditingContext.class::cast) - .flatMap(emfEditingContext -> { - var iterator = emfEditingContext.getDomain().getResourceSet().getAllContents(); - var stream = StreamSupport.stream(Spliterators.spliteratorUnknownSize(iterator, Spliterator.ORDERED), false); - return stream.filter(DiagramDescription.class::isInstance) - .map(DiagramDescription.class::cast) - .findFirst() - .map(EObject::eResource); - }) - .filter(Resource.class::isInstance) - .map(Resource.class::cast) - .map(resource -> resource.getURI().path().substring(1)) - .orElse(""); - - var getObjectIdInput = new ExecuteEditingContextFunctionInput(UUID.randomUUID(), StudioIdentifiers.EMPTY_STUDIO_PROJECT.toString(), getObjectIdFunction); + BiFunction getObjectIdFunction = (editingContext, executeEditingContextFunctionInput) -> { + var id = Optional.of(editingContext) + .filter(IEMFEditingContext.class::isInstance) + .map(IEMFEditingContext.class::cast) + .flatMap(emfEditingContext -> { + var iterator = emfEditingContext.getDomain().getResourceSet().getAllContents(); + var stream = StreamSupport.stream(Spliterators.spliteratorUnknownSize(iterator, Spliterator.ORDERED), false); + return stream.filter(DiagramDescription.class::isInstance) + .map(DiagramDescription.class::cast) + .findFirst() + .map(EObject::eResource); + }) + .filter(Resource.class::isInstance) + .map(Resource.class::cast) + .map(resource -> resource.getURI().path().substring(1)) + .orElse(""); + return new ExecuteEditingContextFunctionSuccessPayload(executeEditingContextFunctionInput.id(), id); + }; + + var getObjectIdInput = new ExecuteEditingContextFunctionInput(UUID.randomUUID(), StudioIdentifiers.EMPTY_STUDIO_PROJECT.toString(), getObjectIdFunction, new ChangeDescription(ChangeKind.SEMANTIC_CHANGE, StudioIdentifiers.EMPTY_STUDIO_PROJECT.toString(), createViewInput)); var payload = this.executeEditingContextFunctionRunner.execute(getObjectIdInput).block(); - objectId.set(payload.result().toString()); - - var optionalEditingContextEventProcessor = this.editingContextEventProcessorRegistry.getEditingContextEventProcessors().stream() - .filter(editingContextEventProcessor -> editingContextEventProcessor.getEditingContextId().equals(StudioIdentifiers.EMPTY_STUDIO_PROJECT.toString())) - .findFirst(); - optionalEditingContextEventProcessor.ifPresentOrElse(editingContextEventProcessor -> { - editingContextEventProcessor.getRepresentationEventProcessors() - .forEach(representationEventProcessor -> representationEventProcessor.refresh(new ChangeDescription(ChangeKind.SEMANTIC_CHANGE, StudioIdentifiers.EMPTY_STUDIO_PROJECT.toString(), createViewInput))); - }, () -> fail("Missing editing context event processor")); + assertThat(payload).isInstanceOf(ExecuteEditingContextFunctionSuccessPayload.class); + ExecuteEditingContextFunctionSuccessPayload successPayload = (ExecuteEditingContextFunctionSuccessPayload) payload; + objectId.set(successPayload.result().toString()); }; Consumer updatedTreeContentConsumer = object -> this.getTreeSubscriptionConsumer(tree -> { diff --git a/packages/sirius-web/backend/sirius-web/src/test/java/org/eclipse/sirius/web/application/controllers/trees/ExplorerTreePathControllerTests.java b/packages/sirius-web/backend/sirius-web/src/test/java/org/eclipse/sirius/web/application/controllers/trees/ExplorerTreePathControllerTests.java index 11a8f0affe..eefcec1b12 100644 --- a/packages/sirius-web/backend/sirius-web/src/test/java/org/eclipse/sirius/web/application/controllers/trees/ExplorerTreePathControllerTests.java +++ b/packages/sirius-web/backend/sirius-web/src/test/java/org/eclipse/sirius/web/application/controllers/trees/ExplorerTreePathControllerTests.java @@ -25,20 +25,22 @@ import java.util.Spliterators; import java.util.UUID; import java.util.concurrent.atomic.AtomicReference; +import java.util.function.BiFunction; import java.util.function.Consumer; -import java.util.function.Function; import java.util.stream.StreamSupport; import org.eclipse.sirius.components.collaborative.api.ChangeDescription; import org.eclipse.sirius.components.collaborative.api.ChangeKind; -import org.eclipse.sirius.components.collaborative.api.IEditingContextEventProcessorRegistry; import org.eclipse.sirius.components.collaborative.trees.dto.TreeEventInput; import org.eclipse.sirius.components.collaborative.trees.dto.TreeRefreshedEventPayload; import org.eclipse.sirius.components.core.api.IEditingContext; import org.eclipse.sirius.components.core.api.IIdentityService; +import org.eclipse.sirius.components.core.api.IInput; +import org.eclipse.sirius.components.core.api.IPayload; import org.eclipse.sirius.components.emf.services.api.IEMFEditingContext; import org.eclipse.sirius.components.graphql.tests.ExecuteEditingContextFunctionInput; import org.eclipse.sirius.components.graphql.tests.ExecuteEditingContextFunctionRunner; +import org.eclipse.sirius.components.graphql.tests.ExecuteEditingContextFunctionSuccessPayload; import org.eclipse.sirius.components.trees.tests.graphql.TreeEventSubscriptionRunner; import org.eclipse.sirius.components.trees.tests.graphql.TreePathQueryRunner; import org.eclipse.sirius.components.view.diagram.RectangularNodeStyleDescription; @@ -77,9 +79,6 @@ public class ExplorerTreePathControllerTests extends AbstractIntegrationTests { @Autowired private ExecuteEditingContextFunctionRunner executeEditingContextFunctionRunner; - @Autowired - private IEditingContextEventProcessorRegistry editingContextEventProcessorRegistry; - @Autowired private PapayaViewInjector papayaViewInjector; @@ -121,30 +120,27 @@ public void givenStudioWhenWeAskForTheTreePathOfAnObjectThenItsPathInTheExplorer var createViewInput = new ExecuteEditingContextFunctionInput(UUID.randomUUID(), StudioIdentifiers.EMPTY_STUDIO_PROJECT.toString(), this.papayaViewInjector); this.executeEditingContextFunctionRunner.execute(createViewInput).block(); - Function getObjectIdFunction = editingContext -> Optional.of(editingContext) - .filter(IEMFEditingContext.class::isInstance) - .map(IEMFEditingContext.class::cast) - .flatMap(emfEditingContext -> { - var iterator = emfEditingContext.getDomain().getResourceSet().getAllContents(); - var stream = StreamSupport.stream(Spliterators.spliteratorUnknownSize(iterator, Spliterator.ORDERED), false); - return stream.filter(RectangularNodeStyleDescription.class::isInstance) - .findFirst(); - }) - .map(this.identityService::getId) - .orElse(""); - - var getObjectIdInput = new ExecuteEditingContextFunctionInput(UUID.randomUUID(), StudioIdentifiers.EMPTY_STUDIO_PROJECT.toString(), getObjectIdFunction); + BiFunction getObjectIdFunction = (editingContext, executeEditingContextFunctionInput) -> { + var id = Optional.of(editingContext) + .filter(IEMFEditingContext.class::isInstance) + .map(IEMFEditingContext.class::cast) + .flatMap(emfEditingContext -> { + var iterator = emfEditingContext.getDomain().getResourceSet().getAllContents(); + var stream = StreamSupport.stream(Spliterators.spliteratorUnknownSize(iterator, Spliterator.ORDERED), false); + return stream.filter(RectangularNodeStyleDescription.class::isInstance) + .findFirst(); + }) + .map(this.identityService::getId) + .orElse(""); + return new ExecuteEditingContextFunctionSuccessPayload(executeEditingContextFunctionInput.id(), id); + }; + + var getObjectIdInput = new ExecuteEditingContextFunctionInput(UUID.randomUUID(), StudioIdentifiers.EMPTY_STUDIO_PROJECT.toString(), getObjectIdFunction, new ChangeDescription(ChangeKind.SEMANTIC_CHANGE, StudioIdentifiers.EMPTY_STUDIO_PROJECT.toString(), createViewInput)); var payload = this.executeEditingContextFunctionRunner.execute(getObjectIdInput).block(); - objectId.set(payload.result().toString()); - - var optionalEditingContextEventProcessor = this.editingContextEventProcessorRegistry.getEditingContextEventProcessors().stream() - .filter(editingContextEventProcessor -> editingContextEventProcessor.getEditingContextId().equals(StudioIdentifiers.EMPTY_STUDIO_PROJECT.toString())) - .findFirst(); - optionalEditingContextEventProcessor.ifPresentOrElse(editingContextEventProcessor -> { - editingContextEventProcessor.getRepresentationEventProcessors() - .forEach(representationEventProcessor -> representationEventProcessor.refresh(new ChangeDescription(ChangeKind.SEMANTIC_CHANGE, StudioIdentifiers.EMPTY_STUDIO_PROJECT.toString(), createViewInput))); - }, () -> fail("Missing editing context event processor")); + assertThat(payload).isInstanceOf(ExecuteEditingContextFunctionSuccessPayload.class); + ExecuteEditingContextFunctionSuccessPayload successPayload = (ExecuteEditingContextFunctionSuccessPayload) payload; + objectId.set(successPayload.result().toString()); }; Consumer updatedTreeContentConsumer = object -> Optional.of(object) diff --git a/packages/sirius-web/backend/sirius-web/src/test/java/org/eclipse/sirius/web/services/PapayaViewInjector.java b/packages/sirius-web/backend/sirius-web/src/test/java/org/eclipse/sirius/web/services/PapayaViewInjector.java index 535f637f5f..44ef2574fa 100644 --- a/packages/sirius-web/backend/sirius-web/src/test/java/org/eclipse/sirius/web/services/PapayaViewInjector.java +++ b/packages/sirius-web/backend/sirius-web/src/test/java/org/eclipse/sirius/web/services/PapayaViewInjector.java @@ -12,11 +12,16 @@ *******************************************************************************/ package org.eclipse.sirius.web.services; +import java.util.List; import java.util.Objects; -import java.util.function.Function; +import java.util.function.BiFunction; +import org.eclipse.sirius.components.core.api.ErrorPayload; import org.eclipse.sirius.components.core.api.IEditingContext; +import org.eclipse.sirius.components.core.api.IInput; +import org.eclipse.sirius.components.core.api.IPayload; import org.eclipse.sirius.components.emf.services.api.IEMFEditingContext; +import org.eclipse.sirius.components.graphql.tests.ExecuteEditingContextFunctionSuccessPayload; import org.eclipse.sirius.web.papaya.services.PapayaViewProvider; import org.springframework.stereotype.Service; @@ -26,7 +31,7 @@ * @author sbegaudeau */ @Service -public class PapayaViewInjector implements Function { +public class PapayaViewInjector implements BiFunction { private final PapayaViewProvider papayaViewProvider; @@ -35,13 +40,13 @@ public PapayaViewInjector(PapayaViewProvider papayaViewProvider) { } @Override - public Object apply(IEditingContext editingContext) { + public IPayload apply(IEditingContext editingContext, IInput input) { if (editingContext instanceof IEMFEditingContext emfEditingContext) { var view = this.papayaViewProvider.create(); emfEditingContext.getDomain().getResourceSet().getResources().add(view.eResource()); - return true; + return new ExecuteEditingContextFunctionSuccessPayload(input.id(), null); } - return false; + return new ErrorPayload(input.id(), "Invalid editing context", List.of()); } } diff --git a/packages/sirius-web/backend/sirius-web/src/test/java/org/eclipse/sirius/web/services/migration/NodeDescriptionLabelExpressionMigrationParticipantTests.java b/packages/sirius-web/backend/sirius-web/src/test/java/org/eclipse/sirius/web/services/migration/NodeDescriptionLabelExpressionMigrationParticipantTests.java index 84ef8dfc04..1a5eb2a348 100644 --- a/packages/sirius-web/backend/sirius-web/src/test/java/org/eclipse/sirius/web/services/migration/NodeDescriptionLabelExpressionMigrationParticipantTests.java +++ b/packages/sirius-web/backend/sirius-web/src/test/java/org/eclipse/sirius/web/services/migration/NodeDescriptionLabelExpressionMigrationParticipantTests.java @@ -22,11 +22,13 @@ import java.util.List; import java.util.Optional; import java.util.UUID; -import java.util.function.Function; +import java.util.function.BiFunction; import java.util.function.Predicate; import org.eclipse.sirius.components.core.api.IEditingContext; import org.eclipse.sirius.components.core.api.IEditingContextSearchService; +import org.eclipse.sirius.components.core.api.IInput; +import org.eclipse.sirius.components.core.api.IPayload; import org.eclipse.sirius.components.emf.ResourceMetadataAdapter; import org.eclipse.sirius.components.emf.migration.api.IMigrationParticipant; import org.eclipse.sirius.components.emf.migration.api.MigrationData; @@ -173,7 +175,9 @@ private void uploadDocument(String editingContextId, String name, String content String typename = JsonPath.read(result, "$.data.uploadDocument.__typename"); assertThat(typename).isEqualTo(UploadDocumentSuccessPayload.class.getSimpleName()); - Predicate predicate = payload -> Optional.of(payload) + Predicate predicate = payload -> Optional.of(payload) + .filter(ExecuteEditingContextFunctionSuccessPayload.class::isInstance) + .map(ExecuteEditingContextFunctionSuccessPayload.class::cast) .map(ExecuteEditingContextFunctionSuccessPayload::result) .filter(Boolean.class::isInstance) .map(Boolean.class::cast) @@ -186,18 +190,21 @@ private void uploadDocument(String editingContextId, String name, String content assertThat(optionalLastMigrationData).isPresent(); var lastMigrationData = optionalLastMigrationData.get(); - Function function = editingContext -> Optional.of(editingContext) - .filter(EditingContext.class::isInstance) - .map(EditingContext.class::cast) - .map(siriusWebEditingContext -> siriusWebEditingContext.getViews().stream() - .anyMatch(view -> view.eResource().eAdapters().stream() - .filter(adapter -> adapter instanceof ResourceMetadataAdapter) - .map(ResourceMetadataAdapter.class::cast) - .filter(resourceMetadataAdapter -> resourceMetadataAdapter.getMigrationData() != null) - .anyMatch(resourceMetadataAdapter -> resourceMetadataAdapter.getMigrationData().migrationVersion().equals(lastMigrationData.migrationVersion()) - && resourceMetadataAdapter.getMigrationData().lastMigrationPerformed().equals(lastMigrationData.lastMigrationPerformed())) - )) - .orElse(false); + BiFunction function = (editingContext, executeEditingContextFunctionInput) -> { + var isMigrated = Optional.of(editingContext) + .filter(EditingContext.class::isInstance) + .map(EditingContext.class::cast) + .map(siriusWebEditingContext -> siriusWebEditingContext.getViews().stream() + .anyMatch(view -> view.eResource().eAdapters().stream() + .filter(ResourceMetadataAdapter.class::isInstance) + .map(ResourceMetadataAdapter.class::cast) + .filter(resourceMetadataAdapter -> resourceMetadataAdapter.getMigrationData() != null) + .anyMatch(resourceMetadataAdapter -> resourceMetadataAdapter.getMigrationData().migrationVersion().equals(lastMigrationData.migrationVersion()) + && resourceMetadataAdapter.getMigrationData().lastMigrationPerformed().equals(lastMigrationData.lastMigrationPerformed())) + )) + .orElse(false); + return new ExecuteEditingContextFunctionSuccessPayload(executeEditingContextFunctionInput.id(), isMigrated); + }; var mono = this.executeEditingContextFunctionRunner.execute(new ExecuteEditingContextFunctionInput(UUID.randomUUID(), editingContextId, function)); StepVerifier.create(mono) diff --git a/packages/sirius-web/backend/sirius-web/src/test/java/org/eclipse/sirius/web/services/migration/NodeStyleDescriptionColorMigrationParticipantTests.java b/packages/sirius-web/backend/sirius-web/src/test/java/org/eclipse/sirius/web/services/migration/NodeStyleDescriptionColorMigrationParticipantTests.java index e6539766d0..caf6222401 100644 --- a/packages/sirius-web/backend/sirius-web/src/test/java/org/eclipse/sirius/web/services/migration/NodeStyleDescriptionColorMigrationParticipantTests.java +++ b/packages/sirius-web/backend/sirius-web/src/test/java/org/eclipse/sirius/web/services/migration/NodeStyleDescriptionColorMigrationParticipantTests.java @@ -22,11 +22,13 @@ import java.util.List; import java.util.Optional; import java.util.UUID; -import java.util.function.Function; +import java.util.function.BiFunction; import java.util.function.Predicate; import org.eclipse.sirius.components.core.api.IEditingContext; import org.eclipse.sirius.components.core.api.IEditingContextSearchService; +import org.eclipse.sirius.components.core.api.IInput; +import org.eclipse.sirius.components.core.api.IPayload; import org.eclipse.sirius.components.emf.ResourceMetadataAdapter; import org.eclipse.sirius.components.emf.migration.api.IMigrationParticipant; import org.eclipse.sirius.components.emf.migration.api.MigrationData; @@ -176,7 +178,9 @@ private void uploadDocument(String editingContextId, String content) { String typename = JsonPath.read(result, "$.data.uploadDocument.__typename"); assertThat(typename).isEqualTo(UploadDocumentSuccessPayload.class.getSimpleName()); - Predicate predicate = payload -> Optional.of(payload) + Predicate predicate = payload -> Optional.of(payload) + .filter(ExecuteEditingContextFunctionSuccessPayload.class::isInstance) + .map(ExecuteEditingContextFunctionSuccessPayload.class::cast) .map(ExecuteEditingContextFunctionSuccessPayload::result) .filter(Boolean.class::isInstance) .map(Boolean.class::cast) @@ -189,18 +193,21 @@ private void uploadDocument(String editingContextId, String content) { assertThat(optionalLastMigrationData).isPresent(); var lastMigrationData = optionalLastMigrationData.get(); - Function function = editingContext -> Optional.of(editingContext) - .filter(EditingContext.class::isInstance) - .map(EditingContext.class::cast) - .map(siriusWebEditingContext -> siriusWebEditingContext.getViews().stream() - .anyMatch(view -> view.eResource().eAdapters().stream() - .filter(ResourceMetadataAdapter.class::isInstance) - .map(ResourceMetadataAdapter.class::cast) - .filter(resourceMetadataAdapter -> resourceMetadataAdapter.getMigrationData() != null) - .anyMatch(resourceMetadataAdapter -> resourceMetadataAdapter.getMigrationData().migrationVersion().equals(lastMigrationData.migrationVersion()) - && resourceMetadataAdapter.getMigrationData().lastMigrationPerformed().equals(lastMigrationData.lastMigrationPerformed())) - )) - .orElse(false); + BiFunction function = (editingContext, executeEditingContextFunctionInput) -> { + var isMigrated = Optional.of(editingContext) + .filter(EditingContext.class::isInstance) + .map(EditingContext.class::cast) + .map(siriusWebEditingContext -> siriusWebEditingContext.getViews().stream() + .anyMatch(view -> view.eResource().eAdapters().stream() + .filter(ResourceMetadataAdapter.class::isInstance) + .map(ResourceMetadataAdapter.class::cast) + .filter(resourceMetadataAdapter -> resourceMetadataAdapter.getMigrationData() != null) + .anyMatch(resourceMetadataAdapter -> resourceMetadataAdapter.getMigrationData().migrationVersion().equals(lastMigrationData.migrationVersion()) + && resourceMetadataAdapter.getMigrationData().lastMigrationPerformed().equals(lastMigrationData.lastMigrationPerformed())) + )) + .orElse(false); + return new ExecuteEditingContextFunctionSuccessPayload(executeEditingContextFunctionInput.id(), isMigrated); + }; var mono = this.executeEditingContextFunctionRunner.execute(new ExecuteEditingContextFunctionInput(UUID.randomUUID(), editingContextId, function)); StepVerifier.create(mono) diff --git a/packages/tests/backend/sirius-components-graphql-tests/src/main/java/org/eclipse/sirius/components/graphql/tests/ExecuteEditingContextFunctionEventHandler.java b/packages/tests/backend/sirius-components-graphql-tests/src/main/java/org/eclipse/sirius/components/graphql/tests/ExecuteEditingContextFunctionEventHandler.java index d859fb998d..ab71f804af 100644 --- a/packages/tests/backend/sirius-components-graphql-tests/src/main/java/org/eclipse/sirius/components/graphql/tests/ExecuteEditingContextFunctionEventHandler.java +++ b/packages/tests/backend/sirius-components-graphql-tests/src/main/java/org/eclipse/sirius/components/graphql/tests/ExecuteEditingContextFunctionEventHandler.java @@ -12,8 +12,12 @@ *******************************************************************************/ package org.eclipse.sirius.components.graphql.tests; +import java.util.Objects; + import org.eclipse.sirius.components.collaborative.api.ChangeDescription; +import org.eclipse.sirius.components.collaborative.api.ChangeKind; import org.eclipse.sirius.components.collaborative.api.IEditingContextEventHandler; +import org.eclipse.sirius.components.collaborative.messages.ICollaborativeMessageService; import org.eclipse.sirius.components.core.api.ErrorPayload; import org.eclipse.sirius.components.core.api.IEditingContext; import org.eclipse.sirius.components.core.api.IInput; @@ -29,17 +33,36 @@ */ @Service public class ExecuteEditingContextFunctionEventHandler implements IEditingContextEventHandler { + + private ICollaborativeMessageService messageService; + + public ExecuteEditingContextFunctionEventHandler(ICollaborativeMessageService messageService) { + this.messageService = Objects.requireNonNull(messageService); + } + @Override public boolean canHandle(IEditingContext editingContext, IInput input) { return input instanceof ExecuteEditingContextFunctionInput; } @Override + @SuppressWarnings("checkstyle:IllegalCatch") public void handle(Sinks.One payloadSink, Sinks.Many changeDescriptionSink, IEditingContext editingContext, IInput input) { + String message = this.messageService.invalidInput(input.getClass().getSimpleName(), ExecuteEditingContextFunctionInput.class.getSimpleName()); + IPayload payload = new ErrorPayload(input.id(), message); + ChangeDescription changeDescription = new ChangeDescription(ChangeKind.NOTHING, editingContext.getId(), input); + if (input instanceof ExecuteEditingContextFunctionInput executeEditingContextFunctionInput) { - var result = executeEditingContextFunctionInput.function().apply(editingContext); - payloadSink.tryEmitValue(new ExecuteEditingContextFunctionSuccessPayload(input.id(), result)); + changeDescription = executeEditingContextFunctionInput.changeDescription(); + + try { + payload = executeEditingContextFunctionInput.function().apply(editingContext, input); + } catch (Exception exception) { + payload = new ErrorPayload(input.id(), exception.getMessage()); + } } - payloadSink.tryEmitValue(new ErrorPayload(input.id(), "Invalid payload")); + + payloadSink.tryEmitValue(payload); + changeDescriptionSink.tryEmitNext(changeDescription); } } diff --git a/packages/tests/backend/sirius-components-graphql-tests/src/main/java/org/eclipse/sirius/components/graphql/tests/ExecuteEditingContextFunctionInput.java b/packages/tests/backend/sirius-components-graphql-tests/src/main/java/org/eclipse/sirius/components/graphql/tests/ExecuteEditingContextFunctionInput.java index 847e183635..30b73f35d8 100644 --- a/packages/tests/backend/sirius-components-graphql-tests/src/main/java/org/eclipse/sirius/components/graphql/tests/ExecuteEditingContextFunctionInput.java +++ b/packages/tests/backend/sirius-components-graphql-tests/src/main/java/org/eclipse/sirius/components/graphql/tests/ExecuteEditingContextFunctionInput.java @@ -13,15 +13,26 @@ package org.eclipse.sirius.components.graphql.tests; import java.util.UUID; -import java.util.function.Function; +import java.util.function.BiFunction; +import org.eclipse.sirius.components.collaborative.api.ChangeDescription; +import org.eclipse.sirius.components.collaborative.api.ChangeKind; import org.eclipse.sirius.components.core.api.IEditingContext; import org.eclipse.sirius.components.core.api.IInput; +import org.eclipse.sirius.components.core.api.IPayload; /** * Used to execute some function on the editing context. * * @author sbegaudeau */ -public record ExecuteEditingContextFunctionInput(UUID id, String editingContextId, Function function) implements IInput { +public record ExecuteEditingContextFunctionInput( + UUID id, + String editingContextId, + BiFunction function, + ChangeDescription changeDescription) implements IInput { + + public ExecuteEditingContextFunctionInput(UUID id, String editingContextId, BiFunction function) { + this(id, editingContextId, function, new ChangeDescription(ChangeKind.NOTHING, editingContextId, () -> id)); + } } diff --git a/packages/tests/backend/sirius-components-graphql-tests/src/main/java/org/eclipse/sirius/components/graphql/tests/ExecuteEditingContextFunctionRunner.java b/packages/tests/backend/sirius-components-graphql-tests/src/main/java/org/eclipse/sirius/components/graphql/tests/ExecuteEditingContextFunctionRunner.java index 766c7c0bed..374e7c24b0 100644 --- a/packages/tests/backend/sirius-components-graphql-tests/src/main/java/org/eclipse/sirius/components/graphql/tests/ExecuteEditingContextFunctionRunner.java +++ b/packages/tests/backend/sirius-components-graphql-tests/src/main/java/org/eclipse/sirius/components/graphql/tests/ExecuteEditingContextFunctionRunner.java @@ -14,6 +14,7 @@ import java.util.Objects; +import org.eclipse.sirius.components.core.api.IPayload; import org.eclipse.sirius.components.graphql.api.IEditingContextDispatcher; import org.eclipse.sirius.components.graphql.tests.api.IExecuteEditingContextFunctionRunner; import org.springframework.stereotype.Service; @@ -35,9 +36,7 @@ public ExecuteEditingContextFunctionRunner(IEditingContextDispatcher editingCont } @Override - public Mono execute(ExecuteEditingContextFunctionInput input) { - return this.editingContextDispatcher.dispatchMutation(input.editingContextId(), input) - .filter(ExecuteEditingContextFunctionSuccessPayload.class::isInstance) - .map(ExecuteEditingContextFunctionSuccessPayload.class::cast); + public Mono execute(ExecuteEditingContextFunctionInput input) { + return this.editingContextDispatcher.dispatchMutation(input.editingContextId(), input); } } diff --git a/packages/tests/backend/sirius-components-graphql-tests/src/main/java/org/eclipse/sirius/components/graphql/tests/api/IExecuteEditingContextFunctionRunner.java b/packages/tests/backend/sirius-components-graphql-tests/src/main/java/org/eclipse/sirius/components/graphql/tests/api/IExecuteEditingContextFunctionRunner.java index 7f6a0dc721..7e8e400bf9 100644 --- a/packages/tests/backend/sirius-components-graphql-tests/src/main/java/org/eclipse/sirius/components/graphql/tests/api/IExecuteEditingContextFunctionRunner.java +++ b/packages/tests/backend/sirius-components-graphql-tests/src/main/java/org/eclipse/sirius/components/graphql/tests/api/IExecuteEditingContextFunctionRunner.java @@ -12,8 +12,8 @@ *******************************************************************************/ package org.eclipse.sirius.components.graphql.tests.api; +import org.eclipse.sirius.components.core.api.IPayload; import org.eclipse.sirius.components.graphql.tests.ExecuteEditingContextFunctionInput; -import org.eclipse.sirius.components.graphql.tests.ExecuteEditingContextFunctionSuccessPayload; import reactor.core.publisher.Mono; @@ -23,5 +23,5 @@ * @author sbegaudeau */ public interface IExecuteEditingContextFunctionRunner { - Mono execute(ExecuteEditingContextFunctionInput input); + Mono execute(ExecuteEditingContextFunctionInput input); }