DATAES-46 - Apply code formatting

This commit is contained in:
Mohsin Husen 2015-01-30 17:19:06 +00:00
parent bb62148bb7
commit d92137247f
19 changed files with 130 additions and 140 deletions

View File

@ -1,5 +1,6 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?> <?xml version="1.0" encoding="UTF-8" standalone="no"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<groupId>org.springframework.data</groupId> <groupId>org.springframework.data</groupId>

View File

@ -28,15 +28,15 @@ import java.lang.annotation.*;
@Inherited @Inherited
public @interface CompletionField { public @interface CompletionField {
String searchAnalyzer() default "simple"; String searchAnalyzer() default "simple";
String indexAnalyzer() default "simple"; String indexAnalyzer() default "simple";
boolean payloads() default false; boolean payloads() default false;
boolean preserveSeparators() default true; boolean preserveSeparators() default true;
boolean preservePositionIncrements() default true; boolean preservePositionIncrements() default true;
int maxInputLength() default 50; int maxInputLength() default 50;
} }

View File

@ -53,5 +53,4 @@ public @interface Field {
String[] ignoreFields() default {}; String[] ignoreFields() default {};
boolean includeInParent() default false; boolean includeInParent() default false;
} }

View File

@ -118,9 +118,9 @@ class CriteriaQueryProcessor {
} }
QueryBuilder query = null; QueryBuilder query = null;
String searchText = StringUtils.toString(value); String searchText = StringUtils.toString(value);
switch (key) { switch (key) {
case EQUALS: case EQUALS:
query = queryString(searchText).field(fieldName); query = queryString(searchText).field(fieldName);
break; break;

View File

@ -79,7 +79,7 @@ class MappingBuilder {
// Properties // Properties
XContentBuilder xContentBuilder = mapping.startObject(FIELD_PROPERTIES); XContentBuilder xContentBuilder = mapping.startObject(FIELD_PROPERTIES);
mapEntity(xContentBuilder, clazz, true, idFieldName, EMPTY, false, FieldType.Auto,null); mapEntity(xContentBuilder, clazz, true, idFieldName, EMPTY, false, FieldType.Auto, null);
return xContentBuilder.endObject().endObject().endObject(); return xContentBuilder.endObject().endObject().endObject();
} }
@ -95,7 +95,7 @@ class MappingBuilder {
type = fieldType.toString().toLowerCase(); type = fieldType.toString().toLowerCase();
} }
XContentBuilder t = xContentBuilder.startObject(nestedObjectFieldName).field(FIELD_TYPE, type); XContentBuilder t = xContentBuilder.startObject(nestedObjectFieldName).field(FIELD_TYPE, type);
if (nestedOrObjectField && FieldType.Nested == fieldType && fieldAnnotation.includeInParent()) { if (nestedOrObjectField && FieldType.Nested == fieldType && fieldAnnotation.includeInParent()) {
t.field("include_in_parent", fieldAnnotation.includeInParent()); t.field("include_in_parent", fieldAnnotation.includeInParent());
} }
@ -117,7 +117,7 @@ class MappingBuilder {
continue; continue;
} }
boolean nestedOrObject = isNestedOrObjectField(field); boolean nestedOrObject = isNestedOrObjectField(field);
mapEntity(xContentBuilder, getFieldType(field), false, EMPTY, field.getName(), nestedOrObject, singleField.type(),field.getAnnotation(Field.class)); mapEntity(xContentBuilder, getFieldType(field), false, EMPTY, field.getName(), nestedOrObject, singleField.type(), field.getAnnotation(Field.class));
if (nestedOrObject) { if (nestedOrObject) {
continue; continue;
} }

View File

@ -19,5 +19,6 @@ package org.springframework.data.elasticsearch.core;
import org.elasticsearch.action.search.SearchResponse; import org.elasticsearch.action.search.SearchResponse;
public interface ResultsExtractor<T> { public interface ResultsExtractor<T> {
T extract(SearchResponse response); T extract(SearchResponse response);
} }

View File

