2 * ============LICENSE_START=======================================================
\r 
   4 * ================================================================================
\r 
   5 * Copyright 2019 China Mobile
\r 
   6 *=================================================================================
\r 
   7 * Licensed under the Apache License, Version 2.0 (the "License");
\r 
   8 * you may not use this file except in compliance with the License.
\r 
   9 * You may obtain a copy of the License at
\r 
  11 *     http://www.apache.org/licenses/LICENSE-2.0
\r 
  13 * Unless required by applicable law or agreed to in writing, software
\r 
  14 * distributed under the License is distributed on an "AS IS" BASIS,
\r 
  15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r 
  16 * See the License for the specific language governing permissions and
\r 
  17 * limitations under the License.
\r 
  18 * ============LICENSE_END=========================================================
\r 
  20 package org.onap.datalake.feeder.repository;
\r 
  22 import org.onap.datalake.feeder.domain.Topic;
\r 
  23 import org.springframework.data.couchbase.core.query.N1qlPrimaryIndexed;
\r 
  24 import org.springframework.data.couchbase.core.query.Query;
\r 
  25 import org.springframework.data.couchbase.core.query.ViewIndexed;
\r 
  26 import org.springframework.data.couchbase.repository.CouchbasePagingAndSortingRepository;
\r 
  27 import org.springframework.data.domain.Page;
\r 
  28 import org.springframework.data.domain.Pageable;
\r 
  31 import java.util.List;
\r 
  35  * Topic Repository interface, implementation is taken care by Spring framework.
\r 
  36  * Customization is done through TopicRepositoryCustom and its implementation TopicRepositoryImpl. 
\r 
  38  * @author Guobiao Mo
\r 
  41 @ViewIndexed(designDoc = "topic", viewName = "all")
\r 
  42 public interface TopicRepository extends CouchbasePagingAndSortingRepository<Topic, String>, TopicRepositoryCustom {
\r 
  44         Topic findFirstById(String topic);
\r 
  46         Topic findByIdAndState(String topic, boolean state);
\r 
  48     //Supports native JSON query string
\r 
  49     @Query("{topic:'?0'}")
\r 
  50     Topic findTopicById(String topic);
\r 
  52     @Query("{topic: { $regex: ?0 } })")
\r 
  53     List<Topic> findTopicByRegExId(String topic);
\r 
  56     //Page<Topic> findByCompanyIdAndNameLikeOrderByName(String companyId, String name, Pageable pageable);
\r 
  58     @Query("#{#n1ql.selectEntity} where #{#n1ql.filter} and companyId = $1 and $2 within #{#n1ql.bucket}")
\r 
  59     Topic findByCompanyAndAreaId(String companyId, String areaId);
\r 
  61     @Query("#{#n1ql.selectEntity} where #{#n1ql.filter} AND ANY phone IN phoneNumbers SATISFIES phone = $1 END")
\r 
  62     List<Topic> findByPhoneNumber(String telephoneNumber);
\r 
  64     @Query("SELECT COUNT(*) AS count FROM #{#n1ql.bucket} WHERE #{#n1ql.filter} and companyId = $1")
\r 
  65     Long countBuildings(String companyId);
\r