c587a799745dbebed95dc87f1f4cd36ea696a9c6
[ccsdk/features.git] /
1 /*
2  * ============LICENSE_START=======================================================
3  * ONAP : ccsdk features
4  * ================================================================================
5  * Copyright (C) 2021 highstreet technologies GmbH Intellectual Property.
6  * All rights reserved.
7  * ================================================================================
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  *     http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  * ============LICENSE_END=========================================================
20  *
21  */
22 package org.onap.ccsdk.features.sdnr.wt.websocketmanager.model.data;
23
24 import com.fasterxml.jackson.annotation.JsonIgnore;
25 import java.util.ArrayList;
26 import java.util.List;
27 import org.opendaylight.yangtools.yang.common.QName;
28
29 public class SchemaInfo {
30     private String namespace;
31     private String revision;
32     private List<String> notification;
33
34     public SchemaInfo() {}
35
36
37
38     public SchemaInfo(QName qname) {
39         this.namespace = qname.getNamespace().toString();
40         this.revision = qname.getRevision().isPresent() ? qname.getRevision().get().toString() : null;
41         this.notification = new ArrayList<>();
42         this.notification.add(qname.getLocalName());
43     }
44
45     public String getNamespace() {
46         return namespace;
47     }
48
49     public void setNamespace(String namespace) {
50         this.namespace = namespace;
51     }
52
53     public String getRevision() {
54         return revision;
55     }
56
57     public void setRevision(String revision) {
58         this.revision = revision;
59     }
60
61     public List<String> getNotification() {
62         return notification;
63     }
64
65     public void setNotification(List<String> notification) {
66         this.notification = notification;
67     }
68
69     @JsonIgnore
70     public boolean isValid() {
71         return this.namespace != null
72                 && (this.notification == null || (this.notification != null && this.notification.size() > 0));
73     }
74
75     /**
76      * Check if schema(qname based info of notification) matches into this scope
77      * @param schema
78      * @return
79      */
80     @JsonIgnore
81     public boolean matches(ReducedSchemaInfo schema) {
82         //if namespace is * placeholder => true
83         if (this.namespace.equals("*")) {
84             return true;
85         }
86         //if namespace does not match => false
87         if (!this.namespace.equals(schema.getNamespace().toString())) {
88             return false;
89         }
90         //if revision of scope is set and it does not match => false
91         if (this.revision != null && !this.revision.equals(schema.getRevision())){
92             return false;
93         }
94         //if notification of scope is set and is current notification is not in the list
95         if (this.notification != null && !this.notification.contains(schema.getType())) {
96             return false;
97         }
98         return true;
99     }
100
101     @JsonIgnore
102     public boolean equalsNamespaceAndRevision(QName qname) {
103         if (this.namespace == null) {
104             return false;
105         }
106         if (!this.namespace.equals(qname.getNamespace().toString())) {
107             return false;
108         }
109         if (this.revision == null && qname.getRevision().isEmpty()) {
110             return true;
111         }
112         if (this.revision != null) {
113             return this.revision.equals(qname.getRevision().isEmpty() ? null : qname.getRevision().get().toString());
114         }
115         return false;
116     }
117
118     @JsonIgnore
119     public void addNotification(String notification) {
120         if(this.notification ==null) {
121             this.notification = new ArrayList<>();
122         }
123         this.notification.add(notification);
124     }
125
126     @Override
127     public String toString() {
128         return "SchemaInfo [namespace=" + namespace + ", revision=" + revision + ", notification=" + notification + "]";
129     }
130
131
132 }