commit faddc9d1443797c694e0ee0d565103e8b8fc7aa5
Author: Tomáš Šimandl <tomas.simandl@gmail.com>
Date:   Thu Nov 29 18:26:15 2018 +0100

    #7 Use SLF4J logger
    
    - replaced System.out.println() and e.printStackTrace() with logger

diff --git a/sources/src/main/java/cz/zcu/kiv/offscreen/graph/loader/JSONConfigLoader.java b/sources/src/main/java/cz/zcu/kiv/offscreen/graph/loader/JSONConfigLoader.java
index e562190..13abba0 100644
--- a/sources/src/main/java/cz/zcu/kiv/offscreen/graph/loader/JSONConfigLoader.java
+++ b/sources/src/main/java/cz/zcu/kiv/offscreen/graph/loader/JSONConfigLoader.java
@@ -8,6 +8,8 @@ import cz.zcu.kiv.offscreen.graph.filter.*;
 import net.sf.json.JSONArray;
 import net.sf.json.JSONObject;
 import org.apache.commons.io.IOUtils;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
 
 import java.io.File;
 import java.io.IOException;
@@ -24,6 +26,7 @@ import java.util.*;
  * @author Stepan Baratta
  */
 public class JSONConfigLoader {
+    private static final Logger logger = LogManager.getLogger();
 
     private GraphManager graphManager;
     private JSONObject json;
@@ -68,7 +71,7 @@ public class JSONConfigLoader {
             createEdgeAttributeFilters(filter, edgeAttributeFilterStrings);
 
         } catch (IOException | NullPointerException e) {
-            e.printStackTrace();
+            logger.warn("Can not load file with configuration. No configuration will be used. Exception: ", e);
         }
 
         return filter;
diff --git a/sources/src/main/java/cz/zcu/kiv/offscreen/storage/FileLoader.java b/sources/src/main/java/cz/zcu/kiv/offscreen/storage/FileLoader.java
index 5af7bbc..f647a31 100644
--- a/sources/src/main/java/cz/zcu/kiv/offscreen/storage/FileLoader.java
+++ b/sources/src/main/java/cz/zcu/kiv/offscreen/storage/FileLoader.java
@@ -51,7 +51,7 @@ public class FileLoader {
             }
 
         } catch (Exception ex) {
-            ex.printStackTrace();
+            logger.error("Can not load file from request: ", ex);
         }
         return resultMap;
     }
diff --git a/sources/src/main/java/cz/zcu/kiv/offscreen/user/DB.java b/sources/src/main/java/cz/zcu/kiv/offscreen/user/DB.java
index 4568eff..08af9fa 100644
--- a/sources/src/main/java/cz/zcu/kiv/offscreen/user/DB.java
+++ b/sources/src/main/java/cz/zcu/kiv/offscreen/user/DB.java
@@ -1,5 +1,8 @@
 package cz.zcu.kiv.offscreen.user;
 
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+
 import javax.servlet.ServletContext;
 import java.sql.*;
 
