Initial commit for AAI-UI(sparky-backend)
[aai/sparky-be.git] / src / main / java / org / openecomp / sparky / viewandinspect / entity / JsonNode.java
1 /**
2  * ============LICENSE_START===================================================
3  * SPARKY (AAI UI service)
4  * ============================================================================
5  * Copyright © 2017 AT&T Intellectual Property.
6  * Copyright © 2017 Amdocs
7  * All rights reserved.
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
12  *
13  *      http://www.apache.org/licenses/LICENSE-2.0
14  *
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=====================================================
21  *
22  * ECOMP and OpenECOMP are trademarks
23  * and service marks of AT&T Intellectual Property.
24  */
25
26 package org.openecomp.sparky.viewandinspect.entity;
27
28 import com.fasterxml.jackson.annotation.JsonIgnore;
29
30 import java.util.Collection;
31 import java.util.HashMap;
32 import java.util.Map;
33
34 import org.apache.log4j.Logger;
35
36 /*
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.
39  */
40
41 /*
42  * This is our current ( 14-June-2016 ) working schema that will remain organic until we get it just
43  * right.
44  *
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" }, }
51  * 
52  */
53
54
55 /**
56  * The Class JsonNode.
57  */
58 public class JsonNode {
59
60   private String id;
61   private String itemType;
62   private String itemNameKey;
63   private String itemNameValue;
64   private Map<String, String> itemProperties;
65   private NodeMeta nodeMeta;
66
67   @JsonIgnore
68   private boolean isRootNode;
69
70
71   @JsonIgnore
72   private String resourceKey;
73   @JsonIgnore
74   private Collection<String> inboundNeighbors;
75
76   @JsonIgnore
77   private Collection<String> outboundNeighbors;
78
79
80   @JsonIgnore
81   private static final Logger LOG = Logger.getLogger(JsonNode.class);
82
83   /**
84    * Instantiates a new json node.
85    *
86    * @param ain the ain
87    */
88   public JsonNode(ActiveInventoryNode ain) {
89     this.resourceKey = ain.getNodeId();
90     this.itemProperties = ain.getProperties();
91     this.setItemType(ain.getEntityType());
92     this.setItemNameKey(ain.getPrimaryKeyName());
93     this.setItemNameValue(ain.getPrimaryKeyValue());
94     this.setId(ain.getNodeId());
95     this.isRootNode = ain.isRootNode();
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();
107
108     nodeMeta.setNodeIssue(ain.isNodeIssue());
109     nodeMeta.setNodeDepth(ain.getNodeDepth());
110
111     nodeMeta.setNumInboundNeighbors(ain.getInboundNeighbors().size());
112     nodeMeta.setNumOutboundNeighbors(ain.getOutboundNeighbors().size());
113
114     nodeMeta.setAtMaxDepth(ain.isAtMaxDepth());
115     nodeMeta.setSelfLinkResolved(!ain.isSelflinkRetrievalFailure());
116     nodeMeta.setProcessingErrorOccurred(ain.isProcessingErrorOccurred());
117     nodeMeta.setHasNeighbors(
118         ain.getOutboundNeighbors().size() > 0 || ain.getInboundNeighbors().size() > 0);
119     nodeMeta.setProcessingState(ain.getState());
120
121   }
122
123   public String getId() {
124     return id;
125   }
126
127   public void setId(String id) {
128     this.id = id;
129   }
130
131   public String getItemNameKey() {
132     return itemNameKey;
133   }
134
135   public String getItemNameValue() {
136     return itemNameValue;
137   }
138
139   public Map<String, String> getItemProperties() {
140     return itemProperties;
141   }
142
143   public String getItemType() {
144     return itemType;
145   }
146
147   public String getResourceKey() {
148     return resourceKey;
149   }
150
151   public void setItemNameKey(String itemNameKey) {
152     this.itemNameKey = itemNameKey;
153   }
154
155   public void setItemNameValue(String itemNameValue) {
156     this.itemNameValue = itemNameValue;
157   }
158
159   public void setItemProperties(HashMap<String, String> itemProperties) {
160     this.itemProperties = itemProperties;
161   }
162
163   public void setItemType(String itemType) {
164     this.itemType = itemType;
165   }
166
167   public void setResourceKey(String resourceKey) {
168     this.resourceKey = resourceKey;
169   }
170
171   public NodeMeta getNodeMeta() {
172     return nodeMeta;
173   }
174
175   public void setNodeMeta(NodeMeta nodeMeta) {
176     this.nodeMeta = nodeMeta;
177   }
178
179   public boolean isRootNode() {
180     return isRootNode;
181   }
182
183   @Override
184   public String toString() {
185     return "JsonNode [" + (id != null ? "id=" + id + ", " : "")
186         + (itemType != null ? "itemType=" + itemType + ", " : "")
187         + (itemNameKey != null ? "itemNameKey=" + itemNameKey + ", " : "")
188         + (itemNameValue != null ? "itemNameValue=" + itemNameValue + ", " : "")
189         + (itemProperties != null ? "itemProperties=" + itemProperties + ", " : "")
190         + (nodeMeta != null ? "nodeMeta=" + nodeMeta + ", " : "") + "isRootNode=" + isRootNode
191         + ", " + (resourceKey != null ? "resourceKey=" + resourceKey + ", " : "")
192         + (inboundNeighbors != null ? "inboundNeighbors=" + inboundNeighbors + ", " : "")
193         + (outboundNeighbors != null ? "outboundNeighbors=" + outboundNeighbors : "") + "]";
194   }
195
196
197 }