Skip to content

Commit 2712a1e

Browse files
committed
DATAES-628 - documentation, assertions, ES7 adaption.
1 parent ba2d859 commit 2712a1e

File tree

3 files changed

+19
-8
lines changed

3 files changed

+19
-8
lines changed

src/main/java/org/springframework/data/elasticsearch/Document.java

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
* {@link UnsupportedOperationException} when calling modifying methods.
3838
*
3939
* @author Mark Paluch
40+
* @author Peter-Josef Meisch
4041
* @since 4.0
4142
*/
4243
public interface Document extends Map<String, Object> {
@@ -53,7 +54,7 @@ static Document create() {
5354
/**
5455
* Create a {@link Document} from a {@link Map} containing key-value pairs and sub-documents.
5556
*
56-
* @param map source map containing key-value pairs and sub-documents.
57+
* @param map source map containing key-value pairs and sub-documents. must not be {@literal null}.
5758
* @return a new {@link Document}.
5859
*/
5960
static Document from(Map<String, Object> map) {
@@ -74,6 +75,9 @@ static Document from(Map<String, Object> map) {
7475
* @return the parsed {@link Document}.
7576
*/
7677
static Document parse(String json) {
78+
79+
Assert.notNull(json, "JSON must not be null");
80+
7781
try {
7882
return new MapDocument(MapDocument.OBJECT_MAPPER.readerFor(Map.class).readValue(json));
7983
} catch (IOException e) {
@@ -84,11 +88,14 @@ static Document parse(String json) {
8488
/**
8589
* {@link #put(Object, Object)} the {@code key}/{@code value} tuple and return {@code this} {@link Document}.
8690
*
87-
* @param key key with which the specified value is to be associated.
91+
* @param key key with which the specified value is to be associated. must not be {@literal null}.
8892
* @param value value to be associated with the specified key.
8993
* @return {@code this} {@link Document}.
9094
*/
9195
default Document append(String key, Object value) {
96+
97+
Assert.notNull(key, "Key must not be null");
98+
9299
put(key, value);
93100
return this;
94101
}
@@ -369,12 +376,15 @@ default String getStringOrDefault(String key, Supplier<String> defaultValue) {
369376
* <p>
370377
* Any exception thrown by the function will be propagated to the caller.
371378
*
372-
* @param transformer functional interface to a apply
379+
* @param transformer functional interface to a apply. must not be {@literal null}.
373380
* @param <R> class of the result
374381
* @return the result of applying the function to this string
375382
* @see java.util.function.Function
376383
*/
377384
default <R> R transform(Function<? super Document, ? extends R> transformer) {
385+
386+
Assert.notNull(transformer, "transformer must not be null");
387+
378388
return transformer.apply(this);
379389
}
380390

src/main/java/org/springframework/data/elasticsearch/core/DocumentAdapters.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,9 @@
4444
import com.fasterxml.jackson.core.JsonGenerator;
4545

4646
/**
47-
* Utility class to adapt {@link org.elasticsearch.common.document.DocumentField} to
48-
* {@link org.springframework.data.elasticsearch.Document}.
47+
* Utility class to adapt {@link org.elasticsearch.action.get.GetResponse},
48+
* {@link org.elasticsearch.index.get.GetResult}, {@link org.elasticsearch.search.SearchHit},
49+
* {@link org.elasticsearch.common.document.DocumentField} to {@link org.springframework.data.elasticsearch.Document}.
4950
*
5051
* @author Mark Paluch
5152
* @since 4.0

src/test/java/org/springframework/data/elasticsearch/core/DocumentAdaptersUnitTests.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,14 @@
2929
import org.elasticsearch.index.get.GetResult;
3030
import org.elasticsearch.search.SearchHit;
3131
import org.junit.Test;
32-
3332
import org.springframework.data.elasticsearch.Document;
3433
import org.springframework.data.elasticsearch.SearchDocument;
3534

3635
/**
3736
* Unit tests for {@link DocumentAdapters}.
3837
*
3938
* @author Mark Paluch
39+
* @author Peter-Josef Meisch
4040
*/
4141
public class DocumentAdaptersUnitTests {
4242

@@ -46,7 +46,7 @@ public void shouldAdaptGetResponse() {
4646
Map<String, DocumentField> fields = Collections.singletonMap("field",
4747
new DocumentField("field", Arrays.asList("value")));
4848

49-
GetResult getResult = new GetResult("index", "type", "my-id", 1, 0, 42, true, null, fields);
49+
GetResult getResult = new GetResult("index", "type", "my-id", 1, 1, 42, true, null, fields, null);
5050
GetResponse response = new GetResponse(getResult);
5151

5252
Document document = DocumentAdapters.from(response);
@@ -63,7 +63,7 @@ public void shouldAdaptGetResponseSource() {
6363

6464
BytesArray source = new BytesArray("{\"field\":\"value\"}");
6565

66-
GetResult getResult = new GetResult("index", "type", "my-id", 1, 0, 42, true, source, Collections.emptyMap());
66+
GetResult getResult = new GetResult("index", "type", "my-id", 1, 1, 42, true, source, Collections.emptyMap(), null);
6767
GetResponse response = new GetResponse(getResult);
6868

6969
Document document = DocumentAdapters.from(response);

0 commit comments

Comments
 (0)