2 * ============LICENSE_START=======================================================
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
12 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.onap.aai.sparky.viewandinspect.entity;
23 import java.io.IOException;
24 import java.util.Collection;
25 import java.util.HashMap;
28 import org.onap.aai.cl.api.Logger;
29 import org.onap.aai.cl.eelf.LoggerFactory;
30 import org.onap.aai.sparky.aggregatevnf.search.AggregateSummaryProcessor;
31 import org.onap.aai.sparky.logging.AaiUiMsgs;
32 import org.onap.aai.sparky.subscription.config.SubscriptionConfig;
33 import org.onap.aai.sparky.subscription.payload.entity.ObjectInspectorPayload;
34 import org.onap.aai.sparky.viewandinspect.config.SparkyConstants;
35 import org.onap.aai.sparky.viewandinspect.config.VisualizationConfigs;
37 import com.fasterxml.jackson.annotation.JsonIgnore;
40 * We can use annotations to differentiate between intermediate data we use to build the node, and
41 * the data that we actually want to appear in the exported JSON.
45 * This is our current ( 14-June-2016 ) working schema that will remain organic until we get it just
48 * { "item-type": "customer", "item-name-key": "subscriber-name", “item-name-value” :
49 * “subscriber-name-123456789-aai847-data-01”, "item-properties": [{ "property-name":
50 * "subscriber-name", "property-value": "subscriber-name-123456789-aai847-data-01" }, {
51 * "property-name": "global-customer-id", "property-value":
52 * "global-customer-id-123456789-aai847-data-01" } ], "node-meta": { “color” : “#f2d2d2”,
53 * "isSearchTarget" : false, "nodeGroups" : "1,2,3,4" }, }
61 public class SparkyGraphNode {
64 private String itemType;
65 private String itemNameKey;
66 private String itemNameValue;
67 private Map<String, String> itemProperties;
68 private NodeMeta nodeMeta;
69 private ObjectInspectorPayload externalResourcePayload;
72 private boolean isRootNode;
76 private String resourceKey;
78 private Collection<String> inboundNeighbors;
81 private Collection<String> outboundNeighbors;
85 private static final Logger LOG = LoggerFactory.getInstance().getLogger(SparkyGraphNode.class);
87 private VisualizationConfigs visualizationConfigs;
88 private SubscriptionConfig subConfig;
91 * Instantiates a new SparkyGraphNode.
95 public SparkyGraphNode(ActiveInventoryNode ain, VisualizationConfigs visualizationConfigs, SubscriptionConfig subConfig) {
96 this.resourceKey = ain.getNodeId();
97 this.itemProperties = ain.getProperties();
98 this.setItemType(ain.getEntityType());
99 this.setItemNameKey(ain.getPrimaryKeyName());
100 this.setItemNameValue(ain.getPrimaryKeyValue());
101 this.setId(ain.getNodeId());
102 this.isRootNode = ain.isRootNode();
103 this.visualizationConfigs = visualizationConfigs;
104 this.setSubConfig(subConfig);
106 if (LOG.isDebugEnabled()) {
108 LOG.debug("JsonNode constructor using AIN = " + ain.dumpNodeTree(true));
112 inboundNeighbors = ain.getInboundNeighbors();
113 outboundNeighbors = ain.getOutboundNeighbors();
115 nodeMeta = new NodeMeta(this.visualizationConfigs);
117 nodeMeta.setNodeIssue(ain.isNodeIssue());
118 nodeMeta.setNodeValidated(ain.isNodeValidated());
119 nodeMeta.setNodeDepth(ain.getNodeDepth());
121 nodeMeta.setNumInboundNeighbors(ain.getInboundNeighbors().size());
122 nodeMeta.setNumOutboundNeighbors(ain.getOutboundNeighbors().size());
124 nodeMeta.setAtMaxDepth(ain.isAtMaxDepth());
125 nodeMeta.setSelfLinkResolved(!ain.isSelflinkRetrievalFailure());
126 nodeMeta.setProcessingErrorOccurred(ain.isProcessingErrorOccurred());
127 nodeMeta.setHasNeighbors(
128 ain.getOutboundNeighbors().size() > 0 || ain.getInboundNeighbors().size() > 0);
130 if (subConfig.getIsLaunchOIEnabled()) {
132 Collection<String> entityTypes = subConfig.getAnnEntitiyTypes();
133 for (String entityType : entityTypes) {
134 if (entityType.equals(this.getItemType())) {
135 ObjectInspectorPayload lic = ObjectInspectorPayload.getOIPayload(subConfig);
136 lic.getMessage().getPayload().getParams().setObjectName(this.getItemNameValue());
137 this.setExternalResourcePayload(lic);
141 } catch (IOException e) {
142 String message = "Could not map JSON to object " + "Attempted to convert: "
143 + SparkyConstants.SUBSCRIPTION_OI_MAPPING + ". Error: " + e.getLocalizedMessage();
144 LOG.error(AaiUiMsgs.JSON_PROCESSING_ERROR, message);
147 nodeMeta.setProcessingState(ain.getState());
151 public String getId() {
155 public void setId(String id) {
159 public String getItemNameKey() {
163 public String getItemNameValue() {
164 return itemNameValue;
167 public Map<String, String> getItemProperties() {
168 return itemProperties;
171 public String getItemType() {
175 public String getResourceKey() {
179 public void setItemNameKey(String itemNameKey) {
180 this.itemNameKey = itemNameKey;
183 public void setItemNameValue(String itemNameValue) {
184 this.itemNameValue = itemNameValue;
187 public void setItemProperties(HashMap<String, String> itemProperties) {
188 this.itemProperties = itemProperties;
191 public void setItemType(String itemType) {
192 this.itemType = itemType;
195 public void setResourceKey(String resourceKey) {
196 this.resourceKey = resourceKey;
199 public NodeMeta getNodeMeta() {
203 public void setNodeMeta(NodeMeta nodeMeta) {
204 this.nodeMeta = nodeMeta;
207 public boolean isRootNode() {
211 public ObjectInspectorPayload getExternalResourcePayload() {
212 return externalResourcePayload;
215 public void setExternalResourcePayload(ObjectInspectorPayload externalResourcePayload) {
216 this.externalResourcePayload = externalResourcePayload;
219 public SubscriptionConfig getSubConfig() {
223 public void setSubConfig(SubscriptionConfig subConfig) {
224 this.subConfig = subConfig;
230 * @see java.lang.Object#toString()
233 public String toString() {
234 return "JsonNode [" + (id != null ? "id=" + id + ", " : "")
235 + (itemType != null ? "itemType=" + itemType + ", " : "")
236 + (itemNameKey != null ? "itemNameKey=" + itemNameKey + ", " : "")
237 + (itemNameValue != null ? "itemNameValue=" + itemNameValue + ", " : "")
238 + (itemProperties != null ? "itemProperties=" + itemProperties + ", " : "")
239 + (nodeMeta != null ? "nodeMeta=" + nodeMeta + ", " : "")
240 + (resourceKey != null ? "resourceKey=" + resourceKey + ", " : "")
241 + (inboundNeighbors != null ? "inboundNeighbors=" + inboundNeighbors + ", " : "")
242 + (outboundNeighbors != null ? "outboundNeighbors=" + outboundNeighbors : "") + "]";