Adding UI extensibility
[aai/sparky-be.git] / src / main / java / org / onap / aai / sparky / viewandinspect / entity / JsonNode.java
1 /**
2  * ============LICENSE_START=======================================================
3  * org.onap.aai
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
11  *
12  *       http://www.apache.org/licenses/LICENSE-2.0
13  *
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.
22  */
23 package org.onap.aai.sparky.viewandinspect.entity;
24
25 import java.util.Collection;
26 import java.util.HashMap;
27 import java.util.Map;
28
29 import org.apache.log4j.Logger;
30 import org.onap.aai.sparky.viewandinspect.config.VisualizationConfigs;
31
32 import com.fasterxml.jackson.annotation.JsonIgnore;
33
34 /*
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.
37  */
38
39 /*
40  * This is our current ( 14-June-2016 ) working schema that will remain organic until we get it just
41  * right.
42  *
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" }, }
49  * 
50  */
51
52
53 /**
54  * The Class JsonNode.
55  */
56 public class JsonNode {
57
58   private String id;
59   private String itemType;
60   private String itemNameKey;
61   private String itemNameValue;
62   private Map<String, String> itemProperties;
63   private NodeMeta nodeMeta;
64
65   @JsonIgnore
66   private boolean isRootNode;
67
68
69   @JsonIgnore
70   private String resourceKey;
71   @JsonIgnore
72   private Collection<String> inboundNeighbors;
73
74   @JsonIgnore
75   private Collection<String> outboundNeighbors;
76
77
78   @JsonIgnore
79   private static final Logger LOG = Logger.getLogger(JsonNode.class);
80
81   private VisualizationConfigs visualizationConfigs;
82
83
84   /**
85    * Instantiates a new json node.
86    *
87    * @param ain the ain
88    */
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;
98
99     if (LOG.isDebugEnabled()) {
100       LOG.debug("---");
101       LOG.debug("JsonNode constructor using AIN = " + ain.dumpNodeTree(true));
102       LOG.debug("---");
103     }
104
105     inboundNeighbors = ain.getInboundNeighbors();
106     outboundNeighbors = ain.getOutboundNeighbors();
107
108     nodeMeta = new NodeMeta(this.visualizationConfigs);
109
110     nodeMeta.setNodeIssue(ain.isNodeIssue());
111     nodeMeta.setNodeValidated(ain.isNodeValidated());
112     nodeMeta.setNodeDepth(ain.getNodeDepth());
113
114     nodeMeta.setNumInboundNeighbors(ain.getInboundNeighbors().size());
115     nodeMeta.setNumOutboundNeighbors(ain.getOutboundNeighbors().size());
116
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());
123
124   }
125
126   public String getId() {
127     return id;
128   }
129
130   public void setId(String id) {
131     this.id = id;
132   }
133
134   public String getItemNameKey() {
135     return itemNameKey;
136   }
137
138   public String getItemNameValue() {
139     return itemNameValue;
140   }
141
142   public Map<String, String> getItemProperties() {
143     return itemProperties;
144   }
145
146   public String getItemType() {
147     return itemType;
148   }
149
150   public String getResourceKey() {
151     return resourceKey;
152   }
153
154   public void setItemNameKey(String itemNameKey) {
155     this.itemNameKey = itemNameKey;
156   }
157
158   public void setItemNameValue(String itemNameValue) {
159     this.itemNameValue = itemNameValue;
160   }
161
162   public void setItemProperties(HashMap<String, String> itemProperties) {
163     this.itemProperties = itemProperties;
164   }
165
166   public void setItemType(String itemType) {
167     this.itemType = itemType;
168   }
169
170   public void setResourceKey(String resourceKey) {
171     this.resourceKey = resourceKey;
172   }
173
174   public NodeMeta getNodeMeta() {
175     return nodeMeta;
176   }
177
178   public void setNodeMeta(NodeMeta nodeMeta) {
179     this.nodeMeta = nodeMeta;
180   }
181
182   public boolean isRootNode() {
183     return isRootNode;
184   }
185
186   /*
187    * (non-Javadoc)
188    * 
189    * @see java.lang.Object#toString()
190    */
191   @Override
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 : "") + "]";
202   }
203
204
205 }