Projekt

Obecné

Profil

« Předchozí | Další » 

Revize c5111d82

Přidáno uživatelem Petr Urban před téměř 3 roky(ů)

#26 Adding logging mechanism

Zobrazit rozdíly:

src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/controller/AppController.java
56 56
    private ConfigurationService configurationService;
57 57

  
58 58
    /**
59
     *  This method is called by the GET method and initializes
60
     *  the main page of the application (index). Loads all projects
61
     *  stored in the db and all implemented AP.
59
     * This method is called by the GET method and initializes
60
     * the main page of the application (index). Loads all projects
61
     * stored in the db and all implemented AP.
62 62
     *
63 63
     * @param model object for passing data to the UI
64 64
     * @return html file name for thymeleaf template
......
66 66
    @GetMapping("/")
67 67
    public String index(Model model) {
68 68
        model.addAttribute("query", new Query(projectService.getAllProjects(), antiPatternService.antiPatternsToModel(antiPatternService.getAllAntiPatterns())));
69
        LOGGER.info("@GetMapping(\"/\") - Accessing main page");
69 70
        return "index";
70 71
    }
71 72

  
72 73
    /**
73
     *  Method for obtaining project by ID.
74
     * Method for obtaining project by ID.
74 75
     *
75
     * @param id project ID
76
     * @param id    project ID
76 77
     * @param model object for passing data to the UI
77 78
     * @return html file name for thymeleaf template
78 79
     */
......
80 81
    public String getProjectById(@PathVariable Long id, Model model) {
81 82
        model.addAttribute("query", new Query(projectService.getAllProjects(), antiPatternService.antiPatternsToModel(antiPatternService.getAllAntiPatterns())));
82 83
        model.addAttribute("project", projectService.getProjectById(id));
84
        LOGGER.info("@GetMapping(\"projects/" + id + ")");
83 85
        return "project";
84 86
    }
85 87

  
86 88
    /**
87 89
     * Method for obtaining all AP.
90
     *
88 91
     * @return list of AP
89 92
     */
90 93
    @GetMapping("/anti-patterns")
91
    public @ResponseBody List<AntiPattern> getAllAntiPatterns(Model model) {
94
    public @ResponseBody
95
    List<AntiPattern> getAllAntiPatterns(Model model) {
92 96
        model.addAttribute("query", new Query(projectService.getAllProjects(), antiPatternService.antiPatternsToModel(antiPatternService.getAllAntiPatterns())));
97
        LOGGER.info("GetMapping(\"/anti-patterns\") and obtaining all APs.");
93 98
        return antiPatternService.antiPatternsToModel(antiPatternService.getAllAntiPatterns());
94 99
    }
95 100

  
96 101
    /**
97 102
     * Method for obtaining AP by ID.
98 103
     *
99
     * @param id AP ID
104
     * @param id    AP ID
100 105
     * @param model object for passing data to the UI
101 106
     * @return html file name for thymeleaf template
102 107
     */
......
108 113
        model.addAttribute("description", antiPatternService.getDescriptionFromCatalogue(id));
109 114
        model.addAttribute("operationalizationText", antiPatternService.getOperationalizationText(antiPatternService.getAntiPatternById(id).getAntiPatternModel().getName()));
110 115
        model.addAttribute("configurations", configurationService.getConfigurationByName(currentConfigurationName));
116
        LOGGER.info("GetMapping(\"/anti-patterns/ " + id + ") and obtaining AP by ID");
111 117
        return "anti-pattern";
112 118
    }
113 119

  
114 120
    /**
115 121
     * Method that processes requirements for analyzing selected projects and AP.
116 122
     *
117
     * @param model object for passing data to the UI
118
     * @param selectedProjects selected project to analyze
123
     * @param model                object for passing data to the UI
124
     * @param selectedProjects     selected project to analyze
119 125
     * @param selectedAntiPatterns selected AP to analyze
120 126
     * @return html file name for thymeleaf template
121 127
     */
......
130 136
            model.addAttribute("errorMessage", "No project selected." +
131 137
                    " Select at least one project.");
132 138
            model.addAttribute("query", new Query(projectService.getAllProjects(), antiPatternService.antiPatternsToModel(antiPatternService.getAllAntiPatterns())));
