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