-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[3979] Add Element related REST APIs in Sirius Web
Bug: #3979 Signed-off-by: Axel RICHARD <[email protected]>
- Loading branch information
1 parent
0df97fb
commit 35e604f
Showing
29 changed files
with
1,509 additions
and
31 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
= [ADR-160] Support REST APIs | ||
|
||
== Context | ||
|
||
REST APIs can be useful to execute CRUD requests in Sirius Web. | ||
|
||
=== Current behavior | ||
|
||
There are currently no REST APIs allowing to query/modify projects/models in Sirius Web. | ||
|
||
== Decision | ||
|
||
The decision is to support all REST APIs described in the Systems Modeling Application Programming Interface (API) and Services section "8.1 REST/HTTP PSM" coming from https://www.omg.org/spec/SystemsModelingAPI/. | ||
|
||
We will consider at least both the ProjectService and ElementNavigationService endpoints. | ||
|
||
Additional resources: | ||
- https://www.omg.org/spec/SystemsModelingAPI/20230201/OpenAPI.json | ||
- https://www.omg.org/spec/SystemsModelingAPI/20230201/Schemas.json | ||
|
||
Some concepts in this specification are coming from SysMLv2 (i.e. Element and Relationship). | ||
For example, the `GET /projects/{projectId}/commits/{commitId}/elements/` will return the list of all objects contained in the given project. | ||
|
||
Depending on the metamodel, objects could be serialized differently in JSON. | ||
So, Sirius Web will let specifiers serialized their objects as they want. | ||
|
||
Some default implementation of the Java services associated to the object-related REST APIs will be provided through a new interface `IDefaultObjectRestService`. | ||
Specifiers will also be able to provide their own implementations by implementing `IObjectRestServiceDelegate` as a spring `Service`. | ||
|
||
== Status | ||
|
||
Work in progress |
116 changes: 116 additions & 0 deletions
116
...main/java/org/eclipse/sirius/web/application/object/controllers/ObjectRestController.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,116 @@ | ||
/******************************************************************************* | ||
* 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.object.controllers; | ||
|
||
import java.time.Duration; | ||
import java.util.List; | ||
import java.util.Objects; | ||
import java.util.Optional; | ||
import java.util.UUID; | ||
|
||
import org.eclipse.sirius.components.collaborative.api.IEditingContextEventProcessorRegistry; | ||
import org.eclipse.sirius.web.application.object.dto.Direction; | ||
import org.eclipse.sirius.web.application.object.dto.GetElementByIdRestInput; | ||
import org.eclipse.sirius.web.application.object.dto.GetElementByIdRestSuccessPayload; | ||
import org.eclipse.sirius.web.application.object.dto.GetElementsRestInput; | ||
import org.eclipse.sirius.web.application.object.dto.GetElementsRestSuccessPayload; | ||
import org.eclipse.sirius.web.application.object.dto.GetRelationshipsByRelatedElementRestInput; | ||
import org.eclipse.sirius.web.application.object.dto.GetRelationshipsByRelatedElementRestSuccessPayload; | ||
import org.eclipse.sirius.web.application.object.dto.GetRootElementsRestInput; | ||
import org.eclipse.sirius.web.application.object.dto.GetRootElementsRestSuccessPayload; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.PathVariable; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
/** | ||
* REST Controller for the Object Endpoint. | ||
* | ||
* @author arichard | ||
*/ | ||
@RestController | ||
@RequestMapping("/api/rest/projects/{projectId}/commits/{commitId}") | ||
public class ObjectRestController { | ||
|
||
private static final int TIMEOUT = 20; | ||
|
||
private final IEditingContextEventProcessorRegistry editingContextEventProcessorRegistry; | ||
|
||
public ObjectRestController(IEditingContextEventProcessorRegistry editingContextEventProcessorRegistry) { | ||
this.editingContextEventProcessorRegistry = Objects.requireNonNull(editingContextEventProcessorRegistry); | ||
} | ||
|
||
@GetMapping(path = "/elements") | ||
public ResponseEntity<List<Object>> getElements(@PathVariable UUID projectId, @PathVariable UUID commitId) { | ||
ResponseEntity<List<Object>> responseEntity = new ResponseEntity<>(null, HttpStatus.NOT_FOUND); | ||
var optionalEditingContextEventProcessor = this.editingContextEventProcessorRegistry.getOrCreateEditingContextEventProcessor(projectId.toString()); | ||
if (optionalEditingContextEventProcessor.isPresent()) { | ||
var editingContextEventProcessor = optionalEditingContextEventProcessor.get(); | ||
var payload = editingContextEventProcessor.handle(new GetElementsRestInput(UUID.randomUUID())).block(Duration.ofSeconds(TIMEOUT)); | ||
if (payload instanceof GetElementsRestSuccessPayload successPayload) { | ||
responseEntity = new ResponseEntity<>(successPayload.elements(), HttpStatus.OK); | ||
} | ||
} | ||
return responseEntity; | ||
} | ||
|
||
@GetMapping(path = "/elements/{elementId}") | ||
public ResponseEntity<Object> getElementById(@PathVariable UUID projectId, @PathVariable UUID commitId, @PathVariable UUID elementId) { | ||
ResponseEntity<Object> responseEntity = new ResponseEntity<>(null, HttpStatus.NOT_FOUND); | ||
var optionalEditingContextEventProcessor = this.editingContextEventProcessorRegistry.getOrCreateEditingContextEventProcessor(projectId.toString()); | ||
if (optionalEditingContextEventProcessor.isPresent()) { | ||
var editingContextEventProcessor = optionalEditingContextEventProcessor.get(); | ||
var payload = editingContextEventProcessor.handle(new GetElementByIdRestInput(UUID.randomUUID(), elementId.toString())).block(Duration.ofSeconds(TIMEOUT)); | ||
if (payload instanceof GetElementByIdRestSuccessPayload successPayload) { | ||
responseEntity = new ResponseEntity<>(successPayload.element(), HttpStatus.OK); | ||
} | ||
} | ||
return responseEntity; | ||
} | ||
|
||
@GetMapping(path = "/elements/{relatedElementId}/relationships") | ||
public ResponseEntity<List<Object>> getRelationshipsByRelatedElement(@PathVariable UUID projectId, @PathVariable UUID commitId, @PathVariable UUID relatedElementId, Optional<Direction> direction) { | ||
ResponseEntity<List<Object>> responseEntity = new ResponseEntity<>(null, HttpStatus.NOT_FOUND); | ||
var optionalEditingContextEventProcessor = this.editingContextEventProcessorRegistry.getOrCreateEditingContextEventProcessor(projectId.toString()); | ||
if (optionalEditingContextEventProcessor.isPresent()) { | ||
var editingContextEventProcessor = optionalEditingContextEventProcessor.get(); | ||
Direction directionParam; | ||
if (direction.isPresent()) { | ||
directionParam = direction.get(); | ||
} else { | ||
directionParam = Direction.BOTH; | ||
} | ||
var payload = editingContextEventProcessor.handle(new GetRelationshipsByRelatedElementRestInput(UUID.randomUUID(), relatedElementId.toString(), directionParam)).block(Duration.ofSeconds(TIMEOUT)); | ||
if (payload instanceof GetRelationshipsByRelatedElementRestSuccessPayload successPayload) { | ||
responseEntity = new ResponseEntity<>(successPayload.relationships(), HttpStatus.OK); | ||
} | ||
} | ||
return responseEntity; | ||
} | ||
|
||
@GetMapping(path = "/roots") | ||
public ResponseEntity<List<Object>> getRootElements(@PathVariable UUID projectId, @PathVariable UUID commitId) { | ||
ResponseEntity<List<Object>> responseEntity = new ResponseEntity<>(null, HttpStatus.NOT_FOUND); | ||
var optionalEditingContextEventProcessor = this.editingContextEventProcessorRegistry.getOrCreateEditingContextEventProcessor(projectId.toString()); | ||
if (optionalEditingContextEventProcessor.isPresent()) { | ||
var editingContextEventProcessor = optionalEditingContextEventProcessor.get(); | ||
var payload = editingContextEventProcessor.handle(new GetRootElementsRestInput(UUID.randomUUID())).block(Duration.ofSeconds(TIMEOUT)); | ||
if (payload instanceof GetRootElementsRestSuccessPayload successPayload) { | ||
responseEntity = new ResponseEntity<>(successPayload.rootElements(), HttpStatus.OK); | ||
} | ||
} | ||
return responseEntity; | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
...eb-application/src/main/java/org/eclipse/sirius/web/application/object/dto/Direction.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,22 @@ | ||
/******************************************************************************* | ||
* 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.object.dto; | ||
|
||
/** | ||
* Used to indicate the direction of the relationships to retrieve when calling "getRelationshipsByRelatedElement" REST API. | ||
* | ||
* @author arichard | ||
*/ | ||
public enum Direction { | ||
IN, OUT, BOTH | ||
} |
25 changes: 25 additions & 0 deletions
25
.../src/main/java/org/eclipse/sirius/web/application/object/dto/GetElementByIdRestInput.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.object.dto; | ||
|
||
import java.util.UUID; | ||
|
||
import org.eclipse.sirius.components.core.api.IInput; | ||
|
||
/** | ||
* The input object of the GetElementByIdRestEventHandler. | ||
* | ||
* @author arichard | ||
*/ | ||
public record GetElementByIdRestInput(UUID id, String elementId) implements IInput { | ||
} |
30 changes: 30 additions & 0 deletions
30
.../java/org/eclipse/sirius/web/application/object/dto/GetElementByIdRestSuccessPayload.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,30 @@ | ||
/******************************************************************************* | ||
* 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.object.dto; | ||
|
||
import java.util.Objects; | ||
import java.util.UUID; | ||
|
||
import org.eclipse.sirius.components.core.api.IPayload; | ||
|
||
/** | ||
* The payload for the "getElementById" REST API on success. | ||
* | ||
* @author arichard | ||
*/ | ||
public record GetElementByIdRestSuccessPayload(UUID id, Object element) implements IPayload { | ||
public GetElementByIdRestSuccessPayload { | ||
Objects.requireNonNull(id); | ||
Objects.requireNonNull(element); | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
...ion/src/main/java/org/eclipse/sirius/web/application/object/dto/GetElementsRestInput.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.object.dto; | ||
|
||
import java.util.UUID; | ||
|
||
import org.eclipse.sirius.components.core.api.IInput; | ||
|
||
/** | ||
* The input object of the GetElementsRestEventHandler. | ||
* | ||
* @author arichard | ||
*/ | ||
public record GetElementsRestInput(UUID id) implements IInput { | ||
} |
31 changes: 31 additions & 0 deletions
31
...ain/java/org/eclipse/sirius/web/application/object/dto/GetElementsRestSuccessPayload.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,31 @@ | ||
/******************************************************************************* | ||
* 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.object.dto; | ||
|
||
import java.util.List; | ||
import java.util.Objects; | ||
import java.util.UUID; | ||
|
||
import org.eclipse.sirius.components.core.api.IPayload; | ||
|
||
/** | ||
* The payload for the "getElements" REST API on success. | ||
* | ||
* @author arichard | ||
*/ | ||
public record GetElementsRestSuccessPayload(UUID id, List<Object> elements) implements IPayload { | ||
public GetElementsRestSuccessPayload { | ||
Objects.requireNonNull(id); | ||
Objects.requireNonNull(elements); | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
.../eclipse/sirius/web/application/object/dto/GetRelationshipsByRelatedElementRestInput.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.object.dto; | ||
|
||
import java.util.UUID; | ||
|
||
import org.eclipse.sirius.components.core.api.IInput; | ||
|
||
/** | ||
* The input object of the GetRelationshipsByRelatedElementRestEventHandler. | ||
* | ||
* @author arichard | ||
*/ | ||
public record GetRelationshipsByRelatedElementRestInput(UUID id, String elementId, Direction direction) implements IInput { | ||
} |
31 changes: 31 additions & 0 deletions
31
...sirius/web/application/object/dto/GetRelationshipsByRelatedElementRestSuccessPayload.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,31 @@ | ||
/******************************************************************************* | ||
* 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.object.dto; | ||
|
||
import java.util.List; | ||
import java.util.Objects; | ||
import java.util.UUID; | ||
|
||
import org.eclipse.sirius.components.core.api.IPayload; | ||
|
||
/** | ||
* The payload for the "getRelationshipsByRelatedElement" REST API on success. | ||
* | ||
* @author arichard | ||
*/ | ||
public record GetRelationshipsByRelatedElementRestSuccessPayload(UUID id, List<Object> relationships) implements IPayload { | ||
public GetRelationshipsByRelatedElementRestSuccessPayload { | ||
Objects.requireNonNull(id); | ||
Objects.requireNonNull(relationships); | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
...src/main/java/org/eclipse/sirius/web/application/object/dto/GetRootElementsRestInput.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.object.dto; | ||
|
||
import java.util.UUID; | ||
|
||
import org.eclipse.sirius.components.core.api.IInput; | ||
|
||
/** | ||
* The input object of the GetRootElementsRestEventHandler. | ||
* | ||
* @author arichard | ||
*/ | ||
public record GetRootElementsRestInput(UUID id) implements IInput { | ||
} |
Oops, something went wrong.