Projekt

Obecné

Profil

« Předchozí | Další » 

Revize faddc9d1

Přidáno uživatelem Tomáš Šimandl před více než 6 roky(ů)

#7 Use SLF4J logger

- replaced System.out.println() and e.printStackTrace() with logger

Zobrazit rozdíly:

sources/src/main/java/cz/zcu/kiv/offscreen/graph/loader/JSONConfigLoader.java
8 8
import net.sf.json.JSONArray;
9 9
import net.sf.json.JSONObject;
10 10
import org.apache.commons.io.IOUtils;
11
import org.apache.logging.log4j.LogManager;
12
import org.apache.logging.log4j.Logger;
11 13

  
12 14
import java.io.File;
13 15
import java.io.IOException;
......
24 26
 * @author Stepan Baratta
25 27
 */
26 28
public class JSONConfigLoader {
29
    private static final Logger logger = LogManager.getLogger();
27 30

  
28 31
    private GraphManager graphManager;
29 32
    private JSONObject json;
......
68 71
            createEdgeAttributeFilters(filter, edgeAttributeFilterStrings);
69 72

  
70 73
        } catch (IOException | NullPointerException e) {
71
            e.printStackTrace();
74
            logger.warn("Can not load file with configuration. No configuration will be used. Exception: ", e);
72 75
        }
73 76

  
74 77
        return filter;
sources/src/main/java/cz/zcu/kiv/offscreen/storage/FileLoader.java
51 51
            }
52 52

  
53 53
        } catch (Exception ex) {
54
            ex.printStackTrace();
54
            logger.error("Can not load file from request: ", ex);
55 55
        }
56 56
        return resultMap;
57 57
    }
sources/src/main/java/cz/zcu/kiv/offscreen/user/DB.java
1 1
package cz.zcu.kiv.offscreen.user;
2 2

  
3
import org.apache.logging.log4j.LogManager;
4
import org.apache.logging.log4j.Logger;
5

  
3 6
import javax.servlet.ServletContext;
4 7
import java.sql.*;
5 8

  
......
11 14
 */
12 15

  
13 16
public class DB {
17

  
18
	private static final Logger logger = LogManager.getLogger();
14 19
	private Connection connection;
15 20
	
16 21
	/**
......
27 32
			connection = DriverManager.getConnection(url, username, password);
28 33
			connection.setAutoCommit(true);
29 34
		} catch (ClassNotFoundException | SQLException e) {
30
			e.printStackTrace();
35
			logger.error("Can not open database connection: ", e);
31 36
		}
32 37
	}
33 38

  
......
56 61
			preparedStatement.execute();
57 62
			return preparedStatement.getResultSet();
58 63
		} catch (SQLException e) {
59
			e.printStackTrace();
64
			logger.error("Can not execute database query: ", e);
60 65
		}
61 66
		return null;
62 67
	}
......
71 76
			preparedStatement.executeUpdate();
72 77
			return preparedStatement.getGeneratedKeys();
73 78
		} catch (SQLException e) {
74
			e.printStackTrace();
79
			logger.error("Can not execute database query: ", e);
75 80
		}
76 81
		return null;
77 82
	}
......
88 93
			return stat.getResultSet();
89 94

  
90 95
		} catch(SQLException | NullPointerException e) {
91
			e.printStackTrace();
96
			logger.error("Can not execute database query: ", e);
92 97
		}
93 98
		return null;
94 99
	}
......
102 107
		try {
103 108
			return preparedStatement.executeUpdate();
104 109
		} catch(SQLException e) {
105
			e.printStackTrace();
110
			logger.error("Can not execute database query: ", e);
106 111
			return -1;
107 112
		} catch (NullPointerException e) {
108
			e.printStackTrace();
113
			logger.error("Can not execute database query: ", e);
109 114
			return -2;
110 115
		}
111 116
	}
sources/src/main/java/cz/zcu/kiv/offscreen/user/Diagram.java
1 1
package cz.zcu.kiv.offscreen.user;
2 2

  
3
import org.apache.logging.log4j.LogManager;
4
import org.apache.logging.log4j.Logger;
5

  
3 6
import java.sql.PreparedStatement;
4 7
import java.sql.ResultSet;
5 8
import java.sql.SQLException;
......
15 18
 * @author Tomáš Šimandl
16 19
 */
17 20
public class Diagram {
21
    private static final Logger logger = LogManager.getLogger();
22

  
18 23
    private DB db = null;
19 24
    private int id = 0;
20 25

  
......
52 57
                return rs.getInt("user_id");
53 58
            }
54 59
        }  catch (SQLException e){
55
            e.printStackTrace();
60
            logger.error("Can not get owner id: ", e);
56 61
        }