139
            LOGGER.warn("@PostMapping(\"/analyze\") - Processing requirements for analyzing selected projects and AP with an error. " +
140
                    "selectedProjects are null!");
133 141
            return "index";
134 142
        }
135 143

  
......
137 145
            model.addAttribute("errorMessage", "No anti-pattern selected." +
138 146
                    " Select at least one anti-pattern.");
139 147
            model.addAttribute("query", new Query(projectService.getAllProjects(), antiPatternService.antiPatternsToModel(antiPatternService.getAllAntiPatterns())));
148
            LOGGER.warn("@PostMapping(\"/analyze\") - Processing requirements for analyzing selected projects and AP with an error. " +
149
                    "selectedAntiPatterns are null!");
140 150
            return "index";
141 151
        }
142 152

  
......
152 162
        model.addAttribute("queryResults", results);
153 163
        model.addAttribute("recalculationTime", DateTimeFormatter.ofPattern("HH:mm:ss").format(LocalTime.now()));
154 164

  
165

  
166
        LOGGER.info("@PostMapping(\"/analyze\") - Processing SUCCESSFULLY requirements for analyzing selected projects and AP.");
155 167
        return "result";
156 168
    }
157 169

  
......
172 184
        model.addAttribute("queryResults", antiPatternService.getResults());
173 185
        model.addAttribute("recalculationTime", DateTimeFormatter.ofPattern("HH:mm:ss").format(LocalTime.now()));
174 186

  
187
        LOGGER.info("@GetMapping(\"/analyze\") - ??");
175 188
        return "result";
176 189
    }
177 190

  
......
183 196
    @GetMapping("/about")
184 197
    public String about(Model model) {
185 198
        model.addAttribute("query", new Query(projectService.getAllProjects(), antiPatternService.antiPatternsToModel(antiPatternService.getAllAntiPatterns())));
199
        LOGGER.info("@GetMapping(\"/about\") - Accessing about page");
186 200
        return "about";
187 201
    }
188 202

  
......
205 219
    /**
206 220
     * Method of saving changes of current configuration
207 221
     *
208
     * @param model object for passing data to the UI
222
     * @param model           object for passing data to the UI
209 223
     * @param thresholdValues changed configuration values
210
     * @param thresholdNames changed configuration names
224
     * @param thresholdNames  changed configuration names
211 225
     * @return html file name for thymeleaf template
212 226
     */
213 227
    @PostMapping(value = "/configuration", params = "configuration-save-button")
214 228
    public String configurationSavePost(Model model,
215
                                    @RequestParam(value = "thresholdValues", required = false) String[] thresholdValues,
216
                                    @RequestParam(value = "thresholdNames", required = false) String[] thresholdNames,
217
                                    @RequestParam(value = "antiPatternNames", required = false) String[] antiPatternNames,
218
                                    HttpSession session, RedirectAttributes redirectAttributes) {
229
                                        @RequestParam(value = "thresholdValues", required = false) String[] thresholdValues,
230
                                        @RequestParam(value = "thresholdNames", required = false) String[] thresholdNames,
231
                                        @RequestParam(value = "antiPatternNames", required = false) String[] antiPatternNames,
232
                                        HttpSession session, RedirectAttributes redirectAttributes) {
219 233

  
220 234
        String currentConfigurationName = configurationGetFromSession(session);
221 235

  
......
225 239

  
226 240
        if (wrongParameters.isEmpty()) {
227 241
            model.addAttribute("successMessage", "All configuration values have been successfully saved.");
242
            LOGGER.info("@PostMapping(value = \"/configuration\", params = \"configuration-save-button\") - " +
243
                    "input parameters were successfully processed...");
228 244
        } else {
229 245
            model.addAttribute("errorMessage", "One or more configuration values are not in correct format, see messages below.");
230 246
            antiPatternService.setErrorMessages(query.getAntiPatterns(), wrongParameters);
247
            LOGGER.warn("@PostMapping(value = \"/configuration\", params = \"configuration-save-button\") ended with an error!" +
248
                    "Some parameters seem to be wrong!");
231 249
        }
232 250

  
233 251
        model.addAttribute("query", query);
234 252

  
235 253
        model.addAttribute("configurations", configurationService.getConfigurationByName(currentConfigurationName));
254
        LOGGER.info("@PostMapping(value = \"/configuration\", params = \"configuration-save-button\") - Save Button was pressed");
236 255
        return "configuration";
237 256
    }
