Search in sources :

Example 1 with QueryBasedObjectInput

use of org.eclipse.sirius.components.collaborative.dto.QueryBasedObjectInput 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);
}
Also used : ErrorPayload(org.eclipse.sirius.components.core.api.ErrorPayload) IQueryService(org.eclipse.sirius.components.collaborative.api.IQueryService) IEditingContext(org.eclipse.sirius.components.core.api.IEditingContext) 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)

Example 2 with QueryBasedObjectInput

use of org.eclipse.sirius.components.collaborative.dto.QueryBasedObjectInput 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 QueryBasedObjectInput

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

the class QueryBasedObjectEventHandlerTests method handle.

private void handle(One<IPayload> payloadSink, Many<ChangeDescription> changeDescriptionSink, IQueryService queryService) {
    QueryBasedObjectEventHandler queryBasedObjectEventHandler = new QueryBasedObjectEventHandler(new ICollaborativeMessageService.NoOp(), new SimpleMeterRegistry(), queryService);
    // $NON-NLS-1$
    IInput input = new QueryBasedObjectInput(UUID.randomUUID(), "", Map.of());
    assertThat(queryBasedObjectEventHandler.canHandle(new IEditingContext.NoOp(), input)).isTrue();
    IEditingContext editingContext = () -> UUID.randomUUID().toString();
    queryBasedObjectEventHandler.handle(payloadSink, changeDescriptionSink, editingContext, input);
}
Also used : ICollaborativeMessageService(org.eclipse.sirius.components.collaborative.messages.ICollaborativeMessageService) IEditingContext(org.eclipse.sirius.components.core.api.IEditingContext) SimpleMeterRegistry(io.micrometer.core.instrument.simple.SimpleMeterRegistry) IInput(org.eclipse.sirius.components.core.api.IInput) QueryBasedObjectInput(org.eclipse.sirius.components.collaborative.dto.QueryBasedObjectInput)

Example 4 with QueryBasedObjectInput

use of org.eclipse.sirius.components.collaborative.dto.QueryBasedObjectInput 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)

Example 5 with QueryBasedObjectInput

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

the class QueryBasedObjectEventHandler method handle.

@Override
public void handle(One<IPayload> payloadSink, Many<ChangeDescription> changeDescriptionSink, IEditingContext editingContext, IInput input) {
    this.counter.increment();
    String message = this.messageService.invalidInput(input.getClass().getSimpleName(), QueryBasedStringInput.class.getSimpleName());
    IPayload payload = new ErrorPayload(input.getId(), message);
    if (input instanceof QueryBasedObjectInput) {
        QueryBasedObjectInput queryBasedObjectInput = (QueryBasedObjectInput) input;
        payload = this.queryService.execute(editingContext, queryBasedObjectInput);
    }
    payloadSink.tryEmitValue(payload);
    ChangeDescription changeDescription = new ChangeDescription(ChangeKind.NOTHING, editingContext.getId(), input);
    changeDescriptionSink.tryEmitNext(changeDescription);
}
Also used : ErrorPayload(org.eclipse.sirius.components.core.api.ErrorPayload) ChangeDescription(org.eclipse.sirius.components.collaborative.api.ChangeDescription) QueryBasedStringInput(org.eclipse.sirius.components.collaborative.dto.QueryBasedStringInput) QueryBasedObjectInput(org.eclipse.sirius.components.collaborative.dto.QueryBasedObjectInput) IPayload(org.eclipse.sirius.components.core.api.IPayload)

Aggregations

QueryBasedObjectInput (org.eclipse.sirius.components.collaborative.dto.QueryBasedObjectInput)5 IEditingContext (org.eclipse.sirius.components.core.api.IEditingContext)4 IPayload (org.eclipse.sirius.components.core.api.IPayload)4 ChangeDescription (org.eclipse.sirius.components.collaborative.api.ChangeDescription)3 IQueryService (org.eclipse.sirius.components.collaborative.api.IQueryService)3 ErrorPayload (org.eclipse.sirius.components.core.api.ErrorPayload)3 Test (org.junit.jupiter.api.Test)3 QueryBasedObjectSuccessPayload (org.eclipse.sirius.components.collaborative.dto.QueryBasedObjectSuccessPayload)2 SimpleMeterRegistry (io.micrometer.core.instrument.simple.SimpleMeterRegistry)1 EObject (org.eclipse.emf.ecore.EObject)1 EPackage (org.eclipse.emf.ecore.EPackage)1 QueryBasedStringInput (org.eclipse.sirius.components.collaborative.dto.QueryBasedStringInput)1 ICollaborativeMessageService (org.eclipse.sirius.components.collaborative.messages.ICollaborativeMessageService)1 IInput (org.eclipse.sirius.components.core.api.IInput)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