diff --git a/rest/src/main/java/io/metaloom/loom/client/http/LoomBinaryResponse.java b/common/src/main/java/io/metaloom/loom/client/common/LoomBinaryResponse.java similarity index 97% rename from rest/src/main/java/io/metaloom/loom/client/http/LoomBinaryResponse.java rename to common/src/main/java/io/metaloom/loom/client/common/LoomBinaryResponse.java index a8f323f..931ae05 100644 --- a/rest/src/main/java/io/metaloom/loom/client/http/LoomBinaryResponse.java +++ b/common/src/main/java/io/metaloom/loom/client/common/LoomBinaryResponse.java @@ -1,4 +1,4 @@ -package io.metaloom.loom.client.http; +package io.metaloom.loom.client.common; import java.io.InputStream; import java.util.Arrays; diff --git a/common/src/main/java/io/metaloom/loom/client/common/LoomClient.java b/common/src/main/java/io/metaloom/loom/client/common/LoomClient.java new file mode 100644 index 0000000..91bb3d7 --- /dev/null +++ b/common/src/main/java/io/metaloom/loom/client/common/LoomClient.java @@ -0,0 +1,18 @@ +package io.metaloom.loom.client.common; + +import io.metaloom.loom.client.common.method.ClientMethods; + +public interface LoomClient extends ClientMethods, CommonSettings, AutoCloseable { + + /** + * Set the token to be used for authentication. + * + * @param token + */ + void setToken(String token); + + /** + * Close the client and release all resources. + */ + void close(); +} diff --git a/common/src/main/java/io/metaloom/loom/client/common/LoomClientException.java b/common/src/main/java/io/metaloom/loom/client/common/LoomClientException.java new file mode 100644 index 0000000..668bfd9 --- /dev/null +++ b/common/src/main/java/io/metaloom/loom/client/common/LoomClientException.java @@ -0,0 +1,26 @@ +package io.metaloom.loom.client.common; + +public class LoomClientException extends Exception { + + private static final long serialVersionUID = 6434236577973357902L; + private int code; + + public LoomClientException(int code, String msg) { + super(msg); + this.code = code; + } + + public LoomClientException(int code, String msg, Exception e) { + super(msg, e); + this.code = code; + } + + public int getStatusCode() { + return code; + } + + public String getStatusMsg() { + return getMessage(); + } + +} diff --git a/common/src/main/java/io/metaloom/loom/client/common/LoomClientRequest.java b/common/src/main/java/io/metaloom/loom/client/common/LoomClientRequest.java new file mode 100644 index 0000000..e095896 --- /dev/null +++ b/common/src/main/java/io/metaloom/loom/client/common/LoomClientRequest.java @@ -0,0 +1,12 @@ +package io.metaloom.loom.client.common; + +import io.metaloom.loom.rest.model.RestResponseModel; +import io.reactivex.rxjava3.core.Single; + +public interface LoomClientRequest> extends QueryParameters { + + Single async(); + + T sync() throws LoomClientException; + +} diff --git a/rest/src/main/java/io/metaloom/loom/client/http/parameter/QueryParameters.java b/common/src/main/java/io/metaloom/loom/client/common/QueryParameters.java similarity index 94% rename from rest/src/main/java/io/metaloom/loom/client/http/parameter/QueryParameters.java rename to common/src/main/java/io/metaloom/loom/client/common/QueryParameters.java index 1439de2..da2ae42 100644 --- a/rest/src/main/java/io/metaloom/loom/client/http/parameter/QueryParameters.java +++ b/common/src/main/java/io/metaloom/loom/client/common/QueryParameters.java @@ -1,4 +1,4 @@ -package io.metaloom.loom.client.http.parameter; +package io.metaloom.loom.client.common; import java.time.Duration; import java.util.UUID; @@ -9,7 +9,6 @@ import io.metaloom.filter.key.impl.StringFilterKey; import io.metaloom.loom.api.sort.SortDirection; import io.metaloom.loom.api.sort.SortKey; -import io.metaloom.loom.client.http.LoomClientRequest; import io.metaloom.loom.rest.model.RestResponseModel; import io.metaloom.loom.rest.parameter.QueryParameterKey; diff --git a/rest/src/main/java/io/metaloom/loom/client/http/method/AnnotationMethods.java b/common/src/main/java/io/metaloom/loom/client/common/method/AnnotationMethods.java similarity index 88% rename from rest/src/main/java/io/metaloom/loom/client/http/method/AnnotationMethods.java rename to common/src/main/java/io/metaloom/loom/client/common/method/AnnotationMethods.java index b63d6a8..fa46988 100644 --- a/rest/src/main/java/io/metaloom/loom/client/http/method/AnnotationMethods.java +++ b/common/src/main/java/io/metaloom/loom/client/common/method/AnnotationMethods.java @@ -1,8 +1,8 @@ -package io.metaloom.loom.client.http.method; +package io.metaloom.loom.client.common.method; import java.util.UUID; -import io.metaloom.loom.client.http.LoomClientRequest; +import io.metaloom.loom.client.common.LoomClientRequest; import io.metaloom.loom.rest.model.NoResponse; import io.metaloom.loom.rest.model.annotation.AnnotationCreateRequest; import io.metaloom.loom.rest.model.annotation.AnnotationListResponse; diff --git a/rest/src/main/java/io/metaloom/loom/client/http/method/AssetLocationMethods.java b/common/src/main/java/io/metaloom/loom/client/common/method/AssetLocationMethods.java similarity index 88% rename from rest/src/main/java/io/metaloom/loom/client/http/method/AssetLocationMethods.java rename to common/src/main/java/io/metaloom/loom/client/common/method/AssetLocationMethods.java index 65d55cb..dab3e4b 100644 --- a/rest/src/main/java/io/metaloom/loom/client/http/method/AssetLocationMethods.java +++ b/common/src/main/java/io/metaloom/loom/client/common/method/AssetLocationMethods.java @@ -1,8 +1,8 @@ -package io.metaloom.loom.client.http.method; +package io.metaloom.loom.client.common.method; import java.util.UUID; -import io.metaloom.loom.client.http.LoomClientRequest; +import io.metaloom.loom.client.common.LoomClientRequest; import io.metaloom.loom.rest.model.NoResponse; import io.metaloom.loom.rest.model.asset.location.AssetLocationCreateRequest; import io.metaloom.loom.rest.model.asset.location.AssetLocationListResponse; diff --git a/rest/src/main/java/io/metaloom/loom/client/http/method/AssetMethods.java b/common/src/main/java/io/metaloom/loom/client/common/method/AssetMethods.java similarity index 93% rename from rest/src/main/java/io/metaloom/loom/client/http/method/AssetMethods.java rename to common/src/main/java/io/metaloom/loom/client/common/method/AssetMethods.java index b7205b5..8195709 100644 --- a/rest/src/main/java/io/metaloom/loom/client/http/method/AssetMethods.java +++ b/common/src/main/java/io/metaloom/loom/client/common/method/AssetMethods.java @@ -1,11 +1,11 @@ -package io.metaloom.loom.client.http.method; +package io.metaloom.loom.client.common.method; import static io.metaloom.loom.api.asset.AssetId.assetId; import java.util.UUID; import io.metaloom.loom.api.asset.AssetId; -import io.metaloom.loom.client.http.LoomClientRequest; +import io.metaloom.loom.client.common.LoomClientRequest; import io.metaloom.loom.rest.model.NoResponse; import io.metaloom.loom.rest.model.asset.AssetCreateRequest; import io.metaloom.loom.rest.model.asset.AssetListResponse; diff --git a/rest/src/main/java/io/metaloom/loom/client/http/method/AttachmentMethods.java b/common/src/main/java/io/metaloom/loom/client/common/method/AttachmentMethods.java similarity index 84% rename from rest/src/main/java/io/metaloom/loom/client/http/method/AttachmentMethods.java rename to common/src/main/java/io/metaloom/loom/client/common/method/AttachmentMethods.java index db453f9..600278f 100644 --- a/rest/src/main/java/io/metaloom/loom/client/http/method/AttachmentMethods.java +++ b/common/src/main/java/io/metaloom/loom/client/common/method/AttachmentMethods.java @@ -1,10 +1,10 @@ -package io.metaloom.loom.client.http.method; +package io.metaloom.loom.client.common.method; import java.io.InputStream; import java.util.UUID; -import io.metaloom.loom.client.http.LoomBinaryResponse; -import io.metaloom.loom.client.http.LoomClientRequest; +import io.metaloom.loom.client.common.LoomBinaryResponse; +import io.metaloom.loom.client.common.LoomClientRequest; import io.metaloom.loom.rest.model.NoResponse; import io.metaloom.loom.rest.model.attachment.AttachmentListResponse; import io.metaloom.loom.rest.model.attachment.AttachmentResponse; diff --git a/rest/src/main/java/io/metaloom/loom/client/http/method/AuthenticationMethods.java b/common/src/main/java/io/metaloom/loom/client/common/method/AuthenticationMethods.java similarity index 63% rename from rest/src/main/java/io/metaloom/loom/client/http/method/AuthenticationMethods.java rename to common/src/main/java/io/metaloom/loom/client/common/method/AuthenticationMethods.java index f9c7bc5..dc82c68 100644 --- a/rest/src/main/java/io/metaloom/loom/client/http/method/AuthenticationMethods.java +++ b/common/src/main/java/io/metaloom/loom/client/common/method/AuthenticationMethods.java @@ -1,6 +1,6 @@ -package io.metaloom.loom.client.http.method; +package io.metaloom.loom.client.common.method; -import io.metaloom.loom.client.http.LoomClientRequest; +import io.metaloom.loom.client.common.LoomClientRequest; import io.metaloom.loom.rest.model.auth.AuthLoginResponse; public interface AuthenticationMethods { diff --git a/common/src/main/java/io/metaloom/loom/client/common/method/ClientMethods.java b/common/src/main/java/io/metaloom/loom/client/common/method/ClientMethods.java new file mode 100644 index 0000000..0321fe1 --- /dev/null +++ b/common/src/main/java/io/metaloom/loom/client/common/method/ClientMethods.java @@ -0,0 +1,23 @@ +package io.metaloom.loom.client.common.method; + +public interface ClientMethods extends + UserMethods, + AssetMethods, + AssetLocationMethods, + AttachmentMethods, + ClusterMethods, + GroupMethods, + RoleMethods, + CollectionMethods, + AnnotationMethods, + TaskMethods, + TagMethods, + AuthenticationMethods, + ReactionMethods, + TokenMethods, + LibraryMethods, + ProjectMethods, + CommentMethods, + EmbeddingMethods { + +} diff --git a/rest/src/main/java/io/metaloom/loom/client/http/method/ClusterMethods.java b/common/src/main/java/io/metaloom/loom/client/common/method/ClusterMethods.java similarity index 87% rename from rest/src/main/java/io/metaloom/loom/client/http/method/ClusterMethods.java rename to common/src/main/java/io/metaloom/loom/client/common/method/ClusterMethods.java index d91e0ce..7ab951a 100644 --- a/rest/src/main/java/io/metaloom/loom/client/http/method/ClusterMethods.java +++ b/common/src/main/java/io/metaloom/loom/client/common/method/ClusterMethods.java @@ -1,8 +1,8 @@ -package io.metaloom.loom.client.http.method; +package io.metaloom.loom.client.common.method; import java.util.UUID; -import io.metaloom.loom.client.http.LoomClientRequest; +import io.metaloom.loom.client.common.LoomClientRequest; import io.metaloom.loom.rest.model.NoResponse; import io.metaloom.loom.rest.model.cluster.ClusterCreateRequest; import io.metaloom.loom.rest.model.cluster.ClusterListResponse; diff --git a/rest/src/main/java/io/metaloom/loom/client/http/method/CollectionMethods.java b/common/src/main/java/io/metaloom/loom/client/common/method/CollectionMethods.java similarity index 88% rename from rest/src/main/java/io/metaloom/loom/client/http/method/CollectionMethods.java rename to common/src/main/java/io/metaloom/loom/client/common/method/CollectionMethods.java index 6d29599..2119fff 100644 --- a/rest/src/main/java/io/metaloom/loom/client/http/method/CollectionMethods.java +++ b/common/src/main/java/io/metaloom/loom/client/common/method/CollectionMethods.java @@ -1,8 +1,8 @@ -package io.metaloom.loom.client.http.method; +package io.metaloom.loom.client.common.method; import java.util.UUID; -import io.metaloom.loom.client.http.LoomClientRequest; +import io.metaloom.loom.client.common.LoomClientRequest; import io.metaloom.loom.rest.model.NoResponse; import io.metaloom.loom.rest.model.collection.CollectionCreateRequest; import io.metaloom.loom.rest.model.collection.CollectionListResponse; diff --git a/rest/src/main/java/io/metaloom/loom/client/http/method/CommentMethods.java b/common/src/main/java/io/metaloom/loom/client/common/method/CommentMethods.java similarity index 88% rename from rest/src/main/java/io/metaloom/loom/client/http/method/CommentMethods.java rename to common/src/main/java/io/metaloom/loom/client/common/method/CommentMethods.java index f2ae34d..763f1f9 100644 --- a/rest/src/main/java/io/metaloom/loom/client/http/method/CommentMethods.java +++ b/common/src/main/java/io/metaloom/loom/client/common/method/CommentMethods.java @@ -1,8 +1,8 @@ -package io.metaloom.loom.client.http.method; +package io.metaloom.loom.client.common.method; import java.util.UUID; -import io.metaloom.loom.client.http.LoomClientRequest; +import io.metaloom.loom.client.common.LoomClientRequest; import io.metaloom.loom.rest.model.NoResponse; import io.metaloom.loom.rest.model.comment.CommentCreateRequest; import io.metaloom.loom.rest.model.comment.CommentListResponse; diff --git a/rest/src/main/java/io/metaloom/loom/client/http/method/EmbeddingMethods.java b/common/src/main/java/io/metaloom/loom/client/common/method/EmbeddingMethods.java similarity index 87% rename from rest/src/main/java/io/metaloom/loom/client/http/method/EmbeddingMethods.java rename to common/src/main/java/io/metaloom/loom/client/common/method/EmbeddingMethods.java index 3287ce2..a5489fb 100644 --- a/rest/src/main/java/io/metaloom/loom/client/http/method/EmbeddingMethods.java +++ b/common/src/main/java/io/metaloom/loom/client/common/method/EmbeddingMethods.java @@ -1,8 +1,8 @@ -package io.metaloom.loom.client.http.method; +package io.metaloom.loom.client.common.method; import java.util.UUID; -import io.metaloom.loom.client.http.LoomClientRequest; +import io.metaloom.loom.client.common.LoomClientRequest; import io.metaloom.loom.rest.model.NoResponse; import io.metaloom.loom.rest.model.embedding.EmbeddingCreateRequest; import io.metaloom.loom.rest.model.embedding.EmbeddingListResponse; diff --git a/rest/src/main/java/io/metaloom/loom/client/http/method/GroupMethods.java b/common/src/main/java/io/metaloom/loom/client/common/method/GroupMethods.java similarity index 86% rename from rest/src/main/java/io/metaloom/loom/client/http/method/GroupMethods.java rename to common/src/main/java/io/metaloom/loom/client/common/method/GroupMethods.java index 5db9623..1b997a3 100644 --- a/rest/src/main/java/io/metaloom/loom/client/http/method/GroupMethods.java +++ b/common/src/main/java/io/metaloom/loom/client/common/method/GroupMethods.java @@ -1,8 +1,8 @@ -package io.metaloom.loom.client.http.method; +package io.metaloom.loom.client.common.method; import java.util.UUID; -import io.metaloom.loom.client.http.LoomClientRequest; +import io.metaloom.loom.client.common.LoomClientRequest; import io.metaloom.loom.rest.model.NoResponse; import io.metaloom.loom.rest.model.group.GroupCreateRequest; import io.metaloom.loom.rest.model.group.GroupListResponse; diff --git a/rest/src/main/java/io/metaloom/loom/client/http/method/LibraryMethods.java b/common/src/main/java/io/metaloom/loom/client/common/method/LibraryMethods.java similarity index 87% rename from rest/src/main/java/io/metaloom/loom/client/http/method/LibraryMethods.java rename to common/src/main/java/io/metaloom/loom/client/common/method/LibraryMethods.java index 62b9ee3..43bdc74 100644 --- a/rest/src/main/java/io/metaloom/loom/client/http/method/LibraryMethods.java +++ b/common/src/main/java/io/metaloom/loom/client/common/method/LibraryMethods.java @@ -1,8 +1,8 @@ -package io.metaloom.loom.client.http.method; +package io.metaloom.loom.client.common.method; import java.util.UUID; -import io.metaloom.loom.client.http.LoomClientRequest; +import io.metaloom.loom.client.common.LoomClientRequest; import io.metaloom.loom.rest.model.NoResponse; import io.metaloom.loom.rest.model.library.LibraryCreateRequest; import io.metaloom.loom.rest.model.library.LibraryListResponse; diff --git a/rest/src/main/java/io/metaloom/loom/client/http/method/ProjectMethods.java b/common/src/main/java/io/metaloom/loom/client/common/method/ProjectMethods.java similarity index 87% rename from rest/src/main/java/io/metaloom/loom/client/http/method/ProjectMethods.java rename to common/src/main/java/io/metaloom/loom/client/common/method/ProjectMethods.java index 52f8950..34e4eb0 100644 --- a/rest/src/main/java/io/metaloom/loom/client/http/method/ProjectMethods.java +++ b/common/src/main/java/io/metaloom/loom/client/common/method/ProjectMethods.java @@ -1,8 +1,8 @@ -package io.metaloom.loom.client.http.method; +package io.metaloom.loom.client.common.method; import java.util.UUID; -import io.metaloom.loom.client.http.LoomClientRequest; +import io.metaloom.loom.client.common.LoomClientRequest; import io.metaloom.loom.rest.model.NoResponse; import io.metaloom.loom.rest.model.project.ProjectCreateRequest; import io.metaloom.loom.rest.model.project.ProjectListResponse; diff --git a/rest/src/main/java/io/metaloom/loom/client/http/method/ReactionMethods.java b/common/src/main/java/io/metaloom/loom/client/common/method/ReactionMethods.java similarity index 96% rename from rest/src/main/java/io/metaloom/loom/client/http/method/ReactionMethods.java rename to common/src/main/java/io/metaloom/loom/client/common/method/ReactionMethods.java index 64f39b0..60759bb 100644 --- a/rest/src/main/java/io/metaloom/loom/client/http/method/ReactionMethods.java +++ b/common/src/main/java/io/metaloom/loom/client/common/method/ReactionMethods.java @@ -1,11 +1,11 @@ -package io.metaloom.loom.client.http.method; +package io.metaloom.loom.client.common.method; import static io.metaloom.loom.api.asset.AssetId.assetId; import java.util.UUID; import io.metaloom.loom.api.asset.AssetId; -import io.metaloom.loom.client.http.LoomClientRequest; +import io.metaloom.loom.client.common.LoomClientRequest; import io.metaloom.loom.rest.model.NoResponse; import io.metaloom.loom.rest.model.reaction.ReactionCreateRequest; import io.metaloom.loom.rest.model.reaction.ReactionListResponse; diff --git a/rest/src/main/java/io/metaloom/loom/client/http/method/RoleMethods.java b/common/src/main/java/io/metaloom/loom/client/common/method/RoleMethods.java similarity index 86% rename from rest/src/main/java/io/metaloom/loom/client/http/method/RoleMethods.java rename to common/src/main/java/io/metaloom/loom/client/common/method/RoleMethods.java index 2185eec..58635d0 100644 --- a/rest/src/main/java/io/metaloom/loom/client/http/method/RoleMethods.java +++ b/common/src/main/java/io/metaloom/loom/client/common/method/RoleMethods.java @@ -1,8 +1,8 @@ -package io.metaloom.loom.client.http.method; +package io.metaloom.loom.client.common.method; import java.util.UUID; -import io.metaloom.loom.client.http.LoomClientRequest; +import io.metaloom.loom.client.common.LoomClientRequest; import io.metaloom.loom.rest.model.NoResponse; import io.metaloom.loom.rest.model.role.RoleCreateRequest; import io.metaloom.loom.rest.model.role.RoleListResponse; diff --git a/rest/src/main/java/io/metaloom/loom/client/http/method/TagMethods.java b/common/src/main/java/io/metaloom/loom/client/common/method/TagMethods.java similarity index 93% rename from rest/src/main/java/io/metaloom/loom/client/http/method/TagMethods.java rename to common/src/main/java/io/metaloom/loom/client/common/method/TagMethods.java index 5f8b5b8..72d5784 100644 --- a/rest/src/main/java/io/metaloom/loom/client/http/method/TagMethods.java +++ b/common/src/main/java/io/metaloom/loom/client/common/method/TagMethods.java @@ -1,11 +1,11 @@ -package io.metaloom.loom.client.http.method; +package io.metaloom.loom.client.common.method; import static io.metaloom.loom.api.asset.AssetId.assetId; import java.util.UUID; import io.metaloom.loom.api.asset.AssetId; -import io.metaloom.loom.client.http.LoomClientRequest; +import io.metaloom.loom.client.common.LoomClientRequest; import io.metaloom.loom.rest.model.NoResponse; import io.metaloom.loom.rest.model.tag.TagCreateRequest; import io.metaloom.loom.rest.model.tag.TagListResponse; diff --git a/rest/src/main/java/io/metaloom/loom/client/http/method/TaskMethods.java b/common/src/main/java/io/metaloom/loom/client/common/method/TaskMethods.java similarity index 86% rename from rest/src/main/java/io/metaloom/loom/client/http/method/TaskMethods.java rename to common/src/main/java/io/metaloom/loom/client/common/method/TaskMethods.java index 80be15f..fb19803 100644 --- a/rest/src/main/java/io/metaloom/loom/client/http/method/TaskMethods.java +++ b/common/src/main/java/io/metaloom/loom/client/common/method/TaskMethods.java @@ -1,8 +1,8 @@ -package io.metaloom.loom.client.http.method; +package io.metaloom.loom.client.common.method; import java.util.UUID; -import io.metaloom.loom.client.http.LoomClientRequest; +import io.metaloom.loom.client.common.LoomClientRequest; import io.metaloom.loom.rest.model.NoResponse; import io.metaloom.loom.rest.model.task.TaskCreateRequest; import io.metaloom.loom.rest.model.task.TaskListResponse; diff --git a/rest/src/main/java/io/metaloom/loom/client/http/method/TokenMethods.java b/common/src/main/java/io/metaloom/loom/client/common/method/TokenMethods.java similarity index 86% rename from rest/src/main/java/io/metaloom/loom/client/http/method/TokenMethods.java rename to common/src/main/java/io/metaloom/loom/client/common/method/TokenMethods.java index 07e9556..795c853 100644 --- a/rest/src/main/java/io/metaloom/loom/client/http/method/TokenMethods.java +++ b/common/src/main/java/io/metaloom/loom/client/common/method/TokenMethods.java @@ -1,8 +1,8 @@ -package io.metaloom.loom.client.http.method; +package io.metaloom.loom.client.common.method; import java.util.UUID; -import io.metaloom.loom.client.http.LoomClientRequest; +import io.metaloom.loom.client.common.LoomClientRequest; import io.metaloom.loom.rest.model.NoResponse; import io.metaloom.loom.rest.model.token.TokenCreateRequest; import io.metaloom.loom.rest.model.token.TokenListResponse; diff --git a/rest/src/main/java/io/metaloom/loom/client/http/method/UserMethods.java b/common/src/main/java/io/metaloom/loom/client/common/method/UserMethods.java similarity index 86% rename from rest/src/main/java/io/metaloom/loom/client/http/method/UserMethods.java rename to common/src/main/java/io/metaloom/loom/client/common/method/UserMethods.java index 2b75c86..81530a5 100644 --- a/rest/src/main/java/io/metaloom/loom/client/http/method/UserMethods.java +++ b/common/src/main/java/io/metaloom/loom/client/common/method/UserMethods.java @@ -1,8 +1,8 @@ -package io.metaloom.loom.client.http.method; +package io.metaloom.loom.client.common.method; import java.util.UUID; -import io.metaloom.loom.client.http.LoomClientRequest; +import io.metaloom.loom.client.common.LoomClientRequest; import io.metaloom.loom.rest.model.NoResponse; import io.metaloom.loom.rest.model.user.UserCreateRequest; import io.metaloom.loom.rest.model.user.UserListResponse; diff --git a/grpc/src/main/java/io/metaloom/loom/client/grpc/LoomGRPCClient.java b/grpc/src/main/java/io/metaloom/loom/client/grpc/LoomGRPCClient.java index e9c4ae3..7a44156 100644 --- a/grpc/src/main/java/io/metaloom/loom/client/grpc/LoomGRPCClient.java +++ b/grpc/src/main/java/io/metaloom/loom/client/grpc/LoomGRPCClient.java @@ -1,9 +1,10 @@ package io.metaloom.loom.client.grpc; +import io.metaloom.loom.client.common.LoomClient; import io.metaloom.loom.client.grpc.impl.LoomGRPCClientImpl; import io.metaloom.loom.client.grpc.method.AssetMethods; -public interface LoomGRPCClient extends AssetMethods, ClientSettings, AutoCloseable { +public interface LoomGRPCClient extends AssetMethods, ClientSettings, LoomClient { static LoomGRPCClientImpl.Builder builder() { return LoomGRPCClientImpl.builder(); @@ -12,16 +13,4 @@ static LoomGRPCClientImpl.Builder builder() { // TODO add version info String USER_AGENT = "Loom gRPC Client"; - /** - * Close the prepared transport channel. - */ - void close(); - - /** - * Set the token that will be used to authenticate the requests. - * - * @param token - */ - void setToken(String token); - } diff --git a/pom.xml b/pom.xml index 6696cda..4223ee1 100644 --- a/pom.xml +++ b/pom.xml @@ -21,7 +21,9 @@ common rest + report @@ -82,6 +84,12 @@ + + + io.metaloom.loom.shared + loom-rest-model + + org.testcontainers diff --git a/report/pom.xml b/report/pom.xml index 1b7c950..d42ba84 100644 --- a/report/pom.xml +++ b/report/pom.xml @@ -1,6 +1,6 @@ + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 loom-client-report @@ -25,11 +25,13 @@ loom-client-rest ${project.version} + diff --git a/rest/pom.xml b/rest/pom.xml index 84fd004..9634ecd 100644 --- a/rest/pom.xml +++ b/rest/pom.xml @@ -1,6 +1,6 @@ + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 loom-client-rest @@ -22,10 +22,6 @@ - - io.metaloom.loom.shared - loom-rest-model - io.metaloom.loom.client loom-client-common diff --git a/rest/src/main/java/io/metaloom/loom/client/http/AbstractLoomOkHttpClient.java b/rest/src/main/java/io/metaloom/loom/client/http/AbstractLoomOkHttpClient.java index 9cc97fd..1a74cd9 100644 --- a/rest/src/main/java/io/metaloom/loom/client/http/AbstractLoomOkHttpClient.java +++ b/rest/src/main/java/io/metaloom/loom/client/http/AbstractLoomOkHttpClient.java @@ -1,14 +1,15 @@ package io.metaloom.loom.client.http; -import static io.metaloom.loom.client.http.LoomClientRequest.DELETE; -import static io.metaloom.loom.client.http.LoomClientRequest.GET; -import static io.metaloom.loom.client.http.LoomClientRequest.PATCH; -import static io.metaloom.loom.client.http.LoomClientRequest.POST; -import static io.metaloom.loom.client.http.LoomClientRequest.PUT; +import static io.metaloom.loom.client.http.LoomClientHttpRequest.DELETE; +import static io.metaloom.loom.client.http.LoomClientHttpRequest.GET; +import static io.metaloom.loom.client.http.LoomClientHttpRequest.PATCH; +import static io.metaloom.loom.client.http.LoomClientHttpRequest.POST; +import static io.metaloom.loom.client.http.LoomClientHttpRequest.PUT; import java.io.InputStream; import java.time.Duration; +import io.metaloom.loom.client.common.LoomBinaryResponse; import io.metaloom.loom.rest.model.NoResponse; import io.metaloom.loom.rest.model.RestRequestModel; import io.metaloom.loom.rest.model.RestResponseModel; @@ -38,40 +39,40 @@ public void close() { // Not needed for OkClient } - protected > LoomClientRequest postUploadRequest(String path, Class responseClass, + protected > LoomClientHttpRequest postUploadRequest(String path, Class responseClass, InputStream binaryData, String mimeType) { - return LoomClientRequest.createBinaryRequest(POST, path, this, okClient, responseClass, binaryData, mimeType); + return LoomClientHttpRequest.createBinaryRequest(POST, path, this, okClient, responseClass, binaryData, mimeType); } - protected LoomClientRequest getDownloadRequest(String path) { - return LoomClientRequest.createDownloadRequest(GET, path, this, okClient, LoomBinaryResponse.class); + protected LoomClientHttpRequest getDownloadRequest(String path) { + return LoomClientHttpRequest.createDownloadRequest(GET, path, this, okClient, LoomBinaryResponse.class); } - protected > LoomClientRequest deleteRequest(String path, Class responseClass) { - return LoomClientRequest.createNoBodyRequest(DELETE, path, this, okClient, responseClass); + protected > LoomClientHttpRequest deleteRequest(String path, Class responseClass) { + return LoomClientHttpRequest.createNoBodyRequest(DELETE, path, this, okClient, responseClass); } - protected LoomClientRequest deleteRequest(String path) { - return LoomClientRequest.createNoResponseRequest(DELETE, path, this, okClient); + protected LoomClientHttpRequest deleteRequest(String path) { + return LoomClientHttpRequest.createNoResponseRequest(DELETE, path, this, okClient); } - protected > LoomClientRequest getRequest(String path, Class responseClass) { - return LoomClientRequest.createNoBodyRequest(GET, path, this, okClient, responseClass); + protected > LoomClientHttpRequest getRequest(String path, Class responseClass) { + return LoomClientHttpRequest.createNoBodyRequest(GET, path, this, okClient, responseClass); } - protected > LoomClientRequest postRequest(String path, RestRequestModel request, Class responseClass) { - return LoomClientRequest.createJsonRequest(POST, path, this, okClient, request, responseClass); + protected > LoomClientHttpRequest postRequest(String path, RestRequestModel request, Class responseClass) { + return LoomClientHttpRequest.createJsonRequest(POST, path, this, okClient, request, responseClass); } - protected > LoomClientRequest postRequest(String path, Class responseClass) { - return LoomClientRequest.createNoBodyRequest(POST, path, this, okClient, responseClass); + protected > LoomClientHttpRequest postRequest(String path, Class responseClass) { + return LoomClientHttpRequest.createNoBodyRequest(POST, path, this, okClient, responseClass); } - protected > LoomClientRequest putRequest(String path, RestRequestModel request, Class responseClass) { - return LoomClientRequest.createJsonRequest(PUT, path, this, okClient, request, responseClass); + protected > LoomClientHttpRequest putRequest(String path, RestRequestModel request, Class responseClass) { + return LoomClientHttpRequest.createJsonRequest(PUT, path, this, okClient, request, responseClass); } - protected > LoomClientRequest patchRequest(String path, RestRequestModel request, Class responseClass) { - return LoomClientRequest.createJsonRequest(PATCH, path, this, okClient, request, responseClass); + protected > LoomClientHttpRequest patchRequest(String path, RestRequestModel request, Class responseClass) { + return LoomClientHttpRequest.createJsonRequest(PATCH, path, this, okClient, request, responseClass); } } diff --git a/rest/src/main/java/io/metaloom/loom/client/http/ClientMethods.java b/rest/src/main/java/io/metaloom/loom/client/http/ClientMethods.java deleted file mode 100644 index dffebbc..0000000 --- a/rest/src/main/java/io/metaloom/loom/client/http/ClientMethods.java +++ /dev/null @@ -1,42 +0,0 @@ -package io.metaloom.loom.client.http; - -import io.metaloom.loom.client.http.method.AnnotationMethods; -import io.metaloom.loom.client.http.method.AssetLocationMethods; -import io.metaloom.loom.client.http.method.AssetMethods; -import io.metaloom.loom.client.http.method.AttachmentMethods; -import io.metaloom.loom.client.http.method.AuthenticationMethods; -import io.metaloom.loom.client.http.method.ClusterMethods; -import io.metaloom.loom.client.http.method.CollectionMethods; -import io.metaloom.loom.client.http.method.CommentMethods; -import io.metaloom.loom.client.http.method.EmbeddingMethods; -import io.metaloom.loom.client.http.method.GroupMethods; -import io.metaloom.loom.client.http.method.LibraryMethods; -import io.metaloom.loom.client.http.method.ProjectMethods; -import io.metaloom.loom.client.http.method.ReactionMethods; -import io.metaloom.loom.client.http.method.RoleMethods; -import io.metaloom.loom.client.http.method.TagMethods; -import io.metaloom.loom.client.http.method.TaskMethods; -import io.metaloom.loom.client.http.method.TokenMethods; -import io.metaloom.loom.client.http.method.UserMethods; - -public interface ClientMethods extends - UserMethods, - AssetMethods, - AssetLocationMethods, - AttachmentMethods, - ClusterMethods, - GroupMethods, - RoleMethods, - CollectionMethods, - AnnotationMethods, - TaskMethods, - TagMethods, - AuthenticationMethods, - ReactionMethods, - TokenMethods, - LibraryMethods, - ProjectMethods, - CommentMethods, - EmbeddingMethods { - -} diff --git a/rest/src/main/java/io/metaloom/loom/client/http/LoomClientRequest.java b/rest/src/main/java/io/metaloom/loom/client/http/LoomClientHttpRequest.java similarity index 73% rename from rest/src/main/java/io/metaloom/loom/client/http/LoomClientRequest.java rename to rest/src/main/java/io/metaloom/loom/client/http/LoomClientHttpRequest.java index 922541f..6a9ffce 100644 --- a/rest/src/main/java/io/metaloom/loom/client/http/LoomClientRequest.java +++ b/rest/src/main/java/io/metaloom/loom/client/http/LoomClientHttpRequest.java @@ -8,9 +8,11 @@ import com.fasterxml.jackson.databind.JsonNode; -import io.metaloom.loom.client.http.impl.HttpErrorException; +import io.metaloom.loom.client.common.LoomBinaryResponse; +import io.metaloom.loom.client.common.LoomClientException; +import io.metaloom.loom.client.common.LoomClientRequest; +import io.metaloom.loom.client.http.error.LoomHttpClientException; import io.metaloom.loom.client.http.impl.LoomClientRequestImpl; -import io.metaloom.loom.client.http.parameter.QueryParameters; import io.metaloom.loom.rest.json.Json; import io.metaloom.loom.rest.model.NoResponse; import io.metaloom.loom.rest.model.RestRequestModel; @@ -22,9 +24,9 @@ import okio.BufferedSink; import okio.Okio; -public interface LoomClientRequest> extends QueryParameters { +public interface LoomClientHttpRequest> extends LoomClientRequest { - public static final Logger log = LoggerFactory.getLogger(LoomClientRequest.class); + public static final Logger log = LoggerFactory.getLogger(LoomClientHttpRequest.class); public static final MediaType MEDIA_TYPE_JSON = MediaType.parse("application/json; charset=utf-8"); @@ -44,7 +46,7 @@ public interface LoomClientRequest> extends Query * @param okClient * @return */ - public static LoomClientRequest createNoResponseRequest(String method, String path, LoomHttpClient loomClient, + public static LoomClientHttpRequest createNoResponseRequest(String method, String path, LoomHttpClient loomClient, OkHttpClient okClient) { return new LoomClientRequestImpl<>(method, path, loomClient, okClient, NoResponse.class, null); } @@ -60,18 +62,18 @@ public static LoomClientRequest createNoResponseRequest(String metho * @param responseClass * @return */ - public static > LoomClientRequest createNoBodyRequest(String method, String path, LoomHttpClient loomClient, + public static > LoomClientHttpRequest createNoBodyRequest(String method, String path, LoomHttpClient loomClient, OkHttpClient okClient, Class responseClass) { return new LoomClientRequestImpl<>(method, path, loomClient, okClient, responseClass, null); } - public static LoomClientRequest createDownloadRequest(String method, String path, LoomHttpClient loomClient, + public static LoomClientHttpRequest createDownloadRequest(String method, String path, LoomHttpClient loomClient, OkHttpClient okClient, Class responseClass) { return new LoomClientRequestImpl<>(method, path, loomClient, okClient, responseClass, null); } - public static > LoomClientRequest createBinaryRequest(String method, String path, LoomHttpClient loomClient, + public static > LoomClientHttpRequest createBinaryRequest(String method, String path, LoomHttpClient loomClient, OkHttpClient okClient, Class responseClass, InputStream data, String contentType) { return new LoomClientRequestImpl<>(method, path, loomClient, okClient, responseClass, new RequestBody() { @Override @@ -102,7 +104,7 @@ public void writeTo(BufferedSink sink) throws IOException { * @param responseClass * @return */ - public static > LoomClientRequest createJsonRequest(String method, String path, LoomHttpClient loomClient, + public static > LoomClientHttpRequest createJsonRequest(String method, String path, LoomHttpClient loomClient, OkHttpClient okClient, RestRequestModel request, Class responseClass) { String bodyStr = Json.parse(request); if (log.isDebugEnabled()) { @@ -123,9 +125,9 @@ public static > LoomClientRequest createJsonRe * Executes the request in a synchronized blocking way and returns the returned JSON data. * * @return - * @throws HttpErrorException + * @throws LoomHttpClientException */ - JsonNode json() throws HttpErrorException; + JsonNode json() throws LoomHttpClientException; /** * Executes the request in a synchronized blocking way. @@ -133,6 +135,6 @@ public static > LoomClientRequest createJsonRe * @return * @throws HttpErrorException */ - T sync() throws HttpErrorException; + T sync() throws LoomClientException; } diff --git a/rest/src/main/java/io/metaloom/loom/client/http/LoomHttpClient.java b/rest/src/main/java/io/metaloom/loom/client/http/LoomHttpClient.java index 281b845..88b4a73 100644 --- a/rest/src/main/java/io/metaloom/loom/client/http/LoomHttpClient.java +++ b/rest/src/main/java/io/metaloom/loom/client/http/LoomHttpClient.java @@ -2,9 +2,11 @@ import java.time.Duration; +import io.metaloom.loom.client.common.LoomClient; +import io.metaloom.loom.client.common.method.ClientMethods; import io.metaloom.loom.client.http.impl.LoomHttpClientImpl; -public interface LoomHttpClient extends ClientMethods, ClientSettings, AutoCloseable { +public interface LoomHttpClient extends ClientSettings, LoomClient { static LoomHttpClientImpl.Builder builder() { return LoomHttpClientImpl.builder(); @@ -40,11 +42,6 @@ static LoomHttpClientImpl.Builder builder() { */ String getPathPrefix(); - /** - * Close the client and release all resources. - */ - void close(); - /** * Return the configured connect timeout. * @@ -66,13 +63,6 @@ static LoomHttpClientImpl.Builder builder() { */ Duration getWriteTimeout(); - /** - * Set the token to be used for authentication. - * - * @param token - */ - void setToken(String token); - /** * Return the used authentication token. * diff --git a/rest/src/main/java/io/metaloom/loom/client/http/impl/HttpErrorException.java b/rest/src/main/java/io/metaloom/loom/client/http/error/LoomHttpClientException.java similarity index 55% rename from rest/src/main/java/io/metaloom/loom/client/http/impl/HttpErrorException.java rename to rest/src/main/java/io/metaloom/loom/client/http/error/LoomHttpClientException.java index d80f07d..804d0a5 100644 --- a/rest/src/main/java/io/metaloom/loom/client/http/impl/HttpErrorException.java +++ b/rest/src/main/java/io/metaloom/loom/client/http/error/LoomHttpClientException.java @@ -1,34 +1,34 @@ -package io.metaloom.loom.client.http.impl; +package io.metaloom.loom.client.http.error; import java.util.function.Function; +import io.metaloom.loom.client.common.LoomClientException; import io.metaloom.loom.rest.json.Json; import io.metaloom.loom.rest.model.message.GenericMessageResponse; /** * Exception which is also used to return non-200 error responses. */ -public class HttpErrorException extends Exception { +public class LoomHttpClientException extends LoomClientException { - private static final long serialVersionUID = -1799524340729007029L; + private static final long serialVersionUID = 7139036965636956371L; - private int statusCode; + private final String body; - private String body; + private final String statusMsg; - private String statusMsg; + public LoomHttpClientException(String message, Exception e) { + super(500, message, e); + this.statusMsg = message; + this.body = ""; + } - public HttpErrorException(String message, int statusCode, String statusMsg, String body) { - super(message); - this.statusCode = statusCode; + public LoomHttpClientException(String message, int statusCode, String statusMsg, String body) { + super(statusCode, message); this.statusMsg = statusMsg; this.body = body; } - public HttpErrorException(String message, Exception e) { - super(message, e); - } - /** * Returns the error response body. * @@ -38,20 +38,7 @@ public String getBody() { return body; } - /** - * Returns the error HTTTP status code. - * - * @return - */ - public int getStatusCode() { - return statusCode; - } - - /** - * Return the error HTTP status message. - * - * @return - */ + @Override public String getStatusMsg() { return statusMsg; } @@ -78,7 +65,7 @@ public T getBodyObject(Function parser) { @Override public String toString() { - return getMessage() + " - status: " + statusCode + " body {" + body + "}"; + return getMessage() + " - status: " + getStatusCode() + " body {" + getBody() + "}"; } } diff --git a/rest/src/main/java/io/metaloom/loom/client/http/impl/LoomBinaryResponseImpl.java b/rest/src/main/java/io/metaloom/loom/client/http/impl/LoomBinaryResponseImpl.java index 3155fe3..9a9cd8f 100644 --- a/rest/src/main/java/io/metaloom/loom/client/http/impl/LoomBinaryResponseImpl.java +++ b/rest/src/main/java/io/metaloom/loom/client/http/impl/LoomBinaryResponseImpl.java @@ -4,7 +4,7 @@ import java.io.UnsupportedEncodingException; import java.net.URLDecoder; -import io.metaloom.loom.client.http.LoomBinaryResponse; +import io.metaloom.loom.client.common.LoomBinaryResponse; import okhttp3.Response; public class LoomBinaryResponseImpl implements LoomBinaryResponse { diff --git a/rest/src/main/java/io/metaloom/loom/client/http/impl/LoomClientRequestImpl.java b/rest/src/main/java/io/metaloom/loom/client/http/impl/LoomClientRequestImpl.java index 558c330..2931808 100644 --- a/rest/src/main/java/io/metaloom/loom/client/http/impl/LoomClientRequestImpl.java +++ b/rest/src/main/java/io/metaloom/loom/client/http/impl/LoomClientRequestImpl.java @@ -8,9 +8,10 @@ import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonNode; -import io.metaloom.loom.client.http.LoomBinaryResponse; -import io.metaloom.loom.client.http.LoomClientRequest; +import io.metaloom.loom.client.common.LoomBinaryResponse; +import io.metaloom.loom.client.http.LoomClientHttpRequest; import io.metaloom.loom.client.http.LoomHttpClient; +import io.metaloom.loom.client.http.error.LoomHttpClientException; import io.metaloom.loom.rest.json.Json; import io.metaloom.loom.rest.model.NoResponse; import io.metaloom.loom.rest.model.RestModel; @@ -26,7 +27,7 @@ import okhttp3.Response; import okhttp3.ResponseBody; -public class LoomClientRequestImpl> implements LoomClientRequest { +public class LoomClientRequestImpl> implements LoomClientHttpRequest { public static final Logger log = LoggerFactory.getLogger(LoomClientRequestImpl.class); @@ -73,7 +74,7 @@ private Request build() { } @Override - public JsonNode json() throws HttpErrorException { + public JsonNode json() throws LoomHttpClientException { return executeSyncJson(build()); } @@ -83,13 +84,13 @@ public Single async() { } @Override - public LoomClientRequest addQueryParameter(String key, String value) { + public LoomClientHttpRequest addQueryParameter(String key, String value) { urlBuilder.addQueryParameter(key, value); return this; } @Override - public T sync() throws HttpErrorException { + public T sync() throws LoomHttpClientException { return executeSync(build()); } @@ -100,7 +101,7 @@ public T sync() throws HttpErrorException { * @return Response body text * @throws HttpErrorException */ - private String executeSyncPlain(Request request) throws HttpErrorException { + private String executeSyncPlain(Request request) throws LoomHttpClientException { try (Response response = okClient.newCall(request).execute()) { ResponseBody body = response.body(); String bodyStr = ""; @@ -108,7 +109,7 @@ private String executeSyncPlain(Request request) throws HttpErrorException { try { bodyStr = body.string(); } catch (Exception e) { - throw new HttpErrorException("Error while reading body", e); + throw new LoomHttpClientException("Error while reading body", e); } } if (!response.isSuccessful()) { @@ -116,12 +117,12 @@ private String executeSyncPlain(Request request) throws HttpErrorException { log.debug("Failed request with code {" + response.code() + "} and body:\n" + bodyStr); } - throw new HttpErrorException("Request failed {" + response.message() + "}", response.code(), response.message(), bodyStr); + throw new LoomHttpClientException("Request failed {" + response.message() + "}", response.code(), response.message(), bodyStr); } return bodyStr; } catch (IOException e1) { - throw new HttpErrorException("Error while excuting request", e1); + throw new LoomHttpClientException("Error while excuting request", e1); } } @@ -131,7 +132,7 @@ private String executeSyncPlain(Request request) throws HttpErrorException { * @param request * @throws HttpErrorException */ - private void executeSyncNoResponse(Request request) throws HttpErrorException { + private void executeSyncNoResponse(Request request) throws LoomHttpClientException { try (Response response = okClient.newCall(request).execute()) { if (response.isSuccessful()) { return; @@ -146,28 +147,28 @@ private void executeSyncNoResponse(Request request) throws HttpErrorException { try { bodyStr = body.string(); } catch (Exception e) { - throw new HttpErrorException("Error while reading body", e); + throw new LoomHttpClientException("Error while reading body", e); } } - throw new HttpErrorException("Request failed {" + response.message() + "}", response.code(), response.message(), bodyStr); + throw new LoomHttpClientException("Request failed {" + response.message() + "}", response.code(), response.message(), bodyStr); } } catch (IOException e1) { - throw new HttpErrorException("Error while excuting request", e1); + throw new LoomHttpClientException("Error while excuting request", e1); } } - private LoomBinaryResponse executeSyncBinary(Request request) throws HttpErrorException { + private LoomBinaryResponse executeSyncBinary(Request request) throws LoomHttpClientException { try { Response response = okClient.newCall(request).execute(); return new LoomBinaryResponseImpl(response); } catch (IOException e1) { - throw new HttpErrorException("Error while excuting request", e1); + throw new LoomHttpClientException("Error while excuting request", e1); } } @SuppressWarnings("unchecked") - public T executeSync(Request request) throws HttpErrorException { + public T executeSync(Request request) throws LoomHttpClientException { if (NoResponse.class.isAssignableFrom(responseClass)) { executeSyncNoResponse(request); return null; @@ -192,12 +193,12 @@ public T executeSync(Request request) throws HttpErrorException { * @return Parsed response object * @throws HttpErrorException */ - private JsonNode executeSyncJson(Request request) throws HttpErrorException { + private JsonNode executeSyncJson(Request request) throws LoomHttpClientException { try { String bodyStr = executeSyncPlain(request); return Json.toJson(bodyStr); } catch (JsonProcessingException e) { - throw new HttpErrorException("Error while excuting request", e); + throw new LoomHttpClientException("Error while excuting request", e); } } @@ -234,12 +235,12 @@ public void onResponse(Call call, Response response) { try { bodyStr = body.string(); } catch (Exception e) { - sub.onError(new HttpErrorException("Error while reading body", e)); + sub.onError(new LoomHttpClientException("Error while reading body", e)); return; } } if (!response.isSuccessful()) { - sub.onError(new HttpErrorException("Request failed", response.code(), response.message(), bodyStr)); + sub.onError(new LoomHttpClientException("Request failed", response.code(), response.message(), bodyStr)); return; } if (RestModel.class.isAssignableFrom(responseClass)) { @@ -258,7 +259,7 @@ public void onResponse(Call call, Response response) { } @Override - public LoomClientRequest self() { + public LoomClientHttpRequest self() { return this; } diff --git a/rest/src/main/java/io/metaloom/loom/client/http/impl/LoomHttpClientImpl.java b/rest/src/main/java/io/metaloom/loom/client/http/impl/LoomHttpClientImpl.java index 5710db5..83786a3 100644 --- a/rest/src/main/java/io/metaloom/loom/client/http/impl/LoomHttpClientImpl.java +++ b/rest/src/main/java/io/metaloom/loom/client/http/impl/LoomHttpClientImpl.java @@ -14,9 +14,9 @@ import org.slf4j.LoggerFactory; import io.metaloom.loom.api.asset.AssetId; +import io.metaloom.loom.client.common.LoomBinaryResponse; import io.metaloom.loom.client.http.AbstractLoomOkHttpClient; -import io.metaloom.loom.client.http.LoomBinaryResponse; -import io.metaloom.loom.client.http.LoomClientRequest; +import io.metaloom.loom.client.http.LoomClientHttpRequest; import io.metaloom.loom.rest.model.NoResponse; import io.metaloom.loom.rest.model.annotation.AnnotationCreateRequest; import io.metaloom.loom.rest.model.annotation.AnnotationListResponse; @@ -256,7 +256,7 @@ public Builder setWriteTimeout(Duration writeTimeout) { // REST Methods @Override - public LoomClientRequest login(String username, String password) { + public LoomClientHttpRequest login(String username, String password) { AuthLoginRequest request = new AuthLoginRequest(); request.setUsername(username); request.setPassword(password); @@ -264,436 +264,436 @@ public LoomClientRequest login(String username, String passwo } @Override - public LoomClientRequest loadUser(UUID uuid) { + public LoomClientHttpRequest loadUser(UUID uuid) { return getRequest("users/" + uuid, UserResponse.class); } @Override - public LoomClientRequest createUser(UserCreateRequest request) { + public LoomClientHttpRequest createUser(UserCreateRequest request) { return postRequest("users", request, UserResponse.class); } @Override - public LoomClientRequest updateUser(UUID userUuid, UserUpdateRequest request) { + public LoomClientHttpRequest updateUser(UUID userUuid, UserUpdateRequest request) { return postRequest("users/" + userUuid, request, UserResponse.class); } @Override - public LoomClientRequest listUsers() { + public LoomClientHttpRequest listUsers() { return getRequest("users", UserListResponse.class); } @Override - public LoomClientRequest deleteUser(UUID userUuid) { + public LoomClientHttpRequest deleteUser(UUID userUuid) { return deleteRequest("users/" + userUuid); } // ASSET @Override - public LoomClientRequest loadAsset(AssetId assetId) { + public LoomClientHttpRequest loadAsset(AssetId assetId) { return getRequest("assets/" + assetId, AssetResponse.class); } @Override - public LoomClientRequest createAsset(AssetCreateRequest request) { + public LoomClientHttpRequest createAsset(AssetCreateRequest request) { return postRequest("assets", request, AssetResponse.class); } @Override - public LoomClientRequest updateAsset(AssetId assetId, AssetUpdateRequest request) { + public LoomClientHttpRequest updateAsset(AssetId assetId, AssetUpdateRequest request) { return postRequest("assets/" + assetId, request, AssetResponse.class); } @Override - public LoomClientRequest deleteAsset(AssetId assetId) { + public LoomClientHttpRequest deleteAsset(AssetId assetId) { return deleteRequest("assets/" + assetId); } @Override - public LoomClientRequest listAssets() { + public LoomClientHttpRequest listAssets() { return getRequest("assets", AssetListResponse.class); } // ASSET + TAG @Override - public LoomClientRequest tagAsset(AssetId assetId, TagCreateRequest request) { + public LoomClientHttpRequest tagAsset(AssetId assetId, TagCreateRequest request) { return postRequest("assets/" + assetId + "/tags", request, TagResponse.class); } @Override - public LoomClientRequest untagAsset(AssetId assetId, UUID tagUuid) { + public LoomClientHttpRequest untagAsset(AssetId assetId, UUID tagUuid) { return deleteRequest("assets/" + assetId + "/tags/" + tagUuid); } // LOCATION @Override - public LoomClientRequest deleteLocation(UUID locationUuid) { + public LoomClientHttpRequest deleteLocation(UUID locationUuid) { return deleteRequest("locations/" + locationUuid); } @Override - public LoomClientRequest createLocation(AssetLocationCreateRequest request) { + public LoomClientHttpRequest createLocation(AssetLocationCreateRequest request) { return postRequest("locations", request, AssetLocationResponse.class); } @Override - public LoomClientRequest updateLocation(UUID locationUuid, AssetLocationUpdateRequest request) { + public LoomClientHttpRequest updateLocation(UUID locationUuid, AssetLocationUpdateRequest request) { return postRequest("locations/" + locationUuid, request, AssetLocationResponse.class); } @Override - public LoomClientRequest loadLocation(UUID locationUuid) { + public LoomClientHttpRequest loadLocation(UUID locationUuid) { return getRequest("locations/" + locationUuid, AssetLocationResponse.class); } @Override - public LoomClientRequest listLocations() { + public LoomClientHttpRequest listLocations() { return getRequest("locations", AssetLocationListResponse.class); } // CLUSTER @Override - public LoomClientRequest loadCluster(UUID uuid) { + public LoomClientHttpRequest loadCluster(UUID uuid) { return getRequest("/clusters/" + uuid, ClusterResponse.class); } @Override - public LoomClientRequest deleteCluster(UUID uuid) { + public LoomClientHttpRequest deleteCluster(UUID uuid) { return deleteRequest("/clusters/" + uuid); } @Override - public LoomClientRequest updateCluster(UUID clusterUuid, ClusterUpdateRequest request) { + public LoomClientHttpRequest updateCluster(UUID clusterUuid, ClusterUpdateRequest request) { return postRequest("clusters/" + clusterUuid, request, ClusterResponse.class); } @Override - public LoomClientRequest createCluster(ClusterCreateRequest request) { + public LoomClientHttpRequest createCluster(ClusterCreateRequest request) { return postRequest("clusters", request, ClusterResponse.class); } @Override - public LoomClientRequest listClusters() { + public LoomClientHttpRequest listClusters() { return getRequest("clusters", ClusterListResponse.class); } // PROJECT @Override - public LoomClientRequest loadProject(UUID projectUuid) { + public LoomClientHttpRequest loadProject(UUID projectUuid) { return getRequest("projects/" + projectUuid, ProjectResponse.class); } @Override - public LoomClientRequest deleteProject(UUID projectUuid) { + public LoomClientHttpRequest deleteProject(UUID projectUuid) { return deleteRequest("projects/" + projectUuid); } @Override - public LoomClientRequest createProject(ProjectCreateRequest request) { + public LoomClientHttpRequest createProject(ProjectCreateRequest request) { return postRequest("projects", request, ProjectResponse.class); } @Override - public LoomClientRequest updateProject(UUID projectUuid, ProjectUpdateRequest request) { + public LoomClientHttpRequest updateProject(UUID projectUuid, ProjectUpdateRequest request) { return postRequest("projects/" + projectUuid, request, ProjectResponse.class); } @Override - public LoomClientRequest listProjects() { + public LoomClientHttpRequest listProjects() { return getRequest("projects", ProjectListResponse.class); } // LIBRARY @Override - public LoomClientRequest loadLibrary(UUID libraryUuid) { + public LoomClientHttpRequest loadLibrary(UUID libraryUuid) { return getRequest("libraries/" + libraryUuid, LibraryResponse.class); } @Override - public LoomClientRequest deleteLibrary(UUID libraryUuid) { + public LoomClientHttpRequest deleteLibrary(UUID libraryUuid) { return deleteRequest("libraries/" + libraryUuid); } @Override - public LoomClientRequest listLibraries() { + public LoomClientHttpRequest listLibraries() { return getRequest("libraries", LibraryListResponse.class); } @Override - public LoomClientRequest updateLibrary(UUID libraryUuid, LibraryUpdateRequest request) { + public LoomClientHttpRequest updateLibrary(UUID libraryUuid, LibraryUpdateRequest request) { return postRequest("libraries/" + libraryUuid, request, LibraryResponse.class); } @Override - public LoomClientRequest createLibrary(LibraryCreateRequest request) { + public LoomClientHttpRequest createLibrary(LibraryCreateRequest request) { return postRequest("libraries", request, LibraryResponse.class); } // ANNOTATION @Override - public LoomClientRequest loadAnnotation(UUID annotationUuid) { + public LoomClientHttpRequest loadAnnotation(UUID annotationUuid) { return getRequest("annotations/" + annotationUuid, AnnotationResponse.class); } @Override - public LoomClientRequest deleteAnnotation(UUID annotationUuid) { + public LoomClientHttpRequest deleteAnnotation(UUID annotationUuid) { return deleteRequest("annotations/" + annotationUuid); } @Override - public LoomClientRequest updateAnnotation(UUID annotationUuid, AnnotationUpdateRequest request) { + public LoomClientHttpRequest updateAnnotation(UUID annotationUuid, AnnotationUpdateRequest request) { return postRequest("annotations/" + annotationUuid, request, AnnotationResponse.class); } @Override - public LoomClientRequest createAnnotation(AnnotationCreateRequest request) { + public LoomClientHttpRequest createAnnotation(AnnotationCreateRequest request) { return postRequest("annotations", request, AnnotationResponse.class); } @Override - public LoomClientRequest listAnnotations() { + public LoomClientHttpRequest listAnnotations() { return getRequest("annotations", AnnotationListResponse.class); } // COLLECTION @Override - public LoomClientRequest loadCollection(UUID collectionUuid) { + public LoomClientHttpRequest loadCollection(UUID collectionUuid) { return getRequest("collections/" + collectionUuid, CollectionResponse.class); } @Override - public LoomClientRequest createCollection(CollectionCreateRequest request) { + public LoomClientHttpRequest createCollection(CollectionCreateRequest request) { return postRequest("collections", request, CollectionResponse.class); } @Override - public LoomClientRequest updateCollection(UUID collectionUuid, CollectionUpdateRequest request) { + public LoomClientHttpRequest updateCollection(UUID collectionUuid, CollectionUpdateRequest request) { return postRequest("collections/" + collectionUuid, request, CollectionResponse.class); } @Override - public LoomClientRequest listCollections() { + public LoomClientHttpRequest listCollections() { return getRequest("collections", CollectionListResponse.class); } @Override - public LoomClientRequest deleteCollection(UUID collectionUuid) { + public LoomClientHttpRequest deleteCollection(UUID collectionUuid) { return deleteRequest("collections/" + collectionUuid); } // TASK REACTION - public LoomClientRequest loadTaskReaction(UUID taskUuid, UUID reactionUuid) { + public LoomClientHttpRequest loadTaskReaction(UUID taskUuid, UUID reactionUuid) { return getRequest("tasks/" + taskUuid + "/reactions/" + reactionUuid, ReactionResponse.class); } - public LoomClientRequest createTaskReaction(UUID taskUuid, ReactionCreateRequest request) { + public LoomClientHttpRequest createTaskReaction(UUID taskUuid, ReactionCreateRequest request) { return postRequest("tasks/" + taskUuid + "/reactions", request, ReactionResponse.class); } - public LoomClientRequest updateTaskReaction(UUID taskUuid, UUID reactionUuid, ReactionUpdateRequest request) { + public LoomClientHttpRequest updateTaskReaction(UUID taskUuid, UUID reactionUuid, ReactionUpdateRequest request) { return postRequest("tasks/" + taskUuid + "/reactions/" + reactionUuid, request, ReactionResponse.class); } - public LoomClientRequest listTaskReaction(UUID taskUuid) { + public LoomClientHttpRequest listTaskReaction(UUID taskUuid) { return getRequest("tasks/" + taskUuid + "/reactions", ReactionListResponse.class); } - public LoomClientRequest deleteTaskReaction(UUID taskUuid, UUID reactionUuid) { + public LoomClientHttpRequest deleteTaskReaction(UUID taskUuid, UUID reactionUuid) { return deleteRequest("tasks/" + taskUuid + "/reactions/" + reactionUuid); } // ASSET REACTION - public LoomClientRequest loadAssetReaction(AssetId assetId, UUID reactionUuid) { + public LoomClientHttpRequest loadAssetReaction(AssetId assetId, UUID reactionUuid) { return getRequest("assets/" + assetId + "/reactions/" + reactionUuid, ReactionResponse.class); } - public LoomClientRequest createAssetReaction(AssetId assetId, ReactionCreateRequest request) { + public LoomClientHttpRequest createAssetReaction(AssetId assetId, ReactionCreateRequest request) { return postRequest("assets/" + assetId + "/reactions", request, ReactionResponse.class); } - public LoomClientRequest updateAssetReaction(AssetId assetId, UUID reactionUuid, ReactionUpdateRequest request) { + public LoomClientHttpRequest updateAssetReaction(AssetId assetId, UUID reactionUuid, ReactionUpdateRequest request) { return postRequest("assets/" + assetId + "/reactions/" + reactionUuid, request, ReactionResponse.class); } - public LoomClientRequest listAssetReaction(AssetId assetId) { + public LoomClientHttpRequest listAssetReaction(AssetId assetId) { return getRequest("assets/" + assetId + "/reactions", ReactionListResponse.class); } - public LoomClientRequest deleteAssetReaction(AssetId assetId, UUID reactionUuid) { + public LoomClientHttpRequest deleteAssetReaction(AssetId assetId, UUID reactionUuid) { return deleteRequest("assets/" + assetId + "/reactions/" + reactionUuid); } // COMMENT REACTION - public LoomClientRequest loadCommentReaction(UUID commentUuid, UUID reactionUuid) { + public LoomClientHttpRequest loadCommentReaction(UUID commentUuid, UUID reactionUuid) { return getRequest("comments/" + commentUuid + "/reactions/" + reactionUuid, ReactionResponse.class); } - public LoomClientRequest createCommentReaction(UUID commentUuid, ReactionCreateRequest request) { + public LoomClientHttpRequest createCommentReaction(UUID commentUuid, ReactionCreateRequest request) { return postRequest("comments/" + commentUuid + "/reactions", request, ReactionResponse.class); } - public LoomClientRequest updateCommentReaction(UUID commentUuid, UUID reactionUuid, ReactionUpdateRequest request) { + public LoomClientHttpRequest updateCommentReaction(UUID commentUuid, UUID reactionUuid, ReactionUpdateRequest request) { return postRequest("comments/" + commentUuid + "/reactions/" + reactionUuid, request, ReactionResponse.class); } - public LoomClientRequest listCommentReaction(UUID commentUuid) { + public LoomClientHttpRequest listCommentReaction(UUID commentUuid) { return getRequest("comments/" + commentUuid + "/reactions", ReactionListResponse.class); } - public LoomClientRequest deleteCommentReaction(UUID commentUuid, UUID reactionUuid) { + public LoomClientHttpRequest deleteCommentReaction(UUID commentUuid, UUID reactionUuid) { return deleteRequest("comments/" + commentUuid + "/reactions/" + reactionUuid); } // EMBEDDING @Override - public LoomClientRequest loadEmbedding(UUID embeddingUuid) { + public LoomClientHttpRequest loadEmbedding(UUID embeddingUuid) { return getRequest("embeddings/" + embeddingUuid, EmbeddingResponse.class); } @Override - public LoomClientRequest deleteEmbedding(UUID embeddingUuid) { + public LoomClientHttpRequest deleteEmbedding(UUID embeddingUuid) { return deleteRequest("embeddings/" + embeddingUuid); } @Override - public LoomClientRequest listEmbeddings() { + public LoomClientHttpRequest listEmbeddings() { return getRequest("embeddings", EmbeddingListResponse.class); } @Override - public LoomClientRequest updateEmbedding(UUID embeddingUuid, EmbeddingUpdateRequest request) { + public LoomClientHttpRequest updateEmbedding(UUID embeddingUuid, EmbeddingUpdateRequest request) { return postRequest("embeddings/" + embeddingUuid, request, EmbeddingResponse.class); } @Override - public LoomClientRequest createEmbedding(EmbeddingCreateRequest request) { + public LoomClientHttpRequest createEmbedding(EmbeddingCreateRequest request) { return postRequest("embeddings", request, EmbeddingResponse.class); } // GROUP @Override - public LoomClientRequest loadGroup(UUID groupUuid) { + public LoomClientHttpRequest loadGroup(UUID groupUuid) { return getRequest("groups/" + groupUuid, GroupResponse.class); } @Override - public LoomClientRequest listGroups() { + public LoomClientHttpRequest listGroups() { return getRequest("groups", GroupListResponse.class); } @Override - public LoomClientRequest deleteGroup(UUID groupUuid) { + public LoomClientHttpRequest deleteGroup(UUID groupUuid) { return deleteRequest("groups/" + groupUuid); } @Override - public LoomClientRequest updateGroup(UUID uuid, GroupUpdateRequest request) { + public LoomClientHttpRequest updateGroup(UUID uuid, GroupUpdateRequest request) { return postRequest("groups/" + uuid, request, GroupResponse.class); } @Override - public LoomClientRequest createGroup(GroupCreateRequest request) { + public LoomClientHttpRequest createGroup(GroupCreateRequest request) { return postRequest("groups", request, GroupResponse.class); } // COMMENT @Override - public LoomClientRequest listCommentsForAnnotation(UUID annotationUuid) { + public LoomClientHttpRequest listCommentsForAnnotation(UUID annotationUuid) { return getRequest("annotation/" + annotationUuid + "/comments", CommentListResponse.class); } @Override - public LoomClientRequest loadComment(UUID uuid) { + public LoomClientHttpRequest loadComment(UUID uuid) { return getRequest("comments/" + uuid, CommentResponse.class); } @Override - public LoomClientRequest deleteComment(UUID uuid) { + public LoomClientHttpRequest deleteComment(UUID uuid) { return deleteRequest("comments/" + uuid); } @Override - public LoomClientRequest updateComment(UUID uuid, CommentUpdateRequest request) { + public LoomClientHttpRequest updateComment(UUID uuid, CommentUpdateRequest request) { return postRequest("comments/" + uuid, request, CommentResponse.class); } @Override - public LoomClientRequest createComment(CommentCreateRequest request) { + public LoomClientHttpRequest createComment(CommentCreateRequest request) { return postRequest("comments", request, CommentResponse.class); } // ROLE @Override - public LoomClientRequest loadRole(UUID uuid) { + public LoomClientHttpRequest loadRole(UUID uuid) { return getRequest("roles/" + uuid, RoleResponse.class); } @Override - public LoomClientRequest deleteRole(UUID uuid) { + public LoomClientHttpRequest deleteRole(UUID uuid) { return deleteRequest("roles/" + uuid); } @Override - public LoomClientRequest updateRole(UUID uuid, RoleUpdateRequest request) { + public LoomClientHttpRequest updateRole(UUID uuid, RoleUpdateRequest request) { return postRequest("roles/" + uuid, request, RoleResponse.class); } @Override - public LoomClientRequest createRole(RoleCreateRequest request) { + public LoomClientHttpRequest createRole(RoleCreateRequest request) { return postRequest("roles", request, RoleResponse.class); } @Override - public LoomClientRequest listRoles() { + public LoomClientHttpRequest listRoles() { return getRequest("roles", RoleListResponse.class); } // TASK @Override - public LoomClientRequest loadTask(UUID uuid) { + public LoomClientHttpRequest loadTask(UUID uuid) { return getRequest("tasks/" + uuid, TaskResponse.class); } @Override - public LoomClientRequest deleteTask(UUID uuid) { + public LoomClientHttpRequest deleteTask(UUID uuid) { return deleteRequest("tasks/" + uuid); } @Override - public LoomClientRequest listTasks() { + public LoomClientHttpRequest listTasks() { return getRequest("tasks", TaskListResponse.class); } @Override - public LoomClientRequest updateTask(UUID uuid, TaskUpdateRequest request) { + public LoomClientHttpRequest updateTask(UUID uuid, TaskUpdateRequest request) { return postRequest("tasks/" + uuid, request, TaskResponse.class); } @Override - public LoomClientRequest createTask(TaskCreateRequest request) { + public LoomClientHttpRequest createTask(TaskCreateRequest request) { return postRequest("tasks", request, TaskResponse.class); } // ATTACHMENT @Override - public LoomClientRequest uploadAttachment(String filename, String mimeType, InputStream fileData) { + public LoomClientHttpRequest uploadAttachment(String filename, String mimeType, InputStream fileData) { Objects.requireNonNull(filename, "filename must not be null"); Objects.requireNonNull(fileData, "fileData must not be null"); Objects.requireNonNull(mimeType, "mimeType must not be null"); @@ -737,81 +737,81 @@ public LoomClientRequest uploadAttachment(String filename, S } @Override - public LoomClientRequest listAttachments() { + public LoomClientHttpRequest listAttachments() { return getRequest("/attachments", AttachmentListResponse.class); } @Override - public LoomClientRequest deleteAttachment(UUID uuid) { + public LoomClientHttpRequest deleteAttachment(UUID uuid) { return deleteRequest("/attachments/" + uuid); } @Override - public LoomClientRequest loadAttachment(UUID uuid) { + public LoomClientHttpRequest loadAttachment(UUID uuid) { return getRequest("/attachments/" + uuid, AttachmentResponse.class); } @Override - public LoomClientRequest downloadAttachment(UUID uuid) { + public LoomClientHttpRequest downloadAttachment(UUID uuid) { return getDownloadRequest("/attachments/" + uuid); } @Override - public LoomClientRequest updateAttachment(UUID uuid, AttachmentUpdateRequest request) { + public LoomClientHttpRequest updateAttachment(UUID uuid, AttachmentUpdateRequest request) { return postRequest("/attachments/" + uuid, request, AttachmentResponse.class); } // TAG @Override - public LoomClientRequest loadTag(UUID uuid) { + public LoomClientHttpRequest loadTag(UUID uuid) { return getRequest("/tags/" + uuid, TagResponse.class); } @Override - public LoomClientRequest deleteTag(UUID uuid) { + public LoomClientHttpRequest deleteTag(UUID uuid) { return deleteRequest("/tags/" + uuid); } @Override - public LoomClientRequest listTags() { + public LoomClientHttpRequest listTags() { return getRequest("/tags", TagListResponse.class); } @Override - public LoomClientRequest updateTag(UUID uuid, TagUpdateRequest request) { + public LoomClientHttpRequest updateTag(UUID uuid, TagUpdateRequest request) { return postRequest("/tags/" + uuid, request, TagResponse.class); } @Override - public LoomClientRequest createTag(TagCreateRequest request) { + public LoomClientHttpRequest createTag(TagCreateRequest request) { return postRequest("/tags", request, TagResponse.class); } // TOKEN @Override - public LoomClientRequest loadToken(UUID uuid) { + public LoomClientHttpRequest loadToken(UUID uuid) { return getRequest("/tokens/" + uuid, TokenResponse.class); } @Override - public LoomClientRequest listTokens() { + public LoomClientHttpRequest listTokens() { return getRequest("/tokens", TokenListResponse.class); } @Override - public LoomClientRequest updateToken(UUID uuid, TokenUpdateRequest request) { + public LoomClientHttpRequest updateToken(UUID uuid, TokenUpdateRequest request) { return postRequest("/tokens/" + uuid, request, TokenResponse.class); } @Override - public LoomClientRequest createToken(TokenCreateRequest request) { + public LoomClientHttpRequest createToken(TokenCreateRequest request) { return postRequest("/tokens", request, TokenResponse.class); } @Override - public LoomClientRequest deleteToken(UUID uuid) { + public LoomClientHttpRequest deleteToken(UUID uuid) { return deleteRequest("/tokens/" + uuid); } diff --git a/rest/src/main/java/io/metaloom/loom/client/http/parameter/HttpQueryParameters.java b/rest/src/main/java/io/metaloom/loom/client/http/parameter/HttpQueryParameters.java new file mode 100644 index 0000000..4ebeb81 --- /dev/null +++ b/rest/src/main/java/io/metaloom/loom/client/http/parameter/HttpQueryParameters.java @@ -0,0 +1,62 @@ +package io.metaloom.loom.client.http.parameter; + +import java.time.Duration; +import java.util.UUID; + +import io.metaloom.filter.Filter; +import io.metaloom.filter.key.impl.DurationFilterKey; +import io.metaloom.filter.key.impl.SizeFilterKey; +import io.metaloom.filter.key.impl.StringFilterKey; +import io.metaloom.loom.api.sort.SortDirection; +import io.metaloom.loom.api.sort.SortKey; +import io.metaloom.loom.client.common.QueryParameters; +import io.metaloom.loom.client.http.LoomClientHttpRequest; +import io.metaloom.loom.rest.model.RestResponseModel; +import io.metaloom.loom.rest.parameter.QueryParameterKey; + +public interface HttpQueryParameters> extends QueryParameters{ + + /** + * Add an additional query parameter. + * + * @param key + * @param value + * @return Fluent API + */ + LoomClientHttpRequest addQueryParameter(String key, String value); + + default LoomClientHttpRequest addLimit(Integer limit) { + return addQueryParameter(QueryParameterKey.LIMIT.key(), String.valueOf(limit)); + } + + default LoomClientHttpRequest addFrom(UUID startUuid) { + return addQueryParameter(QueryParameterKey.FROM.key(), startUuid.toString()); + } + + default LoomClientHttpRequest addFilter(Filter filter) { + return addQueryParameter(QueryParameterKey.FILTER.key(), filter.toString()); + } + + default LoomClientHttpRequest sortBy(SortKey key) { + return addQueryParameter(QueryParameterKey.SORT.key(), key.toString()); + } + + default LoomClientHttpRequest sortDirection(SortDirection direction) { + return addQueryParameter(QueryParameterKey.DIRECTION.key(), direction.toString()); + } + + default LoomClientHttpRequest addEquals(SizeFilterKey key, String value) { + return addQueryParameter(QueryParameterKey.FILTER.key(), key.eq(value).toString()); + } + + default LoomClientHttpRequest addEquals(DurationFilterKey key, Duration duration) { + return addQueryParameter(QueryParameterKey.FILTER.key(), key.eq(duration).toString()); + } + + default LoomClientHttpRequest addEquals(StringFilterKey key, String value) { + return addQueryParameter(QueryParameterKey.FILTER.key(), key.eq(value).toString()); + } + + LoomClientHttpRequest self(); + +} \ No newline at end of file diff --git a/rest/src/test/java/io/metaloom/loom/client/http/AbstractHTTPClientTest.java b/rest/src/test/java/io/metaloom/loom/client/http/AbstractHTTPClientTest.java index d59d9fe..be080f7 100644 --- a/rest/src/test/java/io/metaloom/loom/client/http/AbstractHTTPClientTest.java +++ b/rest/src/test/java/io/metaloom/loom/client/http/AbstractHTTPClientTest.java @@ -5,7 +5,8 @@ import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; -import io.metaloom.loom.client.http.impl.HttpErrorException; +import io.metaloom.loom.client.common.LoomClientException; +import io.metaloom.loom.client.http.error.LoomHttpClientException; import io.metaloom.loom.rest.model.RestResponseModel; import io.metaloom.loom.rest.model.common.AbstractResponse; import io.metaloom.loom.rest.model.message.GenericMessageResponse; @@ -41,23 +42,27 @@ protected String json(String key, String name) { } protected void assertSuccess(RestResponseModel response) { - //assertTrue("The response should be successful.", response.getResult()); + // assertTrue("The response should be successful.", response.getResult()); fail("Not impl"); } protected void assertSuccess(AbstractResponse response) { - //assertEquals("ok", response.getStatus(), "The response should be successful."); + // assertEquals("ok", response.getStatus(), "The response should be successful."); fail("Not impl"); } - protected > T invoke(LoomClientRequest request) throws HttpErrorException { + protected > T invoke(LoomClientHttpRequest request) throws LoomClientException { try { T response = request.sync(); assertSuccess((AbstractResponse) response); return response; - } catch (HttpErrorException e) { - GenericMessageResponse error = e.getResponse(); - fail("Request failed with error " + error.getMessage()); + } catch (LoomClientException e) { + if (e instanceof LoomHttpClientException le) { + GenericMessageResponse error = le.getResponse(); + fail("Request failed with error " + error.getMessage()); + } else { + fail("Request failed with error " + e.getMessage()); + } return null; } } diff --git a/rest/src/test/java/io/metaloom/loom/client/http/BasicUsageExampleTest.java b/rest/src/test/java/io/metaloom/loom/client/http/BasicUsageExampleTest.java index e11d1ce..cee1f4f 100644 --- a/rest/src/test/java/io/metaloom/loom/client/http/BasicUsageExampleTest.java +++ b/rest/src/test/java/io/metaloom/loom/client/http/BasicUsageExampleTest.java @@ -4,6 +4,7 @@ import org.junit.jupiter.api.Test; +import io.metaloom.loom.client.common.LoomClient; import io.metaloom.loom.rest.model.user.UserResponse; public class BasicUsageExampleTest extends AbstractContainerTest { @@ -14,7 +15,7 @@ public void testExample() throws Exception { int port = loom.httpPort(); String host = loom.getHost(); - try (LoomHttpClient client = LoomHttpClient.builder() + try (LoomClient client = LoomHttpClient.builder() .setHostname(host) .setPort(port) .build()) {