2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
6 * Copyright © 2017 Amdocs
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=========================================================
21 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
23 package org.onap.aai.sparky.viewandinspect.entity;
25 import java.util.Collection;
26 import java.util.HashMap;
29 import org.apache.log4j.Logger;
30 import org.onap.aai.sparky.viewandinspect.config.VisualizationConfigs;
32 import com.fasterxml.jackson.annotation.JsonIgnore;
35 * We can use annotations to differentiate between intermediate data we use to build the node, and
36 * the data that we actually want to appear in the exported JSON.
40 * This is our current ( 14-June-2016 ) working schema that will remain organic until we get it just
43 * { "item-type": "customer", "item-name-key": "subscriber-name", “item-name-value” :
44 * “subscriber-name-123456789-aai847-data-01”, "item-properties": [{ "property-name":
45 * "subscriber-name", "property-value": "subscriber-name-123456789-aai847-data-01" }, {
46 * "property-name": "global-customer-id", "property-value":
47 * "global-customer-id-123456789-aai847-data-01" } ], "node-meta": { “color” : “#f2d2d2”,
48 * "isSearchTarget" : false, "nodeGroups" : "1,2,3,4" }, }
56 public class JsonNode {
59 private String itemType;
60 private String itemNameKey;
61 private String itemNameValue;
62 private Map<String, String> itemProperties;
63 private NodeMeta nodeMeta;
66 private boolean isRootNode;
70 private String resourceKey;
72 private Collection<String> inboundNeighbors;
75 private Collection<String> outboundNeighbors;
79 private static final Logger LOG = Logger.getLogger(JsonNode.class);
81 private VisualizationConfigs visualizationConfigs;
85 * Instantiates a new json node.
89 public JsonNode(ActiveInventoryNode ain, VisualizationConfigs visualizationConfigs) {
90 this.resourceKey = ain.getNodeId();
91 this.itemProperties = ain.getProperties();
92 this.setItemType(ain.getEntityType());
93 this.setItemNameKey(ain.getPrimaryKeyName());
94 this.setItemNameValue(ain.getPrimaryKeyValue());
95 this.setId(ain.getNodeId());
96 this.isRootNode = ain.isRootNode();
97 this.visualizationConfigs = visualizationConfigs;
99 if (LOG.isDebugEnabled()) {
101 LOG.debug("JsonNode constructor using AIN = " + ain.dumpNodeTree(true));
105 inboundNeighbors = ain.getInboundNeighbors();
106 outboundNeighbors = ain.getOutboundNeighbors();
108 nodeMeta = new NodeMeta(this.visualizationConfigs);
110 nodeMeta.setNodeIssue(ain.isNodeIssue());
111 nodeMeta.setNodeValidated(ain.isNodeValidated());
112 nodeMeta.setNodeDepth(ain.getNodeDepth());
114 nodeMeta.setNumInboundNeighbors(ain.getInboundNeighbors().size());
115 nodeMeta.setNumOutboundNeighbors(ain.getOutboundNeighbors().size());
117 nodeMeta.setAtMaxDepth(ain.isAtMaxDepth());
118 nodeMeta.setSelfLinkResolved(!ain.isSelflinkRetrievalFailure());
119 nodeMeta.setProcessingErrorOccurred(ain.isProcessingErrorOccurred());
120 nodeMeta.setHasNeighbors(
121 ain.getOutboundNeighbors().size() > 0 || ain.getInboundNeighbors().size() > 0);
122 nodeMeta.setProcessingState(ain.getState());
126 public String getId() {
130 public void setId(String id) {
134 public String getItemNameKey() {
138 public String getItemNameValue() {
139 return itemNameValue;
142 public Map<String, String> getItemProperties() {
143 return itemProperties;
146 public String getItemType() {
150 public String getResourceKey() {
154 public void setItemNameKey(String itemNameKey) {
155 this.itemNameKey = itemNameKey;
158 public void setItemNameValue(String itemNameValue) {
159 this.itemNameValue = itemNameValue;
162 public void setItemProperties(HashMap<String, String> itemProperties) {
163 this.itemProperties = itemProperties;
166 public void setItemType(String itemType) {
167 this.itemType = itemType;
170 public void setResourceKey(String resourceKey) {
171 this.resourceKey = resourceKey;
174 public NodeMeta getNodeMeta() {
178 public void setNodeMeta(NodeMeta nodeMeta) {
179 this.nodeMeta = nodeMeta;
182 public boolean isRootNode() {
189 * @see java.lang.Object#toString()
192 public String toString() {
193 return "JsonNode [" + (id != null ? "id=" + id + ", " : "")
194 + (itemType != null ? "itemType=" + itemType + ", " : "")
195 + (itemNameKey != null ? "itemNameKey=" + itemNameKey + ", " : "")
196 + (itemNameValue != null ? "itemNameValue=" + itemNameValue + ", " : "")
197 + (itemProperties != null ? "itemProperties=" + itemProperties + ", " : "")
198 + (nodeMeta != null ? "nodeMeta=" + nodeMeta + ", " : "")
199 + (resourceKey != null ? "resourceKey=" + resourceKey + ", " : "")
200 + (inboundNeighbors != null ? "inboundNeighbors=" + inboundNeighbors + ", " : "")
201 + (outboundNeighbors != null ? "outboundNeighbors=" + outboundNeighbors : "") + "]";