Skip to content

Commit

Permalink
UUID to URLS
Browse files Browse the repository at this point in the history
Bug : eclipse-sirius#1860

Signed-off-by: Michaël Charfadi <[email protected]>
  • Loading branch information
mcharfadi committed Mar 22, 2023
1 parent a298eed commit 7453832
Show file tree
Hide file tree
Showing 6 changed files with 161 additions and 16 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,15 @@
=== Breaking changes

- https://github.com/eclipse-sirius/sirius-components/issues/1860[1860] [view] Changed the type of descriptionId of Node and Edge from UUID to String
+
Changed values of descriptionId from string uuid to URL with theses syntaxes :
+
DiagramDescription#descriptionId to siriusComponents://diagramDescription?sourceKind=view&sourceId=UUID_OF_DOCUMENT&sourceElementId=UUID_OF_SOURCE_ELEMENT
+
NodeDescription#descriptionId to siriusComponents://nodeDescription?sourceKind=view&sourceId=UUID_OF_DOCUMENT&sourceElementId=UUID_OF_SOURCE_ELEMENT
+
EdgeDescription#descriptionId to vers siriusComponents://edgeDescription?sourceKind=view&sourceId=UUID_OF_DOCUMENT&sourceElementId=UUID_OF_SOURCE_ELEMENT

