9799e4895736efa49aa9b362f7a5cfe756582064
[externalapi/nbi.git] / src / main / java / org / onap / nbi / apis / hub / repository / SubscriberRepositoryImpl.java
1 /**
2  *     Copyright (c) 2018 Orange
3  *
4  *     Licensed under the Apache License, Version 2.0 (the "License");
5  *     you may not use this file except in compliance with the License.
6  *     You may obtain a copy of the License at
7  *
8  *         http://www.apache.org/licenses/LICENSE-2.0
9  *
10  *     Unless required by applicable law or agreed to in writing, software
11  *     distributed under the License is distributed on an "AS IS" BASIS,
12  *     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  *     See the License for the specific language governing permissions and
14  *     limitations under the License.
15  */
16 package org.onap.nbi.apis.hub.repository;
17
18 import org.onap.nbi.apis.hub.model.Event;
19 import org.onap.nbi.apis.hub.model.Subscriber;
20 import org.onap.nbi.apis.hub.service.CriteriaBuilder;
21 import org.springframework.beans.factory.annotation.Autowired;
22 import org.springframework.data.mongodb.core.MongoOperations;
23 import org.springframework.data.mongodb.core.query.Criteria;
24 import org.springframework.data.mongodb.core.query.Query;
25
26 import java.util.List;
27
28 public class SubscriberRepositoryImpl implements SubscriberFinder {
29     @Autowired
30     private MongoOperations mongoOperations;
31
32     @Autowired
33     private CriteriaBuilder criteriaBuilder;
34
35     @Override
36     public List<Subscriber> findSubscribersUsingEvent(Event event) {
37         Criteria criteria = new Criteria();
38         criteria.and("query.eventType").is(event.getEventType());
39         criteriaBuilder.adjust(criteria, event);
40         return mongoOperations.find(new Query(criteria), Subscriber.class);
41     }
42 }