4d39753791617d57e5158431abb758c914e47ac0
[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(qname.getNamespace().toString(),
40                 qname.getRevision().isPresent() ? qname.getRevision().get().toString() : null, new ArrayList<>());
41         this.notification.add(qname.getLocalName());
42     }
43
44     public SchemaInfo(String namespace, String revision, List<String> notifications) {
45         this.namespace = namespace;
46         this.revision = revision;
47         this.notification = notifications;
48     }
49
50     public String getNamespace() {
51         return namespace;
52     }
53
54     public void setNamespace(String namespace) {
55         this.namespace = namespace;
56     }
57
58     public String getRevision() {
59         return revision;
60     }
61
62     public void setRevision(String revision) {
63         this.revision = revision;
64     }
65
66     public List<String> getNotification() {
67         return notification;
68     }
69
70     public void setNotification(List<String> notification) {
71         this.notification = notification;
72     }
73
74     /**
75      * SchemaInfo Validation restrictions: namespace!=null notification=null or if notification list set, then size>0
76      *
77      * @return
78      */
79     @JsonIgnore
80     public boolean isValid() {
81         return this.namespace != null
82                 && (this.notification == null || (this.notification != null && this.notification.size() > 0));
83     }
84
85     /**
86      * Check if schema(qname based info of notification) matches into this scope
87      *
88      * @param schema
89      * @return
90      */
91     @JsonIgnore
92     public boolean matches(ReducedSchemaInfo schema) {
93         //if namespace is * placeholder => true
94         if (this.namespace.equals("*")) {
95             return true;
96         }
97         //if namespace does not match => false
98         if (!this.namespace.equals(schema.getNamespace().toString())) {
99             return false;
100         }
101         //if revision of scope is set and it does not match and is not '*' => false
102         if (this.revision != null && (!this.revision.equals(schema.getRevision()) && !this.revision.equals("*"))) {
103             return false;
104         }
105         //if notification of scope is set and is current notification is not in the list
106         if (this.notification != null && !this.notification.contains(schema.getType())) {
107             return false;
108         }
109         return true;
110     }
111
112     @JsonIgnore
113     public boolean equalsNamespaceAndRevision(QName qname) {
114         if (this.namespace == null) {
115             return false;
116         }
117         if (!this.namespace.equals(qname.getNamespace().toString())) {
118             return false;
119         }
120         if (this.revision == null && qname.getRevision().isEmpty()) {
121             return true;
122         }
123         if (this.revision != null) {
124             return this.revision.equals(qname.getRevision().isEmpty() ? null : qname.getRevision().get().toString());
125         }
126         return false;
127     }
128
129     @JsonIgnore
130     public void addNotification(String notification) {
131         if (this.notification == null) {
132             this.notification = new ArrayList<>();
133         }
134         this.notification.add(notification);
135     }
136
137     @Override
138     public String toString() {
139         return "SchemaInfo [namespace=" + namespace + ", revision=" + revision + ", notification=" + notification + "]";
140     }
141
142
143 }