-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bug: #4346 Signed-off-by: Stéphane Bégaudeau <stephane.begaudeau@obeo.fr>
- Loading branch information
1 parent
0d6a13e
commit bce2046
Showing
22 changed files
with
1,077 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
doc/iterations/2025.2/add_support_for_an_interpreter_view.adoc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
= (M) Shape | ||
|
||
== Problem | ||
|
||
Sirius Web users need an interpreter to perform some queries, view and export 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). | ||
End users shall be able to export the result in CSV for example to import it in another tool. | ||
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. | ||
|
||
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 |
57 changes: 57 additions & 0 deletions
57
...sirius/web/application/views/query/controllers/MutationEvaluateExpressionDataFetcher.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
...main/java/org/eclipse/sirius/web/application/views/query/dto/BooleanExpressionResult.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 { | ||
} |
25 changes: 25 additions & 0 deletions
25
...main/java/org/eclipse/sirius/web/application/views/query/dto/EvaluateExpressionInput.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 { | ||
} |
29 changes: 29 additions & 0 deletions
29
.../org/eclipse/sirius/web/application/views/query/dto/EvaluateExpressionSuccessPayload.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 { | ||
} |
16 changes: 16 additions & 0 deletions
16
...in/java/org/eclipse/sirius/web/application/views/query/dto/IEvaluateExpressionResult.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
/******************************************************************************* | ||
* 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; | ||
|
||
public interface IEvaluateExpressionResult { | ||
} |
21 changes: 21 additions & 0 deletions
21
...src/main/java/org/eclipse/sirius/web/application/views/query/dto/IntExpressionResult.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 { | ||
} |
16 changes: 16 additions & 0 deletions
16
.../main/java/org/eclipse/sirius/web/application/views/query/dto/ObjectExpressionResult.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
/******************************************************************************* | ||
* 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; | ||
|
||
public record ObjectExpressionResult() implements IEvaluateExpressionResult { | ||
} |
23 changes: 23 additions & 0 deletions
23
...main/java/org/eclipse/sirius/web/application/views/query/dto/ObjectsExpressionResult.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 { | ||
} |
21 changes: 21 additions & 0 deletions
21
.../main/java/org/eclipse/sirius/web/application/views/query/dto/StringExpressionResult.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 { | ||
} |
16 changes: 16 additions & 0 deletions
16
...rc/main/java/org/eclipse/sirius/web/application/views/query/dto/VoidExpressionResult.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
/******************************************************************************* | ||
* 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; | ||
|
||
public record VoidExpressionResult() implements IEvaluateExpressionResult { | ||
} |
85 changes: 85 additions & 0 deletions
85
.../java/org/eclipse/sirius/web/application/views/query/services/AQLInterpreterProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
/******************************************************************************* | ||
* 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.services; | ||
|
||
import java.util.List; | ||
import java.util.Objects; | ||
|
||
import org.eclipse.emf.ecore.EPackage; | ||
import org.eclipse.sirius.components.core.api.IEditingContext; | ||
import org.eclipse.sirius.components.emf.query.EditingContextServices; | ||
import org.eclipse.sirius.components.emf.services.api.IEMFEditingContext; | ||
import org.eclipse.sirius.components.interpreter.AQLInterpreter; | ||
import org.eclipse.sirius.web.application.views.query.services.api.IAQLInterpreterProvider; | ||
import org.eclipse.sirius.web.application.views.query.services.api.IInterpreterJavaServiceProvider; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.beans.BeansException; | ||
import org.springframework.beans.factory.config.AutowireCapableBeanFactory; | ||
import org.springframework.context.ApplicationContext; | ||
import org.springframework.stereotype.Service; | ||
|
||
/** | ||
* Used to provide the AQL interpreter. | ||
* | ||
* @author sbegaudeau | ||
*/ | ||
@Service | ||
public class AQLInterpreterProvider implements IAQLInterpreterProvider { | ||
|
||
private final List<IInterpreterJavaServiceProvider> interpreterJavaServiceProviders; | ||
|
||
private final ApplicationContext applicationContext; | ||
|
||
private final Logger logger = LoggerFactory.getLogger(AQLInterpreterProvider.class); | ||
|
||
public AQLInterpreterProvider(List<IInterpreterJavaServiceProvider> interpreterJavaServiceProviders, ApplicationContext applicationContext) { | ||
this.interpreterJavaServiceProviders = Objects.requireNonNull(interpreterJavaServiceProviders); | ||
this.applicationContext = Objects.requireNonNull(applicationContext); | ||
} | ||
|
||
@Override | ||
public AQLInterpreter getInterpreter(IEditingContext editingContext) { | ||
var ePackages = this.getEPackages(editingContext); | ||
var services = this.getServices(editingContext); | ||
return new AQLInterpreter(List.of(EditingContextServices.class), services, ePackages); | ||
} | ||
|
||
private List<EPackage> getEPackages(IEditingContext editingContext) { | ||
if (editingContext instanceof IEMFEditingContext emfEditingContext) { | ||
EPackage.Registry packageRegistry = emfEditingContext.getDomain().getResourceSet().getPackageRegistry(); | ||
return packageRegistry.values().stream() | ||
.filter(EPackage.class::isInstance) | ||
.map(EPackage.class::cast) | ||
.toList(); | ||
} | ||
return List.of(); | ||
} | ||
|
||
private List<Object> getServices(IEditingContext editingContext) { | ||
AutowireCapableBeanFactory beanFactory = this.applicationContext.getAutowireCapableBeanFactory(); | ||
return this.interpreterJavaServiceProviders.stream() | ||
.flatMap(provider -> provider.getServiceClasses(editingContext).stream()) | ||
.map(serviceClass -> { | ||
try { | ||
return beanFactory.createBean(serviceClass); | ||
} catch (BeansException beansException) { | ||
this.logger.warn("Error while trying to instantiate Java service class " + serviceClass.getName(), beansException); | ||
return null; | ||
} | ||
}) | ||
.filter(Objects::nonNull) | ||
.map(Object.class::cast) | ||
.toList(); | ||
} | ||
} |
Oops, something went wrong.