null
nor of length 0.
26 | * Note: Will return true
for a CharSequence that purely consists of whitespace.
27 | * 28 | * StringUtils.hasLength(null) = false 29 | * StringUtils.hasLength("") = false 30 | * StringUtils.hasLength(" ") = true 31 | * StringUtils.hasLength("Hello") = true 32 | *33 | * 34 | * @param str the CharSequence to check (may be
null
)
35 | * @return true
if the CharSequence is not null and has length
36 | * @see #hasText(String)
37 | */
38 | public static boolean hasLength(CharSequence str) {
39 | return (str != null && str.length() > 0);
40 | }
41 |
42 |
43 | /**
44 | * Check that the given CharSequence is either null
or of length 0.
45 | * Note: Will return false
for a CharSequence that purely consists of whitespace.
46 | * 47 | * StringUtils.isEmpty(null) = true 48 | * StringUtils.isEmpty("") = true 49 | * StringUtils.isEmpty(" ") = false 50 | * StringUtils.isEmpty("Hello") = false 51 | *52 | * 53 | * @param str the CharSequence to check (may be
null
)
54 | * @return true
if the CharSequence is either null or has a zero length
55 | */
56 | public static boolean isEmpty(CharSequence str) {
57 | return !hasLength(str);
58 | }
59 |
60 |
61 | /**
62 | * Check whether the given CharSequence has actual text.
63 | * More specifically, returns true
if the string not null
,
64 | * its length is greater than 0, and it contains at least one non-whitespace character.
65 | * 66 | * StringUtils.hasText(null) = false 67 | * StringUtils.hasText("") = false 68 | * StringUtils.hasText(" ") = false 69 | * StringUtils.hasText("12345") = true 70 | * StringUtils.hasText(" 12345 ") = true 71 | *72 | * 73 | * @param str the CharSequence to check (may be
null
)
74 | * @return true
if the CharSequence is not null
,
75 | * its length is greater than 0, and it does not contain whitespace only
76 | * @see Character#isWhitespace
77 | */
78 | public static boolean hasText(CharSequence str) {
79 | if (!hasLength(str)) {
80 | return false;
81 | }
82 | int strLen = str.length();
83 | for (int i = 0; i < strLen; i++) {
84 | if (!Character.isWhitespace(str.charAt(i))) {
85 | return true;
86 | }
87 | }
88 | return false;
89 | }
90 |
91 | /**
92 | * Check whether the given String has actual text.
93 | * More specifically, returns true
if the string not null
,
94 | * its length is greater than 0, and it contains at least one non-whitespace character.
95 | *
96 | * @param str the String to check (may be null
)
97 | * @return true
if the String is not null
, its length is
98 | * greater than 0, and it does not contain whitespace only
99 | * @see #hasText(CharSequence)
100 | */
101 | public static boolean hasText(String str) {
102 | return hasText((CharSequence) str);
103 | }
104 | }
105 |
--------------------------------------------------------------------------------
/src/main/java/fr/pilato/demo/legacysearch/service/PersonService.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to Elasticsearch 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 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 | package fr.pilato.demo.legacysearch.service;
20 |
21 | import com.fasterxml.jackson.annotation.JsonIgnore;
22 | import com.fasterxml.jackson.core.JsonProcessingException;
23 | import com.fasterxml.jackson.databind.ObjectMapper;
24 | import com.github.dozermapper.core.Mapper;
25 | import fr.pilato.demo.legacysearch.dao.PersonRepository;
26 | import fr.pilato.demo.legacysearch.domain.Address;
27 | import fr.pilato.demo.legacysearch.domain.GeoPoint;
28 | import fr.pilato.demo.legacysearch.domain.Person;
29 | import fr.pilato.demo.legacysearch.helper.PersonGenerator;
30 | import fr.pilato.demo.legacysearch.helper.Strings;
31 | import fr.pilato.demo.legacysearch.webapp.InitResult;
32 | import fr.pilato.demo.legacysearch.webapp.PersonNotFoundException;
33 | import org.slf4j.Logger;
34 | import org.slf4j.LoggerFactory;
35 | import org.springframework.beans.factory.annotation.Value;
36 | import org.springframework.data.domain.Example;
37 | import org.springframework.data.domain.ExampleMatcher;
38 | import org.springframework.data.domain.Page;
39 | import org.springframework.data.domain.PageRequest;
40 | import org.springframework.stereotype.Service;
41 |
42 | import java.io.IOException;
43 | import java.util.ArrayList;
44 | import java.util.Collection;
45 | import java.util.Collections;
46 | import java.util.concurrent.atomic.AtomicInteger;
47 |
48 | import static org.springframework.data.domain.ExampleMatcher.GenericPropertyMatchers.contains;
49 |
50 | @Service
51 | public class PersonService {
52 | private final Logger logger = LoggerFactory.getLogger(PersonService.class);
53 |
54 | @Value("${app.batch.size:100}")
55 | private int batchSize;
56 |
57 | private final PersonRepository personRepository;
58 | private final ObjectMapper mapper;
59 | private final Mapper dozerBeanMapper;
60 |
61 | public PersonService(PersonRepository personRepository, ObjectMapper mapper,
62 | Mapper dozerBeanMapper) {
63 | this.personRepository = personRepository;
64 | this.mapper = mapper;
65 | this.dozerBeanMapper = dozerBeanMapper;
66 | }
67 |
68 | public Person get(Integer id) {
69 | Person person = personRepository.findById(id).orElseThrow(PersonNotFoundException::new);
70 | logger.debug("get({})={}", id, person);
71 | return person;
72 | }
73 |
74 | private Iterable35 | Found {{$ctrl.result.hits.total.value}} hits in 36 | {{$ctrl.result.took}} ms 37 |
38 |39 | {{$ctrl.error}} 40 |
41 |Name | 50 |Gender | 51 |Date Of Birth | 52 |Country | 53 |City | 54 |
---|---|---|---|---|
{{entry._source.name}} | 59 |{{entry._source.gender}} | 60 |{{entry._source.dateOfBirth}} | 61 |{{entry._source.address.country}} | 62 |{{entry._source.address.city}} | 63 |
17 | Found {{$ctrl.result.hits.total.value}} hits in 18 | {{$ctrl.result.took}} ms 19 |
20 |21 | {{$ctrl.error}} 22 |
23 |Country | 32 |Count | 33 |Per Year | 34 |||||||
---|---|---|---|---|---|---|---|---|
{{bucket.key}} | 39 |{{bucket.doc_count}} | 40 |
41 |
|
61 |
Name | 74 |Gender | 75 |Date Of Birth | 76 |Country | 77 |City | 78 |Score | 79 |
---|---|---|---|---|---|
{{entry._source.name}} | 84 |{{entry._source.gender}} | 85 |{{entry._source.dateOfBirth}} | 86 |{{entry._source.address.country}} | 87 |{{entry._source.address.city}} | 88 |{{entry._score}} | 89 |
17 | Found {{$ctrl.result.hits.total.value}} hits in 18 | {{$ctrl.result.took}} ms 19 | {{$ctrl.f_country}} 20 | {{$ctrl.f_date}} 21 |
22 |23 | {{$ctrl.error}} 24 |
25 |Country | 34 |Count | 35 |
---|---|
{{bucket.key}} | 40 |{{bucket.doc_count}} | 41 |
{{bucket.key}}0 | 50 |
---|
{{bucket.docs}} | 55 |
Name | 68 |Gender | 69 |Date Of Birth | 70 |Country | 71 |City | 72 |Score | 73 |
---|---|---|---|---|---|
{{entry._source.name}} | 78 |{{entry._source.gender}} | 79 |{{entry._source.dateOfBirth}} | 80 |{{entry._source.address.country}} | 81 |{{entry._source.address.city}} | 82 |{{entry._score}} | 83 |