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 java.util.ArrayList;
27 import java.util.Iterator;
28 import java.util.List;
30 import com.att.eelf.configuration.EELFLogger;
31 import com.att.eelf.configuration.EELFManager;
32 import com.fasterxml.jackson.databind.JsonNode;
35 * Provide base ModelElement functionality.
37 public abstract class ModelElement {
38 protected static final EELFLogger logger = EELFManager.getInstance().getLogger(ModelElement.class);
39 protected static final EELFLogger auditLogger = EELFManager.getInstance().getAuditLogger();
41 public static final String TYPE_POLICY = "policy";
42 public static final String TYPE_TCA = "tca";
44 private final String type;
45 private final ModelBpmn modelBpmn;
46 private final String id;
47 protected String topicPublishes;
48 protected final JsonNode meNode;
49 private boolean isFound;
51 private final ModelProperties modelProp;
54 * Perform base parsing of properties for a ModelElement (such as,
55 * Collector, StringMatch, Policy and Tca)
62 protected ModelElement(String type, ModelProperties modelProp, ModelBpmn modelBpmn, JsonNode modelJson) {
64 this.modelProp = modelProp;
65 this.modelBpmn = modelBpmn;
66 this.id = modelBpmn.getId(type);
67 this.meNode = modelJson.get(id);
68 this.isFound = modelBpmn.getModelElementFound(type);
72 * topicSubscribes is the topicPublishes of the from Model Element
74 * @return the topicSubscribes
76 public String getTopicSubscribes() {
77 // get fromId for this type
78 String fromId = modelBpmn.getFromId(type);
79 // find the type of the from model element
80 String fromType = modelBpmn.getType(fromId);
81 // get the model element for the type
82 ModelElement me = modelProp.getModelElementByType(fromType);
83 // get the topic publishes for the model element
84 return me.topicPublishes;
88 * @return the topicPublishes
90 public String getTopicPublishes() {
91 return topicPublishes;
95 * Return the value field of the json node element that has a name field
96 * equals to the given name.
102 public static String getValueByName(JsonNode nodeIn, String name) {
104 if (nodeIn != null) {
105 for (JsonNode node : nodeIn) {
106 if (node.path("name").asText().equals(name)) {
107 JsonNode vnode = node.path("value");
108 if (vnode.isArray()) {
109 // if array, assume value is in first element
110 value = vnode.path(0).asText();
112 // otherwise, just return text
113 value = vnode.asText();
118 if (value == null || value.length() == 0) {
119 logger.warn(name + "=" + value);
121 logger.debug(name + "=" + value);
127 * Return the int value field of the json node element that has a name field
128 * equals to the given name.
134 public static Integer getIntValueByName(JsonNode nodeIn, String name) {
135 String value = getValueByName(nodeIn, name);
136 return Integer.valueOf(value);
140 * Return an array of values for the field of the json node element that has
141 * a name field equals to the given name.
147 public static List<String> getValuesByName(JsonNode nodeIn, String name) {
148 List<String> values = null;
149 if (nodeIn != null) {
150 Iterator<JsonNode> i = nodeIn.iterator();
151 while (i.hasNext()) {
152 JsonNode node = i.next();
153 if (node.path("name").asText().equals(name)) {
154 values = getValuesList(node);
158 if (values == null || values.size() == 0) {
159 logger.warn(name + "=" + values);
161 logger.debug(name + "=" + values);
167 * Return an array of String values.
172 public static List<String> getValuesList(JsonNode nodeIn) {
173 ArrayList<String> al = new ArrayList<>();
174 if (nodeIn != null) {
175 Iterator<JsonNode> itr = nodeIn.path("value").elements();
176 while (itr.hasNext()) {
177 JsonNode node = itr.next();
178 al.add(node.asText());
185 * Return the value field of the json node element that has a name field
186 * equals to the given name.
191 public String getValueByName(String name) {
192 return getValueByName(meNode, name);
196 * Return the int value field of the json node element that has a name field
197 * equals to the given name.
202 public Integer getIntValueByName(String name) {
203 return getIntValueByName(meNode, name);
207 * Return an array of values for the field of the json node element that has
208 * a name field equals to the given name.
213 public List<String> getValuesByName(String name) {
214 return getValuesByName(meNode, name);
220 public String getId() {
225 * @return the isFound
227 public boolean isFound() {