ff08f594a59ba777b6bda046207dd7ebc4cef081
[dmaap/datarouter.git] / datarouter-prov / src / main / java / org / onap / dmaap / datarouter / provisioning / beans / FeedAuthorization.java
1 /*******************************************************************************\r
2  * ============LICENSE_START==================================================\r
3  * * org.onap.dmaap\r
4  * * ===========================================================================\r
5  * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.\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
10  * *\r
11  *  *      http://www.apache.org/licenses/LICENSE-2.0\r
12  * *\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
19  * *\r
20  * * ECOMP is a trademark and service mark of AT&T Intellectual Property.\r
21  * *\r
22  ******************************************************************************/\r
23 \r
24 \r
25 package org.onap.dmaap.datarouter.provisioning.beans;\r
26 \r
27 import java.util.HashSet;\r
28 import java.util.Objects;\r
29 import java.util.Set;\r
30 \r
31 import org.json.JSONArray;\r
32 import org.json.JSONObject;\r
33 \r
34 /**\r
35  * The representation of a Feed authorization.  This encapsulates the authorization information about a feed.\r
36  *\r
37  * @author Robert Eby\r
38  * @version $Id: FeedAuthorization.java,v 1.2 2013/06/20 14:11:05 eby Exp $\r
39  */\r
40 public class FeedAuthorization implements JSONable {\r
41 \r
42     private String classification;\r
43     private Set<FeedEndpointID> endpointIds;\r
44     private Set<String> endpointAddrs;\r
45 \r
46     /**\r
47      * FeedAuthoization constructor.\r
48      */\r
49     public FeedAuthorization() {\r
50         this.classification = "";\r
51         this.endpointIds = new HashSet<>();\r
52         this.endpointAddrs = new HashSet<>();\r
53     }\r
54 \r
55     public String getClassification() {\r
56         return classification;\r
57     }\r
58 \r
59     public void setClassification(String classification) {\r
60         this.classification = classification;\r
61     }\r
62 \r
63     public Set<FeedEndpointID> getEndpoint_ids() {\r
64         return endpointIds;\r
65     }\r
66 \r
67     public void setEndpoint_ids(Set<FeedEndpointID> endpointIds) {\r
68         this.endpointIds = endpointIds;\r
69     }\r
70 \r
71     public Set<String> getEndpoint_addrs() {\r
72         return endpointAddrs;\r
73     }\r
74 \r
75     public void setEndpoint_addrs(Set<String> endpointAddrs) {\r
76         this.endpointAddrs = endpointAddrs;\r
77     }\r
78 \r
79     @Override\r
80     public JSONObject asJSONObject() {\r
81         JSONObject jo = new JSONObject();\r
82         jo.put("classification", classification);\r
83         JSONArray ja = new JSONArray();\r
84         for (FeedEndpointID eid : endpointIds) {\r
85             ja.put(eid.asJSONObject());\r
86         }\r
87         jo.put("endpoint_ids", ja);\r
88         ja = new JSONArray();\r
89         for (String t : endpointAddrs) {\r
90             ja.put(t);\r
91         }\r
92         jo.put("endpoint_addrs", ja);\r
93         return jo;\r
94     }\r
95 \r
96     @Override\r
97     public boolean equals(Object obj) {\r
98         if (!(obj instanceof FeedAuthorization)) {\r
99             return false;\r
100         }\r
101         FeedAuthorization of = (FeedAuthorization) obj;\r
102         if (!classification.equals(of.classification)) {\r
103             return false;\r
104         }\r
105         if (!endpointIds.equals(of.endpointIds)) {\r
106             return false;\r
107         }\r
108         if (!endpointAddrs.equals(of.endpointAddrs)) {\r
109             return false;\r
110         }\r
111         return true;\r
112     }\r
113 \r
114     @Override\r
115     public int hashCode() {\r
116         return Objects.hash(classification, endpointIds, endpointAddrs);\r
117     }\r
118 }\r