57 62
        return -1;
58 63
    }
......
72 77
                return rs.getString("public").equals("1");
73 78
            }
74 79
        }  catch (SQLException e){
75
            e.printStackTrace();
80
            logger.error("Can not check if diagram is public: ", e);
76 81
        }
77 82
        return false;
78 83
    }
......
91 96
                return rs.getString("graph_json");
92 97
            }
93 98
        }  catch (SQLException e){
94
            e.printStackTrace();
99
            logger.error("Can not get json of diagram: ", e);
95 100
        }
96 101
        return "";
97 102
    }
......
114 119
            }
115 120

  
116 121
        } catch (SQLException e) {
117
            e.printStackTrace();
122
            logger.error("Can not get diagram: ", e);
118 123
        }
119 124

  
120 125
        return Collections.emptyMap();
......
166 171
                db.executeStatement(pst);
167 172
            }
168 173
        } catch (SQLException e) {
169
            e.printStackTrace();
174
            logger.error("Can not update diagram: ", e);
170 175
        }
171 176
    }
172 177

  
......
184 189
            db.executeStatement(pst);
185 190

  
186 191
        } catch (SQLException e) {
187
            e.printStackTrace();
192
            logger.error("Can not delete diagram: ", e);
188 193
        }
189 194
    }
190 195

  
......
229 234
            return diagram_list;
230 235

  
231 236
        } catch (SQLException e){
232
            e.printStackTrace();
237
            logger.error("Can not create map from input result set: ", e);
233 238
        }
234 239

  
235 240
        return new ArrayList<>();
sources/src/main/java/cz/zcu/kiv/offscreen/user/User.java
1 1
package cz.zcu.kiv.offscreen.user;
2
import org.apache.logging.log4j.LogManager;
3
import org.apache.logging.log4j.Logger;
4

  
2 5
import java.sql.PreparedStatement;
3 6
import java.sql.ResultSet;
4 7
import java.sql.SQLException;
......
13 16
 *
14 17
 */
15 18
public class User {
19

  
20
	private static final Logger logger = LogManager.getLogger();
21

  
16 22
	private DB db = null;
17 23
	private int id = 0;
18 24

  
......
55 61
				}
56 62
			}
57 63
		} catch (SQLException e) {
58
			e.printStackTrace();
64
			logger.error("Can not login user: ", e);
59 65
		}
60 66

  
61 67
		return false;
......
91 97
			}
92 98

  
93 99
		} catch (SQLException e) {
94
			e.printStackTrace();
100
			logger.error("Can not register user: ", e);
95 101
		}
96 102
	}
97 103

  
......
123 129
				this.id = 0;
124 130
			}
125 131
		} catch (SQLException e) {
126
			e.printStackTrace();
132
			logger.error("Can not get user: ", e);
127 133
		}
128 134

  
129 135
		return Collections.emptyMap();
......
152 158
				db.executeStatement(pst);
153 159

  
154 160
			} catch (SQLException e) {
155
				e.printStackTrace();
161
				logger.error("Can not get user session: ", e);
156 162
			}
157 163
		}
158 164
	}
......
174 180

  
175 181
				db.executeStatement(pst);
176 182
			} catch (SQLException e) {
177
				e.printStackTrace();
183
				logger.error("Can not update user: ", e);
178 184
			}
179 185
		}
180 186
	}
......
192 198
					return rs.getString("nick");
193 199
				}
194 200
			}  catch (SQLException e){
195
				e.printStackTrace();
201
				logger.error("Can not get users nick name: ", e);
196 202
			}
197 203
		}
198 204

  
......
234 240
				return true;
235 241
			}
236 242
		} catch (SQLException e) {
237
			e.printStackTrace();
243
			logger.error("Can not check if user exits: ", e);
238 244
		}
239 245

  
240 246
		return false;
