07bb2530842b73c22370879cc577414cc81349ec
[aai/sparky-be.git] / src / main / java / org / onap / aai / sparky / viewandinspect / entity / SparkyGraphNode.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 java.io.IOException;
26 import java.util.Collection;
27 import java.util.HashMap;
28 import java.util.Map;
29
30 import org.onap.aai.cl.api.Logger;
31 import org.onap.aai.cl.eelf.LoggerFactory;
32 import org.onap.aai.sparky.aggregatevnf.search.AggregateSummaryProcessor;
33 import org.onap.aai.sparky.logging.AaiUiMsgs;
34 import org.onap.aai.sparky.subscription.config.SubscriptionConfig;
35 import org.onap.aai.sparky.subscription.payload.entity.ObjectInspectorPayload;
36 import org.onap.aai.sparky.viewandinspect.config.SparkyConstants;
37 import org.onap.aai.sparky.viewandinspect.config.VisualizationConfigs;
38
39 import com.fasterxml.jackson.annotation.JsonIgnore;
40
41 /*
42  * We can use annotations to differentiate between intermediate data we use to build the node, and
43  * the data that we actually want to appear in the exported JSON.
44  */
45
46 /*
47  * This is our current ( 14-June-2016 ) working schema that will remain organic until we get it just
48  * right.
49  *
50  * { "item-type": "customer", "item-name-key": "subscriber-name", “item-name-value” :
51  * “subscriber-name-123456789-aai847-data-01”, "item-properties": [{ "property-name":
52  * "subscriber-name", "property-value": "subscriber-name-123456789-aai847-data-01" }, {
53  * "property-name": "global-customer-id", "property-value":
54  * "global-customer-id-123456789-aai847-data-01" } ], "node-meta": { “color” : “#f2d2d2”,
55  * "isSearchTarget" : false, "nodeGroups" : "1,2,3,4" }, }
56  * 
57  */
58
59
60 /**
61  * The Class JsonNode.
62  */
63 public class SparkyGraphNode {
64
65   private String id;
66   private String itemType;
67   private String itemNameKey;
68   private String itemNameValue;
69   private Map<String, String> itemProperties;
70   private NodeMeta nodeMeta;
71   private ObjectInspectorPayload externalResourcePayload;
72
73   @JsonIgnore
74   private boolean isRootNode;
75
76
77   @JsonIgnore
78   private String resourceKey;
79   @JsonIgnore
80   private Collection<String> inboundNeighbors;
81
82   @JsonIgnore
83   private Collection<String> outboundNeighbors;
84
85
86   @JsonIgnore
87   private static final Logger LOG = LoggerFactory.getInstance().getLogger(SparkyGraphNode.class);
88
89   private VisualizationConfigs visualizationConfigs;
90   private SubscriptionConfig subConfig;
91
92   /**
93    * Instantiates a new SparkyGraphNode.
94    *
95    * @param ain the ain
96    */
97   public SparkyGraphNode(ActiveInventoryNode ain, VisualizationConfigs visualizationConfigs, SubscriptionConfig subConfig) {
98     this.resourceKey = ain.getNodeId();
99     this.itemProperties = ain.getProperties();
100     this.setItemType(ain.getEntityType());
101     this.setItemNameKey(ain.getPrimaryKeyName());
102     this.setItemNameValue(ain.getPrimaryKeyValue());
103     this.setId(ain.getNodeId());
104     this.isRootNode = ain.isRootNode();
105     this.visualizationConfigs = visualizationConfigs;
106     this.setSubConfig(subConfig);
107
108     if (LOG.isDebugEnabled()) {
109       LOG.debug("---");
110       LOG.debug("JsonNode constructor using AIN = " + ain.dumpNodeTree(true));
111       LOG.debug("---");
112     }
113
114     inboundNeighbors = ain.getInboundNeighbors();
115     outboundNeighbors = ain.getOutboundNeighbors();
116
117     nodeMeta = new NodeMeta(this.visualizationConfigs);
118
119     nodeMeta.setNodeIssue(ain.isNodeIssue());
120     nodeMeta.setNodeValidated(ain.isNodeValidated());
121     nodeMeta.setNodeDepth(ain.getNodeDepth());
122
123     nodeMeta.setNumInboundNeighbors(ain.getInboundNeighbors().size());
124     nodeMeta.setNumOutboundNeighbors(ain.getOutboundNeighbors().size());
125
126     nodeMeta.setAtMaxDepth(ain.isAtMaxDepth());
127     nodeMeta.setSelfLinkResolved(!ain.isSelflinkRetrievalFailure());
128     nodeMeta.setProcessingErrorOccurred(ain.isProcessingErrorOccurred());
129     nodeMeta.setHasNeighbors(
130         ain.getOutboundNeighbors().size() > 0 || ain.getInboundNeighbors().size() > 0);
131
132     if (subConfig.getIsLaunchOIEnabled()) {
133       try {
134         Collection<String> entityTypes = subConfig.getAnnEntitiyTypes();
135         for (String entityType : entityTypes) {
136           if (entityType.equals(this.getItemType())) {
137             ObjectInspectorPayload lic = ObjectInspectorPayload.getOIPayload(subConfig);
138             lic.getMessage().getPayload().getParams().setObjectName(this.getItemNameValue());
139             this.setExternalResourcePayload(lic);
140             break;
141           }
142         }
143       } catch (IOException e) {
144         String message = "Could not map JSON to object " + "Attempted to convert: "
145             + SparkyConstants.SUBSCRIPTION_OI_MAPPING + ". Error: " + e.getLocalizedMessage();
146         LOG.error(AaiUiMsgs.JSON_PROCESSING_ERROR, message);
147       }
148     }
149     nodeMeta.setProcessingState(ain.getState());
150
151   }
152
153   public String getId() {
154     return id;
155   }
156
157   public void setId(String id) {
158     this.id = id;
159   }
160
161   public String getItemNameKey() {
162     return itemNameKey;
163   }
164
165   public String getItemNameValue() {
166     return itemNameValue;
167   }
168
169   public Map<String, String> getItemProperties() {
170     return itemProperties;
171   }
172
173   public String getItemType() {
174     return itemType;
175   }
176
177   public String getResourceKey() {
178     return resourceKey;
179   }
180
181   public void setItemNameKey(String itemNameKey) {
182     this.itemNameKey = itemNameKey;
183   }
184
185   public void setItemNameValue(String itemNameValue) {
186     this.itemNameValue = itemNameValue;
187   }
188
189   public void setItemProperties(HashMap<String, String> itemProperties) {
190     this.itemProperties = itemProperties;
191   }
192
193   public void setItemType(String itemType) {
194     this.itemType = itemType;
195   }
196
197   public void setResourceKey(String resourceKey) {
198     this.resourceKey = resourceKey;
199   }
200
201   public NodeMeta getNodeMeta() {
202     return nodeMeta;
203   }
204
205   public void setNodeMeta(NodeMeta nodeMeta) {
206     this.nodeMeta = nodeMeta;
207   }
208
209   public boolean isRootNode() {
210     return isRootNode;
211   }
212
213   public ObjectInspectorPayload getExternalResourcePayload() {
214     return externalResourcePayload;
215   }
216
217   public void setExternalResourcePayload(ObjectInspectorPayload externalResourcePayload) {
218     this.externalResourcePayload = externalResourcePayload;
219   }
220   
221   public SubscriptionConfig getSubConfig() {
222     return subConfig;
223   }
224
225   public void setSubConfig(SubscriptionConfig subConfig) {
226     this.subConfig = subConfig;
227   }
228
229   /*
230    * (non-Javadoc)
231    * 
232    * @see java.lang.Object#toString()
233    */
234   @Override
235   public String toString() {
236     return "JsonNode [" + (id != null ? "id=" + id + ", " : "")
237         + (itemType != null ? "itemType=" + itemType + ", " : "")
238         + (itemNameKey != null ? "itemNameKey=" + itemNameKey + ", " : "")
239         + (itemNameValue != null ? "itemNameValue=" + itemNameValue + ", " : "")
240         + (itemProperties != null ? "itemProperties=" + itemProperties + ", " : "")
241         + (nodeMeta != null ? "nodeMeta=" + nodeMeta + ", " : "")
242         + (resourceKey != null ? "resourceKey=" + resourceKey + ", " : "")
243         + (inboundNeighbors != null ? "inboundNeighbors=" + inboundNeighbors + ", " : "")
244         + (outboundNeighbors != null ? "outboundNeighbors=" + outboundNeighbors : "") + "]";
245   }
246 }