Search in sources :

Example 1 with IInput

use of org.eclipse.sirius.components.core.api.IInput 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 2 with IInput

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

the class QueryBasedStringEventHandlerTests method handle.

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

Example 3 with IInput

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

the class EditingContextEventProcessor method handleInput.

private void handleInput(One<IPayload> payloadSink, IInput input) {
    if (input instanceof DeleteRepresentationInput) {
        DeleteRepresentationInput deleteRepresentationInput = (DeleteRepresentationInput) input;
        this.disposeRepresentation(deleteRepresentationInput.getRepresentationId());
    }
    // @formatter:off
    Optional<IEditingContextEventHandler> optionalEditingContextEventHandler = this.editingContextEventHandlers.stream().filter(handler -> handler.canHandle(this.editingContext, input)).findFirst();
    if (optionalEditingContextEventHandler.isPresent()) {
        IEditingContextEventHandler editingContextEventHandler = optionalEditingContextEventHandler.get();
        editingContextEventHandler.handle(payloadSink, this.changeDescriptionSink, this.editingContext, input);
    } else {
        // $NON-NLS-1$
        this.logger.warn("No handler found for event: {}", input);
    }
}
Also used : ErrorPayload(org.eclipse.sirius.components.core.api.ErrorPayload) Sinks(reactor.core.publisher.Sinks) IEditingContextEventProcessor(org.eclipse.sirius.components.collaborative.api.IEditingContextEventProcessor) IEditingContext(org.eclipse.sirius.components.core.api.IEditingContext) Disposable(reactor.core.Disposable) IRepresentationConfiguration(org.eclipse.sirius.components.collaborative.api.IRepresentationConfiguration) LoggerFactory(org.slf4j.LoggerFactory) One(reactor.core.publisher.Sinks.One) IDanglingRepresentationDeletionService(org.eclipse.sirius.components.collaborative.api.IDanglingRepresentationDeletionService) IInput(org.eclipse.sirius.components.core.api.IInput) ArrayList(java.util.ArrayList) Future(java.util.concurrent.Future) IEditingContextPersistenceService(org.eclipse.sirius.components.core.api.IEditingContextPersistenceService) IRepresentationEventProcessorComposedFactory(org.eclipse.sirius.components.collaborative.api.IRepresentationEventProcessorComposedFactory) Duration(java.time.Duration) Map(java.util.Map) IRepresentation(org.eclipse.sirius.components.representations.IRepresentation) ApplicationEventPublisher(org.springframework.context.ApplicationEventPublisher) ICollaborativeMessageService(org.eclipse.sirius.components.collaborative.messages.ICollaborativeMessageService) EmitResult(reactor.core.publisher.Sinks.EmitResult) Schedulers(reactor.core.scheduler.Schedulers) IRepresentationEventProcessor(org.eclipse.sirius.components.collaborative.api.IRepresentationEventProcessor) RepresentationRefreshedEvent(org.eclipse.sirius.components.collaborative.dto.RepresentationRefreshedEvent) ExecutorService(java.util.concurrent.ExecutorService) ChangeKind(org.eclipse.sirius.components.collaborative.api.ChangeKind) Logger(org.slf4j.Logger) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) ChangeDescription(org.eclipse.sirius.components.collaborative.api.ChangeDescription) RenameRepresentationInput(org.eclipse.sirius.components.collaborative.dto.RenameRepresentationInput) RepresentationRenamedEventPayload(org.eclipse.sirius.components.collaborative.dto.RepresentationRenamedEventPayload) Mono(reactor.core.publisher.Mono) UUID(java.util.UUID) IRepresentationInput(org.eclipse.sirius.components.core.api.IRepresentationInput) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) ExecutionException(java.util.concurrent.ExecutionException) Consumer(java.util.function.Consumer) Flux(reactor.core.publisher.Flux) List(java.util.List) IPayload(org.eclipse.sirius.components.core.api.IPayload) DelegatingRequestContextExecutorService(org.eclipse.sirius.components.collaborative.requestcontext.DelegatingRequestContextExecutorService) Entry(java.util.Map.Entry) Many(reactor.core.publisher.Sinks.Many) Optional(java.util.Optional) IEditingContextEventHandler(org.eclipse.sirius.components.collaborative.api.IEditingContextEventHandler) DeleteRepresentationInput(org.eclipse.sirius.components.collaborative.dto.DeleteRepresentationInput) IEditingContextEventHandler(org.eclipse.sirius.components.collaborative.api.IEditingContextEventHandler) DeleteRepresentationInput(org.eclipse.sirius.components.collaborative.dto.DeleteRepresentationInput)

Example 4 with IInput

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

the class SubscriptionManager method getFlux.

@Override
public Flux<IPayload> getFlux(IInput input) {
    return this.sink.asFlux().doOnSubscribe(subscription -> {
        this.subscriptionCount.getAndIncrement();
        // $NON-NLS-1$
        this.logger.trace("A new subscription to the representation has occurred {}", this.subscriptionCount.intValue());
    }).doOnCancel(() -> {
        this.subscriptionCount.updateAndGet(current -> Math.max(0, current - 1));
        // $NON-NLS-1$
        this.logger.trace("A new cancellation from the representation has occurred {}", this.subscriptionCount.intValue());
        if (this.subscriptionCount.get() == 0) {
            EmitResult emitResult = this.canBeDisposedSink.tryEmitNext(Boolean.TRUE);
            if (emitResult.isFailure()) {
                // $NON-NLS-1$
                String pattern = "An error has occurred while emitting that the processor can be disposed: {}";
                this.logger.warn(pattern, emitResult);
            }
        }
    });
}
Also used : Sinks(reactor.core.publisher.Sinks) Flux(reactor.core.publisher.Flux) IPayload(org.eclipse.sirius.components.core.api.IPayload) ISubscriptionManager(org.eclipse.sirius.components.collaborative.api.ISubscriptionManager) Logger(org.slf4j.Logger) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) LoggerFactory(org.slf4j.LoggerFactory) Many(reactor.core.publisher.Sinks.Many) EmitResult(reactor.core.publisher.Sinks.EmitResult) IInput(org.eclipse.sirius.components.core.api.IInput) EmitResult(reactor.core.publisher.Sinks.EmitResult)

