Search in sources :

Example 1 with RenameDiagramInput

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

the class RenameDiagramEventHandlerTests method testRenameRepresentation.

@Test
public void testRenameRepresentation() {
    String projectId = UUID.randomUUID().toString();
    String representationId = UUID.randomUUID().toString();
    UUID targetObjectId = UUID.randomUUID();
    DiagramDescription diagramDescription = new TestDiagramDescriptionBuilder().getDiagramDescription(UUID.randomUUID(), List.of(), List.of(), List.of());
    // @formatter:off
    Diagram diagram = Diagram.newDiagram(representationId).label(OLD_LABEL).descriptionId(diagramDescription.getId()).targetObjectId(targetObjectId.toString()).size(Size.of(10, 10)).position(Position.at(0, 0)).nodes(Collections.emptyList()).edges(Collections.emptyList()).build();
    // @formatter:on
    IRepresentationSearchService representationSearchService = new IRepresentationSearchService() {

        @Override
        public <T extends IRepresentation> Optional<T> findById(IEditingContext editingContext, String representationId, Class<T> representationClass) {
            return Optional.of(diagram).map(representationClass::cast);
        }
    };
    RenameDiagramEventHandler handler = new RenameDiagramEventHandler(representationSearchService, new IRepresentationPersistenceService.NoOp(), new ICollaborativeDiagramMessageService.NoOp(), new SimpleMeterRegistry());
    var input = new RenameDiagramInput(UUID.randomUUID(), projectId, representationId, NEW_LABEL);
    assertThat(handler.canHandle(input)).isTrue();
    Many<ChangeDescription> changeDescriptionSink = Sinks.many().unicast().onBackpressureBuffer();
    One<IPayload> payloadSink = Sinks.one();
    handler.handle(payloadSink, changeDescriptionSink, new IEditingContext.NoOp(), new IDiagramContext.NoOp(), input);
    ChangeDescription changeDescription = changeDescriptionSink.asFlux().blockFirst();
    assertThat(changeDescription.getKind()).isEqualTo(ChangeKind.REPRESENTATION_RENAMING);
    IPayload payload = payloadSink.asMono().block();
    assertThat(payload).isInstanceOf(RenameRepresentationSuccessPayload.class);
    assertThat(((RenameRepresentationSuccessPayload) payload).getRepresentation().getLabel()).isEqualTo(NEW_LABEL);
}
Also used : TestDiagramDescriptionBuilder(org.eclipse.sirius.components.diagrams.tests.TestDiagramDescriptionBuilder) IPayload(org.eclipse.sirius.components.core.api.IPayload) ChangeDescription(org.eclipse.sirius.components.collaborative.api.ChangeDescription) ICollaborativeDiagramMessageService(org.eclipse.sirius.components.collaborative.diagrams.messages.ICollaborativeDiagramMessageService) UUID(java.util.UUID) IRepresentationPersistenceService(org.eclipse.sirius.components.collaborative.api.IRepresentationPersistenceService) SimpleMeterRegistry(io.micrometer.core.instrument.simple.SimpleMeterRegistry) IRepresentationSearchService(org.eclipse.sirius.components.collaborative.api.IRepresentationSearchService) DiagramDescription(org.eclipse.sirius.components.diagrams.description.DiagramDescription) IRepresentation(org.eclipse.sirius.components.representations.IRepresentation) Diagram(org.eclipse.sirius.components.diagrams.Diagram) RenameDiagramInput(org.eclipse.sirius.components.collaborative.diagrams.dto.RenameDiagramInput) IEditingContext(org.eclipse.sirius.components.core.api.IEditingContext) IDiagramContext(org.eclipse.sirius.components.collaborative.diagrams.api.IDiagramContext) Test(org.junit.jupiter.api.Test)

Example 2 with RenameDiagramInput

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

the class DiagramEventProcessor method handle.

