multiple identical hub
[externalapi/nbi.git] / src / main / java / org / onap / nbi / apis / hub / model / Subscription.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.model;
17
18 import java.util.stream.Collectors;
19 import org.onap.nbi.commons.Resource;
20
21 public class Subscription implements Resource{
22
23
24     private String id;
25
26     private String callback;
27
28     private String query;
29
30     public Subscription(){
31
32     }
33
34     public Subscription(String id, String callback, String query) {
35         this.id = id;
36         this.callback = callback;
37         this.query = query;
38     }
39
40     public String getId() {
41         return id;
42     }
43
44     public void setId(String id) {
45         this.id = id;
46     }
47
48     public String getCallback() {
49         return callback;
50     }
51
52     public void setCallback(String callback) {
53         this.callback = callback;
54     }
55
56     public String getQuery() {
57         return query;
58     }
59
60     public void setQuery(String query) {
61         this.query = query;
62     }
63
64     public static Subscription createFromSubscriber(Subscriber subscriber) {
65         Subscription sub = new Subscription();
66         sub.setId(subscriber.getId());
67         sub.setCallback(subscriber.getCallback());
68
69         String query = subscriber.getQuery().entrySet()
70                 .stream()
71                 .map(entry -> entry.getKey()+ "=" + String.join(" ",entry.getValue()))
72                 .collect(Collectors.joining());
73
74         sub.setQuery(query);
75         return sub;
76     }
77 }