-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[4375] Add support for impact analysis before tool execution
Bug: #4375 Signed-off-by: Florian ROUËNÉ <[email protected]>
- Loading branch information
Showing
55 changed files
with
2,115 additions
and
859 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
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
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
32 changes: 32 additions & 0 deletions
32
...ain/java/org/eclipse/sirius/components/collaborative/api/IToolRepresentationExecutor.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,32 @@ | ||
/******************************************************************************* | ||
* 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.components.collaborative.api; | ||
|
||
import java.util.List; | ||
|
||
import org.eclipse.sirius.components.collaborative.dto.ToolVariable; | ||
import org.eclipse.sirius.components.core.api.IEditingContext; | ||
import org.eclipse.sirius.components.representations.IRepresentation; | ||
import org.eclipse.sirius.components.representations.IStatus; | ||
|
||
/** | ||
* Used to execute a tool on a representation. | ||
* | ||
* @author frouene | ||
*/ | ||
public interface IToolRepresentationExecutor { | ||
|
||
boolean canExecute(IEditingContext editingContext, IRepresentation representation); | ||
|
||
IStatus execute(IEditingContext editingContext, IRepresentation representation, String toolId, String targetObjectId, List<ToolVariable> variables); | ||
} |
24 changes: 24 additions & 0 deletions
24
...e/src/main/java/org/eclipse/sirius/components/collaborative/dto/ImpactAnalysisReport.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,24 @@ | ||
/******************************************************************************* | ||
* 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.components.collaborative.dto; | ||
|
||
import java.util.List; | ||
|
||
/** | ||
* Report with data to display on an impact analysis. | ||
* | ||
* @author frouene | ||
*/ | ||
public record ImpactAnalysisReport(int nbElementDeleted, int nbElementModified, int nbElementCreated, List<String> additionalReports) { | ||
|
||
} |
27 changes: 27 additions & 0 deletions
27
...n/java/org/eclipse/sirius/components/collaborative/dto/InvokeImpactAnalysisToolInput.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,27 @@ | ||
/******************************************************************************* | ||
* 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.components.collaborative.dto; | ||
|
||
import java.util.List; | ||
import java.util.UUID; | ||
|
||
import org.eclipse.sirius.components.core.api.IInput; | ||
|
||
/** | ||
* The input for the "impact analysis" query. | ||
* | ||
* @author frouene | ||
*/ | ||
public record InvokeImpactAnalysisToolInput(UUID id, String editingContextId, String representationId, String toolId, String targetObjectId, List<ToolVariable> variables) implements IInput { | ||
|
||
} |
34 changes: 34 additions & 0 deletions
34
...g/eclipse/sirius/components/collaborative/dto/InvokeImpactAnalysisToolSuccessPayload.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,34 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2022, 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.components.collaborative.dto; | ||
|
||
import java.util.List; | ||
import java.util.Objects; | ||
import java.util.UUID; | ||
|
||
import org.eclipse.sirius.components.core.api.IPayload; | ||
import org.eclipse.sirius.components.representations.Message; | ||
|
||
/** | ||
* The "initial direct edit element label" success payload. | ||
* | ||
* @author gcoutable | ||
*/ | ||
public record InvokeImpactAnalysisToolSuccessPayload(UUID id, ImpactAnalysisReport impactAnalysisReport, List<Message> messages) implements IPayload { | ||
|
||
public InvokeImpactAnalysisToolSuccessPayload { | ||
Objects.requireNonNull(id); | ||
Objects.requireNonNull(impactAnalysisReport); | ||
Objects.requireNonNull(messages); | ||
} | ||
} |
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
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
10 changes: 10 additions & 0 deletions
10
...backend/sirius-components-collaborative/src/main/resources/schema/impactanalysis.graphqls
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,10 @@ | ||
extend type RepresentationMetadata { | ||
impactAnalysisReport(toolId: ID!, targetObjectId: ID!, variables: [ToolVariable!]!): ImpactAnalysisReport! | ||
} | ||
|
||
type ImpactAnalysisReport { | ||
nbElementDeleted: Int! | ||
nbElementModified: Int! | ||
nbElementCreated: Int! | ||
additionalReports: [String!]! | ||
} |
89 changes: 89 additions & 0 deletions
89
.../eclipse/sirius/components/core/graphql/datafetchers/ImpactAnalysisReportDataFetcher.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,89 @@ | ||
/******************************************************************************* | ||
* 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.components.core.graphql.datafetchers; | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Objects; | ||
import java.util.Optional; | ||
import java.util.UUID; | ||
import java.util.concurrent.CompletableFuture; | ||
|
||
import org.eclipse.sirius.components.annotations.spring.graphql.QueryDataFetcher; | ||
import org.eclipse.sirius.components.collaborative.dto.ImpactAnalysisReport; | ||
import org.eclipse.sirius.components.collaborative.dto.InvokeImpactAnalysisToolInput; | ||
import org.eclipse.sirius.components.collaborative.dto.InvokeImpactAnalysisToolSuccessPayload; | ||
import org.eclipse.sirius.components.collaborative.dto.ToolVariable; | ||
import org.eclipse.sirius.components.graphql.api.IDataFetcherWithFieldCoordinates; | ||
import org.eclipse.sirius.components.graphql.api.IEditingContextDispatcher; | ||
import org.eclipse.sirius.components.graphql.api.LocalContextConstants; | ||
|
||
import graphql.schema.DataFetchingEnvironment; | ||
import reactor.core.publisher.Mono; | ||
|
||
/** | ||
* Used to retrieve the impact analysis on a tool execution. | ||
* | ||
* @author frouene | ||
*/ | ||
@QueryDataFetcher(type = "RepresentationMetadata", field = "impactAnalysisReport") | ||
public class ImpactAnalysisReportDataFetcher implements IDataFetcherWithFieldCoordinates<CompletableFuture<ImpactAnalysisReport>> { | ||
|
||
private static final String TOOL_ID = "toolId"; | ||
private static final String TARGET_OBJECT_ID = "targetObjectId"; | ||
|
||
private static final String VARIABLES = "variables"; | ||
|
||
private final ObjectMapper objectMapper; | ||
|
||
private final IEditingContextDispatcher editingContextDispatcher; | ||
|
||
public ImpactAnalysisReportDataFetcher(ObjectMapper objectMapper, IEditingContextDispatcher editingContextDispatcher) { | ||
this.objectMapper = Objects.requireNonNull(objectMapper); | ||
this.editingContextDispatcher = Objects.requireNonNull(editingContextDispatcher); | ||
} | ||
|
||
@Override | ||
public CompletableFuture<ImpactAnalysisReport> get(DataFetchingEnvironment environment) throws Exception { | ||
CompletableFuture<ImpactAnalysisReport> result = Mono.<ImpactAnalysisReport>empty().toFuture(); | ||
Map<String, Object> localContext = environment.getLocalContext(); | ||
|
||
String editingContextId = Optional.ofNullable(localContext.get(LocalContextConstants.EDITING_CONTEXT_ID)).map(Object::toString).orElse(null); | ||
String representationId = Optional.ofNullable(localContext.get(LocalContextConstants.REPRESENTATION_ID)).map(Object::toString).orElse(null); | ||
String toolId = environment.getArgument(TOOL_ID); | ||
String targetObjectId = environment.getArgument(TARGET_OBJECT_ID); | ||
var variables = Optional.ofNullable(environment.getArgument(VARIABLES)) | ||
.filter(List.class::isInstance) | ||
.map(List.class::cast) | ||
.map(this::convertToToolVariables) | ||
.orElseGet(List::of); | ||
if (editingContextId != null && representationId != null) { | ||
InvokeImpactAnalysisToolInput input = new InvokeImpactAnalysisToolInput(UUID.randomUUID(), editingContextId, representationId, toolId, targetObjectId, variables); | ||
result = this.editingContextDispatcher.dispatchQuery(input.editingContextId(), input) | ||
.filter(InvokeImpactAnalysisToolSuccessPayload.class::isInstance) | ||
.map(InvokeImpactAnalysisToolSuccessPayload.class::cast) | ||
.map(InvokeImpactAnalysisToolSuccessPayload::impactAnalysisReport) | ||
.toFuture(); | ||
} | ||
return result; | ||
} | ||
|
||
private List<ToolVariable> convertToToolVariables(List<?> arguments) { | ||
return arguments.stream() | ||
.map(argument -> this.objectMapper.convertValue(argument, ToolVariable.class)) | ||
.toList(); | ||
} | ||
|
||
} |
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
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
Oops, something went wrong.