Search in sources :

Example 1 with RepresentationRefreshedEvent

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

the class EditingContextEventProcessor method refreshOtherRepresentations.

/**
 * Refresh all the representations except the one with the given representationId.
 *
 * @param input
 *            The input which has triggered the refresh sequence
 * @param representationId
 *            The identifier of the representation which should not be refreshed
 * @param changeDescription
 *            The description of change to consider in order to determine if the representation should be refreshed
 */
private void refreshOtherRepresentations(ChangeDescription changeDescription) {
    // @formatter:off
    this.representationEventProcessors.entrySet().stream().filter(entry -> !Objects.equals(entry.getKey(), changeDescription.getSourceId())).map(Entry::getValue).map(RepresentationEventProcessorEntry::getRepresentationEventProcessor).forEach(representationEventProcessor -> {
        representationEventProcessor.refresh(changeDescription);
        IRepresentation representation = representationEventProcessor.getRepresentation();
        this.applicationEventPublisher.publishEvent(new RepresentationRefreshedEvent(this.editingContext.getId(), representation));
    });
// @formatter:on
}
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) Entry(java.util.Map.Entry) RepresentationRefreshedEvent(org.eclipse.sirius.components.collaborative.dto.RepresentationRefreshedEvent) IRepresentation(org.eclipse.sirius.components.representations.IRepresentation)

Example 2 with RepresentationRefreshedEvent

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

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 ChangeDescription (org.eclipse.sirius.components.collaborative.api.ChangeDescription)2 ChangeKind (org.eclipse.sirius.components.collaborative.api.ChangeKind)2 IDanglingRepresentationDeletionService (org.eclipse.sirius.components.collaborative.api.IDanglingRepresentationDeletionService)2 IEditingContextEventHandler (org.eclipse.sirius.components.collaborative.api.IEditingContextEventHandler)2 IEditingContextEventProcessor (org.eclipse.sirius.components.collaborative.api.IEditingContextEventProcessor)2 IRepresentationConfiguration (org.eclipse.sirius.components.collaborative.api.IRepresentationConfiguration)2