sources/src/test/java/cz/zcu/kiv/imiger/tests/frontend/ArchetypeIconConfigTest.java
1 1
package cz.zcu.kiv.imiger.tests.frontend;
2 2

  
3
import org.apache.logging.log4j.LogManager;
4
import org.apache.logging.log4j.Logger;
3 5
import org.junit.jupiter.api.AfterAll;
4 6
import org.junit.jupiter.api.Assertions;
5 7
import org.junit.jupiter.api.BeforeAll;
......
9 11
import org.openqa.selenium.WebElement;
10 12

  
11 13
class ArchetypeIconConfigTest {
14
    private static final Logger logger = LogManager.getLogger();
12 15
    private static WebDriver browser;
13 16

  
14 17
    @BeforeAll
......
23 26
    void SpecifiedValueDefinition(){
24 27
        WebElement iconDef = browser.findElement(By.id("vertexArchetypeIcon-SpecifiedIcon"));
25 28

  
26
        System.out.println("Trying to locate an element with class 'testingArchetypeIcon'");
29
        logger.debug("Trying to locate an element with class 'testingArchetypeIcon'");
27 30
        iconDef.findElement(By.className("testingArchetypeIcon"));
28
        System.out.println("Element found.");
31
        logger.debug("Element found.");
29 32
    }
30 33

  
31 34
    @Test
......
70 73
        WebElement iconDef = browser.findElement(By.id("vertexArchetypeIcon-" + iconName))
71 74
                .findElement(By.tagName("text"));
72 75

  
73
        System.out.println("Testing if icon contains specific text");
76
        logger.debug("Testing if icon contains specific text");
74 77
        Assertions.assertEquals(iconName.substring(0,1), iconDef.getText());
75 78
    }
