@@ -0,0 +1,2427 @@
+/*%0A * Copyright 2012-2016 the original author or authors.%0A *%0A * Licensed under the Apache License, Version 2.0 (the %22License%22);%0A * you may not use this file except in compliance with the License.%0A * You may obtain a copy of the License at%0A *%0A *      http://www.apache.org/licenses/LICENSE-2.0%0A *%0A * Unless required by applicable law or agreed to in writing, software%0A * distributed under the License is distributed on an %22AS IS%22 BASIS,%0A * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.%0A * See the License for the specific language governing permissions and%0A * limitations under the License.%0A */%0A%0Apackage sample.data.jpa.service;%0A%0Aimport sample.data.jpa.domain.City;%0Aimport sample.data.jpa.domain.HotelSummary;%0A%0Aimport org.springframework.data.domain.Page;%0Aimport org.springframework.data.domain.Pageable;%0Aimport org.springframework.stereotype.Component;%0Aimport org.springframework.transaction.annotation.Transactional;%0Aimport org.springframework.util.Assert;%0Aimport org.springframework.util.StringUtils;%0A%0A@Component(%22cityService%22)%0A@Transactional%0Aclass CityServiceImpl implements CityService %7B%0A%0A%09private final CityRepository cityRepository;%0A%0A%09private final HotelRepository hotelRepository;%0A%0A%09public CityServiceImpl(CityRepository cityRepository,%0A%09%09%09HotelRepository hotelRepository) %7B%0A%09%09this.cityRepository = cityRepository;%0A%09%09this.hotelRepository = hotelRepository;%0A%09%7D%0A%0A%09@Override%0A%09public Page%3CCity%3E findCities(CitySearchCriteria criteria, Pageable pageable) %7B%0A%0A%09%09Assert.notNull(criteria, %22Criteria must not be null%22);%0A%09%09String name = criteria.getName();%0A%0A%09%09if (!StringUtils.hasLength(name)) %7B%0A%09%09%09return this.cityRepository.findAll(null);%0A%09%09%7D%0A%0A%09%09String country = %22%22;%0A%09%09int splitPos = name.lastIndexOf(%22,%22);%0A%0A%09%09if (splitPos %3E= 0) %7B%0A%09%09%09country = name.substring(splitPos + 1);%0A%09%09%09name = name.substring(0, splitPos);%0A%09%09%7D%0A%0A%09%09return this.cityRepository%0A%09%09%09%09.findByNameContainingAndCountryContainingAllIgnoringCase(name.trim(),%0A%09%09%09%09%09%09country.trim(), pageable);%0A%09%7D%0A%0A%09@Override%0A%09public City getCity(String name, String country) %7B%0A%09%09Assert.notNull(name, %22Name must not be null%22);%0A%09%09Assert.notNull(country, %22Country must not be null%22);%0A%09%09return this.cityRepository.findByNameAndCountryAllIgnoringCase(name, country);%0A%09%7D%0A%0A%09@Override%0A%09public Page%3CHotelSummary%3E getHotels(City city, Pageable pageable) %7B%0A%09%09Assert.notNull(city, %22City must not be null%22);%0A%09%09return this.hotelRepository.findByCity(city, pageable);%0A%09%7D%0A%7D%0A

Create CityServiceImpl.java