Search in sources :

Example 1 with DeleteRepresentationInput

use of org.eclipse.sirius.components.collaborative.dto.DeleteRepresentationInput 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 2 with DeleteRepresentationInput

use of org.eclipse.sirius.components.collaborative.dto.DeleteRepresentationInput in project sirius-web by eclipse-sirius.

the class DeleteRepresentationEventHandler method handle.

@Override
public void handle(One<IPayload> payloadSink, Many<ChangeDescription> changeDescriptionSink, IEditingContext editingContext, IInput input) {
    this.counter.increment();
    String message = this.messageService.invalidInput(input.getClass().getSimpleName(), DeleteRepresentationInput.class.getSimpleName());
    IPayload payload = new ErrorPayload(input.getId(), message);
    ChangeDescription changeDescription = new ChangeDescription(ChangeKind.NOTHING, editingContext.getId(), input);
    if (input instanceof DeleteRepresentationInput) {
        DeleteRepresentationInput deleteRepresentationInput = (DeleteRepresentationInput) input;
        var representationId = new IDParser().parse(deleteRepresentationInput.getRepresentationId());
        if (representationId.isPresent() && this.representationService.existsById(representationId.get())) {
            this.representationService.delete(representationId.get());
            payload = new DeleteRepresentationSuccessPayload(input.getId(), deleteRepresentationInput.getRepresentationId());
            changeDescription = new ChangeDescription(ChangeKind.REPRESENTATION_DELETION, editingContext.getId(), input);
        }
    }
    payloadSink.tryEmitValue(payload);
    changeDescriptionSink.tryEmitNext(changeDescription);
}
Also used : ErrorPayload(org.eclipse.sirius.components.core.api.ErrorPayload) IDParser(org.eclipse.sirius.web.services.api.id.IDParser) ChangeDescription(org.eclipse.sirius.components.collaborative.api.ChangeDescription) DeleteRepresentationInput(org.eclipse.sirius.components.collaborative.dto.DeleteRepresentationInput) DeleteRepresentationSuccessPayload(org.eclipse.sirius.components.collaborative.dto.DeleteRepresentationSuccessPayload) IPayload(org.eclipse.sirius.components.core.api.IPayload)

Example 3 with DeleteRepresentationInput

use of org.eclipse.sirius.components.collaborative.dto.DeleteRepresentationInput in project sirius-components by eclipse-sirius.

the class EditingContextEventProcessor method setupChangeDescriptionSinkConsumer.

@SuppressWarnings("checkstyle:IllegalCatch")
private Disposable setupChangeDescriptionSinkConsumer() {
    Consumer<ChangeDescription> consumer = changeDescription -> {
        if (ChangeKind.REPRESENTATION_TO_DELETE.equals(changeDescription.getKind())) {
            Object representationId = changeDescription.getParameters().get(REPRESENTATION_ID);
            if (representationId instanceof String) {
                DeleteRepresentationInput deleteRepresentationInput = new DeleteRepresentationInput(UUID.randomUUID(), (String) representationId);
                this.doHandle(Sinks.one(), deleteRepresentationInput);
            }
        } else if (ChangeKind.REPRESENTATION_TO_RENAME.equals(changeDescription.getKind())) {
            Object representationId = changeDescription.getParameters().get(REPRESENTATION_ID);
            Object representationLabel = changeDescription.getParameters().get(REPRESENTATION_LABEL);
            if (representationId instanceof String && representationLabel instanceof String) {
                RenameRepresentationInput renameRepresentationInput = new RenameRepresentationInput(UUID.randomUUID(), this.getEditingContextId(), (String) representationId, (String) representationLabel);
                this.doHandle(Sinks.one(), renameRepresentationInput);
            }
        }
        this.publishEvent(changeDescription);
        this.disposeRepresentationIfNeeded();
        RepresentationEventProcessorEntry representationEventProcessorEntry = this.representationEventProcessors.get(changeDescription.getSourceId());
        if (representationEventProcessorEntry != null) {
            try {
                IRepresentationEventProcessor representationEventProcessor = representationEventProcessorEntry.getRepresentationEventProcessor();
                representationEventProcessor.refresh(changeDescription);
                IRepresentation representation = representationEventProcessor.getRepresentation();
                this.applicationEventPublisher.publishEvent(new RepresentationRefreshedEvent(this.editingContext.getId(), representation));
            } catch (Exception exception) {
                this.logger.warn(exception.getMessage(), exception);
            }
        }
        this.refreshOtherRepresentations(changeDescription);
        if (this.shouldPersistTheEditingContext(changeDescription)) {
            this.editingContextPersistenceService.persist(this.editingContext);
        }
        this.danglingRepresentationDeletionService.deleteDanglingRepresentations(this.editingContext.getId());
    };
    Consumer<Throwable> errorConsumer = throwable -> this.logger.warn(throwable.getMessage(), throwable);
    return this.changeDescriptionSink.asFlux().subscribe(consumer, errorConsumer);
}
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) RepresentationRefreshedEvent(org.eclipse.sirius.components.collaborative.dto.RepresentationRefreshedEvent) DeleteRepresentationInput(org.eclipse.sirius.components.collaborative.dto.DeleteRepresentationInput) IRepresentation(org.eclipse.sirius.components.representations.IRepresentation) ExecutionException(java.util.concurrent.ExecutionException) IRepresentationEventProcessor(org.eclipse.sirius.components.collaborative.api.IRepresentationEventProcessor) ChangeDescription(org.eclipse.sirius.components.collaborative.api.ChangeDescription) RenameRepresentationInput(org.eclipse.sirius.components.collaborative.dto.RenameRepresentationInput)

Aggregations

ChangeDescription (org.eclipse.sirius.components.collaborative.api.ChangeDescription)3 DeleteRepresentationInput (org.eclipse.sirius.components.collaborative.dto.DeleteRepresentationInput)3 ErrorPayload (org.eclipse.sirius.components.core.api.ErrorPayload)3 IPayload (org.eclipse.sirius.components.core.api.IPayload)3 Duration (java.time.Duration)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Map (java.util.Map)2 Entry (java.util.Map.Entry)2 Objects (java.util.Objects)2 Optional (java.util.Optional)2 UUID (java.util.UUID)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 ExecutionException (java.util.concurrent.ExecutionException)2 ExecutorService (java.util.concurrent.ExecutorService)2 Future (java.util.concurrent.Future)2 Consumer (java.util.function.Consumer)2 Collectors (java.util.stream.Collectors)2 ChangeKind (org.eclipse.sirius.components.collaborative.api.ChangeKind)2 IDanglingRepresentationDeletionService (org.eclipse.sirius.components.collaborative.api.IDanglingRepresentationDeletionService)2