Skip to content

Commit

Permalink
[4346] Add support for a query view
Browse files Browse the repository at this point in the history
Bug: #4346
Signed-off-by: Stéphane Bégaudeau <[email protected]>
  • Loading branch information
sbegaudeau committed Dec 30, 2024
1 parent 0112a51 commit 5091a81
Show file tree
Hide file tree
Showing 26 changed files with 1,417 additions and 0 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

=== Shapes

- Add support for a query view


=== Architectural decision records

Expand All @@ -22,6 +24,9 @@

=== New Features

- https://github.com/eclipse-sirius/sirius-web/issues/4346[#4346] Add support for a query view.
Specifiers can contribute dedicated AQL services for this feature using implementations of `IInterpreterJavaServiceProvider`.


=== Improvements

Expand Down
43 changes: 43 additions & 0 deletions doc/iterations/2025.2/add_support_for_a_query_view.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
= Add support for a query view

== Problem

Sirius Web users need a query view to execute some expressions and view the results.

== Key Result

It shall be possible to run a query against the editing context and view the result along with its type (for example to distinguish one element from a list containing only one element).

The current selection shall be usable as an entry point of the query.
An extension point on the backend shall be available to add custom Java services too.
Various interpreter shall be supported on the backend to let specifiers add custom interpreters.

This new view shall be contributed using an extension point in order to be removal by downstream projects which may not need it.

The result of the expression will only be computed when the user will ask for it.
This view will not be a synchronized representation.

=== Scenario

==== An user wants to query some model

- The user open the interpreter view
- The user click on an element in the explorer or another representation like a diagram
- They start typing an expression in the interpreter view and click on a button to perform the query
- The result appears in the result viewer underneath


=== Breadboarding

- A view on the right of the workbench with a textarea to enter an expression and a viewer underneath to display the result.


=== Cutting backs

- Content assist in the interpreter.


== Rabbit holes


== No-gos
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*******************************************************************************
* Copyright (c) 2024 Obeo.
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Obeo - initial API and implementation
*******************************************************************************/
package org.eclipse.sirius.web.application.views.query.controllers;

import com.fasterxml.jackson.databind.ObjectMapper;

import java.util.Objects;
import java.util.concurrent.CompletableFuture;

import org.eclipse.sirius.components.annotations.spring.graphql.MutationDataFetcher;
import org.eclipse.sirius.components.core.api.IPayload;
import org.eclipse.sirius.components.graphql.api.IDataFetcherWithFieldCoordinates;
import org.eclipse.sirius.components.graphql.api.IEditingContextDispatcher;
import org.eclipse.sirius.components.graphql.api.IExceptionWrapper;
import org.eclipse.sirius.web.application.views.query.dto.EvaluateExpressionInput;

import graphql.schema.DataFetchingEnvironment;

/**
* The data fetcher used to evaluate an expression for the interpreter view.
*
* @author sbegaudeau
*/
@MutationDataFetcher(type = "Mutation", field = "evaluateExpression")
public class MutationEvaluateExpressionDataFetcher implements IDataFetcherWithFieldCoordinates<CompletableFuture<IPayload>> {

private static final String INPUT_ARGUMENT = "input";

private final ObjectMapper objectMapper;

private final IExceptionWrapper exceptionWrapper;

private final IEditingContextDispatcher editingContextDispatcher;

public MutationEvaluateExpressionDataFetcher(ObjectMapper objectMapper, IExceptionWrapper exceptionWrapper, IEditingContextDispatcher editingContextDispatcher) {
this.objectMapper = Objects.requireNonNull(objectMapper);
this.exceptionWrapper = Objects.requireNonNull(exceptionWrapper);
this.editingContextDispatcher = Objects.requireNonNull(editingContextDispatcher);
}

@Override
public CompletableFuture<IPayload> get(DataFetchingEnvironment environment) throws Exception {
Object argument = environment.getArgument(INPUT_ARGUMENT);
var input = this.objectMapper.convertValue(argument, EvaluateExpressionInput.class);
return this.exceptionWrapper.wrapMono(() -> this.editingContextDispatcher.dispatchMutation(input.editingContextId(), input), input).toFuture();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*******************************************************************************
* Copyright (c) 2024 Obeo.
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Obeo - initial API and implementation
*******************************************************************************/
package org.eclipse.sirius.web.application.views.query.dto;

/**
* Used to return a boolean value.
*
* @author sbegaudeau
*/
public record BooleanExpressionResult(boolean value) implements IEvaluateExpressionResult {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*******************************************************************************
* Copyright (c) 2024 Obeo.
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Obeo - initial API and implementation
*******************************************************************************/
package org.eclipse.sirius.web.application.views.query.dto;

import java.util.UUID;

import org.eclipse.sirius.components.core.api.IInput;

/**
* Used to execute an expression.
*
* @author sbegaudeau
*/
public record EvaluateExpressionInput(UUID id, String editingContextId, String expression) implements IInput {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*******************************************************************************
* Copyright (c) 2024 Obeo.
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Obeo - initial API and implementation
*******************************************************************************/
package org.eclipse.sirius.web.application.views.query.dto;

import java.util.UUID;

import org.eclipse.sirius.components.core.api.IPayload;

import jakarta.validation.constraints.NotNull;

/**
* Used to indicate that the expression has been successfully evaluated.
*
* @author sbegaudeau
*/
public record EvaluateExpressionSuccessPayload(
@NotNull UUID id,
@NotNull IEvaluateExpressionResult result) implements IPayload {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*******************************************************************************
* Copyright (c) 2024 Obeo.
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Obeo - initial API and implementation
*******************************************************************************/
package org.eclipse.sirius.web.application.views.query.dto;

/**
* Interface to be implemented by all the evaluation results.
*
* @author sbegaudeau
*/
public interface IEvaluateExpressionResult {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*******************************************************************************
* Copyright (c) 2024 Obeo.
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Obeo - initial API and implementation
*******************************************************************************/
package org.eclipse.sirius.web.application.views.query.dto;

/**
* Used to return an integer value.
*
* @author sbegaudeau
*/
public record IntExpressionResult(int value) implements IEvaluateExpressionResult {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*******************************************************************************
* Copyright (c) 2024 Obeo.
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Obeo - initial API and implementation
*******************************************************************************/
package org.eclipse.sirius.web.application.views.query.dto;

/**
* Used to return a single object.
*
* @author sbegaudeau
*/
public record ObjectExpressionResult(Object value) implements IEvaluateExpressionResult {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*******************************************************************************
* Copyright (c) 2024 Obeo.
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Obeo - initial API and implementation
*******************************************************************************/
package org.eclipse.sirius.web.application.views.query.dto;

import java.util.List;

/**
* Used to return a list of objects.
*
* @author sbegaudeau
*/
public record ObjectsExpressionResult(List<Object> value) implements IEvaluateExpressionResult {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*******************************************************************************
* Copyright (c) 2024 Obeo.
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Obeo - initial API and implementation
*******************************************************************************/
package org.eclipse.sirius.web.application.views.query.dto;

/**
* Used to return a string based value.
*
* @author sbegaudeau
*/
public record StringExpressionResult(String value) implements IEvaluateExpressionResult {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*******************************************************************************
* Copyright (c) 2024 Obeo.
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Obeo - initial API and implementation
*******************************************************************************/
package org.eclipse.sirius.web.application.views.query.dto;

/**
* Used to indicate the lack of result.
*
* @author sbegaudeau
*/
public record VoidExpressionResult() implements IEvaluateExpressionResult {
}
Loading

0 comments on commit 5091a81

Please sign in to comment.