76 79

  
sources/src/test/java/cz/zcu/kiv/imiger/tests/frontend/AssociatedArchetypeTest.java
1 1
package cz.zcu.kiv.imiger.tests.frontend;
2 2

  
3
import org.apache.logging.log4j.LogManager;
4
import org.apache.logging.log4j.Logger;
3 5
import org.junit.jupiter.api.AfterAll;
4 6
import org.junit.jupiter.api.Assertions;
5 7
import org.junit.jupiter.api.BeforeAll;
......
13 15

  
14 16

  
15 17
class AssociatedArchetypeTest {
18
    private static final Logger logger = LogManager.getLogger();
16 19
    private static WebDriver browser;
17 20

  
18 21
    @BeforeAll
......
63 66
     * @param expectedArchetypeIconTexts Texts of all the associated archetype icons that are expected to occur
64 67
     */
65 68
    private void checkVisibilityOfIcons(String elementId, List<String> expectedArchetypes, List<String> expectedArchetypeIconTexts) {
66
        System.out.println("Checking element " + elementId);
69
        logger.debug("Checking element " + elementId);
67 70
        WebElement vertex = browser.findElement(By.cssSelector("[data-id='vertices']"))
68 71
                .findElement(By.cssSelector("[data-id='" + elementId + "']"));
69 72

  
70 73
        List<WebElement> associatedArchetypeIcons = vertex.findElement(By.tagName("g")).
71 74
                findElements(By.className("archetype-icon"));
72 75

  
73
        System.out.println("Associated archetypes: \n");
76
        logger.debug("Associated archetypes: \n");
74 77
        Assertions.assertEquals(associatedArchetypeIcons.size(), expectedArchetypeIconTexts.size());
75 78

  
76 79
        for (int i = 0; i < expectedArchetypeIconTexts.size(); i++) {
77 80
            WebElement icon = associatedArchetypeIcons.get(i);
78 81

  
79 82
            String iconHref = icon.getAttribute("href");
80
            System.out.println("Icon href: " + iconHref+"\n");
83
            logger.debug("Icon href: " + iconHref+"\n");
81 84
            Assertions.assertEquals("#vertexArchetypeIcon-" + expectedArchetypes.get(i), iconHref);
82 85

  
83 86

  
84 87
            WebElement iconDef = browser.findElement(By.id("vertexArchetypeIcon-" + expectedArchetypes.get(i)));
85 88

  
86
            System.out.println("Testing if icon contains specific text");
89
            logger.debug("Testing if icon contains specific text");
87 90
            Assertions.assertEquals(expectedArchetypeIconTexts.get(i), iconDef.getText());
88 91
        }
89 92
    }
......
95 98
     * @param expectedHighlightedVertexIds Ids of all the vertices that are expected to be highlighted
96 99
     */
97 100
    private void checkHighlightedVertices(String vertexId, String archetypeName, List<String> expectedHighlightedVertexIds) {
98
        System.out.println("\nChecking associated vertices of vertex: " + vertexId + " for archetype icon with : " + archetypeName);
101
        logger.debug("\nChecking associated vertices of vertex: " + vertexId + " for archetype icon with : " + archetypeName);
99 102

  
100 103
        WebElement vertex = browser.findElement(By.cssSelector("[data-id='vertices']"))
101 104
                .findElement(By.cssSelector("[data-id='" + vertexId + "']"));
......
115 118

  
116 119
        List<WebElement> highlightedVertices = browser.findElements(By.className("node--highlighted-archetype"));
117 120

  
118
        System.out.println("Number of highlighted vertices: " + highlightedVertices.size());
121
        logger.debug("Number of highlighted vertices: " + highlightedVertices.size());
119 122
        Assertions.assertEquals(expectedHighlightedVertexIds.size(), highlightedVertices.size());
120 123

  
121 124
        for(int i = 0; i < highlightedVertices.size(); i++) {
122 125
            String id = highlightedVertices.get(i).getAttribute("data-id");
123
            System.out.println(id);
126
            logger.debug(id);
124 127

  
125 128
            Assertions.assertEquals(expectedHighlightedVertexIds.get(i), id);
126 129
        }
sources/src/test/java/cz/zcu/kiv/imiger/tests/frontend/GroupStatsChangingTest.java
1 1
package cz.zcu.kiv.imiger.tests.frontend;
2 2

  
3
import org.apache.logging.log4j.LogManager;
4
import org.apache.logging.log4j.Logger;
3 5
import org.junit.jupiter.api.AfterAll;
4 6
import org.junit.jupiter.api.Assertions;
5 7
import org.junit.jupiter.api.BeforeAll;
......
11 13
import java.util.*;
12 14

  
13 15
class GroupStatsChangingTest {
16
    private static final Logger logger = LogManager.getLogger();
14 17
    private static WebDriver browser;
15 18

  
16 19
    @BeforeAll
......
29 32
                .findElement(By.cssSelector("[data-id='3']"));
30 33

  
31 34
        SeleniumUtil.svgRectClick(firstExcludedVertex);
32
        System.out.println("Exclude vertex3 to group as first vertex of group");
35
        logger.debug("Exclude vertex3 to group as first vertex of group");
33 36

  
34 37
        excludeToExistingGroup("2");
35
        System.out.println("Exclude vertex2 to group");
38
        logger.debug("Exclude vertex2 to group");
36 39

  
37 40
        //get data-id of fgroup
38 41
        groupId = browser.findElement(By.id("excludedNodeListComponent"))
......
46 49
//        EXCLUDING VERTICES FROM GROUPS IS NOT SUPPORTED YET
47 50
//        excludeToExistingGroup("1");
48 51
//        compareExpectedValues(groupId, new ArrayList<String>(Arrays.asList("2","2","0","2")));
49
//        System.out.println("Exclude vertex1 to group");
52
//        logger.debug("Exclude vertex1 to group");
50 53
//
51
//        System.out.println("Remove vertex2 to group");
54
//        logger.debug("Remove vertex2 to group");
52 55
//        removeVertexFromGroup("li2");
53 56
//        compareExpectedValues(groupId, new ArrayList<String>(Arrays.asList("1","2","0","2")));
54 57
//
55
//        System.out.println("Switch off stats for vertex1");
58
//        logger.debug("Switch off stats for vertex1");
56 59
//        toogleVertexInGroup("li1");
57 60
//        compareExpectedValues(groupId, new ArrayList<String>(Arrays.asList("1","0","0","0")));
58 61
//
59
//        System.out.println("Switch off stats for vertex3");
62
//        logger.debug("Switch off stats for vertex3");
60 63
//        toogleVertexInGroup("li3");
61 64
//        compareExpectedValues(groupId, new ArrayList<String>(Arrays.asList("0","0","0","0")));
62 65
//
63
//        System.out.println("Switch on stats for vertex1");
66
//        logger.debug("Switch on stats for vertex1");
64 67
//        toogleVertexInGroup("li3");
65 68
//        excludeToExistingGroup("vertex2");
66 69
//        compareExpectedValues(groupId, new ArrayList<String>(Arrays.asList("2","0","0","0")));
......
69 72
//        String archetypePrefix = "v_archetype_4_";
70 73
//        SeleniumUtil.switchToExcludeMode();
71 74
//        WebElement singleEcludedVertex = browser.findElement(By.id("vertex4"));
72
//        System.out.println("Exclude vertex4 to group as first vertex of group");
75
//        logger.debug("Exclude vertex4 to group as first vertex of group");
73 76
//        SeleniumUtil.svgClick(singleEcludedVertex);
74 77
//
75
//        System.out.println("Checking group statistics");
78
//        logger.debug("Checking group statistics");
76 79
//        String actualValue1 = browser.findElement(By.id(archetypePrefix + "0")).findElement(By.tagName("text")).getText();
77 80
//        String actualValue2 = browser.findElement(By.id(archetypePrefix + "2")).findElement(By.tagName("text")).getText();
78 81
//        Assertions.assertEquals(actualValue1, "2");
79 82
//        Assertions.assertEquals(actualValue2, "1");
80 83
//
81
//        System.out.println("Expected: 2 - Real: " + actualValue1);
82
//        System.out.println("Expected: 1 - Real: " + actualValue2);
84
//        logger.debug("Expected: 2 - Real: " + actualValue1);
85
//        logger.debug("Expected: 1 - Real: " + actualValue2);
83 86

  
84 87
    }
85 88

  
......
120 123
     * @param expectedValues list of expected values
121 124
     */
122 125
    private void compareExpectedValues(String groupId, Map<String, String> expectedValues){
123
        System.out.println("Checking group statistics");
126
        logger.debug("Checking group statistics");
124 127
        String archetypePrefix = "#vertexArchetypeIcon-";
125 128

  
126 129
        WebElement nodeList = browser.findElement(By.id("excludedNodeListComponent"))
sources/src/test/java/cz/zcu/kiv/imiger/tests/frontend/SeleniumUtil.java
1 1
package cz.zcu.kiv.imiger.tests.frontend;
2 2

  
3
import org.apache.logging.log4j.LogManager;
4
import org.apache.logging.log4j.Logger;
3 5
import org.openqa.selenium.By;
4 6
import org.openqa.selenium.WebDriver;
5 7
import org.openqa.selenium.WebElement;
......
13 15
import java.nio.file.Paths;
14 16

  
15 17
class SeleniumUtil {
16

  
18
    private static final Logger logger = LogManager.getLogger();
17 19
    private static final String TEST_DIRECTORY = System.getProperty("user.dir") + "\\src\\test\\resources";
18 20

  
19 21
    /**
......
49 51
        try {
50 52
            Thread.sleep(1000);
51 53
        } catch (InterruptedException e) {
52
            e.printStackTrace();
54
            logger.warn("Thread.sleep caused exception: ", e);
53 55
        }
54 56
    }
55 57

  
......
59 61
            Files.createLink(Paths.get(APP_CONFIG_LOCATION + "\\config.json"),
60 62
                    Paths.get(TEST_DIRECTORY + "\\config\\" + configFile));
61 63
        } catch (IOException e) {
62
            e.printStackTrace();
64
            logger.error("Can not prepare configuration file: ", e);
63 65
        }
64 66
    }
65 67

  
......
76 78
        try {
77 79
            Thread.sleep(1000);
78 80
        } catch (InterruptedException e) {
79
            e.printStackTrace();
81
            logger.warn("Thread.sleep caused exception: ", e);
80 82
        }
81 83
    }
82 84

  
......
86 88
        try {
87 89
            Thread.sleep(1000);
88 90
        } catch (InterruptedException e) {
89
            e.printStackTrace();
91
            logger.warn("Thread.sleep caused exception: ", e);
90 92
        }
91 93
    }
92 94

  
......
97 99
        try {
98 100
            Thread.sleep(1000);
99 101
        } catch (InterruptedException e) {
100
            e.printStackTrace();
102
            logger.warn("Thread.sleep caused exception: ", e);
101 103
        }
102 104
    }
103 105

  
......
112 114
        try {
113 115
            Thread.sleep(1000);
114 116
        } catch (InterruptedException e) {
115
            e.printStackTrace();
117
            logger.warn("Thread.sleep caused exception: ", e);
116 118
        }
117 119
    }
118 120

  
......
127 129
        try {
128 130
            Thread.sleep(1000);
129 131
        } catch (InterruptedException e) {
130
            e.printStackTrace();
132
            logger.warn("Thread.sleep caused exception: ", e);
131 133
        }
132 134
    }
133 135

  

Také k dispozici: Unified diff