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());
}
}
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);
}
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);
}
Aggregations