Search in sources :

Example 1 with IEditingContext

use of org.eclipse.sirius.components.core.api.IEditingContext in project sirius-components by eclipse-sirius.

the class EditingContextEventProcessorRegistry method getOrCreateEditingContextEventProcessor.

@Override
public synchronized Optional<IEditingContextEventProcessor> getOrCreateEditingContextEventProcessor(String editingContextId) {
    Optional<IEditingContextEventProcessor> optionalEditingContextEventProcessor = Optional.empty();
    if (this.editingContextSearchService.existsById(editingContextId)) {
        optionalEditingContextEventProcessor = Optional.ofNullable(this.editingContextEventProcessors.get(editingContextId)).map(EditingContextEventProcessorEntry::getEditingContextEventProcessor);
        if (optionalEditingContextEventProcessor.isEmpty()) {
            Optional<IEditingContext> optionalEditingContext = this.editingContextSearchService.findById(editingContextId);
            if (optionalEditingContext.isPresent()) {
                IEditingContext editingContext = optionalEditingContext.get();
                var editingContextEventProcessor = this.editingContextEventProcessorFactory.createEditingContextEventProcessor(editingContext);
                Disposable subscription = editingContextEventProcessor.canBeDisposed().delayElements(this.disposeDelay).subscribe(canBeDisposed -> {
                    // We will check if the editing context event processor is still empty
                    if (canBeDisposed.booleanValue() && editingContextEventProcessor.getRepresentationEventProcessors().isEmpty()) {
                        this.disposeEditingContextEventProcessor(editingContextId);
                    } else {
                        // $NON-NLS-1$
                        this.logger.trace("Stopping the disposal of the editing context");
                    }
                });
                var editingContextEventProcessorEntry = new EditingContextEventProcessorEntry(editingContextEventProcessor, subscription);
                this.editingContextEventProcessors.put(editingContextId, editingContextEventProcessorEntry);
                optionalEditingContextEventProcessor = Optional.of(editingContextEventProcessor);
            }
        }
    }
    return optionalEditingContextEventProcessor;
}
Also used : Disposable(reactor.core.Disposable) IEditingContext(org.eclipse.sirius.components.core.api.IEditingContext) IEditingContextEventProcessor(org.eclipse.sirius.components.collaborative.api.IEditingContextEventProcessor)

Example 2 with IEditingContext

use of org.eclipse.sirius.components.core.api.IEditingContext in project sirius-components by eclipse-sirius.

the class QueryBasedBooleanEventHandlerTests method testQueryBasedBooleanFailed.

@Test
public void testQueryBasedBooleanFailed() {
    IQueryService queryService = new IQueryService.NoOp() {

        @Override
        public IPayload execute(IEditingContext editingContext, QueryBasedBooleanInput input) {
            // $NON-NLS-1$
            return new ErrorPayload(UUID.randomUUID(), "An error occured");
        }
    };
    Many<ChangeDescription> changeDescriptionSink = Sinks.many().unicast().onBackpressureBuffer();
    One<IPayload> payloadSink = Sinks.one();
    this.handle(payloadSink, changeDescriptionSink, queryService);
    ChangeDescription changeDescription = changeDescriptionSink.asFlux().blockFirst();
    assertThat(changeDescription.getKind()).isEqualTo(ChangeKind.NOTHING);
    IPayload payload = payloadSink.asMono().block();
    assertThat(payload).isInstanceOf(ErrorPayload.class);
}
Also used : ErrorPayload(org.eclipse.sirius.components.core.api.ErrorPayload) IQueryService(org.eclipse.sirius.components.collaborative.api.IQueryService) IEditingContext(org.eclipse.sirius.components.core.api.IEditingContext) ChangeDescription(org.eclipse.sirius.components.collaborative.api.ChangeDescription) QueryBasedBooleanInput(org.eclipse.sirius.components.collaborative.dto.QueryBasedBooleanInput) IPayload(org.eclipse.sirius.components.core.api.IPayload) Test(org.junit.jupiter.api.Test)

Example 3 with IEditingContext

use of org.eclipse.sirius.components.core.api.IEditingContext in project sirius-components by eclipse-sirius.

the class QueryBasedIntEventHandlerTests method handle.

private void handle(One<IPayload> payloadSink, Many<ChangeDescription> changeDescriptionSink, IQueryService queryService) {
    QueryBasedIntEventHandler queryBasedIntEventHandler = new QueryBasedIntEventHandler(new ICollaborativeMessageService.NoOp(), new SimpleMeterRegistry(), queryService);
    // $NON-NLS-1$
    IInput input = new QueryBasedIntInput(UUID.randomUUID(), "", Map.of());
    assertThat(queryBasedIntEventHandler.canHandle(new IEditingContext.NoOp(), input)).isTrue();
    IEditingContext editingContext = () -> UUID.randomUUID().toString();
    queryBasedIntEventHandler.handle(payloadSink, changeDescriptionSink, editingContext, input);
}
Also used : QueryBasedIntInput(org.eclipse.sirius.components.collaborative.dto.QueryBasedIntInput) ICollaborativeMessageService(org.eclipse.sirius.components.collaborative.messages.ICollaborativeMessageService) IEditingContext(org.eclipse.sirius.components.core.api.IEditingContext) SimpleMeterRegistry(io.micrometer.core.instrument.simple.SimpleMeterRegistry) IInput(org.eclipse.sirius.components.core.api.IInput)

