-
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 Project related REST APIs in Sirius Web
Bug: #3979 Signed-off-by: Axel RICHARD <[email protected]>
- Loading branch information
1 parent
b4ff0a7
commit 61ae89c
Showing
9 changed files
with
494 additions
and
1 deletion.
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
34 changes: 34 additions & 0 deletions
34
...ius-web-application/src/main/java/org/eclipse/sirius/web/application/dto/IRestRecord.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) 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.dto; | ||
|
||
import java.util.List; | ||
import java.util.UUID; | ||
|
||
/** | ||
* Interface for the REST Record DTO. | ||
* | ||
* @author arichard | ||
*/ | ||
public interface IRestRecord { | ||
|
||
UUID id(); | ||
|
||
String resourceIdentifier(); | ||
|
||
List<String> alias(); | ||
|
||
String humanIdentifier(); | ||
|
||
String decription(); | ||
} |
120 changes: 120 additions & 0 deletions
120
...in/java/org/eclipse/sirius/web/application/project/controllers/ProjectRestController.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,120 @@ | ||
/******************************************************************************* | ||
* 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.project.controllers; | ||
|
||
import java.util.List; | ||
import java.util.Objects; | ||
import java.util.Optional; | ||
import java.util.UUID; | ||
|
||
import org.eclipse.sirius.components.core.api.ErrorPayload; | ||
import org.eclipse.sirius.web.application.project.data.versioning.dto.RestBranch; | ||
import org.eclipse.sirius.web.application.project.dto.CreateProjectInput; | ||
import org.eclipse.sirius.web.application.project.dto.CreateProjectSuccessPayload; | ||
import org.eclipse.sirius.web.application.project.dto.DeleteProjectInput; | ||
import org.eclipse.sirius.web.application.project.dto.RenameProjectInput; | ||
import org.eclipse.sirius.web.application.project.dto.RenameProjectSuccessPayload; | ||
import org.eclipse.sirius.web.application.project.dto.RestProject; | ||
import org.eclipse.sirius.web.application.project.services.api.IProjectApplicationService; | ||
import org.springframework.data.domain.PageRequest; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.DeleteMapping; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.PathVariable; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.PutMapping; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RequestParam; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
/** | ||
* REST Controller for the Project Endpoint. | ||
* | ||
* @author arichard | ||
*/ | ||
@RestController | ||
@RequestMapping("/api/rest/projects") | ||
public class ProjectRestController { | ||
|
||
private final IProjectApplicationService projectApplicationService; | ||
|
||
public ProjectRestController(IProjectApplicationService projectApplicationService) { | ||
this.projectApplicationService = Objects.requireNonNull(projectApplicationService); | ||
} | ||
|
||
@GetMapping | ||
public ResponseEntity<List<RestProject>> getProjects() { | ||
var restProjects = this.projectApplicationService.findAll(PageRequest.of(0, 20)) | ||
.map(project -> new RestProject(project.id(), null, List.of(), null, null, project.name(), List.of())) | ||
.toList(); | ||
|
||
return new ResponseEntity<>(restProjects, HttpStatus.OK); | ||
} | ||
|
||
@GetMapping(path = "/{projectId}") | ||
public ResponseEntity<RestProject> getProjectById(@PathVariable UUID projectId) { | ||
var restProject = this.projectApplicationService.findById(projectId) | ||
.map(project -> new RestProject(project.id(), null, List.of(), null, null, project.name(), List.of())); | ||
|
||
if (restProject.isPresent()) { | ||
return new ResponseEntity<>(restProject.get(), HttpStatus.OK); | ||
} | ||
|
||
return new ResponseEntity<>(null, HttpStatus.NOT_FOUND); | ||
} | ||
|
||
@PostMapping | ||
public ResponseEntity<RestProject> createProject(@RequestParam String name, @RequestParam Optional<String> description) { | ||
var createProjectInput = new CreateProjectInput(UUID.randomUUID(), name, List.of()); | ||
var newProjectPayload = this.projectApplicationService.createProject(createProjectInput); | ||
|
||
if (newProjectPayload instanceof CreateProjectSuccessPayload createProjectSuccessPayload) { | ||
var projectDTO = createProjectSuccessPayload.project(); | ||
var restProject = new RestProject(projectDTO.id(), null, List.of(), null, null, projectDTO.name(), List.of()); | ||
return new ResponseEntity<>(restProject, HttpStatus.CREATED); | ||
} | ||
// The specification does not handle other HttpStatus than HttpStatus.CREATED for this endpoint | ||
return null; | ||
} | ||
|
||
@PutMapping(path = "/{projectId}") | ||
public ResponseEntity<RestProject> updateProject(@PathVariable UUID projectId, @RequestParam Optional<String> name, @RequestParam Optional<String> description, @RequestParam Optional<RestBranch> branch) { | ||
if (name.isPresent()) { | ||
var renameProjectInput = new RenameProjectInput(UUID.randomUUID(), projectId, name.get()); | ||
var renamedProjectPayload = this.projectApplicationService.renameProject(renameProjectInput); | ||
if (renamedProjectPayload instanceof RenameProjectSuccessPayload) { | ||
var restProject = new RestProject(projectId, null, List.of(), null, null, name.get(), List.of()); | ||
return new ResponseEntity<>(restProject, HttpStatus.OK); | ||
} | ||
} | ||
|
||
return new ResponseEntity<>(null, HttpStatus.NOT_FOUND); | ||
} | ||
|
||
@DeleteMapping(path = "/{projectId}") | ||
public ResponseEntity<RestProject> deleteProject(@PathVariable UUID projectId) { | ||
var restProject = this.projectApplicationService.findById(projectId) | ||
.map(project -> new RestProject(project.id(), null, List.of(), null, null, project.name(), List.of())) | ||
.orElse(null); | ||
|
||
var deleteProjectInput = new DeleteProjectInput(UUID.randomUUID(), projectId); | ||
var deleteProjectPayload = this.projectApplicationService.deleteProject(deleteProjectInput); | ||
|
||
if (deleteProjectPayload instanceof ErrorPayload) { | ||
return new ResponseEntity<>(null, HttpStatus.NO_CONTENT); | ||
} | ||
|
||
return new ResponseEntity<>(restProject, HttpStatus.OK); | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
.../org/eclipse/sirius/web/application/project/data/versioning/dto/IRestCommitReference.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,29 @@ | ||
/******************************************************************************* | ||
* 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.project.data.versioning.dto; | ||
|
||
import java.text.DateFormat; | ||
|
||
import org.eclipse.sirius.web.application.dto.IRestRecord; | ||
|
||
/** | ||
* Interface for the REST CommitReference DTO. | ||
* | ||
* @author arichard | ||
*/ | ||
public interface IRestCommitReference extends IRestRecord { | ||
|
||
DateFormat created(); | ||
|
||
String name(); | ||
} |
22 changes: 22 additions & 0 deletions
22
.../main/java/org/eclipse/sirius/web/application/project/data/versioning/dto/RestBranch.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.project.data.versioning.dto; | ||
|
||
/** | ||
* REST Branch DTO. | ||
* | ||
* @author arichard | ||
*/ | ||
public record RestBranch() { | ||
|
||
} |
35 changes: 35 additions & 0 deletions
35
...application/src/main/java/org/eclipse/sirius/web/application/project/dto/RestProject.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,35 @@ | ||
/******************************************************************************* | ||
* 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.project.dto; | ||
|
||
import java.util.List; | ||
import java.util.UUID; | ||
|
||
import org.eclipse.sirius.web.application.dto.IRestRecord; | ||
import org.eclipse.sirius.web.application.query.dto.RestQuery; | ||
|
||
/** | ||
* REST Project DTO. | ||
* | ||
* @author arichard | ||
*/ | ||
public record RestProject( | ||
UUID id, | ||
String resourceIdentifier, | ||
List<String> alias, | ||
String humanIdentifier, | ||
String decription, | ||
String name, | ||
List<RestQuery> queries) implements IRestRecord { | ||
|
||
} |
31 changes: 31 additions & 0 deletions
31
...web-application/src/main/java/org/eclipse/sirius/web/application/query/dto/RestQuery.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.query.dto; | ||
|
||
import java.util.List; | ||
import java.util.UUID; | ||
|
||
import org.eclipse.sirius.web.application.dto.IRestRecord; | ||
|
||
/** | ||
* REST Query DTO. | ||
* | ||
* @author arichard | ||
*/ | ||
public record RestQuery( | ||
UUID id, | ||
String resourceIdentifier, | ||
List<String> alias, | ||
String humanIdentifier, | ||
String decription) implements IRestRecord { | ||
} |
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.