@Override
public void handle(One<IPayload> payloadSink, Many<ChangeDescription> changeDescriptionSink, IRepresentationInput representationInput) {
    IRepresentationInput effectiveInput = representationInput;
    if (representationInput instanceof RenameRepresentationInput) {
        RenameRepresentationInput renameRepresentationInput = (RenameRepresentationInput) representationInput;
        effectiveInput = new RenameDiagramInput(renameRepresentationInput.getId(), renameRepresentationInput.getEditingContextId(), renameRepresentationInput.getRepresentationId(), renameRepresentationInput.getNewLabel());
    }
    if (effectiveInput instanceof IDiagramInput) {
        IDiagramInput diagramInput = (IDiagramInput) effectiveInput;
        Optional<IDiagramEventHandler> optionalDiagramEventHandler = this.diagramEventHandlers.stream().filter(handler -> handler.canHandle(diagramInput)).findFirst();
        if (optionalDiagramEventHandler.isPresent()) {
            IDiagramEventHandler diagramEventHandler = optionalDiagramEventHandler.get();
            diagramEventHandler.handle(payloadSink, changeDescriptionSink, this.editingContext, this.diagramContext, diagramInput);
        } else {
            // $NON-NLS-1$
            this.logger.warn("No handler found for event: {}", diagramInput);
        }
    }
}
Also used : IEditingContext(org.eclipse.sirius.components.core.api.IEditingContext) IDiagramInput(org.eclipse.sirius.components.collaborative.diagrams.api.IDiagramInput) LoggerFactory(org.slf4j.LoggerFactory) One(reactor.core.publisher.Sinks.One) DiagramDescription(org.eclipse.sirius.components.diagrams.description.DiagramDescription) IInput(org.eclipse.sirius.components.core.api.IInput) Diagram(org.eclipse.sirius.components.diagrams.Diagram) IRepresentation(org.eclipse.sirius.components.representations.IRepresentation) IRepresentationRefreshPolicyRegistry(org.eclipse.sirius.components.collaborative.api.IRepresentationRefreshPolicyRegistry) IDiagramEventProcessor(org.eclipse.sirius.components.collaborative.diagrams.api.IDiagramEventProcessor) ChangeKind(org.eclipse.sirius.components.collaborative.api.ChangeKind) ISubscriptionManager(org.eclipse.sirius.components.collaborative.api.ISubscriptionManager) Logger(org.slf4j.Logger) IDiagramContext(org.eclipse.sirius.components.collaborative.diagrams.api.IDiagramContext) ChangeDescription(org.eclipse.sirius.components.collaborative.api.ChangeDescription) RenameRepresentationInput(org.eclipse.sirius.components.collaborative.dto.RenameRepresentationInput) IRepresentationDescriptionSearchService(org.eclipse.sirius.components.core.api.IRepresentationDescriptionSearchService) IRepresentationInput(org.eclipse.sirius.components.core.api.IRepresentationInput) IRepresentationRefreshPolicy(org.eclipse.sirius.components.collaborative.api.IRepresentationRefreshPolicy) IDiagramCreationService(org.eclipse.sirius.components.collaborative.diagrams.api.IDiagramCreationService) Objects(java.util.Objects) RenameDiagramInput(org.eclipse.sirius.components.collaborative.diagrams.dto.RenameDiagramInput) Flux(reactor.core.publisher.Flux) List(java.util.List) IPayload(org.eclipse.sirius.components.core.api.IPayload) IDiagramEventHandler(org.eclipse.sirius.components.collaborative.diagrams.api.IDiagramEventHandler) Many(reactor.core.publisher.Sinks.Many) Optional(java.util.Optional) RenameDiagramInput(org.eclipse.sirius.components.collaborative.diagrams.dto.RenameDiagramInput) IDiagramInput(org.eclipse.sirius.components.collaborative.diagrams.api.IDiagramInput) IDiagramEventHandler(org.eclipse.sirius.components.collaborative.diagrams.api.IDiagramEventHandler) IRepresentationInput(org.eclipse.sirius.components.core.api.IRepresentationInput) RenameRepresentationInput(org.eclipse.sirius.components.collaborative.dto.RenameRepresentationInput)

Example 3 with RenameDiagramInput

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

the class RenameDiagramEventHandler method handle.

