From 23576bbbe1557de977243d0267fa5e4f0ee60058 Mon Sep 17 00:00:00 2001 From: Jai2305 Date: Wed, 21 Aug 2024 13:18:44 +0530 Subject: [PATCH] Added test cases and withJson for important request classes Signed-off-by: Jai2305 --- .../client/json/PlainDeserializable.java | 5 +- .../cluster/AllocationExplainRequest.java | 14 +- .../cluster/PutClusterSettingsRequest.java | 18 +- .../cluster/PutComponentTemplateRequest.java | 18 +- .../opensearch/cluster/RerouteRequest.java | 14 +- .../opensearch/core/ClearScrollRequest.java | 14 +- .../opensearch/core/DeleteByQueryRequest.java | 23 +-- .../opensearch/core/ExplainRequest.java | 14 +- .../opensearch/core/PutScriptRequest.java | 14 +- .../opensearch/core/ReindexRequest.java | 21 +-- .../core/RenderSearchTemplateRequest.java | 18 +- .../opensearch/core/UpdateByQueryRequest.java | 24 +-- .../opensearch/indices/CloneIndexRequest.java | 15 +- .../indices/PutTemplateRequest.java | 15 +- .../indices/UpdateAliasesRequest.java | 14 +- .../nodes/ReloadSecureSettingsRequest.java | 17 +- .../snapshot/CreateSnapshotRequest.java | 15 +- .../json/PlainDeserializableTest.java | 168 +++++++++++++++++- 18 files changed, 293 insertions(+), 148 deletions(-) diff --git a/java-client/src/main/java/org/opensearch/client/json/PlainDeserializable.java b/java-client/src/main/java/org/opensearch/client/json/PlainDeserializable.java index 29aff9703c..f5d5a444f4 100644 --- a/java-client/src/main/java/org/opensearch/client/json/PlainDeserializable.java +++ b/java-client/src/main/java/org/opensearch/client/json/PlainDeserializable.java @@ -21,7 +21,7 @@ public interface PlainDeserializable { /** Updates object with newly provided JSON properties @param parser the JsonParser parser @param mapper the JsonpMapper mapper used to deserialize values - @return object + @return this object **/ default B withJson(JsonParser parser, JsonpMapper mapper) { @@ -38,7 +38,8 @@ default B withJson(JsonParser parser, JsonpMapper mapper) { * **/ default B withJson(InputStream inputStream) { JsonpMapper defaultMapper = JsonpUtils.DEFAULT_JSONP_MAPPER; - return withJson(defaultMapper.jsonProvider().createParser(inputStream), defaultMapper); + JsonParser parser = defaultMapper.jsonProvider().createParser(inputStream); + return withJson(parser, defaultMapper); } /** Updates object with newly provided JSON properties diff --git a/java-client/src/main/java/org/opensearch/client/opensearch/cluster/AllocationExplainRequest.java b/java-client/src/main/java/org/opensearch/client/opensearch/cluster/AllocationExplainRequest.java index 9e711de486..de9606a059 100644 --- a/java-client/src/main/java/org/opensearch/client/opensearch/cluster/AllocationExplainRequest.java +++ b/java-client/src/main/java/org/opensearch/client/opensearch/cluster/AllocationExplainRequest.java @@ -37,12 +37,7 @@ import java.util.Map; import java.util.function.Function; import javax.annotation.Nullable; -import org.opensearch.client.json.JsonpDeserializable; -import org.opensearch.client.json.JsonpDeserializer; -import org.opensearch.client.json.JsonpMapper; -import org.opensearch.client.json.ObjectBuilderDeserializer; -import org.opensearch.client.json.ObjectDeserializer; -import org.opensearch.client.json.PlainJsonSerializable; +import org.opensearch.client.json.*; import org.opensearch.client.opensearch._types.ErrorResponse; import org.opensearch.client.opensearch._types.RequestBase; import org.opensearch.client.transport.Endpoint; @@ -194,7 +189,7 @@ protected void serializeInternal(JsonGenerator generator, JsonpMapper mapper) { * Builder for {@link AllocationExplainRequest}. */ - public static class Builder extends ObjectBuilderBase implements ObjectBuilder { + public static class Builder extends ObjectBuilderBase implements ObjectBuilder, PlainDeserializable { @Nullable private String currentNode; @@ -285,6 +280,11 @@ public AllocationExplainRequest build() { return new AllocationExplainRequest(this); } + + @Override + public Builder get() { + return this; + } } // --------------------------------------------------------------------------------------------- diff --git a/java-client/src/main/java/org/opensearch/client/opensearch/cluster/PutClusterSettingsRequest.java b/java-client/src/main/java/org/opensearch/client/opensearch/cluster/PutClusterSettingsRequest.java index 54583b5631..ccd529ba2d 100644 --- a/java-client/src/main/java/org/opensearch/client/opensearch/cluster/PutClusterSettingsRequest.java +++ b/java-client/src/main/java/org/opensearch/client/opensearch/cluster/PutClusterSettingsRequest.java @@ -37,13 +37,7 @@ import java.util.Map; import java.util.function.Function; import javax.annotation.Nullable; -import org.opensearch.client.json.JsonData; -import org.opensearch.client.json.JsonpDeserializable; -import org.opensearch.client.json.JsonpDeserializer; -import org.opensearch.client.json.JsonpMapper; -import org.opensearch.client.json.ObjectBuilderDeserializer; -import org.opensearch.client.json.ObjectDeserializer; -import org.opensearch.client.json.PlainJsonSerializable; +import org.opensearch.client.json.*; import org.opensearch.client.opensearch._types.ErrorResponse; import org.opensearch.client.opensearch._types.RequestBase; import org.opensearch.client.opensearch._types.Time; @@ -192,7 +186,10 @@ protected void serializeInternal(JsonGenerator generator, JsonpMapper mapper) { * Builder for {@link PutClusterSettingsRequest}. */ - public static class Builder extends ObjectBuilderBase implements ObjectBuilder { + public static class Builder extends ObjectBuilderBase + implements + ObjectBuilder, + PlainDeserializable { @Nullable private Boolean flatSettings; @@ -330,6 +327,11 @@ public PutClusterSettingsRequest build() { return new PutClusterSettingsRequest(this); } + + @Override + public Builder get() { + return this; + } } // --------------------------------------------------------------------------------------------- diff --git a/java-client/src/main/java/org/opensearch/client/opensearch/cluster/PutComponentTemplateRequest.java b/java-client/src/main/java/org/opensearch/client/opensearch/cluster/PutComponentTemplateRequest.java index 4e336f9fff..0cd1f10c66 100644 --- a/java-client/src/main/java/org/opensearch/client/opensearch/cluster/PutComponentTemplateRequest.java +++ b/java-client/src/main/java/org/opensearch/client/opensearch/cluster/PutComponentTemplateRequest.java @@ -37,13 +37,7 @@ import java.util.Map; import java.util.function.Function; import javax.annotation.Nullable; -import org.opensearch.client.json.JsonData; -import org.opensearch.client.json.JsonpDeserializable; -import org.opensearch.client.json.JsonpDeserializer; -import org.opensearch.client.json.JsonpMapper; -import org.opensearch.client.json.ObjectBuilderDeserializer; -import org.opensearch.client.json.ObjectDeserializer; -import org.opensearch.client.json.PlainJsonSerializable; +import org.opensearch.client.json.*; import org.opensearch.client.opensearch._types.ErrorResponse; import org.opensearch.client.opensearch._types.RequestBase; import org.opensearch.client.opensearch._types.Time; @@ -259,7 +253,10 @@ protected void serializeInternal(JsonGenerator generator, JsonpMapper mapper) { * Builder for {@link PutComponentTemplateRequest}. */ - public static class Builder extends ObjectBuilderBase implements ObjectBuilder { + public static class Builder extends ObjectBuilderBase + implements + ObjectBuilder, + PlainDeserializable { @Nullable private Map meta; @@ -463,6 +460,11 @@ public PutComponentTemplateRequest build() { return new PutComponentTemplateRequest(this); } + + @Override + public Builder get() { + return this; + } } // --------------------------------------------------------------------------------------------- diff --git a/java-client/src/main/java/org/opensearch/client/opensearch/cluster/RerouteRequest.java b/java-client/src/main/java/org/opensearch/client/opensearch/cluster/RerouteRequest.java index 29891c0aa0..b914a1e5d2 100644 --- a/java-client/src/main/java/org/opensearch/client/opensearch/cluster/RerouteRequest.java +++ b/java-client/src/main/java/org/opensearch/client/opensearch/cluster/RerouteRequest.java @@ -39,12 +39,7 @@ import java.util.function.Function; import java.util.stream.Collectors; import javax.annotation.Nullable; -import org.opensearch.client.json.JsonpDeserializable; -import org.opensearch.client.json.JsonpDeserializer; -import org.opensearch.client.json.JsonpMapper; -import org.opensearch.client.json.ObjectBuilderDeserializer; -import org.opensearch.client.json.ObjectDeserializer; -import org.opensearch.client.json.PlainJsonSerializable; +import org.opensearch.client.json.*; import org.opensearch.client.opensearch._types.ErrorResponse; import org.opensearch.client.opensearch._types.RequestBase; import org.opensearch.client.opensearch._types.Time; @@ -220,7 +215,7 @@ protected void serializeInternal(JsonGenerator generator, JsonpMapper mapper) { * Builder for {@link RerouteRequest}. */ - public static class Builder extends ObjectBuilderBase implements ObjectBuilder { + public static class Builder extends ObjectBuilderBase implements ObjectBuilder, PlainDeserializable { @Nullable private List commands; @@ -414,6 +409,11 @@ public RerouteRequest build() { return new RerouteRequest(this); } + + @Override + public Builder get() { + return this; + } } // --------------------------------------------------------------------------------------------- diff --git a/java-client/src/main/java/org/opensearch/client/opensearch/core/ClearScrollRequest.java b/java-client/src/main/java/org/opensearch/client/opensearch/core/ClearScrollRequest.java index eefdff36a4..a850d5a1ae 100644 --- a/java-client/src/main/java/org/opensearch/client/opensearch/core/ClearScrollRequest.java +++ b/java-client/src/main/java/org/opensearch/client/opensearch/core/ClearScrollRequest.java @@ -37,12 +37,7 @@ import java.util.List; import java.util.function.Function; import javax.annotation.Nullable; -import org.opensearch.client.json.JsonpDeserializable; -import org.opensearch.client.json.JsonpDeserializer; -import org.opensearch.client.json.JsonpMapper; -import org.opensearch.client.json.ObjectBuilderDeserializer; -import org.opensearch.client.json.ObjectDeserializer; -import org.opensearch.client.json.PlainJsonSerializable; +import org.opensearch.client.json.*; import org.opensearch.client.opensearch._types.ErrorResponse; import org.opensearch.client.opensearch._types.RequestBase; import org.opensearch.client.transport.Endpoint; @@ -114,7 +109,7 @@ public Builder toBuilder() { * Builder for {@link ClearScrollRequest}. */ - public static class Builder extends ObjectBuilderBase implements ObjectBuilder { + public static class Builder extends ObjectBuilderBase implements ObjectBuilder, PlainDeserializable { @Nullable private List scrollId; @@ -149,6 +144,11 @@ public ClearScrollRequest build() { return new ClearScrollRequest(this); } + + @Override + public Builder get() { + return this; + } } // --------------------------------------------------------------------------------------------- diff --git a/java-client/src/main/java/org/opensearch/client/opensearch/core/DeleteByQueryRequest.java b/java-client/src/main/java/org/opensearch/client/opensearch/core/DeleteByQueryRequest.java index 5e973dba47..a9872875d6 100644 --- a/java-client/src/main/java/org/opensearch/client/opensearch/core/DeleteByQueryRequest.java +++ b/java-client/src/main/java/org/opensearch/client/opensearch/core/DeleteByQueryRequest.java @@ -39,20 +39,8 @@ import java.util.function.Function; import java.util.stream.Collectors; import javax.annotation.Nullable; -import org.opensearch.client.json.JsonpDeserializable; -import org.opensearch.client.json.JsonpDeserializer; -import org.opensearch.client.json.JsonpMapper; -import org.opensearch.client.json.ObjectBuilderDeserializer; -import org.opensearch.client.json.ObjectDeserializer; -import org.opensearch.client.json.PlainJsonSerializable; -import org.opensearch.client.opensearch._types.Conflicts; -import org.opensearch.client.opensearch._types.ErrorResponse; -import org.opensearch.client.opensearch._types.ExpandWildcard; -import org.opensearch.client.opensearch._types.RequestBase; -import org.opensearch.client.opensearch._types.SearchType; -import org.opensearch.client.opensearch._types.SlicedScroll; -import org.opensearch.client.opensearch._types.Time; -import org.opensearch.client.opensearch._types.WaitForActiveShards; +import org.opensearch.client.json.*; +import org.opensearch.client.opensearch._types.*; import org.opensearch.client.opensearch._types.query_dsl.Operator; import org.opensearch.client.opensearch._types.query_dsl.Query; import org.opensearch.client.opensearch.core.search.SourceConfigParam; @@ -661,7 +649,7 @@ public Builder toBuilder() { * Builder for {@link DeleteByQueryRequest}. */ - public static class Builder extends ObjectBuilderBase implements ObjectBuilder { + public static class Builder extends ObjectBuilderBase implements ObjectBuilder, PlainDeserializable { @Nullable private SourceConfigParam source; @@ -1306,6 +1294,11 @@ public DeleteByQueryRequest build() { return new DeleteByQueryRequest(this); } + + @Override + public Builder get() { + return this; + } } // --------------------------------------------------------------------------------------------- diff --git a/java-client/src/main/java/org/opensearch/client/opensearch/core/ExplainRequest.java b/java-client/src/main/java/org/opensearch/client/opensearch/core/ExplainRequest.java index 43aa098af1..829e1ab9a9 100644 --- a/java-client/src/main/java/org/opensearch/client/opensearch/core/ExplainRequest.java +++ b/java-client/src/main/java/org/opensearch/client/opensearch/core/ExplainRequest.java @@ -39,12 +39,7 @@ import java.util.function.Function; import java.util.stream.Collectors; import javax.annotation.Nullable; -import org.opensearch.client.json.JsonpDeserializable; -import org.opensearch.client.json.JsonpDeserializer; -import org.opensearch.client.json.JsonpMapper; -import org.opensearch.client.json.ObjectBuilderDeserializer; -import org.opensearch.client.json.ObjectDeserializer; -import org.opensearch.client.json.PlainJsonSerializable; +import org.opensearch.client.json.*; import org.opensearch.client.opensearch._types.ErrorResponse; import org.opensearch.client.opensearch._types.RequestBase; import org.opensearch.client.opensearch._types.query_dsl.Operator; @@ -320,7 +315,7 @@ public Builder toBuilder() { * Builder for {@link ExplainRequest}. */ - public static class Builder extends ObjectBuilderBase implements ObjectBuilder { + public static class Builder extends ObjectBuilderBase implements ObjectBuilder, PlainDeserializable { @Nullable private SourceConfigParam source; @@ -586,6 +581,11 @@ public ExplainRequest build() { return new ExplainRequest(this); } + + @Override + public Builder get() { + return this; + } } // --------------------------------------------------------------------------------------------- diff --git a/java-client/src/main/java/org/opensearch/client/opensearch/core/PutScriptRequest.java b/java-client/src/main/java/org/opensearch/client/opensearch/core/PutScriptRequest.java index c6cbcdb6b5..fc859527ad 100644 --- a/java-client/src/main/java/org/opensearch/client/opensearch/core/PutScriptRequest.java +++ b/java-client/src/main/java/org/opensearch/client/opensearch/core/PutScriptRequest.java @@ -37,12 +37,7 @@ import java.util.Map; import java.util.function.Function; import javax.annotation.Nullable; -import org.opensearch.client.json.JsonpDeserializable; -import org.opensearch.client.json.JsonpDeserializer; -import org.opensearch.client.json.JsonpMapper; -import org.opensearch.client.json.ObjectBuilderDeserializer; -import org.opensearch.client.json.ObjectDeserializer; -import org.opensearch.client.json.PlainJsonSerializable; +import org.opensearch.client.json.*; import org.opensearch.client.opensearch._types.ErrorResponse; import org.opensearch.client.opensearch._types.RequestBase; import org.opensearch.client.opensearch._types.StoredScript; @@ -183,7 +178,7 @@ public Builder toBuilder() { * Builder for {@link PutScriptRequest}. */ - public static class Builder extends ObjectBuilderBase implements ObjectBuilder { + public static class Builder extends ObjectBuilderBase implements ObjectBuilder, PlainDeserializable { @Nullable private String context; @@ -306,6 +301,11 @@ public PutScriptRequest build() { return new PutScriptRequest(this); } + + @Override + public Builder get() { + return this; + } } // --------------------------------------------------------------------------------------------- diff --git a/java-client/src/main/java/org/opensearch/client/opensearch/core/ReindexRequest.java b/java-client/src/main/java/org/opensearch/client/opensearch/core/ReindexRequest.java index 94729d0256..5b7e9d1736 100644 --- a/java-client/src/main/java/org/opensearch/client/opensearch/core/ReindexRequest.java +++ b/java-client/src/main/java/org/opensearch/client/opensearch/core/ReindexRequest.java @@ -37,18 +37,8 @@ import java.util.Map; import java.util.function.Function; import javax.annotation.Nullable; -import org.opensearch.client.json.JsonpDeserializable; -import org.opensearch.client.json.JsonpDeserializer; -import org.opensearch.client.json.JsonpMapper; -import org.opensearch.client.json.ObjectBuilderDeserializer; -import org.opensearch.client.json.ObjectDeserializer; -import org.opensearch.client.json.PlainJsonSerializable; -import org.opensearch.client.opensearch._types.Conflicts; -import org.opensearch.client.opensearch._types.ErrorResponse; -import org.opensearch.client.opensearch._types.RequestBase; -import org.opensearch.client.opensearch._types.Script; -import org.opensearch.client.opensearch._types.Time; -import org.opensearch.client.opensearch._types.WaitForActiveShards; +import org.opensearch.client.json.*; +import org.opensearch.client.opensearch._types.*; import org.opensearch.client.opensearch.core.reindex.Destination; import org.opensearch.client.opensearch.core.reindex.Source; import org.opensearch.client.transport.Endpoint; @@ -332,7 +322,7 @@ public Builder toBuilder() { * Builder for {@link ReindexRequest}. */ - public static class Builder extends ObjectBuilderBase implements ObjectBuilder { + public static class Builder extends ObjectBuilderBase implements ObjectBuilder, PlainDeserializable { @Nullable private Conflicts conflicts; @@ -572,6 +562,11 @@ public ReindexRequest build() { return new ReindexRequest(this); } + + @Override + public Builder get() { + return this; + } } // --------------------------------------------------------------------------------------------- diff --git a/java-client/src/main/java/org/opensearch/client/opensearch/core/RenderSearchTemplateRequest.java b/java-client/src/main/java/org/opensearch/client/opensearch/core/RenderSearchTemplateRequest.java index 2e738f2dc7..94556aa53a 100644 --- a/java-client/src/main/java/org/opensearch/client/opensearch/core/RenderSearchTemplateRequest.java +++ b/java-client/src/main/java/org/opensearch/client/opensearch/core/RenderSearchTemplateRequest.java @@ -37,13 +37,7 @@ import java.util.Map; import java.util.function.Function; import javax.annotation.Nullable; -import org.opensearch.client.json.JsonData; -import org.opensearch.client.json.JsonpDeserializable; -import org.opensearch.client.json.JsonpDeserializer; -import org.opensearch.client.json.JsonpMapper; -import org.opensearch.client.json.ObjectBuilderDeserializer; -import org.opensearch.client.json.ObjectDeserializer; -import org.opensearch.client.json.PlainJsonSerializable; +import org.opensearch.client.json.*; import org.opensearch.client.opensearch._types.ErrorResponse; import org.opensearch.client.opensearch._types.RequestBase; import org.opensearch.client.transport.Endpoint; @@ -164,7 +158,10 @@ public Builder toBuilder() { * Builder for {@link RenderSearchTemplateRequest}. */ - public static class Builder extends ObjectBuilderBase implements ObjectBuilder { + public static class Builder extends ObjectBuilderBase + implements + ObjectBuilder, + PlainDeserializable { @Nullable private String file; @@ -234,6 +231,11 @@ public RenderSearchTemplateRequest build() { return new RenderSearchTemplateRequest(this); } + + @Override + public Builder get() { + return this; + } } // --------------------------------------------------------------------------------------------- diff --git a/java-client/src/main/java/org/opensearch/client/opensearch/core/UpdateByQueryRequest.java b/java-client/src/main/java/org/opensearch/client/opensearch/core/UpdateByQueryRequest.java index f10d6b4a6b..c21968c246 100644 --- a/java-client/src/main/java/org/opensearch/client/opensearch/core/UpdateByQueryRequest.java +++ b/java-client/src/main/java/org/opensearch/client/opensearch/core/UpdateByQueryRequest.java @@ -39,21 +39,8 @@ import java.util.function.Function; import java.util.stream.Collectors; import javax.annotation.Nullable; -import org.opensearch.client.json.JsonpDeserializable; -import org.opensearch.client.json.JsonpDeserializer; -import org.opensearch.client.json.JsonpMapper; -import org.opensearch.client.json.ObjectBuilderDeserializer; -import org.opensearch.client.json.ObjectDeserializer; -import org.opensearch.client.json.PlainJsonSerializable; -import org.opensearch.client.opensearch._types.Conflicts; -import org.opensearch.client.opensearch._types.ErrorResponse; -import org.opensearch.client.opensearch._types.ExpandWildcard; -import org.opensearch.client.opensearch._types.RequestBase; -import org.opensearch.client.opensearch._types.Script; -import org.opensearch.client.opensearch._types.SearchType; -import org.opensearch.client.opensearch._types.SlicedScroll; -import org.opensearch.client.opensearch._types.Time; -import org.opensearch.client.opensearch._types.WaitForActiveShards; +import org.opensearch.client.json.*; +import org.opensearch.client.opensearch._types.*; import org.opensearch.client.opensearch._types.query_dsl.Operator; import org.opensearch.client.opensearch._types.query_dsl.Query; import org.opensearch.client.opensearch.core.search.SourceConfigParam; @@ -700,7 +687,7 @@ public Builder toBuilder() { * Builder for {@link UpdateByQueryRequest}. */ - public static class Builder extends ObjectBuilderBase implements ObjectBuilder { + public static class Builder extends ObjectBuilderBase implements ObjectBuilder, PlainDeserializable { @Nullable private SourceConfigParam source; @@ -1376,6 +1363,11 @@ public UpdateByQueryRequest build() { return new UpdateByQueryRequest(this); } + + @Override + public Builder get() { + return this; + } } // --------------------------------------------------------------------------------------------- diff --git a/java-client/src/main/java/org/opensearch/client/opensearch/indices/CloneIndexRequest.java b/java-client/src/main/java/org/opensearch/client/opensearch/indices/CloneIndexRequest.java index 980afd4fa9..ab9ddb4a70 100644 --- a/java-client/src/main/java/org/opensearch/client/opensearch/indices/CloneIndexRequest.java +++ b/java-client/src/main/java/org/opensearch/client/opensearch/indices/CloneIndexRequest.java @@ -37,13 +37,7 @@ import java.util.Map; import java.util.function.Function; import javax.annotation.Nullable; -import org.opensearch.client.json.JsonData; -import org.opensearch.client.json.JsonpDeserializable; -import org.opensearch.client.json.JsonpDeserializer; -import org.opensearch.client.json.JsonpMapper; -import org.opensearch.client.json.ObjectBuilderDeserializer; -import org.opensearch.client.json.ObjectDeserializer; -import org.opensearch.client.json.PlainJsonSerializable; +import org.opensearch.client.json.*; import org.opensearch.client.opensearch._types.ErrorResponse; import org.opensearch.client.opensearch._types.RequestBase; import org.opensearch.client.opensearch._types.Time; @@ -217,7 +211,7 @@ protected void serializeInternal(JsonGenerator generator, JsonpMapper mapper) { * Builder for {@link CloneIndexRequest}. */ - public static class Builder extends ObjectBuilderBase implements ObjectBuilder { + public static class Builder extends ObjectBuilderBase implements ObjectBuilder, PlainDeserializable { @Nullable private Map aliases; @@ -401,6 +395,11 @@ public CloneIndexRequest build() { return new CloneIndexRequest(this); } + + @Override + public Builder get() { + return this; + } } // --------------------------------------------------------------------------------------------- diff --git a/java-client/src/main/java/org/opensearch/client/opensearch/indices/PutTemplateRequest.java b/java-client/src/main/java/org/opensearch/client/opensearch/indices/PutTemplateRequest.java index 408cdd58bc..5ad4109625 100644 --- a/java-client/src/main/java/org/opensearch/client/opensearch/indices/PutTemplateRequest.java +++ b/java-client/src/main/java/org/opensearch/client/opensearch/indices/PutTemplateRequest.java @@ -38,13 +38,7 @@ import java.util.Map; import java.util.function.Function; import javax.annotation.Nullable; -import org.opensearch.client.json.JsonData; -import org.opensearch.client.json.JsonpDeserializable; -import org.opensearch.client.json.JsonpDeserializer; -import org.opensearch.client.json.JsonpMapper; -import org.opensearch.client.json.ObjectBuilderDeserializer; -import org.opensearch.client.json.ObjectDeserializer; -import org.opensearch.client.json.PlainJsonSerializable; +import org.opensearch.client.json.*; import org.opensearch.client.opensearch._types.ErrorResponse; import org.opensearch.client.opensearch._types.RequestBase; import org.opensearch.client.opensearch._types.Time; @@ -307,7 +301,7 @@ protected void serializeInternal(JsonGenerator generator, JsonpMapper mapper) { * Builder for {@link PutTemplateRequest}. */ - public static class Builder extends ObjectBuilderBase implements ObjectBuilder { + public static class Builder extends ObjectBuilderBase implements ObjectBuilder, PlainDeserializable { @Nullable private Map aliases; @@ -571,6 +565,11 @@ public PutTemplateRequest build() { return new PutTemplateRequest(this); } + + @Override + public Builder get() { + return this; + } } // --------------------------------------------------------------------------------------------- diff --git a/java-client/src/main/java/org/opensearch/client/opensearch/indices/UpdateAliasesRequest.java b/java-client/src/main/java/org/opensearch/client/opensearch/indices/UpdateAliasesRequest.java index a9e3d29d0c..37be12b0bf 100644 --- a/java-client/src/main/java/org/opensearch/client/opensearch/indices/UpdateAliasesRequest.java +++ b/java-client/src/main/java/org/opensearch/client/opensearch/indices/UpdateAliasesRequest.java @@ -38,12 +38,7 @@ import java.util.Map; import java.util.function.Function; import javax.annotation.Nullable; -import org.opensearch.client.json.JsonpDeserializable; -import org.opensearch.client.json.JsonpDeserializer; -import org.opensearch.client.json.JsonpMapper; -import org.opensearch.client.json.ObjectBuilderDeserializer; -import org.opensearch.client.json.ObjectDeserializer; -import org.opensearch.client.json.PlainJsonSerializable; +import org.opensearch.client.json.*; import org.opensearch.client.opensearch._types.ErrorResponse; import org.opensearch.client.opensearch._types.RequestBase; import org.opensearch.client.opensearch._types.Time; @@ -157,7 +152,7 @@ protected void serializeInternal(JsonGenerator generator, JsonpMapper mapper) { * Builder for {@link UpdateAliasesRequest}. */ - public static class Builder extends ObjectBuilderBase implements ObjectBuilder { + public static class Builder extends ObjectBuilderBase implements ObjectBuilder, PlainDeserializable { @Nullable private List actions; @@ -270,6 +265,11 @@ public UpdateAliasesRequest build() { return new UpdateAliasesRequest(this); } + + @Override + public Builder get() { + return this; + } } // --------------------------------------------------------------------------------------------- diff --git a/java-client/src/main/java/org/opensearch/client/opensearch/nodes/ReloadSecureSettingsRequest.java b/java-client/src/main/java/org/opensearch/client/opensearch/nodes/ReloadSecureSettingsRequest.java index e5ef71ed8e..e8f9571079 100644 --- a/java-client/src/main/java/org/opensearch/client/opensearch/nodes/ReloadSecureSettingsRequest.java +++ b/java-client/src/main/java/org/opensearch/client/opensearch/nodes/ReloadSecureSettingsRequest.java @@ -39,12 +39,7 @@ import java.util.function.Function; import java.util.stream.Collectors; import javax.annotation.Nullable; -import org.opensearch.client.json.JsonpDeserializable; -import org.opensearch.client.json.JsonpDeserializer; -import org.opensearch.client.json.JsonpMapper; -import org.opensearch.client.json.ObjectBuilderDeserializer; -import org.opensearch.client.json.ObjectDeserializer; -import org.opensearch.client.json.PlainJsonSerializable; +import org.opensearch.client.json.*; import org.opensearch.client.opensearch._types.ErrorResponse; import org.opensearch.client.opensearch._types.RequestBase; import org.opensearch.client.opensearch._types.Time; @@ -136,7 +131,10 @@ protected void serializeInternal(JsonGenerator generator, JsonpMapper mapper) { * Builder for {@link ReloadSecureSettingsRequest}. */ - public static class Builder extends ObjectBuilderBase implements ObjectBuilder { + public static class Builder extends ObjectBuilderBase + implements + ObjectBuilder, + PlainDeserializable { @Nullable private List nodeId; @@ -210,6 +208,11 @@ public ReloadSecureSettingsRequest build() { return new ReloadSecureSettingsRequest(this); } + + @Override + public Builder get() { + return null; + } } // --------------------------------------------------------------------------------------------- diff --git a/java-client/src/main/java/org/opensearch/client/opensearch/snapshot/CreateSnapshotRequest.java b/java-client/src/main/java/org/opensearch/client/opensearch/snapshot/CreateSnapshotRequest.java index 4a1e14baea..928f25ff3f 100644 --- a/java-client/src/main/java/org/opensearch/client/opensearch/snapshot/CreateSnapshotRequest.java +++ b/java-client/src/main/java/org/opensearch/client/opensearch/snapshot/CreateSnapshotRequest.java @@ -38,13 +38,7 @@ import java.util.Map; import java.util.function.Function; import javax.annotation.Nullable; -import org.opensearch.client.json.JsonData; -import org.opensearch.client.json.JsonpDeserializable; -import org.opensearch.client.json.JsonpDeserializer; -import org.opensearch.client.json.JsonpMapper; -import org.opensearch.client.json.ObjectBuilderDeserializer; -import org.opensearch.client.json.ObjectDeserializer; -import org.opensearch.client.json.PlainJsonSerializable; +import org.opensearch.client.json.*; import org.opensearch.client.opensearch._types.ErrorResponse; import org.opensearch.client.opensearch._types.RequestBase; import org.opensearch.client.opensearch._types.Time; @@ -307,7 +301,7 @@ protected void serializeInternal(JsonGenerator generator, JsonpMapper mapper) { * Builder for {@link CreateSnapshotRequest}. */ - public static class Builder extends ObjectBuilderBase implements ObjectBuilder { + public static class Builder extends ObjectBuilderBase implements ObjectBuilder, PlainDeserializable { @Nullable private List featureStates; @@ -554,6 +548,11 @@ public CreateSnapshotRequest build() { return new CreateSnapshotRequest(this); } + + @Override + public Builder get() { + return this; + } } // --------------------------------------------------------------------------------------------- diff --git a/java-client/src/test/java/org/opensearch/client/opensearch/json/PlainDeserializableTest.java b/java-client/src/test/java/org/opensearch/client/opensearch/json/PlainDeserializableTest.java index 6234e47e10..9bd08334f4 100644 --- a/java-client/src/test/java/org/opensearch/client/opensearch/json/PlainDeserializableTest.java +++ b/java-client/src/test/java/org/opensearch/client/opensearch/json/PlainDeserializableTest.java @@ -8,13 +8,18 @@ package org.opensearch.client.opensearch.json; -import org.junit.Test; -import org.opensearch.client.opensearch.indices.PutIndexTemplateRequest; - import java.io.ByteArrayInputStream; import java.io.InputStream; import java.nio.charset.StandardCharsets; +import java.util.Arrays; import java.util.List; +import org.junit.Test; +import org.opensearch.client.opensearch._types.FieldSort; +import org.opensearch.client.opensearch._types.SortOptions; +import org.opensearch.client.opensearch._types.SortOrder; +import org.opensearch.client.opensearch.core.ScrollRequest; +import org.opensearch.client.opensearch.core.SearchRequest; +import org.opensearch.client.opensearch.indices.PutIndexTemplateRequest; public class PlainDeserializableTest { @@ -31,12 +36,165 @@ public void testWithJsonPutIndexTemplateRequest() { .build(); String expectedName = "My index"; // My index 2 will be replaced by My index from inputStream - List expectedIndexPatterns = List.of("index_pattern3", "index_pattern1"); - List expectedComponents = List.of("component1", "component2"); + List expectedIndexPatterns = Arrays.asList("index_pattern3", "index_pattern1"); + List expectedComponents = Arrays.asList("component1", "component2"); assert expectedName.equals(indexTemplateRequest.name()); assert expectedIndexPatterns.equals(indexTemplateRequest.indexPatterns()); assert expectedComponents.equals(indexTemplateRequest.composedOf()); } + + @Test + public void testWithJsonScrollRequest() { + + String stringTemplate = "{\"scroll\": \"2023-12-31T23:59:59Z\", \"scroll_id\": \"my_scroll_id\"}"; + InputStream inputStream = new ByteArrayInputStream(stringTemplate.getBytes(StandardCharsets.UTF_8)); + + ScrollRequest scrollRequest = new ScrollRequest.Builder().withJson(inputStream).build(); + + String expectedScrollId = "my_scroll_id"; + assert scrollRequest.scrollId().equals(expectedScrollId); + + } + + @Test + public void testWithJsonSearchRequest() { + String stringTemplate = "{\n" + + " \"source\": {\n" + + " \"includes\": [\"field1\", \"field2\"],\n" + + " \"excludes\": [\"field3\"]\n" + + " },\n" + + " \"aggregations\": {\n" + + " \"term_aggregation\": {\n" + + " \"terms\": {\n" + + " \"field\": \"category\"\n" + + " }\n" + + " }\n" + + " },\n" + + " \"allowNoIndices\": false,\n" + + " \"allowPartialSearchResults\": true,\n" + + " \"analyzeWildcard\": false,\n" + + " \"analyzer\": \"standard\",\n" + + " \"batchedReduceSize\": 512,\n" + + " \"ccsMinimizeRoundtrips\": true,\n" + + " \"phaseTook\": true,\n" + + " \"pipeline\": \"my_pipeline\",\n" + + " \"collapse\": {\n" + + " \"field\": \"user_id\"\n" + + " },\n" + + " \"defaultOperator\": \"AND\",\n" + + " \"df\": \"text_field\",\n" + + " \"docvalue_fields\": [\n" + + " {\"field\": \"field1\", \"format\": \"raw\"},\n" + + " {\"field\": \"field2\", \"format\": \"date_time\"}\n" + + " ],\n" + + " \"expandWildcards\": [\"open\", \"closed\"],\n" + + " \"explain\": true,\n" + + " \"fields\": [\"field1\", \"field2\"],\n" + + " \"from\": 0,\n" + + " \"highlight\": {\n" + + " \"fields\": {\n" + + " \"title\": {\n" + + " \"fragment_size\": 150\n" + + " }\n" + + " }\n" + + " },\n" + + " \"ignoreThrottled\": false,\n" + + " \"ignoreUnavailable\": false,\n" + + " \"index\": [\"my_index\"],\n" + + " \"indicesBoost\": [\n" + + " {\"index\": \"index1\", \"boost\": 2.0},\n" + + " {\"index\": \"index2\", \"boost\": 1.5}\n" + + " ],\n" + + " \"lenient\": true,\n" + + " \"maxConcurrentShardRequests\": 5,\n" + + " \"minCompatibleShardNode\": \"1.5.0\",\n" + + " \"minScore\": 0.5,\n" + + " \"pit\": {\n" + + " \"id\": 123,\n" + + " \"keepOnCompletion\": true\n" + + " },\n" + + " \"postFilter\": {\n" + + " \"term\": {\n" + + " \"status\": \"active\"\n" + + " }\n" + + " },\n" + + " \"preFilterShardSize\": 10000,\n" + + " \"preference\": \"_local\",\n" + + " \"profile\": true,\n" + + " \"q\": \"query_string\",\n" + + " \"query\": {\n" + + " \"match\": {\n" + + " \"title\": \"search term\"\n" + + " }\n" + + " },\n" + + " \"requestCache\": true,\n" + + " \"rescore\": [\n" + + " {\n" + + " \"query\": {\n" + + " \"rescore_query\": {\n" + + " \"match\": {\n" + + " \"field\": \"boost_field\"\n" + + " }\n" + + " },\n" + + " \"window_size\": 100\n" + + " }\n" + + " }\n" + + " ],\n" + + " \"routing\": \"my_routing_value\",\n" + + " \"runtime_mappings\": {\n" + + " \"my_field\": {\n" + + " \"type\": \"keyword\"\n" + + " }\n" + + " },\n" + + " \"script_fields\": {\n" + + " \"my_script\": {\n" + + " \"script\": {\n" + + " \"lang\": \"painless\",\n" + + " \"source\": \"doc['field1'].value * 2\"\n" + + " }\n" + + " }\n" + + " },\n" + + " \"scroll\": \"1m\",\n" + + " \"search_after\": [100, \"abc\"],\n" + + " \"searchType\": \"dfs_query_then_fetch\",\n" + + " \"seq_no_primary_term\": true,\n" + + " \"size\": 10,\n" + + " \"slice\": {\n" + + " \"id\": 2,\n" + + " \"max\": 100\n" + + " },\n" + + " \"stats\": [\"field1\", \"field2\"],\n" + + " \"stored_fields\": [\"field1\", \"field2\"],\n" + + " \"suggest\": {\n" + + " \"my_suggest\": {\n" + + " \"text\": \"search_term\",\n" + + " \"term\": {\n" + + " \"field\": \"suggest_field\"\n" + + " }\n" + + " }\n" + + " },\n" + + " \"terminate_after\": 5000,\n" + + " \"timeout\": \"1m\",\n" + + " \"track_scores\": true,\n" + + " \"version\": true,\n" + + " \"ext\": {\n" + + " \"custom_field\": \"custom_value\"\n" + + " }\n" + + "}"; + + InputStream inputStream = new ByteArrayInputStream(stringTemplate.getBytes(StandardCharsets.UTF_8)); + SortOptions sortOptions = new SortOptions.Builder().field(new FieldSort.Builder().field("sortField").order(SortOrder.Desc).build()) + .build(); + + SearchRequest searchRequest = new SearchRequest.Builder().withJson(inputStream).build(); + + assert searchRequest.terminateAfter().equals(5000L); + assert searchRequest.trackScores().equals(true); + assert searchRequest.aggregations().size() == 1; + assert searchRequest.storedFields().equals(Arrays.asList("field1", "field2")); + + } + }