@ -10,48 +10,48 @@ import com.fasterxml.jackson.annotation.JsonInclude;
@JsonInclude(value = JsonInclude.Include.NON_NULL) @JsonInclude(value = JsonInclude.Include.NON_NULL)
public class Completion { public class Completion {
private String[] input; private String[] input;
private String output; private String output;
private Integer weight; private Integer weight;
private Object payload; private Object payload;
private Completion() { private Completion() {
//required by mapper to instantiate object //required by mapper to instantiate object
} }
public Completion(String[] input) { public Completion(String[] input) {
this.input = input; this.input = input;
} }
public String[] getInput() { public String[] getInput() {
return input; return input;
} }
public void setInput(String[] input) { public void setInput(String[] input) {
this.input = input; this.input = input;
} }
public String getOutput() { public String getOutput() {
return output; return output;
} }
public void setOutput(String output) { public void setOutput(String output) {
this.output = output; this.output = output;
} }
public Object getPayload() { public Object getPayload() {
return payload; return payload;
} }
public void setPayload(Object payload) { public void setPayload(Object payload) {
this.payload = payload; this.payload = payload;
} }
public Integer getWeight() { public Integer getWeight() {
return weight; return weight;
} }
public void setWeight(Integer weight) { public void setWeight(Integer weight) {
this.weight = weight; this.weight = weight;
} }
} }

View File

