2 * ============LICENSE_START===================================================
3 * SPARKY (AAI UI service)
4 * ============================================================================
5 * Copyright © 2017 AT&T Intellectual Property.
6 * Copyright © 2017 Amdocs
8 * ============================================================================
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
20 * ============LICENSE_END=====================================================
22 * ECOMP and OpenECOMP are trademarks
23 * and service marks of AT&T Intellectual Property.
25 package org.onap.aai.sparky.viewandinspect.entity;
27 import java.util.Collection;
28 import java.util.HashMap;
31 import org.apache.log4j.Logger;
32 import org.onap.aai.sparky.viewandinspect.config.VisualizationConfigs;
34 import com.fasterxml.jackson.annotation.JsonIgnore;
37 * We can use annotations to differentiate between intermediate data we use to build the node, and
38 * the data that we actually want to appear in the exported JSON.
42 * This is our current ( 14-June-2016 ) working schema that will remain organic until we get it just
45 * { "item-type": "customer", "item-name-key": "subscriber-name", “item-name-value” :
46 * “subscriber-name-123456789-aai847-data-01”, "item-properties": [{ "property-name":
47 * "subscriber-name", "property-value": "subscriber-name-123456789-aai847-data-01" }, {
48 * "property-name": "global-customer-id", "property-value":
49 * "global-customer-id-123456789-aai847-data-01" } ], "node-meta": { “color” : “#f2d2d2”,
50 * "isSearchTarget" : false, "nodeGroups" : "1,2,3,4" }, }
58 public class JsonNode {
61 private String itemType;
62 private String itemNameKey;
63 private String itemNameValue;
64 private Map<String, String> itemProperties;
65 private NodeMeta nodeMeta;
68 private boolean isRootNode;
72 private String resourceKey;
74 private Collection<String> inboundNeighbors;
77 private Collection<String> outboundNeighbors;
81 private static final Logger LOG = Logger.getLogger(JsonNode.class);
83 private VisualizationConfigs visualizationConfigs;
87 * Instantiates a new json node.
91 public JsonNode(ActiveInventoryNode ain, VisualizationConfigs visualizationConfigs) {
92 this.resourceKey = ain.getNodeId();
93 this.itemProperties = ain.getProperties();
94 this.setItemType(ain.getEntityType());
95 this.setItemNameKey(ain.getPrimaryKeyName());
96 this.setItemNameValue(ain.getPrimaryKeyValue());
97 this.setId(ain.getNodeId());
98 this.isRootNode = ain.isRootNode();
99 this.visualizationConfigs = visualizationConfigs;
101 if (LOG.isDebugEnabled()) {
103 LOG.debug("JsonNode constructor using AIN = " + ain.dumpNodeTree(true));
107 inboundNeighbors = ain.getInboundNeighbors();
108 outboundNeighbors = ain.getOutboundNeighbors();
110 nodeMeta = new NodeMeta(this.visualizationConfigs);
112 nodeMeta.setNodeIssue(ain.isNodeIssue());
113 nodeMeta.setNodeValidated(ain.isNodeValidated());
114 nodeMeta.setNodeDepth(ain.getNodeDepth());
116 nodeMeta.setNumInboundNeighbors(ain.getInboundNeighbors().size());
117 nodeMeta.setNumOutboundNeighbors(ain.getOutboundNeighbors().size());
119 nodeMeta.setAtMaxDepth(ain.isAtMaxDepth());
120 nodeMeta.setSelfLinkResolved(!ain.isSelflinkRetrievalFailure());
121 nodeMeta.setProcessingErrorOccurred(ain.isProcessingErrorOccurred());
122 nodeMeta.setHasNeighbors(
123 ain.getOutboundNeighbors().size() > 0 || ain.getInboundNeighbors().size() > 0);
124 nodeMeta.setProcessingState(ain.getState());
128 public String getId() {
132 public void setId(String id) {
136 public String getItemNameKey() {
140 public String getItemNameValue() {
141 return itemNameValue;
144 public Map<String, String> getItemProperties() {
145 return itemProperties;
148 public String getItemType() {
152 public String getResourceKey() {
156 public void setItemNameKey(String itemNameKey) {
157 this.itemNameKey = itemNameKey;
160 public void setItemNameValue(String itemNameValue) {
161 this.itemNameValue = itemNameValue;
164 public void setItemProperties(HashMap<String, String> itemProperties) {
165 this.itemProperties = itemProperties;
168 public void setItemType(String itemType) {
169 this.itemType = itemType;
172 public void setResourceKey(String resourceKey) {
173 this.resourceKey = resourceKey;
176 public NodeMeta getNodeMeta() {
180 public void setNodeMeta(NodeMeta nodeMeta) {
181 this.nodeMeta = nodeMeta;
184 public boolean isRootNode() {
191 * @see java.lang.Object#toString()
194 public String toString() {
195 return "JsonNode [" + (id != null ? "id=" + id + ", " : "")
196 + (itemType != null ? "itemType=" + itemType + ", " : "")
197 + (itemNameKey != null ? "itemNameKey=" + itemNameKey + ", " : "")
198 + (itemNameValue != null ? "itemNameValue=" + itemNameValue + ", " : "")
199 + (itemProperties != null ? "itemProperties=" + itemProperties + ", " : "")
200 + (nodeMeta != null ? "nodeMeta=" + nodeMeta + ", " : "")
201 + (resourceKey != null ? "resourceKey=" + resourceKey + ", " : "")
202 + (inboundNeighbors != null ? "inboundNeighbors=" + inboundNeighbors + ", " : "")
203 + (outboundNeighbors != null ? "outboundNeighbors=" + outboundNeighbors : "") + "]";