DATAES-739 - Introduce nullable annotations for API validation.

Original PR: #387
This commit is contained in:
Peter-Josef Meisch
2020-02-09 13:00:25 +01:00
committed by GitHub
parent 4fc4d91b74
commit 936de20421
94 changed files with 612 additions and 357 deletions

View File

@@ -149,8 +149,7 @@ public class NestedObjectTests {
indexOperations.refresh(PersonMultipleLevelNested.class);
// then
GetQuery getQuery = new GetQuery();
getQuery.setId("1");
GetQuery getQuery = new GetQuery("1");
PersonMultipleLevelNested personIndexed = operations.get(getQuery, PersonMultipleLevelNested.class,
IndexCoordinates.of("test-index-person-multiple-level-nested").withTypes("user"));
assertThat(personIndexed).isNotNull();

View File

@@ -0,0 +1,3 @@
@org.springframework.lang.NonNullApi
@org.springframework.lang.NonNullFields
package org.springframework.data.elasticsearch.client.reactive;

View File

@@ -0,0 +1,3 @@
@org.springframework.lang.NonNullApi
@org.springframework.lang.NonNullFields
package org.springframework.data.elasticsearch.client.util;

View File

@@ -28,6 +28,7 @@ import org.springframework.data.elasticsearch.annotations.Document;
import org.springframework.data.elasticsearch.config.AbstractElasticsearchConfiguration;
import org.springframework.data.elasticsearch.repository.ElasticsearchRepository;
import org.springframework.data.elasticsearch.repository.config.EnableElasticsearchRepositories;
import org.springframework.lang.Nullable;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit.jupiter.SpringExtension;
@@ -68,7 +69,7 @@ public class ElasticsearchConfigurationTests {
@Document(indexName = "test-index-config-abstractelasticsearchconfiguraiton", createIndex = false)
static class CreateIndexFalseEntity {
@Id private String id;
@Nullable @Id private String id;
}
interface CreateIndexFalseRepository extends ElasticsearchRepository<CreateIndexFalseEntity, String> {}

View File

@@ -0,0 +1,3 @@
@org.springframework.lang.NonNullApi
@org.springframework.lang.NonNullFields
package org.springframework.data.elasticsearch.config.abstractelasticsearchconfiguration;

View File

@@ -47,6 +47,7 @@ import org.springframework.data.elasticsearch.repository.ElasticsearchRepository
import org.springframework.data.elasticsearch.repository.config.EnableElasticsearchRepositories;
import org.springframework.data.elasticsearch.utils.IndexInitializer;
import org.springframework.data.repository.Repository;
import org.springframework.lang.Nullable;
import org.springframework.test.context.ContextConfiguration;
/**
@@ -60,7 +61,7 @@ import org.springframework.test.context.ContextConfiguration;
@ContextConfiguration(classes = { EnableElasticsearchRepositoriesTests.Config.class })
public class EnableElasticsearchRepositoriesTests implements ApplicationContextAware {
ApplicationContext context;
@Nullable ApplicationContext context;
@Override
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {

View File

@@ -0,0 +1,3 @@
@org.springframework.lang.NonNullApi
@org.springframework.lang.NonNullFields
package org.springframework.data.elasticsearch.config.notnested;

View File

@@ -32,6 +32,7 @@ import org.springframework.data.elasticsearch.core.convert.MappingElasticsearchC
import org.springframework.data.elasticsearch.core.mapping.SimpleElasticsearchMappingContext;
import org.springframework.data.elasticsearch.core.query.Criteria;
import org.springframework.data.elasticsearch.core.query.CriteriaQuery;
import org.springframework.lang.Nullable;
/**
* Tests for the mapping of {@link CriteriaQuery} by a
@@ -95,10 +96,10 @@ public class CriteriaQueryMappingTests {
}
static class Person {
@Id String id;
@Field(name = "first-name") String firstName;
@Field(name = "last-name") String lastName;
@Field(name = "birth-date", type = FieldType.Date, format = DateFormat.custom,
@Nullable @Id String id;
@Nullable @Field(name = "first-name") String firstName;
@Nullable @Field(name = "last-name") String lastName;
@Nullable @Field(name = "birth-date", type = FieldType.Date, format = DateFormat.custom,
pattern = "dd.MM.uuuu") LocalDate birthDate;
}
}

View File

@@ -44,6 +44,7 @@ import org.springframework.data.elasticsearch.repository.query.ElasticsearchQuer
import org.springframework.data.projection.SpelAwareProxyProjectionFactory;
import org.springframework.data.repository.core.support.DefaultRepositoryMetadata;
import org.springframework.data.repository.query.ParametersParameterAccessor;
import org.springframework.lang.Nullable;
/**
* Tests for {@link ElasticsearchPartQuery}. Resides in the core package, as we need an instance of the
@@ -549,11 +550,12 @@ class ElasticsearchPartQueryTests {
}
static class Book {
@Id private String id;
private String name;
private Integer price;
@Nullable @Id private String id;
@Nullable private String name;
@Nullable private Integer price;
@Field(type = FieldType.Boolean) private boolean available;
@Nullable
public String getId() {
return id;
}
@@ -562,6 +564,7 @@ class ElasticsearchPartQueryTests {
this.id = id;
}
@Nullable
public String getName() {
return name;
}
@@ -570,6 +573,7 @@ class ElasticsearchPartQueryTests {
this.name = name;
}
@Nullable
public Integer getPrice() {
return price;
}

View File

@@ -76,6 +76,7 @@ import org.springframework.data.elasticsearch.core.geo.GeoPoint;
import org.springframework.data.elasticsearch.core.mapping.IndexCoordinates;
import org.springframework.data.elasticsearch.core.query.*;
import org.springframework.data.util.CloseableIterator;
import org.springframework.lang.Nullable;
/**
* Base for testing rest/transport templates. Contains the test common to both implementing classes.
@@ -199,8 +200,7 @@ public abstract class ElasticsearchTemplateTests {
operations.index(indexQuery, index);
// when
GetQuery getQuery = new GetQuery();
getQuery.setId(documentId);
GetQuery getQuery = new GetQuery(documentId);
SampleEntity sampleEntity1 = operations.get(getQuery, SampleEntity.class, index);
// then
@@ -415,8 +415,7 @@ public abstract class ElasticsearchTemplateTests {
operations.bulkUpdate(queries, index);
// then
GetQuery getQuery = new GetQuery();
getQuery.setId(documentId);
GetQuery getQuery = new GetQuery(documentId);
SampleEntity indexedEntity = operations.get(getQuery, SampleEntity.class, index);
assertThat(indexedEntity.getMessage()).isEqualTo(messageAfterUpdate);
}
@@ -1431,8 +1430,7 @@ public abstract class ElasticsearchTemplateTests {
operations.update(updateQuery, index);
// then
GetQuery getQuery = new GetQuery();
getQuery.setId(documentId);
GetQuery getQuery = new GetQuery(documentId);
SampleEntity indexedEntity = operations.get(getQuery, SampleEntity.class, index);
assertThat(indexedEntity.getMessage()).isEqualTo(messageAfterUpdate);
}
@@ -1497,8 +1495,7 @@ public abstract class ElasticsearchTemplateTests {
operations.update(updateQuery, index);
// then
GetQuery getQuery = new GetQuery();
getQuery.setId(documentId);
GetQuery getQuery = new GetQuery(documentId);
SampleEntity indexedEntity = operations.get(getQuery, SampleEntity.class, index);
assertThat(indexedEntity.getMessage()).isEqualTo(message);
}
@@ -1741,8 +1738,7 @@ public abstract class ElasticsearchTemplateTests {
// then
assertThat(sampleEntity.getId()).isEqualTo(documentId);
GetQuery getQuery = new GetQuery();
getQuery.setId(documentId);
GetQuery getQuery = new GetQuery(documentId);
SampleEntity result = operations.get(getQuery, SampleEntity.class, index);
assertThat(result.getId()).isEqualTo(documentId);
}
@@ -3043,8 +3039,10 @@ public abstract class ElasticsearchTemplateTests {
static class NestedEntity {
@Nullable
@Field(type = Text) private String someField;
@Nullable
public String getSomeField() {
return someField;
}

View File

@@ -35,14 +35,15 @@ import org.springframework.data.elasticsearch.core.mapping.SimpleElasticsearchMa
import org.springframework.data.elasticsearch.core.query.Criteria;
import org.springframework.data.elasticsearch.core.query.CriteriaQuery;
import org.springframework.data.elasticsearch.core.query.GeoDistanceOrder;
import org.springframework.lang.Nullable;
/**
* @author Peter-Josef Meisch
*/
class RequestFactoryTest {
private static RequestFactory requestFactory;
private static MappingElasticsearchConverter converter;
@Nullable private static RequestFactory requestFactory;
@Nullable private static MappingElasticsearchConverter converter;
@BeforeAll
@@ -118,8 +119,8 @@ class RequestFactoryTest {
}
static class Person {
@Id String id;
@Field(name = "last-name") String lastName;
@Field(name = "current-location") GeoPoint location;
@Nullable @Id String id;
@Nullable @Field(name = "last-name") String lastName;
@Nullable @Field(name = "current-location") GeoPoint location;
}
}

View File

@@ -43,6 +43,7 @@ import org.springframework.data.elasticsearch.core.query.IndexQuery;
import org.springframework.data.elasticsearch.junit.jupiter.ElasticsearchRestTemplateConfiguration;
import org.springframework.data.elasticsearch.junit.jupiter.SpringIntegrationTest;
import org.springframework.data.elasticsearch.utils.IndexInitializer;
import org.springframework.lang.Nullable;
import org.springframework.test.context.ContextConfiguration;
/**
@@ -217,10 +218,11 @@ public class ElasticsearchTemplateCompletionTests {
*/
static class NonDocumentEntity {
@Id private String someId;
private String someField1;
private String someField2;
@Nullable @Id private String someId;
@Nullable private String someField1;
@Nullable private String someField2;
@Nullable
public String getSomeField1() {
return someField1;
}
@@ -229,6 +231,7 @@ public class ElasticsearchTemplateCompletionTests {
this.someField1 = someField1;
}
@Nullable
public String getSomeField2() {
return someField2;
}
@@ -244,11 +247,11 @@ public class ElasticsearchTemplateCompletionTests {
@Document(indexName = "test-index-core-completion", replicas = 0, refreshInterval = "-1")
static class CompletionEntity {
@Id private String id;
@Nullable @Id private String id;
private String name;
@Nullable private String name;
@CompletionField(maxInputLength = 100) private Completion suggest;
@Nullable @CompletionField(maxInputLength = 100) private Completion suggest;
private CompletionEntity() {}
@@ -256,6 +259,7 @@ public class ElasticsearchTemplateCompletionTests {
this.id = id;
}
@Nullable
public String getId() {
return id;
}
@@ -264,6 +268,7 @@ public class ElasticsearchTemplateCompletionTests {
this.id = id;
}
@Nullable
public String getName() {
return name;
}
@@ -272,6 +277,7 @@ public class ElasticsearchTemplateCompletionTests {
this.name = name;
}
@Nullable
public Completion getSuggest() {
return suggest;
}
@@ -327,10 +333,9 @@ public class ElasticsearchTemplateCompletionTests {
@Document(indexName = "test-index-annotated-completion", replicas = 0, refreshInterval = "-1")
static class AnnotatedCompletionEntity {
@Id private String id;
private String name;
@CompletionField(maxInputLength = 100) private Completion suggest;
@Nullable @Id private String id;
@Nullable private String name;
@Nullable @CompletionField(maxInputLength = 100) private Completion suggest;
private AnnotatedCompletionEntity() {}
@@ -338,6 +343,7 @@ public class ElasticsearchTemplateCompletionTests {
this.id = id;
}
@Nullable
public String getId() {
return id;
}
@@ -346,6 +352,7 @@ public class ElasticsearchTemplateCompletionTests {
this.id = id;
}
@Nullable
public String getName() {
return name;
}
@@ -354,6 +361,7 @@ public class ElasticsearchTemplateCompletionTests {
this.name = name;
}
@Nullable
public Completion getSuggest() {
return suggest;
}

View File

@@ -51,6 +51,7 @@ import org.springframework.data.elasticsearch.core.query.IndexQuery;
import org.springframework.data.elasticsearch.junit.jupiter.ElasticsearchRestTemplateConfiguration;
import org.springframework.data.elasticsearch.junit.jupiter.SpringIntegrationTest;
import org.springframework.data.elasticsearch.utils.IndexInitializer;
import org.springframework.lang.Nullable;
import org.springframework.test.context.ContextConfiguration;
/**
@@ -216,10 +217,11 @@ public class ElasticsearchTemplateCompletionWithContextsTests {
*/
static class NonDocumentEntity {
@Id private String someId;
private String someField1;
private String someField2;
@Nullable @Id private String someId;
@Nullable private String someField1;
@Nullable private String someField2;
@Nullable
public String getSomeField1() {
return someField1;
}
@@ -228,6 +230,7 @@ public class ElasticsearchTemplateCompletionWithContextsTests {
this.someField1 = someField1;
}
@Nullable
public String getSomeField2() {
return someField2;
}
@@ -245,10 +248,10 @@ public class ElasticsearchTemplateCompletionWithContextsTests {
static class ContextCompletionEntity {
public static final String LANGUAGE_CATEGORY = "language";
@Id private String id;
private String name;
@Nullable @Id private String id;
@Nullable private String name;
@CompletionField(maxInputLength = 100, contexts = {
@Nullable @CompletionField(maxInputLength = 100, contexts = {
@CompletionContext(name = LANGUAGE_CATEGORY, type = ContextMapping.Type.CATEGORY) }) private Completion suggest;
private ContextCompletionEntity() {}
@@ -257,6 +260,7 @@ public class ElasticsearchTemplateCompletionWithContextsTests {
this.id = id;
}
@Nullable
public String getId() {
return id;
}
@@ -265,6 +269,7 @@ public class ElasticsearchTemplateCompletionWithContextsTests {
this.id = id;
}
@Nullable
public String getName() {
return name;
}
@@ -273,6 +278,7 @@ public class ElasticsearchTemplateCompletionWithContextsTests {
this.name = name;
}
@Nullable
public Completion getSuggest() {
return suggest;
}

View File

@@ -26,7 +26,6 @@ import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.RequiredArgsConstructor;
import java.io.IOException;
import java.time.LocalDate;
import java.util.ArrayList;
import java.util.Arrays;
@@ -61,6 +60,7 @@ import org.springframework.data.geo.Circle;
import org.springframework.data.geo.Point;
import org.springframework.data.geo.Polygon;
import org.springframework.data.mapping.context.MappingContext;
import org.springframework.lang.Nullable;
/**
* Unit tests for {@link MappingElasticsearchConverter}.
@@ -629,10 +629,10 @@ public class MappingElasticsearchConverterUnitTests {
public static class Sample {
public @ReadOnlyProperty String readOnly;
public @Transient String annotatedTransientProperty;
public transient String javaTransientProperty;
public String property;
@Nullable public @ReadOnlyProperty String readOnly;
@Nullable public @Transient String annotatedTransientProperty;
@Nullable public transient String javaTransientProperty;
@Nullable public String property;
}
@Data

View File

@@ -65,6 +65,7 @@ import org.springframework.data.geo.Box;
import org.springframework.data.geo.Circle;
import org.springframework.data.geo.Point;
import org.springframework.data.geo.Polygon;
import org.springframework.lang.Nullable;
import org.springframework.test.context.ContextConfiguration;
/**
@@ -562,59 +563,59 @@ public class MappingBuilderTests extends MappingContextBaseTests {
@Document(indexName = "fieldname-index")
static class IdEntity {
@Id @Field("id-property") private String id;
@Nullable @Id @Field("id-property") private String id;
}
@Document(indexName = "fieldname-index")
static class TextEntity {
@Id @Field("id-property") private String id;
@Nullable @Id @Field("id-property") private String id;
@Field(name = "text-property", type = FieldType.Text) //
private String textProperty;
@Nullable private String textProperty;
}
@Document(indexName = "fieldname-index")
static class MappingEntity {
@Id @Field("id-property") private String id;
@Nullable @Id @Field("id-property") private String id;
@Field("mapping-property") @Mapping(mappingPath = "/mappings/test-field-analyzed-mappings.json") //
private byte[] mappingProperty;
@Nullable private byte[] mappingProperty;
}
@Document(indexName = "fieldname-index")
static class GeoPointEntity {
@Id @Field("id-property") private String id;
@Nullable @Id @Field("id-property") private String id;
@Field("geopoint-property") private GeoPoint geoPoint;
@Nullable @Field("geopoint-property") private GeoPoint geoPoint;
}
@Document(indexName = "fieldname-index")
static class CircularEntity {
@Id @Field("id-property") private String id;
@Nullable @Id @Field("id-property") private String id;
@Field(name = "circular-property", type = FieldType.Object, ignoreFields = { "circular-property" }) //
@Nullable @Field(name = "circular-property", type = FieldType.Object, ignoreFields = { "circular-property" }) //
private CircularEntity circularProperty;
}
@Document(indexName = "fieldname-index")
static class CompletionEntity {
@Id @Field("id-property") private String id;
@Nullable @Id @Field("id-property") private String id;
@Field("completion-property") @CompletionField(maxInputLength = 100) //
@Nullable @Field("completion-property") @CompletionField(maxInputLength = 100) //
private Completion suggest;
}
@Document(indexName = "fieldname-index")
static class MultiFieldEntity {
@Id @Field("id-property") private String id;
@Nullable @Id @Field("id-property") private String id;
@Field("multifield-property") //
@Nullable @Field("multifield-property") //
@MultiField(mainField = @Field(type = FieldType.Text, analyzer = "whitespace"), otherFields = {
@InnerField(suffix = "prefix", type = FieldType.Text, analyzer = "stop", searchAnalyzer = "standard") }) //
private String description;
@@ -629,9 +630,9 @@ public class MappingBuilderTests extends MappingContextBaseTests {
@Document(indexName = "test-index-minimal")
static class MinimalChildEntity {
@Id private String id;
@Nullable @Id private String id;
@Parent(type = "parentType") private String parentId;
@Nullable @Parent(type = "parentType") private String parentId;
}
/**
@@ -663,8 +664,9 @@ public class MappingBuilderTests extends MappingContextBaseTests {
@Document(indexName = "test-index-simple-recursive-mapping-builder", replicas = 0, refreshInterval = "-1")
static class SimpleRecursiveEntity {
@Id private String id;
@Field(type = FieldType.Object, ignoreFields = { "circularObject" }) private SimpleRecursiveEntity circularObject;
@Nullable @Id private String id;
@Nullable @Field(type = FieldType.Object,
ignoreFields = { "circularObject" }) private SimpleRecursiveEntity circularObject;
}
/**
@@ -713,9 +715,10 @@ public class MappingBuilderTests extends MappingContextBaseTests {
*/
static class Author {
private String id;
private String name;
@Nullable private String id;
@Nullable private String name;
@Nullable
public String getId() {
return id;
}
@@ -724,6 +727,7 @@ public class MappingBuilderTests extends MappingContextBaseTests {
this.id = id;
}
@Nullable
public String getName() {
return name;
}
@@ -739,8 +743,9 @@ public class MappingBuilderTests extends MappingContextBaseTests {
@Document(indexName = "test-index-sample-inherited-mapping-builder", replicas = 0, refreshInterval = "-1")
static class SampleInheritedEntity extends AbstractInheritedEntity {
@Field(type = Text, index = false, store = true, analyzer = "standard") private String message;
@Nullable @Field(type = Text, index = false, store = true, analyzer = "standard") private String message;
@Nullable
public String getMessage() {
return message;
}
@@ -808,10 +813,11 @@ public class MappingBuilderTests extends MappingContextBaseTests {
*/
static class AbstractInheritedEntity {
@Id private String id;
@Nullable @Id private String id;
@Field(type = FieldType.Date, index = false) private Date createdDate;
@Nullable @Field(type = FieldType.Date, index = false) private Date createdDate;
@Nullable
public String getId() {
return id;
}
@@ -820,6 +826,7 @@ public class MappingBuilderTests extends MappingContextBaseTests {
this.id = id;
}
@Nullable
public Date getCreatedDate() {
return createdDate;
}
@@ -835,12 +842,13 @@ public class MappingBuilderTests extends MappingContextBaseTests {
@Document(indexName = "test-index-recursive-mapping-mapping-builder", replicas = 0, refreshInterval = "-1")
static class SampleTransientEntity {
@Id private String id;
@Nullable @Id private String id;
@Field(type = Text, index = false, store = true, analyzer = "standard") private String message;
@Nullable @Field(type = Text, index = false, store = true, analyzer = "standard") private String message;
@Transient private SampleTransientEntity.NestedEntity nested;
@Nullable @Transient private SampleTransientEntity.NestedEntity nested;
@Nullable
public String getId() {
return id;
}
@@ -849,6 +857,7 @@ public class MappingBuilderTests extends MappingContextBaseTests {
this.id = id;
}
@Nullable
public String getMessage() {
return message;
}
@@ -860,7 +869,7 @@ public class MappingBuilderTests extends MappingContextBaseTests {
static class NestedEntity {
@Field private static SampleTransientEntity.NestedEntity someField = new SampleTransientEntity.NestedEntity();
@Field private Boolean something;
@Nullable @Field private Boolean something;
public SampleTransientEntity.NestedEntity getSomeField() {
return someField;
@@ -870,6 +879,7 @@ public class MappingBuilderTests extends MappingContextBaseTests {
NestedEntity.someField = someField;
}
@Nullable
public Boolean getSomething() {
return something;
}
@@ -913,7 +923,7 @@ public class MappingBuilderTests extends MappingContextBaseTests {
*/
@Document(indexName = "test-index-user-mapping-builder")
static class User {
@Id private String id;
@Nullable @Id private String id;
@Field(type = FieldType.Nested, ignoreFields = { "users" }) private Set<Group> groups = new HashSet<>();
}
@@ -924,54 +934,55 @@ public class MappingBuilderTests extends MappingContextBaseTests {
@Document(indexName = "test-index-group-mapping-builder")
static class Group {
@Id String id;
@Nullable @Id String id;
@Field(type = FieldType.Nested, ignoreFields = { "groups" }) private Set<User> users = new HashSet<>();
}
@Document(indexName = "test-index-field-mapping-parameters")
static class FieldMappingParameters {
@Field private String indexTrue;
@Field(index = false) private String indexFalse;
@Field(store = true) private String storeTrue;
@Field private String storeFalse;
@Field private String coerceTrue;
@Field(coerce = false) private String coerceFalse;
@Field(fielddata = true) private String fielddataTrue;
@Field private String fielddataFalse;
@Field(copyTo = { "foo", "bar" }) private String copyTo;
@Field(ignoreAbove = 42) private String ignoreAbove;
@Field(type = FieldType.Integer) private String type;
@Field(type = FieldType.Date, format = DateFormat.custom, pattern = "YYYYMMDD") private LocalDate date;
@Field(analyzer = "ana", searchAnalyzer = "sana", normalizer = "norma") private String analyzers;
@Field(type = Keyword) private String docValuesTrue;
@Field(type = Keyword, docValues = false) private String docValuesFalse;
@Field(ignoreMalformed = true) private String ignoreMalformedTrue;
@Field() private String ignoreMalformedFalse;
@Field(indexOptions = IndexOptions.none) private String indexOptionsNone;
@Field(indexOptions = IndexOptions.positions) private String indexOptionsPositions;
@Field(indexPhrases = true) private String indexPhrasesTrue;
@Field() private String indexPhrasesFalse;
@Field(indexPrefixes = @IndexPrefixes) private String defaultIndexPrefixes;
@Field(indexPrefixes = @IndexPrefixes(minChars = 1, maxChars = 10)) private String customIndexPrefixes;
@Field private String normsTrue;
@Field(norms = false) private String normsFalse;
@Field private String nullValueNotSet;
@Field(nullValue = "NULLNULL") private String nullValueSet;
@Field(positionIncrementGap = 42) private String positionIncrementGap;
@Field private String similarityDefault;
@Field(similarity = Similarity.Boolean) private String similarityBoolean;
@Field private String termVectorDefault;
@Field(termVector = TermVector.with_offsets) private String termVectorWithOffsets;
@Field(type = FieldType.Scaled_Float, scalingFactor = 100.0) Double scaledFloat;
@Nullable @Field private String indexTrue;
@Nullable @Field(index = false) private String indexFalse;
@Nullable @Field(store = true) private String storeTrue;
@Nullable @Field private String storeFalse;
@Nullable @Field private String coerceTrue;
@Nullable @Field(coerce = false) private String coerceFalse;
@Nullable @Field(fielddata = true) private String fielddataTrue;
@Nullable @Field private String fielddataFalse;
@Nullable @Field(copyTo = { "foo", "bar" }) private String copyTo;
@Nullable @Field(ignoreAbove = 42) private String ignoreAbove;
@Nullable @Field(type = FieldType.Integer) private String type;
@Nullable @Field(type = FieldType.Date, format = DateFormat.custom, pattern = "YYYYMMDD") private LocalDate date;
@Nullable @Field(analyzer = "ana", searchAnalyzer = "sana", normalizer = "norma") private String analyzers;
@Nullable @Field(type = Keyword) private String docValuesTrue;
@Nullable @Field(type = Keyword, docValues = false) private String docValuesFalse;
@Nullable @Field(ignoreMalformed = true) private String ignoreMalformedTrue;
@Nullable @Field() private String ignoreMalformedFalse;
@Nullable @Field(indexOptions = IndexOptions.none) private String indexOptionsNone;
@Nullable @Field(indexOptions = IndexOptions.positions) private String indexOptionsPositions;
@Nullable @Field(indexPhrases = true) private String indexPhrasesTrue;
@Nullable @Field() private String indexPhrasesFalse;
@Nullable @Field(indexPrefixes = @IndexPrefixes) private String defaultIndexPrefixes;
@Nullable @Field(indexPrefixes = @IndexPrefixes(minChars = 1, maxChars = 10)) private String customIndexPrefixes;
@Nullable @Field private String normsTrue;
@Nullable @Field(norms = false) private String normsFalse;
@Nullable @Field private String nullValueNotSet;
@Nullable @Field(nullValue = "NULLNULL") private String nullValueSet;
@Nullable @Field(positionIncrementGap = 42) private String positionIncrementGap;
@Nullable @Field private String similarityDefault;
@Nullable @Field(similarity = Similarity.Boolean) private String similarityBoolean;
@Nullable @Field private String termVectorDefault;
@Nullable @Field(termVector = TermVector.with_offsets) private String termVectorWithOffsets;
@Nullable @Field(type = FieldType.Scaled_Float, scalingFactor = 100.0) Double scaledFloat;
}
@Document(indexName = "test-index-configure-dynamic-mapping")
@DynamicMapping(DynamicMappingValue.False)
static class ConfigureDynamicMappingEntity {
@DynamicMapping(DynamicMappingValue.Strict) @Field(type = FieldType.Object) private Author author;
@Nullable @DynamicMapping(DynamicMappingValue.Strict) @Field(type = FieldType.Object) private Author author;
@Nullable
public Author getAuthor() {
return author;
}

View File

@@ -10,6 +10,7 @@ import org.springframework.data.elasticsearch.annotations.FieldType;
import org.springframework.data.elasticsearch.annotations.InnerField;
import org.springframework.data.elasticsearch.annotations.Score;
import org.springframework.data.elasticsearch.core.mapping.ElasticsearchPersistentEntity;
import org.springframework.lang.Nullable;
/**
* @author Peter-Josef Meisch
@@ -59,10 +60,10 @@ public class MappingParametersTest extends MappingContextBaseTests {
}
static class AnnotatedClass {
@Field private String field;
@InnerField(suffix = "test", type = FieldType.Text) private String innerField;
@Nullable @Field private String field;
@Nullable @InnerField(suffix = "test", type = FieldType.Text) private String innerField;
@Score private float score;
@Field(type = FieldType.Text, docValues = false) private String docValuesText;
@Field(type = FieldType.Nested, docValues = false) private String docValuesNested;
@Nullable @Field(type = FieldType.Text, docValues = false) private String docValuesText;
@Nullable @Field(type = FieldType.Nested, docValues = false) private String docValuesNested;
}
}

View File

@@ -17,7 +17,6 @@ package org.springframework.data.elasticsearch.core.index;
import static org.assertj.core.api.Assertions.*;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
@@ -29,6 +28,7 @@ import org.springframework.data.elasticsearch.annotations.Field;
import org.springframework.data.elasticsearch.annotations.FieldType;
import org.springframework.data.elasticsearch.junit.jupiter.ElasticsearchTemplateConfiguration;
import org.springframework.data.elasticsearch.junit.jupiter.SpringIntegrationTest;
import org.springframework.lang.Nullable;
import org.springframework.test.context.ContextConfiguration;
/**
@@ -46,8 +46,7 @@ public class SimpleDynamicTemplatesMappingTests extends MappingContextBaseTests
String mapping = getMappingBuilder().buildPropertyMapping(SampleDynamicTemplatesEntity.class);
String EXPECTED_MAPPING_ONE = "{\"dynamic_templates\":"
+ "[{\"with_custom_analyzer\":{"
String EXPECTED_MAPPING_ONE = "{\"dynamic_templates\":" + "[{\"with_custom_analyzer\":{"
+ "\"mapping\":{\"type\":\"string\",\"analyzer\":\"standard_lowercase_asciifolding\"},"
+ "\"path_match\":\"names.*\"}}]," + "\"properties\":{\"names\":{\"type\":\"object\"}}}";
@@ -58,8 +57,7 @@ public class SimpleDynamicTemplatesMappingTests extends MappingContextBaseTests
public void testCorrectDynamicTemplatesMappingsTwo() {
String mapping = getMappingBuilder().buildPropertyMapping(SampleDynamicTemplatesEntityTwo.class);
String EXPECTED_MAPPING_TWO = "{\"dynamic_templates\":"
+ "[{\"with_custom_analyzer\":{"
String EXPECTED_MAPPING_TWO = "{\"dynamic_templates\":" + "[{\"with_custom_analyzer\":{"
+ "\"mapping\":{\"type\":\"string\",\"analyzer\":\"standard_lowercase_asciifolding\"},"
+ "\"path_match\":\"names.*\"}}," + "{\"participantA1_with_custom_analyzer\":{"
+ "\"mapping\":{\"type\":\"string\",\"analyzer\":\"standard_lowercase_asciifolding\"},"
@@ -71,27 +69,25 @@ public class SimpleDynamicTemplatesMappingTests extends MappingContextBaseTests
/**
* @author Petr Kukral
*/
@Document(indexName = "test-dynamictemplates", indexStoreType = "memory",
replicas = 0, refreshInterval = "-1")
@Document(indexName = "test-dynamictemplates", indexStoreType = "memory", replicas = 0, refreshInterval = "-1")
@DynamicTemplates(mappingPath = "/mappings/test-dynamic_templates_mappings.json")
static class SampleDynamicTemplatesEntity {
@Id private String id;
@Nullable @Id private String id;
@Field(type = FieldType.Object) private Map<String, String> names = new HashMap<>();
@Nullable @Field(type = FieldType.Object) private Map<String, String> names = new HashMap<>();
}
/**
* @author Petr Kukral
*/
@Document(indexName = "test-dynamictemplates", indexStoreType = "memory",
replicas = 0, refreshInterval = "-1")
@Document(indexName = "test-dynamictemplates", indexStoreType = "memory", replicas = 0, refreshInterval = "-1")
@DynamicTemplates(mappingPath = "/mappings/test-dynamic_templates_mappings_two.json")
static class SampleDynamicTemplatesEntityTwo {
@Id private String id;
@Nullable @Id private String id;
@Field(type = FieldType.Object) private Map<String, String> names = new HashMap<>();
@Nullable @Field(type = FieldType.Object) private Map<String, String> names = new HashMap<>();
}
}

View File

@@ -27,6 +27,7 @@ import org.springframework.data.mapping.model.Property;
import org.springframework.data.mapping.model.SimpleTypeHolder;
import org.springframework.data.util.ClassTypeInformation;
import org.springframework.data.util.TypeInformation;
import org.springframework.lang.Nullable;
import org.springframework.util.ReflectionUtils;
/**
@@ -105,8 +106,9 @@ public class SimpleElasticsearchPersistentEntityTests {
private class EntityWithWrongVersionType {
@Version private String version;
@Nullable @Version private String version;
@Nullable
public String getVersion() {
return version;
}
@@ -118,9 +120,10 @@ public class SimpleElasticsearchPersistentEntityTests {
private class EntityWithMultipleVersionField {
@Version private Long version1;
@Version private Long version2;
@Nullable @Version private Long version1;
@Nullable @Version private Long version2;
@Nullable
public Long getVersion1() {
return version1;
}
@@ -129,6 +132,7 @@ public class SimpleElasticsearchPersistentEntityTests {
this.version1 = version1;
}
@Nullable
public Long getVersion2() {
return version2;
}
@@ -147,7 +151,7 @@ public class SimpleElasticsearchPersistentEntityTests {
}
private static class FieldNameEntity {
@Id private String id;
@Field(name = "renamed-field") private String renamedField;
@Nullable @Id private String id;
@Nullable @Field(name = "renamed-field") private String renamedField;
}
}

View File

@@ -27,6 +27,7 @@ import org.springframework.data.elasticsearch.annotations.Field;
import org.springframework.data.elasticsearch.annotations.FieldType;
import org.springframework.data.elasticsearch.annotations.Score;
import org.springframework.data.mapping.MappingException;
import org.springframework.lang.Nullable;
/**
* Unit tests for {@link SimpleElasticsearchPersistentProperty}.
@@ -110,20 +111,20 @@ public class SimpleElasticsearchPersistentPropertyUnitTests {
}
static class InvalidScoreProperty {
@Score String scoreProperty;
@Nullable @Score String scoreProperty;
}
static class FieldNameProperty {
@Field(name = "by-name") String fieldProperty;
@Nullable @Field(name = "by-name") String fieldProperty;
}
static class FieldValueProperty {
@Field(value = "by-value") String fieldProperty;
@Nullable @Field(value = "by-value") String fieldProperty;
}
static class DatesProperty {
@Field(type = FieldType.Date, format = DateFormat.basic_date) Date date;
@Field(type = FieldType.Date, format = DateFormat.custom, pattern = "dd.MM.uuuu") LocalDate localDate;
@Field(type = FieldType.Date, format = DateFormat.basic_date_time) LocalDateTime localDateTime;
@Nullable @Field(type = FieldType.Date, format = DateFormat.basic_date) Date date;
@Nullable @Field(type = FieldType.Date, format = DateFormat.custom, pattern = "dd.MM.uuuu") LocalDate localDate;
@Nullable @Field(type = FieldType.Date, format = DateFormat.basic_date_time) LocalDateTime localDateTime;
}
}

View File

@@ -30,6 +30,7 @@ import org.springframework.data.elasticsearch.annotations.HighlightField;
import org.springframework.data.elasticsearch.annotations.HighlightParameters;
import org.springframework.data.elasticsearch.core.ResourceUtil;
import org.springframework.data.elasticsearch.core.mapping.SimpleElasticsearchMappingContext;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
/**
@@ -117,10 +118,11 @@ class HighlightQueryBuilderTests {
@Document(indexName = "dont-care")
private static class HighlightEntity {
@Id private String id;
@Field(name = "some-field") private String someField;
@Field(name = "other-field") private String otherField;
@Nullable @Id private String id;
@Nullable @Field(name = "some-field") private String someField;
@Nullable @Field(name = "other-field") private String otherField;
@Nullable
public String getId() {
return id;
}
@@ -129,6 +131,7 @@ class HighlightQueryBuilderTests {
this.id = id;
}
@Nullable
public String getSomeField() {
return someField;
}

View File

@@ -17,17 +17,21 @@ package org.springframework.data.elasticsearch.repositories.cdi;
import javax.inject.Inject;
import org.springframework.lang.Nullable;
/**
* @author Mohsin Husen
* @author Oliver Gierke
* @author Mark Paluch
* @author Peter-Josef Meisch
*/
class CdiRepositoryClient {
private CdiProductRepository repository;
private SamplePersonRepository samplePersonRepository;
private QualifiedProductRepository qualifiedProductRepository;
@Nullable private CdiProductRepository repository;
@Nullable private SamplePersonRepository samplePersonRepository;
@Nullable private QualifiedProductRepository qualifiedProductRepository;
@Nullable
public CdiProductRepository getRepository() {
return repository;
}
@@ -37,6 +41,7 @@ class CdiRepositoryClient {
this.repository = repository;
}
@Nullable
public SamplePersonRepository getSamplePersonRepository() {
return samplePersonRepository;
}
@@ -46,6 +51,7 @@ class CdiRepositoryClient {
this.samplePersonRepository = samplePersonRepository;
}
@Nullable
public QualifiedProductRepository getQualifiedProductRepository() {
return qualifiedProductRepository;
}

View File

@@ -41,6 +41,7 @@ import org.springframework.data.elasticsearch.annotations.Field;
import org.springframework.data.elasticsearch.annotations.FieldType;
import org.springframework.data.elasticsearch.annotations.InnerField;
import org.springframework.data.elasticsearch.annotations.MultiField;
import org.springframework.lang.Nullable;
/**
* @author Mohsin Husen
@@ -50,7 +51,7 @@ import org.springframework.data.elasticsearch.annotations.MultiField;
*/
public class CdiRepositoryTests {
private static CdiTestContainer cdiContainer;
@Nullable private static CdiTestContainer cdiContainer;
private CdiProductRepository repository;
private SamplePersonRepository personRepository;
private QualifiedProductRepository qualifiedProductRepository;
@@ -158,8 +159,7 @@ public class CdiRepositoryTests {
@NoArgsConstructor
@AllArgsConstructor
@Builder
@Document(indexName = "test-index-product-cdi-repository", replicas = 0,
refreshInterval = "-1")
@Document(indexName = "test-index-product-cdi-repository", replicas = 0, refreshInterval = "-1")
static class Product {
@Id private String id;
@@ -188,8 +188,7 @@ public class CdiRepositoryTests {
}
@Data
@Document(indexName = "test-index-person-cdi-repository", replicas = 0,
refreshInterval = "-1")
@Document(indexName = "test-index-person-cdi-repository", replicas = 0, refreshInterval = "-1")
static class Person {
@Id private String id;
@@ -206,8 +205,7 @@ public class CdiRepositoryTests {
@NoArgsConstructor
@AllArgsConstructor
@Builder
@Document(indexName = "test-index-book-cdi-repository", replicas = 0,
refreshInterval = "-1")
@Document(indexName = "test-index-book-cdi-repository", replicas = 0, refreshInterval = "-1")
static class Book {
@Id private String id;

View File

@@ -0,0 +1,3 @@
@org.springframework.lang.NonNullApi
@org.springframework.lang.NonNullFields
package org.springframework.data.elasticsearch.repositories.cdi;

View File

@@ -50,6 +50,7 @@ import org.springframework.data.elasticsearch.core.query.StringQuery;
import org.springframework.data.projection.SpelAwareProxyProjectionFactory;
import org.springframework.data.repository.Repository;
import org.springframework.data.repository.core.support.DefaultRepositoryMetadata;
import org.springframework.lang.Nullable;
/**
* @author Christoph Strobl
@@ -123,18 +124,15 @@ public class ElasticsearchStringQueryUnitTests {
* @author Artur Konczak
*/
@Document(indexName = "test-index-person-query-unittest", replicas = 0,
refreshInterval = "-1")
@Document(indexName = "test-index-person-query-unittest", replicas = 0, refreshInterval = "-1")
static class Person {
@Id private String id;
private String name;
@Field(type = FieldType.Nested) private List<Car> car;
@Field(type = FieldType.Nested, includeInParent = true) private List<Book> books;
@Nullable @Id private String id;
@Nullable private String name;
@Nullable @Field(type = FieldType.Nested) private List<Car> car;
@Nullable @Field(type = FieldType.Nested, includeInParent = true) private List<Book> books;
@Nullable
public String getId() {
return id;
}
@@ -143,6 +141,7 @@ public class ElasticsearchStringQueryUnitTests {
this.id = id;
}
@Nullable
public String getName() {
return name;
}
@@ -151,6 +150,7 @@ public class ElasticsearchStringQueryUnitTests {
this.name = name;
}
@Nullable
public List<Car> getCar() {
return car;
}
@@ -159,6 +159,7 @@ public class ElasticsearchStringQueryUnitTests {
this.car = car;
}
@Nullable
public List<Book> getBooks() {
return books;
}
@@ -178,8 +179,7 @@ public class ElasticsearchStringQueryUnitTests {
@NoArgsConstructor
@AllArgsConstructor
@Builder
@Document(indexName = "test-index-book-query-unittest", replicas = 0,
refreshInterval = "-1")
@Document(indexName = "test-index-book-query-unittest", replicas = 0, refreshInterval = "-1")
static class Book {
@Id private String id;
@@ -229,9 +229,10 @@ public class ElasticsearchStringQueryUnitTests {
*/
static class Author {
private String id;
private String name;
@Nullable private String id;
@Nullable private String name;
@Nullable
public String getId() {
return id;
}
@@ -240,6 +241,7 @@ public class ElasticsearchStringQueryUnitTests {
this.id = id;
}
@Nullable
public String getName() {
return name;
}

View File

@@ -48,6 +48,7 @@ import org.springframework.data.projection.ProjectionFactory;
import org.springframework.data.projection.SpelAwareProxyProjectionFactory;
import org.springframework.data.repository.Repository;
import org.springframework.data.repository.core.support.DefaultRepositoryMetadata;
import org.springframework.lang.Nullable;
/**
* @author Christoph Strobl
@@ -152,14 +153,15 @@ public class ReactiveElasticsearchQueryMethodUnitTests {
@Document(indexName = INDEX_NAME, replicas = 0, refreshInterval = "-1")
static class Person {
@Id private String id;
@Nullable @Id private String id;
private String name;
@Nullable private String name;
@Field(type = FieldType.Nested) private List<Car> car;
@Nullable @Field(type = FieldType.Nested) private List<Car> car;
@Field(type = FieldType.Nested, includeInParent = true) private List<Book> books;
@Nullable @Field(type = FieldType.Nested, includeInParent = true) private List<Book> books;
@Nullable
public String getId() {
return id;
}
@@ -168,6 +170,7 @@ public class ReactiveElasticsearchQueryMethodUnitTests {
this.id = id;
}
@Nullable
public String getName() {
return name;
}
@@ -176,6 +179,7 @@ public class ReactiveElasticsearchQueryMethodUnitTests {
this.name = name;
}
@Nullable
public List<Car> getCar() {
return car;
}
@@ -184,6 +188,7 @@ public class ReactiveElasticsearchQueryMethodUnitTests {
this.car = car;
}
@Nullable
public List<Book> getBooks() {
return books;
}
@@ -203,8 +208,7 @@ public class ReactiveElasticsearchQueryMethodUnitTests {
@NoArgsConstructor
@AllArgsConstructor
@Builder
@Document(indexName = "test-index-book-reactive-repository-query", replicas = 0,
refreshInterval = "-1")
@Document(indexName = "test-index-book-reactive-repository-query", replicas = 0, refreshInterval = "-1")
static class Book {
@Id private String id;
@@ -254,9 +258,10 @@ public class ReactiveElasticsearchQueryMethodUnitTests {
*/
static class Author {
private String id;
private String name;
@Nullable private String id;
@Nullable private String name;
@Nullable
public String getId() {
return id;
}
@@ -265,6 +270,7 @@ public class ReactiveElasticsearchQueryMethodUnitTests {
this.id = id;
}
@Nullable
public String getName() {
return name;
}

View File

@@ -55,6 +55,7 @@ import org.springframework.data.repository.Repository;
import org.springframework.data.repository.core.support.DefaultRepositoryMetadata;
import org.springframework.data.repository.query.QueryMethodEvaluationContextProvider;
import org.springframework.expression.spel.standard.SpelExpressionParser;
import org.springframework.lang.Nullable;
/**
* @author Christoph Strobl
@@ -175,18 +176,18 @@ public class ReactiveElasticsearchStringQueryUnitTests {
* @author Artur Konczak
*/
@Document(indexName = "test-index-person-reactive-repository-string-query", replicas = 0,
refreshInterval = "-1")
@Document(indexName = "test-index-person-reactive-repository-string-query", replicas = 0, refreshInterval = "-1")
public class Person {
@Id private String id;
@Nullable @Id private String id;
private String name;
@Nullable private String name;
@Field(type = FieldType.Nested) private List<Car> car;
@Nullable @Field(type = FieldType.Nested) private List<Car> car;
@Field(type = FieldType.Nested, includeInParent = true) private List<Book> books;
@Nullable @Field(type = FieldType.Nested, includeInParent = true) private List<Book> books;
@Nullable
public String getId() {
return id;
}
@@ -195,6 +196,7 @@ public class ReactiveElasticsearchStringQueryUnitTests {
this.id = id;
}
@Nullable
public String getName() {
return name;
}
@@ -203,6 +205,7 @@ public class ReactiveElasticsearchStringQueryUnitTests {
this.name = name;
}
@Nullable
public List<Car> getCar() {
return car;
}
@@ -211,6 +214,7 @@ public class ReactiveElasticsearchStringQueryUnitTests {
this.car = car;
}
@Nullable
public List<Book> getBooks() {
return books;
}
@@ -230,8 +234,7 @@ public class ReactiveElasticsearchStringQueryUnitTests {
@NoArgsConstructor
@AllArgsConstructor
@Builder
@Document(indexName = "test-index-book-reactive-repository-string-query", replicas = 0,
refreshInterval = "-1")
@Document(indexName = "test-index-book-reactive-repository-string-query", replicas = 0, refreshInterval = "-1")
static class Book {
@Id private String id;
@@ -281,9 +284,10 @@ public class ReactiveElasticsearchStringQueryUnitTests {
*/
static class Author {
private String id;
private String name;
@Nullable private String id;
@Nullable private String name;
@Nullable
public String getId() {
return id;
}
@@ -292,6 +296,7 @@ public class ReactiveElasticsearchStringQueryUnitTests {
this.id = id;
}
@Nullable
public String getName() {
return name;
}

View File

@@ -43,7 +43,7 @@ class StubParameterAccessor implements ElasticsearchParameterAccessor {
*/
@Override
public Pageable getPageable() {
return null;
return Pageable.unpaged();
}
/*
@@ -104,8 +104,8 @@ class StubParameterAccessor implements ElasticsearchParameterAccessor {
* (non-Javadoc)
* @see org.springframework.data.repository.query.ParameterAccessor#findDynamicProjection()
*/
@Override
public Class<?> findDynamicProjection() {
return null;
}
@Override
public Class<?> findDynamicProjection() {
return null;
}
}