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);
}
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);
}
}
}
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);
}
Aggregations