Merge "Fix Blocker/Critical sonar issues"
[aai/sparky-be.git] / src / main / java / org / openecomp / sparky / viewandinspect / entity / D3VisualizationOutput.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.openecomp.sparky.viewandinspect.entity;
24
25 import com.fasterxml.jackson.core.JsonProcessingException;
26 import com.fasterxml.jackson.databind.ObjectMapper;
27 import com.fasterxml.jackson.databind.ObjectWriter;
28
29 import java.util.ArrayList;
30 import java.util.List;
31
32 /**
33  * The Class D3VisualizationOutput.
34  */
35 public class D3VisualizationOutput {
36
37   public GraphMeta graphMeta;
38   public List<JsonNode> nodes;
39   public List<JsonNodeLink> links;
40   public InlineMessage inlineMessage;
41
42   /**
43    * Instantiates a new d 3 visualization output.
44    */
45   public D3VisualizationOutput() {
46     nodes = new ArrayList<JsonNode>();
47     links = new ArrayList<JsonNodeLink>();
48     inlineMessage = null;
49   }
50
51   public GraphMeta getGraphMeta() {
52     return graphMeta;
53   }
54
55   /**
56    * Peg counter.
57    *
58    * @param counterName the counter name
59    */
60   public void pegCounter(String counterName) {
61     graphMeta.pegCounter(counterName);
62   }
63
64   public void setGraphMeta(GraphMeta graphMeta) {
65     this.graphMeta = graphMeta;
66   }
67
68   /**
69    * Adds the nodes.
70    *
71    * @param nodes the nodes
72    */
73   public void addNodes(List<JsonNode> nodes) {
74     this.nodes.addAll(nodes);
75   }
76
77   /**
78    * Adds the links.
79    *
80    * @param links the links
81    */
82   public void addLinks(List<JsonNodeLink> links) {
83     this.links.addAll(links);
84   }
85
86   public InlineMessage getInlineMessage() {
87     return inlineMessage;
88   }
89
90   public void setInlineMessage(InlineMessage inlineMessage) {
91     this.inlineMessage = inlineMessage;
92   }
93
94   /**
95    * The main method.
96    *
97    * @param args the arguments
98    * @throws JsonProcessingException the json processing exception
99    */
100   public static final void main(String[] args) throws JsonProcessingException {
101
102     ActiveInventoryNode pserverAin = new ActiveInventoryNode();
103     pserverAin.setNodeId("pserver.76786asd87asgd");
104     JsonNode pserver = new JsonNode(pserverAin);
105
106     List<JsonNode> nodes = new ArrayList<JsonNode>();
107     nodes.add(pserver);
108
109     JsonNodeLink l1 = new JsonNodeLink();
110     l1.setSource(pserverAin.getNodeId());
111     l1.setTarget(pserverAin.getNodeId());
112     l1.setId(l1.getSource() + "_" + l1.getTarget());
113
114     List<JsonNodeLink> links = new ArrayList<JsonNodeLink>();
115     links.add(l1);
116
117     D3VisualizationOutput output = new D3VisualizationOutput();
118     output.addNodes(nodes);
119     output.addLinks(links);
120
121
122     ObjectWriter ow = new ObjectMapper().writer().withDefaultPrettyPrinter();
123     String json = ow.writeValueAsString(output);
124
125     System.out.println(json);
126
127   }
128
129 }