Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[4346] Add support for a query view #4347

Merged
merged 2 commits into from
Jan 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 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 Down Expand Up @@ -32,6 +34,8 @@ This may have some consequences for downstream applications which are embedding

- https://github.com/eclipse-sirius/sirius-web/issues/4356[#4356] [diagram] Add a minimap to diagram.
+ Added by default to all sirius-web diagrams
- https://github.com/eclipse-sirius/sirius-web/issues/4346[#4346] [query] 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

==== A user wants to query some models

- 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) 2025 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) 2025 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) 2025 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) 2025 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) 2025 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) 2025 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) 2025 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) 2025 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) 2025 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) 2025 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
Loading