@@ -11,6 +14,8 @@ import java.sql.*;
  */
 
 public class DB {
+
+	private static final Logger logger = LogManager.getLogger();
 	private Connection connection;
 	
 	/**
@@ -27,7 +32,7 @@ public class DB {
 			connection = DriverManager.getConnection(url, username, password);
 			connection.setAutoCommit(true);
 		} catch (ClassNotFoundException | SQLException e) {
-			e.printStackTrace();
+			logger.error("Can not open database connection: ", e);
 		}
 	}
 
@@ -56,7 +61,7 @@ public class DB {
 			preparedStatement.execute();
 			return preparedStatement.getResultSet();
 		} catch (SQLException e) {
-			e.printStackTrace();
+			logger.error("Can not execute database query: ", e);
 		}
 		return null;
 	}
@@ -71,7 +76,7 @@ public class DB {
 			preparedStatement.executeUpdate();
 			return preparedStatement.getGeneratedKeys();
 		} catch (SQLException e) {
-			e.printStackTrace();
+			logger.error("Can not execute database query: ", e);
 		}
 		return null;
 	}
@@ -88,7 +93,7 @@ public class DB {
 			return stat.getResultSet();
 
 		} catch(SQLException | NullPointerException e) {
-			e.printStackTrace();
+			logger.error("Can not execute database query: ", e);
 		}
 		return null;
 	}
@@ -102,10 +107,10 @@ public class DB {
 		try {
 			return preparedStatement.executeUpdate();
 		} catch(SQLException e) {
-			e.printStackTrace();
+			logger.error("Can not execute database query: ", e);
 			return -1;
 		} catch (NullPointerException e) {
-			e.printStackTrace();
+			logger.error("Can not execute database query: ", e);
 			return -2;
 		}
 	}
diff --git a/sources/src/main/java/cz/zcu/kiv/offscreen/user/Diagram.java b/sources/src/main/java/cz/zcu/kiv/offscreen/user/Diagram.java
index a8cc5ff..85fd8ae 100644
--- a/sources/src/main/java/cz/zcu/kiv/offscreen/user/Diagram.java
+++ b/sources/src/main/java/cz/zcu/kiv/offscreen/user/Diagram.java
@@ -1,5 +1,8 @@
 package cz.zcu.kiv.offscreen.user;
 
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+
 import java.sql.PreparedStatement;
 import java.sql.ResultSet;
 import java.sql.SQLException;
@@ -15,6 +18,8 @@ import java.util.Map;
  * @author Tomáš Šimandl
  */
 public class Diagram {
+    private static final Logger logger = LogManager.getLogger();
+
     private DB db = null;
     private int id = 0;
 
@@ -52,7 +57,7 @@ public class Diagram {
                 return rs.getInt("user_id");
             }
         }  catch (SQLException e){
-            e.printStackTrace();
+            logger.error("Can not get owner id: ", e);
         }
         return -1;
     }
@@ -72,7 +77,7 @@ public class Diagram {
                 return rs.getString("public").equals("1");
             }
         }  catch (SQLException e){
-            e.printStackTrace();
+            logger.error("Can not check if diagram is public: ", e);
         }
         return false;
     }
@@ -91,7 +96,7 @@ public class Diagram {
                 return rs.getString("graph_json");
             }
         }  catch (SQLException e){
-            e.printStackTrace();
+            logger.error("Can not get json of diagram: ", e);
         }
         return "";
     }
@@ -114,7 +119,7 @@ public class Diagram {
             }
 
         } catch (SQLException e) {
-            e.printStackTrace();
+            logger.error("Can not get diagram: ", e);
         }
 
         return Collections.emptyMap();
@@ -166,7 +171,7 @@ public class Diagram {
                 db.executeStatement(pst);
             }
         } catch (SQLException e) {
-            e.printStackTrace();
+            logger.error("Can not update diagram: ", e);
         }
     }
 
@@ -184,7 +189,7 @@ public class Diagram {
             db.executeStatement(pst);
 
         } catch (SQLException e) {
-            e.printStackTrace();
+            logger.error("Can not delete diagram: ", e);
         }
     }
 
@@ -229,7 +234,7 @@ public class Diagram {
             return diagram_list;
 
         } catch (SQLException e){
-            e.printStackTrace();
+            logger.error("Can not create map from input result set: ", e);
         }
 
         return new ArrayList<>();
diff --git a/sources/src/main/java/cz/zcu/kiv/offscreen/user/User.java b/sources/src/main/java/cz/zcu/kiv/offscreen/user/User.java
index 2310827..7fa533d 100644
--- a/sources/src/main/java/cz/zcu/kiv/offscreen/user/User.java
+++ b/sources/src/main/java/cz/zcu/kiv/offscreen/user/User.java
@@ -1,4 +1,7 @@
 package cz.zcu.kiv.offscreen.user;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+
 import java.sql.PreparedStatement;
 import java.sql.ResultSet;
 import java.sql.SQLException;
