Skip to content

Commit

Permalink
[3606] Improve error handling for ExecuteEditingContextFunction
Browse files Browse the repository at this point in the history
Bug: #3606
Signed-off-by: Gwendal Daniel <[email protected]>
  • Loading branch information
gdaniel authored and sbegaudeau committed Jun 17, 2024
1 parent baf25fa commit 2132ea8
Show file tree
Hide file tree
Showing 11 changed files with 184 additions and 127 deletions.
5 changes: 3 additions & 2 deletions CHANGELOG.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<IEditingContext, Object> 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<IEditingContext, IInput, IPayload> 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<ExecuteEditingContextFunctionSuccessPayload> predicate = payload -> Optional.of(payload)
Predicate<IPayload> predicate = payload -> Optional.of(payload)
.filter(ExecuteEditingContextFunctionSuccessPayload.class::isInstance)
.map(ExecuteEditingContextFunctionSuccessPayload.class::cast)
.map(ExecuteEditingContextFunctionSuccessPayload::result)
.filter(Boolean.class::isInstance)
.map(Boolean.class::cast)
Expand Down Expand Up @@ -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<IEditingContext, Object> 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<IEditingContext, IInput, IPayload> 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<ExecuteEditingContextFunctionSuccessPayload> predicate = payload -> Optional.of(payload)
Predicate<IPayload> predicate = payload -> Optional.of(payload)
.filter(ExecuteEditingContextFunctionSuccessPayload.class::isInstance)
.map(ExecuteEditingContextFunctionSuccessPayload.class::cast)
.map(ExecuteEditingContextFunctionSuccessPayload::result)
.filter(Boolean.class::isInstance)
.map(Boolean.class::cast)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -81,9 +83,6 @@ public class ExplorerExpandAllControllerTests extends AbstractIntegrationTests {
@Autowired
private ExecuteEditingContextFunctionRunner executeEditingContextFunctionRunner;

@Autowired
private IEditingContextEventProcessorRegistry editingContextEventProcessorRegistry;

@Autowired
private PapayaViewInjector papayaViewInjector;

Expand Down Expand Up @@ -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<IEditingContext, Object> 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<IEditingContext, IInput, IPayload> 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<Object> updatedTreeContentConsumer = object -> this.getTreeSubscriptionConsumer(tree -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -77,9 +79,6 @@ public class ExplorerTreePathControllerTests extends AbstractIntegrationTests {
@Autowired
private ExecuteEditingContextFunctionRunner executeEditingContextFunctionRunner;

@Autowired
private IEditingContextEventProcessorRegistry editingContextEventProcessorRegistry;

@Autowired
private PapayaViewInjector papayaViewInjector;

Expand Down Expand Up @@ -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<IEditingContext, Object> 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<IEditingContext, IInput, IPayload> 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<Object> updatedTreeContentConsumer = object -> Optional.of(object)
Expand Down
Loading

0 comments on commit 2132ea8

Please sign in to comment.