-
Notifications
You must be signed in to change notification settings - Fork 5
Add REST API with JAX-RS/OpenAPI annotations and endpoint tests #46
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 |
|---|---|---|
| @@ -1,6 +1,10 @@ | ||
| package io.hyperfoil.tools.h5m.api; | ||
|
|
||
| import jakarta.validation.constraints.NotEmpty; | ||
| import org.eclipse.microprofile.openapi.annotations.media.Schema; | ||
|
|
||
| public record Folder(Long id, @NotEmpty String name) { | ||
| @Schema(description = "A folder containing uploaded data") | ||
| public record Folder( | ||
| @Schema(description = "Unique folder ID") Long id, | ||
| @Schema(description = "Folder name") @NotEmpty String name) { | ||
| } |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
| @@ -1,8 +1,12 @@ | ||
| package io.hyperfoil.tools.h5m.api; | ||
|
|
||
| import com.fasterxml.jackson.databind.JsonNode; | ||
| import org.eclipse.microprofile.openapi.annotations.media.Schema; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| public record Value(Long id, JsonNode data, Node node, Folder folder) { | ||
| @Schema(description = "A computed value produced by a node") | ||
| public record Value( | ||
| @Schema(description = "Unique value ID") Long id, | ||
| @Schema(description = "The JSON data payload") JsonNode data, | ||
| @Schema(description = "The node that produced this value") Node node, | ||
| @Schema(description = "The folder this value belongs to") Folder folder) { | ||
| } |
This file contains hidden or 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 hidden or 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 hidden or 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
75 changes: 75 additions & 0 deletions
75
src/main/java/io/hyperfoil/tools/h5m/rest/FolderResource.java
This file contains hidden or 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,75 @@ | ||
| package io.hyperfoil.tools.h5m.rest; | ||
|
|
||
| import com.fasterxml.jackson.databind.JsonNode; | ||
| import io.hyperfoil.tools.h5m.api.Folder; | ||
| import io.hyperfoil.tools.h5m.api.svc.FolderServiceInterface; | ||
| import io.hyperfoil.tools.yaup.json.Json; | ||
| import jakarta.inject.Inject; | ||
| import jakarta.ws.rs.*; | ||
| import jakarta.ws.rs.core.MediaType; | ||
| import org.eclipse.microprofile.openapi.annotations.Operation; | ||
| import org.eclipse.microprofile.openapi.annotations.parameters.Parameter; | ||
| import org.eclipse.microprofile.openapi.annotations.tags.Tag; | ||
|
|
||
| import java.util.Map; | ||
|
|
||
| @Path("/api/folder") | ||
| @Produces(MediaType.APPLICATION_JSON) | ||
| @Consumes(MediaType.APPLICATION_JSON) | ||
| @Tag(name = "Folder", description = "Manage folders for uploaded data") | ||
| public class FolderResource { | ||
|
|
||
| @Inject | ||
| FolderServiceInterface folderService; | ||
|
|
||
| @GET | ||
| @Path("{name}") | ||
| @Operation(description = "Retrieve a folder by its name") | ||
| public Folder byName(@PathParam("name") String name) { | ||
| return folderService.byName(name); | ||
| } | ||
|
|
||
| @GET | ||
| @Operation(description = "Get the upload count for all folders") | ||
| public Map<String, Integer> getFolderUploadCount() { | ||
| return folderService.getFolderUploadCount(); | ||
| } | ||
|
|
||
| @POST | ||
| @Path("{name}") | ||
| @Operation(description = "Create a new folder") | ||
| public long create(@PathParam("name") String name) { | ||
| return folderService.create(name); | ||
| } | ||
|
|
||
| @DELETE | ||
| @Path("{name}") | ||
| @Operation(description = "Delete a folder by its name") | ||
| public long delete(@PathParam("name") String name) { | ||
| return folderService.delete(name); | ||
| } | ||
|
stalep marked this conversation as resolved.
|
||
|
|
||
| @POST | ||
| @Path("{name}/upload") | ||
| @Operation(description = "Upload JSON data to a folder") | ||
| public void upload( | ||
| @PathParam("name") String name, | ||
| @QueryParam("path") @Parameter(description = "Path within the folder") String path, | ||
| JsonNode data) { | ||
| folderService.upload(name, path, data); | ||
| } | ||
|
|
||
| @POST | ||
| @Path("{name}/recalculate") | ||
| @Operation(description = "Recalculate all values in a folder") | ||
| public void recalculate(@PathParam("name") String name) { | ||
| folderService.recalculate(name); | ||
| } | ||
|
|
||
| @GET | ||
| @Path("{name}/structure") | ||
| @Operation(description = "Get the structural representation of a folder") | ||
| public Json structure(@PathParam("name") String name) { | ||
| return folderService.structure(name); | ||
| } | ||
| } | ||
33 changes: 33 additions & 0 deletions
33
src/main/java/io/hyperfoil/tools/h5m/rest/NodeGroupResource.java
This file contains hidden or 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,33 @@ | ||
| package io.hyperfoil.tools.h5m.rest; | ||
|
|
||
| import io.hyperfoil.tools.h5m.api.NodeGroup; | ||
| import io.hyperfoil.tools.h5m.api.svc.NodeGroupServiceInterface; | ||
| import jakarta.inject.Inject; | ||
| import jakarta.ws.rs.*; | ||
| import jakarta.ws.rs.core.MediaType; | ||
| import org.eclipse.microprofile.openapi.annotations.Operation; | ||
| import org.eclipse.microprofile.openapi.annotations.tags.Tag; | ||
|
|
||
| @Path("/api/group") | ||
| @Produces(MediaType.APPLICATION_JSON) | ||
| @Consumes(MediaType.APPLICATION_JSON) | ||
| @Tag(name = "NodeGroup", description = "Manage node groups (transformation pipelines)") | ||
| public class NodeGroupResource { | ||
|
|
||
| @Inject | ||
| NodeGroupServiceInterface nodeGroupService; | ||
|
|
||
| @GET | ||
| @Path("{name}") | ||
| @Operation(description = "Retrieve a node group by its name") | ||
| public NodeGroup byName(@PathParam("name") String groupName) { | ||
| return nodeGroupService.byName(groupName); | ||
| } | ||
|
|
||
| @DELETE | ||
| @Path("{id}") | ||
| @Operation(description = "Delete a node group by its ID") | ||
| public void delete(@PathParam("id") Long groupId) { | ||
| nodeGroupService.delete(groupId); | ||
| } | ||
|
stalep marked this conversation as resolved.
|
||
| } | ||
70 changes: 70 additions & 0 deletions
70
src/main/java/io/hyperfoil/tools/h5m/rest/NodeResource.java
This file contains hidden or 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,70 @@ | ||
| package io.hyperfoil.tools.h5m.rest; | ||
|
|
||
| import com.fasterxml.jackson.core.JsonProcessingException; | ||
| import io.hyperfoil.tools.h5m.api.Node; | ||
| import io.hyperfoil.tools.h5m.api.NodeType; | ||
| import io.hyperfoil.tools.h5m.api.svc.NodeServiceInterface; | ||
| import jakarta.inject.Inject; | ||
| import jakarta.validation.constraints.NotEmpty; | ||
| import jakarta.validation.constraints.NotNull; | ||
| import jakarta.ws.rs.*; | ||
| import jakarta.ws.rs.core.MediaType; | ||
| import org.eclipse.microprofile.openapi.annotations.Operation; | ||
| import org.eclipse.microprofile.openapi.annotations.parameters.Parameter; | ||
| import org.eclipse.microprofile.openapi.annotations.tags.Tag; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| @Path("/api/node") | ||
| @Produces(MediaType.APPLICATION_JSON) | ||
| @Consumes(MediaType.APPLICATION_JSON) | ||
| @Tag(name = "Node", description = "Manage transformation nodes in the DAG pipeline") | ||
| public class NodeResource { | ||
|
|
||
| @Inject | ||
| NodeServiceInterface nodeService; | ||
|
|
||
| @POST | ||
| @Operation(description = "Create a new node with an operation") | ||
| public Long create( | ||
| @QueryParam("name") @NotEmpty String name, | ||
| @QueryParam("groupId") @NotNull Long groupId, | ||
| @QueryParam("type") @NotNull NodeType type, | ||
| @QueryParam("operation") String operation) { | ||
| return nodeService.create(name, groupId, type, operation); | ||
| } | ||
|
|
||
| @POST | ||
| @Path("configured") | ||
| @Operation(description = "Create a new node with sources and configuration") | ||
| public Long createConfigured( | ||
| @QueryParam("name") @NotEmpty String name, | ||
| @QueryParam("groupId") @NotNull Long groupId, | ||
| @QueryParam("type") @NotNull NodeType type, | ||
| @QueryParam("sources") @NotNull @NotEmpty List<Long> sources, | ||
| Object configuration) { | ||
| try { | ||
| return nodeService.createConfigured(name, groupId, type, sources, configuration); | ||
| } catch (JsonProcessingException e) { | ||
| throw new BadRequestException("Invalid node configuration payload", e); | ||
| } catch (IllegalArgumentException e) { | ||
| throw new BadRequestException("Invalid node configuration request: " + e.getMessage(), e); | ||
| } | ||
| } | ||
|
|
||
| @DELETE | ||
| @Path("{id}") | ||
| @Operation(description = "Delete a node by its ID") | ||
| public void delete(@PathParam("id") Long nodeId) { | ||
| nodeService.delete(nodeId); | ||
| } | ||
|
|
||
| @GET | ||
| @Path("find") | ||
| @Operation(description = "Find nodes by FQDN within a specific group") | ||
| public List<Node> findNodeByFqdn( | ||
| @QueryParam("name") @Parameter(description = "FQDN of the node") String name, | ||
| @QueryParam("groupId") @Parameter(description = "Group ID to search within") Long groupId) { | ||
| return nodeService.findNodeByFqdn(name, groupId); | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.