@ -193,7 +193,7 @@ public class Criteria {
* @return * @return
*/ */
public Criteria is(Object o) { public Criteria is(Object o) {
queryCriteria.add(new CriteriaEntry(OperationKey.EQUALS, o)); queryCriteria.add(new CriteriaEntry(OperationKey.EQUALS, o));
return this; return this;
} }

View File

@ -46,10 +46,10 @@ public class ElasticsearchRepositoryBean<T> extends CdiRepositoryBean<T> {
* @param repositoryType must not be {@literal null}. * @param repositoryType must not be {@literal null}.
* @param beanManager must not be {@literal null}. * @param beanManager must not be {@literal null}.
* @param detector detector for the custom {@link org.springframework.data.repository.Repository} implementations * @param detector detector for the custom {@link org.springframework.data.repository.Repository} implementations
* {@link CustomRepositoryImplementationDetector}, can be {@literal null}. * {@link CustomRepositoryImplementationDetector}, can be {@literal null}.
*/ */
public ElasticsearchRepositoryBean(Bean<ElasticsearchOperations> operations, Set<Annotation> qualifiers, public ElasticsearchRepositoryBean(Bean<ElasticsearchOperations> operations, Set<Annotation> qualifiers,
Class<T> repositoryType, BeanManager beanManager, CustomRepositoryImplementationDetector detector) { Class<T> repositoryType, BeanManager beanManager, CustomRepositoryImplementationDetector detector) {
super(qualifiers, repositoryType, beanManager, detector); super(qualifiers, repositoryType, beanManager, detector);
Assert.notNull(operations, "Cannot create repository with 'null' for ElasticsearchOperations."); Assert.notNull(operations, "Cannot create repository with 'null' for ElasticsearchOperations.");

View File

@ -67,7 +67,7 @@ public class ElasticsearchRepositoryExtension extends CdiRepositoryExtensionSupp
} }
private <T> CdiRepositoryBean<T> createRepositoryBean(Class<T> repositoryType, Set<Annotation> qualifiers, private <T> CdiRepositoryBean<T> createRepositoryBean(Class<T> repositoryType, Set<Annotation> qualifiers,
BeanManager beanManager) { BeanManager beanManager) {
Bean<ElasticsearchOperations> elasticsearchOperationsBean = this.elasticsearchOperationsMap.get(qualifiers Bean<ElasticsearchOperations> elasticsearchOperationsBean = this.elasticsearchOperationsMap.get(qualifiers
.toString()); .toString());

View File

@ -90,7 +90,7 @@ public class ElasticsearchQueryCreator extends AbstractQueryCreator<CriteriaQuer
} }
private Criteria from(Part part, Criteria instance, Iterator<?> parameters) { private Criteria from(Part part, Criteria instance, Iterator<?> parameters) {
Part.Type type = part.getType(); Part.Type type = part.getType();
Criteria criteria = instance; Criteria criteria = instance;
if (criteria == null) { if (criteria == null) {
@ -126,24 +126,24 @@ public class ElasticsearchQueryCreator extends AbstractQueryCreator<CriteriaQuer
return criteria.in(asArray(parameters.next())); return criteria.in(asArray(parameters.next()));
case NOT_IN: case NOT_IN:
return criteria.in(asArray(parameters.next())).not(); return criteria.in(asArray(parameters.next())).not();
case SIMPLE_PROPERTY: case SIMPLE_PROPERTY:
case WITHIN: { case WITHIN: {
Object firstParameter = parameters.next(); Object firstParameter = parameters.next();
Object secondParameter = null; Object secondParameter = null;
if(type == Part.Type.SIMPLE_PROPERTY) { if (type == Part.Type.SIMPLE_PROPERTY) {
if(part.getProperty().getType() != GeoPoint.class) if (part.getProperty().getType() != GeoPoint.class)
return criteria.is(firstParameter); return criteria.is(firstParameter);
else { else {
// it means it's a simple find with exact geopoint matching (e.g. findByLocation) // it means it's a simple find with exact geopoint matching (e.g. findByLocation)
// and because Elasticsearch does not have any kind of query with just a geopoint // and because Elasticsearch does not have any kind of query with just a geopoint
// as argument we use a "geo distance" query with a distance of one meter. // as argument we use a "geo distance" query with a distance of one meter.
secondParameter = ".001km"; secondParameter = ".001km";
} }
} else { } else {
secondParameter = parameters.next(); secondParameter = parameters.next();
} }
if (firstParameter instanceof GeoPoint && secondParameter instanceof String) if (firstParameter instanceof GeoPoint && secondParameter instanceof String)
return criteria.within((GeoPoint) firstParameter, (String) secondParameter); return criteria.within((GeoPoint) firstParameter, (String) secondParameter);
if (firstParameter instanceof Point && secondParameter instanceof Distance) if (firstParameter instanceof Point && secondParameter instanceof Distance)

View File

@ -168,11 +168,11 @@ public class NestedObjectTests {
final Map mapping = elasticsearchTemplate.getMapping(PersonMultipleLevelNested.class); final Map mapping = elasticsearchTemplate.getMapping(PersonMultipleLevelNested.class);
assertThat(mapping,is(notNullValue())); assertThat(mapping, is(notNullValue()));
final Map propertyMap = (Map) mapping.get("properties"); final Map propertyMap = (Map) mapping.get("properties");
assertThat(propertyMap,is(notNullValue())); assertThat(propertyMap, is(notNullValue()));
final Map bestCarsAttributes = (Map) propertyMap.get("bestCars"); final Map bestCarsAttributes = (Map) propertyMap.get("bestCars");
assertThat(bestCarsAttributes.get("include_in_parent"),is(notNullValue())); assertThat(bestCarsAttributes.get("include_in_parent"), is(notNullValue()));
} }
@ -189,11 +189,11 @@ public class NestedObjectTests {
//then //then
final BoolQueryBuilder builder = boolQuery(); final BoolQueryBuilder builder = boolQuery();
builder.must(nestedQuery("girlFriends", termQuery("girlFriends.type", "temp"))) builder.must(nestedQuery("girlFriends", termQuery("girlFriends.type", "temp")))
.must(nestedQuery("girlFriends.cars", termQuery("girlFriends.cars.name", "Ford".toLowerCase()))); .must(nestedQuery("girlFriends.cars", termQuery("girlFriends.cars.name", "Ford".toLowerCase())));
final SearchQuery searchQuery = new NativeSearchQueryBuilder() final SearchQuery searchQuery = new NativeSearchQueryBuilder()
.withQuery(builder) .withQuery(builder)
.build(); .build();
final Page<PersonMultipleLevelNested> personIndexed = elasticsearchTemplate.queryForPage(searchQuery, PersonMultipleLevelNested.class); final Page<PersonMultipleLevelNested> personIndexed = elasticsearchTemplate.queryForPage(searchQuery, PersonMultipleLevelNested.class);
assertThat(personIndexed, is(notNullValue())); assertThat(personIndexed, is(notNullValue()));
@ -375,8 +375,8 @@ public class NestedObjectTests {
elasticsearchTemplate.refresh(Book.class, true); elasticsearchTemplate.refresh(Book.class, true);
//then //then
final SearchQuery searchQuery = new NativeSearchQueryBuilder() final SearchQuery searchQuery = new NativeSearchQueryBuilder()
.withQuery(nestedQuery("buckets", termQuery("buckets.1", "test3"))) .withQuery(nestedQuery("buckets", termQuery("buckets.1", "test3")))
.build(); .build();
final Page<Book> books = elasticsearchTemplate.queryForPage(searchQuery, Book.class); final Page<Book> books = elasticsearchTemplate.queryForPage(searchQuery, Book.class);
assertThat(books.getContent().size(), is(1)); assertThat(books.getContent().size(), is(1));

View File

@ -154,7 +154,7 @@ public class ElasticsearchTemplateCompletionTests {
assertThat(options.size(), is(2)); assertThat(options.size(), is(2));
assertThat(options.get(0).getText().string(), isOneOf("Marchand", "Mohsin Husen")); assertThat(options.get(0).getText().string(), isOneOf("Marchand", "Mohsin Husen"));
assertThat(options.get(1).getText().string(), isOneOf("Marchand", "Mohsin Husen")); assertThat(options.get(1).getText().string(), isOneOf("Marchand", "Mohsin Husen"));
} }
@Test @Test
public void shouldFindSuggestionsForGivenCriteriaQueryUsingAnnotatedCompletionEntity() { public void shouldFindSuggestionsForGivenCriteriaQueryUsingAnnotatedCompletionEntity() {
@ -171,8 +171,8 @@ public class ElasticsearchTemplateCompletionTests {
//then //then
assertThat(options.size(), is(2)); assertThat(options.size(), is(2));
assertThat(options.get(0).getText().string(), isOneOf("Marchand","Mohsin Husen")); assertThat(options.get(0).getText().string(), isOneOf("Marchand", "Mohsin Husen"));
assertThat(options.get(1).getText().string(), isOneOf("Marchand","Mohsin Husen")); assertThat(options.get(1).getText().string(), isOneOf("Marchand", "Mohsin Husen"));
} }
@Test @Test
@ -193,14 +193,11 @@ public class ElasticsearchTemplateCompletionTests {
for (CompletionSuggestion.Entry.Option option : options) { for (CompletionSuggestion.Entry.Option option : options) {
if (option.getText().string().equals("Mewes Kochheim1")) { if (option.getText().string().equals("Mewes Kochheim1")) {
assertEquals(Double.MAX_VALUE, option.getPayloadAsDouble(), 0); assertEquals(Double.MAX_VALUE, option.getPayloadAsDouble(), 0);
} } else if (option.getText().string().equals("Mewes Kochheim2")) {
else if (option.getText().string().equals("Mewes Kochheim2")) {
assertEquals(Long.MAX_VALUE, option.getPayloadAsLong()); assertEquals(Long.MAX_VALUE, option.getPayloadAsLong());
} } else if (option.getText().string().equals("Mewes Kochheim3")) {
else if (option.getText().string().equals("Mewes Kochheim3")) {
assertEquals("Payload test", option.getPayloadAsString()); assertEquals("Payload test", option.getPayloadAsString());
} } else if (option.getText().string().equals("Mewes Kochheim4")) {
else if (option.getText().string().equals("Mewes Kochheim4")) {
assertEquals("Payload", option.getPayloadAsMap().get("someField1")); assertEquals("Payload", option.getPayloadAsMap().get("someField1"));
assertEquals("test", option.getPayloadAsMap().get("someField2")); assertEquals("test", option.getPayloadAsMap().get("someField2"));
} else { } else {
@ -227,14 +224,11 @@ public class ElasticsearchTemplateCompletionTests {
for (CompletionSuggestion.Entry.Option option : options) { for (CompletionSuggestion.Entry.Option option : options) {
if (option.getText().string().equals("Mewes Kochheim1")) { if (option.getText().string().equals("Mewes Kochheim1")) {
assertEquals(4, option.getScore(), 0); assertEquals(4, option.getScore(), 0);
} } else if (option.getText().string().equals("Mewes Kochheim2")) {
else if (option.getText().string().equals("Mewes Kochheim2")) {
assertEquals(0, option.getScore(), 0); assertEquals(0, option.getScore(), 0);
} } else if (option.getText().string().equals("Mewes Kochheim3")) {
else if (option.getText().string().equals("Mewes Kochheim3")) {
assertEquals(1, option.getScore(), 0); assertEquals(1, option.getScore(), 0);
} } else if (option.getText().string().equals("Mewes Kochheim4")) {
else if (option.getText().string().equals("Mewes Kochheim4")) {
assertEquals(Integer.MAX_VALUE, option.getScore(), 0); assertEquals(Integer.MAX_VALUE, option.getScore(), 0);
} else { } else {
fail("Unexpected option"); fail("Unexpected option");

View File

@ -48,5 +48,4 @@ public class AbstractInheritedEntity {
public void setCreatedDate(Date createdDate) { public void setCreatedDate(Date createdDate) {
this.createdDate = createdDate; this.createdDate = createdDate;
} }
} }

View File

@ -40,7 +40,7 @@ public class Person {
@Field(type = FieldType.Nested) @Field(type = FieldType.Nested)
private List<Car> car; private List<Car> car;
@Field(type = FieldType.Nested, includeInParent=true) @Field(type = FieldType.Nested, includeInParent = true)
private List<Book> books; private List<Book> books;
public String getId() { public String getId() {

View File

@ -43,7 +43,7 @@ public class PersonMultipleLevelNested {
@Field(type = FieldType.Nested) @Field(type = FieldType.Nested)
private List<Car> cars; private List<Car> cars;
@Field(type = FieldType.Nested, includeInParent=true) @Field(type = FieldType.Nested, includeInParent = true)
private List<Car> bestCars; private List<Car> bestCars;
public String getId() { public String getId() {
@ -85,5 +85,4 @@ public class PersonMultipleLevelNested {
public void setBestCars(List<Car> bestCars) { public void setBestCars(List<Car> bestCars) {
this.bestCars = bestCars; this.bestCars = bestCars;
} }
} }

View File

@ -37,6 +37,4 @@ public class SampleInheritedEntity extends AbstractInheritedEntity {
public void setMessage(String message) { public void setMessage(String message) {
this.message = message; this.message = message;
} }
} }

View File

@ -495,54 +495,55 @@ public class CustomMethodRepositoryTests {
assertThat(sampleEntities.size(), is(1)); assertThat(sampleEntities.size(), is(1));
} }
@Test @Test
public void shouldExecuteCustomMethodWithGeoPoint() { public void shouldExecuteCustomMethodWithGeoPoint() {
// given // given
String documentId = randomNumeric(5); String documentId = randomNumeric(5);
SampleEntity sampleEntity = new SampleEntity(); SampleEntity sampleEntity = new SampleEntity();
sampleEntity.setId(documentId); sampleEntity.setId(documentId);
sampleEntity.setType("test"); sampleEntity.setType("test");
sampleEntity.setRate(10); sampleEntity.setRate(10);
sampleEntity.setMessage("foo"); sampleEntity.setMessage("foo");
sampleEntity.setLocation(new GeoPoint(45.7806d, 3.0875d)); sampleEntity.setLocation(new GeoPoint(45.7806d, 3.0875d));
repository.save(sampleEntity); repository.save(sampleEntity);
// when // when
Page<SampleEntity> page = repository.findByLocation(new GeoPoint(45.7806d, 3.0875d), new PageRequest(0, 10)); Page<SampleEntity> page = repository.findByLocation(new GeoPoint(45.7806d, 3.0875d), new PageRequest(0, 10));
// then // then
assertThat(page, is(notNullValue())); assertThat(page, is(notNullValue()));
assertThat(page.getTotalElements(), is(equalTo(1L))); assertThat(page.getTotalElements(), is(equalTo(1L)));
} }
@Test
public void shouldExecuteCustomMethodWithGeoPointAndString() {
// given
String documentId = randomNumeric(5);
SampleEntity sampleEntity = new SampleEntity();
sampleEntity.setId(documentId);
sampleEntity.setType("test");
sampleEntity.setRate(10);
sampleEntity.setMessage("foo");
sampleEntity.setLocation(new GeoPoint(45.7806d, 3.0875d));
repository.save(sampleEntity); @Test
public void shouldExecuteCustomMethodWithGeoPointAndString() {
// given
String documentId = randomNumeric(5);
SampleEntity sampleEntity = new SampleEntity();
sampleEntity.setId(documentId);
sampleEntity.setType("test");
sampleEntity.setRate(10);
sampleEntity.setMessage("foo");
sampleEntity.setLocation(new GeoPoint(45.7806d, 3.0875d));
documentId = randomNumeric(5); repository.save(sampleEntity);
sampleEntity = new SampleEntity();
sampleEntity.setId(documentId);
sampleEntity.setType("test");
sampleEntity.setRate(10);
sampleEntity.setMessage("foo");
sampleEntity.setLocation(new GeoPoint(48.7806d, 3.0875d));
repository.save(sampleEntity); documentId = randomNumeric(5);
sampleEntity = new SampleEntity();
sampleEntity.setId(documentId);
sampleEntity.setType("test");
sampleEntity.setRate(10);
sampleEntity.setMessage("foo");
sampleEntity.setLocation(new GeoPoint(48.7806d, 3.0875d));
// when repository.save(sampleEntity);
Page<SampleEntity> page = repository.findByLocationAndMessage(new GeoPoint(45.7806d, 3.0875d), "foo", new PageRequest(0, 10));
// then // when
assertThat(page, is(notNullValue())); Page<SampleEntity> page = repository.findByLocationAndMessage(new GeoPoint(45.7806d, 3.0875d), "foo", new PageRequest(0, 10));
assertThat(page.getTotalElements(), is(equalTo(1L))); // then
} assertThat(page, is(notNullValue()));
assertThat(page.getTotalElements(), is(equalTo(1L)));
}
@Test @Test
public void shouldExecuteCustomMethodWithWithinGeoPoint() { public void shouldExecuteCustomMethodWithWithinGeoPoint() {
@ -1173,6 +1174,5 @@ public class CustomMethodRepositoryTests {
// then // then
assertThat(count, is(equalTo(1L))); assertThat(count, is(equalTo(1L)));
} }
} }

View File

@ -75,7 +75,7 @@ public interface SampleCustomMethodRepository extends ElasticsearchRepository<Sa
Page<SampleEntity> findByLocationAndMessage(GeoPoint point, String msg, Pageable pageable); Page<SampleEntity> findByLocationAndMessage(GeoPoint point, String msg, Pageable pageable);
Page<SampleEntity> findByLocationWithin(GeoPoint point, String distance, Pageable pageable); Page<SampleEntity> findByLocationWithin(GeoPoint point, String distance, Pageable pageable);
Page<SampleEntity> findByLocationWithin(Point point, Distance distance, Pageable pageable); Page<SampleEntity> findByLocationWithin(Point point, Distance distance, Pageable pageable);
@ -126,5 +126,4 @@ public interface SampleCustomMethodRepository extends ElasticsearchRepository<Sa
long countByLocationNear(Point point, Distance distance); long countByLocationNear(Point point, Distance distance);
long countByLocationNear(GeoPoint point, String distance); long countByLocationNear(GeoPoint point, String distance);
} }