Search in sources :

Example 1 with QueryBasedStringSuccessPayload

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

the class EMFQueryService method execute.

@Override
public IPayload execute(IEditingContext editingContext, QueryBasedStringInput input) {
    Result result = this.executeQuery(editingContext, input.getQuery(), input.getVariables());
    Optional<String> optionalString = result.asString();
    if (optionalString.isPresent()) {
        return new QueryBasedStringSuccessPayload(input.getId(), optionalString.get());
    } else {
        return new ErrorPayload(input.getId(), EVALUATION_ERROR_MESSAGE + result.getStatus());
    }
}
Also used : ErrorPayload(org.eclipse.sirius.components.core.api.ErrorPayload) QueryBasedStringSuccessPayload(org.eclipse.sirius.components.collaborative.dto.QueryBasedStringSuccessPayload) Result(org.eclipse.sirius.components.interpreter.Result)

Example 2 with QueryBasedStringSuccessPayload

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

the class QueryBasedStringEventHandlerTests method testQueryBasedString.

@Test
public void testQueryBasedString() {
    IQueryService queryService = new IQueryService.NoOp() {

        @Override
        public IPayload execute(IEditingContext editingContext, QueryBasedStringInput input) {
            return new QueryBasedStringSuccessPayload(UUID.randomUUID(), EXPECTED_RESULT);
        }
    };
    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(QueryBasedStringSuccessPayload.class);
    assertThat(((QueryBasedStringSuccessPayload) payload).getResult()).isEqualTo(EXPECTED_RESULT);
}
Also used : IQueryService(org.eclipse.sirius.components.collaborative.api.IQueryService) IEditingContext(org.eclipse.sirius.components.core.api.IEditingContext) ChangeDescription(org.eclipse.sirius.components.collaborative.api.ChangeDescription) QueryBasedStringInput(org.eclipse.sirius.components.collaborative.dto.QueryBasedStringInput) QueryBasedStringSuccessPayload(org.eclipse.sirius.components.collaborative.dto.QueryBasedStringSuccessPayload) IPayload(org.eclipse.sirius.components.core.api.IPayload) Test(org.junit.jupiter.api.Test)

Aggregations

QueryBasedStringSuccessPayload (org.eclipse.sirius.components.collaborative.dto.QueryBasedStringSuccessPayload)2 ChangeDescription (org.eclipse.sirius.components.collaborative.api.ChangeDescription)1 IQueryService (org.eclipse.sirius.components.collaborative.api.IQueryService)1 QueryBasedStringInput (org.eclipse.sirius.components.collaborative.dto.QueryBasedStringInput)1 ErrorPayload (org.eclipse.sirius.components.core.api.ErrorPayload)1 IEditingContext (org.eclipse.sirius.components.core.api.IEditingContext)1 IPayload (org.eclipse.sirius.components.core.api.IPayload)1 Result (org.eclipse.sirius.components.interpreter.Result)1 Test (org.junit.jupiter.api.Test)1