Search in sources :

Example 1 with QueryBasedObjectSuccessPayload

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

the class EMFQueryService method execute.

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

Example 2 with QueryBasedObjectSuccessPayload

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

the class EMFQueryServiceTests method testEMFQueryServiceGetObjectById.

@Test
public void testEMFQueryServiceGetObjectById() {
    EditingContext editingContext = this.createEditingContext();
    IEditingContextEPackageService editingContextEPackageService = new IEditingContextEPackageService() {

        @Override
        public List<EPackage> getEPackages(String editingContextId) {
            return List.of(EcorePackage.eINSTANCE);
        }
    };
    IQueryService queryService = new EMFQueryService(editingContextEPackageService, List.of());
    // @formatter:off
    EObject eObjectToRetrieve = editingContext.getDomain().getResourceSet().getResources().get(0).getContents().get(0);
    Optional<IDAdapter> optionalIDAdapter = eObjectToRetrieve.eAdapters().stream().filter(IDAdapter.class::isInstance).map(IDAdapter.class::cast).findFirst();
    // $NON-NLS-1$
    String id = optionalIDAdapter.map(IDAdapter::getId).map(Object::toString).orElse("");
    // @formatter:on
    // $NON-NLS-1$ //$NON-NLS-2$
    QueryBasedObjectInput input = new QueryBasedObjectInput(UUID.randomUUID(), "aql:editingContext.getObjectById('" + id + "')", Map.of());
    IPayload payload = queryService.execute(editingContext, input);
    assertTrue(payload instanceof QueryBasedObjectSuccessPayload);
    assertEquals(eObjectToRetrieve, ((QueryBasedObjectSuccessPayload) payload).getResult());
    // $NON-NLS-1$ //$NON-NLS-2$
    input = new QueryBasedObjectInput(UUID.randomUUID(), "aql:editingContext.getObjectById('" + id + "wrong')", Map.of());
    payload = queryService.execute(editingContext, input);
    assertTrue(payload instanceof ErrorPayload);
}
Also used : IQueryService(org.eclipse.sirius.components.collaborative.api.IQueryService) QueryBasedObjectSuccessPayload(org.eclipse.sirius.components.collaborative.dto.QueryBasedObjectSuccessPayload) IEditingContextEPackageService(org.eclipse.sirius.components.emf.services.IEditingContextEPackageService) IDAdapter(org.eclipse.sirius.components.emf.services.IDAdapter) EPackage(org.eclipse.emf.ecore.EPackage) IPayload(org.eclipse.sirius.components.core.api.IPayload) ErrorPayload(org.eclipse.sirius.components.core.api.ErrorPayload) IEditingContext(org.eclipse.sirius.components.core.api.IEditingContext) EditingContext(org.eclipse.sirius.components.emf.services.EditingContext) EObject(org.eclipse.emf.ecore.EObject) QueryBasedObjectInput(org.eclipse.sirius.components.collaborative.dto.QueryBasedObjectInput) Test(org.junit.jupiter.api.Test)

Example 3 with QueryBasedObjectSuccessPayload

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

the class QueryBasedObjectEventHandlerTests method testQueryBasedObject.

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

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

Aggregations

QueryBasedObjectSuccessPayload (org.eclipse.sirius.components.collaborative.dto.QueryBasedObjectSuccessPayload)3 IQueryService (org.eclipse.sirius.components.collaborative.api.IQueryService)2 QueryBasedObjectInput (org.eclipse.sirius.components.collaborative.dto.QueryBasedObjectInput)2 ErrorPayload (org.eclipse.sirius.components.core.api.ErrorPayload)2 IEditingContext (org.eclipse.sirius.components.core.api.IEditingContext)2 IPayload (org.eclipse.sirius.components.core.api.IPayload)2 Test (org.junit.jupiter.api.Test)2 EObject (org.eclipse.emf.ecore.EObject)1 EPackage (org.eclipse.emf.ecore.EPackage)1 ChangeDescription (org.eclipse.sirius.components.collaborative.api.ChangeDescription)1 EditingContext (org.eclipse.sirius.components.emf.services.EditingContext)1 IDAdapter (org.eclipse.sirius.components.emf.services.IDAdapter)1 IEditingContextEPackageService (org.eclipse.sirius.components.emf.services.IEditingContextEPackageService)1 Result (org.eclipse.sirius.components.interpreter.Result)1