238 257

  
239 258
    /**
240 259
     * Method for saving full new configuration
241 260
     *
242
     * @param model object for passing data to the UI
261
     * @param model           object for passing data to the UI
243 262
     * @param thresholdValues changed configuration values
244
     * @param thresholdNames changed configuration names
263
     * @param thresholdNames  changed configuration names
245 264
     * @return html file name for thymeleaf template
246 265
     */
247 266
    @PostMapping(value = "/configuration", params = "configuration-save-as-button")
248 267
    public String configurationSaveAsPost(Model model,
249
                                    @RequestParam(value = "thresholdValues", required = false) String[] thresholdValues,
250
                                    @RequestParam(value = "thresholdNames", required = false) String[] thresholdNames,
251
                                    @RequestParam(value = "antiPatternNames", required = false) String[] antiPatternNames,
252
                                    @RequestParam(value = "configuration-save-as-input", required = false) String newConfigName,
253
                                    HttpSession session, RedirectAttributes redirectAttributes) {
268
                                          @RequestParam(value = "thresholdValues", required = false) String[] thresholdValues,
269
                                          @RequestParam(value = "thresholdNames", required = false) String[] thresholdNames,
270
                                          @RequestParam(value = "antiPatternNames", required = false) String[] antiPatternNames,
271
                                          @RequestParam(value = "configuration-save-as-input", required = false) String newConfigName,
272
                                          HttpSession session, RedirectAttributes redirectAttributes) {
254 273

  
255 274
        Query query = new Query(projectService.getAllProjects(), antiPatternService.antiPatternsToModel(antiPatternService.getAllAntiPatterns()));
256 275
        String currentConfigurationName = configurationGetFromSession(session);
257 276

  
258 277
        List<String> allConfigurationNames = configurationService.getAllConfigurationNames();
259
        if (newConfigName == null || newConfigName.length() == 0 ||  allConfigurationNames.contains(newConfigName)) {
278
        if (newConfigName == null || newConfigName.length() == 0 || allConfigurationNames.contains(newConfigName)) {
260 279
            model.addAttribute("configurations", configurationService.getConfigurationByName(currentConfigurationName));
261 280
            model.addAttribute("errorMessage", "Configuration name is not possible.");
281
            LOGGER.error("@PostMapping(value = \"/configuration\", params = \"configuration-save-as-button\") - " +
282
                    "new configuration could not be saved because the name was not entered!");
262 283
            return "configuration";
263 284
        }
264 285

  
......
268 289
            model.addAttribute("successMessage", "New configuration has been successfully saved.");
269 290
            session.setAttribute("configuration", newConfigName);
270 291
            model.addAttribute("configurations", configurationService.getConfigurationByName(newConfigName));
292
            LOGGER.warn("@PostMapping(value = \"/configuration\", params = \"configuration-save-as-button\") - " +
293
                    "some parameters seem to be wrong!");
271 294
        } else {
272 295
            model.addAttribute("errorMessage", "One or more configuration values are not in correct format, see messages below.");
273 296
            antiPatternService.setErrorMessages(query.getAntiPatterns(), wrongParameters);
274 297
            model.addAttribute("configurations", configurationService.getConfigurationByName(currentConfigurationName));
298
            LOGGER.info("@PostMapping(value = \"/configuration\", params = \"configuration-save-as-button\") - " +
299
                    "parameters were successfully processed...");
275 300
        }
276 301

  
277 302
        model.addAttribute("query", query);
......
279 304
        model.addAttribute("configurationList", configurationsGetList(session));
280 305
        model.addAttribute("selectedConfiguration", session.getAttribute("configuration"));
281 306

  
307
        LOGGER.info("@PostMapping(value = \"/configuration\", params = \"configuration-save-as-button\") - " +
308
                "everything successfully processed... Returning configuration.html");
282 309
        return "configuration";
283 310
    }
284 311

  
285 312
    /**
286 313
     * Method for saving changes of one AP in current configuration
287 314
     *
288
     * @param model object for passing data to the UI
289
     * @param id id of AP
315
     * @param model           object for passing data to the UI
316
     * @param id              id of AP
290 317
     * @param thresholdValues new config values
291
     * @param thresholdNames configuration names
292
     * @param redirectAttrs attributes for redirection
318
     * @param thresholdNames  configuration names
319
     * @param redirectAttrs   attributes for redirection
293 320
     * @return redirected html file name for thymeleaf template
294 321
     */
