Clover icon

sunshower-core

  1. Project Clover database Fri Apr 6 2018 03:27:42 UTC
  2. Package io.sunshower.service.task.exec

File DefaultGraphTransformer.java

 

Coverage histogram

../../../../../img/srcFileCovDistChart8.png
14% of files have more coverage

Code metrics

8
50
1
1
103
88
5
0.1
50
1
5

Classes

Class Line # Actions
DefaultGraphTransformer 17 50 5
0.745762774.6%
 

Contributing tests

This file is covered by 2 tests. .

Source view

1    package io.sunshower.service.task.exec;
2   
3    import static java.util.function.Function.identity;
4   
5    import io.sunshower.common.Identifier;
6    import io.sunshower.persistence.core.DistributableEntity;
7    import io.sunshower.service.hal.core.Content;
8    import io.sunshower.service.hal.core.Edge;
9    import io.sunshower.service.hal.core.Graph;
10    import io.sunshower.service.hal.core.Vertex;
11    import io.sunshower.service.task.Node;
12    import io.sunshower.service.task.TaskGraph;
13    import java.util.List;
14    import java.util.Map;
15    import java.util.stream.Collectors;
16   
 
17    public class DefaultGraphTransformer implements GraphTransformer {
18   
 
19  2 toggle @Override
20    public TaskGraph transform(Graph graph) {
21   
22  2 Map<Identifier, Vertex> vertices =
23    graph
24    .getVertices()
25    .stream()
26    .collect(Collectors.toMap(DistributableEntity::getId, identity()));
27  2 Map<Identifier, Edge> edges =
28    graph.getEdges().stream().collect(Collectors.toMap(DistributableEntity::getId, identity()));
29  2 TaskGraph taskGraph = new TaskGraph();
30   
31  2 for (Edge e : edges.values()) {
32  2 io.sunshower.service.task.Edge edge = new io.sunshower.service.task.Edge();
33  2 edge.setId(e.getId());
34  2 Vertex source = e.getSource();
35  2 if (source != null) {
36  2 edge.setSource(source.getId());
37    }
38   
39  2 Vertex target = e.getTarget();
40   
41  2 if (!e.getContents().isEmpty()) {
42  0 for (Content c : e.getContents()) {
43  0 io.sunshower.service.task.Edge pseudoEdge = new io.sunshower.service.task.Edge();
44  0 pseudoEdge.setSource(e.getSource().getId());
45  0 pseudoEdge.setTarget(c.getId());
46  0 taskGraph.addEdge(pseudoEdge);
47   
48  0 io.sunshower.service.task.Edge pseudoEdgeToVertex = new io.sunshower.service.task.Edge();
49  0 pseudoEdgeToVertex.setSource(pseudoEdge.getSource());
50  0 pseudoEdgeToVertex.setTarget(target.getId());
51  0 final Node pseudoVertex = new Node();
52  0 pseudoVertex.setId(target.getId());
53  0 taskGraph.addNode(pseudoVertex);
54    }
55    } else {
56  2 edge.setTarget(target.getId());
57  2 taskGraph.addEdge(edge);
58    }
59    }
60   
61  2 for (Vertex v : vertices.values()) {
62  6 Node node = new Node();
63  6 node.setId(v.getId());
64  6 node.setName(v.getName());
65  6 String elementProperty = v.getElementProperty("task-reference");
66  6 if (elementProperty != null) {
67  0 node.setKey(elementProperty);
68    }
69  6 node.setValue(v);
70   
71  6 if (!v.getContents().isEmpty()) {
72   
73  1 List<Edge> adjacencies =
74    graph
75    .getEdges()
76    .stream()
77    .filter(t -> t.getSource().getId().equals(v.getId()))
78    .collect(Collectors.toList());
79  1 for (Edge e : adjacencies) {
80   
81  1 for (Content c : v.getContents()) {
82  2 final Node pseudoNode = new Node();
83  2 pseudoNode.setName(c.getName());
84  2 pseudoNode.setId(c.getId());
85  2 taskGraph.addNode(pseudoNode);
86  2 final io.sunshower.service.task.Edge vsp = new io.sunshower.service.task.Edge();
87  2 vsp.setSource(v.getId());
88  2 vsp.setTarget(pseudoNode.getId());
89  2 taskGraph.addEdge(vsp);
90   
91  2 final io.sunshower.service.task.Edge pst = new io.sunshower.service.task.Edge();
92  2 pst.setSource(pseudoNode.getId());
93  2 pst.setTarget(e.getTarget().getId());
94  2 taskGraph.addEdge(pst);
95    }
96    }
97    }
98  6 taskGraph.addNode(node);
99    }
100   
101  2 return taskGraph;
102    }
103    }