Skip to content

Commit 1df3f02

Browse files
committed
Add support for nd-json, path fragment encoding, tests & bugfixes
1 parent c9f18df commit 1df3f02

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+702
-261
lines changed

config/checkstyle/checkstyle.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,14 @@
3939
<!-- Checks Java files and forbids empty Javadoc comments. -->
4040
<!-- Although you can use the "JavadocStyle" rule for this, it considers Javadoc -->
4141
<!-- that only contains a "@return" line to be empty. -->
42+
<!--
4243
<module name="RegexpMultiline">
4344
<property name="id" value="EmptyJavadoc" />
4445
<property name="format" value="\/\*[\s\*]*\*\/" />
4546
<property name="fileExtensions" value="java" />
4647
<property name="message" value="Empty javadoc comments are forbidden" />
4748
</module>
49+
-->
4850

4951
<!-- Its our official line length! See checkstyle_suppressions.xml for the files that don't pass this. For now we
5052
suppress the check there but enforce it everywhere else. This prevents the list from getting longer even if it is

java-client/build.gradle.kts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,13 +107,15 @@ publishing {
107107
}
108108

109109
dependencies {
110-
val elasticsearchVersion = "7.12.0"
110+
val elasticsearchVersion = "7.15.0"
111111
val jacksonVersion = "2.12.0"
112112

113113
// Apache 2.0
114+
// https://www.elastic.co/guide/en/elasticsearch/client/java-rest/current/java-rest-low.html
114115
implementation("org.elasticsearch.client", "elasticsearch-rest-client", elasticsearchVersion)
115116

116117
// Apache 2.0
118+
// https://search.maven.org/artifact/com.google.code.findbugs/jsr305
117119
implementation("com.google.code.findbugs:jsr305:3.0.2")
118120

119121
// EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
@@ -131,20 +133,26 @@ dependencies {
131133
testImplementation("jakarta.json.bind", "jakarta.json.bind-api", "2.0.0")
132134

133135
// Apache 2.0
136+
// https://github.com/FasterXML/jackson
134137
compileOnly("com.fasterxml.jackson.core", "jackson-core", jacksonVersion)
135138
compileOnly("com.fasterxml.jackson.core", "jackson-databind", jacksonVersion)
136139
testImplementation("com.fasterxml.jackson.core", "jackson-core", jacksonVersion)
137140
testImplementation("com.fasterxml.jackson.core", "jackson-databind", jacksonVersion)
138-
testImplementation("io.github.classgraph:classgraph:4.8.116")
139141

140142
// EPL-2.0 OR BSD-3-Clause
141143
// https://eclipse-ee4j.github.io/yasson/
142144
testImplementation("org.eclipse", "yasson", "2.0.2")
143145

144-
// Eclipse 1.0
146+
// EPL-1.0
147+
// https://junit.org/junit4/
145148
testImplementation("junit", "junit" , "4.12")
146149

147150
// MIT
151+
// https://github.com/classgraph/classgraph
152+
testImplementation("io.github.classgraph:classgraph:4.8.116")
153+
154+
// MIT
155+
// https://www.testcontainers.org/
148156
testImplementation("org.testcontainers", "testcontainers", "1.15.3")
149157
testImplementation("org.testcontainers", "elasticsearch", "1.15.3")
150158
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*
2+
* Licensed to Elasticsearch B.V. under one or more contributor
3+
* license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright
5+
* ownership. Elasticsearch B.V. licenses this file to you under
6+
* the Apache License, Version 2.0 (the "License"); you may
7+
* not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
package co.elastic.clients.base;
21+
22+
import co.elastic.clients.json.JsonpDeserializer;
23+
24+
import java.util.Map;
25+
import java.util.function.Function;
26+
27+
public class BooleanEndpoint<RequestT> extends SimpleEndpoint<RequestT, BooleanResponse> {
28+
29+
public BooleanEndpoint(
30+
Function<RequestT, String> method,
31+
Function<RequestT, String> requestUrl,
32+
Function<RequestT,
33+
Map<String, String>> queryParameters,
34+
Function<RequestT, Map<String, String>> headers,
35+
boolean hasRequestBody, // always true
36+
JsonpDeserializer<BooleanResponse> responseParser // always null
37+
) {
38+
super(method, requestUrl, queryParameters, headers, hasRequestBody, responseParser);
39+
}
40+
41+
@Override
42+
public boolean isError(int statusCode) {
43+
return statusCode >= 500;
44+
}
45+
46+
public boolean getResult(int statusCode) {
47+
return statusCode < 400;
48+
}
49+
}

java-client/src/main/java/co/elastic/clients/base/AdditionalProperties.java renamed to java-client/src/main/java/co/elastic/clients/base/DictionaryResponse.java

Lines changed: 29 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,11 @@
3333
import java.util.HashMap;
3434
import java.util.Map;
3535

36-
public abstract class AdditionalProperties<TKey, TValue> implements JsonpSerializable {
37-
private final Map<String, TValue> value;
36+
/**
37+
* Base class for dictionary responses, i.e. a series of key/value pairs.
38+
*/
39+
public abstract class DictionaryResponse<TKey, TValue> implements JsonpSerializable {
40+
private final Map<String, TValue> result;
3841

3942
@Nullable
4043
private final JsonpSerializer<TKey> tKeySerializer;
@@ -44,19 +47,26 @@ public abstract class AdditionalProperties<TKey, TValue> implements JsonpSeriali
4447

4548
// ---------------------------------------------------------------------------------------------
4649

47-
protected AdditionalProperties(AbstractBuilder<TKey, TValue, ?> builder) {
50+
protected DictionaryResponse(AbstractBuilder<TKey, TValue, ?> builder) {
4851

49-
this.value = builder.value;
52+
this.result = builder.result;
5053
this.tKeySerializer = builder.tKeySerializer;
5154
this.tValueSerializer = builder.tValueSerializer;
5255

5356
}
5457

5558
/**
56-
* Returns the map of additional properties.
59+
* Returns the response as a map.
60+
*/
61+
public Map<String, TValue> result() {
62+
return this.result == null ? Collections.emptyMap() : result;
63+
}
64+
65+
/**
66+
*
5767
*/
58-
public Map<String, TValue> value() {
59-
return this.value != null ? value : Collections.emptyMap();
68+
public TValue get(String key) {
69+
return this.result == null ? null : result.get(key);
6070
}
6171

6272
/**
@@ -69,14 +79,14 @@ public void serialize(JsonGenerator generator, JsonpMapper mapper) {
6979
}
7080

7181
protected void toJsonpInternal(JsonGenerator generator, JsonpMapper mapper) {
72-
for (Map.Entry<String, TValue> item0 : this.value.entrySet()) {
82+
for (Map.Entry<String, TValue> item0 : this.result.entrySet()) {
7383
generator.writeKey(item0.getKey());
7484
JsonpUtils.serialize(item0.getValue(), generator, tValueSerializer, mapper);
7585
}
7686
}
7787

7888
protected abstract static class AbstractBuilder<TKey, TValue, BuilderT extends AbstractBuilder<TKey, TValue, BuilderT>> {
79-
private Map<String, TValue> value;
89+
private Map<String, TValue> result;
8090

8191
@Nullable
8292
private JsonpSerializer<TKey> tKeySerializer;
@@ -85,23 +95,21 @@ protected abstract static class AbstractBuilder<TKey, TValue, BuilderT extends A
8595
private JsonpSerializer<TValue> tValueSerializer;
8696

8797
/**
88-
* Response value.
89-
*
90-
* API name: {@code value}
98+
* Response result.
9199
*/
92-
public BuilderT value(Map<String, TValue> value) {
93-
this.value = value;
100+
public BuilderT result(Map<String, TValue> value) {
101+
this.result = value;
94102
return self();
95103
}
96104

97105
/**
98-
* Add a key/value to {@link #value(Map)}, creating the map if needed.
106+
* Add a key/value to {@link #result(Map)}, creating the map if needed.
99107
*/
100-
public BuilderT putValue(String key, TValue value) {
101-
if (this.value == null) {
102-
this.value = new HashMap<>();
108+
public BuilderT putResult(String key, TValue value) {
109+
if (this.result == null) {
110+
this.result = new HashMap<>();
103111
}
104-
this.value.put(key, value);
112+
this.result.put(key, value);
105113
return self();
106114
}
107115

@@ -130,14 +138,14 @@ public BuilderT tValueSerializer(@Nullable JsonpSerializer<TValue> value) {
130138
}
131139

132140
// ---------------------------------------------------------------------------------------------
133-
protected static <TKey, TValue, BuilderT extends AbstractBuilder<TKey, TValue, BuilderT>> void setupAdditionalPropertiesDeserializer(
141+
protected static <TKey, TValue, BuilderT extends AbstractBuilder<TKey, TValue, BuilderT>> void setupDictionaryResponseDeserializer(
134142
DelegatingDeserializer<BuilderT> op, JsonpDeserializer<TKey> tKeyParser,
135143
JsonpDeserializer<TValue> tValueParser) {
136144

137145
@SuppressWarnings("unckecked")
138146
ObjectDeserializer<BuilderT> op1 = (ObjectDeserializer<BuilderT>)op;
139147
op1.setUnknownFieldHandler((builder, name, parser, params) -> {
140-
builder.putValue(name, tValueParser.deserialize(parser, params));
148+
builder.putResult(name, tValueParser.deserialize(parser, params));
141149
});
142150
}
143151
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
* Licensed to Elasticsearch B.V. under one or more contributor
3+
* license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright
5+
* ownership. Elasticsearch B.V. licenses this file to you under
6+
* the Apache License, Version 2.0 (the "License"); you may
7+
* not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
package co.elastic.clients.base;
21+
22+
/**
23+
* Marker interface for Elasticsearch cat requests.
24+
*/
25+
public interface ElasticsearchCatRequest {
26+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*
2+
* Licensed to Elasticsearch B.V. under one or more contributor
3+
* license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright
5+
* ownership. Elasticsearch B.V. licenses this file to you under
6+
* the Apache License, Version 2.0 (the "License"); you may
7+
* not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
package co.elastic.clients.base;
21+
22+
/**
23+
* Marker interface for Elasticsearch standard requests that accept common parameters.
24+
*
25+
* @see <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/common-options.html">Documentation</a>
26+
*/
27+
public interface ElasticsearchCommonRequest {
28+
}

0 commit comments

Comments
 (0)