aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/org
diff options
context:
space:
mode:
authorPavel Paroulek <pavel.paroulek@orange.com>2019-01-15 18:53:50 +0100
committerPavel Paroulek <pavel.paroulek@orange.com>2019-01-15 18:53:50 +0100
commit58457a8de75959ae07dc09df095d72adc5965a7c (patch)
tree2c90c601d32099a42b33eeab4aa4bcf1e112767f /src/main/java/org
parent81ff4563106192982aef4abcce91b78d54891247 (diff)
Initial commit
Java dummy backend and frontend Change-Id: I8c5528fcf8a746154e0463e065238061ddf6b877 Issue-ID: AAI-532 Signed-off-by: Pavel Paroulek <pavel.paroulek@orange.com>
Diffstat (limited to 'src/main/java/org')
-rw-r--r--src/main/java/org/onap/aai/graphgraph/App.java13
-rw-r--r--src/main/java/org/onap/aai/graphgraph/Config.java25
-rw-r--r--src/main/java/org/onap/aai/graphgraph/SchemaResource.java74
-rw-r--r--src/main/java/org/onap/aai/graphgraph/dto/Edge.java49
-rw-r--r--src/main/java/org/onap/aai/graphgraph/dto/Graph.java49
-rw-r--r--src/main/java/org/onap/aai/graphgraph/dto/NodeName.java17
-rw-r--r--src/main/java/org/onap/aai/graphgraph/dto/Property.java27
-rw-r--r--src/main/java/org/onap/aai/graphgraph/reader/DummySchemaReader.java108
-rw-r--r--src/main/java/org/onap/aai/graphgraph/reader/Parser.java112
-rw-r--r--src/main/java/org/onap/aai/graphgraph/reader/SchemaReader.java16
-rw-r--r--src/main/java/org/onap/aai/graphgraph/reader/SchemaRepository.java25
11 files changed, 515 insertions, 0 deletions
diff --git a/src/main/java/org/onap/aai/graphgraph/App.java b/src/main/java/org/onap/aai/graphgraph/App.java
new file mode 100644
index 0000000..35a8b86
--- /dev/null
+++ b/src/main/java/org/onap/aai/graphgraph/App.java
@@ -0,0 +1,13 @@
+package org.onap.aai.graphgraph;
+
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+
+@SpringBootApplication
+public class App
+{
+ public static void main( String[] args )
+ {
+ SpringApplication.run(App.class, args);
+ }
+}
diff --git a/src/main/java/org/onap/aai/graphgraph/Config.java b/src/main/java/org/onap/aai/graphgraph/Config.java
new file mode 100644
index 0000000..ab364a5
--- /dev/null
+++ b/src/main/java/org/onap/aai/graphgraph/Config.java
@@ -0,0 +1,25 @@
+package org.onap.aai.graphgraph;
+
+
+import org.onap.aai.graphgraph.reader.DummySchemaReader;
+import org.onap.aai.graphgraph.reader.SchemaRepository;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.ComponentScan;
+import org.springframework.context.annotation.Configuration;
+
+import java.util.Collections;
+
+@Configuration
+@ComponentScan("org.onap.aai.graphgraph")
+public class Config {
+
+ @Bean
+ SchemaRepository createSchemaRepository(){
+ DummySchemaReader dummyReader = new DummySchemaReader();
+ SchemaRepository repository = new SchemaRepository(Collections.singletonList(dummyReader));
+ return repository;
+ }
+
+}
+
+
diff --git a/src/main/java/org/onap/aai/graphgraph/SchemaResource.java b/src/main/java/org/onap/aai/graphgraph/SchemaResource.java
new file mode 100644
index 0000000..f6823ee
--- /dev/null
+++ b/src/main/java/org/onap/aai/graphgraph/SchemaResource.java
@@ -0,0 +1,74 @@
+package org.onap.aai.graphgraph;
+
+import org.onap.aai.graphgraph.dto.Graph;
+import org.onap.aai.graphgraph.dto.NodeName;
+import org.onap.aai.graphgraph.dto.Property;
+import org.onap.aai.graphgraph.reader.SchemaRepository;
+import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.bind.annotation.RestController;
+
+import javax.annotation.Resource;
+import java.util.Collections;
+import java.util.List;
+
+@RestController
+public class SchemaResource {
+
+ @Resource
+ SchemaRepository repository;
+
+ @RequestMapping("/schemas")
+ public List<String> loadSchemaNames() {
+ return repository.getAllSchemaNames();
+ }
+
+
+ @RequestMapping("/schemas/{schema}/nodes")
+ public List<NodeName> loadVertexNames(@PathVariable("schema") String schemaName) {
+ return repository.getSchemaReader(schemaName).getAllVertexNames();
+ }
+
+ @RequestMapping("/schemas/{schema}/nodes/{node}")
+ public List<Property> loadProperties(@PathVariable("schema") String schemaName, @PathVariable("node") String node) {
+ return repository.getSchemaReader(schemaName).getVertexProperties(node);
+ }
+
+
+ @RequestMapping("/schemas/{schema}/edges")
+ public List<Property> loadedgeProperties(
+ @PathVariable("schema") String schemaName,
+ @RequestParam("fromNode") String fromNodeName,
+ @RequestParam("toNode") String toNodeName) {
+ return repository.getSchemaReader(schemaName).getEdgeProperties(fromNodeName, toNodeName);
+ }
+
+
+ @RequestMapping("/schemas/{schema}/graph/basic")
+ public Graph loadGraph(
+ @PathVariable("schema") String schemaName,
+ @RequestParam("node") String initialNodeName,
+ @RequestParam("parentHops") Integer parentHops,
+ @RequestParam("cousinHops") Integer cousinHops,
+ @RequestParam("childHops") Integer childHops)
+ {
+ Graph graph = repository.getSchemaReader(schemaName).getGraph(initialNodeName, parentHops, cousinHops, childHops);
+ graph.setPaths(Collections.emptyList());
+ return graph;
+ }
+
+
+ @RequestMapping("/schemas/{schema}/graph/paths")
+ public Graph loadGraphWithPaths(
+ @PathVariable("schema") String schemaName,
+ @RequestParam("fromNode") String fromNode,
+ @RequestParam("toNode") String toNode)
+ {
+ return repository.getSchemaReader(schemaName).getGraph(fromNode, toNode);
+ }
+
+
+}
+
+
diff --git a/src/main/java/org/onap/aai/graphgraph/dto/Edge.java b/src/main/java/org/onap/aai/graphgraph/dto/Edge.java
new file mode 100644
index 0000000..e8ad9c5
--- /dev/null
+++ b/src/main/java/org/onap/aai/graphgraph/dto/Edge.java
@@ -0,0 +1,49 @@
+package org.onap.aai.graphgraph.dto;
+
+import java.util.List;
+
+public class Edge {
+ private String source;
+ private String target;
+ private String type;
+ private List<Property> tooltipProperties;
+
+ public Edge(String source, String target, String type, List<Property> tooltipProperties) {
+ this.source = source;
+ this.target = target;
+ this.type = type;
+ this.tooltipProperties = tooltipProperties;
+ }
+
+ public List<Property> getTooltipProperties() {
+ return tooltipProperties;
+ }
+
+ public void setTooltipProperties(List<Property> tooltipProperties) {
+ this.tooltipProperties = tooltipProperties;
+ }
+
+ public String getSource() {
+ return source;
+ }
+
+ public void setSource(String source) {
+ this.source = source;
+ }
+
+ public String getTarget() {
+ return target;
+ }
+
+ public void setTarget(String target) {
+ this.target = target;
+ }
+
+ public String getType() {
+ return type;
+ }
+
+ public void setType(String type) {
+ this.type = type;
+ }
+}
diff --git a/src/main/java/org/onap/aai/graphgraph/dto/Graph.java b/src/main/java/org/onap/aai/graphgraph/dto/Graph.java
new file mode 100644
index 0000000..ca496b6
--- /dev/null
+++ b/src/main/java/org/onap/aai/graphgraph/dto/Graph.java
@@ -0,0 +1,49 @@
+package org.onap.aai.graphgraph.dto;
+
+import java.util.List;
+
+public class Graph {
+ private List<NodeName> nodeNames;
+ private List<Edge> edges;
+ private List<List<NodeName>> paths;
+ private List <Property> startNodeProperties;
+
+ public Graph(List<NodeName> nodeNames, List<Edge> edges, List<List<NodeName>> pathsList, List <Property> startNodeProperties) {
+ this.nodeNames = nodeNames;
+ this.edges = edges;
+ this.paths = pathsList;
+ this.startNodeProperties = startNodeProperties;
+ }
+
+ public List<Property> getStartNodeProperties() {
+ return startNodeProperties;
+ }
+
+ public void setStartNodeProperties(List<Property> startNodeProperties) {
+ this.startNodeProperties = startNodeProperties;
+ }
+
+ public List<List<NodeName>> getPaths() {
+ return paths;
+ }
+
+ public void setPaths(List<List<NodeName>> paths) {
+ this.paths = paths;
+ }
+
+ public List<NodeName> getNodeNames() {
+ return nodeNames;
+ }
+
+ public void setNodeNames(List<NodeName> nodeNames) {
+ this.nodeNames = nodeNames;
+ }
+
+ public List<Edge> getEdges() {
+ return edges;
+ }
+
+ public void setEdges(List<Edge> edges) {
+ this.edges = edges;
+ }
+}
diff --git a/src/main/java/org/onap/aai/graphgraph/dto/NodeName.java b/src/main/java/org/onap/aai/graphgraph/dto/NodeName.java
new file mode 100644
index 0000000..4c3051b
--- /dev/null
+++ b/src/main/java/org/onap/aai/graphgraph/dto/NodeName.java
@@ -0,0 +1,17 @@
+package org.onap.aai.graphgraph.dto;
+
+public class NodeName {
+ private String id;
+
+ public NodeName(String name) {
+ this.id = name;
+ }
+
+ public String getId() {
+ return id;
+ }
+
+ public void setId(String id) {
+ this.id = id;
+ }
+}
diff --git a/src/main/java/org/onap/aai/graphgraph/dto/Property.java b/src/main/java/org/onap/aai/graphgraph/dto/Property.java
new file mode 100644
index 0000000..0e0d1d6
--- /dev/null
+++ b/src/main/java/org/onap/aai/graphgraph/dto/Property.java
@@ -0,0 +1,27 @@
+package org.onap.aai.graphgraph.dto;
+
+public class Property {
+ private String propertyName;
+ private String propertyValue;
+
+ public Property(String propertyName, String propertyValue) {
+ this.propertyName = propertyName;
+ this.propertyValue = propertyValue;
+ }
+
+ public String getPropertyName() {
+ return propertyName;
+ }
+
+ public void setPropertyName(String propertyName) {
+ this.propertyName = propertyName;
+ }
+
+ public String getPropertyValue() {
+ return propertyValue;
+ }
+
+ public void setPropertyValue(String propertyValue) {
+ this.propertyValue = propertyValue;
+ }
+}
diff --git a/src/main/java/org/onap/aai/graphgraph/reader/DummySchemaReader.java b/src/main/java/org/onap/aai/graphgraph/reader/DummySchemaReader.java
new file mode 100644
index 0000000..b8bca38
--- /dev/null
+++ b/src/main/java/org/onap/aai/graphgraph/reader/DummySchemaReader.java
@@ -0,0 +1,108 @@
+package org.onap.aai.graphgraph.reader;
+
+import org.onap.aai.graphgraph.dto.Edge;
+import org.onap.aai.graphgraph.dto.Graph;
+import org.onap.aai.graphgraph.dto.NodeName;
+import org.onap.aai.graphgraph.dto.Property;
+import org.xml.sax.SAXException;
+
+import javax.xml.parsers.ParserConfigurationException;
+import java.io.IOException;
+import java.util.*;
+import java.util.stream.Collectors;
+
+public class DummySchemaReader implements SchemaReader{
+
+ @Override
+ public String getSchemaName() {
+ return "dummy";
+ }
+
+ @Override
+ public List<NodeName> getAllVertexNames() {
+ try {
+ Parser.parse();
+ } catch (IOException | ParserConfigurationException | SAXException e) {
+ e.printStackTrace();
+ }
+
+ List<NodeName> names = Parser.getNodes().stream()
+ .map(NodeName::new).sorted(Comparator.comparing(NodeName::getId)).collect(Collectors.toList());
+ return names;
+ }
+
+ @Override
+ public List<Property> getVertexProperties(String nodeName) {
+ return getProperties("node");
+ }
+
+ @Override
+ public List<Property> getEdgeProperties(String fromNode, String toNode) {
+ return getProperties("edge");
+ }
+
+ @Override
+ public Graph getGraph(String initialNode, int parentHops, int cousingHops, int childHops) {
+ try {
+ Parser.parse();
+ } catch (IOException | ParserConfigurationException | SAXException e) {
+ e.printStackTrace();
+ }
+
+ List<Edge> edges = new LinkedList<>();
+ Parser.getNodes();
+ Random rand = new Random(System.currentTimeMillis());
+
+ for (int i = 0; i < 20; i++) {
+ int v1 = rand.nextInt(Parser.getNodes().size() - 1);
+ int v2 = rand.nextInt(Parser.getNodes().size() - 1);
+
+ edges.add(new Edge(Parser.getNodes().get(v1), Parser.getNodes().get(v2), "parent", getProperties("edgeshort")));
+ }
+
+ return new Graph( Parser.getNodes().stream().map(NodeName::new).collect(Collectors.toList()), edges, getPaths(), getProperties("node"));
+ }
+
+ @Override
+ public Graph getGraph(String fromNode, String toNode) {
+ return getGraph(fromNode,1,1,1);
+ }
+
+
+ public static List<Property> getProperties(String type) {
+ List<Property> result = new LinkedList<>();
+
+ Property p0 = new Property("proptype", type);
+ Property p1 = new Property("prop1", "test1");
+ Property p2 = new Property("prop2", "test2");
+ Property p3 = new Property("random", String.valueOf(new Random(System.currentTimeMillis()).nextInt(1000)));
+
+ result.add(p1);
+ result.add(p2);
+ result.add(p3);
+ result.add(p0);
+
+ return result;
+ }
+
+ private List<List<NodeName>> getPaths() {
+ List <List<NodeName>> l = new LinkedList<>();
+ List <NodeName> l1 = new LinkedList<>();
+ List <NodeName> l2 = new LinkedList<>();
+
+ l1.add(new NodeName("action"));
+ l1.add(new NodeName("pserver"));
+ l1.add(new NodeName("vserver"));
+ l1.add(new NodeName("complex"));
+
+ l2.add(new NodeName("XXaction"));
+ l2.add(new NodeName("XXaction2"));
+ l2.add(new NodeName("XXserver"));
+ l2.add(new NodeName("XXservers"));
+
+ l.add(l1);
+ l.add(l2);
+
+ return l;
+ }
+}
diff --git a/src/main/java/org/onap/aai/graphgraph/reader/Parser.java b/src/main/java/org/onap/aai/graphgraph/reader/Parser.java
new file mode 100644
index 0000000..7db1eb6
--- /dev/null
+++ b/src/main/java/org/onap/aai/graphgraph/reader/Parser.java
@@ -0,0 +1,112 @@
+package org.onap.aai.graphgraph.reader;
+
+import com.tinkerpop.blueprints.Graph;
+import com.tinkerpop.blueprints.Vertex;
+import com.tinkerpop.blueprints.impls.tg.TinkerGraphFactory;
+import org.onap.aai.graphgraph.dto.Edge;
+import org.springframework.core.io.ClassPathResource;
+import org.w3c.dom.Document;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+import org.xml.sax.SAXException;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+import java.io.File;
+import java.io.IOException;
+import java.util.*;
+
+import static org.onap.aai.graphgraph.reader.DummySchemaReader.getProperties;
+
+public class Parser {
+
+ static Graph g = TinkerGraphFactory.createTinkerGraph();
+ static int counter = 10000;
+ private static List<String> nodeNames = new ArrayList<>();
+ static List <Edge> edges = new LinkedList<>();
+
+ public static List<String> getNodes(){
+ Set<String> hs = new HashSet<>();
+ hs.addAll(nodeNames);
+ nodeNames.clear();
+ nodeNames.addAll(hs);
+ return nodeNames;
+ }
+
+
+ public static void parse() throws IOException, SAXException, ParserConfigurationException {
+
+ //File fXmlFile = new File("src/main/resources/aai_schema_v11.xsd");
+ File fXmlFile = new ClassPathResource("aai_schema_v11.xsd").getFile();
+ DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
+ DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
+ Document doc = dBuilder.parse(fXmlFile);
+
+ doc.getDocumentElement().normalize();
+
+ NodeList elements = doc.getElementsByTagName("xs:element");
+
+ for (int i = 0; i < elements.getLength(); i++) {
+ Node node = elements.item(i);
+ handleNode(node, null);
+ }
+ }
+
+ private static boolean isType(Node c) {
+ String type = c.getAttributes().getNamedItem("type").getNodeValue();
+ return type.equals("xs:string")
+ || type.equals("xs:int")
+ || type.equals("xs:boolean")
+ || type.equals("xs:unsignedInt");
+ }
+
+ static void handleNode(Node c, Node parent){
+ if (c.getNodeName().equals("xs:complexType") || c.getNodeName().equals("xs:sequence")){
+ for (int i = 0; i < c.getChildNodes().getLength(); i++)
+ handleNode(c.getChildNodes().item(i), parent);
+ return;
+ }
+
+ if(c.getAttributes() == null)
+ return;
+
+ if(c.getAttributes().getNamedItem("name") == null && c.getAttributes().getNamedItem("ref") == null)
+ return;
+
+ if(c.getAttributes().getNamedItem("type") != null)
+ if(isType(c))
+ return;
+
+ String vertexId = determineVertexId(c);
+ nodeNames.add(vertexId);
+
+ Vertex current;
+
+ if (g.getVertex(vertexId) == null) {
+ current = g.addVertex(vertexId);
+ }else
+ current = g.getVertex(vertexId);
+
+ NodeList childNodes = getChildren(c);
+ for (int i = 0; i < childNodes.getLength(); i++)
+ handleNode(childNodes.item(i), c);
+
+ if(parent != null) {
+ g.addEdge(counter++, g.getVertex(determineVertexId(parent)), current, "parent");
+ edges.add(new Edge(g.getVertex(determineVertexId(parent)).getId().toString(), current.getId().toString(), "parent", getProperties("edgeshort")));
+ }
+
+ }
+
+ private static NodeList getChildren(Node n) {
+ NodeList childNodes = n.getChildNodes();
+ return childNodes;
+ }
+
+ private static String determineVertexId(Node n) {
+ Node nameAttrib = n.getAttributes().getNamedItem("name");
+ return nameAttrib != null ? nameAttrib.getNodeValue() : n.getAttributes().getNamedItem("ref").getNodeValue().split(":")[1];
+ }
+
+}
diff --git a/src/main/java/org/onap/aai/graphgraph/reader/SchemaReader.java b/src/main/java/org/onap/aai/graphgraph/reader/SchemaReader.java
new file mode 100644
index 0000000..be01e6a
--- /dev/null
+++ b/src/main/java/org/onap/aai/graphgraph/reader/SchemaReader.java
@@ -0,0 +1,16 @@
+package org.onap.aai.graphgraph.reader;
+
+import org.onap.aai.graphgraph.dto.Graph;
+import org.onap.aai.graphgraph.dto.NodeName;
+import org.onap.aai.graphgraph.dto.Property;
+
+import java.util.List;
+
+public interface SchemaReader {
+ String getSchemaName();
+ List<NodeName> getAllVertexNames();
+ List<Property> getVertexProperties(String nodeName);
+ List<Property> getEdgeProperties(String fromNode, String toNode);
+ Graph getGraph(String initialNode, int parentHops, int cousingHops, int childHops);
+ Graph getGraph(String fromNode, String toNode);
+}
diff --git a/src/main/java/org/onap/aai/graphgraph/reader/SchemaRepository.java b/src/main/java/org/onap/aai/graphgraph/reader/SchemaRepository.java
new file mode 100644
index 0000000..c7fdd33
--- /dev/null
+++ b/src/main/java/org/onap/aai/graphgraph/reader/SchemaRepository.java
@@ -0,0 +1,25 @@
+package org.onap.aai.graphgraph.reader;
+
+import java.util.List;
+import java.util.Optional;
+import java.util.stream.Collectors;
+
+public class SchemaRepository {
+ private List<SchemaReader> readers;
+
+ public SchemaRepository(List<SchemaReader> readers) {
+ this.readers = readers;
+ }
+
+ public List<String> getAllSchemaNames(){
+ return readers.stream().map(SchemaReader::getSchemaName).collect(Collectors.toList());
+ }
+
+ public SchemaReader getSchemaReader(String schemaName){
+ Optional<SchemaReader> reader = readers.stream().filter(r -> schemaName.equals(r.getSchemaName())).findFirst();
+ if(!reader.isPresent())
+ throw new IllegalArgumentException("Schema " + schemaName + " not found");
+
+ return reader.get();
+ }
+}