2 * ============LICENSE_START=======================================================
3 * ONAP : ccsdk features
4 * ================================================================================
5 * Copyright (C) 2021 highstreet technologies GmbH Intellectual Property.
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
12 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
22 package org.onap.ccsdk.features.sdnr.wt.websocketmanager.model.data;
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;
29 public class SchemaInfo {
30 private String namespace;
31 private String revision;
32 private List<String> notification;
34 public SchemaInfo() {}
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());
44 public SchemaInfo(String namespace, String revision, List<String> notifications) {
45 this.namespace = namespace;
46 this.revision = revision;
47 this.notification = notifications;
50 public String getNamespace() {
54 public void setNamespace(String namespace) {
55 this.namespace = namespace;
58 public String getRevision() {
62 public void setRevision(String revision) {
63 this.revision = revision;
66 public List<String> getNotification() {
70 public void setNotification(List<String> notification) {
71 this.notification = notification;
75 * SchemaInfo Validation restrictions: namespace!=null notification=null or if notification list set, then size>0
80 public boolean isValid() {
81 return this.namespace != null
82 && (this.notification == null || (this.notification != null && !this.notification.isEmpty()));
86 * Check if schema(qname based info of notification) matches into this scope
92 public boolean matches(ReducedSchemaInfo schema) {
93 //if namespace is * placeholder => true
94 if (this.namespace.equals("*")) {
97 //if namespace does not match => false
98 if (!this.namespace.equals(schema.getNamespace().toString())) {
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("*"))) {
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())) {
113 public boolean equalsNamespaceAndRevision(QName qname) {
114 if (this.namespace == null) {
117 if (!this.namespace.equals(qname.getNamespace().toString())) {
120 if (this.revision == null && qname.getRevision().isEmpty()) {
123 if (this.revision != null) {
124 return this.revision.equals(qname.getRevision().isEmpty() ? null : qname.getRevision().get().toString());
130 public void addNotification(String notification) {
131 if (this.notification == null) {
132 this.notification = new ArrayList<>();
134 this.notification.add(notification);
138 public String toString() {
139 return "SchemaInfo [namespace=" + namespace + ", revision=" + revision + ", notification=" + notification + "]";