@Override
public void handle(One<IPayload> payloadSink, Many<ChangeDescription> changeDescriptionSink, IEditingContext editingContext, IDiagramContext diagramContext, IDiagramInput diagramInput) {
    this.counter.increment();
    String message = this.messageService.invalidInput(diagramInput.getClass().getSimpleName(), RenameDiagramInput.class.getSimpleName());
    IPayload payload = new ErrorPayload(diagramInput.getId(), message);
    ChangeDescription changeDescription = new ChangeDescription(ChangeKind.NOTHING, diagramInput.getRepresentationId(), diagramInput);
    if (diagramInput instanceof RenameDiagramInput) {
        RenameDiagramInput renameRepresentationInput = (RenameDiagramInput) diagramInput;
        String representationId = renameRepresentationInput.getRepresentationId();
        String newLabel = renameRepresentationInput.getNewLabel();
        Optional<Diagram> optionalDiagram = this.representationSearchService.findById(editingContext, representationId, Diagram.class);
        if (optionalDiagram.isPresent()) {
            Diagram diagram = optionalDiagram.get();
            Diagram renamedDiagram = Diagram.newDiagram(diagram).label(newLabel).build();
            this.representationPersistenceService.save(editingContext, renamedDiagram);
            diagramContext.update(renamedDiagram);
            payload = new RenameRepresentationSuccessPayload(diagramInput.getId(), renamedDiagram);
            changeDescription = new ChangeDescription(ChangeKind.REPRESENTATION_RENAMING, renameRepresentationInput.getRepresentationId(), diagramInput);
        }
    }
    payloadSink.tryEmitValue(payload);
    changeDescriptionSink.tryEmitNext(changeDescription);
}
Also used : RenameDiagramInput(org.eclipse.sirius.components.collaborative.diagrams.dto.RenameDiagramInput) ErrorPayload(org.eclipse.sirius.components.core.api.ErrorPayload) ChangeDescription(org.eclipse.sirius.components.collaborative.api.ChangeDescription) RenameRepresentationSuccessPayload(org.eclipse.sirius.components.collaborative.dto.RenameRepresentationSuccessPayload) IPayload(org.eclipse.sirius.components.core.api.IPayload) Diagram(org.eclipse.sirius.components.diagrams.Diagram)

Aggregations

ChangeDescription (org.eclipse.sirius.components.collaborative.api.ChangeDescription)3 RenameDiagramInput (org.eclipse.sirius.components.collaborative.diagrams.dto.RenameDiagramInput)3 IPayload (org.eclipse.sirius.components.core.api.IPayload)3 Diagram (org.eclipse.sirius.components.diagrams.Diagram)3 IDiagramContext (org.eclipse.sirius.components.collaborative.diagrams.api.IDiagramContext)2 IEditingContext (org.eclipse.sirius.components.core.api.IEditingContext)2 DiagramDescription (org.eclipse.sirius.components.diagrams.description.DiagramDescription)2 IRepresentation (org.eclipse.sirius.components.representations.IRepresentation)2 SimpleMeterRegistry (io.micrometer.core.instrument.simple.SimpleMeterRegistry)1 List (java.util.List)1 Objects (java.util.Objects)1 Optional (java.util.Optional)1 UUID (java.util.UUID)1 ChangeKind (org.eclipse.sirius.components.collaborative.api.ChangeKind)1 IRepresentationPersistenceService (org.eclipse.sirius.components.collaborative.api.IRepresentationPersistenceService)1 IRepresentationRefreshPolicy (org.eclipse.sirius.components.collaborative.api.IRepresentationRefreshPolicy)1 IRepresentationRefreshPolicyRegistry (org.eclipse.sirius.components.collaborative.api.IRepresentationRefreshPolicyRegistry)1 IRepresentationSearchService (org.eclipse.sirius.components.collaborative.api.IRepresentationSearchService)1 ISubscriptionManager (org.eclipse.sirius.components.collaborative.api.ISubscriptionManager)1 IDiagramCreationService (org.eclipse.sirius.components.collaborative.diagrams.api.IDiagramCreationService)1