295 322
    @PostMapping("/anti-patterns/{id}")
......
305 332
        List<AntiPattern> antiPatterns = antiPatternService.antiPatternsToModel(antiPatternService.getAllAntiPatterns());
306 333

  
307 334
        AntiPattern antiPattern = antiPatternService.antiPatternToModel(antiPatternService.getAntiPatternById(id));
308
        List<String> wrongParameters = configurationService.saveNewConfiguration(antiPatterns, currentConfigurationName,antiPatternNames, thresholdNames, thresholdValues, false);
335
        List<String> wrongParameters = configurationService.saveNewConfiguration(antiPatterns, currentConfigurationName, antiPatternNames, thresholdNames, thresholdValues, false);
309 336

  
310 337

  
311 338
        if (wrongParameters.isEmpty()) {
312 339
            redirectAttrs.addFlashAttribute("successMessage", "All threshold values has been successfully saved.");
340
            LOGGER.info("@PostMapping(\"/anti-patterns/{id}\") - Success");
313 341
        } else {
314 342
            redirectAttrs.addFlashAttribute("errorMessage", "One or more configuration values are not in correct format, see messages below.");
315 343
            antiPatternService.setErrorMessages(antiPattern, wrongParameters);
344
            LOGGER.warn("@PostMapping(\"/anti-patterns/{id}\") - Some parameters seem to be wrong!");
316 345
        }
317 346

  
318 347
        model.addAttribute("antiPatterns", antiPattern);
319 348
        model.addAttribute("configurations", configurationService.getConfigurationByName(currentConfigurationName));
349

  
350
        LOGGER.info("@PostMapping(\"/anti-patterns/{id}\") - redirecting to current anti pattern id");
320 351
        return "redirect:/anti-patterns/{id}";
321 352
    }
322 353

  
323 354
    /**
324 355
     * Method for storing operationalization detail for individual AP
325 356
     *
326
     * @param model object for passing data to the UI
327
     * @param id id of AP
328
     * @param innerText operationalization text (HTML)
357
     * @param model         object for passing data to the UI
358
     * @param id            id of AP
359
     * @param innerText     operationalization text (HTML)
329 360
     * @param redirectAttrs attributes for redirection
330 361
     * @return redirected html file name for thymeleaf template
331 362
     */
......
345 376
            writer.close();
346 377
            redirectAttrs.addFlashAttribute("successMessage", "Operationalization detail has been successfully saved.");
347 378
        } catch (Exception e) {
379
            LOGGER.error("@PostMapping(\"/anti-patterns/{id}/operationalization\") - " +
380
                    "An error has occurred while trying to create new BufferedWriter or FileWriter!");
348 381
        }
349 382
        return "redirect:/anti-patterns/{id}";
350 383
    }
......
357 390
     * @throws Exception If image is not in the folder
358 391
     */
359 392
    @GetMapping("/operationalizations/images/{imageName}")
