Skip to content

Commit

Permalink
DATAES-46 - Apply code formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
mohsinh committed Jan 30, 2015
1 parent bb62148 commit d921372
Show file tree
Hide file tree
Showing 19 changed files with 147 additions and 157 deletions.
3 changes: 2 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?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>

<groupId>org.springframework.data</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@
@Inherited
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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,5 +53,4 @@
String[] ignoreFields() default {};

boolean includeInParent() default false;

}
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,9 @@ private QueryBuilder processCriteriaEntry(OperationKey key, Object value, String
}
QueryBuilder query = null;

String searchText = StringUtils.toString(value);
String searchText = StringUtils.toString(value);

switch (key) {
switch (key) {
case EQUALS:
query = queryString(searchText).field(fieldName);
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ static XContentBuilder buildMapping(Class clazz, String indexType, String idFiel
// 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();
}
Expand All @@ -95,7 +95,7 @@ private static void mapEntity(XContentBuilder xContentBuilder, Class clazz, bool
type = fieldType.toString().toLowerCase();
}
XContentBuilder t = xContentBuilder.startObject(nestedObjectFieldName).field(FIELD_TYPE, type);

if (nestedOrObjectField && FieldType.Nested == fieldType && fieldAnnotation.includeInParent()) {
t.field("include_in_parent", fieldAnnotation.includeInParent());
}
Expand All @@ -117,7 +117,7 @@ private static void mapEntity(XContentBuilder xContentBuilder, Class clazz, bool
continue;
}
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) {
continue;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,6 @@
import org.elasticsearch.action.search.SearchResponse;

public interface ResultsExtractor<T> {

T extract(SearchResponse response);
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,48 +10,48 @@
@JsonInclude(value = JsonInclude.Include.NON_NULL)
public class Completion {

private String[] input;
private String output;
private Integer weight;
private Object payload;

private Completion() {
//required by mapper to instantiate object
}

public Completion(String[] input) {
this.input = input;
}

public String[] getInput() {
return input;
}

public void setInput(String[] input) {
this.input = input;
}

public String getOutput() {
return output;
}

public void setOutput(String output) {
this.output = output;
}

public Object getPayload() {
return payload;
}

public void setPayload(Object payload) {
this.payload = payload;
}

public Integer getWeight() {
return weight;
}

public void setWeight(Integer weight) {
this.weight = weight;
}
private String[] input;
private String output;
private Integer weight;
private Object payload;

private Completion() {
//required by mapper to instantiate object
}

public Completion(String[] input) {
this.input = input;
}

public String[] getInput() {
return input;
}

public void setInput(String[] input) {
this.input = input;
}

public String getOutput() {
return output;
}

public void setOutput(String output) {
this.output = output;
}

public Object getPayload() {
return payload;
}

public void setPayload(Object payload) {
this.payload = payload;
}

public Integer getWeight() {
return weight;
}

public void setWeight(Integer weight) {
this.weight = weight;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ public Criteria or(String fieldName) {
* @return
*/
public Criteria is(Object o) {
queryCriteria.add(new CriteriaEntry(OperationKey.EQUALS, o));
queryCriteria.add(new CriteriaEntry(OperationKey.EQUALS, o));
return this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@ public class ElasticsearchRepositoryBean<T> extends CdiRepositoryBean<T> {
* @param repositoryType 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
* {@link CustomRepositoryImplementationDetector}, can be {@literal null}.
* {@link CustomRepositoryImplementationDetector}, can be {@literal null}.
*/
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);

Assert.notNull(operations, "Cannot create repository with 'null' for ElasticsearchOperations.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ void afterBeanDiscovery(@Observes AfterBeanDiscovery afterBeanDiscovery, BeanMan
}

private <T> CdiRepositoryBean<T> createRepositoryBean(Class<T> repositoryType, Set<Annotation> qualifiers,
BeanManager beanManager) {
BeanManager beanManager) {

Bean<ElasticsearchOperations> elasticsearchOperationsBean = this.elasticsearchOperationsMap.get(qualifiers
.toString());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ protected CriteriaQuery complete(CriteriaQuery query, Sort sort) {
}

private Criteria from(Part part, Criteria instance, Iterator<?> parameters) {
Part.Type type = part.getType();
Part.Type type = part.getType();

Criteria criteria = instance;
if (criteria == null) {
Expand Down Expand Up @@ -126,24 +126,24 @@ private Criteria from(Part part, Criteria instance, Iterator<?> parameters) {
return criteria.in(asArray(parameters.next()));
case NOT_IN:
return criteria.in(asArray(parameters.next())).not();
case SIMPLE_PROPERTY:
case SIMPLE_PROPERTY:
case WITHIN: {
Object firstParameter = parameters.next();
Object secondParameter = null;
if(type == Part.Type.SIMPLE_PROPERTY) {
if(part.getProperty().getType() != GeoPoint.class)
return criteria.is(firstParameter);
else {
// 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
// as argument we use a "geo distance" query with a distance of one meter.
secondParameter = ".001km";
}
} else {
secondParameter = parameters.next();
}

if (firstParameter instanceof GeoPoint && secondParameter instanceof String)
if (type == Part.Type.SIMPLE_PROPERTY) {
if (part.getProperty().getType() != GeoPoint.class)
return criteria.is(firstParameter);
else {
// 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
// as argument we use a "geo distance" query with a distance of one meter.
secondParameter = ".001km";
}
} else {
secondParameter = parameters.next();
}

if (firstParameter instanceof GeoPoint && secondParameter instanceof String)
return criteria.within((GeoPoint) firstParameter, (String) secondParameter);

if (firstParameter instanceof Point && secondParameter instanceof Distance)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,11 +168,11 @@ public void shouldIndexMultipleLevelNestedObjectWithIncludeInParent() {

final Map mapping = elasticsearchTemplate.getMapping(PersonMultipleLevelNested.class);

assertThat(mapping,is(notNullValue()));
assertThat(mapping, is(notNullValue()));
final Map propertyMap = (Map) mapping.get("properties");
assertThat(propertyMap,is(notNullValue()));
assertThat(propertyMap, is(notNullValue()));
final Map bestCarsAttributes = (Map) propertyMap.get("bestCars");
assertThat(bestCarsAttributes.get("include_in_parent"),is(notNullValue()));
assertThat(bestCarsAttributes.get("include_in_parent"), is(notNullValue()));
}


Expand All @@ -189,11 +189,11 @@ public void shouldSearchUsingNestedQueryOnMultipleLevelNestedObject() {
//then
final BoolQueryBuilder builder = boolQuery();
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()
.withQuery(builder)
.build();
.withQuery(builder)
.build();

final Page<PersonMultipleLevelNested> personIndexed = elasticsearchTemplate.queryForPage(searchQuery, PersonMultipleLevelNested.class);
assertThat(personIndexed, is(notNullValue()));
Expand Down Expand Up @@ -375,8 +375,8 @@ public void shouldIndexAndSearchMapAsNestedType() {
elasticsearchTemplate.refresh(Book.class, true);
//then
final SearchQuery searchQuery = new NativeSearchQueryBuilder()
.withQuery(nestedQuery("buckets", termQuery("buckets.1", "test3")))
.build();
.withQuery(nestedQuery("buckets", termQuery("buckets.1", "test3")))
.build();
final Page<Book> books = elasticsearchTemplate.queryForPage(searchQuery, Book.class);

assertThat(books.getContent().size(), is(1));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ public void shouldFindSuggestionsForGivenCriteriaQueryUsingCompletionEntity() {
assertThat(options.size(), is(2));
assertThat(options.get(0).getText().string(), isOneOf("Marchand", "Mohsin Husen"));
assertThat(options.get(1).getText().string(), isOneOf("Marchand", "Mohsin Husen"));
}
}

@Test
public void shouldFindSuggestionsForGivenCriteriaQueryUsingAnnotatedCompletionEntity() {
Expand All @@ -171,8 +171,8 @@ public void shouldFindSuggestionsForGivenCriteriaQueryUsingAnnotatedCompletionEn

//then
assertThat(options.size(), is(2));
assertThat(options.get(0).getText().string(), isOneOf("Marchand","Mohsin Husen"));
assertThat(options.get(1).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"));
}

@Test
Expand All @@ -193,14 +193,11 @@ public void shouldFindSuggestionsWithPayloadsForGivenCriteriaQueryUsingAnnotated
for (CompletionSuggestion.Entry.Option option : options) {
if (option.getText().string().equals("Mewes Kochheim1")) {
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());
}
else if (option.getText().string().equals("Mewes Kochheim3")) {
} else if (option.getText().string().equals("Mewes Kochheim3")) {
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("test", option.getPayloadAsMap().get("someField2"));
} else {
Expand All @@ -227,14 +224,11 @@ public void shouldFindSuggestionsWithWeightsForGivenCriteriaQueryUsingAnnotatedC
for (CompletionSuggestion.Entry.Option option : options) {
if (option.getText().string().equals("Mewes Kochheim1")) {
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);
}
else if (option.getText().string().equals("Mewes Kochheim3")) {
} else if (option.getText().string().equals("Mewes Kochheim3")) {
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);
} else {
fail("Unexpected option");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,4 @@ public Date getCreatedDate() {
public void setCreatedDate(Date createdDate) {
this.createdDate = createdDate;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public class Person {
@Field(type = FieldType.Nested)
private List<Car> car;

@Field(type = FieldType.Nested, includeInParent=true)
@Field(type = FieldType.Nested, includeInParent = true)
private List<Book> books;

public String getId() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public class PersonMultipleLevelNested {
@Field(type = FieldType.Nested)
private List<Car> cars;

@Field(type = FieldType.Nested, includeInParent=true)
@Field(type = FieldType.Nested, includeInParent = true)
private List<Car> bestCars;

public String getId() {
Expand Down Expand Up @@ -85,5 +85,4 @@ public List<Car> getBestCars() {
public void setBestCars(List<Car> bestCars) {
this.bestCars = bestCars;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,4 @@ public String getMessage() {
public void setMessage(String message) {
this.message = message;
}


}
Loading

0 comments on commit d921372

Please sign in to comment.