Convert Sparky to Spring-Boot
[aai/sparky-be.git] / sparkybe-onap-service / src / main / java / org / onap / aai / sparky / viewandinspect / entity / SparkyGraphNode.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 package org.onap.aai.sparky.viewandinspect.entity;
26
27 import java.io.IOException;
28 import java.util.Collection;
29 import java.util.HashMap;
30 import java.util.Map;
31
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;
40
41 import com.fasterxml.jackson.annotation.JsonIgnore;
42
43 /*
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.
46  */
47
48 /*
49  * This is our current ( 14-June-2016 ) working schema that will remain organic until we get it just
50  * right.
51  *
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" }, }
58  * 
59  */
60
61
62 /**
63  * The Class JsonNode.
64  */
65 public class SparkyGraphNode {
66
67   private String id;
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;
74
75   @JsonIgnore
76   private boolean isRootNode;
77
78
79   @JsonIgnore
80   private String resourceKey;
81   @JsonIgnore
82   private Collection<String> inboundNeighbors;
83
84   @JsonIgnore
85   private Collection<String> outboundNeighbors;
86
87
88   @JsonIgnore
89   private static final Logger LOG = LoggerFactory.getInstance().getLogger(SparkyGraphNode.class);
90
91   private VisualizationConfigs visualizationConfigs;
92   private SubscriptionConfig subConfig;
93
94   /**
95    * Instantiates a new SparkyGraphNode.
96    *
97    * @param ain the ain
98    */
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);
109
110     if (LOG.isDebugEnabled()) {
111       LOG.debug("---");
112       LOG.debug("JsonNode constructor using AIN = " + ain.dumpNodeTree(true));
113       LOG.debug("---");
114     }
115
116     inboundNeighbors = ain.getInboundNeighbors();
117     outboundNeighbors = ain.getOutboundNeighbors();
118
119     nodeMeta = new NodeMeta(this.visualizationConfigs);
120
121     nodeMeta.setNodeIssue(ain.isNodeIssue());
122     nodeMeta.setNodeValidated(ain.isNodeValidated());
123     nodeMeta.setNodeDepth(ain.getNodeDepth());
124
125     nodeMeta.setNumInboundNeighbors(ain.getInboundNeighbors().size());
126     nodeMeta.setNumOutboundNeighbors(ain.getOutboundNeighbors().size());
127
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);
133
134     if (subConfig.getIsLaunchOIEnabled()) {
135       try {
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);
142             break;
143           }
144         }
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);
149       }
150     }
151     nodeMeta.setProcessingState(ain.getState());
152
153   }
154
155   public String getId() {
156     return id;
157   }
158
159   public void setId(String id) {
160     this.id = id;
161   }
162
163   public String getItemNameKey() {
164     return itemNameKey;
165   }
166
167   public String getItemNameValue() {
168     return itemNameValue;
169   }
170
171   public Map<String, String> getItemProperties() {
172     return itemProperties;
173   }
174
175   public String getItemType() {
176     return itemType;
177   }
178
179   public String getResourceKey() {
180     return resourceKey;
181   }
182
183   public void setItemNameKey(String itemNameKey) {
184     this.itemNameKey = itemNameKey;
185   }
186
187   public void setItemNameValue(String itemNameValue) {
188     this.itemNameValue = itemNameValue;
189   }
190
191   public void setItemProperties(HashMap<String, String> itemProperties) {
192     this.itemProperties = itemProperties;
193   }
194
195   public void setItemType(String itemType) {
196     this.itemType = itemType;
197   }
198
199   public void setResourceKey(String resourceKey) {
200     this.resourceKey = resourceKey;
201   }
202
203   public NodeMeta getNodeMeta() {
204     return nodeMeta;
205   }
206
207   public void setNodeMeta(NodeMeta nodeMeta) {
208     this.nodeMeta = nodeMeta;
209   }
210
211   public boolean isRootNode() {
212     return isRootNode;
213   }
214
215   public ObjectInspectorPayload getExternalResourcePayload() {
216     return externalResourcePayload;
217   }
218
219   public void setExternalResourcePayload(ObjectInspectorPayload externalResourcePayload) {
220     this.externalResourcePayload = externalResourcePayload;
221   }
222   
223   public SubscriptionConfig getSubConfig() {
224     return subConfig;
225   }
226
227   public void setSubConfig(SubscriptionConfig subConfig) {
228     this.subConfig = subConfig;
229   }
230
231   /*
232    * (non-Javadoc)
233    * 
234    * @see java.lang.Object#toString()
235    */
236   @Override
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 : "") + "]";
247   }
248 }