2 * ============LICENSE_START=======================================================
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
12 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
23 package org.openecomp.sparky.viewandinspect.entity;
25 import com.fasterxml.jackson.core.JsonProcessingException;
26 import com.fasterxml.jackson.databind.ObjectMapper;
27 import com.fasterxml.jackson.databind.ObjectWriter;
29 import java.util.ArrayList;
30 import java.util.List;
33 * The Class D3VisualizationOutput.
35 public class D3VisualizationOutput {
37 public GraphMeta graphMeta;
38 public List<JsonNode> nodes;
39 public List<JsonNodeLink> links;
40 public InlineMessage inlineMessage;
43 * Instantiates a new d 3 visualization output.
45 public D3VisualizationOutput() {
46 nodes = new ArrayList<JsonNode>();
47 links = new ArrayList<JsonNodeLink>();
51 public GraphMeta getGraphMeta() {
58 * @param counterName the counter name
60 public void pegCounter(String counterName) {
61 graphMeta.pegCounter(counterName);
64 public void setGraphMeta(GraphMeta graphMeta) {
65 this.graphMeta = graphMeta;
71 * @param nodes the nodes
73 public void addNodes(List<JsonNode> nodes) {
74 this.nodes.addAll(nodes);
80 * @param links the links
82 public void addLinks(List<JsonNodeLink> links) {
83 this.links.addAll(links);
86 public InlineMessage getInlineMessage() {
90 public void setInlineMessage(InlineMessage inlineMessage) {
91 this.inlineMessage = inlineMessage;
97 * @param args the arguments
98 * @throws JsonProcessingException the json processing exception
100 public static final void main(String[] args) throws JsonProcessingException {
102 ActiveInventoryNode pserverAin = new ActiveInventoryNode();
103 pserverAin.setNodeId("pserver.76786asd87asgd");
104 JsonNode pserver = new JsonNode(pserverAin);
106 List<JsonNode> nodes = new ArrayList<JsonNode>();
109 JsonNodeLink l1 = new JsonNodeLink();
110 l1.setSource(pserverAin.getNodeId());
111 l1.setTarget(pserverAin.getNodeId());
112 l1.setId(l1.getSource() + "_" + l1.getTarget());
114 List<JsonNodeLink> links = new ArrayList<JsonNodeLink>();
117 D3VisualizationOutput output = new D3VisualizationOutput();
118 output.addNodes(nodes);
119 output.addLinks(links);
122 ObjectWriter ow = new ObjectMapper().writer().withDefaultPrettyPrinter();
123 String json = ow.writeValueAsString(output);
125 System.out.println(json);