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