2 * ============LICENSE_START===================================================
3 * SPARKY (AAI UI service)
4 * ============================================================================
5 * Copyright © 2017 AT&T Intellectual Property.
6 * Copyright © 2017 Amdocs
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
13 * http://www.apache.org/licenses/LICENSE-2.0
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=====================================================
22 * ECOMP and OpenECOMP are trademarks
23 * and service marks of AT&T Intellectual Property.
25 package org.onap.aai.sparky.viewandinspect.entity;
27 import java.io.IOException;
28 import java.util.Collection;
29 import java.util.HashMap;
32 import org.onap.aai.cl.api.Logger;
33 import org.onap.aai.cl.eelf.LoggerFactory;
34 import org.onap.aai.sparky.aggregatevnf.search.AggregateSummaryProcessor;
35 import org.onap.aai.sparky.logging.AaiUiMsgs;
36 import org.onap.aai.sparky.subscription.config.SubscriptionConfig;
37 import org.onap.aai.sparky.subscription.payload.entity.ObjectInspectorPayload;
38 import org.onap.aai.sparky.viewandinspect.config.SparkyConstants;
39 import org.onap.aai.sparky.viewandinspect.config.VisualizationConfigs;
41 import com.fasterxml.jackson.annotation.JsonIgnore;
44 * We can use annotations to differentiate between intermediate data we use to build the node, and
45 * the data that we actually want to appear in the exported JSON.
49 * This is our current ( 14-June-2016 ) working schema that will remain organic until we get it just
52 * { "item-type": "customer", "item-name-key": "subscriber-name", “item-name-value” :
53 * “subscriber-name-123456789-aai847-data-01”, "item-properties": [{ "property-name":
54 * "subscriber-name", "property-value": "subscriber-name-123456789-aai847-data-01" }, {
55 * "property-name": "global-customer-id", "property-value":
56 * "global-customer-id-123456789-aai847-data-01" } ], "node-meta": { “color” : “#f2d2d2”,
57 * "isSearchTarget" : false, "nodeGroups" : "1,2,3,4" }, }
65 public class SparkyGraphNode {
68 private String itemType;
69 private String itemNameKey;
70 private String itemNameValue;
71 private Map<String, String> itemProperties;
72 private NodeMeta nodeMeta;
73 private ObjectInspectorPayload externalResourcePayload;
76 private boolean isRootNode;
80 private String resourceKey;
82 private Collection<String> inboundNeighbors;
85 private Collection<String> outboundNeighbors;
89 private static final Logger LOG = LoggerFactory.getInstance().getLogger(SparkyGraphNode.class);
91 private VisualizationConfigs visualizationConfigs;
92 private SubscriptionConfig subConfig;
95 * Instantiates a new SparkyGraphNode.
99 public SparkyGraphNode(ActiveInventoryNode ain, VisualizationConfigs visualizationConfigs, SubscriptionConfig subConfig) {
100 this.resourceKey = ain.getNodeId();
101 this.itemProperties = ain.getProperties();
102 this.setItemType(ain.getEntityType());
103 this.setItemNameKey(ain.getPrimaryKeyName());
104 this.setItemNameValue(ain.getPrimaryKeyValue());
105 this.setId(ain.getNodeId());
106 this.isRootNode = ain.isRootNode();
107 this.visualizationConfigs = visualizationConfigs;
108 this.setSubConfig(subConfig);
110 if (LOG.isDebugEnabled()) {
112 LOG.debug("JsonNode constructor using AIN = " + ain.dumpNodeTree(true));
116 inboundNeighbors = ain.getInboundNeighbors();
117 outboundNeighbors = ain.getOutboundNeighbors();
119 nodeMeta = new NodeMeta(this.visualizationConfigs);
121 nodeMeta.setNodeIssue(ain.isNodeIssue());
122 nodeMeta.setNodeValidated(ain.isNodeValidated());
123 nodeMeta.setNodeDepth(ain.getNodeDepth());
125 nodeMeta.setNumInboundNeighbors(ain.getInboundNeighbors().size());
126 nodeMeta.setNumOutboundNeighbors(ain.getOutboundNeighbors().size());
128 nodeMeta.setAtMaxDepth(ain.isAtMaxDepth());
129 nodeMeta.setSelfLinkResolved(!ain.isSelflinkRetrievalFailure());
130 nodeMeta.setProcessingErrorOccurred(ain.isProcessingErrorOccurred());
131 nodeMeta.setHasNeighbors(
132 ain.getOutboundNeighbors().size() > 0 || ain.getInboundNeighbors().size() > 0);
134 if (subConfig.getIsLaunchOIEnabled()) {
136 Collection<String> entityTypes = subConfig.getAnnEntitiyTypes();
137 for (String entityType : entityTypes) {
138 if (entityType.equals(this.getItemType())) {
139 ObjectInspectorPayload lic = ObjectInspectorPayload.getOIPayload(subConfig);
140 lic.getMessage().getPayload().getParams().setObjectName(this.getItemNameValue());
141 this.setExternalResourcePayload(lic);
145 } catch (IOException e) {
146 String message = "Could not map JSON to object " + "Attempted to convert: "
147 + SparkyConstants.SUBSCRIPTION_OI_MAPPING + ". Error: " + e.getLocalizedMessage();
148 LOG.error(AaiUiMsgs.JSON_PROCESSING_ERROR, message);
151 nodeMeta.setProcessingState(ain.getState());
155 public String getId() {
159 public void setId(String id) {
163 public String getItemNameKey() {
167 public String getItemNameValue() {
168 return itemNameValue;
171 public Map<String, String> getItemProperties() {
172 return itemProperties;
175 public String getItemType() {
179 public String getResourceKey() {
183 public void setItemNameKey(String itemNameKey) {
184 this.itemNameKey = itemNameKey;
187 public void setItemNameValue(String itemNameValue) {
188 this.itemNameValue = itemNameValue;
191 public void setItemProperties(HashMap<String, String> itemProperties) {
192 this.itemProperties = itemProperties;
195 public void setItemType(String itemType) {
196 this.itemType = itemType;
199 public void setResourceKey(String resourceKey) {
200 this.resourceKey = resourceKey;
203 public NodeMeta getNodeMeta() {
207 public void setNodeMeta(NodeMeta nodeMeta) {
208 this.nodeMeta = nodeMeta;
211 public boolean isRootNode() {
215 public ObjectInspectorPayload getExternalResourcePayload() {
216 return externalResourcePayload;
219 public void setExternalResourcePayload(ObjectInspectorPayload externalResourcePayload) {
220 this.externalResourcePayload = externalResourcePayload;
223 public SubscriptionConfig getSubConfig() {
227 public void setSubConfig(SubscriptionConfig subConfig) {
228 this.subConfig = subConfig;
234 * @see java.lang.Object#toString()
237 public String toString() {
238 return "JsonNode [" + (id != null ? "id=" + id + ", " : "")
239 + (itemType != null ? "itemType=" + itemType + ", " : "")
240 + (itemNameKey != null ? "itemNameKey=" + itemNameKey + ", " : "")
241 + (itemNameValue != null ? "itemNameValue=" + itemNameValue + ", " : "")
242 + (itemProperties != null ? "itemProperties=" + itemProperties + ", " : "")
243 + (nodeMeta != null ? "nodeMeta=" + nodeMeta + ", " : "")
244 + (resourceKey != null ? "resourceKey=" + resourceKey + ", " : "")
245 + (inboundNeighbors != null ? "inboundNeighbors=" + inboundNeighbors + ", " : "")
246 + (outboundNeighbors != null ? "outboundNeighbors=" + outboundNeighbors : "") + "]";