use of org.eclipse.sirius.components.core.api.IEditingContext in project sirius-components by eclipse-sirius.
the class EditingContextEventProcessorRegistry method getOrCreateEditingContextEventProcessor.
@Override
public synchronized Optional<IEditingContextEventProcessor> getOrCreateEditingContextEventProcessor(String editingContextId) {
Optional<IEditingContextEventProcessor> optionalEditingContextEventProcessor = Optional.empty();
if (this.editingContextSearchService.existsById(editingContextId)) {
optionalEditingContextEventProcessor = Optional.ofNullable(this.editingContextEventProcessors.get(editingContextId)).map(EditingContextEventProcessorEntry::getEditingContextEventProcessor);
if (optionalEditingContextEventProcessor.isEmpty()) {
Optional<IEditingContext> optionalEditingContext = this.editingContextSearchService.findById(editingContextId);
if (optionalEditingContext.isPresent()) {
IEditingContext editingContext = optionalEditingContext.get();
var editingContextEventProcessor = this.editingContextEventProcessorFactory.createEditingContextEventProcessor(editingContext);
Disposable subscription = editingContextEventProcessor.canBeDisposed().delayElements(this.disposeDelay).subscribe(canBeDisposed -> {
// We will check if the editing context event processor is still empty
if (canBeDisposed.booleanValue() && editingContextEventProcessor.getRepresentationEventProcessors().isEmpty()) {
this.disposeEditingContextEventProcessor(editingContextId);
} else {
// $NON-NLS-1$
this.logger.trace("Stopping the disposal of the editing context");
}
});
var editingContextEventProcessorEntry = new EditingContextEventProcessorEntry(editingContextEventProcessor, subscription);
this.editingContextEventProcessors.put(editingContextId, editingContextEventProcessorEntry);
optionalEditingContextEventProcessor = Optional.of(editingContextEventProcessor);
}
}
}
return optionalEditingContextEventProcessor;
}
use of org.eclipse.sirius.components.core.api.IEditingContext in project sirius-components by eclipse-sirius.
the class QueryBasedBooleanEventHandlerTests method testQueryBasedBooleanFailed.
@Test
public void testQueryBasedBooleanFailed() {
IQueryService queryService = new IQueryService.NoOp() {
@Override
public IPayload execute(IEditingContext editingContext, QueryBasedBooleanInput input) {
// $NON-NLS-1$
return new ErrorPayload(UUID.randomUUID(), "An error occured");
}
};
Many<ChangeDescription> changeDescriptionSink = Sinks.many().unicast().onBackpressureBuffer();
One<IPayload> payloadSink = Sinks.one();
this.handle(payloadSink, changeDescriptionSink, queryService);
ChangeDescription changeDescription = changeDescriptionSink.asFlux().blockFirst();
assertThat(changeDescription.getKind()).isEqualTo(ChangeKind.NOTHING);
IPayload payload = payloadSink.asMono().block();
assertThat(payload).isInstanceOf(ErrorPayload.class);
}
use of org.eclipse.sirius.components.core.api.IEditingContext 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);
}
use of org.eclipse.sirius.components.core.api.IEditingContext in project sirius-components by eclipse-sirius.
the class QueryBasedIntEventHandlerTests method testQueryBasedInt.
@Test
public void testQueryBasedInt() {
IQueryService queryService = new IQueryService.NoOp() {
@Override
public IPayload execute(IEditingContext editingContext, QueryBasedIntInput input) {
return new QueryBasedIntSuccessPayload(UUID.randomUUID(), EXPECTED_RESULT_10);
}
};
Many<ChangeDescription> changeDescriptionSink = Sinks.many().unicast().onBackpressureBuffer();
One<IPayload> payloadSink = Sinks.one();
this.handle(payloadSink, changeDescriptionSink, queryService);
ChangeDescription changeDescription = changeDescriptionSink.asFlux().blockFirst();
assertThat(changeDescription.getKind()).isEqualTo(ChangeKind.NOTHING);
IPayload payload = payloadSink.asMono().block();
assertThat(payload).isInstanceOf(QueryBasedIntSuccessPayload.class);
assertThat(((QueryBasedIntSuccessPayload) payload).getResult()).isEqualTo(EXPECTED_RESULT_10);
}
use of org.eclipse.sirius.components.core.api.IEditingContext in project sirius-components by eclipse-sirius.
the class QueryBasedObjectEventHandlerTests method testQueryBasedObjectFailed.
@Test
public void testQueryBasedObjectFailed() {
IQueryService queryService = new IQueryService.NoOp() {
@Override
public IPayload execute(IEditingContext editingContext, QueryBasedObjectInput input) {
// $NON-NLS-1$
return new ErrorPayload(UUID.randomUUID(), "An error occured");
}
};
Many<ChangeDescription> changeDescriptionSink = Sinks.many().unicast().onBackpressureBuffer();
One<IPayload> payloadSink = Sinks.one();
this.handle(payloadSink, changeDescriptionSink, queryService);
ChangeDescription changeDescription = changeDescriptionSink.asFlux().blockFirst();
assertThat(changeDescription.getKind()).isEqualTo(ChangeKind.NOTHING);
IPayload payload = payloadSink.asMono().block();
assertThat(payload).isInstanceOf(ErrorPayload.class);
}
Aggregations