Search in sources :

Example 1 with QueryBasedObjectsSuccessPayload

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

the class QueryBasedObjectsEventHandlerTests method testQueryBasedObjects.

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

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

Example 2 with QueryBasedObjectsSuccessPayload

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

the class EMFQueryService method execute.

@Override
public IPayload execute(IEditingContext editingContext, QueryBasedObjectsInput input) {
    Result result = this.executeQuery(editingContext, input.getQuery(), input.getVariables());
    Optional<List<Object>> optionalObjects = result.asObjects();
    if (optionalObjects.isPresent()) {
        return new QueryBasedObjectsSuccessPayload(input.getId(), optionalObjects.get());
    } else {
        return new ErrorPayload(input.getId(), EVALUATION_ERROR_MESSAGE + result.getStatus());
    }
}
Also used : ErrorPayload(org.eclipse.sirius.components.core.api.ErrorPayload) QueryBasedObjectsSuccessPayload(org.eclipse.sirius.components.collaborative.dto.QueryBasedObjectsSuccessPayload) List(java.util.List) Result(org.eclipse.sirius.components.interpreter.Result)

Aggregations

QueryBasedObjectsSuccessPayload (org.eclipse.sirius.components.collaborative.dto.QueryBasedObjectsSuccessPayload)2 List (java.util.List)1 ChangeDescription (org.eclipse.sirius.components.collaborative.api.ChangeDescription)1 IQueryService (org.eclipse.sirius.components.collaborative.api.IQueryService)1 QueryBasedObjectsInput (org.eclipse.sirius.components.collaborative.dto.QueryBasedObjectsInput)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