Skip to content

Commit

Permalink
[2796] Convert flow to view DSL
Browse files Browse the repository at this point in the history
Bug: #2796
Signed-off-by: Florian ROUËNÉ <florian.rouene@obeosoft.com>
  • Loading branch information
frouene committed Jan 9, 2024
1 parent 017e3ed commit f4dff4f
Show file tree
Hide file tree
Showing 69 changed files with 3,795 additions and 195 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ The GraphQL type `NodeDescription` has a new field `childNodeDescriptionIds`, re
The GraphQL type `NodeDescription` has a new field `borderNodeDescriptionIds`, returning a list of Ids and replacing the field `borderNodeDescriptions` which has been deleted.
- https://github.com/eclipse-sirius/sirius-web/issues/2872[#2872] [diagram] Change the signature of the node converters in order to leverage the diagram description to resolve the reuse descriptions.
Additional changes to this interface will propably occur in the near future in order to support more complex use cases.
- https://github.com/eclipse-sirius/sirius-web/issues/2796[#2796] [sirius-web] All Flow related configurations have been moved to `sirius-components-flow-starter` module.

=== Dependency update

Expand Down Expand Up @@ -139,6 +140,7 @@ This is a preliminary work to add some proper support for outside labels in the
- https://github.com/eclipse-sirius/sirius-web/issues/2869[#2869] [diagram] Add `diagramContext` variable to accessible variables when computing semantic candidates expression.
- https://github.com/eclipse-sirius/sirius-web/issues/2774[#2774] [gantt] Rework the gantt representation front-end to follow best practises.
- https://github.com/eclipse-sirius/sirius-web/issues/2872[#2872] [diagram] Reduce the time needed to retrieve a diagram description, thus leading to reduce the duration of diagrams opening.
- https://github.com/eclipse-sirius/sirius-web/issues/2796[#2796] [sirius-web] Flow diagram description has been converted to the view DSL.

== v2023.12.0

Expand Down
35 changes: 12 additions & 23 deletions packages/sirius-web/backend/sirius-web-sample-application/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@

<properties>
<java.version>17</java.version>
<flow.version>1.0.11-SNAPSHOT</flow.version>
<bpmn.version>4.0.3-SNAPSHOT</bpmn.version>
<eef.version>2.1.5-SNAPSHOT</eef.version>
</properties>
Expand Down Expand Up @@ -156,23 +155,13 @@
</dependency>
<dependency>
<groupId>org.eclipse.sirius</groupId>
<artifactId>sirius-components-view-deck</artifactId>
<version>2023.12.5</version>
</dependency>
<dependency>
<groupId>fr.obeo.dsl.designer.sample.flow</groupId>
<artifactId>fr.obeo.dsl.designer.sample.flow</artifactId>
<version>${flow.version}</version>
</dependency>
<dependency>
<groupId>fr.obeo.dsl.designer.sample.flow</groupId>
<artifactId>fr.obeo.dsl.designer.sample.flow.edit</artifactId>
<version>${flow.version}</version>
<artifactId>sirius-components-flow-starter</artifactId>
<version>2023.12.5</version>
</dependency>
<dependency>
<groupId>fr.obeo.dsl.designer.sample.flow</groupId>
<artifactId>fr.obeo.dsl.designer.sample.flow.design</artifactId>
<version>${flow.version}</version>
<groupId>org.eclipse.sirius</groupId>
<artifactId>sirius-components-view-deck</artifactId>
<version>2023.12.5</version>
</dependency>
<dependency>
<groupId>BPMN2</groupId>
Expand Down Expand Up @@ -269,13 +258,13 @@
<version>2023.12.5</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.eclipse.sirius</groupId>
<artifactId>sirius-components-view-deck-edit</artifactId>
<version>2023.12.5</version>
<scope>compile</scope>
</dependency>
</dependencies>
<dependency>
<groupId>org.eclipse.sirius</groupId>
<artifactId>sirius-components-view-deck-edit</artifactId>
<version>2023.12.5</version>
<scope>compile</scope>
</dependency>
</dependencies>

