Revize 4e05470f
Přidáno uživatelem Tomáš Šimandl před asi 6 roky(ů)
plugins/imigerSpadeConverter/pom.xml | ||
---|---|---|
1 |
<?xml version="1.0" encoding="UTF-8"?> |
|
2 |
<project xmlns="http://maven.apache.org/POM/4.0.0" |
|
3 |
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
|
4 |
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> |
|
5 |
<modelVersion>4.0.0</modelVersion> |
|
6 |
|
|
7 |
<groupId>cz.zcu.kiv</groupId> |
|
8 |
<artifactId>imiger-spade-converter</artifactId> |
|
9 |
<version>1.0-SNAPSHOT</version> |
|
10 |
<packaging>jar</packaging> |
|
11 |
|
|
12 |
<properties> |
|
13 |
<maven.compiler.source>1.8</maven.compiler.source> |
|
14 |
<maven.compiler.target>1.8</maven.compiler.target> |
|
15 |
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> |
|
16 |
</properties> |
|
17 |
|
|
18 |
<build> |
|
19 |
<plugins> |
|
20 |
<plugin> |
|
21 |
<groupId>org.apache.maven.plugins</groupId> |
|
22 |
<artifactId>maven-assembly-plugin</artifactId> |
|
23 |
<configuration> |
|
24 |
<archive> |
|
25 |
<manifestFile>${project.build.outputDirectory}/META-INF/MANIFEST.MF</manifestFile> |
|
26 |
</archive> |
|
27 |
<descriptorRefs> |
|
28 |
<descriptorRef>jar-with-dependencies</descriptorRef> |
|
29 |
</descriptorRefs> |
|
30 |
</configuration> |
|
31 |
<executions> |
|
32 |
<execution> |
|
33 |
<id>make-assembly</id> <!-- this is used for inheritance merges --> |
|
34 |
<phase>package</phase> <!-- bind to the packaging phase --> |
|
35 |
<goals> |
|
36 |
<goal>single</goal> |
|
37 |
</goals> |
|
38 |
</execution> |
|
39 |
</executions> |
|
40 |
</plugin> |
|
41 |
</plugins> |
|
42 |
</build> |
|
43 |
|
|
44 |
<dependencies> |
|
45 |
<!-- Libs for JSON handling --> |
|
46 |
<dependency> |
|
47 |
<groupId>com.google.code.gson</groupId> |
|
48 |
<artifactId>gson</artifactId> |
|
49 |
<version>2.8.5</version> |
|
50 |
</dependency> |
|
51 |
<dependency> |
|
52 |
<groupId>net.sf.json-lib</groupId> |
|
53 |
<artifactId>json-lib</artifactId> |
|
54 |
<version>2.4</version> |
|
55 |
<classifier>jdk15</classifier> |
|
56 |
</dependency> |
|
57 |
|
|
58 |
<!-- Lib for loading file --> |
|
59 |
<dependency> |
|
60 |
<groupId>commons-io</groupId> |
|
61 |
<artifactId>commons-io</artifactId> |
|
62 |
<version>2.6</version> |
|
63 |
</dependency> |
|
64 |
|
|
65 |
<!-- Libs for Logging --> |
|
66 |
<dependency> |
|
67 |
<groupId>org.apache.logging.log4j</groupId> |
|
68 |
<artifactId>log4j-api</artifactId> |
|
69 |
<version>2.11.1</version> |
|
70 |
</dependency> |
|
71 |
<dependency> |
|
72 |
<groupId>org.apache.logging.log4j</groupId> |
|
73 |
<artifactId>log4j-core</artifactId> |
|
74 |
<version>2.11.1</version> |
|
75 |
</dependency> |
|
76 |
|
|
77 |
<!-- Libs for Unit testing --> |
|
78 |
<dependency> |
|
79 |
<groupId>org.junit.jupiter</groupId> |
|
80 |
<artifactId>junit-jupiter-api</artifactId> |
|
81 |
<version>5.3.2</version> |
|
82 |
<scope>test</scope> |
|
83 |
</dependency> |
|
84 |
</dependencies> |
|
85 |
|
|
86 |
|
|
87 |
</project> |
plugins/imigerSpadeConverter/src/main/java/cz/zcu/kiv/imiger/plugin/spade/Spade.java | ||
---|---|---|
1 |
package cz.zcu.kiv.imiger.plugin.spade; |
|
2 |
|
|
3 |
import cz.zcu.kiv.imiger.plugin.spade.api.Graph; |
|
4 |
import cz.zcu.kiv.imiger.plugin.spade.graph.GraphManager; |
|
5 |
import cz.zcu.kiv.imiger.plugin.spade.graph.loader.GraphJSONDataLoader; |
|
6 |
import cz.zcu.kiv.imiger.plugin.spade.graph.loader.JSONConfigLoader; |
|
7 |
import net.sf.json.JSONObject; |
|
8 |
|
|
9 |
public class Spade { |
|
10 |
|
|
11 |
/** |
|
12 |
* Convert input spade JSON to RAW JSON and return it. |
|
13 |
*/ |
|
14 |
public String getRawJson(String file) { |
|
15 |
GraphManager graphManager = new GraphJSONDataLoader(file).loadData(); |
|
16 |
JSONConfigLoader configLoader = new JSONConfigLoader(graphManager); |
|
17 |
|
|
18 |
Graph graph = graphManager.createGraph(configLoader); |
|
19 |
JSONObject json = JSONObject.fromObject(graph); |
|
20 |
|
|
21 |
throw new NullPointerException(); |
|
22 |
//return json.toString(); |
|
23 |
} |
|
24 |
} |
plugins/imigerSpadeConverter/src/main/java/cz/zcu/kiv/imiger/plugin/spade/api/AttributeDataType.java | ||
---|---|---|
1 |
package cz.zcu.kiv.imiger.plugin.spade.api; |
|
2 |
|
|
3 |
public enum AttributeDataType { |
|
4 |
NUMBER { |
|
5 |
@Override |
|
6 |
public String toString() { |
|
7 |
return "number"; |
|
8 |
} |
|
9 |
}, |
|
10 |
DATE { |
|
11 |
@Override |
|
12 |
public String toString() { |
|
13 |
return "date"; |
|
14 |
} |
|
15 |
}, |
|
16 |
ENUM { |
|
17 |
@Override |
|
18 |
public String toString() { |
|
19 |
return "enum"; |
|
20 |
} |
|
21 |
}, |
|
22 |
STRING { |
|
23 |
@Override |
|
24 |
public String toString() { |
|
25 |
return "string"; |
|
26 |
} |
|
27 |
}; |
|
28 |
|
|
29 |
public static AttributeDataType getEnum(String value){ |
|
30 |
switch (value) { |
|
31 |
case "number": return AttributeDataType.NUMBER; |
|
32 |
case "date": return AttributeDataType.DATE; |
|
33 |
case "enum": return AttributeDataType.ENUM; |
|
34 |
default: return AttributeDataType.STRING; |
|
35 |
} |
|
36 |
} |
|
37 |
} |
plugins/imigerSpadeConverter/src/main/java/cz/zcu/kiv/imiger/plugin/spade/api/AttributeType.java | ||
---|---|---|
1 |
package cz.zcu.kiv.imiger.plugin.spade.api; |
|
2 |
|
|
3 |
/** |
|
4 |
* Class represents one attribute type which is used in input JSON file and in output JSON file (file between frontend |
|
5 |
* and backend). |
|
6 |
*/ |
|
7 |
public class AttributeType { |
|
8 |
/** name of attribute */ |
|
9 |
public String name; |
|
10 |
/** data type of attribute */ |
|
11 |
public AttributeDataType dataType; |
|
12 |
/** additional info */ |
|
13 |
public String text; |
|
14 |
|
|
15 |
public AttributeType(String name, AttributeDataType dataType, String text) { |
|
16 |
this.name = name; |
|
17 |
this.dataType = dataType; |
|
18 |
this.text = text; |
|
19 |
} |
|
20 |
|
|
21 |
public String getName() { |
|
22 |
return name; |
|
23 |
} |
|
24 |
|
|
25 |
public AttributeDataType getDataType() { |
|
26 |
return dataType; |
|
27 |
} |
|
28 |
|
|
29 |
public String getText() { |
|
30 |
return text; |
|
31 |
} |
|
32 |
} |
plugins/imigerSpadeConverter/src/main/java/cz/zcu/kiv/imiger/plugin/spade/api/BaseEdge.java | ||
---|---|---|
1 |
package cz.zcu.kiv.imiger.plugin.spade.api; |
|
2 |
|
|
3 |
/** |
|
4 |
* Class represents edge. Class contains attributes which are common for input JSON format and for |
|
5 |
* output JSON format (JSON between frontend and backend) |
|
6 |
*/ |
|
7 |
public class BaseEdge { |
|
8 |
/** identification number of edge */ |
|
9 |
private int id; |
|
10 |
/** original ID of vertex from edge leads */ |
|
11 |
private int from; |
|
12 |
/** original ID of vertex where edge leads */ |
|
13 |
private int to; |
|
14 |
/** additional info */ |
|
15 |
private String text; |
|
16 |
|
|
17 |
public BaseEdge(int id, int from, int to, String text) { |
|
18 |
this.id = id; |
|
19 |
this.from = from; |
|
20 |
this.to = to; |
|
21 |
this.text = text; |
|
22 |
} |
|
23 |
|
|
24 |
public int getId() { |
|
25 |
return id; |
|
26 |
} |
|
27 |
|
|
28 |
public void setId(int id) { |
|
29 |
this.id = id; |
|
30 |
} |
|
31 |
|
|
32 |
public int getFrom() { |
|
33 |
return from; |
|
34 |
} |
|
35 |
|
|
36 |
public void setFrom(int from) { |
|
37 |
this.from = from; |
|
38 |
} |
|
39 |
|
|
40 |
public int getTo() { |
|
41 |
return to; |
|
42 |
} |
|
43 |
|
|
44 |
public void setTo(int to) { |
|
45 |
this.to = to; |
|
46 |
} |
|
47 |
|
|
48 |
public String getText() { |
|
49 |
return text; |
|
50 |
} |
|
51 |
|
|
52 |
public void setText(String text) { |
|
53 |
this.text = text; |
|
54 |
} |
|
55 |
|
|
56 |
/** |
|
57 |
* Generate hash code based on attributes {@code from} and {@code to}. |
|
58 |
* @return generated hash code. |
|
59 |
*/ |
|
60 |
@Override |
|
61 |
public int hashCode() { |
|
62 |
return from * 100000 + to; |
|
63 |
} |
|
64 |
|
|
65 |
/** |
|
66 |
* Two edges are equals where their {@code from} and {@code to} are equals. |
|
67 |
* |
|
68 |
* @param edge which will be compared with this instance |
|
69 |
* @return tru if edges are equal, false otherwise |
|
70 |
*/ |
|
71 |
@Override |
|
72 |
public boolean equals(Object edge) { |
|
73 |
if (!(edge instanceof BaseEdge)) return false; |
|
74 |
|
|
75 |
BaseEdge cmpEdge = (BaseEdge) edge; |
|
76 |
return from == cmpEdge.from && to == cmpEdge.to; |
|
77 |
} |
|
78 |
} |
plugins/imigerSpadeConverter/src/main/java/cz/zcu/kiv/imiger/plugin/spade/api/BaseVertex.java | ||
---|---|---|
1 |
package cz.zcu.kiv.imiger.plugin.spade.api; |
|
2 |
|
|
3 |
/** |
|
4 |
* Class represents vertex. Class contains attributes which are common for input JSON format and for |
|
5 |
* output JSON format (JSON between frontend and backend) |
|
6 |
*/ |
|
7 |
public class BaseVertex { |
|
8 |
|
|
9 |
/** New generated identification number. */ |
|
10 |
private int id; |
|
11 |
/** Name of vertex. */ |
|
12 |
private String name; |
|
13 |
/** Index of vertex archetype. */ |
|
14 |
private int archetypeIndex; |
|
15 |
/** Additional info. */ |
|
16 |
private String text; |
|
17 |
|
|
18 |
public BaseVertex(int id, String name, int archetypeIndex, String text) { |
|
19 |
this.id = id; |
|
20 |
this.name = name; |
|
21 |
this.archetypeIndex = archetypeIndex; |
|
22 |
this.text = text; |
|
23 |
} |
|
24 |
|
|
25 |
public int getId() { |
|
26 |
return id; |
|
27 |
} |
|
28 |
|
|
29 |
public void setId(int id) { |
|
30 |
this.id = id; |
|
31 |
} |
|
32 |
|
|
33 |
public String getName() { |
|
34 |
return name; |
|
35 |
} |
|
36 |
|
|
37 |
public void setName(String name) { |
|
38 |
this.name = name; |
|
39 |
} |
|
40 |
|
|
41 |
public int getArchetype() { |
|
42 |
return archetypeIndex; |
|
43 |
} |
|
44 |
|
|
45 |
public void setArchetype(int archetypeIndex) { |
|
46 |
this.archetypeIndex = archetypeIndex; |
|
47 |
} |
|
48 |
|
|
49 |
public String getText() { |
|
50 |
return text; |
|
51 |
} |
|
52 |
|
|
53 |
public void setText(String text) { |
|
54 |
this.text = text; |
|
55 |
} |
|
56 |
|
|
57 |
/** |
|
58 |
* Generate hash code which is based on {@code originalId}. |
|
59 |
* @return generated has code |
|
60 |
*/ |
|
61 |
@Override |
|
62 |
public int hashCode() { |
|
63 |
return id; |
|
64 |
} |
|
65 |
|
|
66 |
/** |
|
67 |
* Two vertices are equals when their {@code originalId} is equals. |
|
68 |
* @param vertex which will be compared with this instance |
|
69 |
* @return true if vertices are equal, false otherwise |
|
70 |
*/ |
|
71 |
@Override |
|
72 |
public boolean equals(Object vertex) { |
|
73 |
if (!(vertex instanceof BaseVertex)) return false; |
|
74 |
return id == ((BaseVertex) vertex).id; |
|
75 |
} |
|
76 |
} |
plugins/imigerSpadeConverter/src/main/java/cz/zcu/kiv/imiger/plugin/spade/api/Edge.java | ||
---|---|---|
1 |
package cz.zcu.kiv.imiger.plugin.spade.api; |
|
2 |
|
|
3 |
import java.util.List; |
|
4 |
|
|
5 |
/** |
|
6 |
* Class represents edge which is used for output JSON format (JSON between frontend and backend). |
|
7 |
*/ |
|
8 |
public class Edge extends BaseEdge { |
|
9 |
|
|
10 |
/** |
|
11 |
* List of subedgeInfo. |
|
12 |
* When two input edges are equals, in output their are in one record and their differences are in subedgeInfo. |
|
13 |
*/ |
|
14 |
private List<SubedgeInfo> subedgeInfo; |
|
15 |
|
|
16 |
/** |
|
17 |
* Create new edge. |
|
18 |
* @param id new generated identification number |
|
19 |
* @param from original ID of vertex from edge leads |
|
20 |
* @param to original ID of vertex where edge leads |
|
21 |
* @param text additional info |
|
22 |
* @param subedgeInfo list which contains differences between equals edges |
|
23 |
*/ |
|
24 |
public Edge(int id, int from, int to, String text, List<SubedgeInfo> subedgeInfo) { |
|
25 |
super(id, from, to, text); |
|
26 |
this.subedgeInfo = subedgeInfo; |
|
27 |
} |
|
28 |
|
|
29 |
public List<SubedgeInfo> getSubedgeInfo(){ |
|
30 |
return subedgeInfo; |
|
31 |
} |
|
32 |
|
|
33 |
public void setSubedgeInfo(List<SubedgeInfo> subedgeInfo) { |
|
34 |
this.subedgeInfo = subedgeInfo; |
|
35 |
} |
|
36 |
} |
plugins/imigerSpadeConverter/src/main/java/cz/zcu/kiv/imiger/plugin/spade/api/EdgeArchetype.java | ||
---|---|---|
1 |
package cz.zcu.kiv.imiger.plugin.spade.api; |
|
2 |
|
|
3 |
public class EdgeArchetype { |
|
4 |
public String name; |
|
5 |
public String text; |
|
6 |
|
|
7 |
public EdgeArchetype(String name, String text) { |
|
8 |
this.name = name; |
|
9 |
this.text = text; |
|
10 |
} |
|
11 |
|
|
12 |
public String getName() { |
|
13 |
return name; |
|
14 |
} |
|
15 |
|
|
16 |
public String getText() { |
|
17 |
return text; |
|
18 |
} |
|
19 |
} |
plugins/imigerSpadeConverter/src/main/java/cz/zcu/kiv/imiger/plugin/spade/api/Graph.java | ||
---|---|---|
1 |
package cz.zcu.kiv.imiger.plugin.spade.api; |
|
2 |
|
|
3 |
import org.apache.logging.log4j.LogManager; |
|
4 |
import org.apache.logging.log4j.Logger; |
|
5 |
|
|
6 |
import java.util.*; |
|
7 |
|
|
8 |
/** |
|
9 |
* Class represents graph with all information about graph plus information about state in which used store graph. |
|
10 |
* Class is used for creating of JSON which is send to frontend. |
|
11 |
*/ |
|
12 |
public class Graph { |
|
13 |
|
|
14 |
private Set<Vertex> vertices; |
|
15 |
private List<Edge> edges; |
|
16 |
private List<VertexArchetype> vertexArchetypes; |
|
17 |
private List<EdgeArchetype> edgeArchetypes; |
|
18 |
private List<AttributeType> attributeTypes; |
|
19 |
private Map<String, List<String>> possibleEnumValues; |
|
20 |
|
|
21 |
private List<Group> groups; |
|
22 |
private List<SideBar> sideBar; |
|
23 |
private String highlightedVertex; // group-ID, vertex-ID |
|
24 |
private String highlightedEdge; |
|
25 |
|
|
26 |
private static final Logger logger = LogManager.getLogger(); |
|
27 |
|
|
28 |
public Graph() { |
|
29 |
vertices = new HashSet<>(); |
|
30 |
edges = new LinkedList<>(); |
|
31 |
} |
|
32 |
|
|
33 |
public List<Edge> getEdges() { |
|
34 |
logger.trace("ENTRY"); |
|
35 |
logger.trace("EXIT"); |
|
36 |
return edges; |
|
37 |
} |
|
38 |
|
|
39 |
public Set<Vertex> getVertices() { |
|
40 |
logger.trace("ENTRY"); |
|
41 |
logger.trace("EXIT"); |
|
42 |
return vertices; |
|
43 |
} |
|
44 |
|
|
45 |
public List<VertexArchetype> getVertexArchetypes() { |
|
46 |
return vertexArchetypes; |
|
47 |
} |
|
48 |
|
|
49 |
public List<EdgeArchetype> getEdgeArchetypes() { |
|
50 |
return edgeArchetypes; |
|
51 |
} |
|
52 |
|
|
53 |
public List<AttributeType> getAttributeTypes() { |
|
54 |
return attributeTypes; |
|
55 |
} |
|
56 |
|
|
57 |
public Map<String, List<String>> getPossibleEnumValues() { |
|
58 |
return possibleEnumValues; |
|
59 |
} |
|
60 |
|
|
61 |
public List<Group> getGroups() { |
|
62 |
return groups; |
|
63 |
} |
|
64 |
|
|
65 |
public List<SideBar> getSideBar() { |
|
66 |
return sideBar; |
|
67 |
} |
|
68 |
|
|
69 |
public String getHighlightedVertex() { |
|
70 |
return highlightedVertex; |
|
71 |
} |
|
72 |
|
|
73 |
public String getHighlightedEdge() { |
|
74 |
return highlightedEdge; |
|
75 |
} |
|
76 |
|
|
77 |
public void setVertexArchetypes(List<VertexArchetype> vertexArchetypes) { |
|
78 |
this.vertexArchetypes = vertexArchetypes; |
|
79 |
} |
|
80 |
|
|
81 |
public void setEdgeArchetypes(List<EdgeArchetype> edgeArchetypes) { |
|
82 |
this.edgeArchetypes = edgeArchetypes; |
|
83 |
} |
|
84 |
|
|
85 |
public void setAttributeTypes(List<AttributeType> attributeTypes) { |
|
86 |
this.attributeTypes = attributeTypes; |
|
87 |
} |
|
88 |
|
|
89 |
public void setPossibleEnumValues(Map<Integer, List<String>> possibleEnumValues) { |
|
90 |
this.possibleEnumValues = new HashMap<>(); |
|
91 |
for (Map.Entry<Integer, List<String>> entry : possibleEnumValues.entrySet()) { |
|
92 |
this.possibleEnumValues.put("" + entry.getKey(), entry.getValue()); |
|
93 |
} |
|
94 |
} |
|
95 |
|
|
96 |
public void setGroups(List<Group> groups) { |
|
97 |
this.groups = groups; |
|
98 |
} |
|
99 |
|
|
100 |
public void setSideBar(List<SideBar> sideBar) { |
|
101 |
this.sideBar = sideBar; |
|
102 |
} |
|
103 |
|
|
104 |
public void setHighlightedVertex(String highlightedVertex) { |
|
105 |
this.highlightedVertex = highlightedVertex; |
|
106 |
} |
|
107 |
|
|
108 |
public void setHighlightedEdge(String highlightedEdge) { |
|
109 |
this.highlightedEdge = highlightedEdge; |
|
110 |
} |
|
111 |
} |
plugins/imigerSpadeConverter/src/main/java/cz/zcu/kiv/imiger/plugin/spade/api/Group.java | ||
---|---|---|
1 |
package cz.zcu.kiv.imiger.plugin.spade.api; |
|
2 |
|
|
3 |
import java.util.ArrayList; |
|
4 |
import java.util.List; |
|
5 |
|
|
6 |
/** |
|
7 |
* Class represents group of edges and their settings. Used in JSON between frontend and backend. |
|
8 |
*/ |
|
9 |
public class Group { |
|
10 |
|
|
11 |
/** Generated id of group. */ |
|
12 |
private int id; |
|
13 |
/** Name of group */ |
|
14 |
private String name; |
|
15 |
/** List of vertices id which belongs to this group */ |
|
16 |
private List<Integer> verticesId; |
|
17 |
/** List of vertices id whose outgoing edges are visible. */ |
|
18 |
private List<Integer> verticesEdgeFromId; |
|
19 |
/** List of vertices id whose incoming edges are visible. */ |
|
20 |
private List<Integer> verticesEdgeToId; |
|
21 |
/** Relative position in graph */ |
|
22 |
private Position position; |
|
23 |
|
|
24 |
public Group(int id, String name){ |
|
25 |
this.id = id; |
|
26 |
this.name = name; |
|
27 |
this.verticesId = new ArrayList<>(); |
|
28 |
this.verticesEdgeFromId = new ArrayList<>(); |
|
29 |
this.verticesEdgeToId = new ArrayList<>(); |
|
30 |
this.position = null; |
|
31 |
} |
|
32 |
|
|
33 |
public Group(int id, String name, List<Integer> verticesId, List<Integer> verticesEdgeFromId, List<Integer> verticesEdgeToId) { |
|
34 |
this.id = id; |
|
35 |
this.name = name; |
|
36 |
this.verticesId = verticesId; |
|
37 |
this.verticesEdgeFromId = verticesEdgeFromId; |
|
38 |
this.verticesEdgeToId = verticesEdgeToId; |
|
39 |
this.position = null; |
|
40 |
} |
|
41 |
|
|
42 |
public int getId() { |
|
43 |
return id; |
|
44 |
} |
|
45 |
|
|
46 |
public void setId(int id) { |
|
47 |
this.id = id; |
|
48 |
} |
|
49 |
|
|
50 |
public String getName() { |
|
51 |
return name; |
|
52 |
} |
|
53 |
|
|
54 |
public void setName(String name) { |
|
55 |
this.name = name; |
|
56 |
} |
|
57 |
|
|
58 |
public List<Integer> getVerticesId() { |
|
59 |
return verticesId; |
|
60 |
} |
|
61 |
|
|
62 |
public void setVerticesId(List<Integer> verticesId) { |
|
63 |
this.verticesId = verticesId; |
|
64 |
} |
|
65 |
|
|
66 |
public List<Integer> getVerticesEdgeFromId() { |
|
67 |
return verticesEdgeFromId; |
|
68 |
} |
|
69 |
|
|
70 |
public void setVerticesEdgeFromId(List<Integer> verticesEdgeFromId) { |
|
71 |
this.verticesEdgeFromId = verticesEdgeFromId; |
|
72 |
} |
|
73 |
|
|
74 |
public List<Integer> getVerticesEdgeToId() { |
|
75 |
return verticesEdgeToId; |
|
76 |
} |
|
77 |
|
|
78 |
public void setVerticesEdgeToId(List<Integer> verticesEdgeToId) { |
|
79 |
this.verticesEdgeToId = verticesEdgeToId; |
|
80 |
} |
|
81 |
|
|
82 |
public void addVertexId(int vertexId){ |
|
83 |
this.verticesId.add(vertexId); |
|
84 |
} |
|
85 |
|
|
86 |
public void addVetexEdgeToId(int vertexId){ |
|
87 |
this.verticesEdgeToId.add(vertexId); |
|
88 |
} |
|
89 |
|
|
90 |
public void addVetexEdgeFromId(int vertexId){ |
|
91 |
this.verticesEdgeFromId.add(vertexId); |
|
92 |
} |
|
93 |
|
|
94 |
public Position getPosition() { |
|
95 |
return position; |
|
96 |
} |
|
97 |
|
|
98 |
public void setPosition(Position position) { |
|
99 |
this.position = position; |
|
100 |
} |
|
101 |
} |
plugins/imigerSpadeConverter/src/main/java/cz/zcu/kiv/imiger/plugin/spade/api/Position.java | ||
---|---|---|
1 |
package cz.zcu.kiv.imiger.plugin.spade.api; |
|
2 |
|
|
3 |
/** |
|
4 |
* Class is used for storing information about vertex/group relative position. |
|
5 |
*/ |
|
6 |
public class Position { |
|
7 |
|
|
8 |
/** Relative X position. */ |
|
9 |
private float x; |
|
10 |
/** Relative Y position */ |
|
11 |
private float y; |
|
12 |
|
|
13 |
public Position(float x, float y) { |
|
14 |
this.x = x; |
|
15 |
this.y = y; |
|
16 |
} |
|
17 |
|
|
18 |
public float getX() { |
|
19 |
return x; |
|
20 |
} |
|
21 |
|
|
22 |
public void setX(float x) { |
|
23 |
this.x = x; |
|
24 |
} |
|
25 |
|
|
26 |
public float getY() { |
|
27 |
return y; |
|
28 |
} |
|
29 |
|
|
30 |
public void setY(float y) { |
|
31 |
this.y = y; |
|
32 |
} |
|
33 |
} |
plugins/imigerSpadeConverter/src/main/java/cz/zcu/kiv/imiger/plugin/spade/api/SideBar.java | ||
---|---|---|
1 |
package cz.zcu.kiv.imiger.plugin.spade.api; |
|
2 |
|
|
3 |
/** |
|
4 |
* Class store information about item in side bar. |
|
5 |
*/ |
|
6 |
public class SideBar { |
|
7 |
|
|
8 |
/** Identification number of vertex or group which was generated in application. */ |
|
9 |
private int vertexId; |
|
10 |
/** Indicates if related vertexes of this item have visible icon which shows relation with this item. */ |
|
11 |
private boolean isIconsDisplayed; |
|
12 |
|
|
13 |
public SideBar(int vertexId, boolean isIconsDisplayed) { |
|
14 |
this.vertexId = vertexId; |
|
15 |
this.isIconsDisplayed = isIconsDisplayed; |
|
16 |
} |
|
17 |
|
|
18 |
public int getVertexId() { |
|
19 |
return vertexId; |
|
20 |
} |
|
21 |
|
|
22 |
public void setVertexId(int vertexId) { |
|
23 |
this.vertexId = vertexId; |
|
24 |
} |
|
25 |
|
|
26 |
public boolean isIconsDisplayed() { |
|
27 |
return isIconsDisplayed; |
|
28 |
} |
|
29 |
|
|
30 |
public void setIconsDisplayed(boolean iconsDisplayed) { |
|
31 |
this.isIconsDisplayed = iconsDisplayed; |
|
32 |
} |
|
33 |
} |
plugins/imigerSpadeConverter/src/main/java/cz/zcu/kiv/imiger/plugin/spade/api/SubedgeInfo.java | ||
---|---|---|
1 |
package cz.zcu.kiv.imiger.plugin.spade.api; |
|
2 |
|
|
3 |
import java.util.List; |
|
4 |
|
|
5 |
public class SubedgeInfo { |
|
6 |
|
|
7 |
/** Edge archetype index. */ |
|
8 |
private int archetype; |
|
9 |
/** Original id of edge which is taken from input JSON file. */ |
|
10 |
private int id; |
|
11 |
/** List of all tributes. Every attribute is stored in String array in pair as {attribute name, attribute value}. */ |
|
12 |
private List<String[]> attributes; |
|
13 |
|
|
14 |
/** |
|
15 |
* Create new subedgeInfo |
|
16 |
* @param id Original id of edge which is taken from input JSON file. |
|
17 |
* @param archetype Edge archetype index. |
|
18 |
* @param attributes List of all tributes. Every attribute is stored in String array in pair as {attribute name, attribute value}. |
|
19 |
*/ |
|
20 |
public SubedgeInfo(int id, int archetype, List<String[]> attributes) { |
|
21 |
this.id = id; |
|
22 |
this.archetype = archetype; |
|
23 |
this.attributes = attributes; |
|
24 |
} |
|
25 |
|
|
26 |
public int getId() { |
|
27 |
return id; |
|
28 |
} |
|
29 |
|
|
30 |
public int getArchetype() { |
|
31 |
return archetype; |
|
32 |
} |
|
33 |
|
|
34 |
public List<String[]> getAttributes() { |
|
35 |
return attributes; |
|
36 |
} |
|
37 |
} |
plugins/imigerSpadeConverter/src/main/java/cz/zcu/kiv/imiger/plugin/spade/api/Vertex.java | ||
---|---|---|
1 |
package cz.zcu.kiv.imiger.plugin.spade.api; |
|
2 |
|
|
3 |
import cz.zcu.kiv.imiger.plugin.spade.graph.VertexImpl; |
|
4 |
|
|
5 |
import java.util.List; |
|
6 |
|
|
7 |
/** |
|
8 |
* Class represents vertex which is used for output JSON format (JSON between frontend and backend) |
|
9 |
*/ |
|
10 |
public class Vertex extends BaseVertex { |
|
11 |
|
|
12 |
/** List of all tributes. Every attribute is stored in String array in pair as {attribute name, attribute value}. */ |
|
13 |
private List<String[]> attributes; |
|
14 |
/** Relative position in graph */ |
|
15 |
private Position position; |
|
16 |
|
|
17 |
/** |
|
18 |
* Create new vertex. |
|
19 |
* @param id original identification number from input file |
|
20 |
* @param name of vertex |
|
21 |
* @param archetypeIndex index of vertex archetype |
|
22 |
* @param text additional info |
|
23 |
* @param attributes List of all attributes. Every attribute is stored in String array in pair as {attribute name, attribute value}. |
|
24 |
*/ |
|
25 |
public Vertex(int id, String name, int archetypeIndex, String text, List<String[]> attributes) { |
|
26 |
super(id, name, archetypeIndex, text); |
|
27 |
this.attributes = attributes; |
|
28 |
this.position = null; |
|
29 |
} |
|
30 |
|
|
31 |
/** |
|
32 |
* Create new vertex. |
|
33 |
* @param vertex instance of VertexImpl with set all parameters |
|
34 |
* @param attributes ist of all attributes. Every attribute is stored in String array in pair as {attribute name, attribute value}. |
|
35 |
*/ |
|
36 |
public Vertex(VertexImpl vertex, List<String[]> attributes){ |
|
37 |
this(vertex.getId(), vertex.getName(), vertex.getArchetype(), vertex.getText(), attributes); |
|
38 |
} |
|
39 |
|
|
40 |
public List<String[]> getAttributes() { |
|
41 |
return attributes; |
|
42 |
} |
|
43 |
|
|
44 |
public void setAttributes(List<String[]> attributes) { |
|
45 |
this.attributes = attributes; |
|
46 |
} |
|
47 |
|
|
48 |
public Position getPosition() { |
|
49 |
return position; |
|
50 |
} |
|
51 |
|
|
52 |
public void setPosition(Position position) { |
|
53 |
this.position = position; |
|
54 |
} |
|
55 |
} |
plugins/imigerSpadeConverter/src/main/java/cz/zcu/kiv/imiger/plugin/spade/api/VertexArchetype.java | ||
---|---|---|
1 |
package cz.zcu.kiv.imiger.plugin.spade.api; |
|
2 |
|
|
3 |
public class VertexArchetype { |
|
4 |
public String name; |
|
5 |
public String text; |
|
6 |
public String icon; |
|
7 |
|
|
8 |
public VertexArchetype(String name, String text, String icon) { |
|
9 |
this.name = name; |
|
10 |
this.text = text; |
|
11 |
this.icon = icon; |
|
12 |
} |
|
13 |
|
|
14 |
public VertexArchetype(String name, String text) { |
|
15 |
this(name, text, ""); |
|
16 |
} |
|
17 |
|
|
18 |
public String getName() { |
|
19 |
return name; |
|
20 |
} |
|
21 |
|
|
22 |
public String getText() { |
|
23 |
return text; |
|
24 |
} |
|
25 |
|
|
26 |
public String getIcon() { |
|
27 |
return icon; |
|
28 |
} |
|
29 |
} |
plugins/imigerSpadeConverter/src/main/java/cz/zcu/kiv/imiger/plugin/spade/graph/Attribute.java | ||
---|---|---|
1 |
package cz.zcu.kiv.imiger.plugin.spade.graph; |
|
2 |
|
|
3 |
/** |
|
4 |
* This class represents attribute of edge or vertex. |
|
5 |
*/ |
|
6 |
public class Attribute { |
|
7 |
/** Index to array of attribute types which is defined in input JSON file */ |
|
8 |
private int typeIndex; |
|
9 |
/** Value of attribute */ |
|
10 |
private Object value; |
|
11 |
|
|
12 |
public Attribute(int typeIndex, Object value) { |
|
13 |
this.typeIndex = typeIndex; |
|
14 |
this.value = value; |
|
15 |
} |
|
16 |
|
|
17 |
public int getTypeIndex() { |
|
18 |
return typeIndex; |
|
19 |
} |
|
20 |
|
|
21 |
public void setTypeIndex(int typeIndex) { |
|
22 |
this.typeIndex = typeIndex; |
|
23 |
} |
|
24 |
|
|
25 |
public Object getValue() { |
|
26 |
return value; |
|
27 |
} |
|
28 |
|
|
29 |
public void setValue(Object value) { |
|
30 |
this.value = value; |
|
31 |
} |
|
32 |
} |
plugins/imigerSpadeConverter/src/main/java/cz/zcu/kiv/imiger/plugin/spade/graph/EdgeArchetypeInfo.java | ||
---|---|---|
1 |
package cz.zcu.kiv.imiger.plugin.spade.graph; |
|
2 |
|
|
3 |
public class EdgeArchetypeInfo { |
|
4 |
/** |
|
5 |
* index of the archetype of the vertex the edge leads to |
|
6 |
*/ |
|
7 |
public int fromArchetypeIndex; |
|
8 |
|
|
9 |
/** |
|
10 |
* index of the archetype of the edge |
|
11 |
*/ |
|
12 |
public int edgeArchetypeIndex; |
|
13 |
|
|
14 |
/** |
|
15 |
* index of the archetype of the vertex the edge leads from |
|
16 |
*/ |
|
17 |
public int toArchetypeIndex; |
|
18 |
|
|
19 |
public EdgeArchetypeInfo(int fromArchetypeIndex, int edgeArchetypeIndex, int toArchetypeIndex) { |
|
20 |
this.fromArchetypeIndex = fromArchetypeIndex; |
|
21 |
this.edgeArchetypeIndex = edgeArchetypeIndex; |
|
22 |
this.toArchetypeIndex = toArchetypeIndex; |
|
23 |
} |
|
24 |
|
|
25 |
@Override |
|
26 |
public int hashCode() { |
|
27 |
return fromArchetypeIndex * 10000 + edgeArchetypeIndex * 100 + fromArchetypeIndex; |
|
28 |
} |
|
29 |
|
|
30 |
@Override |
|
31 |
public boolean equals(Object obj) { |
|
32 |
if(!(obj instanceof EdgeArchetypeInfo)) return false; |
|
33 |
|
|
34 |
EdgeArchetypeInfo info = (EdgeArchetypeInfo)obj; |
|
35 |
return (info.fromArchetypeIndex == fromArchetypeIndex) && |
|
36 |
(info.edgeArchetypeIndex == edgeArchetypeIndex) && |
|
37 |
(info.toArchetypeIndex == toArchetypeIndex); |
|
38 |
} |
|
39 |
} |
plugins/imigerSpadeConverter/src/main/java/cz/zcu/kiv/imiger/plugin/spade/graph/EdgeImpl.java | ||
---|---|---|
1 |
package cz.zcu.kiv.imiger.plugin.spade.graph; |
|
2 |
|
|
3 |
import cz.zcu.kiv.imiger.plugin.spade.api.BaseEdge; |
|
4 |
|
|
5 |
import java.util.*; |
|
6 |
|
|
7 |
/** |
|
8 |
* Class represents edge which is used for input JSON format. |
|
9 |
*/ |
|
10 |
public class EdgeImpl extends BaseEdge { |
|
11 |
|
|
12 |
/** original identification number which is defined in input file */ |
|
13 |
private int originalId; |
|
14 |
/** index of edge archetype */ |
|
15 |
private int archetypeIndex; |
|
16 |
/** Map contains attributes stored in key value format. Key is index to array of attribute types defined in input file */ |
|
17 |
private Map<Integer, Attribute> attributesMap; |
|
18 |
|
|
19 |
/** |
|
20 |
* Create new edge. |
|
21 |
* @param id new generated identification number |
|
22 |
* @param from original ID of vertex from edge leads |
|
23 |
* @param to original ID of vertex where edge leads |
|
24 |
* @param text additional info |
|
25 |
* @param originalId original identification number which is defined in input file |
|
26 |
* @param archetypeIndex index of edge archetype |
|
27 |
*/ |
|
28 |
public EdgeImpl(int id, int from, int to, String text, int originalId, int archetypeIndex) { |
|
29 |
super(id, from, to, text); |
|
30 |
this.originalId = originalId; |
|
31 |
this.archetypeIndex = archetypeIndex; |
|
32 |
this.attributesMap = new HashMap<>(); |
|
33 |
} |
|
34 |
|
|
35 |
public Attribute getAttribute(int attrTypeIndex) { |
|
36 |
return attributesMap.get(attrTypeIndex); |
|
37 |
} |
|
38 |
|
|
39 |
public Map<Integer, Attribute> getAttributesMap() { |
|
40 |
return attributesMap; |
|
41 |
} |
|
42 |
|
|
43 |
|
|
44 |
public int getOriginalId() { |
|
45 |
return originalId; |
|
46 |
} |
|
47 |
|
|
48 |
|
|
49 |
public int getArchetype() { |
|
50 |
return archetypeIndex; |
|
51 |
} |
|
52 |
|
|
53 |
|
|
54 |
public void addAttribute(int attrTypeIndex, Object value) { |
|
55 |
Attribute attr = new Attribute(attrTypeIndex, value); |
|
56 |
attributesMap.put(attrTypeIndex, attr); |
|
57 |
} |
|
58 |
|
|
59 |
public void addAttributes(Map<Integer, Attribute> attributes) { |
|
60 |
this.attributesMap.putAll(attributes); |
|
61 |
} |
|
62 |
|
|
63 |
public void setOriginalId(int originalId) { |
|
64 |
this.originalId = originalId; |
|
65 |
} |
|
66 |
|
|
67 |
public void setArchetypeIndex(int archetypeIndex) { |
|
68 |
this.archetypeIndex = archetypeIndex; |
|
69 |
} |
|
70 |
|
|
71 |
/** |
|
72 |
* Return list of attributes sorted by their key value in {@code attributeMap} |
|
73 |
* @return sorted list |
|
74 |
*/ |
|
75 |
public List<Attribute> getSortedAttributes() { |
|
76 |
List<Attribute> list = new ArrayList<>(); |
|
77 |
ArrayList<Integer> indices = new ArrayList<>(attributesMap.keySet()); |
|
78 |
//indices.sort(Integer::compareTo); |
|
79 |
Collections.sort(indices); |
|
80 |
for (Integer index : indices) { |
|
81 |
list.add(attributesMap.get(index)); |
|
82 |
} |
|
83 |
return list; |
|
84 |
} |
|
85 |
} |
plugins/imigerSpadeConverter/src/main/java/cz/zcu/kiv/imiger/plugin/spade/graph/GraphManager.java | ||
---|---|---|
1 |
package cz.zcu.kiv.imiger.plugin.spade.graph; |
|
2 |
|
|
3 |
import cz.zcu.kiv.imiger.plugin.spade.api.*; |
|
4 |
import cz.zcu.kiv.imiger.plugin.spade.graph.filter.*; |
|
5 |
import cz.zcu.kiv.imiger.plugin.spade.graph.loader.JSONConfigLoader; |
|
6 |
|
|
7 |
import java.util.*; |
|
8 |
|
|
9 |
public class GraphManager { |
|
10 |
|
|
11 |
public List<VertexArchetype> vertexArchetypes = new ArrayList<>(); |
|
12 |
public List<EdgeArchetype> edgeArchetypes = new ArrayList<>(); |
|
13 |
public List<AttributeType> attributeTypes = new ArrayList<>(); |
|
14 |
|
|
15 |
/** |
|
16 |
* the key is the attributeType index, the value is the list of possible values |
|
17 |
*/ |
|
18 |
private Map<Integer, List<String>> possibleEnumValues = new HashMap<>(); |
|
19 |
|
|
20 |
/** |
|
21 |
* key is the archetype index, value is the set of vertices of the given archetype |
|
22 |
*/ |
|
23 |
public Map<Integer, HashSet<VertexImpl>> vertices = new HashMap<>(); |
|
24 |
|
|
25 |
/** |
|
26 |
* key is the triplet of archetypes {fromVertex, edge, toVertex}, value is the list of edges for the given archetype triplet |
|
27 |
*/ |
|
28 |
public Map<EdgeArchetypeInfo, List<EdgeImpl>> edges = new HashMap<>(); |
|
29 |
|
|
30 |
public void addVertexArchetype(String name, String text) { |
|
31 |
vertexArchetypes.add(new VertexArchetype(name, text)); |
|
32 |
} |
|
33 |
|
|
34 |
public void addEdgeArchetype(String name, String text) { |
|
35 |
edgeArchetypes.add(new EdgeArchetype(name, text)); |
|
36 |
} |
|
37 |
|
|
38 |
|
|
39 |
public void addAttributeType(String name, AttributeDataType dataType, String text) { |
|
40 |
attributeTypes.add(new AttributeType(name, dataType, text)); |
|
41 |
} |
|
42 |
|
|
43 |
/** |
|
44 |
* Adds a list of values to the possible values hashmap. All duplicated are |
|
45 |
* removed. |
|
46 |
* |
|
47 |
* @param attributeTypeId - Id of attribute type |
|
48 |
* @param values - List of values of the corresponding attribute type |
|
49 |
*/ |
|
50 |
public void addUniquePossibleAttributeValues(int attributeTypeId, List<String> values) { |
|
51 |
if (possibleEnumValues.containsKey(attributeTypeId)) { |
|
52 |
List<String> attrValues = possibleEnumValues.get(attributeTypeId); |
|
53 |
List<String> valuesWithoutDuplicates = new ArrayList<>(new HashSet<>(values)); // Converting to hashset removes duplicates |
|
54 |
valuesWithoutDuplicates.removeAll(attrValues); // Values to add without values already present in the hashmap |
|
55 |
attrValues.addAll(valuesWithoutDuplicates); |
|
56 |
} else { |
|
57 |
possibleEnumValues.put(attributeTypeId, values); |
|
58 |
} |
|
59 |
} |
|
60 |
|
|
61 |
public List<Integer> getEnumPositionsForAttrIndex(int attributeTypeId, List<String> enumValues) { |
|
62 |
List<Integer> positions = new ArrayList<>(); |
|
63 |
if (!possibleEnumValues.containsKey(attributeTypeId)) { |
|
64 |
return positions; |
|
65 |
} |
|
66 |
|
|
67 |
List<String> possibleValues = possibleEnumValues.get(attributeTypeId); |
|
68 |
for (int i = 0; i < possibleValues.size(); i++) { |
|
69 |
String possibleValue = possibleValues.get(i); |
|
70 |
if (enumValues.contains(possibleValue)) { |
|
71 |
positions.add(i); |
|
72 |
} |
|
73 |
} |
|
74 |
|
|
75 |
return positions; |
|
76 |
} |
|
77 |
|
|
78 |
/** |
|
79 |
* Gets string values from possible enums for attribute type id. |
|
80 |
* |
|
81 |
* @param attributeTypeId - Id of the attribute type |
|
82 |
* @param valuePositions - List of positions in the possible enums hashmap for which to find the enum values. |
|
83 |
* @return - List of string values of enums. |
|
84 |
*/ |
|
85 |
private List<String> getEnumStringsForAttrIndex(int attributeTypeId, List<Integer> valuePositions) { |
|
86 |
List<String> values = new ArrayList<>(); |
|
87 |
|
|
88 |
List<String> possibleValues = possibleEnumValues.get(attributeTypeId); |
|
89 |
for (int i = 0; i < possibleValues.size(); i++) { |
|
90 |
if (valuePositions.contains(i)) { |
|
91 |
values.add(possibleValues.get(i)); |
|
92 |
} |
|
93 |
} |
|
94 |
|
|
95 |
return values; |
|
96 |
} |
|
97 |
|
|
98 |
public AttributeType getAttributeDataTypeByName(String attributeName) { |
|
99 |
return attributeTypes.get(getAttributeIndex(attributeName)); |
|
100 |
} |
|
101 |
|
|
102 |
/** |
|
103 |
* Adds a record to the possibleEnumValues hashset of the attributes possible values. |
|
104 |
* |
|
105 |
* @param attributeIndex - Index of the attribute for which to add the possible values |
|
106 |
* @param possibleValues - All the possible values of the attribute |
|
107 |
*/ |
|
108 |
public void addEnumValues(int attributeIndex, List<String> possibleValues) { |
|
109 |
possibleEnumValues.put(attributeIndex, possibleValues); |
|
110 |
} |
|
111 |
|
|
112 |
/** |
|
113 |
* Creates a new vertex from input parameters and adds it to the map of |
|
114 |
* vertices with the archetypeIndex as the key. |
|
115 |
* |
|
116 |
* @param id - ID of the vertex to add |
|
117 |
* @param name - Name of the vertex |
|
118 |
* @param text - Text of the vertex |
|
119 |
* @param archetypeIndex - Type of archetype associated with this vertex |
|
120 |
* @param attributes - Map of attributes associated with the vertex |
|
121 |
*/ |
|
122 |
public void addVertex(int id, String name, String text, int archetypeIndex, Map<Integer, Attribute> attributes) { |
|
123 |
VertexImpl vertexToAdd = new VertexImpl(id, name, archetypeIndex, text); |
|
124 |
if (vertices.containsKey(archetypeIndex)) { |
|
125 |
vertices.get(archetypeIndex).add(vertexToAdd); |
|
126 |
} else { |
|
127 |
HashSet<VertexImpl> vertexSet = new HashSet<>(); |
|
128 |
vertexSet.add(vertexToAdd); |
|
129 |
vertices.put(archetypeIndex, vertexSet); |
|
130 |
} |
|
131 |
|
|
132 |
vertexToAdd.addAttributes(attributes); |
|
133 |
} |
|
134 |
|
|
135 |
/** |
|
136 |
* Creates a new edge from input parameters and adds it to the map of |
|
137 |
* edges with the archetypeIndex as the key. |
|
138 |
* |
|
139 |
* @param id - ID of the edge to add |
|
140 |
* @param from - ID of the vertex the edge comes from |
|
141 |
* @param to - ID of the vertex the edge points to |
|
142 |
* @param text - Text of edge |
|
143 |
* @param archetypeInfo - The archetype information associated with this edge |
|
144 |
* @param attributes - Map of attributes associated with the edge |
|
145 |
*/ |
|
146 |
public void addEdge(int id, int from, int to, String text, EdgeArchetypeInfo archetypeInfo, Map<Integer, Attribute> attributes) { |
|
147 |
EdgeImpl edgeToAdd = new EdgeImpl(id, from, to, text, id, archetypeInfo.edgeArchetypeIndex); |
|
148 |
edgeToAdd.addAttributes(attributes); |
|
149 |
|
|
150 |
if (edges.containsKey(archetypeInfo)) { |
|
151 |
edges.get(archetypeInfo).add(edgeToAdd); |
|
152 |
} else { |
|
153 |
List<EdgeImpl> edgesList = new ArrayList<>(); |
|
154 |
edgesList.add(edgeToAdd); |
|
155 |
edges.put(archetypeInfo, edgesList); |
|
156 |
} |
|
157 |
} |
|
158 |
|
|
159 |
/** |
|
160 |
* returns the index of a given enum value in the list of the possible enum values |
|
161 |
* |
|
162 |
* @param value the enum value |
|
163 |
* @return index in the list of possible enum values or -1 if the value is not in the list |
|
164 |
*/ |
|
165 |
public int getEnumValueIndex(int attributeTypeIndex, String value) { |
|
166 |
int index = -1; |
|
167 |
List<String> values = possibleEnumValues.get(attributeTypeIndex); |
|
168 |
for (int i = 0; i < values.size(); i++) { |
|
169 |
if (values.get(i).equals(value)) { |
|
170 |
index = i; |
|
171 |
break; |
|
172 |
} |
|
173 |
} |
|
174 |
return index; |
|
175 |
} |
|
176 |
|
|
177 |
/** |
|
178 |
* returns the index of an attribute with a given name in the attributeTypes list |
|
179 |
* |
|
180 |
* @param name the name of the attribute |
|
181 |
* @return the attribute index or -1 if there is no attribute with such a name |
|
182 |
*/ |
|
183 |
public int getAttributeIndex(String name) { |
|
184 |
int index = -1; |
|
185 |
for (int i = 0; i < attributeTypes.size(); i++) { |
|
186 |
if (attributeTypes.get(i).name.equals(name)) { |
|
187 |
index = i; |
|
188 |
break; |
|
189 |
} |
|
190 |
} |
|
191 |
return index; |
|
192 |
} |
|
193 |
|
|
194 |
/** |
|
195 |
* returns the index of an archetype with a given name in the vertexArchetypes list |
|
196 |
* |
|
197 |
* @param archetypeName name of the archetype |
|
198 |
* @return the index or -1 if there is no archetype with the given name in the list |
|
199 |
*/ |
|
200 |
public int getVertexArchetypeIndex(String archetypeName) { |
|
201 |
int index = -1; |
|
202 |
for (int i = 0; i < vertexArchetypes.size(); i++) { |
|
203 |
if (vertexArchetypes.get(i).name.equals(archetypeName)) { |
|
204 |
index = i; |
|
205 |
break; |
|
206 |
} |
|
207 |
} |
|
208 |
return index; |
|
209 |
} |
|
210 |
|
|
211 |
/** |
|
212 |
* returns the index of an archetype with a given name in the edgeArchetypes list |
|
213 |
* |
|
214 |
* @param archetypeName name of the archetype |
|
215 |
* @return the index or -1 if there is no archetype with the given name in the list |
|
216 |
*/ |
|
217 |
public int getEdgeArchetypeIndex(String archetypeName) { |
|
218 |
int index = -1; |
|
219 |
for (int i = 0; i < edgeArchetypes.size(); i++) { |
|
220 |
if (edgeArchetypes.get(i).name.equals(archetypeName)) { |
|
221 |
index = i; |
|
222 |
break; |
|
223 |
} |
|
224 |
} |
|
225 |
return index; |
|
226 |
} |
|
227 |
|
|
228 |
/** |
|
229 |
* Filters the edges and vertices according to the default filter loaded from the configuration file |
|
230 |
* and constructs the {@code Graph} object. |
|
231 |
* |
|
232 |
* @param configLoader - The object that loads the configuration file. |
|
233 |
* @return - Constructed {@code Graph} object. |
|
234 |
*/ |
|
235 |
public Graph createGraph(JSONConfigLoader configLoader) { |
|
236 |
Graph graph = new Graph(); |
|
237 |
|
|
238 |
// To use default filter from a configuration file |
|
239 |
GraphFilter filter = configLoader.loadDefaultFilter(); |
|
240 |
if (filter == null) { |
|
241 |
// To Enable Everything |
|
242 |
filter = new GraphFilter(); |
|
243 |
filter.setVertexArchetypeFilter(new ArrayList<>(), GraphFilter.ArchetypeMatchType.NON_MATCHING); |
|
244 |
filter.setEdgeArchetypeFilter(new ArrayList<>(), GraphFilter.ArchetypeMatchType.NON_MATCHING); |
|
245 |
} |
|
246 |
|
|
247 |
|
|
248 |
Set<VertexImpl> resultVertices = getVerticesByArchetypeFilter(filter); |
|
249 |
resultVertices = getVerticesByAttributeFilter(filter, resultVertices); |
|
250 |
List<EdgeImpl> resultEdges = getEdgesByArchetypeFilter(filter, resultVertices); |
|
251 |
resultEdges = getEdgesByAttributeFilter(filter, resultEdges); |
|
252 |
|
|
253 |
addVerticesToGraph(graph, resultVertices); |
|
254 |
addEdgesToGraph(graph, resultEdges); |
|
255 |
|
|
256 |
Map<String, String> archetypeIcons = configLoader.loadArchetypeIcons(); |
|
257 |
addVertexArchetypes(graph, archetypeIcons); |
|
258 |
graph.setEdgeArchetypes(edgeArchetypes); |
|
259 |
|
|
260 |
graph.setAttributeTypes(attributeTypes); |
|
261 |
graph.setPossibleEnumValues(possibleEnumValues); |
|
262 |
|
|
263 |
List<String> defaultGroupArchetypes = configLoader.loadGroupArchetypesStrings(); |
|
264 |
addDefaultGroups(graph, defaultGroupArchetypes); |
|
265 |
|
|
266 |
return graph; |
|
267 |
} |
|
268 |
|
|
269 |
/** |
|
270 |
* Gets filtered vertices by attributes. |
|
271 |
* |
|
272 |
* @param filter - Filter object. |
|
273 |
* @param vertices - List of vertices for filtration. |
|
274 |
* @return - List of vertices filtered by attribute. |
|
275 |
*/ |
|
276 |
private Set<VertexImpl> getVerticesByAttributeFilter(GraphFilter filter, Set<VertexImpl> vertices) { |
|
277 |
Set<VertexImpl> resultVertices = new HashSet<>(); |
|
278 |
for (VertexImpl vertex : vertices) { |
|
279 |
boolean filterPassed = true; |
|
280 |
AttributeFilter attributeFilter = filter.getVertexAttributeFilter(vertex.getArchetype()); |
|
281 |
if (attributeFilter != null) { |
|
282 |
// Iterate through all attributes of the vertex |
|
283 |
for (int attributeIndex : vertex.getAttributesMap().keySet()) { |
|
284 |
Attribute vertexAttribute = vertex.getAttributesMap().get(attributeIndex); |
|
285 |
|
|
286 |
filterPassed = (filterPassed && checkAttributeFiltersPassed(vertexAttribute, attributeFilter, attributeIndex)); |
|
287 |
if (!filterPassed) break; // filter did not pass |
|
288 |
} |
|
289 |
} |
|
290 |
if (filterPassed) |
|
291 |
resultVertices.add(vertex); |
|
292 |
} |
|
293 |
return resultVertices; |
|
294 |
} |
|
295 |
|
|
296 |
/** |
|
297 |
* Gets filtered edges by attribute. |
|
298 |
* |
|
299 |
* @param filter - Filter object. |
|
300 |
* @param edges - List of edges for filtration. |
|
301 |
* @return - List of edges filtered by attribute. |
|
302 |
*/ |
|
303 |
private List<EdgeImpl> getEdgesByAttributeFilter(GraphFilter filter, List<EdgeImpl> edges) { |
|
304 |
List<EdgeImpl> resultEdges = new ArrayList<>(); |
|
305 |
for (EdgeImpl edge : edges) { |
|
306 |
boolean filterPassed = true; |
|
307 |
AttributeFilter attributeFilter = filter.getEdgeAttributeFilter(edge.getArchetype()); |
|
308 |
if (attributeFilter != null) { |
|
309 |
// Iterate through all attributes of the edge |
|
310 |
for (int attributeIndex : edge.getAttributesMap().keySet()) { |
|
311 |
Attribute edgeAttribute = edge.getAttributesMap().get(attributeIndex); |
|
312 |
|
|
313 |
filterPassed = (filterPassed && checkAttributeFiltersPassed(edgeAttribute, attributeFilter, attributeIndex)); |
|
314 |
if (!filterPassed) break; // filter did not pass |
|
315 |
} |
|
316 |
} |
|
317 |
if (filterPassed) |
|
318 |
resultEdges.add(edge); |
|
319 |
} |
|
320 |
|
|
321 |
return resultEdges; |
|
322 |
} |
|
323 |
|
|
324 |
/** |
|
325 |
* Filters the attribute by its attribute filters and checks if it passed. |
|
326 |
* |
|
327 |
* @param vertexAttribute - Attribute object to filter. |
|
328 |
* @param attributeFilter - Attribute filter of the attribute. |
|
329 |
* @param attributeIndex - Index of the attribute. |
|
330 |
* @return - true if passed the filter, else false. |
|
331 |
*/ |
|
332 |
private boolean checkAttributeFiltersPassed(Attribute vertexAttribute, AttributeFilter attributeFilter, int attributeIndex) { |
|
333 |
AttributeDataType attributeType = attributeTypes.get(vertexAttribute.getTypeIndex()).dataType; |
|
334 |
|
|
335 |
boolean filterPassed; |
|
336 |
ITypeAttributeFilter typeFilter = null; |
|
337 |
switch (attributeType) { |
|
338 |
case NUMBER: |
|
339 |
typeFilter = attributeFilter.getNumberFilter(attributeIndex); |
|
340 |
break; |
|
341 |
case DATE: |
|
342 |
typeFilter = attributeFilter.getDateFilter(attributeIndex); |
|
343 |
break; |
|
344 |
case ENUM: |
|
345 |
typeFilter = attributeFilter.getEnumFilter(attributeIndex); |
|
346 |
break; |
|
347 |
case STRING: |
|
348 |
typeFilter = attributeFilter.getStringFilter(attributeIndex); |
|
349 |
break; |
|
350 |
} |
|
351 |
if (typeFilter == null) { // No filters mean pass |
|
352 |
return true; |
|
353 |
} |
|
354 |
|
|
355 |
filterPassed = typeFilter.filter(vertexAttribute.getValue()); |
|
356 |
|
|
357 |
return filterPassed; |
|
358 |
} |
|
359 |
|
|
360 |
/** |
|
361 |
* Filters vertices by archetype from the specified filter object. |
|
362 |
* |
|
363 |
* @param filter - Filter to be applied to the vertices. |
|
364 |
* @return A list of vertices filtered by the specified filter object. |
|
365 |
*/ |
|
366 |
private HashSet<VertexImpl> getVerticesByArchetypeFilter(GraphFilter filter) { |
|
367 |
HashSet<VertexImpl> resultVertices = new HashSet<>(); |
|
368 |
|
|
369 |
VertexArchetypeFilter vertexArchetypeFilter = filter.getVertexArchetypeFilter(); |
|
370 |
List<Integer> archetypesFiltered = vertexArchetypeFilter.archetypeIndeces; |
|
371 |
switch (vertexArchetypeFilter.matchType) { |
|
372 |
case MATCHING: |
|
373 |
for (Map.Entry<Integer, HashSet<VertexImpl>> vertexArchetypeEntry : vertices.entrySet()) { |
|
374 |
if (archetypesFiltered.contains(vertexArchetypeEntry.getKey())) { |
|
375 |
resultVertices.addAll(vertexArchetypeEntry.getValue()); |
|
376 |
} |
|
377 |
} |
|
378 |
break; |
|
379 |
case NON_MATCHING: |
|
380 |
for (Map.Entry<Integer, HashSet<VertexImpl>> vertexArchetypeEntry : vertices.entrySet()) { |
|
381 |
if (!archetypesFiltered.contains(vertexArchetypeEntry.getKey())) { |
|
382 |
resultVertices.addAll(vertexArchetypeEntry.getValue()); |
|
383 |
} |
|
384 |
} |
|
385 |
break; |
|
386 |
} |
|
387 |
|
|
388 |
return resultVertices; |
|
389 |
} |
|
390 |
|
|
391 |
/** |
|
392 |
* Filters edges by archetype from the specified filter object. Also removes all edges that contain either a vertex |
|
393 |
* from which the edge originates or to which the edge leads. |
|
394 |
* |
|
395 |
* @param filter - Filter to be applied to the edges list. |
|
396 |
* @param resultVertices - List of vertices which should be present in the result graph. |
|
397 |
* @return A list of edges filtered by the specified filter object |
|
398 |
*/ |
|
399 |
private List<EdgeImpl> getEdgesByArchetypeFilter(GraphFilter filter, Set<VertexImpl> resultVertices) { |
|
400 |
List<EdgeImpl> resultEdges = new ArrayList<>(); |
|
401 |
|
|
402 |
EdgeArchetypeFilter edgeArchetypeFilter = filter.getEdgeArchetypeFilter(); |
|
403 |
List<EdgeArchetypeInfo> edgeInfosFiltered = edgeArchetypeFilter.archetypeIndeces; |
|
404 |
switch (edgeArchetypeFilter.matchType) { |
|
405 |
case MATCHING: |
|
406 |
for (Map.Entry<EdgeArchetypeInfo, List<EdgeImpl>> edgeEntry : edges.entrySet()) { |
|
407 |
if (edgeInfosFiltered.contains(edgeEntry.getKey())) { |
|
408 |
resultEdges.addAll(edgeEntry.getValue()); |
|
409 |
} |
|
410 |
} |
|
411 |
break; |
|
412 |
case NON_MATCHING: |
|
413 |
for (Map.Entry<EdgeArchetypeInfo, List<EdgeImpl>> edgeEntry : edges.entrySet()) { |
|
414 |
if (!edgeInfosFiltered.contains(edgeEntry.getKey())) { |
|
415 |
resultEdges.addAll(edgeEntry.getValue()); |
|
416 |
} |
|
417 |
} |
|
418 |
break; |
|
419 |
} |
|
420 |
|
|
421 |
Iterator<EdgeImpl> i = resultEdges.iterator(); |
|
422 |
while (i.hasNext()) { |
|
423 |
EdgeImpl edge = i.next(); |
|
424 |
|
|
425 |
VertexImpl toDummy = new VertexImpl(edge.getTo(), null, -1, null); |
|
426 |
VertexImpl fromDummy = new VertexImpl(edge.getFrom(), null, -1, null); |
|
427 |
|
|
428 |
if (!resultVertices.contains(toDummy) || !resultVertices.contains(fromDummy)) { |
|
429 |
i.remove(); |
|
430 |
} |
|
431 |
} |
|
432 |
|
|
433 |
return resultEdges; |
|
434 |
} |
|
435 |
|
Také k dispozici: Unified diff
added Spade plugin sources