- https://github.com/eclipse-sirius/sirius-components/issues/1643[1643] [core] Removed our dependencies to Spring Security
- https://github.com/eclipse-sirius/sirius-components/issues/1592[#1592] [view] In View-based diagram definition, all tools applicable on a given element are now configured inside the new _Palette_ element directly inside the element (diagram, node or edge) description.
- https://github.com/eclipse-sirius/sirius-components/issues/1761[#1761] [core] Remove `sirius-web-graphql-schema` since it was not really used anymore
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,12 @@
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.sirius.components.emf.services.JSONResourceFactory;
import org.eclipse.sirius.components.view.DiagramDescription;
import org.eclipse.sirius.components.view.RepresentationDescription;
import org.eclipse.sirius.components.view.View;
import org.eclipse.sirius.components.view.ViewPackage;
import org.eclipse.sirius.components.view.emf.IViewService;
import org.eclipse.sirius.components.view.emf.diagram.IdDiagramProvider;
import org.eclipse.sirius.emfjson.resource.JsonResource;
import org.eclipse.sirius.web.persistence.entities.DocumentEntity;
import org.eclipse.sirius.web.persistence.repositories.IDocumentRepository;
Expand All @@ -53,7 +55,10 @@ public class ViewService implements IViewService {

private final EPackage.Registry ePackageRegistry;

public ViewService(IDocumentRepository documentRepository, EPackage.Registry ePackageRegistry) {
private final IdDiagramProvider idProvider;

public ViewService(IdDiagramProvider idProvider, IDocumentRepository documentRepository, EPackage.Registry ePackageRegistry) {
this.idProvider = Objects.requireNonNull(idProvider);
this.documentRepository = Objects.requireNonNull(documentRepository);
this.ePackageRegistry = Objects.requireNonNull(ePackageRegistry);
}
Expand Down Expand Up @@ -96,6 +101,10 @@ private Stream<View> getViewDefinitions(Resource resource) {
}

private String getDescriptionId(EObject description) {
if (description instanceof DiagramDescription diagramDescription) {
return this.idProvider.getIdDiagramDescription(diagramDescription);
}

String descriptionURI = EcoreUtil.getURI(description).toString();
return UUID.nameUUIDFromBytes(descriptionURI.getBytes()).toString();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*******************************************************************************
* Copyright (c) 2023 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.view.emf.diagram;


import org.eclipse.sirius.components.view.DiagramDescription;
import org.eclipse.sirius.components.view.DiagramElementDescription;

/**
* Interface to provide ids for DiagramDescription & DiagramElementDescription.
*
* @author mcharfadi
*/
public interface IIdDiagramProvider {

String getIdDiagramDescription(DiagramDescription diagramDescription);

String getIdElementDescription(DiagramElementDescription diagramElementDescription);

/**
* Implementation which does nothing, used for mocks in unit tests.
*
* @author mcharfadi
*/
class NoOp implements IIdDiagramProvider {

@Override
public String getIdDiagramDescription(DiagramDescription diagramDescription) {
return "";
}

@Override
public String getIdElementDescription(DiagramElementDescription diagramElementDescription) {
return "";
}

}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/*******************************************************************************
* Copyright (c) 2023 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.view.emf.diagram;

import java.util.Objects;

import org.eclipse.emf.ecore.EObject;
import org.eclipse.sirius.components.core.api.IObjectService;
import org.eclipse.sirius.components.view.DiagramDescription;
import org.eclipse.sirius.components.view.DiagramElementDescription;
import org.springframework.stereotype.Service;

/**
* Set a detailed descriptionID.
*
* @author mcharfadi
*/
@Service
public class IdDiagramProvider implements IIdDiagramProvider {

private static final String SIRIUS_PROTOCOL = "siriusComponents://";

private static final String SOURCE_KIND_VIEW = "?sourceKind=view";

private static final String DIAGRAM_PATH_VIEW = SIRIUS_PROTOCOL + "diagramDescription" + SOURCE_KIND_VIEW;

private static final String EDGE_PATH_VIEW = SIRIUS_PROTOCOL + "edgeDescription" + SOURCE_KIND_VIEW;

private static final String NODE_PATH_VIEW = SIRIUS_PROTOCOL + "nodeDescription" + SOURCE_KIND_VIEW;

private static final String SOURCE_ID = "sourceId=";

private static final String SOURCE_ELEMENT_ID = "sourceElementId=";

private static final String AMPERSAND = "&";

private IObjectService objectService;

public IdDiagramProvider(IObjectService objectService) {
this.objectService = Objects.requireNonNull(objectService);
}

@Override
public String getIdDiagramDescription(DiagramDescription diagramDescription) {
String sourceId = this.getSourceIdFromElementDescription(diagramDescription);
String sourceElementId = this.objectService.getId(diagramDescription);
return DIAGRAM_PATH_VIEW + AMPERSAND + SOURCE_ID + sourceId + AMPERSAND + SOURCE_ELEMENT_ID + sourceElementId;
}

@Override
public String getIdElementDescription(DiagramElementDescription diagramElementDescription) {
String sourceId = this.getSourceIdFromElementDescription(diagramElementDescription);
String sourceElementId = this.objectService.getId(diagramElementDescription);
if (diagramElementDescription instanceof org.eclipse.sirius.components.view.NodeDescription) {
return NODE_PATH_VIEW + AMPERSAND + SOURCE_ID + sourceId + AMPERSAND + SOURCE_ELEMENT_ID + sourceElementId;
}
else {
return EDGE_PATH_VIEW + AMPERSAND + SOURCE_ID + sourceId + AMPERSAND + SOURCE_ELEMENT_ID + sourceElementId;
}
}

private String getSourceIdFromElementDescription(EObject elementDescription) {
return elementDescription.eResource().getURI().toString().split("///")[1];
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.UUID;
import java.util.function.BiFunction;
import java.util.function.Function;
import java.util.function.Predicate;
Expand Down Expand Up @@ -88,6 +87,8 @@ public class ViewDiagramDescriptionConverter implements IRepresentationDescripti

private final IObjectService objectService;

private final IIdDiagramProvider idProvider;

private final IEditService editService;

private final StylesFactory stylesFactory;
Expand All @@ -98,20 +99,19 @@ public class ViewDiagramDescriptionConverter implements IRepresentationDescripti

private final Function<VariableManager, String> semanticTargetLabelProvider;

private final Function<DiagramElementDescription, String> idProvider = (diagramElementDescription) -> {
// DiagramElementDescription should have a proper id.
return UUID.nameUUIDFromBytes(EcoreUtil.getURI(diagramElementDescription).toString().getBytes()).toString();
};
private final Function<org.eclipse.sirius.components.view.DiagramElementDescription, String> diagramIdElementProvider;

private final IViewToolImageProvider viewToolImageProvider;

public ViewDiagramDescriptionConverter(IObjectService objectService, IEditService editService, List<INodeStyleProvider> iNodeStyleProviders, IViewToolImageProvider viewToolImageProvider) {
public ViewDiagramDescriptionConverter(IIdDiagramProvider idProvider, IObjectService objectService, IEditService editService, List<INodeStyleProvider> iNodeStyleProviders, IViewToolImageProvider viewToolImageProvider) {
this.objectService = Objects.requireNonNull(objectService);
this.idProvider = Objects.requireNonNull(idProvider);
this.editService = Objects.requireNonNull(editService);
this.stylesFactory = new StylesFactory(Objects.requireNonNull(iNodeStyleProviders), this.objectService);
this.semanticTargetIdProvider = variableManager -> this.self(variableManager).map(this.objectService::getId).orElse(null);
this.semanticTargetKindProvider = variableManager -> this.self(variableManager).map(this.objectService::getKind).orElse(null);
this.semanticTargetLabelProvider = variableManager -> this.self(variableManager).map(this.objectService::getLabel).orElse(null);
this.diagramIdElementProvider = (diagramElementDescription) -> this.idProvider.getIdElementDescription(diagramElementDescription);
this.viewToolImageProvider = Objects.requireNonNull(viewToolImageProvider);
}

Expand All @@ -128,9 +128,9 @@ public IRepresentationDescription convert(RepresentationDescription viewRepresen
List<NodeDescription> nodeDescriptions = viewDiagramDescription.getNodeDescriptions().stream().map(node -> this.convert(node, converterContext)).toList();
List<EdgeDescription> edgeDescriptions = viewDiagramDescription.getEdgeDescriptions().stream().map(edge -> this.convert(edge, converterContext)).toList();
// @formatter:off
String diagramDescriptionURI = EcoreUtil.getURI(viewDiagramDescription).toString();
var toolConverter = new ToolConverter(this.objectService, this.editService, this.viewToolImageProvider);
return DiagramDescription.newDiagramDescription(UUID.nameUUIDFromBytes(diagramDescriptionURI.getBytes()).toString())

return DiagramDescription.newDiagramDescription(this.idProvider.getIdDiagramDescription(viewDiagramDescription))
.label(Optional.ofNullable(viewDiagramDescription.getName()).orElse(DEFAULT_DIAGRAM_LABEL))
.labelProvider(variableManager -> this.computeDiagramLabel(viewDiagramDescription, variableManager, interpreter))
.canCreatePredicate(new IViewDiagramCreationPredicate() {
Expand Down Expand Up @@ -237,18 +237,18 @@ private NodeDescription convert(org.eclipse.sirius.components.view.NodeDescripti

// @formatter:off
List<String> reusedChildNodeDescriptionIds = viewNodeDescription.getReusedChildNodeDescriptions().stream()
.map(this.idProvider)
.map(this.diagramIdElementProvider)
.toList();
List<String> reusedBorderNodeDescriptionIds = viewNodeDescription.getReusedBorderNodeDescriptions().stream()
.map(this.idProvider)
.map(this.diagramIdElementProvider)
.toList();

Predicate<VariableManager> shouldRenderPredicate = variableManager -> {
Result result = interpreter.evaluateExpression(variableManager.getVariables(), viewNodeDescription.getPreconditionExpression());
return result.asBoolean().orElse(true);
};

NodeDescription result = NodeDescription.newNodeDescription(this.idProvider.apply(viewNodeDescription))
NodeDescription result = NodeDescription.newNodeDescription(this.idProvider.getIdElementDescription(viewNodeDescription))
.targetObjectIdProvider(this.semanticTargetIdProvider)
.targetObjectKindProvider(this.semanticTargetKindProvider)
.targetObjectLabelProvider(this.semanticTargetLabelProvider)
Expand Down Expand Up @@ -426,7 +426,7 @@ private EdgeDescription convert(org.eclipse.sirius.components.view.EdgeDescripti
};
}

Function<VariableManager, List<Element>> targetNodesProvider = new TargetNodesProvider(this.idProvider, viewEdgeDescription, interpreter);
Function<VariableManager, List<Element>> targetNodesProvider = new TargetNodesProvider(this.diagramIdElementProvider, viewEdgeDescription, interpreter);

Function<VariableManager, EdgeStyle> styleProvider = variableManager -> {
// @formatter:off
Expand All @@ -442,7 +442,7 @@ private EdgeDescription convert(org.eclipse.sirius.components.view.EdgeDescripti
SynchronizationPolicy synchronizationPolicy = SynchronizationPolicy.valueOf(viewEdgeDescription.getSynchronizationPolicy().getName());

// @formatter:off
var builder = EdgeDescription.newEdgeDescription(this.idProvider.apply(viewEdgeDescription))
var builder = EdgeDescription.newEdgeDescription(this.idProvider.getIdElementDescription(viewEdgeDescription))
.targetObjectIdProvider(this.semanticTargetIdProvider)
.targetObjectKindProvider(this.semanticTargetKindProvider)
.targetObjectLabelProvider(this.semanticTargetLabelProvider)
Expand Down Expand Up @@ -587,7 +587,7 @@ private Predicate<Element> isFromCompatibleSourceMapping(org.eclipse.sirius.comp

private boolean isFromDescription(Element nodeElement, DiagramElementDescription diagramElementDescription) {
if (nodeElement.getProps() instanceof NodeElementProps props) {
return Objects.equals(this.idProvider.apply(diagramElementDescription), props.getDescriptionId());
return Objects.equals(this.idProvider.getIdElementDescription(diagramElementDescription), props.getDescriptionId());
}
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import org.eclipse.sirius.components.view.View;
import org.eclipse.sirius.components.view.ViewFactory;
import org.eclipse.sirius.components.view.emf.ViewConverter;
import org.eclipse.sirius.components.view.emf.diagram.IIdDiagramProvider;
import org.eclipse.sirius.components.view.emf.diagram.ViewDiagramDescriptionConverter;
import org.eclipse.sirius.components.view.emf.diagram.providers.api.IViewToolImageProvider;
import org.junit.jupiter.api.BeforeEach;
Expand Down Expand Up @@ -140,7 +141,7 @@ private Diagram render(DiagramDescription diagramDescription, Object target) {
res.getContents().add(view);
new ResourceSetImpl().getResources().add(res);

ViewDiagramDescriptionConverter diagramDescriptionConverter = new ViewDiagramDescriptionConverter(new IObjectService.NoOp(), new IEditService.NoOp(), List.of(),
ViewDiagramDescriptionConverter diagramDescriptionConverter = new ViewDiagramDescriptionConverter(new IIdDiagramProvider.NoOp(), new IObjectService.NoOp(), new IEditService.NoOp(), List.of(),
new IViewToolImageProvider.NoOp());
var viewConverter = new ViewConverter(List.of(), List.of(diagramDescriptionConverter), new StaticApplicationContext());
List<IRepresentationDescription> conversionResult = viewConverter.convert(List.of(view), List.of(EcorePackage.eINSTANCE));
Expand All @@ -155,6 +156,7 @@ public Optional<IRepresentationDescription> findById(IEditingContext editingCont
return Optional.of(convertedDiagramDescription);
}
};

IObjectService objectService = new IObjectService.NoOp();
ILayoutService layoutService = new ILayoutService.NoOp();
MeterRegistry meterRegistry = new SimpleMeterRegistry();
Expand Down

0 comments on commit 7453832

Please sign in to comment.