<build>
<plugins>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2019, 2023 Obeo.
* Copyright (c) 2019, 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
Expand All @@ -12,16 +12,11 @@
*******************************************************************************/
package org.eclipse.sirius.web.sample.configuration;

import fr.obeo.dsl.designer.sample.flow.FlowPackage;
import fr.obeo.dsl.designer.sample.flow.provider.FlowItemProviderAdapterFactory;

import org.eclipse.emf.common.notify.AdapterFactory;
import org.eclipse.emf.ecore.EPackage;
import org.eclipse.sirius.components.domain.DomainPackage;
import org.eclipse.sirius.components.domain.provider.DomainItemProviderAdapterFactory;
import org.eclipse.sirius.components.emf.configuration.ChildExtenderProvider;
import org.eclipse.sirius.components.emf.services.ILabelFeatureProvider;
import org.eclipse.sirius.components.emf.services.LabelFeatureProvider;
import org.eclipse.sirius.components.view.ViewPackage;
import org.eclipse.sirius.components.view.diagram.DiagramPackage;
import org.eclipse.sirius.components.view.diagram.provider.DiagramItemProviderAdapterFactory;
Expand All @@ -44,21 +39,6 @@
@Configuration
public class SampleEMFConfiguration {

@Bean
public AdapterFactory flowAdapterFactory() {
return new FlowItemProviderAdapterFactory();
}

@Bean
public EPackage flowEPackage() {
return FlowPackage.eINSTANCE;
}

@Bean
public ILabelFeatureProvider flowLabelFeatureProvider() {
return new LabelFeatureProvider(FlowPackage.eINSTANCE.getNsURI(), new FlowLabelFeatureSwitch(), new FlowEditableSwitch());
}

@Bean
@ConditionalOnProperty(prefix = "org.eclipse.sirius.web.features", name = "studioDefinition")
public EPackage domainEPackage() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2019, 2022 Obeo.
* Copyright (c) 2019, 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
Expand Down Expand Up @@ -29,7 +29,7 @@ public class SampleSiriusConfiguration implements ISiriusConfiguration {

@Override
public List<String> getODesignPaths() {
return List.of("description/flow.odesign");
return List.of();
}

@Bean
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2019, 2023 Obeo.
* Copyright (c) 2019, 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
Expand All @@ -12,8 +12,6 @@
*******************************************************************************/
package org.eclipse.sirius.web.sample.configuration;

import fr.obeo.dsl.designer.sample.flow.FlowFactory;

import java.util.List;
import java.util.UUID;

Expand All @@ -30,7 +28,6 @@
import org.eclipse.sirius.web.sample.papaya.view.PapayaViewProvider;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.ClassPathResource;

import io.micrometer.core.instrument.MeterRegistry;

Expand All @@ -46,18 +43,6 @@ public class StereotypeDescriptionRegistryConfigurer implements IStereotypeDescr

public static final String EMPTY_LABEL = "Others...";

public static final UUID EMPTY_FLOW_ID = UUID.nameUUIDFromBytes("empty_flow".getBytes());

public static final String EMPTY_FLOW_LABEL = "Flow";

public static final UUID ROBOT_FLOW_ID = UUID.nameUUIDFromBytes("robot_flow".getBytes());

public static final String ROBOT_FLOW_LABEL = "Robot Flow";

public static final UUID BIG_GUY_FLOW_ID = UUID.nameUUIDFromBytes("big_guy_flow".getBytes());

public static final String BIG_GUY_FLOW_LABEL = "Big Guy Flow (17k elements)";

public static final UUID EMPTY_VIEW_ID = UUID.nameUUIDFromBytes("empty_view".getBytes());

public static final String EMPTY_VIEW_LABEL = "View";
Expand Down Expand Up @@ -90,15 +75,12 @@ public StereotypeDescriptionRegistryConfigurer(MeterRegistry meterRegistry, @Val

@Override
public void addStereotypeDescriptions(IStereotypeDescriptionRegistry registry) {
registry.add(new StereotypeDescription(EMPTY_FLOW_ID, EMPTY_FLOW_LABEL, this::getEmptyFlowContent));
if (this.studiosEnabled) {
registry.add(new StereotypeDescription(EMPTY_DOMAIN_ID, EMPTY_DOMAIN_LABEL, this::getEmptyDomainContent));
registry.add(new StereotypeDescription(EMPTY_VIEW_ID, EMPTY_VIEW_LABEL, this::getEmptyViewContent));
registry.add(new StereotypeDescription(PAPAYA_DOMAIN_ID, PAPAYA_DOMAIN_LABEL, this::getPapayaDomainContent));
registry.add(new StereotypeDescription(PAPAYA_VIEW_ID, PAPAYA_VIEW_LABEL, this::getPapayaViewContent));
}
registry.add(new StereotypeDescription(ROBOT_FLOW_ID, ROBOT_FLOW_LABEL, this::getRobotFlowContent));
registry.add(new StereotypeDescription(BIG_GUY_FLOW_ID, BIG_GUY_FLOW_LABEL, this::getBigGuyFlowContent));
registry.add(new StereotypeDescription(EMPTY_ID, EMPTY_LABEL, "New", this::getEmptyContent));
}

Expand Down Expand Up @@ -130,15 +112,4 @@ private String getEmptyContent() {
return this.stereotypeBuilder.getStereotypeBody(List.of());
}

private String getEmptyFlowContent() {
return this.stereotypeBuilder.getStereotypeBody(List.of(FlowFactory.eINSTANCE.createSystem()));
}

private String getRobotFlowContent() {
return this.stereotypeBuilder.getStereotypeBody(new ClassPathResource("robot.flow"));
}

private String getBigGuyFlowContent() {
return this.stereotypeBuilder.getStereotypeBody(new ClassPathResource("Big_Guy.flow"));
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2023 Obeo.
* Copyright (c) 2023, 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
Expand All @@ -12,32 +12,19 @@
*******************************************************************************/
package org.eclipse.sirius.web.sample.services;

import static org.eclipse.sirius.web.sample.services.EditingContextActionProvider.BIG_GUY_FLOW_ID;
import static org.eclipse.sirius.web.sample.services.EditingContextActionProvider.EMPTY_ACTION_ID;
import static org.eclipse.sirius.web.sample.services.EditingContextActionProvider.EMPTY_DOMAIN_ID;
import static org.eclipse.sirius.web.sample.services.EditingContextActionProvider.EMPTY_FLOW_ID;
import static org.eclipse.sirius.web.sample.services.EditingContextActionProvider.EMPTY_VIEW_ID;
import static org.eclipse.sirius.web.sample.services.EditingContextActionProvider.PAPAYA_DOMAIN_ID;
import static org.eclipse.sirius.web.sample.services.EditingContextActionProvider.PAPAYA_VIEW_ID;
import static org.eclipse.sirius.web.sample.services.EditingContextActionProvider.ROBOT_FLOW_ID;

import fr.obeo.dsl.designer.sample.flow.FlowFactory;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.UUID;
import java.util.function.Consumer;

import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.emf.ecore.xmi.XMLParserPool;
import org.eclipse.emf.ecore.xmi.impl.XMIResourceImpl;
import org.eclipse.emf.ecore.xmi.impl.XMLParserPoolImpl;
import org.eclipse.emf.edit.domain.AdapterFactoryEditingDomain;
import org.eclipse.sirius.components.collaborative.api.ChangeKind;
import org.eclipse.sirius.components.collaborative.api.IEditingContextActionHandler;
Expand All @@ -47,7 +34,6 @@
import org.eclipse.sirius.components.emf.ResourceMetadataAdapter;
import org.eclipse.sirius.components.emf.services.EditingContext;
import org.eclipse.sirius.components.emf.services.JSONResourceFactory;
import org.eclipse.sirius.components.emf.utils.EMFResourceUtils;
import org.eclipse.sirius.components.representations.Failure;
import org.eclipse.sirius.components.representations.IStatus;
import org.eclipse.sirius.components.representations.Success;
Expand All @@ -61,7 +47,6 @@
import org.eclipse.sirius.web.sample.papaya.view.PapayaViewProvider;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.core.io.ClassPathResource;
import org.springframework.stereotype.Service;


Expand All @@ -73,9 +58,7 @@
@Service
public class EditingContextActionHandler implements IEditingContextActionHandler {

private static final XMLParserPool PARSER_POOL = new XMLParserPoolImpl();

private static final List<String> HANDLED_ACTIONS = List.of(EMPTY_ACTION_ID, EMPTY_FLOW_ID, ROBOT_FLOW_ID, BIG_GUY_FLOW_ID,
private static final List<String> HANDLED_ACTIONS = List.of(EMPTY_ACTION_ID,
EMPTY_DOMAIN_ID, PAPAYA_DOMAIN_ID, EMPTY_VIEW_ID, PAPAYA_VIEW_ID);

private final Logger logger = LoggerFactory.getLogger(EditingContextActionHandler.class);
Expand Down Expand Up @@ -105,9 +88,6 @@ public IStatus handle(IEditingContext editingContext, String actionId) {
private IStatus performActionOnResourceSet(ResourceSet resourceSet, String actionId) {
return switch (actionId) {
case EMPTY_ACTION_ID -> this.createResourceAndReturnSuccess(resourceSet, this::createEmptyResource);
case EMPTY_FLOW_ID -> this.createResourceAndReturnSuccess(resourceSet, this::createEmptyFlowResource);
case ROBOT_FLOW_ID -> this.createResourceAndReturnSuccess(resourceSet, this::createRobotFlowResource);
case BIG_GUY_FLOW_ID -> this.createResourceAndReturnSuccess(resourceSet, this::createBigGuyFlowResource);
case EMPTY_DOMAIN_ID -> this.createResourceAndReturnSuccess(resourceSet, this::createEmptyDomainResource);
case PAPAYA_DOMAIN_ID -> this.createResourceAndReturnSuccess(resourceSet, this::createPapayaDomainResource);
case EMPTY_VIEW_ID -> this.createResourceAndReturnSuccess(resourceSet, this::createEmptyViewResource);
Expand All @@ -128,13 +108,6 @@ private void createEmptyResource(ResourceSet resourceSet) {
resourceSet.getResources().add(resource);
}

private void createEmptyFlowResource(ResourceSet resourceSet) {
JsonResource resource = new JSONResourceFactory().createResourceFromPath(UUID.randomUUID().toString());
resource.getContents().add(FlowFactory.eINSTANCE.createSystem());
resource.eAdapters().add(new ResourceMetadataAdapter("Flow"));
resourceSet.getResources().add(resource);
}

private void createEmptyDomainResource(ResourceSet resourceSet) {
JsonResource resource = new JSONResourceFactory().createResourceFromPath(UUID.randomUUID().toString());
Domain domain = DomainFactory.eINSTANCE.createDomain();
Expand Down Expand Up @@ -171,49 +144,4 @@ private void createPapayaViewResource(ResourceSet resourceSet) {
resourceSet.getResources().add(resource);
}


private void createRobotFlowResource(ResourceSet resourceSet) {
this.getResourceFromClassPathResource(new ClassPathResource("robot.flow")).ifPresent(resource -> {
resource.eAdapters().add(new ResourceMetadataAdapter("Robot Flow"));
resourceSet.getResources().add(resource);
});
}

private void createBigGuyFlowResource(ResourceSet resourceSet) {
this.getResourceFromClassPathResource(new ClassPathResource("Big_Guy.flow")).ifPresent(resource -> {
resource.eAdapters().add(new ResourceMetadataAdapter("Big Guy Flow (17k elements)"));
resourceSet.getResources().add(resource);
});
}

public Optional<Resource> getResourceFromClassPathResource(ClassPathResource classPathResource) {

try (var inputStream = classPathResource.getInputStream()) {
URI uri = new JSONResourceFactory().createResourceURI(UUID.randomUUID().toString());
return Optional.of(this.loadFromXMIAndTransformToJSONResource(uri, inputStream));
} catch (IOException exception) {
this.logger.error(exception.getMessage(), exception);
return Optional.empty();
}
}

private Resource loadFromXMIAndTransformToJSONResource(URI uri, InputStream inputStream) throws IOException {
Resource inputResource = new XMIResourceImpl(uri);
Map<String, Object> xmiLoadOptions = new EMFResourceUtils().getXMILoadOptions(PARSER_POOL);
inputResource.load(inputStream, xmiLoadOptions);
return this.transformToJSON(uri, inputResource);
}

private JsonResource transformToJSON(URI uri, Resource inputResource) throws IOException {
JsonResource outputResource = new JSONResourceFactory().createResource(uri);
outputResource.getContents().addAll(inputResource.getContents());
try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) {
Map<String, Object> jsonSaveOptions = new EMFResourceUtils().getFastJSONSaveOptions();
jsonSaveOptions.put(JsonResource.OPTION_ENCODING, JsonResource.ENCODING_UTF_8);
jsonSaveOptions.put(JsonResource.OPTION_SCHEMA_LOCATION, Boolean.TRUE);
outputResource.save(outputStream, jsonSaveOptions);
}
return outputResource;
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2023 Obeo.
* Copyright (c) 2023, 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
Expand Down Expand Up @@ -34,12 +34,6 @@ public class EditingContextActionProvider implements IEditingContextActionProvid

public static final String EMPTY_ACTION_ID = "empty";

public static final String EMPTY_FLOW_ID = "empty_flow";

public static final String ROBOT_FLOW_ID = "robot_flow";

public static final String BIG_GUY_FLOW_ID = "big_guy_flow";

public static final String EMPTY_DOMAIN_ID = "empty_domain";

public static final String PAPAYA_DOMAIN_ID = "papaya_domain";
Expand All @@ -50,12 +44,6 @@ public class EditingContextActionProvider implements IEditingContextActionProvid

private static final EditingContextAction EMPTY_EDITING_CONTEXT_ACTION = new EditingContextAction(EMPTY_ACTION_ID, "Others...");

private static final EditingContextAction EMPTY_FLOW_EDITING_CONTEXT_ACTION = new EditingContextAction(EMPTY_FLOW_ID, "Flow");

private static final EditingContextAction ROBOT_FLOW_EDITING_CONTEXT_ACTION = new EditingContextAction(ROBOT_FLOW_ID, "Robot Flow");

private static final EditingContextAction BIG_GUY_FLOW_EDITING_CONTEXT_ACTION = new EditingContextAction(BIG_GUY_FLOW_ID, "Big Guy Flow (17k elements)");

private static final EditingContextAction EMPTY_DOMAIN_EDITING_CONTEXT_ACTION = new EditingContextAction(EMPTY_DOMAIN_ID, "Domain");

private static final EditingContextAction PAPAYA_DOMAIN_EDITING_CONTEXT_ACTION = new EditingContextAction(PAPAYA_DOMAIN_ID, "Papaya Domain");
Expand All @@ -78,9 +66,6 @@ public List<EditingContextAction> getEditingContextAction(IEditingContext editin
var containsDomain = nsURIs.contains(DomainPackage.eNS_URI);
var containsView = nsURIs.contains(ViewPackage.eNS_URI);

actions.add(EMPTY_FLOW_EDITING_CONTEXT_ACTION);
actions.add(ROBOT_FLOW_EDITING_CONTEXT_ACTION);
actions.add(BIG_GUY_FLOW_EDITING_CONTEXT_ACTION);
if (containsDomain) {
actions.add(EMPTY_DOMAIN_EDITING_CONTEXT_ACTION);
}
Expand Down
Loading

0 comments on commit f4dff4f

Please sign in to comment.