commit 90426a446198f8928e034515fe5810284462d6f0
Author: Tomáš Šimandl <tomas.simandl@gmail.com>
Date:   Thu Sep 20 14:09:08 2018 +0200

    Simplify transformation between JSONs by removing graph.Graph class and use instead api.Graph

diff --git a/sources/src/main/java/cz/zcu/kiv/offscreen/api/Graph.java b/sources/src/main/java/cz/zcu/kiv/offscreen/api/Graph.java
index c5ee149..ee75bbd 100644
--- a/sources/src/main/java/cz/zcu/kiv/offscreen/api/Graph.java
+++ b/sources/src/main/java/cz/zcu/kiv/offscreen/api/Graph.java
@@ -1,8 +1,6 @@
 package cz.zcu.kiv.offscreen.api;
 
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
+import java.util.*;
 
 import org.apache.log4j.Logger;
 
@@ -26,19 +24,9 @@ public class Graph {
 
     private Logger logger = Logger.getLogger(Graph.class);
 
-    public Graph(cz.zcu.kiv.offscreen.graph.Graph graph) {
-        logger.trace("ENTRY");
-        this.vertices = graph.getVertices();
-        this.edges = graph.getEdges();
-        this.vertexArchetypes = graph.getVertexArchetypes();
-        this.edgeArchetypes = graph.getEdgeArchetypes();
-        this.attributeTypes = graph.getAttributeTypes();
-        this.possibleEnumValues = graph.getPossibleEnumValues();
-        this.groups = graph.getGraphState().getGroups();
-        this.sideBar = graph.getGraphState().getSideBar();
-        this.highlightedVertex = graph.getGraphState().getHighlightedVertex();
-        this.highlightedEdge = graph.getGraphState().getHighlightedEdge();
-        logger.trace("EXIT");
+    public Graph() {
+        vertices = new HashSet<>();
+        edges = new LinkedList<>();
     }
 
     public List<Edge> getEdges() {
@@ -84,4 +72,39 @@ public class Graph {
     public String getHighlightedEdge() {
         return highlightedEdge;
     }
+
+    public void setVertexArchetypes(List<VertexArchetype> vertexArchetypes) {
+        this.vertexArchetypes = vertexArchetypes;
+    }
+
+    public void setEdgeArchetypes(List<EdgeArchetype> edgeArchetypes) {
+        this.edgeArchetypes = edgeArchetypes;
+    }
+
+    public void setAttributeTypes(List<AttributeType> attributeTypes) {
+        this.attributeTypes = attributeTypes;
+    }
+
+    public void setPossibleEnumValues(Map<Integer, List<String>> possibleEnumValues) {
+        this.possibleEnumValues = new HashMap<>();
+        for (Integer index : possibleEnumValues.keySet()) {
+            this.possibleEnumValues.put("" + index, possibleEnumValues.get(index));
+        }
+    }
+
+    public void setGroups(List<Group> groups) {
+        this.groups = groups;
+    }
+
+    public void setSideBar(List<SideBar> sideBar) {
+        this.sideBar = sideBar;
+    }
+
+    public void setHighlightedVertex(String highlightedVertex) {
+        this.highlightedVertex = highlightedVertex;
+    }
+
+    public void setHighlightedEdge(String highlightedEdge) {
+        this.highlightedEdge = highlightedEdge;
+    }
 }
diff --git a/sources/src/main/java/cz/zcu/kiv/offscreen/graph/Graph.java b/sources/src/main/java/cz/zcu/kiv/offscreen/graph/Graph.java
deleted file mode 100644
index f5aef98..0000000
--- a/sources/src/main/java/cz/zcu/kiv/offscreen/graph/Graph.java
+++ /dev/null
@@ -1,106 +0,0 @@
-package cz.zcu.kiv.offscreen.graph;
-
-import cz.zcu.kiv.offscreen.api.*;
-import org.apache.log4j.Logger;
-
-import java.util.*;
-
-/**
- * Class represents graph which is loaded from input JSON file.
- */
-public class Graph {
-
-    private Set<Vertex> vertices;
-    private List<Edge> edges;
-    private List<VertexArchetype> vertexArchetypes;
-    private List<EdgeArchetype> edgeArchetypes;
-    private List<AttributeType> attributeTypes;
-    private Map<String, List<String>> possibleEnumValues;
-    private List<String> defaultGroupArchetypes;
-
-    private GraphState graphState;
-
-    private Logger logger = Logger.getLogger(Graph.class);
-
-    public Graph() {
-        logger.trace("ENTRY");
-        this.vertices = new HashSet<>();
-        this.edges = new LinkedList<>();
-        logger.trace("EXIT");
-    }
-
-    public List<Edge> getEdges() {
-        logger.trace("ENTRY");
-        logger.trace("EXIT");
-        return edges;
-    }
-
-    public List<VertexArchetype> getVertexArchetypes() {
-        return vertexArchetypes;
-    }
-
-    public List<EdgeArchetype> getEdgeArchetypes() {
-        return edgeArchetypes;
-    }
-
-    public void setVertexArchetypes(List<VertexArchetype> vertexArchetypes) {
-        this.vertexArchetypes = vertexArchetypes;
-    }
-
-    public  void setEdgeArchetypes(List<EdgeArchetype> edgeArchetypes) {
-        this.edgeArchetypes = edgeArchetypes;
-    }
-
-    public void setAttributeTypes(List<AttributeType> attributeTypes) {
-        this.attributeTypes = attributeTypes;
-    }
-
-    public void setPossibleEnumValues(Map<Integer, List<String>> possibleEnumValues) {
-        this.possibleEnumValues = new HashMap<>();
-        for (Integer index : possibleEnumValues.keySet()) {
-            this.possibleEnumValues.put("" + index, possibleEnumValues.get(index));
-        }
-    }
-
-    public List<String> getDefaultGroupArchetypes() {
-        return defaultGroupArchetypes;
-    }
-
-    public void setDefaultGroupArchetypes(List<String> defaultGroupArchetypes) {
-        this.defaultGroupArchetypes = defaultGroupArchetypes;
-    }
-
-    public List<AttributeType> getAttributeTypes() {
-        return attributeTypes;
-    }
-
-    public Map<String, List<String>> getPossibleEnumValues() {
-        return possibleEnumValues;
-    }
-
-    public Set<Vertex> getVertices() {
-        logger.trace("ENTRY");
-        logger.trace("EXIT");
-        return vertices;
-    }
-
-    public void addEdge(Edge edge) {
-        logger.trace("ENTRY");
-        this.edges.add(edge);
-        logger.trace("EXIT");
-    }
-
-    public void addVertex(Vertex vertex) {
-        logger.trace("ENTRY");
-        this.vertices.add(vertex);
-        logger.trace("EXIT");
-    }
-
-    public GraphState getGraphState() {
-        return graphState;
-    }
-
-    public void setGraphState(GraphState graphState) {
-        this.graphState = graphState;
-    }
-}
diff --git a/sources/src/main/java/cz/zcu/kiv/offscreen/graph/GraphManager.java b/sources/src/main/java/cz/zcu/kiv/offscreen/graph/GraphManager.java
index 49ae707..d16b88f 100644
--- a/sources/src/main/java/cz/zcu/kiv/offscreen/graph/GraphManager.java
+++ b/sources/src/main/java/cz/zcu/kiv/offscreen/graph/GraphManager.java
@@ -239,9 +239,6 @@ public class GraphManager {
         }
 
 
-        List<String> defaultGroupArchetypes = configLoader.loadGroupArchetypesStrings();
-        graph.setDefaultGroupArchetypes(defaultGroupArchetypes);
-
         Set<VertexImpl> resultVertices = getVerticesByArchetypeFilter(filter);
         resultVertices = getVerticesByAttributeFilter(filter, resultVertices);
         List<EdgeImpl> resultEdges = getEdgesByArchetypeFilter(filter, resultVertices);
@@ -257,7 +254,8 @@ public class GraphManager {
         graph.setAttributeTypes(attributeTypes);
         graph.setPossibleEnumValues(possibleEnumValues);
 
-        graph.setGraphState(createGraphState(graph));
+        List<String> defaultGroupArchetypes = configLoader.loadGroupArchetypesStrings();
+        addDefaultGroups(graph, defaultGroupArchetypes);
 
         return graph;
     }
@@ -454,7 +452,7 @@ public class GraphManager {
         int idCounter = 1;
         for (EdgeImpl edgeImpl : edgeSet.keySet()) {
             Edge edge = new Edge(idCounter++, edgeImpl.getFrom(), edgeImpl.getTo(), edgeImpl.getText(), edgeSet.get(edgeImpl));
-            graph.addEdge(edge);
+            graph.getEdges().add(edge);
         }
     }
 
@@ -488,7 +486,7 @@ public class GraphManager {
 
             List<String[]> attributes = getAttributesAsArray(vertexImpl.getSortedAttributes());
             Vertex vertex = new Vertex(vertexImpl,attributes);
-            graph.addVertex(vertex);
+            graph.getVertices().add(vertex);
         }
     }
 
@@ -540,28 +538,13 @@ public class GraphManager {
     }
 
     /**
-     * Method is used for initialization of default graph status based on input graph.
-     *
-     * @param graph graph where are set vertices, defaultGroupArchetypes and vertexArchetypes.
-     * @return instance of created GraphState
-     */
-    private GraphState createGraphState(Graph graph) {
-        GraphState state = new GraphState();
-
-        state.addGroupsAll(createDefaultGroups(graph));
-
-
-        return state;
-    }
-
-    /**
-     * Method create list of groups based on defaultGroupArchetypes whose are defined in graph. Vertices are taken
-     * from graph too.
+     * Method add list of groups whose are defined in defaultGroupArchetypes to graph.
+     * Vertices are taken from graph.
      *
-     * @param graph graph from which are groups created.
-     * @return created list of groups or empty list.
+     * @param graph graph to which are groups added.
+     * @param defaultGroupArchetypes list of group archetypes
      */
-    private Collection<Group> createDefaultGroups(Graph graph){
+    private void addDefaultGroups(Graph graph, List<String> defaultGroupArchetypes){
 
         Map<Integer, Group> groups = new HashMap<>();
         int groupId = 1;
@@ -569,7 +552,7 @@ public class GraphManager {
         // find index of vertex archetypes names
         int index = 0;
         for(VertexArchetype archetype : graph.getVertexArchetypes()){
-            if(graph.getDefaultGroupArchetypes().contains(archetype.name)){
+            if(defaultGroupArchetypes.contains(archetype.name)){
                 groups.put(index, new Group(groupId++, archetype.name));
             }
             index++;
@@ -590,6 +573,6 @@ public class GraphManager {
             }
         }
 
-        return groupList;
+        graph.setGroups(groupList);
     }
 }
diff --git a/sources/src/main/java/cz/zcu/kiv/offscreen/graph/GraphState.java b/sources/src/main/java/cz/zcu/kiv/offscreen/graph/GraphState.java
deleted file mode 100644
index 2efa435..0000000
--- a/sources/src/main/java/cz/zcu/kiv/offscreen/graph/GraphState.java
+++ /dev/null
@@ -1,57 +0,0 @@
-package cz.zcu.kiv.offscreen.graph;
-
-import cz.zcu.kiv.offscreen.api.Group;
-import cz.zcu.kiv.offscreen.api.SideBar;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.List;
-
-public class GraphState {
-
-    private List<Group> groups = new ArrayList<>();
-    private List<SideBar> sideBar = new ArrayList<>();
-    private String highlightedVertex;
-    private String highlightedEdge;
-
-
-    public List<Group> getGroups() {
-        return groups;
-    }
-
-    public List<SideBar> getSideBar() {
-        return sideBar;
-    }
-
-    public String getHighlightedVertex() {
-        return highlightedVertex;
-    }
-
-    public String getHighlightedEdge() {
-        return highlightedEdge;
-    }
-
-    public void addGroup(Group group){
-        this.groups.add(group);
-    }
-
-    public void addSideBar(SideBar sideBar){
-        this.sideBar.add(sideBar);
-    }
-
-    public void addGroupsAll(Collection<Group> collection){
-        this.groups.addAll(collection);
-    }
-
-    public void addSideBarsAll(Collection<SideBar> collection){
-        this.sideBar.addAll(collection);
-    }
-
-    public void setHighlightedVertex(String highlightedVertex) {
-        this.highlightedVertex = highlightedVertex;
-    }
-
-    public void setHighlightedEdge(String highlightedEdge) {
-        this.highlightedEdge = highlightedEdge;
-    }
-}
diff --git a/sources/src/main/java/cz/zcu/kiv/offscreen/servlets/api/LoadGraphData.java b/sources/src/main/java/cz/zcu/kiv/offscreen/servlets/api/LoadGraphData.java
index cbbad5b..c0d37a4 100644
--- a/sources/src/main/java/cz/zcu/kiv/offscreen/servlets/api/LoadGraphData.java
+++ b/sources/src/main/java/cz/zcu/kiv/offscreen/servlets/api/LoadGraphData.java
@@ -53,11 +53,12 @@ public class LoadGraphData extends BaseServlet {
 
         if (!Strings.isNullOrEmpty(jsonToDisplay)) {
             GraphManager graphManager = new GraphJSONDataLoader(jsonToDisplay).LoadData();
+
             String configLocation = ConfigurationLoader.getConfigLocation(request.getServletContext());
             JSONConfigLoader configLoader = new JSONConfigLoader(graphManager, configLocation);
-            cz.zcu.kiv.offscreen.graph.Graph graph = graphManager.createGraph(configLoader);
-            Graph export = new Graph(graph);
-            JSONObject json = JSONObject.fromObject(export);
+
+            Graph graph = graphManager.createGraph(configLoader);
+            JSONObject json = JSONObject.fromObject(graph);
 
             response.setStatus(HttpServletResponse.SC_OK);
             response.getWriter().write(json.toString());
diff --git a/sources/src/test/java/cz/zcu/kiv/imiger/tests/backend/GraphFilterTest.java b/sources/src/test/java/cz/zcu/kiv/imiger/tests/backend/GraphFilterTest.java
index 8b556a5..9d8ba66 100644
--- a/sources/src/test/java/cz/zcu/kiv/imiger/tests/backend/GraphFilterTest.java
+++ b/sources/src/test/java/cz/zcu/kiv/imiger/tests/backend/GraphFilterTest.java
@@ -1,9 +1,9 @@
 package cz.zcu.kiv.imiger.tests.backend;
 
 import cz.zcu.kiv.offscreen.api.Edge;
+import cz.zcu.kiv.offscreen.api.Graph;
 import cz.zcu.kiv.offscreen.api.SubedgeInfo;
 import cz.zcu.kiv.offscreen.api.Vertex;
-import cz.zcu.kiv.offscreen.graph.Graph;
 import cz.zcu.kiv.offscreen.graph.GraphManager;
 import cz.zcu.kiv.offscreen.graph.loader.GraphJSONDataLoader;
 import cz.zcu.kiv.offscreen.graph.loader.JSONConfigLoader;
@@ -12,7 +12,6 @@ import org.junit.jupiter.api.BeforeAll;
 import org.junit.jupiter.api.Test;
 
 import java.io.File;
-import java.io.IOException;
 import java.util.ArrayList;
 import java.util.List;
 
