Revize fa634b08
Přidáno uživatelem Pavel Fidranský před více než 6 roky(ů)
sources/src/cz/zcu/kiv/offscreen/api/BaseEdge.java | ||
---|---|---|
1 |
package cz.zcu.kiv.offscreen.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 |
} |
sources/src/cz/zcu/kiv/offscreen/api/BaseVertex.java | ||
---|---|---|
1 |
package cz.zcu.kiv.offscreen.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 |
/** Identification number which is in input file. */ |
|
12 |
private int originalId; |
|
13 |
/** Title of vertex. */ |
|
14 |
private String title; |
|
15 |
/** Index of vertex archetype. */ |
|
16 |
private int archetypeIndex; |
|
17 |
/** Additional info. */ |
|
18 |
private String text; |
|
19 |
|
|
20 |
public BaseVertex(int id, int originalId, String title, int archetypeIndex, String text) { |
|
21 |
this.id = id; |
|
22 |
this.originalId = originalId; |
|
23 |
this.title = title; |
|
24 |
this.archetypeIndex = archetypeIndex; |
|
25 |
this.text = text; |
|
26 |
} |
|
27 |
|
|
28 |
public int getId() { |
|
29 |
return id; |
|
30 |
} |
|
31 |
|
|
32 |
public void setId(int id) { |
|
33 |
this.id = id; |
|
34 |
} |
|
35 |
|
|
36 |
public int getOriginalId() { |
|
37 |
return originalId; |
|
38 |
} |
|
39 |
|
|
40 |
public void setOriginalId(int originalId) { |
|
41 |
this.originalId = originalId; |
|
42 |
} |
|
43 |
|
|
44 |
public String getTitle() { |
|
45 |
return title; |
|
46 |
} |
|
47 |
|
|
48 |
public void setTitle(String title) { |
|
49 |
this.title = title; |
|
50 |
} |
|
51 |
|
|
52 |
public int getArchetype() { |
|
53 |
return archetypeIndex; |
|
54 |
} |
|
55 |
|
|
56 |
public void setArchetype(int archetypeIndex) { |
|
57 |
this.archetypeIndex = archetypeIndex; |
|
58 |
} |
|
59 |
|
|
60 |
public String getText() { |
|
61 |
return text; |
|
62 |
} |
|
63 |
|
|
64 |
public void setText(String text) { |
|
65 |
this.text = text; |
|
66 |
} |
|
67 |
|
|
68 |
/** |
|
69 |
* Generate hash code which is based on {@code originalId}. |
|
70 |
* @return generated has code |
|
71 |
*/ |
|
72 |
@Override |
|
73 |
public int hashCode() { |
|
74 |
return originalId; |
|
75 |
} |
|
76 |
|
|
77 |
/** |
|
78 |
* Two vertices are equals when their {@code originalId} is equals. |
|
79 |
* @param edge which will be compared with this instance |
|
80 |
* @return true if vertices are equal, false otherwise |
|
81 |
*/ |
|
82 |
@Override |
|
83 |
public boolean equals(Object edge) { |
|
84 |
if (!(edge instanceof BaseVertex)) return false; |
|
85 |
return originalId == ((BaseVertex) edge).originalId; |
|
86 |
} |
|
87 |
} |
sources/src/cz/zcu/kiv/offscreen/api/Edge.java | ||
---|---|---|
1 |
package cz.zcu.kiv.offscreen.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 |
} |
sources/src/cz/zcu/kiv/offscreen/api/GraphExport.java | ||
---|---|---|
1 |
package cz.zcu.kiv.offscreen.api; |
|
2 |
|
|
3 |
import cz.zcu.kiv.offscreen.graph.*; |
|
4 |
|
|
5 |
import java.util.ArrayList; |
|
6 |
import java.util.List; |
|
7 |
import java.util.Map; |
|
8 |
|
|
9 |
import org.apache.log4j.Logger; |
|
10 |
|
|
11 |
/** |
|
12 |
* Class represents graph with all information about graph plus information about state in which used store graph. |
|
13 |
* Class is used for creating of JSON which is send to frontend. |
|
14 |
*/ |
|
15 |
public class GraphExport { |
|
16 |
|
|
17 |
private List<Vertex> vertices; |
|
18 |
private List<Edge> edges; |
|
19 |
private List<VertexArchetype> vertexArchetypes; |
|
20 |
private List<EdgeArchetype> edgeArchetypes; |
|
21 |
private List<AttributeType> attributeTypes; |
|
22 |
private Map<String, List<String>> possibleEnumValues; |
|
23 |
private Map<String, String> archetypeIcons; |
|
24 |
|
|
25 |
private List<Group> groups; |
|
26 |
private List<Position> positions; |
|
27 |
private List<SideBar> sideBar; |
|
28 |
private int selectedVertex; |
|
29 |
private int selectedEdge; |
|
30 |
|
|
31 |
private Logger logger = Logger.getLogger(GraphExport.class); |
|
32 |
|
|
33 |
public GraphExport(Graph graph) { |
|
34 |
logger.trace("ENTRY"); |
|
35 |
this.vertices = new ArrayList<>(graph.getVertices().values()); |
|
36 |
this.edges = new ArrayList<>(graph.getEdges()); |
|
37 |
this.vertexArchetypes = new ArrayList<>(graph.getVertexArchetypes()); |
|
38 |
this.edgeArchetypes = new ArrayList<>(graph.getEdgeArchetypes()); |
|
39 |
this.attributeTypes = new ArrayList<>(graph.getAttributeTypes()); |
|
40 |
this.possibleEnumValues = graph.getPossibleEnumValues(); |
|
41 |
this.archetypeIcons = graph.getArchetypeIcons(); |
|
42 |
this.groups = graph.getGraphState().getGroups(); |
|
43 |
this.positions = graph.getGraphState().getPositions(); |
|
44 |
this.sideBar = graph.getGraphState().getSideBar(); |
|
45 |
this.selectedVertex = graph.getGraphState().getSelectedVertex(); |
|
46 |
this.selectedEdge = graph.getGraphState().getSelectedEdge(); |
|
47 |
logger.trace("EXIT"); |
|
48 |
} |
|
49 |
|
|
50 |
public List<Edge> getEdges() { |
|
51 |
logger.trace("ENTRY"); |
|
52 |
logger.trace("EXIT"); |
|
53 |
return edges; |
|
54 |
} |
|
55 |
|
|
56 |
public List<Vertex> getVertices() { |
|
57 |
logger.trace("ENTRY"); |
|
58 |
logger.trace("EXIT"); |
|
59 |
return vertices; |
|
60 |
} |
|
61 |
|
|
62 |
public List<VertexArchetype> getVertexArchetypes() { |
|
63 |
return vertexArchetypes; |
|
64 |
} |
|
65 |
|
|
66 |
public List<EdgeArchetype> getEdgeArchetypes() { |
|
67 |
return edgeArchetypes; |
|
68 |
} |
|
69 |
|
|
70 |
public List<AttributeType> getAttributeTypes() { |
|
71 |
return attributeTypes; |
|
72 |
} |
|
73 |
|
|
74 |
public Map<String, List<String>> getPossibleEnumValues() { |
|
75 |
return possibleEnumValues; |
|
76 |
} |
|
77 |
|
|
78 |
public Map<String, String> getArchetypeIcons() { |
|
79 |
return archetypeIcons; |
|
80 |
} |
|
81 |
|
|
82 |
public List<Group> getGroups() { |
|
83 |
return groups; |
|
84 |
} |
|
85 |
|
|
86 |
public List<Position> getPositions() { |
|
87 |
return positions; |
|
88 |
} |
|
89 |
|
|
90 |
public List<SideBar> getSideBar() { |
|
91 |
return sideBar; |
|
92 |
} |
|
93 |
|
|
94 |
public int getSelectedVertex() { |
|
95 |
return selectedVertex; |
|
96 |
} |
|
97 |
|
|
98 |
public int getSelectedEdge() { |
|
99 |
return selectedEdge; |
|
100 |
} |
|
101 |
} |
sources/src/cz/zcu/kiv/offscreen/api/Group.java | ||
---|---|---|
1 |
package cz.zcu.kiv.offscreen.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 which is unique only in groups. */ |
|
12 |
private int groupId; |
|
13 |
/** Generated if of group which is unique in groups and vertexes. */ |
|
14 |
private int id; |
|
15 |
/** Name of group */ |
|
16 |
private String name; |
|
17 |
/** List of vertices id which belongs to this group */ |
|
18 |
private List<Integer> verticesId; |
|
19 |
/** List of vertices id whose outgoing edges are visible. */ |
|
20 |
private List<Integer> verticesEdgeFromId; |
|
21 |
/** List of vertices id whose incoming edges are visible. */ |
|
22 |
private List<Integer> verticesEdgeToId; |
|
23 |
|
|
24 |
public Group(int groupId, int id, String name){ |
|
25 |
this.groupId = groupId; |
|
26 |
this.id = id; |
|
27 |
this.name = name; |
|
28 |
verticesId = new ArrayList<>(); |
|
29 |
verticesEdgeFromId = new ArrayList<>(); |
|
30 |
verticesEdgeToId = new ArrayList<>(); |
|
31 |
} |
|
32 |
|
|
33 |
public Group(int groupId, int id, String name, List<Integer> verticesId, List<Integer> verticesEdgeFromId, List<Integer> verticesEdgeToId) { |
|
34 |
this.groupId = groupId; |
|
35 |
this.id = id; |
|
36 |
this.name = name; |
|
37 |
this.verticesId = verticesId; |
|
38 |
this.verticesEdgeFromId = verticesEdgeFromId; |
|
39 |
this.verticesEdgeToId = verticesEdgeToId; |
|
40 |
} |
|
41 |
|
|
42 |
public int getGroupId() { |
|
43 |
return groupId; |
|
44 |
} |
|
45 |
|
|
46 |
public void setGroupId(int groupId) { |
|
47 |
this.groupId = groupId; |
|
48 |
} |
|
49 |
|
|
50 |
public int getId() { |
|
51 |
return id; |
|
52 |
} |
|
53 |
|
|
54 |
public void setId(int id) { |
|
55 |
this.id = id; |
|
56 |
} |
|
57 |
|
|
58 |
public String getName() { |
|
59 |
return name; |
|
60 |
} |
|
61 |
|
|
62 |
public void setName(String name) { |
|
63 |
this.name = name; |
|
64 |
} |
|
65 |
|
|
66 |
public List<Integer> getVerticesId() { |
|
67 |
return verticesId; |
|
68 |
} |
|
69 |
|
|
70 |
public void setVerticesId(List<Integer> verticesId) { |
|
71 |
this.verticesId = verticesId; |
|
72 |
} |
|
73 |
|
|
74 |
public List<Integer> getVerticesEdgeFromId() { |
|
75 |
return verticesEdgeFromId; |
|
76 |
} |
|
77 |
|
|
78 |
public void setVerticesEdgeFromId(List<Integer> verticesEdgeFromId) { |
|
79 |
this.verticesEdgeFromId = verticesEdgeFromId; |
|
80 |
} |
|
81 |
|
|
82 |
public List<Integer> getVerticesEdgeToId() { |
|
83 |
return verticesEdgeToId; |
|
84 |
} |
|
85 |
|
|
86 |
public void setVerticesEdgeToId(List<Integer> verticesEdgeToId) { |
|
87 |
this.verticesEdgeToId = verticesEdgeToId; |
|
88 |
} |
|
89 |
|
|
90 |
public void addVertexId(int vertexId){ |
|
91 |
this.verticesId.add(vertexId); |
|
92 |
} |
|
93 |
|
|
94 |
public void addVetexEdgeToId(int vertexId){ |
|
95 |
this.verticesEdgeToId.add(vertexId); |
|
96 |
} |
|
97 |
|
|
98 |
public void addVetexEdgeFromId(int vertexId){ |
|
99 |
this.verticesEdgeFromId.add(vertexId); |
|
100 |
} |
|
101 |
} |
sources/src/cz/zcu/kiv/offscreen/api/Position.java | ||
---|---|---|
1 |
package cz.zcu.kiv.offscreen.api; |
|
2 |
|
|
3 |
/** |
|
4 |
* Class is used for storing information about vertex/group relative position. |
|
5 |
*/ |
|
6 |
public class Position { |
|
7 |
|
|
8 |
/** Identification number of vertex or group which was generated in application. */ |
|
9 |
private int vertexId; |
|
10 |
/** Relative X position. */ |
|
11 |
private float x; |
|
12 |
/** Relative Y position */ |
|
13 |
private float y; |
|
14 |
|
|
15 |
public Position(int vertexId, float x, float y) { |
|
16 |
this.vertexId = vertexId; |
|
17 |
this.x = x; |
|
18 |
this.y = y; |
|
19 |
} |
|
20 |
|
|
21 |
public int getVertexId() { |
|
22 |
return vertexId; |
|
23 |
} |
|
24 |
|
|
25 |
public void setVertexId(int vertexId) { |
|
26 |
this.vertexId = vertexId; |
|
27 |
} |
|
28 |
|
|
29 |
public float getX() { |
|
30 |
return x; |
|
31 |
} |
|
32 |
|
|
33 |
public void setX(float x) { |
|
34 |
this.x = x; |
|
35 |
} |
|
36 |
|
|
37 |
public float getY() { |
|
38 |
return y; |
|
39 |
} |
|
40 |
|
|
41 |
public void setY(float y) { |
|
42 |
this.y = y; |
|
43 |
} |
|
44 |
} |
sources/src/cz/zcu/kiv/offscreen/api/SideBar.java | ||
---|---|---|
1 |
package cz.zcu.kiv.offscreen.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 highlighted; |
|
12 |
|
|
13 |
public SideBar(int vertexId, boolean highlighted) { |
|
14 |
this.vertexId = vertexId; |
|
15 |
this.highlighted = highlighted; |
|
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 isHighlighted() { |
|
27 |
return highlighted; |
|
28 |
} |
|
29 |
|
|
30 |
public void setHighlighted(boolean highlighted) { |
|
31 |
this.highlighted = highlighted; |
|
32 |
} |
|
33 |
} |
sources/src/cz/zcu/kiv/offscreen/api/SubedgeInfo.java | ||
---|---|---|
1 |
package cz.zcu.kiv.offscreen.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 originalId; |
|
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 originalId 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 originalId, int archetype, List<String[]> attributes) { |
|
21 |
this.originalId = originalId; |
|
22 |
this.archetype = archetype; |
|
23 |
this.attributes = attributes; |
|
24 |
} |
|
25 |
|
|
26 |
public int getOriginalId() { |
|
27 |
return originalId; |
|
28 |
} |
|
29 |
|
|
30 |
public int getArchetype() { |
|
31 |
return archetype; |
|
32 |
} |
|
33 |
|
|
34 |
public List<String[]> getAttributes() { |
|
35 |
return attributes; |
|
36 |
} |
|
37 |
} |
sources/src/cz/zcu/kiv/offscreen/api/Vertex.java | ||
---|---|---|
1 |
package cz.zcu.kiv.offscreen.api; |
|
2 |
|
|
3 |
import java.util.List; |
|
4 |
|
|
5 |
/** |
|
6 |
* Class represents vertex which is used for output JSON format (JSON between frontend and backend) |
|
7 |
*/ |
|
8 |
public class Vertex extends BaseVertex { |
|
9 |
|
|
10 |
/** List of all tributes. Every attribute is stored in String array in pair as {attribute name, attribute value}. */ |
|
11 |
private List<String[]> attributes; |
|
12 |
|
|
13 |
/** |
|
14 |
* Create new vertex. |
|
15 |
* @param id new generated identification number. |
|
16 |
* @param originalId original identification number from input file |
|
17 |
* @param title title of vertex |
|
18 |
* @param archetypeIndex index of vertex archetype |
|
19 |
* @param text additional info |
|
20 |
* @param attributes List of all attributes. Every attribute is stored in String array in pair as {attribute name, attribute value}. |
|
21 |
*/ |
|
22 |
public Vertex(int id, int originalId, String title, int archetypeIndex, String text, List<String[]> attributes) { |
|
23 |
super(id, originalId, title, archetypeIndex, text); |
|
24 |
this.attributes = attributes; |
|
25 |
} |
|
26 |
|
|
27 |
public List<String[]> getAttributes() { |
|
28 |
return attributes; |
|
29 |
} |
|
30 |
|
|
31 |
public void setAttributes(List<String[]> attributes) { |
|
32 |
this.attributes = attributes; |
|
33 |
} |
|
34 |
} |
sources/src/cz/zcu/kiv/offscreen/data/efpportal/CocaexData.java | ||
---|---|---|
1 |
///** |
|
2 |
// * |
|
3 |
// */ |
|
4 |
//package cz.zcu.kiv.offscreen.data.efpportal; |
|
5 |
// |
|
6 |
//import java.util.HashMap; |
|
7 |
//import java.util.Map; |
|
8 |
// |
|
9 |
///** |
|
10 |
// * |
|
11 |
// * Representation of EFPPortal's connections . A connection consists of a provided and required features. |
|
12 |
// * |
|
13 |
// * @author Jiri Loudil |
|
14 |
// * |
|
15 |
// */ |
|
16 |
//public class CocaexData { |
|
17 |
// /** |
|
18 |
// * Map of all provided features. |
|
19 |
// */ |
|
20 |
// private Map<String, CocaexDataFeature> providedFeatures; |
|
21 |
// |
|
22 |
// /** |
|
23 |
// * Map of all required features. |
|
24 |
// */ |
|
25 |
// private Map<String, CocaexDataFeature> requiredFeatures; |
|
26 |
// |
|
27 |
// public CocaexData() { |
|
28 |
// this.providedFeatures = new HashMap<String, CocaexDataFeature>(); |
|
29 |
// this.requiredFeatures = new HashMap<String, CocaexDataFeature>(); |
|
30 |
// } |
|
31 |
// |
|
32 |
// /** |
|
33 |
// * @return the providedFeatures |
|
34 |
// */ |
|
35 |
// public Map<String, CocaexDataFeature> getProvidedFeatures() { |
|
36 |
// return providedFeatures; |
|
37 |
// } |
|
38 |
// |
|
39 |
// /** |
|
40 |
// * @return the importedFeatures |
|
41 |
// */ |
|
42 |
// public Map<String, CocaexDataFeature> getRequiredFeatures() { |
|
43 |
// return requiredFeatures; |
|
44 |
// } |
|
45 |
// |
|
46 |
//} |
sources/src/cz/zcu/kiv/offscreen/data/efpportal/CocaexDataEfp.java | ||
---|---|---|
1 |
//package cz.zcu.kiv.offscreen.data.efpportal; |
|
2 |
// |
|
3 |
//import cz.zcu.kiv.efps.comparator.result.EfpEvalResult.MatchingResult; |
|
4 |
//import cz.zcu.kiv.efps.types.datatypes.EfpValueType; |
|
5 |
// |
|
6 |
///** |
|
7 |
// * Holds EFP's data. |
|
8 |
// * |
|
9 |
// * @author Jiri Loudil |
|
10 |
// * |
|
11 |
// */ |
|
12 |
//public class CocaexDataEfp { |
|
13 |
// private String efpName; |
|
14 |
// private String efpValueTypeName; |
|
15 |
// private EfpValueType efpValue; |
|
16 |
// private MatchingResult typeError; |
|
17 |
// |
|
18 |
// /** |
|
19 |
// * @return the efpName |
|
20 |
// */ |
|
21 |
// public String getEfpName() { |
|
22 |
// return efpName; |
|
23 |
// } |
|
24 |
// /** |
|
25 |
// * @param efpName the efpName to set |
|
26 |
// */ |
|
27 |
// public void setEfpName(String efpName) { |
|
28 |
// this.efpName = efpName; |
|
29 |
// } |
|
30 |
// /** |
|
31 |
// * @return the efpValueTypeName |
|
32 |
// */ |
|
33 |
// public String getEfpValueTypeName() { |
|
34 |
// return efpValueTypeName; |
|
35 |
// } |
|
36 |
// /** |
|
37 |
// * @param efpValueTypeName the efpValueTypeName to set |
|
38 |
// */ |
|
39 |
// public void setEfpValueTypeName(String efpValueTypeName) { |
|
40 |
// this.efpValueTypeName = efpValueTypeName; |
|
41 |
// } |
|
42 |
// /** |
|
43 |
// * @return the efpValue |
|
44 |
// */ |
|
45 |
// public EfpValueType getEfpValue() { |
|
46 |
// return efpValue; |
|
47 |
// } |
|
48 |
// /** |
|
49 |
// * @param efpValue the efpValue to set |
|
50 |
// */ |
|
51 |
// public void setEfpValue(EfpValueType efpValue) { |
|
52 |
// this.efpValue = efpValue; |
|
53 |
// } |
|
54 |
// |
|
55 |
// /** |
|
56 |
// * @return the typeError |
|
57 |
// */ |
|
58 |
// public MatchingResult getTypeError() { |
|
59 |
// return typeError; |
|
60 |
// } |
|
61 |
// |
|
62 |
// /** |
|
63 |
// * @param typeError the typeError to set |
|
64 |
// */ |
|
65 |
// public void setTypeError(MatchingResult typeError) { |
|
66 |
// this.typeError = typeError; |
|
67 |
// } |
|
68 |
// |
|
69 |
//} |
sources/src/cz/zcu/kiv/offscreen/data/efpportal/CocaexDataFeature.java | ||
---|---|---|
1 |
//package cz.zcu.kiv.offscreen.data.efpportal; |
|
2 |
// |
|
3 |
//import java.util.ArrayList; |
|
4 |
//import java.util.List; |
|
5 |
// |
|
6 |
///** |
|
7 |
// * Holds feature's data. |
|
8 |
// * |
|
9 |
// * @author Jiri Loudil |
|
10 |
// * |
|
11 |
// */ |
|
12 |
//public class CocaexDataFeature { |
|
13 |
// private List<CocaexDataEfp> efps; |
|
14 |
// |
|
15 |
// public CocaexDataFeature() { |
|
16 |
// this.efps = new ArrayList<CocaexDataEfp>(); |
|
17 |
// } |
|
18 |
// |
|
19 |
// /** |
|
20 |
// * @return the efps |
|
21 |
// */ |
|
22 |
// public List<CocaexDataEfp> getEfps() { |
|
23 |
// return efps; |
|
24 |
// } |
|
25 |
// |
|
26 |
// /** |
|
27 |
// * @param efps the efps to set |
|
28 |
// */ |
|
29 |
// public void setEfps(List<CocaexDataEfp> efps) { |
|
30 |
// this.efps = efps; |
|
31 |
// } |
|
32 |
// |
|
33 |
//} |
sources/src/cz/zcu/kiv/offscreen/data/efpportal/CocaexWrapper.java | ||
---|---|---|
1 |
//package cz.zcu.kiv.offscreen.data.efpportal; |
|
2 |
// |
|
3 |
//import java.util.Map; |
|
4 |
// |
|
5 |
///** |
|
6 |
// * |
|
7 |
// * EFPPortal export data wrapper. Contains mappings for feature connection names and EFPs names. |
|
8 |
// * |
|
9 |
// * @author Jiri Loudil |
|
10 |
// * |
|
11 |
// */ |
|
12 |
//public class CocaexWrapper { |
|
13 |
// /** |
|
14 |
// * Feature names mapping. |
|
15 |
// */ |
|
16 |
// private Map<String, String> featureMappings; |
|
17 |
// |
|
18 |
// /** |
|
19 |
// * EFPs name s mapping. |
|
20 |
// */ |
|
21 |
// private Map<String, String> efpMappings; |
|
22 |
// |
|
23 |
// /** |
|
24 |
// * EFPPortal data with IDs instead of names for EFPs and Features. |
|
25 |
// */ |
|
26 |
// private Map<String, CocaexData> data; |
|
27 |
// |
|
28 |
// /** |
|
29 |
// * @return the featureMappings |
|
30 |
// */ |
|
31 |
// public Map<String, String> getFeatureMappings() { |
|
32 |
// return featureMappings; |
|
33 |
// } |
|
34 |
// /** |
|
35 |
// * @param featureMappings the featureMappings to set |
|
36 |
// */ |
|
37 |
// public void setFeatureMappings(Map<String, String> featureMappings) { |
|
38 |
// this.featureMappings = featureMappings; |
|
39 |
// } |
|
40 |
// /** |
|
41 |
// * @return the efpMappings |
|
42 |
// */ |
|
43 |
// public Map<String, String> getEfpMappings() { |
|
44 |
// return efpMappings; |
|
45 |
// } |
|
46 |
// /** |
|
47 |
// * @param efpMappings the efpMappings to set |
|
48 |
// */ |
|
49 |
// public void setEfpMappings(Map<String, String> efpMappings) { |
|
50 |
// this.efpMappings = efpMappings; |
|
51 |
// } |
|
52 |
// /** |
|
53 |
// * @return the data |
|
54 |
// */ |
|
55 |
// public Map<String, CocaexData> getData() { |
|
56 |
// return data; |
|
57 |
// } |
|
58 |
// /** |
|
59 |
// * @param data the data to set |
|
60 |
// */ |
|
61 |
// public void setData(Map<String, CocaexData> data) { |
|
62 |
// this.data = data; |
|
63 |
// } |
|
64 |
// |
|
65 |
// |
|
66 |
//} |
sources/src/cz/zcu/kiv/offscreen/efp/utils/JsonTransformer.java | ||
---|---|---|
1 |
//package cz.zcu.kiv.offscreen.efp.utils; |
|
2 |
// |
|
3 |
//import java.io.ByteArrayInputStream; |
|
4 |
//import java.io.IOException; |
|
5 |
//import java.util.zip.GZIPInputStream; |
|
6 |
// |
|
7 |
//import javax.servlet.http.HttpServletRequest; |
|
8 |
// |
|
9 |
//import org.apache.log4j.Logger; |
|
10 |
// |
|
11 |
//import net.sf.json.JSONObject; |
|
12 |
// |
|
13 |
//import org.apache.commons.codec.binary.Base64; |
|
14 |
//import org.apache.commons.io.IOUtils; |
|
15 |
// |
|
16 |
//import com.google.gson.Gson; |
|
17 |
//import com.google.gson.GsonBuilder; |
|
18 |
// |
|
19 |
//import cz.zcu.kiv.efps.types.datatypes.EfpValueType; |
|
20 |
//import cz.zcu.kiv.efps.types.serialisation.json.EfpValueTypeAdapter; |
|
21 |
//import cz.zcu.kiv.offscreen.api.GraphInterface; |
|
22 |
//import cz.zcu.kiv.offscreen.data.efpportal.CocaexWrapper; |
|
23 |
//import cz.zcu.kiv.offscreen.graph.GraphExport; |
|
24 |
//import cz.zcu.kiv.offscreen.graph.creator.EfpGraphTransfomer; |
|
25 |
// |
|
26 |
///** |
|
27 |
// * |
|
28 |
// * Transofma and decompress tools for incoming JSON. |
|
29 |
// * |
|
30 |
// * @author Jiri Loudil |
|
31 |
// * |
|
32 |
// */ |
|
33 |
//public class JsonTransformer { |
|
34 |
// private Logger logger = Logger.getLogger(JsonTransformer.class); |
|
35 |
// |
|
36 |
// /** |
|
37 |
// * |
|
38 |
// * Deserialize input JSON and transform to graph JSON. |
|
39 |
// * |
|
40 |
// * @param inputJSON |
|
41 |
// * @param request |
|
42 |
// * @return |
|
43 |
// * @throws IOException |
|
44 |
// */ |
|
45 |
// public String transformInputJSONToGraphJSON(String inputJSON, |
|
46 |
// HttpServletRequest request) throws IOException { |
|
47 |
// CocaexWrapper efpResults; |
|
48 |
// |
|
49 |
// GsonBuilder gsonBuilder = new GsonBuilder(); |
|
50 |
// // JSON deserializing adapter provided for EFP type classes |
|
51 |
// gsonBuilder.registerTypeAdapter(EfpValueType.class, |
|
52 |
// new EfpValueTypeAdapter()); |
|
53 |
// // JSON deserializing adapter for the Wrapper class |
|
54 |
// gsonBuilder.registerTypeAdapter(CocaexWrapper.class, |
|
55 |
// new WrapperDeserializer()); |
|
56 |
// Gson gson = gsonBuilder.create(); |
|
57 |
// |
|
58 |
// // decode + unzip received data |
|
59 |
// String data = decompress(inputJSON); |
|
60 |
// |
|
61 |
// // deserialize using deserializer adapters |
|
62 |
// efpResults = gson.fromJson(data, CocaexWrapper.class); |
|
63 |
// |
|
64 |
// request.setAttribute("efpPortalEfpNames", efpResults.getEfpMappings()); |
|
65 |
// |
|
66 |
// // transform received data to readable graph form |
|
67 |
// EfpGraphTransfomer transformer = new EfpGraphTransfomer(efpResults); |
|
68 |
// GraphInterface graph = transformer.transform(); |
|
69 |
// GraphExport export = new GraphExport(graph); |
|
70 |
// |
|
71 |
// // transform graph to JSON |
|
72 |
// JSONObject o = JSONObject.fromObject(export); |
|
73 |
// |
|
74 |
// return o.toString(); |
|
75 |
// } |
|
76 |
// |
|
77 |
// /** |
|
78 |
// * Decode and unzip a Base64 encoded GZIPed string. |
|
79 |
// * |
|
80 |
// * @param input |
|
81 |
// * @return |
|
82 |
// * @throws IOException |
|
83 |
// */ |
|
84 |
// private String decompress(String input) throws IOException { |
|
85 |
// logger.trace("ENTRY"); |
|
86 |
// String result = null; |
|
87 |
// |
|
88 |
// byte[] bytes = Base64.decodeBase64(input); |
|
89 |
// GZIPInputStream zi = null; |
|
90 |
// try { |
|
91 |
// zi = new GZIPInputStream(new ByteArrayInputStream(bytes)); |
|
92 |
// result = IOUtils.toString(zi); |
|
93 |
// } finally { |
|
94 |
// IOUtils.closeQuietly(zi); |
|
95 |
// } |
|
96 |
// logger.trace("EXIT"); |
|
97 |
// |
|
98 |
// return result; |
|
99 |
// } |
|
100 |
// |
|
101 |
//} |
sources/src/cz/zcu/kiv/offscreen/efp/utils/WrapperDeserializer.java | ||
---|---|---|
1 |
//package cz.zcu.kiv.offscreen.efp.utils; |
|
2 |
// |
|
3 |
//import java.lang.reflect.Type; |
|
4 |
//import java.util.HashMap; |
|
5 |
//import java.util.Map; |
|
6 |
// |
|
7 |
//import org.apache.log4j.Logger; |
|
8 |
// |
|
9 |
//import com.google.gson.Gson; |
|
10 |
//import com.google.gson.GsonBuilder; |
|
11 |
//import com.google.gson.JsonDeserializationContext; |
|
12 |
//import com.google.gson.JsonDeserializer; |
|
13 |
//import com.google.gson.JsonElement; |
|
14 |
//import com.google.gson.JsonObject; |
|
15 |
// |
|
16 |
//import cz.zcu.kiv.efps.types.datatypes.EfpValueType; |
|
17 |
//import cz.zcu.kiv.efps.types.serialisation.json.EfpValueTypeAdapter; |
|
18 |
//import cz.zcu.kiv.offscreen.data.efpportal.CocaexData; |
|
19 |
//import cz.zcu.kiv.offscreen.data.efpportal.CocaexWrapper; |
|
20 |
// |
|
21 |
///** |
|
22 |
// * |
|
23 |
// * CocaexWrapper class deserializer. |
|
24 |
// * |
|
25 |
// * @author Jiri Loudil |
|
26 |
// * |
|
27 |
// */ |
|
28 |
//public class WrapperDeserializer implements JsonDeserializer<CocaexWrapper> { |
|
29 |
// private Logger logger = Logger.getLogger(WrapperDeserializer.class); |
|
30 |
// |
|
31 |
// @Override |
|
32 |
// public CocaexWrapper deserialize(JsonElement json, Type typeOfT, |
|
33 |
// JsonDeserializationContext context) { |
|
34 |
// logger.trace("ENTRY"); |
|
35 |
// |
|
36 |
// GsonBuilder gsonBuilder = new GsonBuilder(); |
|
37 |
// // JSON deserializing adapter provided for EFP type classes |
|
38 |
// gsonBuilder.registerTypeAdapter(EfpValueType.class, |
|
39 |
// new EfpValueTypeAdapter()); |
|
40 |
// Gson gson = gsonBuilder.create(); |
|
41 |
// |
|
42 |
// CocaexWrapper wrapper = gson.fromJson(json, CocaexWrapper.class); |
|
43 |
// JsonObject jo = json.getAsJsonObject(); |
|
44 |
// |
|
45 |
// Map<String, String> featureMappings = new HashMap<String, String>(); |
|
46 |
// Map<String, String> efpMappings = new HashMap<String, String>(); |
|
47 |
// Map<String, CocaexData> data = new HashMap<String, CocaexData>(); |
|
48 |
// |
|
49 |
// // parse feature mappings |
|
50 |
// JsonObject featuresObject = jo.getAsJsonObject("featureMappings"); |
|
51 |
// for (Map.Entry<String, JsonElement> entry : featuresObject.entrySet()) { |
|
52 |
// featureMappings.put(entry.getKey(), entry.getValue().getAsString()); |
|
53 |
// } |
|
54 |
// |
|
55 |
// // parse efps mappings |
|
56 |
// JsonObject efpsObject = jo.getAsJsonObject("efpMappings"); |
|
57 |
// for (Map.Entry<String, JsonElement> entry : efpsObject.entrySet()) { |
|
58 |
// efpMappings.put(entry.getKey(), entry.getValue().getAsString()); |
|
59 |
// } |
|
60 |
// |
|
61 |
// // parse data |
|
62 |
// JsonObject dataObject = jo.getAsJsonObject("data"); |
|
63 |
// for (Map.Entry<String, JsonElement> entry : dataObject.entrySet()) { |
|
64 |
// data.put(entry.getKey(), (CocaexData) context.deserialize( |
|
65 |
// entry.getValue(), CocaexData.class)); |
|
66 |
// } |
|
67 |
// |
|
68 |
// // fill output structure |
|
69 |
// wrapper.setFeatureMappings(featureMappings); |
|
70 |
// wrapper.setEfpMappings(efpMappings); |
|
71 |
// wrapper.setData(data); |
|
72 |
// logger.trace("EXIT"); |
|
73 |
// |
|
74 |
// return wrapper; |
|
75 |
// } |
|
76 |
//} |
sources/src/cz/zcu/kiv/offscreen/graph/Attribute.java | ||
---|---|---|
1 |
package cz.zcu.kiv.offscreen.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 |
} |
sources/src/cz/zcu/kiv/offscreen/graph/AttributeType.java | ||
---|---|---|
1 |
package cz.zcu.kiv.offscreen.graph; |
|
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 GraphManager.AttributeDataType dataType; |
|
12 |
/** additional info */ |
|
13 |
public String text; |
|
14 |
|
|
15 |
public AttributeType(String name, GraphManager.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 GraphManager.AttributeDataType getDataType() { |
|
26 |
return dataType; |
|
27 |
} |
|
28 |
|
|
29 |
public String getText() { |
|
30 |
return text; |
|
31 |
} |
|
32 |
} |
sources/src/cz/zcu/kiv/offscreen/graph/EdgeArchetype.java | ||
---|---|---|
1 |
package cz.zcu.kiv.offscreen.graph; |
|
2 |
|
|
3 |
public class EdgeArchetype { |
|
4 |
public String name; |
|
5 |
public String text; |
|
6 |
|
|
7 |
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 |
} |
sources/src/cz/zcu/kiv/offscreen/graph/EdgeArchetypeInfo.java | ||
---|---|---|
1 |
package cz.zcu.kiv.offscreen.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 |
EdgeArchetypeInfo info = (EdgeArchetypeInfo)obj; |
|
33 |
return (info.fromArchetypeIndex == fromArchetypeIndex) && (info.edgeArchetypeIndex == edgeArchetypeIndex) && (info.toArchetypeIndex == toArchetypeIndex); |
|
34 |
} |
|
35 |
} |
sources/src/cz/zcu/kiv/offscreen/graph/EdgeImpl.java | ||
---|---|---|
1 |
package cz.zcu.kiv.offscreen.graph; |
|
2 |
|
|
3 |
import cz.zcu.kiv.offscreen.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 |
} |
sources/src/cz/zcu/kiv/offscreen/graph/Graph.java | ||
---|---|---|
1 |
package cz.zcu.kiv.offscreen.graph; |
|
2 |
|
|
3 |
import cz.zcu.kiv.offscreen.api.Edge; |
|
4 |
import cz.zcu.kiv.offscreen.api.Vertex; |
|
5 |
import org.apache.log4j.Logger; |
|
6 |
|
|
7 |
import java.util.HashMap; |
|
8 |
import java.util.LinkedList; |
|
9 |
import java.util.List; |
|
10 |
import java.util.Map; |
|
11 |
|
|
12 |
/** |
|
13 |
* Class represents graph which is loaded from input JSON file. |
|
14 |
*/ |
|
15 |
public class Graph { |
|
16 |
|
|
17 |
private Map<String, Vertex> vertices; |
|
18 |
private List<Edge> edges; |
|
19 |
private List<VertexArchetype> vertexArchetypes; |
|
20 |
private List<EdgeArchetype> edgeArchetypes; |
|
21 |
private List<AttributeType> attributeTypes; |
|
22 |
private Map<String, List<String>> possibleEnumValues; |
|
23 |
private List<String> defaultGroupArchetypes; |
|
24 |
private Map<String, String> archetypeIcons; |
|
25 |
|
|
26 |
private GraphState graphState; |
|
27 |
|
|
28 |
private Logger logger = Logger.getLogger(Graph.class); |
|
29 |
|
|
30 |
public Graph() { |
|
31 |
logger.trace("ENTRY"); |
|
32 |
this.vertices = new HashMap<String, Vertex>(); |
|
33 |
this.edges = new LinkedList<Edge>(); |
|
34 |
logger.trace("EXIT"); |
|
35 |
} |
|
36 |
|
|
37 |
public List<Edge> getEdges() { |
|
38 |
logger.trace("ENTRY"); |
|
39 |
logger.trace("EXIT"); |
|
40 |
return edges; |
|
41 |
} |
|
42 |
|
|
43 |
public List<VertexArchetype> getVertexArchetypes() { |
|
44 |
return vertexArchetypes; |
|
45 |
} |
|
46 |
|
|
47 |
public List<EdgeArchetype> getEdgeArchetypes() { |
|
48 |
return edgeArchetypes; |
|
49 |
} |
|
50 |
|
|
51 |
public void setVertexArchetypes(List<VertexArchetype> vertexArchetypes) { |
|
52 |
this.vertexArchetypes = vertexArchetypes; |
|
53 |
} |
|
54 |
|
|
55 |
public void setEdgeArchetypes(List<EdgeArchetype> edgeArchetypes) { |
|
56 |
this.edgeArchetypes = edgeArchetypes; |
|
57 |
} |
|
58 |
|
|
59 |
public void setAttributeTypes(List<AttributeType> attributeTypes) { |
|
60 |
this.attributeTypes = attributeTypes; |
|
61 |
} |
|
62 |
|
|
63 |
public void setPossibleEnumValues(Map<Integer, List<String>> possibleEnumValues) { |
|
64 |
this.possibleEnumValues = new HashMap<>(); |
|
65 |
for (Integer index : possibleEnumValues.keySet()) { |
|
66 |
this.possibleEnumValues.put("" + index, possibleEnumValues.get(index)); |
|
67 |
} |
|
68 |
} |
|
69 |
|
|
70 |
public void setArchetypeIcons(Map<String, String> archetypeIcons) { |
|
71 |
this.archetypeIcons = archetypeIcons; |
|
72 |
} |
|
73 |
|
|
74 |
public List<String> getDefaultGroupArchetypes() { |
|
75 |
return defaultGroupArchetypes; |
|
76 |
} |
|
77 |
|
|
78 |
public void setDefaultGroupArchetypes(List<String> defaultGroupArchetypes) { |
|
79 |
this.defaultGroupArchetypes = defaultGroupArchetypes; |
|
80 |
} |
|
81 |
|
|
82 |
public List<AttributeType> getAttributeTypes() { |
|
83 |
return attributeTypes; |
|
84 |
} |
|
85 |
|
|
86 |
public Map<String, List<String>> getPossibleEnumValues() { |
|
87 |
return possibleEnumValues; |
|
88 |
} |
|
89 |
|
|
90 |
public Map<String, String> getArchetypeIcons() { |
|
91 |
return archetypeIcons; |
|
92 |
} |
|
93 |
|
|
94 |
public Map<String, Vertex> getVertices() { |
|
95 |
logger.trace("ENTRY"); |
|
96 |
logger.trace("EXIT"); |
|
97 |
return vertices; |
|
98 |
} |
|
99 |
|
|
100 |
public void addEdge(Edge edge) { |
|
101 |
logger.trace("ENTRY"); |
|
102 |
this.edges.add(edge); |
|
103 |
logger.trace("EXIT"); |
|
104 |
} |
|
105 |
|
|
106 |
public void addVertex(String name, Vertex vertex) { |
|
107 |
logger.trace("ENTRY"); |
|
108 |
this.vertices.put(name, vertex); |
|
109 |
logger.trace("EXIT"); |
|
110 |
} |
|
111 |
|
|
112 |
public GraphState getGraphState() { |
|
113 |
return graphState; |
|
114 |
} |
|
115 |
|
|
116 |
public void setGraphState(GraphState graphState) { |
|
117 |
this.graphState = graphState; |
|
118 |
} |
|
119 |
} |
sources/src/cz/zcu/kiv/offscreen/graph/GraphManager.java | ||
---|---|---|
1 |
package cz.zcu.kiv.offscreen.graph; |
|
2 |
|
|
3 |
import cz.zcu.kiv.offscreen.api.Edge; |
|
4 |
import cz.zcu.kiv.offscreen.api.Group; |
|
5 |
import cz.zcu.kiv.offscreen.api.SubedgeInfo; |
|
6 |
import cz.zcu.kiv.offscreen.api.Vertex; |
|
7 |
import cz.zcu.kiv.offscreen.graph.filter.*; |
|
8 |
import cz.zcu.kiv.offscreen.graph.loader.JSONConfigLoader; |
|
9 |
|
|
10 |
import java.util.*; |
|
11 |
|
|
12 |
public class GraphManager { |
|
13 |
|
|
14 |
public enum AttributeDataType { |
|
15 |
NUMBER { |
|
16 |
@Override |
|
17 |
public String toString() { |
|
18 |
return "number"; |
|
19 |
} |
|
20 |
}, |
|
21 |
DATE { |
|
22 |
@Override |
|
23 |
public String toString() { |
|
24 |
return "date"; |
|
25 |
} |
|
26 |
}, |
|
27 |
ENUM { |
|
28 |
@Override |
|
29 |
public String toString() { |
|
30 |
return "enum"; |
|
31 |
} |
|
32 |
}, |
|
33 |
STRING { |
|
34 |
@Override |
|
35 |
public String toString() { |
|
36 |
return "string"; |
|
37 |
} |
|
38 |
} |
|
39 |
} |
|
40 |
|
|
41 |
private int lastVertexOrGroupId = 1; |
|
42 |
|
|
43 |
public List<VertexArchetype> vertexArchetypes = new ArrayList<>(); |
|
44 |
public List<EdgeArchetype> edgeArchetypes = new ArrayList<>(); |
|
45 |
public List<AttributeType> attributeTypes = new ArrayList<>(); |
|
46 |
|
|
47 |
/** |
|
48 |
* the key is the attributeType index, the value is the list of possible values |
|
49 |
*/ |
|
50 |
private Map<Integer, List<String>> possibleEnumValues = new HashMap<>(); |
|
51 |
|
|
52 |
/** |
|
53 |
* key is the archetype index, value is the set of vertices of the given archetype |
|
54 |
*/ |
|
55 |
public Map<Integer, HashSet<VertexImpl>> vertices = new HashMap<>(); |
|
56 |
|
|
57 |
/** |
|
58 |
* key is the triplet of archetypes {fromVertex, edge, toVertex}, value is the list of edges for the given archetype triplet |
|
59 |
*/ |
|
60 |
public Map<EdgeArchetypeInfo, List<EdgeImpl>> edges = new HashMap<>(); |
|
61 |
|
|
62 |
public void addVertexArchetype(String name, String text) { |
|
63 |
vertexArchetypes.add(new VertexArchetype(name, text)); |
|
64 |
} |
|
65 |
|
|
66 |
public void addEdgeArchetype(String name, String text) { |
|
67 |
edgeArchetypes.add(new EdgeArchetype(name, text)); |
|
68 |
} |
|
69 |
|
|
70 |
|
|
71 |
public void addAttributeType(String name, AttributeDataType dataType, String text) { |
|
72 |
attributeTypes.add(new AttributeType(name, dataType, text)); |
|
73 |
} |
|
74 |
|
|
75 |
/** |
|
76 |
* Adds a list of values to the possible values hashmap. All duplicated are |
|
77 |
* removed. |
|
78 |
* |
|
79 |
* @param attributeTypeId - Id of attribute type |
|
80 |
* @param values - List of values of the corresponding attribute type |
|
81 |
*/ |
|
82 |
public void addUniquePossibleAttributeValues(int attributeTypeId, List<String> values) { |
|
83 |
if (possibleEnumValues.containsKey(attributeTypeId)) { |
|
84 |
List<String> attrValues = possibleEnumValues.get(attributeTypeId); |
|
85 |
List<String> valuesWithoutDuplicates = new ArrayList<>(new HashSet<>(values)); // Converting to hashset removes duplicates |
|
86 |
valuesWithoutDuplicates.removeAll(attrValues); // Values to add without values already present in the hashmap |
|
87 |
attrValues.addAll(valuesWithoutDuplicates); |
|
88 |
} else { |
|
89 |
possibleEnumValues.put(attributeTypeId, values); |
|
90 |
} |
|
91 |
} |
|
92 |
|
|
93 |
public List<Integer> getEnumPositionsForAttrIndex(int attributeTypeId, List<String> enumValues) { |
|
94 |
List<Integer> positions = new ArrayList<>(); |
|
95 |
if (!possibleEnumValues.containsKey(attributeTypeId)) { |
|
96 |
return positions; |
Také k dispozici: Unified diff
moved backend code to directories following Maven convention