2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
6 * Copyright © 2017-2018 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 package org.onap.aai.sparky.viewandinspect.entity;
23 import java.util.Collection;
24 import java.util.HashMap;
27 import org.apache.log4j.Logger;
28 import org.onap.aai.sparky.viewandinspect.config.VisualizationConfigs;
30 import com.fasterxml.jackson.annotation.JsonIgnore;
33 * We can use annotations to differentiate between intermediate data we use to build the node, and
34 * the data that we actually want to appear in the exported JSON.
38 * This is our current ( 14-June-2016 ) working schema that will remain organic until we get it just
41 * { "item-type": "customer", "item-name-key": "subscriber-name", “item-name-value” :
42 * “subscriber-name-123456789-aai847-data-01”, "item-properties": [{ "property-name":
43 * "subscriber-name", "property-value": "subscriber-name-123456789-aai847-data-01" }, {
44 * "property-name": "global-customer-id", "property-value":
45 * "global-customer-id-123456789-aai847-data-01" } ], "node-meta": { “color” : “#f2d2d2”,
46 * "isSearchTarget" : false, "nodeGroups" : "1,2,3,4" }, }
54 public class JsonNode {
57 private String itemType;
58 private String itemNameKey;
59 private String itemNameValue;
60 private Map<String, String> itemProperties;
61 private NodeMeta nodeMeta;
64 private boolean isRootNode;
68 private String resourceKey;
70 private Collection<String> inboundNeighbors;
73 private Collection<String> outboundNeighbors;
77 private static final Logger LOG = Logger.getLogger(JsonNode.class);
79 private VisualizationConfigs visualizationConfigs;
83 * Instantiates a new json node.
87 public JsonNode(ActiveInventoryNode ain, VisualizationConfigs visualizationConfigs) {
88 this.resourceKey = ain.getNodeId();
89 this.itemProperties = ain.getProperties();
90 this.setItemType(ain.getEntityType());
91 this.setItemNameKey(ain.getPrimaryKeyName());
92 this.setItemNameValue(ain.getPrimaryKeyValue());
93 this.setId(ain.getNodeId());
94 this.isRootNode = ain.isRootNode();
95 this.visualizationConfigs = visualizationConfigs;
97 if (LOG.isDebugEnabled()) {
99 LOG.debug("JsonNode constructor using AIN = " + ain.dumpNodeTree(true));
103 inboundNeighbors = ain.getInboundNeighbors();
104 outboundNeighbors = ain.getOutboundNeighbors();
106 nodeMeta = new NodeMeta(this.visualizationConfigs);
108 nodeMeta.setNodeIssue(ain.isNodeIssue());
109 nodeMeta.setNodeValidated(ain.isNodeValidated());
110 nodeMeta.setNodeDepth(ain.getNodeDepth());
112 nodeMeta.setNumInboundNeighbors(ain.getInboundNeighbors().size());
113 nodeMeta.setNumOutboundNeighbors(ain.getOutboundNeighbors().size());
115 nodeMeta.setAtMaxDepth(ain.isAtMaxDepth());
116 nodeMeta.setSelfLinkResolved(!ain.isSelflinkRetrievalFailure());
117 nodeMeta.setProcessingErrorOccurred(ain.isProcessingErrorOccurred());
118 nodeMeta.setHasNeighbors(
119 ain.getOutboundNeighbors().size() > 0 || ain.getInboundNeighbors().size() > 0);
120 nodeMeta.setProcessingState(ain.getState());
124 public String getId() {
128 public void setId(String id) {
132 public String getItemNameKey() {
136 public String getItemNameValue() {
137 return itemNameValue;
140 public Map<String, String> getItemProperties() {
141 return itemProperties;
144 public String getItemType() {
148 public String getResourceKey() {
152 public void setItemNameKey(String itemNameKey) {
153 this.itemNameKey = itemNameKey;
156 public void setItemNameValue(String itemNameValue) {
157 this.itemNameValue = itemNameValue;
160 public void setItemProperties(HashMap<String, String> itemProperties) {
161 this.itemProperties = itemProperties;
164 public void setItemType(String itemType) {
165 this.itemType = itemType;
168 public void setResourceKey(String resourceKey) {
169 this.resourceKey = resourceKey;
172 public NodeMeta getNodeMeta() {
176 public void setNodeMeta(NodeMeta nodeMeta) {
177 this.nodeMeta = nodeMeta;
180 public boolean isRootNode() {
187 * @see java.lang.Object#toString()
190 public String toString() {
191 return "JsonNode [" + (id != null ? "id=" + id + ", " : "")
192 + (itemType != null ? "itemType=" + itemType + ", " : "")
193 + (itemNameKey != null ? "itemNameKey=" + itemNameKey + ", " : "")
194 + (itemNameValue != null ? "itemNameValue=" + itemNameValue + ", " : "")
195 + (itemProperties != null ? "itemProperties=" + itemProperties + ", " : "")
196 + (nodeMeta != null ? "nodeMeta=" + nodeMeta + ", " : "")
197 + (resourceKey != null ? "resourceKey=" + resourceKey + ", " : "")
198 + (inboundNeighbors != null ? "inboundNeighbors=" + inboundNeighbors + ", " : "")
199 + (outboundNeighbors != null ? "outboundNeighbors=" + outboundNeighbors : "") + "]";