Example 4 with IEditingContext

use of org.eclipse.sirius.components.core.api.IEditingContext in project sirius-components by eclipse-sirius.

the class QueryBasedIntEventHandlerTests method testQueryBasedInt.

@Test
public void testQueryBasedInt() {
    IQueryService queryService = new IQueryService.NoOp() {

        @Override
        public IPayload execute(IEditingContext editingContext, QueryBasedIntInput input) {
            return new QueryBasedIntSuccessPayload(UUID.randomUUID(), EXPECTED_RESULT_10);
        }
    };
    Many<ChangeDescription> changeDescriptionSink = Sinks.many().unicast().onBackpressureBuffer();
    One<IPayload> payloadSink = Sinks.one();
    this.handle(payloadSink, changeDescriptionSink, queryService);
    ChangeDescription changeDescription = changeDescriptionSink.asFlux().blockFirst();
    assertThat(changeDescription.getKind()).isEqualTo(ChangeKind.NOTHING);
    IPayload payload = payloadSink.asMono().block();
    assertThat(payload).isInstanceOf(QueryBasedIntSuccessPayload.class);
    assertThat(((QueryBasedIntSuccessPayload) payload).getResult()).isEqualTo(EXPECTED_RESULT_10);
}
Also used : QueryBasedIntInput(org.eclipse.sirius.components.collaborative.dto.QueryBasedIntInput) QueryBasedIntSuccessPayload(org.eclipse.sirius.components.collaborative.dto.QueryBasedIntSuccessPayload) IQueryService(org.eclipse.sirius.components.collaborative.api.IQueryService) IEditingContext(org.eclipse.sirius.components.core.api.IEditingContext) ChangeDescription(org.eclipse.sirius.components.collaborative.api.ChangeDescription) IPayload(org.eclipse.sirius.components.core.api.IPayload) Test(org.junit.jupiter.api.Test)

Example 5 with IEditingContext

use of org.eclipse.sirius.components.core.api.IEditingContext in project sirius-components by eclipse-sirius.

the class QueryBasedObjectEventHandlerTests method testQueryBasedObjectFailed.

@Test
public void testQueryBasedObjectFailed() {
    IQueryService queryService = new IQueryService.NoOp() {

        @Override
        public IPayload execute(IEditingContext editingContext, QueryBasedObjectInput input) {
            // $NON-NLS-1$
            return new ErrorPayload(UUID.randomUUID(), "An error occured");
        }
    };
    Many<ChangeDescription> changeDescriptionSink = Sinks.many().unicast().onBackpressureBuffer();
    One<IPayload> payloadSink = Sinks.one();
    this.handle(payloadSink, changeDescriptionSink, queryService);
    ChangeDescription changeDescription = changeDescriptionSink.asFlux().blockFirst();
    assertThat(changeDescription.getKind()).isEqualTo(ChangeKind.NOTHING);
    IPayload payload = payloadSink.asMono().block();
    assertThat(payload).isInstanceOf(ErrorPayload.class);
}
Also used : ErrorPayload(org.eclipse.sirius.components.core.api.ErrorPayload) IQueryService(org.eclipse.sirius.components.collaborative.api.IQueryService) IEditingContext(org.eclipse.sirius.components.core.api.IEditingContext) ChangeDescription(org.eclipse.sirius.components.collaborative.api.ChangeDescription) QueryBasedObjectInput(org.eclipse.sirius.components.collaborative.dto.QueryBasedObjectInput) IPayload(org.eclipse.sirius.components.core.api.IPayload) Test(org.junit.jupiter.api.Test)

Aggregations

IEditingContext (org.eclipse.sirius.components.core.api.IEditingContext)58 IPayload (org.eclipse.sirius.components.core.api.IPayload)30 ChangeDescription (org.eclipse.sirius.components.collaborative.api.ChangeDescription)28 Test (org.junit.jupiter.api.Test)24 UUID (java.util.UUID)22 SimpleMeterRegistry (io.micrometer.core.instrument.simple.SimpleMeterRegistry)18 List (java.util.List)18 EditingContext (org.eclipse.sirius.components.emf.services.EditingContext)17 Objects (java.util.Objects)14 Optional (java.util.Optional)14 IObjectService (org.eclipse.sirius.components.core.api.IObjectService)14 AdapterFactoryEditingDomain (org.eclipse.emf.edit.domain.AdapterFactoryEditingDomain)12 IQueryService (org.eclipse.sirius.components.collaborative.api.IQueryService)12 ErrorPayload (org.eclipse.sirius.components.core.api.ErrorPayload)12 Service (org.springframework.stereotype.Service)12 ArrayList (java.util.ArrayList)11 Resource (org.eclipse.emf.ecore.resource.Resource)11 Collectors (java.util.stream.Collectors)10 ICollaborativeMessageService (org.eclipse.sirius.components.collaborative.messages.ICollaborativeMessageService)10 ResourceSet (org.eclipse.emf.ecore.resource.ResourceSet)9