2 * ============LICENSE_START=======================================================
3 * ONAP : ccsdk features
4 * ================================================================================
5 * Copyright (C) 2020 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 java.util.Optional;
28 import org.opendaylight.yangtools.yang.common.QName;
32 private String nodeId;
33 private SchemaInfo schema;
35 public String getNodeId() {
39 public void setNodeId(String nodeId) {
43 public SchemaInfo getSchema() {
47 public void setSchema(SchemaInfo schema) {
52 public boolean isValid() {
53 if (this.nodeId == null && this.schema == null) {
56 if (this.nodeId == null && !this.schema.isValid()) {
63 public boolean matches(String nodeId, ReducedSchemaInfo reducedSchemaInfo) {
64 if (this.nodeId == null) {
65 return this.schema.matches(reducedSchemaInfo);
66 } else if (this.schema == null) {
67 return this.nodeId.equals(nodeId);
69 return this.nodeId.equals(nodeId) && this.schema.matches(reducedSchemaInfo);
73 public boolean addQname(QName qname) {
74 if(this.schema==null) {
75 this.schema = new SchemaInfo(qname);
78 if(!this.schema.equalsNamespaceAndRevision(qname)) {
81 this.schema.addNotification(qname.getLocalName());
86 public String toString() {
87 return "Scope [nodeId=" + nodeId + ", schema=" + schema + "]";
90 public static Scope create(QName qname) {
91 return create(null, qname);
94 public static Scope create(String nodeId, QName qname) {
95 return create(nodeId, qname == null ? null : new SchemaInfo(qname));
98 public static Scope create(String nodeId, SchemaInfo schemaInfo) {
99 Scope scope = new Scope();
100 scope.setNodeId(nodeId);
101 scope.setSchema(schemaInfo);
105 public static Scope create(String nodeId) {
106 return create(nodeId, (SchemaInfo) null);
109 public static List<Scope> createList(List<QName> qnames) {
110 return createList(null, qnames);
113 public static List<Scope> createList(String nodeId, List<QName> qnames) {
114 List<Scope> scopes = new ArrayList<>();
115 Optional<Scope> listElem;
116 for (QName qname : qnames) {
117 listElem = scopes.stream().filter(e -> e.schema != null && e.schema.equalsNamespaceAndRevision(qname))
119 if (listElem.isPresent()) {
120 if (!listElem.get().addQname(qname)) {
121 scopes.add(Scope.create(nodeId, qname));
124 scopes.add(Scope.create(nodeId, qname));