-
Notifications
You must be signed in to change notification settings - Fork 26
feat: Support collection aliases #409
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
Show all changes
8 commits
Select commit
Hold shift + click to select a range
3f718cb
feat: add aliases namespace to sync client
bevzzz db5902e
feat: add aliases namespace to async client
bevzzz 20fece7
test: add integration tests for alias management
bevzzz 0098862
feat: add AliasesPermission to RBAC
bevzzz 165058f
chore: rename Permission.alias -> Permission.aliases
bevzzz 8783c8b
test: fix expected action value
bevzzz 3861e7e
chore: implement review feedback
bevzzz 70733c7
fix: typo in tests
bevzzz 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
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,39 @@ | ||
| package io.weaviate.client.v1.aliases; | ||
|
|
||
| import io.weaviate.client.Config; | ||
| import io.weaviate.client.base.http.HttpClient; | ||
| import io.weaviate.client.v1.aliases.api.AliasAllGetter; | ||
| import io.weaviate.client.v1.aliases.api.AliasCreator; | ||
| import io.weaviate.client.v1.aliases.api.AliasDeleter; | ||
| import io.weaviate.client.v1.aliases.api.AliasGetter; | ||
| import io.weaviate.client.v1.aliases.api.AliasUpdater; | ||
|
|
||
| public class Aliases { | ||
| private final Config config; | ||
| private final HttpClient httpClient; | ||
|
|
||
| public Aliases(HttpClient httpClient, Config config) { | ||
| this.config = config; | ||
| this.httpClient = httpClient; | ||
| } | ||
|
|
||
| public AliasCreator creator() { | ||
| return new AliasCreator(httpClient, config); | ||
| } | ||
|
|
||
| public AliasGetter getter() { | ||
| return new AliasGetter(httpClient, config); | ||
| } | ||
|
|
||
| public AliasAllGetter allGetter() { | ||
| return new AliasAllGetter(httpClient, config); | ||
| } | ||
|
|
||
| public AliasDeleter deleter() { | ||
| return new AliasDeleter(httpClient, config); | ||
| } | ||
|
|
||
| public AliasUpdater updater() { | ||
| return new AliasUpdater(httpClient, config); | ||
| } | ||
| } |
45 changes: 45 additions & 0 deletions
45
src/main/java/io/weaviate/client/v1/aliases/api/AliasAllGetter.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,45 @@ | ||
| package io.weaviate.client.v1.aliases.api; | ||
|
|
||
| import java.util.List; | ||
| import java.util.Map; | ||
| import java.util.function.Function; | ||
| import java.util.stream.Collectors; | ||
|
|
||
| import io.weaviate.client.Config; | ||
| import io.weaviate.client.base.BaseClient; | ||
| import io.weaviate.client.base.ClientResult; | ||
| import io.weaviate.client.base.Response; | ||
| import io.weaviate.client.base.Result; | ||
| import io.weaviate.client.base.http.HttpClient; | ||
| import io.weaviate.client.v1.aliases.api.AliasAllGetter.ResponseBody; | ||
| import io.weaviate.client.v1.aliases.model.Alias; | ||
|
|
||
| public class AliasAllGetter extends BaseClient<ResponseBody> implements ClientResult<Map<String, Alias>> { | ||
| private String className; | ||
|
|
||
| public AliasAllGetter(HttpClient httpClient, Config config) { | ||
| super(httpClient, config); | ||
| } | ||
|
|
||
| /** List aliases defined for this class. */ | ||
| public AliasAllGetter withClassName(String className) { | ||
| this.className = className; | ||
| return this; | ||
| } | ||
|
|
||
| static class ResponseBody { | ||
| List<Alias> aliases; | ||
| } | ||
|
|
||
| @Override | ||
| public Result<Map<String, Alias>> run() { | ||
| String path = "/aliases" + (className != null ? "?class=" + className : ""); | ||
| Response<ResponseBody> resp = sendGetRequest(path, ResponseBody.class); | ||
| if (resp.getErrors() != null) { | ||
| return new Result<>(resp, null); | ||
| } | ||
| Map<String, Alias> aliases = resp.getBody().aliases.stream() | ||
| .collect(Collectors.toMap(Alias::getAlias, Function.identity())); | ||
| return new Result<>(resp, aliases); | ||
| } | ||
| } | ||
34 changes: 34 additions & 0 deletions
34
src/main/java/io/weaviate/client/v1/aliases/api/AliasCreator.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,34 @@ | ||
| package io.weaviate.client.v1.aliases.api; | ||
|
|
||
| import io.weaviate.client.Config; | ||
| import io.weaviate.client.base.BaseClient; | ||
| import io.weaviate.client.base.ClientResult; | ||
| import io.weaviate.client.base.Response; | ||
| import io.weaviate.client.base.Result; | ||
| import io.weaviate.client.base.http.HttpClient; | ||
| import io.weaviate.client.v1.aliases.model.Alias; | ||
|
|
||
| public class AliasCreator extends BaseClient<Void> implements ClientResult<Boolean> { | ||
| private String className; | ||
| private String alias; | ||
|
|
||
| public AliasCreator(HttpClient httpClient, Config config) { | ||
| super(httpClient, config); | ||
| } | ||
|
|
||
| public AliasCreator withClassName(String className) { | ||
| this.className = className; | ||
| return this; | ||
| } | ||
|
|
||
| public AliasCreator withAlias(String alias) { | ||
| this.alias = alias; | ||
| return this; | ||
| } | ||
|
|
||
| @Override | ||
| public Result<Boolean> run() { | ||
| Response<Void> resp = sendPostRequest("/aliases", new Alias(className, alias), Void.class); | ||
| return Result.voidToBoolean(resp); | ||
| } | ||
| } |
27 changes: 27 additions & 0 deletions
27
src/main/java/io/weaviate/client/v1/aliases/api/AliasDeleter.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,27 @@ | ||
| package io.weaviate.client.v1.aliases.api; | ||
|
|
||
| import io.weaviate.client.Config; | ||
| import io.weaviate.client.base.BaseClient; | ||
| import io.weaviate.client.base.ClientResult; | ||
| import io.weaviate.client.base.Response; | ||
| import io.weaviate.client.base.Result; | ||
| import io.weaviate.client.base.http.HttpClient; | ||
|
|
||
| public class AliasDeleter extends BaseClient<Void> implements ClientResult<Boolean> { | ||
| private String alias; | ||
|
|
||
| public AliasDeleter(HttpClient httpClient, Config config) { | ||
| super(httpClient, config); | ||
| } | ||
|
|
||
| public AliasDeleter withAlias(String alias) { | ||
| this.alias = alias; | ||
| return this; | ||
| } | ||
|
|
||
| @Override | ||
| public Result<Boolean> run() { | ||
| Response<Void> resp = sendDeleteRequest("/aliases/" + alias, null, Void.class); | ||
| return Result.voidToBoolean(resp); | ||
| } | ||
| } |
26 changes: 26 additions & 0 deletions
26
src/main/java/io/weaviate/client/v1/aliases/api/AliasGetter.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,26 @@ | ||
| package io.weaviate.client.v1.aliases.api; | ||
|
|
||
| import io.weaviate.client.Config; | ||
| import io.weaviate.client.base.BaseClient; | ||
| import io.weaviate.client.base.ClientResult; | ||
| import io.weaviate.client.base.Result; | ||
| import io.weaviate.client.base.http.HttpClient; | ||
| import io.weaviate.client.v1.aliases.model.Alias; | ||
|
|
||
| public class AliasGetter extends BaseClient<Alias> implements ClientResult<Alias> { | ||
| private String alias; | ||
|
|
||
| public AliasGetter(HttpClient httpClient, Config config) { | ||
| super(httpClient, config); | ||
| } | ||
|
|
||
| public AliasGetter withAlias(String alias) { | ||
| this.alias = alias; | ||
| return this; | ||
| } | ||
|
|
||
| @Override | ||
| public Result<Alias> run() { | ||
| return new Result<>(sendGetRequest("/aliases/" + alias, Alias.class)); | ||
| } | ||
| } |
40 changes: 40 additions & 0 deletions
40
src/main/java/io/weaviate/client/v1/aliases/api/AliasUpdater.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,40 @@ | ||
| package io.weaviate.client.v1.aliases.api; | ||
|
|
||
| import com.google.gson.annotations.SerializedName; | ||
|
|
||
| import io.weaviate.client.Config; | ||
| import io.weaviate.client.base.BaseClient; | ||
| import io.weaviate.client.base.ClientResult; | ||
| import io.weaviate.client.base.Response; | ||
| import io.weaviate.client.base.Result; | ||
| import io.weaviate.client.base.http.HttpClient; | ||
|
|
||
| public class AliasUpdater extends BaseClient<Void> implements ClientResult<Boolean> { | ||
| private String className; | ||
| private String alias; | ||
|
|
||
| public AliasUpdater(HttpClient httpClient, Config config) { | ||
| super(httpClient, config); | ||
| } | ||
|
|
||
| public AliasUpdater withAlias(String alias) { | ||
| this.alias = alias; | ||
| return this; | ||
| } | ||
|
|
||
| public AliasUpdater withNewClassName(String className) { | ||
| this.className = className; | ||
| return this; | ||
| } | ||
|
|
||
| class Body { | ||
| @SerializedName("class") | ||
| String className = AliasUpdater.this.className; | ||
| } | ||
|
|
||
| @Override | ||
| public Result<Boolean> run() { | ||
| Response<Void> resp = sendPutRequest("/aliases/" + alias, new Body(), Void.class); | ||
| return Result.voidToBoolean(resp); | ||
| } | ||
| } |
17 changes: 17 additions & 0 deletions
17
src/main/java/io/weaviate/client/v1/aliases/model/Alias.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,17 @@ | ||
| package io.weaviate.client.v1.aliases.model; | ||
|
|
||
| import com.google.gson.annotations.SerializedName; | ||
|
|
||
| import lombok.EqualsAndHashCode; | ||
| import lombok.Getter; | ||
| import lombok.RequiredArgsConstructor; | ||
|
|
||
| @Getter | ||
| @RequiredArgsConstructor | ||
| @EqualsAndHashCode | ||
| public class Alias { | ||
| @SerializedName("class") | ||
| private final String className; | ||
| @SerializedName("alias") | ||
| private final String alias; | ||
| } |
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
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.