Renaming openecomp to onap
[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 com.fasterxml.jackson.annotation.JsonIgnore;
26
27 import java.util.Collection;
28 import java.util.HashMap;
29 import java.util.Map;
30
31 import org.apache.log4j.Logger;
32
33 /*
34  * We can use annotations to differentiate between intermediate data we use to build the node, and
35  * the data that we actually want to appear in the exported JSON.
36  */
37
38 /*
39  * This is our current ( 14-June-2016 ) working schema that will remain organic until we get it just
40  * right.
41  *
42  * { "item-type": "customer", "item-name-key": "subscriber-name", “item-name-value” :
43  * “subscriber-name-123456789-aai847-data-01”, "item-properties": [{ "property-name":
44  * "subscriber-name", "property-value": "subscriber-name-123456789-aai847-data-01" }, {
45  * "property-name": "global-customer-id", "property-value":
46  * "global-customer-id-123456789-aai847-data-01" } ], "node-meta": { “color” : “#f2d2d2”,
47  * "isSearchTarget" : false, "nodeGroups" : "1,2,3,4" }, }
48  * 
49  */
50
51
52 /**
53  * The Class JsonNode.
54  */
55 public class JsonNode {
56
57   private String id;
58   private String itemType;
59   private String itemNameKey;
60   private String itemNameValue;
61   private Map<String, String> itemProperties;
62   private NodeMeta nodeMeta;
63
64   @JsonIgnore
65   private boolean isRootNode;
66
67
68   @JsonIgnore
69   private String resourceKey;
70   @JsonIgnore
71   private Collection<String> inboundNeighbors;
72
73   @JsonIgnore
74   private Collection<String> outboundNeighbors;
75
76
77   @JsonIgnore
78   private static final Logger LOG = Logger.getLogger(JsonNode.class);
79
80   /**
81    * Instantiates a new json node.
82    *
83    * @param ain the ain
84    */
85   public JsonNode(ActiveInventoryNode ain) {
86     this.resourceKey = ain.getNodeId();
87     this.itemProperties = ain.getProperties();
88     this.setItemType(ain.getEntityType());
89     this.setItemNameKey(ain.getPrimaryKeyName());
90     this.setItemNameValue(ain.getPrimaryKeyValue());
91     this.setId(ain.getNodeId());
92     this.isRootNode = ain.isRootNode();
93
94     if (LOG.isDebugEnabled()) {
95       LOG.debug("---");
96       LOG.debug("JsonNode constructor using AIN = " + ain.dumpNodeTree(true));
97       LOG.debug("---");
98     }
99
100     inboundNeighbors = ain.getInboundNeighbors();
101     outboundNeighbors = ain.getOutboundNeighbors();
102
103     nodeMeta = new NodeMeta();
104
105     nodeMeta.setNodeIssue(ain.isNodeIssue());
106     nodeMeta.setNodeDepth(ain.getNodeDepth());
107
108     nodeMeta.setNumInboundNeighbors(ain.getInboundNeighbors().size());
109     nodeMeta.setNumOutboundNeighbors(ain.getOutboundNeighbors().size());
110
111     nodeMeta.setAtMaxDepth(ain.isAtMaxDepth());
112     nodeMeta.setSelfLinkResolved(!ain.isSelflinkRetrievalFailure());
113     nodeMeta.setProcessingErrorOccurred(ain.isProcessingErrorOccurred());
114     nodeMeta.setHasNeighbors(
115         ain.getOutboundNeighbors().size() > 0 || ain.getInboundNeighbors().size() > 0);
116     nodeMeta.setProcessingState(ain.getState());
117
118   }
119
120   public String getId() {
121     return id;
122   }
123
124   public void setId(String id) {
125     this.id = id;
126   }
127
128   public String getItemNameKey() {
129     return itemNameKey;
130   }
131
132   public String getItemNameValue() {
133     return itemNameValue;
134   }
135
136   public Map<String, String> getItemProperties() {
137     return itemProperties;
138   }
139
140   public String getItemType() {
141     return itemType;
142   }
143
144   public String getResourceKey() {
145     return resourceKey;
146   }
147
148   public void setItemNameKey(String itemNameKey) {
149     this.itemNameKey = itemNameKey;
150   }
151
152   public void setItemNameValue(String itemNameValue) {
153     this.itemNameValue = itemNameValue;
154   }
155
156   public void setItemProperties(HashMap<String, String> itemProperties) {
157     this.itemProperties = itemProperties;
158   }
159
160   public void setItemType(String itemType) {
161     this.itemType = itemType;
162   }
163
164   public void setResourceKey(String resourceKey) {
165     this.resourceKey = resourceKey;
166   }
167
168   public NodeMeta getNodeMeta() {
169     return nodeMeta;
170   }
171
172   public void setNodeMeta(NodeMeta nodeMeta) {
173     this.nodeMeta = nodeMeta;
174   }
175
176   public boolean isRootNode() {
177     return isRootNode;
178   }
179
180   @Override
181   public String toString() {
182     return "JsonNode [" + (id != null ? "id=" + id + ", " : "")
183         + (itemType != null ? "itemType=" + itemType + ", " : "")
184         + (itemNameKey != null ? "itemNameKey=" + itemNameKey + ", " : "")
185         + (itemNameValue != null ? "itemNameValue=" + itemNameValue + ", " : "")
186         + (itemProperties != null ? "itemProperties=" + itemProperties + ", " : "")
187         + (nodeMeta != null ? "nodeMeta=" + nodeMeta + ", " : "") + "isRootNode=" + isRootNode
188         + ", " + (resourceKey != null ? "resourceKey=" + resourceKey + ", " : "")
189         + (inboundNeighbors != null ? "inboundNeighbors=" + inboundNeighbors + ", " : "")
190         + (outboundNeighbors != null ? "outboundNeighbors=" + outboundNeighbors : "") + "]";
191   }
192
193
194 }