aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/org/onap/aai/graphgraph/reader/DummySchemaReader.java
blob: b8bca38ddcf07f1e29ada8750991b73ca68289a0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
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;
    }
}