@@ -13,6 +16,9 @@ import java.util.Map;
  *
  */
 public class User {
+
+	private static final Logger logger = LogManager.getLogger();
+
 	private DB db = null;
 	private int id = 0;
 
@@ -55,7 +61,7 @@ public class User {
 				}
 			}
 		} catch (SQLException e) {
-			e.printStackTrace();
+			logger.error("Can not login user: ", e);
 		}
 
 		return false;
@@ -91,7 +97,7 @@ public class User {
 			}
 
 		} catch (SQLException e) {
-			e.printStackTrace();
+			logger.error("Can not register user: ", e);
 		}
 	}
 
@@ -123,7 +129,7 @@ public class User {
 				this.id = 0;
 			}
 		} catch (SQLException e) {
-			e.printStackTrace();
+			logger.error("Can not get user: ", e);
 		}
 
 		return Collections.emptyMap();
@@ -152,7 +158,7 @@ public class User {
 				db.executeStatement(pst);
 
 			} catch (SQLException e) {
-				e.printStackTrace();
+				logger.error("Can not get user session: ", e);
 			}
 		}
 	}
@@ -174,7 +180,7 @@ public class User {
 
 				db.executeStatement(pst);
 			} catch (SQLException e) {
-				e.printStackTrace();
+				logger.error("Can not update user: ", e);
 			}
 		}
 	}
@@ -192,7 +198,7 @@ public class User {
 					return rs.getString("nick");
 				}
 			}  catch (SQLException e){
-				e.printStackTrace();
+				logger.error("Can not get users nick name: ", e);
 			}
 		}
 
@@ -234,7 +240,7 @@ public class User {
 				return true;
 			}
 		} catch (SQLException e) {
-			e.printStackTrace();
+			logger.error("Can not check if user exits: ", e);
 		}
 
 		return false;
diff --git a/sources/src/test/java/cz/zcu/kiv/imiger/tests/frontend/ArchetypeIconConfigTest.java b/sources/src/test/java/cz/zcu/kiv/imiger/tests/frontend/ArchetypeIconConfigTest.java
index 434ed79..d876d29 100644
--- a/sources/src/test/java/cz/zcu/kiv/imiger/tests/frontend/ArchetypeIconConfigTest.java
+++ b/sources/src/test/java/cz/zcu/kiv/imiger/tests/frontend/ArchetypeIconConfigTest.java
@@ -1,5 +1,7 @@
 package cz.zcu.kiv.imiger.tests.frontend;
 
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
 import org.junit.jupiter.api.AfterAll;
 import org.junit.jupiter.api.Assertions;
 import org.junit.jupiter.api.BeforeAll;
