commit 80ed28fbde8bda4d883e8219b44382dfc43a4d0e
Author: Vít Mazín <n5ver@seznam.cz>
Date:   Sat Apr 20 14:24:26 2019 +0200

    Alert with information about error in source file (#7268)

diff --git a/sources/imiger-core/src/main/java/cz/zcu/kiv/offscreen/servlets/api/GetSessionDiagram.java b/sources/imiger-core/src/main/java/cz/zcu/kiv/offscreen/servlets/api/GetSessionDiagram.java
index 46c876e..25c5d8f 100644
--- a/sources/imiger-core/src/main/java/cz/zcu/kiv/offscreen/servlets/api/GetSessionDiagram.java
+++ b/sources/imiger-core/src/main/java/cz/zcu/kiv/offscreen/servlets/api/GetSessionDiagram.java
@@ -53,7 +53,7 @@ public class GetSessionDiagram extends BaseServlet {
                 if(optional.isPresent()){
                     rawJson = optional.get();
                 } else {
-                    response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
+                    response.setStatus(HttpServletResponse.SC_NOT_ACCEPTABLE);
                     return;
                 }
             }
diff --git a/sources/imiger-core/src/main/webapp/js/showGraphApp.js b/sources/imiger-core/src/main/webapp/js/showGraphApp.js
index ad91080..1844ea2 100644
--- a/sources/imiger-core/src/main/webapp/js/showGraphApp.js
+++ b/sources/imiger-core/src/main/webapp/js/showGraphApp.js
@@ -263,6 +263,9 @@ class ShowGraphApp extends App {
 					case 401:
 						alert('You are not allowed to view the diagram.');
 						break;
+					case 406:
+						alert('There was a problem in graph source file.');
+						break;
 					default:
 						console.error(error);
 						alert('Something went wrong. Check console for more details.');
diff --git a/sources/imiger-dot-converter/src/main/java/cz/zcu/kiv/imiger/plugin/dot/DOT.java b/sources/imiger-dot-converter/src/main/java/cz/zcu/kiv/imiger/plugin/dot/DOT.java
index f14ce1a..d9d0b62 100644
--- a/sources/imiger-dot-converter/src/main/java/cz/zcu/kiv/imiger/plugin/dot/DOT.java
+++ b/sources/imiger-dot-converter/src/main/java/cz/zcu/kiv/imiger/plugin/dot/DOT.java
@@ -4,7 +4,7 @@ import com.google.gson.Gson;
 import cz.zcu.kiv.imiger.plugin.dot.dto.EdgeDTO;
 import cz.zcu.kiv.imiger.plugin.dot.dto.VertexDTO;
 import cz.zcu.kiv.imiger.plugin.dot.loader.BaseDOTLoader;
-import cz.zcu.kiv.imiger.plugin.dot.loader.PaypalDOTLoader;
+import cz.zcu.kiv.imiger.plugin.dot.loader.DigraphDOTLoader;
 import cz.zcu.kiv.imiger.spi.IModule;
 import cz.zcu.kiv.imiger.vo.Graph;
 
@@ -32,11 +32,17 @@ public class DOT implements IModule {
      */
     @Override
     public String getRawJson(String stringToConvert) {
-        BaseDOTLoader<VertexDTO, EdgeDTO> loader = new PaypalDOTLoader(stringToConvert);
+        BaseDOTLoader<VertexDTO, EdgeDTO> loader = new DigraphDOTLoader(stringToConvert);
         GraphFactory graphFactory = new GraphFactory(loader);
         Graph graph = graphFactory.createGraph();
 
-        Gson gson = new Gson();
-        return gson.toJson(graph, Graph.class);
+        if(!graph.getVertices().isEmpty()) {
+            Gson gson = new Gson();
+            return gson.toJson(graph, Graph.class);
+        }
+
+        else {
+            return "";
+        }
     }
 }
diff --git a/sources/imiger-dot-converter/src/main/java/cz/zcu/kiv/imiger/plugin/dot/loader/DigraphDOTLoader.java b/sources/imiger-dot-converter/src/main/java/cz/zcu/kiv/imiger/plugin/dot/loader/DigraphDOTLoader.java
new file mode 100644
index 0000000..18a09e5
--- /dev/null
+++ b/sources/imiger-dot-converter/src/main/java/cz/zcu/kiv/imiger/plugin/dot/loader/DigraphDOTLoader.java
@@ -0,0 +1,137 @@
+package cz.zcu.kiv.imiger.plugin.dot.loader;
+
+import com.paypal.digraph.parser.GraphEdge;
+import com.paypal.digraph.parser.GraphNode;
+import com.paypal.digraph.parser.GraphParser;
+import com.paypal.digraph.parser.GraphParserException;
+import cz.zcu.kiv.imiger.plugin.dot.dto.EdgeDTO;
+import cz.zcu.kiv.imiger.plugin.dot.dto.VertexDTO;
+import cz.zcu.kiv.imiger.vo.AttributeDataType;
+import cz.zcu.kiv.imiger.vo.AttributeType;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+
+import java.io.ByteArrayInputStream;
+import java.util.*;
+
+public class DigraphDOTLoader extends BaseDOTLoader<VertexDTO, EdgeDTO> {
+    private static Logger logger = LogManager.getLogger();
+
+    private GraphParser parser;
+    private final List<VertexDTO> vertices;
+    private final List<EdgeDTO> edges;
+    private final HashSet<AttributeType> attributeTypes;
+    private final HashSet<String> attributeNames;
+    private final HashMap<GraphNode, Integer> remappedVertices;
+
+    /**
+     * DOT loader which uses Digraph library
+     *
+     * @param dotInput - Source DOT file
+     */
+    public DigraphDOTLoader(String dotInput) {
+        super(dotInput);
+        parser = null;
+
+        try {
+            parser = new GraphParser(new ByteArrayInputStream(super.dotInput.getBytes()));
+        } catch (GraphParserException ex) {
+            logger.warn("There was a mistake in input DOT file. Exception: " + ex.getMessage());
+        }
+        vertices = new ArrayList<>();
+        edges = new ArrayList<>();
+        attributeTypes = new HashSet<>();
+        remappedVertices = new HashMap<>();
+        attributeNames = new HashSet<>();
+
+        if(parser != null) {
+            processVertices();
+            processEdges();
+        }
+    }
+
+    /**
+     * Returns list of vertices DTO
+     * @return List of vertices DTO
+     */
+    @Override
+    public List<VertexDTO> getVertices() {
+        return vertices;
+    }
+
+    /**
+     * Returns list of edges DTO
+     * @return List of edges DTO
+     */
+    @Override
+    public List<EdgeDTO> getEdges() {
+        return edges;
+    }
+
+    /**
+     * Returns list of attribute types
+     * @return List of attribute types
+     */
+    @Override
+    public Set<AttributeType> getAttributeTypes() {
+        if(attributeTypes.size() == 0 && attributeNames.size() > 0) {
+            for(String attr : attributeNames) {
+                attributeTypes.add(new AttributeType(attr, AttributeDataType.STRING, ""));
+            }
+        }
+        return attributeTypes;
+    }
+
+    /**
+     * Method transforms vertices from GraphNode object to vertex DTO and stores attribute type.
+     * It has to be called before processing edges.
+     */
+    private void processVertices() {
+        int id = 0;
+
+        for(GraphNode node : this.parser.getNodes().values()) {
+            HashMap<String, String> attrs = new HashMap<>();
+
+            if(!node.getAttributes().entrySet().isEmpty()) {
+                for (Map.Entry<String, Object> entry : node.getAttributes().entrySet()) {
+                    String key = entry.getKey().replaceAll("\\\\n|\\\\l|\"", "");
+                    String value = entry.getValue().toString().replaceAll("\\\\n|\\\\l|\"", "");
+                    attrs.put(key, value);
+                    attributeNames.add(key);
+                }
+            }
+
+            VertexDTO vertex = new VertexDTO(node.getId().replaceAll("\\\\n|\\\\l|\"", ""), id++, attrs);
+            this.remappedVertices.put(node, vertex.getId());
+
+            vertices.add(vertex);
+        }
+    }
+
+    /**
+     * Method transforms vertices from GraphNode object to vertex DTO and stores attribute type.
+     * It has to be called after processing vertices.
+     */
+    private void processEdges() {
+        int id = 0;
+
+        for(GraphEdge edge : this.parser.getEdges().values()) {
+            HashMap<String, String> attrs = new HashMap<>();
+
+            if(!edge.getAttributes().entrySet().isEmpty()) {
+                for (Map.Entry<String, Object> entry : edge.getAttributes().entrySet()) {
+                    String key = entry.getKey().replaceAll("\\\\n|\\\\l|\"", "");
+                    String value = entry.getValue().toString().replaceAll("\\\\n|\\\\l|\"", "");
+                    attrs.put(key, value);
+                    attributeNames.add(key);
+                }
+            }
+
+            int from = remappedVertices.get(edge.getNode1());
+            int to = remappedVertices.get(edge.getNode2());
+            EdgeDTO edgeDTO = new EdgeDTO(edge.getId().replaceAll("\\\\n|\\\\l|\"", ""), from, to, id++, attrs);
+            
+            edges.add(edgeDTO);
+        }
+    }
+}
diff --git a/sources/imiger-dot-converter/src/main/java/cz/zcu/kiv/imiger/plugin/dot/loader/PaypalDOTLoader.java b/sources/imiger-dot-converter/src/main/java/cz/zcu/kiv/imiger/plugin/dot/loader/PaypalDOTLoader.java
deleted file mode 100644
index c3aff06..0000000
--- a/sources/imiger-dot-converter/src/main/java/cz/zcu/kiv/imiger/plugin/dot/loader/PaypalDOTLoader.java
+++ /dev/null
@@ -1,137 +0,0 @@
-package cz.zcu.kiv.imiger.plugin.dot.loader;
-
-import com.paypal.digraph.parser.GraphEdge;
-import com.paypal.digraph.parser.GraphNode;
-import com.paypal.digraph.parser.GraphParser;
-import com.paypal.digraph.parser.GraphParserException;
-import cz.zcu.kiv.imiger.plugin.dot.dto.EdgeDTO;
-import cz.zcu.kiv.imiger.plugin.dot.dto.VertexDTO;
-import cz.zcu.kiv.imiger.vo.AttributeDataType;
-import cz.zcu.kiv.imiger.vo.AttributeType;
-import org.apache.logging.log4j.LogManager;
-import org.apache.logging.log4j.Logger;
-
-import java.io.ByteArrayInputStream;
-import java.util.*;
-
-public class PaypalDOTLoader extends BaseDOTLoader<VertexDTO, EdgeDTO> {
-    private static Logger logger = LogManager.getLogger();
-
-    private GraphParser parser;
-    private final List<VertexDTO> vertices;
-    private final List<EdgeDTO> edges;
-    private final HashSet<AttributeType> attributeTypes;
-    private final HashSet<String> attributeNames;
-    private final HashMap<GraphNode, Integer> remappedVertices;
-
-    /**
-     * DOT loader which uses Digraph library
-     *
-     * @param dotInput - Source DOT file
-     */
-    public PaypalDOTLoader(String dotInput) {
-        super(dotInput);
-        parser = null;
-
-        try {
-            parser = new GraphParser(new ByteArrayInputStream(super.dotInput.getBytes()));
-        } catch (GraphParserException ex) {
-            logger.warn("There was a mistake in input DOT file. Exception: " + ex.getMessage());
-        }
-        vertices = new ArrayList<>();
-        edges = new ArrayList<>();
-        attributeTypes = new HashSet<>();
-        remappedVertices = new HashMap<>();
-        attributeNames = new HashSet<>();
-
-        if(parser != null) {
-            processVertices();
-            processEdges();
-        }
-    }
-
-    /**
-     * Returns list of vertices DTO
-     * @return List of vertices DTO
-     */
-    @Override
-    public List<VertexDTO> getVertices() {
-        return vertices;
-    }
-
-    /**
-     * Returns list of edges DTO
-     * @return List of edges DTO
-     */
-    @Override
-    public List<EdgeDTO> getEdges() {
-        return edges;
-    }
-
-    /**
-     * Returns list of attribute types
-     * @return List of attribute types
-     */
-    @Override
-    public Set<AttributeType> getAttributeTypes() {
-        if(attributeTypes.size() == 0 && attributeNames.size() > 0) {
-            for(String attr : attributeNames) {
-                attributeTypes.add(new AttributeType(attr, AttributeDataType.STRING, ""));
-            }
-        }
-        return attributeTypes;
-    }
-
-    /**
-     * Method transforms vertices from GraphNode object to vertex DTO and stores attribute type.
-     * It has to be called before processing edges.
-     */
-    private void processVertices() {
-        int id = 0;
-
-        for(GraphNode node : this.parser.getNodes().values()) {
-            HashMap<String, String> attrs = new HashMap<>();
-
-            if(!node.getAttributes().entrySet().isEmpty()) {
-                for (Map.Entry<String, Object> entry : node.getAttributes().entrySet()) {
-                    String key = entry.getKey().replaceAll("\\\\n|\\\\l|\"", "");
-                    String value = entry.getValue().toString().replaceAll("\\\\n|\\\\l|\"", "");
-                    attrs.put(key, value);
-                    attributeNames.add(key);
-                }
-            }
-
-            VertexDTO vertex = new VertexDTO(node.getId().replaceAll("\\\\n|\\\\l|\"", ""), id++, attrs);
-            this.remappedVertices.put(node, vertex.getId());
-
-            vertices.add(vertex);
-        }
-    }
-
-    /**
-     * Method transforms vertices from GraphNode object to vertex DTO and stores attribute type.
-     * It has to be called after processing vertices.
-     */
-    private void processEdges() {
-        int id = 0;
-
-        for(GraphEdge edge : this.parser.getEdges().values()) {
-            HashMap<String, String> attrs = new HashMap<>();
-
-            if(!edge.getAttributes().entrySet().isEmpty()) {
-                for (Map.Entry<String, Object> entry : edge.getAttributes().entrySet()) {
-                    String key = entry.getKey().replaceAll("\\\\n|\\\\l|\"", "");
-                    String value = entry.getValue().toString().replaceAll("\\\\n|\\\\l|\"", "");
-                    attrs.put(key, value);
-                    attributeNames.add(key);
-                }
-            }
-
-            int from = remappedVertices.get(edge.getNode1());
-            int to = remappedVertices.get(edge.getNode2());
-            EdgeDTO edgeDTO = new EdgeDTO(edge.getId().replaceAll("\\\\n|\\\\l|\"", ""), from, to, id++, attrs);
-            
-            edges.add(edgeDTO);
-        }
-    }
-}
diff --git a/sources/imiger-dot-converter/src/test/java/cz/zcu/kiv/imiger/plugin/dot/backend/DigraphDOTLoaderTest.java b/sources/imiger-dot-converter/src/test/java/cz/zcu/kiv/imiger/plugin/dot/backend/DigraphDOTLoaderTest.java
new file mode 100644
index 0000000..686872f
--- /dev/null
+++ b/sources/imiger-dot-converter/src/test/java/cz/zcu/kiv/imiger/plugin/dot/backend/DigraphDOTLoaderTest.java
@@ -0,0 +1,79 @@
+package cz.zcu.kiv.imiger.plugin.dot.backend;
+
+import cz.zcu.kiv.imiger.plugin.dot.dto.EdgeDTO;
+import cz.zcu.kiv.imiger.plugin.dot.dto.VertexDTO;
+import cz.zcu.kiv.imiger.plugin.dot.loader.BaseDOTLoader;
+import cz.zcu.kiv.imiger.plugin.dot.loader.DigraphDOTLoader;
+import cz.zcu.kiv.imiger.vo.AttributeType;
+import org.junit.Before;
+import org.junit.Test;
+import org.apache.commons.io.*;
+
+import java.io.IOException;
+import java.util.List;
+import java.util.Set;
+
+import static org.junit.Assert.*;
+
+public class DigraphDOTLoaderTest {
+
+    BaseDOTLoader<VertexDTO, EdgeDTO> loader;
+
+    @Before
+    public void setup() {
+        loader = null;
+    }
+
+    private String getFileAsString(String fileName) {
+        try {
+            return IOUtils.toString(getClass().getClassLoader().getResourceAsStream(fileName), "UTF-8");
+        } catch (IOException e) {
+            return null;
+        }
+    }
+
+    @Test
+    public void testOkGraph() {
+        String input = getFileAsString("complete1.dot");
+
+        loader = new DigraphDOTLoader(input);
+
+        List<VertexDTO> vertices = loader.getVertices();
+        List<EdgeDTO> edges = loader.getEdges();
+        Set<AttributeType> attrs = loader.getAttributeTypes();
+
+        assertEquals(13, vertices.size());
+        assertEquals(12, edges.size());
+        assertEquals(5, attrs.size());
+    }
+
+    @Test
+    public void testIncompleteGraph() {
+        String input = getFileAsString("incomplete1.dot");
+
+        loader = new DigraphDOTLoader(input);
+
+        List<VertexDTO> vertices = loader.getVertices();
+        List<EdgeDTO> edges = loader.getEdges();
+        Set<AttributeType> attrs = loader.getAttributeTypes();
+
+        assertEquals(0, vertices.size());
+        assertEquals(0, edges.size());
+        assertEquals(0, attrs.size());
+    }
+
+    @Test
+    public void missingVertexDefinitionTest() {
+        String input = getFileAsString("incomplete2.dot");
+
+        loader = new DigraphDOTLoader(input);
+
+        List<VertexDTO> vertices = loader.getVertices();
+        List<EdgeDTO> edges = loader.getEdges();
+        Set<AttributeType> attrs = loader.getAttributeTypes();
+
+        assertEquals(13, vertices.size());
+        assertEquals(12, edges.size());
+        assertEquals(5, attrs.size());
+    }
+}
diff --git a/sources/imiger-dot-converter/src/test/java/cz/zcu/kiv/imiger/plugin/dot/backend/PaypalDOTLoaderTest.java b/sources/imiger-dot-converter/src/test/java/cz/zcu/kiv/imiger/plugin/dot/backend/PaypalDOTLoaderTest.java
deleted file mode 100644
index afc6101..0000000
--- a/sources/imiger-dot-converter/src/test/java/cz/zcu/kiv/imiger/plugin/dot/backend/PaypalDOTLoaderTest.java
+++ /dev/null
@@ -1,79 +0,0 @@
-package cz.zcu.kiv.imiger.plugin.dot.backend;
-
-import cz.zcu.kiv.imiger.plugin.dot.dto.EdgeDTO;
-import cz.zcu.kiv.imiger.plugin.dot.dto.VertexDTO;
-import cz.zcu.kiv.imiger.plugin.dot.loader.BaseDOTLoader;
-import cz.zcu.kiv.imiger.plugin.dot.loader.PaypalDOTLoader;
-import cz.zcu.kiv.imiger.vo.AttributeType;
-import org.junit.Before;
-import org.junit.Test;
-import org.apache.commons.io.*;
-
-import java.io.IOException;
-import java.util.List;
-import java.util.Set;
-
-import static org.junit.Assert.*;
-
-public class PaypalDOTLoaderTest {
-
-    BaseDOTLoader<VertexDTO, EdgeDTO> loader;
-
-    @Before
-    public void setup() {
-        loader = null;
-    }
-
-    private String getFileAsString(String fileName) {
-        try {
-            return IOUtils.toString(getClass().getClassLoader().getResourceAsStream(fileName), "UTF-8");
-        } catch (IOException e) {
-            return null;
-        }
-    }
-
-    @Test
-    public void testOkGraph() {
-        String input = getFileAsString("complete1.dot");
-
-        loader = new PaypalDOTLoader(input);
-
-        List<VertexDTO> vertices = loader.getVertices();
-        List<EdgeDTO> edges = loader.getEdges();
-        Set<AttributeType> attrs = loader.getAttributeTypes();
-
-        assertEquals(13, vertices.size());
-        assertEquals(12, edges.size());
-        assertEquals(5, attrs.size());
-    }
-
-    @Test
-    public void testIncompleteGraph() {
-        String input = getFileAsString("incomplete1.dot");
-
-        loader = new PaypalDOTLoader(input);
-
-        List<VertexDTO> vertices = loader.getVertices();
-        List<EdgeDTO> edges = loader.getEdges();
-        Set<AttributeType> attrs = loader.getAttributeTypes();
-
-        assertEquals(0, vertices.size());
-        assertEquals(0, edges.size());
-        assertEquals(0, attrs.size());
-    }
-
-    @Test
-    public void missingVertexDefinitionTest() {
-        String input = getFileAsString("incomplete2.dot");
-
-        loader = new PaypalDOTLoader(input);
-
-        List<VertexDTO> vertices = loader.getVertices();
-        List<EdgeDTO> edges = loader.getEdges();
-        Set<AttributeType> attrs = loader.getAttributeTypes();
-
-        assertEquals(13, vertices.size());
-        assertEquals(12, edges.size());
-        assertEquals(5, attrs.size());
-    }
-}
