Skip to content

Commit

Permalink
[4474] Add EMF Services for Query View
Browse files Browse the repository at this point in the history
Bug: #4474
Signed-off-by: Axel RICHARD <[email protected]>
  • Loading branch information
AxelRICHARD committed Jan 28, 2025
1 parent f39045d commit 84f22bd
Show file tree
Hide file tree
Showing 5 changed files with 146 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ Note that you may need to encode special characters like `[`(by `%5B`) and `]` (
- https://github.com/eclipse-sirius/sirius-web/issues/4346[#4346] [query] Leverage the session storage to keep expressions entered in the query view even if the view is unmounted.
- https://github.com/eclipse-sirius/sirius-web/issues/4345[#4345] [table] Make table cells independently selectable
- https://github.com/eclipse-sirius/sirius-web/issues/4352[#4352] [table] Add support to range column filters in table
- https://github.com/eclipse-sirius/sirius-web/issues/4474[#4474] [query] Add EMF Services (eSet, eUnset) for the Query View.


== v2025.1.0
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*******************************************************************************
* 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.services;

import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EStructuralFeature;

/**
* Custom services to manipulate EMF objects.
*
* @author arichard
*/
public class EMFQueryServices {

public void eSet(EObject object, EStructuralFeature eStructuralFeature, Object newValue) {
object.eSet(eStructuralFeature, newValue);
}

public void eSet(EObject object, String eStructuralFeatureName, Object newValue) {
var eStructuralFeature = object.eClass().getEStructuralFeature(eStructuralFeatureName);
object.eSet(eStructuralFeature, newValue);
}

public void eUnset(EObject object, EStructuralFeature eStructuralFeature) {
object.eUnset(eStructuralFeature);
}

public void eUnset(EObject object, String eStructuralFeatureName) {
var eStructuralFeature = object.eClass().getEStructuralFeature(eStructuralFeatureName);
object.eUnset(eStructuralFeature);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*******************************************************************************
* 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.services;

import java.util.List;

import org.eclipse.sirius.components.core.api.IEditingContext;
import org.eclipse.sirius.web.application.views.query.services.api.IInterpreterJavaServiceProvider;
import org.springframework.stereotype.Service;

/**
* Used to contribute additional services while executing queries.
*
* @author arichard
*/
@Service
public class SiriusWebInterpreterJavaServiceProvider implements IInterpreterJavaServiceProvider {
@Override
public List<Class<?>> getServiceClasses(IEditingContext editingContext) {
return List.of(EMFQueryServices.class);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -183,4 +183,72 @@ public void givenProjectWhenWeExecuteAnExpressionUsingTheSelectionThenTheResultI
String name = JsonPath.read(result, "$.data.evaluateExpression.result.stringValue");
assertThat(name).isEqualTo("sirius-web-domain");
}

@Test
@GivenSiriusWebServer
@DisplayName("Given a project, when we execute an expression using the eSet EMF service, then the modification is executed")
public void givenProjectWhenWeExecuteAnExpressionUsingTheeSetEMFServiceThenTheModificationIsExecuted() {
var getNameExpression = "aql:self.eContainer(papaya::Project).eContents(papaya::Component)->first().name";
var selectedObjectIds = List.of(PapayaIdentifiers.SIRIUS_WEB_DOMAIN_OBJECT.toString());
var result = this.evaluateExpressionMutationRunner.run(new EvaluateExpressionInput(UUID.randomUUID(), PapayaIdentifiers.PAPAYA_PROJECT.toString(), getNameExpression, selectedObjectIds));

String payloadTypename = JsonPath.read(result, "$.data.evaluateExpression.__typename");
assertThat(payloadTypename).isEqualTo(EvaluateExpressionSuccessPayload.class.getSimpleName());

String resultTypename = JsonPath.read(result, "$.data.evaluateExpression.result.__typename");
assertThat(resultTypename).isEqualTo(StringExpressionResult.class.getSimpleName());

String name = JsonPath.read(result, "$.data.evaluateExpression.result.stringValue");
assertThat(name).isEqualTo("sirius-web-domain");

var componentNewName = "sirius-web-domain-renamed";
var setNameExpression = "aql:self.eContainer(papaya::Project).eContents(papaya::Component)->first().eSet('name' , '" + componentNewName + "')";
result = this.evaluateExpressionMutationRunner.run(new EvaluateExpressionInput(UUID.randomUUID(), PapayaIdentifiers.PAPAYA_PROJECT.toString(), setNameExpression, selectedObjectIds));

payloadTypename = JsonPath.read(result, "$.data.evaluateExpression.__typename");
assertThat(payloadTypename).isEqualTo(EvaluateExpressionSuccessPayload.class.getSimpleName());

resultTypename = JsonPath.read(result, "$.data.evaluateExpression.result.__typename");
assertThat(resultTypename).isEqualTo(VoidExpressionResult.class.getSimpleName());

result = this.evaluateExpressionMutationRunner.run(new EvaluateExpressionInput(UUID.randomUUID(), PapayaIdentifiers.PAPAYA_PROJECT.toString(), getNameExpression, selectedObjectIds));

name = JsonPath.read(result, "$.data.evaluateExpression.result.stringValue");
assertThat(name).isEqualTo(componentNewName);
}

@Test
@GivenSiriusWebServer
@DisplayName("Given a project, when we execute an expression using the eUnset EMF service, then the modification is executed")
public void givenProjectWhenWeExecuteAnExpressionUsingTheeUnsetEMFServiceThenTheModificationIsExecuted() {
var getNameExpression = "aql:self.eContainer(papaya::Project).eContents(papaya::Component)->first().name";
var selectedObjectIds = List.of(PapayaIdentifiers.SIRIUS_WEB_DOMAIN_OBJECT.toString());
var result = this.evaluateExpressionMutationRunner.run(new EvaluateExpressionInput(UUID.randomUUID(), PapayaIdentifiers.PAPAYA_PROJECT.toString(), getNameExpression, selectedObjectIds));

String payloadTypename = JsonPath.read(result, "$.data.evaluateExpression.__typename");
assertThat(payloadTypename).isEqualTo(EvaluateExpressionSuccessPayload.class.getSimpleName());

String resultTypename = JsonPath.read(result, "$.data.evaluateExpression.result.__typename");
assertThat(resultTypename).isEqualTo(StringExpressionResult.class.getSimpleName());

String name = JsonPath.read(result, "$.data.evaluateExpression.result.stringValue");
assertThat(name).isEqualTo("sirius-web-domain");

var unsetNameExpression = "aql:self.eContainer(papaya::Project).eContents(papaya::Component)->first().eUnset('name')";
result = this.evaluateExpressionMutationRunner.run(new EvaluateExpressionInput(UUID.randomUUID(), PapayaIdentifiers.PAPAYA_PROJECT.toString(), unsetNameExpression, selectedObjectIds));

payloadTypename = JsonPath.read(result, "$.data.evaluateExpression.__typename");
assertThat(payloadTypename).isEqualTo(EvaluateExpressionSuccessPayload.class.getSimpleName());

resultTypename = JsonPath.read(result, "$.data.evaluateExpression.result.__typename");
assertThat(resultTypename).isEqualTo(VoidExpressionResult.class.getSimpleName());

result = this.evaluateExpressionMutationRunner.run(new EvaluateExpressionInput(UUID.randomUUID(), PapayaIdentifiers.PAPAYA_PROJECT.toString(), getNameExpression, selectedObjectIds));

payloadTypename = JsonPath.read(result, "$.data.evaluateExpression.__typename");
assertThat(payloadTypename).isEqualTo(EvaluateExpressionSuccessPayload.class.getSimpleName());

resultTypename = JsonPath.read(result, "$.data.evaluateExpression.result.__typename");
assertThat(resultTypename).isEqualTo(VoidExpressionResult.class.getSimpleName());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import java.util.List;

import org.eclipse.sirius.components.core.api.IEditingContext;
import org.eclipse.sirius.web.application.views.query.services.EMFQueryServices;
import org.eclipse.sirius.web.application.views.query.services.api.IInterpreterJavaServiceProvider;
import org.springframework.stereotype.Service;

Expand All @@ -27,6 +28,6 @@
public class PapayaInterpreterJavaServiceProvider implements IInterpreterJavaServiceProvider {
@Override
public List<Class<?>> getServiceClasses(IEditingContext editingContext) {
return List.of(PapayaQueryServices.class);
return List.of(PapayaQueryServices.class, EMFQueryServices.class);
}
}

0 comments on commit 84f22bd

Please sign in to comment.