@@ -9,6 +11,7 @@ import org.openqa.selenium.WebDriver;
 import org.openqa.selenium.WebElement;
 
 class ArchetypeIconConfigTest {
+    private static final Logger logger = LogManager.getLogger();
     private static WebDriver browser;
 
     @BeforeAll
@@ -23,9 +26,9 @@ class ArchetypeIconConfigTest {
     void SpecifiedValueDefinition(){
         WebElement iconDef = browser.findElement(By.id("vertexArchetypeIcon-SpecifiedIcon"));
 
-        System.out.println("Trying to locate an element with class 'testingArchetypeIcon'");
+        logger.debug("Trying to locate an element with class 'testingArchetypeIcon'");
         iconDef.findElement(By.className("testingArchetypeIcon"));
-        System.out.println("Element found.");
+        logger.debug("Element found.");
     }
 
     @Test
@@ -70,7 +73,7 @@ class ArchetypeIconConfigTest {
         WebElement iconDef = browser.findElement(By.id("vertexArchetypeIcon-" + iconName))
                 .findElement(By.tagName("text"));
 
-        System.out.println("Testing if icon contains specific text");
+        logger.debug("Testing if icon contains specific text");
         Assertions.assertEquals(iconName.substring(0,1), iconDef.getText());
     }
 
diff --git a/sources/src/test/java/cz/zcu/kiv/imiger/tests/frontend/AssociatedArchetypeTest.java b/sources/src/test/java/cz/zcu/kiv/imiger/tests/frontend/AssociatedArchetypeTest.java
index 58e5f97..0880790 100644
--- a/sources/src/test/java/cz/zcu/kiv/imiger/tests/frontend/AssociatedArchetypeTest.java
+++ b/sources/src/test/java/cz/zcu/kiv/imiger/tests/frontend/AssociatedArchetypeTest.java
@@ -1,5 +1,7 @@
 package cz.zcu.kiv.imiger.tests.frontend;
 
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
 import org.junit.jupiter.api.AfterAll;
 import org.junit.jupiter.api.Assertions;
 import org.junit.jupiter.api.BeforeAll;
@@ -13,6 +15,7 @@ import java.util.List;
 
 
 class AssociatedArchetypeTest {
+    private static final Logger logger = LogManager.getLogger();
     private static WebDriver browser;
 
     @BeforeAll
@@ -63,27 +66,27 @@ class AssociatedArchetypeTest {
      * @param expectedArchetypeIconTexts Texts of all the associated archetype icons that are expected to occur
      */
     private void checkVisibilityOfIcons(String elementId, List<String> expectedArchetypes, List<String> expectedArchetypeIconTexts) {
-        System.out.println("Checking element " + elementId);
+        logger.debug("Checking element " + elementId);
         WebElement vertex = browser.findElement(By.cssSelector("[data-id='vertices']"))
                 .findElement(By.cssSelector("[data-id='" + elementId + "']"));
 
         List<WebElement> associatedArchetypeIcons = vertex.findElement(By.tagName("g")).
                 findElements(By.className("archetype-icon"));
 
-        System.out.println("Associated archetypes: \n");
+        logger.debug("Associated archetypes: \n");
         Assertions.assertEquals(associatedArchetypeIcons.size(), expectedArchetypeIconTexts.size());
 
         for (int i = 0; i < expectedArchetypeIconTexts.size(); i++) {
             WebElement icon = associatedArchetypeIcons.get(i);
 
             String iconHref = icon.getAttribute("href");
-            System.out.println("Icon href: " + iconHref+"\n");
+            logger.debug("Icon href: " + iconHref+"\n");
             Assertions.assertEquals("#vertexArchetypeIcon-" + expectedArchetypes.get(i), iconHref);
 
 
             WebElement iconDef = browser.findElement(By.id("vertexArchetypeIcon-" + expectedArchetypes.get(i)));
 
-            System.out.println("Testing if icon contains specific text");
+            logger.debug("Testing if icon contains specific text");
             Assertions.assertEquals(expectedArchetypeIconTexts.get(i), iconDef.getText());
         }
     }
@@ -95,7 +98,7 @@ class AssociatedArchetypeTest {
      * @param expectedHighlightedVertexIds Ids of all the vertices that are expected to be highlighted
      */
     private void checkHighlightedVertices(String vertexId, String archetypeName, List<String> expectedHighlightedVertexIds) {
-        System.out.println("\nChecking associated vertices of vertex: " + vertexId + " for archetype icon with : " + archetypeName);
+        logger.debug("\nChecking associated vertices of vertex: " + vertexId + " for archetype icon with : " + archetypeName);
 
         WebElement vertex = browser.findElement(By.cssSelector("[data-id='vertices']"))
                 .findElement(By.cssSelector("[data-id='" + vertexId + "']"));
@@ -115,12 +118,12 @@ class AssociatedArchetypeTest {
 
         List<WebElement> highlightedVertices = browser.findElements(By.className("node--highlighted-archetype"));
 
-        System.out.println("Number of highlighted vertices: " + highlightedVertices.size());
+        logger.debug("Number of highlighted vertices: " + highlightedVertices.size());
         Assertions.assertEquals(expectedHighlightedVertexIds.size(), highlightedVertices.size());
 
         for(int i = 0; i < highlightedVertices.size(); i++) {
             String id = highlightedVertices.get(i).getAttribute("data-id");
-            System.out.println(id);
+            logger.debug(id);
 
             Assertions.assertEquals(expectedHighlightedVertexIds.get(i), id);
         }
diff --git a/sources/src/test/java/cz/zcu/kiv/imiger/tests/frontend/GroupStatsChangingTest.java b/sources/src/test/java/cz/zcu/kiv/imiger/tests/frontend/GroupStatsChangingTest.java
index 9533db5..93c437d 100644
--- a/sources/src/test/java/cz/zcu/kiv/imiger/tests/frontend/GroupStatsChangingTest.java
+++ b/sources/src/test/java/cz/zcu/kiv/imiger/tests/frontend/GroupStatsChangingTest.java
@@ -1,5 +1,7 @@
 package cz.zcu.kiv.imiger.tests.frontend;
 
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
 import org.junit.jupiter.api.AfterAll;
 import org.junit.jupiter.api.Assertions;
 import org.junit.jupiter.api.BeforeAll;
@@ -11,6 +13,7 @@ import org.openqa.selenium.WebElement;
 import java.util.*;
 
 class GroupStatsChangingTest {
+    private static final Logger logger = LogManager.getLogger();
     private static WebDriver browser;
 
     @BeforeAll
@@ -29,10 +32,10 @@ class GroupStatsChangingTest {
                 .findElement(By.cssSelector("[data-id='3']"));
 
         SeleniumUtil.svgRectClick(firstExcludedVertex);
-        System.out.println("Exclude vertex3 to group as first vertex of group");
+        logger.debug("Exclude vertex3 to group as first vertex of group");
 
         excludeToExistingGroup("2");
-        System.out.println("Exclude vertex2 to group");
+        logger.debug("Exclude vertex2 to group");
 
         //get data-id of fgroup
         groupId = browser.findElement(By.id("excludedNodeListComponent"))
@@ -46,21 +49,21 @@ class GroupStatsChangingTest {
 //        EXCLUDING VERTICES FROM GROUPS IS NOT SUPPORTED YET
 //        excludeToExistingGroup("1");
 //        compareExpectedValues(groupId, new ArrayList<String>(Arrays.asList("2","2","0","2")));
-//        System.out.println("Exclude vertex1 to group");
+//        logger.debug("Exclude vertex1 to group");
 //
-//        System.out.println("Remove vertex2 to group");
+//        logger.debug("Remove vertex2 to group");
 //        removeVertexFromGroup("li2");
 //        compareExpectedValues(groupId, new ArrayList<String>(Arrays.asList("1","2","0","2")));
 //
-//        System.out.println("Switch off stats for vertex1");
+//        logger.debug("Switch off stats for vertex1");
 //        toogleVertexInGroup("li1");
 //        compareExpectedValues(groupId, new ArrayList<String>(Arrays.asList("1","0","0","0")));
 //
-//        System.out.println("Switch off stats for vertex3");
+//        logger.debug("Switch off stats for vertex3");
 //        toogleVertexInGroup("li3");
 //        compareExpectedValues(groupId, new ArrayList<String>(Arrays.asList("0","0","0","0")));
 //
-//        System.out.println("Switch on stats for vertex1");
+//        logger.debug("Switch on stats for vertex1");
 //        toogleVertexInGroup("li3");
 //        excludeToExistingGroup("vertex2");
 //        compareExpectedValues(groupId, new ArrayList<String>(Arrays.asList("2","0","0","0")));
@@ -69,17 +72,17 @@ class GroupStatsChangingTest {
 //        String archetypePrefix = "v_archetype_4_";
 //        SeleniumUtil.switchToExcludeMode();
 //        WebElement singleEcludedVertex = browser.findElement(By.id("vertex4"));
-//        System.out.println("Exclude vertex4 to group as first vertex of group");
+//        logger.debug("Exclude vertex4 to group as first vertex of group");
 //        SeleniumUtil.svgClick(singleEcludedVertex);
 //
-//        System.out.println("Checking group statistics");
+//        logger.debug("Checking group statistics");
 //        String actualValue1 = browser.findElement(By.id(archetypePrefix + "0")).findElement(By.tagName("text")).getText();
 //        String actualValue2 = browser.findElement(By.id(archetypePrefix + "2")).findElement(By.tagName("text")).getText();
 //        Assertions.assertEquals(actualValue1, "2");
 //        Assertions.assertEquals(actualValue2, "1");
 //
-//        System.out.println("Expected: 2 - Real: " + actualValue1);
-//        System.out.println("Expected: 1 - Real: " + actualValue2);
+//        logger.debug("Expected: 2 - Real: " + actualValue1);
+//        logger.debug("Expected: 1 - Real: " + actualValue2);
 
     }
 
@@ -120,7 +123,7 @@ class GroupStatsChangingTest {
      * @param expectedValues list of expected values
      */
     private void compareExpectedValues(String groupId, Map<String, String> expectedValues){
-        System.out.println("Checking group statistics");
+        logger.debug("Checking group statistics");
         String archetypePrefix = "#vertexArchetypeIcon-";
 
         WebElement nodeList = browser.findElement(By.id("excludedNodeListComponent"))
diff --git a/sources/src/test/java/cz/zcu/kiv/imiger/tests/frontend/SeleniumUtil.java b/sources/src/test/java/cz/zcu/kiv/imiger/tests/frontend/SeleniumUtil.java
index d502806..2895759 100644
--- a/sources/src/test/java/cz/zcu/kiv/imiger/tests/frontend/SeleniumUtil.java
+++ b/sources/src/test/java/cz/zcu/kiv/imiger/tests/frontend/SeleniumUtil.java
@@ -1,5 +1,7 @@
 package cz.zcu.kiv.imiger.tests.frontend;
 
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
 import org.openqa.selenium.By;
 import org.openqa.selenium.WebDriver;
 import org.openqa.selenium.WebElement;
@@ -13,7 +15,7 @@ import java.nio.file.Files;
 import java.nio.file.Paths;
 
 class SeleniumUtil {
-
+    private static final Logger logger = LogManager.getLogger();
     private static final String TEST_DIRECTORY = System.getProperty("user.dir") + "\\src\\test\\resources";
 
     /**
@@ -49,7 +51,7 @@ class SeleniumUtil {
         try {
             Thread.sleep(1000);
         } catch (InterruptedException e) {
-            e.printStackTrace();
+            logger.warn("Thread.sleep caused exception: ", e);
         }
     }
 
@@ -59,7 +61,7 @@ class SeleniumUtil {
             Files.createLink(Paths.get(APP_CONFIG_LOCATION + "\\config.json"),
                     Paths.get(TEST_DIRECTORY + "\\config\\" + configFile));
         } catch (IOException e) {
-            e.printStackTrace();
+            logger.error("Can not prepare configuration file: ", e);
         }
     }
 
@@ -76,7 +78,7 @@ class SeleniumUtil {
         try {
             Thread.sleep(1000);
         } catch (InterruptedException e) {
-            e.printStackTrace();
+            logger.warn("Thread.sleep caused exception: ", e);
         }
     }
 
@@ -86,7 +88,7 @@ class SeleniumUtil {
         try {
             Thread.sleep(1000);
         } catch (InterruptedException e) {
-            e.printStackTrace();
+            logger.warn("Thread.sleep caused exception: ", e);
         }
     }
 
@@ -97,7 +99,7 @@ class SeleniumUtil {
         try {
             Thread.sleep(1000);
         } catch (InterruptedException e) {
-            e.printStackTrace();
+            logger.warn("Thread.sleep caused exception: ", e);
         }
     }
 
@@ -112,7 +114,7 @@ class SeleniumUtil {
         try {
             Thread.sleep(1000);
         } catch (InterruptedException e) {
-            e.printStackTrace();
+            logger.warn("Thread.sleep caused exception: ", e);
         }
     }
 
@@ -127,7 +129,7 @@ class SeleniumUtil {
         try {
             Thread.sleep(1000);
         } catch (InterruptedException e) {
-            e.printStackTrace();
+            logger.warn("Thread.sleep caused exception: ", e);
         }
     }
 
