646d39b87666515f03c0791be10b1669acec2dec
[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     private String ewId;
30     private String ewHost;
31
32     public void setEwHost(String ewHost) {
33         this.ewHost = ewHost;
34     }
35
36     public String getEwId() {
37         return ewId;
38     }
39
40     public void setEwId(String ewId) {
41         this.ewId = ewId;
42     }
43
44
45
46     public String getEwHost() {
47         return ewHost;
48     }
49
50     public Subscription(){
51
52     }
53
54     public Subscription(String id, String callback, String query) {
55         this.id = id;
56         this.callback = callback;
57         this.query = query;
58     }
59
60     public String getId() {
61         return id;
62     }
63
64     public void setId(String id) {
65         this.id = id;
66     }
67
68     public String getCallback() {
69         return callback;
70     }
71
72     public void setCallback(String callback) {
73         this.callback = callback;
74     }
75
76     public String getQuery() {
77         return query;
78     }
79
80     public void setQuery(String query) {
81         this.query = query;
82     }
83
84     public static Subscription createFromSubscriber(Subscriber subscriber) {
85         Subscription sub = new Subscription();
86         sub.setId(subscriber.getId());
87         sub.setCallback(subscriber.getCallback());
88         sub.setEwId( subscriber.getEwId());
89         sub.setEwHost( subscriber.getEwHost());
90
91
92         String query = subscriber.getQuery().entrySet()
93                 .stream()
94                 .map(entry -> entry.getKey()+ "=" + String.join(" ",entry.getValue()))
95                 .collect(Collectors.joining());
96
97         sub.setQuery(query);
98         return sub;
99     }
100 }