2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights
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============================================
20 * ===================================================================
21 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
24 package org.onap.clamp.clds.model.prop;
26 import com.fasterxml.jackson.databind.JsonNode;
28 import java.util.ArrayList;
29 import java.util.Iterator;
30 import java.util.List;
31 import java.util.logging.Logger;
34 * Provide base ModelElement functionality.
36 public abstract class ModelElement {
37 private final static Logger sLOGGER = Logger.getLogger(ModelElement.class.getName());
38 private static final Logger logger = Logger.getLogger(ModelElement.class.getName());
40 public static final String TYPE_COLLECTOR = "collector";
41 public static final String TYPE_STRING_MATCH = "stringMatch";
42 public static final String TYPE_POLICY = "policy";
43 public static final String TYPE_TCA = "tca";
45 private final String type;
46 private final ModelBpmn modelBpmn;
47 private final String id;
48 protected String topicPublishes;
49 protected final JsonNode meNode;
50 private boolean isFound;
52 private final ModelProperties modelProp;
55 * Perform base parsing of properties for a ModelElement (such as,
56 * Collector, StringMatch, Policy and Tca)
63 protected ModelElement(String type, ModelProperties modelProp, ModelBpmn modelBpmn, JsonNode modelJson) {
65 this.modelProp = modelProp;
66 this.modelBpmn = modelBpmn;
67 this.id = modelBpmn.getId(type);
68 this.meNode = modelJson.get(id);
69 this.isFound = modelBpmn.getModelElementFound(type);
73 * topicSubscribes is the topicPublishes of the from Model Element
75 * @return the topicSubscribes
77 public String getTopicSubscribes() {
78 // get fromId for this type
79 String fromId = modelBpmn.getFromId(type);
80 // find the type of the from model element
81 String fromType = modelBpmn.getType(fromId);
82 // get the model element for the type
83 ModelElement me = modelProp.getModelElementByType(fromType);
84 // get the topic publishes for the model element
85 return me.topicPublishes;
89 * @return the topicPublishes
91 public String getTopicPublishes() {
92 return topicPublishes;
96 * Return the value field of the json node element that has a name field
97 * equals to the given name.
103 public static String getValueByName(JsonNode nodeIn, String name) {
105 if (nodeIn != null) {
106 for (JsonNode node : nodeIn) {
107 if (node.path("name").asText().equals(name)) {
108 JsonNode vnode = node.path("value");
109 if (vnode.isArray()) {
110 // if array, assume value is in first element
111 value = vnode.path(0).asText();
113 // otherwise, just return text
114 value = vnode.asText();
119 if (value == null || value.length() == 0) {
120 sLOGGER.warning(name + "=" + value);
122 sLOGGER.fine(name + "=" + value);
128 * Return the int value field of the json node element that has a name field
129 * equals to the given name.
135 public static Integer getIntValueByName(JsonNode nodeIn, String name) {
136 String value = getValueByName(nodeIn, name);
137 return Integer.valueOf(value);
141 * Return an array of values for the field of the json node element that has
142 * a name field equals to the given name.
148 public static List<String> getValuesByName(JsonNode nodeIn, String name) {
149 List<String> values = null;
150 if (nodeIn != null) {
151 Iterator<JsonNode> i = nodeIn.iterator();
152 while (i.hasNext()) {
153 JsonNode node = i.next();
154 if (node.path("name").asText().equals(name)) {
155 values = getValuesList(node);
159 if (values == null || values.size() == 0) {
160 sLOGGER.warning(name + "=" + values);
162 sLOGGER.fine(name + "=" + values);
168 * Return an array of String values.
173 public static List<String> getValuesList(JsonNode nodeIn) {
174 ArrayList<String> al = new ArrayList<>();
175 if (nodeIn != null) {
176 Iterator<JsonNode> itr = nodeIn.path("value").elements();
177 while (itr.hasNext()) {
178 JsonNode node = itr.next();
179 al.add(node.asText());
186 * Return the value field of the json node element that has a name field
187 * equals to the given name.
192 public String getValueByName(String name) {
193 return getValueByName(meNode, name);
197 * Return the int value field of the json node element that has a name field
198 * equals to the given name.
203 public Integer getIntValueByName(String name) {
204 return getIntValueByName(meNode, name);
208 * Return an array of values for the field of the json node element that has
209 * a name field equals to the given name.
214 public List<String> getValuesByName(String name) {
215 return getValuesByName(meNode, name);
221 public String getId() {
226 * @return the isFound
228 public boolean isFound() {