360
    public @ResponseBody byte[] imageGet(@PathVariable String imageName) throws Exception {
393
    public @ResponseBody
394
    byte[] imageGet(@PathVariable String imageName) throws Exception {
361 395
        File f = new File(antiPatternService.getOperationalizationImageFilePath(imageName));
362 396
        return Files.readAllBytes(f.toPath());
363 397
    }
......
369 403
     * @return result
370 404
     */
371 405
    @PostMapping("/uploadImage")
372
    public ResponseEntity<?> handleFileUpload(@RequestParam("file") MultipartFile file ) {
406
    public ResponseEntity<?> handleFileUpload(@RequestParam("file") MultipartFile file) {
373 407

  
374 408
        String fileName = file.getOriginalFilename();
375 409

  
376
        if(new File(antiPatternService.getOperationalizationImageFilePath(fileName)).isFile()){
410
        if (new File(antiPatternService.getOperationalizationImageFilePath(fileName)).isFile()) {
377 411
            return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
378 412
        }
379 413

  
380 414
        try {
381 415
            file.transferTo(new File(antiPatternService.getOperationalizationImageFilePath(fileName)));
382 416
        } catch (Exception e) {
417
            LOGGER.error("An error with uploading images has occurred!");
383 418
            return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
384 419
        }
385 420
        return ResponseEntity.ok("File uploaded successfully.");
......
391 426
     * @return html file name for thymeleaf template
392 427
     */
393 428
    @GetMapping("/login")
394
    public String login(Model model){
429
    public String login(Model model) {
395 430
        model.addAttribute("query", new Query(projectService.getAllProjects(), antiPatternService.antiPatternsToModel(antiPatternService.getAllAntiPatterns())));
396 431
        return "login";
397 432
    }
398 433

  
399 434
    /**
400 435
     * Processing login details
401
     * @param session current session
402
     * @param nameInput input field for name
403
     * @param passInput input field for password
436
     *
437
     * @param session       current session
438
     * @param nameInput     input field for name
439
     * @param passInput     input field for password
404 440
     * @param redirectAttrs redirect attributes for adding flash message
405 441
     * @return html file name for thymeleaf template
406 442
     */
......
410 446
                               @RequestParam(value = "passInput", required = false) String passInput,
411 447
                               RedirectAttributes redirectAttrs) {
412 448

  
413
        if(userAccountService.checkCredentials(nameInput, passInput)){
449
        if (userAccountService.checkCredentials(nameInput, passInput)) {
414 450
            session.setAttribute("user", nameInput);
415 451
            return "redirect:/";
416 452
        }
......
421 457

  
422 458
    /**
423 459
     * Getting the name of the logged user from the session
424
     * @param model object for passing data to the UI
460
     *
461
     * @param model   object for passing data to the UI
425 462
     * @param session current session
426 463
     * @return html file name for thymeleaf template
427 464
     */
428 465
    @GetMapping("/userLogged")
429
    public String userLogged(Model model, HttpSession session){
466
    public String userLogged(Model model, HttpSession session) {
430 467
        String user = (String) session.getAttribute("user");
431 468
        model.addAttribute("user", user);
432 469
        return "redirect:/";
......
434 471

  
435 472
    /**
436 473
     * Processing logout, removing user from session
437
     * @param model object for passing data to the UI
474
     *
475
     * @param model   object for passing data to the UI
438 476
     * @param session current session
439 477
     * @return html file name for thymeleaf template
440 478
     */
441 479
    @GetMapping("/logout")
442
    public String userLogout(Model model, HttpSession session, RedirectAttributes redirectAttrs){
480
    public String userLogout(Model model, HttpSession session, RedirectAttributes redirectAttrs) {
443 481
        session.removeAttribute("user");
444 482
        session.removeAttribute("configuration");
445 483
        return "redirect:/";
......
447 485

  
448 486
    /**
449 487
     * Model attribute for getting list of configurations
488
     *
450 489
     * @param session current session
451 490
     * @return list of configurations
452 491
     */
453 492
    @ModelAttribute("configurationList")
454
    public List<String> configurationsGetList(HttpSession session){
493
    public List<String> configurationsGetList(HttpSession session) {
455 494
        List<String> configurationList;
456 495

  
457
        if(session.getAttribute("user") != null)
496
        if (session.getAttribute("user") != null)
458 497
            configurationList = configurationService.getAllConfigurationNames();
459 498
        else
460 499
            configurationList = configurationService.getDefaultConfigurationNames();
......
464 503

  
465 504
    /**
466 505
     * Model attribute for getting current configuration
506
     *
467 507
     * @param session current session
468 508
     * @return name of current configuration
469 509
     */
470 510
    @ModelAttribute("selectedConfiguration")
471
    public String configurationGetFromSession(HttpSession session){
472
        if(session.getAttribute("configuration") != null)
511
    public String configurationGetFromSession(HttpSession session) {
512
        if (session.getAttribute("configuration") != null)
473 513
            return session.getAttribute("configuration").toString(); // return configuration stored in session
474
        else{
514
        else {
475 515
            List<String> configurationList = configurationService.getDefaultConfigurationNames();
476
            if(configurationList.size() == 0)
516
            if (configurationList.size() == 0)
477 517
                return null;
478 518

  
479 519
            return configurationList.get(0); // return first item from the list of default configurations
......
482 522

  
483 523
    /**
484 524
     * Processing select of configuration from select box
485
     * @param session current session
525
     *
526
     * @param session            current session
486 527
     * @param selectedConfigName name of selected configuration
487
     * @param redirectAttrs attributes for redirection
528
     * @param redirectAttrs      attributes for redirection
488 529
     * @return html page for redirect
489 530
     */
490 531
    @PostMapping("/setSelectedConfiguration")
491 532
    public String setSelectedConfiguration(HttpSession session,
492 533
                                           @RequestParam(value = "current-configuration-select", required = false) String selectedConfigName,
493
                                           RedirectAttributes redirectAttrs){
534
                                           RedirectAttributes redirectAttrs) {
494 535

  
495 536
        session.setAttribute("configuration", selectedConfigName); // storing selected configuration to session
496 537

  
......
499 540

  
500 541
    /**
501 542
     * Checking if configuration is default and editable by user
502
     * @param model object for passing data to the UI
503
     * @param session current session
543
     *
544
     * @param model             object for passing data to the UI
545
     * @param session           current session
504 546
     * @param configurationName name of the curren configuration
505 547
     * @return html template
506 548
     */
507 549
    @GetMapping("/isConfigEditable/{configurationName}")
508
    public String isConfigEditableForUser(Model model, HttpSession session, @PathVariable String configurationName){
509
       List<String> defaultConfigurationNames = configurationService.getDefaultConfigurationNames();
550
    public String isConfigEditableForUser(Model model, HttpSession session, @PathVariable String configurationName) {
551
        List<String> defaultConfigurationNames = configurationService.getDefaultConfigurationNames();
510 552

  
511
        for(int i = 0; i < defaultConfigurationNames.size(); i++){
512
            if(defaultConfigurationNames.get(i).equals(configurationName))
553
        for (int i = 0; i < defaultConfigurationNames.size(); i++) {
554
            if (defaultConfigurationNames.get(i).equals(configurationName))
513 555
                model.addAttribute("default", "true"); // configuration is default
514 556
        }
515 557

  
src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/detecting/DatabaseConnection.java
4 4
import cz.zcu.fav.kiv.antipatterndetectionapp.spring.ApplicationProperties;
5 5
import cz.zcu.fav.kiv.antipatterndetectionapp.spring.SpringApplicationContext;
6 6
import cz.zcu.fav.kiv.antipatterndetectionapp.utils.Utils;
7
import org.slf4j.Logger;
8
import org.slf4j.LoggerFactory;
7 9

  
8 10
import java.sql.*;
9 11
import java.util.ArrayList;
......
14 16
 * A class that takes care of database connections and running queries.
15 17
 */
16 18
public class DatabaseConnection {
19
    private final Logger LOGGER = LoggerFactory.getLogger(DatabaseConnection.class);
17 20

  
18 21
    private Connection databaseConnection;
19 22

  
......
45 48

  
46 49
        } catch (SQLException e) {
47 50
            e.printStackTrace();
51
            LOGGER.error("Connection with DB could not be created");
48 52
        }
49 53
        return conn;
50 54
    }
......
58 62
        try {
59 63
            this.databaseConnection.close();
60 64
        } catch (SQLException e) {
65
            LOGGER.error("Connection to DB could not be closed!");
61 66
            e.printStackTrace();
62 67
        }
63 68
    }
......
96 101

  
97 102
            }
98 103
        } catch (SQLException e) {
104
            LOGGER.error("DB query could not be performed!");
99 105
            e.printStackTrace();
100 106
        }
101 107
        return resultSet;
......
129 135

  
130 136
            }
131 137
        } catch (SQLException e) {
138
            LOGGER.error("DB query with multiple results could not be performed!");
132 139
            e.printStackTrace();
133 140
        }
134 141

  
src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/model/types/Percentage.java
1 1
package cz.zcu.fav.kiv.antipatterndetectionapp.model.types;
2 2

  
3
import org.slf4j.Logger;
4
import org.slf4j.LoggerFactory;
5

  
3 6
/**
4 7
 * This class represents percentage as a positive float number between 0 an 100.
5 8
 */
......
10 13

  
11 14
    private final float value;
12 15

  
16
    private final Logger LOGGER = LoggerFactory.getLogger(Percentage.class);
17

  
13 18
    public Percentage(float value) throws NumberFormatException {
14 19
        if (value > MAX_VALUE || value < MIN_VALUE) {
20
            LOGGER.error("Invalid number entered!");
15 21
            throw new NumberFormatException("Percentage should be between 0 and 100");
16 22
        }
17 23
        this.value = value;
src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/model/types/PositiveFloat.java
1 1
package cz.zcu.fav.kiv.antipatterndetectionapp.model.types;
2 2

  
3
import org.slf4j.Logger;
4
import org.slf4j.LoggerFactory;
5

  
3 6
/**
4 7
 * This class represents percentage as a positive float number between 0 and MAX_FLOAT.
5 8
 */
......
9 12

  
10 13
    private final float value;
11 14

  
15
    private final Logger LOGGER = LoggerFactory.getLogger(Percentage.class);
16

  
12 17
    public PositiveFloat(float value) throws NumberFormatException {
13 18
        if (value > MAX_VALUE || value < MIN_VALUE) {
19
            LOGGER.error("Invalid number entered!");
14 20
            throw new NumberFormatException("Positive integer should be between 0 and infinity");
15 21
        }
16 22
        this.value = value;
src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/model/types/PositiveInteger.java
1 1
package cz.zcu.fav.kiv.antipatterndetectionapp.model.types;
2 2

  
3
import org.slf4j.Logger;
4
import org.slf4j.LoggerFactory;
5

  
3 6
/**
4 7
 * This class represents percentage as a positive int number between 0 and MAX_INT.
5 8
 */
......
10 13

  
11 14
    private final int value;
12 15

  
16
    private final Logger LOGGER = LoggerFactory.getLogger(PositiveInteger.class);
17

  
13 18
    public PositiveInteger(int value) throws NumberFormatException {
14 19
        if (value > MAX_VALUE || value < MIN_VALUE) {
20
            LOGGER.error("Invalid number entered!");
15 21
            throw new NumberFormatException("Positive integer should be between 0 and infinity");
16 22
        }
17 23
        this.value = value;
src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/repository/AntiPatternRepository.java
182 182
            APCatalogueFileName = node.get("catalogueFileName") != null ? node.get("catalogueFileName").asText() : null; // optional field
183 183
        }
184 184
        catch(Exception e){
185
            LOGGER.error(e.getMessage());
185 186
            return null;
186 187
        }
187 188

  
......
202 203
                thresholdErrorMess = tmpNode.get("thresholdErrorMess").asText();
203 204
            }
204 205
            catch(Exception e){
206
                LOGGER.error(e.getMessage());
205 207
                return null;
206 208
            }
207 209

  
......
260 262
        try {
261 263
            return new FileSystemResource(OPERATIONALIZATION_DIR).getFile().getAbsolutePath();
262 264
        } catch (Exception e) {
265
            LOGGER.error(e.getMessage());
263 266
            e.printStackTrace();
264 267
        }
265 268
        return null;
......
269 272
        try {
270 273
            return new FileSystemResource(OPERATIONALIZATION_IMG_DIR).getFile().getAbsolutePath();
271 274
        } catch (Exception e) {
275
            LOGGER.error(e.getMessage());
272 276
            e.printStackTrace();
273 277
        }
274 278
        return null;
src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/repository/ConfigurationRepository.java
66 66
                }
67 67
            }
68 68
            catch(Exception e){
69
                LOGGER.error("Cannot read configuration from file " + fileEntry.getName());
69
                LOGGER.error("Cannot read configuration from file " + fileEntry.getName(), e);
70 70
                continue;
71 71
            }
72 72

  
......
183 183
                        }
184 184
                        catch(NumberFormatException e){
185 185
                            incorrectParameters.add(thresholdNames[i]);
186
                            LOGGER.error(e.getMessage());
186 187
                        }
187 188
                    }
188 189
                    else if(antiPattern.getThresholds().get(thresholdNames[i]).getType().equals("Percentage")){
......
191 192
                        }
192 193
                        catch(NumberFormatException e){
193 194
                            incorrectParameters.add(thresholdNames[i]);
195
                            LOGGER.error(e.getMessage());
194 196
                        }
195 197
                    }
196 198
                    else if(antiPattern.getThresholds().get(thresholdNames[i]).getType().equals("PositiveInteger")){
......
199 201
                        }
200 202
                        catch(NumberFormatException e){
201 203
                            incorrectParameters.add(thresholdNames[i]);
204
                            LOGGER.error(e.getMessage());
202 205
                        }
203 206
                    }
204 207
                    else if(antiPattern.getThresholds().get(thresholdNames[i]).getType().equals("PositiveFloat")){
......
207 210
                        }
208 211
                        catch(NumberFormatException e){
209 212
                            incorrectParameters.add(thresholdNames[i]);
213
                            LOGGER.error(e.getMessage());
210 214
                        }
211 215
                    }
212 216
                    else if(antiPattern.getThresholds().get(thresholdNames[i]).getType().equals("Float")){
......
215 219
                        }
216 220
                        catch(NumberFormatException e){
217 221
                            incorrectParameters.add(thresholdNames[i]);
222
                            LOGGER.error(e.getMessage());
218 223
                        }
219 224
                    }
220 225
                    else if(antiPattern.getThresholds().get(thresholdNames[i]).getType().equals("Double")){
......
223 228
                        }
224 229
                        catch(NumberFormatException e){
225 230
                            incorrectParameters.add(thresholdNames[i]);
231
                            LOGGER.error(e.getMessage());
226 232
                        }
227 233
                    }
228 234
                    else if(antiPattern.getThresholds().get(thresholdNames[i]).getType().equals("String")){
src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/service/AntiPatternServiceImpl.java
8 8
import cz.zcu.fav.kiv.antipatterndetectionapp.model.QueryResult;
9 9
import cz.zcu.fav.kiv.antipatterndetectionapp.repository.AntiPatternRepository;
10 10
import org.jsoup.Jsoup;
11
import org.slf4j.Logger;
12
import org.slf4j.LoggerFactory;
11 13
import org.springframework.beans.factory.annotation.Autowired;
12 14
import org.springframework.stereotype.Service;
13 15

  
......
19 21

  
20 22
@Service
21 23
public class AntiPatternServiceImpl implements AntiPatternService {
24
    private final Logger LOGGER = LoggerFactory.getLogger(AntiPatternServiceImpl.class);
22 25

  
23 26
    @Autowired
24 27
    private AntiPatternRepository antiPatternRepository;
......
141 144
        }
142 145
        catch (Exception e){
143 146
            /* If html from catalogue is not extracted, the description from anti-pattern configuration is returned */
147
            LOGGER.error(e.getMessage());
144 148
            return ap.getDescription();
145 149
        }
146 150

  
......
175 179
        try {
176 180
            content = new String (Files.readAllBytes(Paths.get(filePath)));
177 181
        } catch (IOException e) {
182
            LOGGER.error(e.getMessage());
178 183
            e.printStackTrace();
179 184
        }
180 185
        return content;
src/main/resources/application.properties
12 12

  
13 13
# admin account password:
14 14
account.user.password=
15

  
16
# logger
17
logging.level.root=INFO
18
logging.level.cz.zcu.fav.kiv.antipatterndetectionapp=TRACE
src/main/resources/logback.xml
1
<?xml version="1.0" encoding="UTF-8" ?>
2
<configuration>
3

  
4
    <property name="LOGS" value="./logs" />
5

  
6
    <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
7
        <encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
8
            <pattern>%d{HH:mm:ss.SSS} %-5level %logger{36} - %msg%n</pattern>
9
        </encoder>
10
    </appender>
11

  
12
    <appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
13
        <file>${LOGS}/appController.log</file>
14

  
15
        <encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
16
            <pattern>%-30(%d{HH:mm:ss} [%thread]) %-5level %logger{10} [%file:%line] %msg%n</pattern>
17
        </encoder>
18

  
19
        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
20
            <fileNamePattern>
21
                ${LOGS}/archived/appController-%d{yyyy-MM-dd}.%i.log
22
            </fileNamePattern>
23
            <timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
24
                <maxFileSize>1MB</maxFileSize>
25
            </timeBasedFileNamingAndTriggeringPolicy>
26
        </rollingPolicy>
27
    </appender>
28

  
29
    <root level="info">
30
        <appender-ref ref="STDOUT" />
31
    </root>
32

  
33
    <logger name="cz.zcu.fav.kiv.antipatterndetectionapp" level="INFO" additivity="false">
34
        <appender-ref ref="FILE" />
35
        <appender-ref ref="STDOUT" />
36
    </logger>
37

  
38
</configuration>

Také k dispozici: Unified diff