Example 5 with IInput

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

the class RenameDocumentEventHandlerTests method testRenameDocument.

@Test
public void testRenameDocument() {
    IDocumentService noOpDocumentService = new IDocumentService.NoOp() {

        @Override
        public Optional<Document> rename(UUID documentId, String newName) {
            // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
            return Optional.of(new Document(documentId, new Project(UUID.randomUUID(), "", new Profile(UUID.randomUUID(), "username"), Visibility.PUBLIC), newName, "noContent"));
        }
    };
    RenameDocumentEventHandler handler = new RenameDocumentEventHandler(noOpDocumentService, new NoOpServicesMessageService(), new SimpleMeterRegistry());
    UUID documentId = UUID.randomUUID();
    IInput input = new RenameDocumentInput(UUID.randomUUID(), documentId, NEW_NAME);
    AdapterFactoryEditingDomain editingDomain = new EditingDomainFactory().create();
    DocumentMetadataAdapter adapter = new DocumentMetadataAdapter(OLD_NAME);
    Resource resource = new SiriusWebJSONResourceFactoryImpl().createResource(URI.createURI(documentId.toString()));
    resource.eAdapters().add(adapter);
    editingDomain.getResourceSet().getResources().add(resource);
    assertThat(editingDomain.getResourceSet().getResources().size()).isEqualTo(1);
    assertThat(adapter.getName()).isEqualTo(OLD_NAME);
    IEditingContext editingContext = new EditingContext(UUID.randomUUID().toString(), editingDomain);
    Many<ChangeDescription> changeDescriptionSink = Sinks.many().unicast().onBackpressureBuffer();
    One<IPayload> payloadSink = Sinks.one();
    assertThat(handler.canHandle(editingContext, input)).isTrue();
    handler.handle(payloadSink, changeDescriptionSink, editingContext, input);
    assertThat(editingDomain.getResourceSet().getResources().size()).isEqualTo(1);
    assertThat(adapter.getName()).isEqualTo(NEW_NAME);
    ChangeDescription changeDescription = changeDescriptionSink.asFlux().blockFirst();
    assertThat(changeDescription.getKind()).isEqualTo(ChangeKind.SEMANTIC_CHANGE);
    IPayload payload = payloadSink.asMono().block();
    assertThat(payload).isInstanceOf(RenameDocumentSuccessPayload.class);
}
Also used : AdapterFactoryEditingDomain(org.eclipse.emf.edit.domain.AdapterFactoryEditingDomain) NoOpServicesMessageService(org.eclipse.sirius.web.services.projects.NoOpServicesMessageService) SimpleMeterRegistry(io.micrometer.core.instrument.simple.SimpleMeterRegistry) RenameDocumentInput(org.eclipse.sirius.components.collaborative.dto.RenameDocumentInput) Resource(org.eclipse.emf.ecore.resource.Resource) IInput(org.eclipse.sirius.components.core.api.IInput) Document(org.eclipse.sirius.web.services.api.document.Document) Profile(org.eclipse.sirius.web.services.api.accounts.Profile) IPayload(org.eclipse.sirius.components.core.api.IPayload) Project(org.eclipse.sirius.web.services.api.projects.Project) IEditingContext(org.eclipse.sirius.components.core.api.IEditingContext) IEditingContext(org.eclipse.sirius.components.core.api.IEditingContext) EditingContext(org.eclipse.sirius.components.emf.services.EditingContext) ChangeDescription(org.eclipse.sirius.components.collaborative.api.ChangeDescription) SiriusWebJSONResourceFactoryImpl(org.eclipse.sirius.components.emf.services.SiriusWebJSONResourceFactoryImpl) IDocumentService(org.eclipse.sirius.web.services.api.document.IDocumentService) UUID(java.util.UUID) Test(org.junit.jupiter.api.Test)

Aggregations

IInput (org.eclipse.sirius.components.core.api.IInput)12 IEditingContext (org.eclipse.sirius.components.core.api.IEditingContext)10 SimpleMeterRegistry (io.micrometer.core.instrument.simple.SimpleMeterRegistry)6 ICollaborativeMessageService (org.eclipse.sirius.components.collaborative.messages.ICollaborativeMessageService)6 IPayload (org.eclipse.sirius.components.core.api.IPayload)4 UUID (java.util.UUID)3 ChangeDescription (org.eclipse.sirius.components.collaborative.api.ChangeDescription)3 Many (reactor.core.publisher.Sinks.Many)3 List (java.util.List)2 Map (java.util.Map)2 Objects (java.util.Objects)2 Optional (java.util.Optional)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 Collectors (java.util.stream.Collectors)2 Resource (org.eclipse.emf.ecore.resource.Resource)2 AdapterFactoryEditingDomain (org.eclipse.emf.edit.domain.AdapterFactoryEditingDomain)2 ChangeKind (org.eclipse.sirius.components.collaborative.api.ChangeKind)2 IEditingContextEventHandler (org.eclipse.sirius.components.collaborative.api.IEditingContextEventHandler)2 SubscriptionManager (org.eclipse.sirius.components.collaborative.representations.SubscriptionManager)2 ErrorPayload (org.eclipse.sirius.components.core.api.ErrorPayload)2