Adding interfaces in documentation
[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-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
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 package org.onap.aai.sparky.viewandinspect.entity;
22
23 import java.io.IOException;
24 import java.util.Collection;
25 import java.util.HashMap;
26 import java.util.Map;
27
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;
36
37 import com.fasterxml.jackson.annotation.JsonIgnore;
38
39 /*
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.
42  */
43
44 /*
45  * This is our current ( 14-June-2016 ) working schema that will remain organic until we get it just
46  * right.
47  *
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" }, }
54  * 
55  */
56
57
58 /**
59  * The Class JsonNode.
60  */
61 public class SparkyGraphNode {
62
63   private String id;
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;
70
71   @JsonIgnore
72   private boolean isRootNode;
73
74
75   @JsonIgnore
76   private String resourceKey;
77   @JsonIgnore
78   private Collection<String> inboundNeighbors;
79
80   @JsonIgnore
81   private Collection<String> outboundNeighbors;
82
83
84   @JsonIgnore
85   private static final Logger LOG = LoggerFactory.getInstance().getLogger(SparkyGraphNode.class);
86
87   private VisualizationConfigs visualizationConfigs;
88   private SubscriptionConfig subConfig;
89
90   /**
91    * Instantiates a new SparkyGraphNode.
92    *
93    * @param ain the ain
94    */
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);
105
106     if (LOG.isDebugEnabled()) {
107       LOG.debug("---");
108       LOG.debug("JsonNode constructor using AIN = " + ain.dumpNodeTree(true));
109       LOG.debug("---");
110     }
111
112     inboundNeighbors = ain.getInboundNeighbors();
113     outboundNeighbors = ain.getOutboundNeighbors();
114
115     nodeMeta = new NodeMeta(this.visualizationConfigs);
116
117     nodeMeta.setNodeIssue(ain.isNodeIssue());
118     nodeMeta.setNodeValidated(ain.isNodeValidated());
119     nodeMeta.setNodeDepth(ain.getNodeDepth());
120
121     nodeMeta.setNumInboundNeighbors(ain.getInboundNeighbors().size());
122     nodeMeta.setNumOutboundNeighbors(ain.getOutboundNeighbors().size());
123
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);
129
130     if (subConfig.getIsLaunchOIEnabled()) {
131       try {
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);
138             break;
139           }
140         }
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);
145       }
146     }
147     nodeMeta.setProcessingState(ain.getState());
148
149   }
150
151   public String getId() {
152     return id;
153   }
154
155   public void setId(String id) {
156     this.id = id;
157   }
158
159   public String getItemNameKey() {
160     return itemNameKey;
161   }
162
163   public String getItemNameValue() {
164     return itemNameValue;
165   }
166
167   public Map<String, String> getItemProperties() {
168     return itemProperties;
169   }
170
171   public String getItemType() {
172     return itemType;
173   }
174
175   public String getResourceKey() {
176     return resourceKey;
177   }
178
179   public void setItemNameKey(String itemNameKey) {
180     this.itemNameKey = itemNameKey;
181   }
182
183   public void setItemNameValue(String itemNameValue) {
184     this.itemNameValue = itemNameValue;
185   }
186
187   public void setItemProperties(HashMap<String, String> itemProperties) {
188     this.itemProperties = itemProperties;
189   }
190
191   public void setItemType(String itemType) {
192     this.itemType = itemType;
193   }
194
195   public void setResourceKey(String resourceKey) {
196     this.resourceKey = resourceKey;
197   }
198
199   public NodeMeta getNodeMeta() {
200     return nodeMeta;
201   }
202
203   public void setNodeMeta(NodeMeta nodeMeta) {
204     this.nodeMeta = nodeMeta;
205   }
206
207   public boolean isRootNode() {
208     return isRootNode;
209   }
210
211   public ObjectInspectorPayload getExternalResourcePayload() {
212     return externalResourcePayload;
213   }
214
215   public void setExternalResourcePayload(ObjectInspectorPayload externalResourcePayload) {
216     this.externalResourcePayload = externalResourcePayload;
217   }
218   
219   public SubscriptionConfig getSubConfig() {
220     return subConfig;
221   }
222
223   public void setSubConfig(SubscriptionConfig subConfig) {
224     this.subConfig = subConfig;
225   }
226
227   /*
228    * (non-Javadoc)
229    * 
230    * @see java.lang.Object#toString()
231    */
232   @Override
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 : "") + "]";
243   }
244 }