commit 345955a56ed3f70c8bb283615f5ee0d2ceb83a18
Author: stepanekp <1stepanekpetr@gmail.com>
Date:   Fri Apr 1 23:27:41 2022 +0200

    #14 Loading configuration from json edit

diff --git a/src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/repository/ConfigurationRepository.java b/src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/repository/ConfigurationRepository.java
index a80e8bd..3ad5279 100644
--- a/src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/repository/ConfigurationRepository.java
+++ b/src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/repository/ConfigurationRepository.java
@@ -8,9 +8,8 @@ import org.springframework.stereotype.Component;
 import org.springframework.web.context.ServletContextAware;
 
 import javax.servlet.ServletContext;
-import java.io.File;
+import java.io.*;
 import java.net.URL;
-import java.nio.file.Files;
 import java.util.HashMap;
 import java.util.Map;
 
@@ -34,59 +33,78 @@ public class ConfigurationRepository implements ServletContextAware {
     private void loadConfigurations(){
         LOGGER.info("-------START READING CONFIGURATIONS FROM FILES-------");
         Map<String, Map<String, Map<String, String>>> configurations = new HashMap<>();
+
+        File folder = null;
+
         try {
             URL url = servletContext.getResource(CONFIGURATION_DIR);
-            File folder = new File(url.getFile());
+            folder = new File(url.getFile());
+        } catch (Exception e) {
+            e.printStackTrace();
+            LOGGER.error("Cannot access folder with configurations " + CONFIGURATION_DIR);
+        }
 
+        for (final File fileEntry : folder.listFiles()) {
+            LOGGER.info("Reading configuration from file " + fileEntry.getName());
 
+            String json = "";   // json configuration file
+            try {
+                BufferedReader read = new BufferedReader(new InputStreamReader(fileEntry.toURI().toURL().openStream()));
 
-            for (final File fileEntry : folder.listFiles()) {
-                LOGGER.info("Reading configuration from file " + fileEntry.getName());
-                String json = "";   // json configuration file
-                JsonNode node = null;
-                try {
-                    json = new String(Files.readAllBytes(fileEntry.toPath()));
-                    node = JsonParser.parse(json);
-                } catch (Exception e) {
-                    e.printStackTrace();
+                String line;
+                while ((line = read.readLine()) != null) {
+                    json += line;
                 }
+            }
+            catch(Exception e){
+                e.printStackTrace();
+                LOGGER.error("Cannot read configuration from file " + fileEntry.getName());
+                continue;
+            }
 
+            JsonNode node = null;
+            try {
+                node = JsonParser.parse(json);
+            } catch (IOException e) {
+                e.printStackTrace();
+                LOGGER.error("Cannot parse configuration from file " + fileEntry.getName());
+                continue;
+            }
 
-                String configurationName = fileEntry.getName().split("\\.")[0];
+            String configurationName = fileEntry.getName().split("\\.")[0];
 
-                JsonNode arrayOfConfigurations = node.get("configuration");
+            JsonNode arrayOfConfigurations = node.get("configuration");
 
-                Map<String, Map<String, String>> newAntiPatternMap = new HashMap<>();
+            if(arrayOfConfigurations == null)
+                continue;
 
-                for (int i = 0; i < arrayOfConfigurations.size(); i++) {
+            Map<String, Map<String, String>> newAntiPatternMap = new HashMap<>();
 
-                    JsonNode antiPatternNode = arrayOfConfigurations.get(i);
+            for (int i = 0; i < arrayOfConfigurations.size(); i++) {
 
-                    String antiPatternName = antiPatternNode.get("antiPattern").asText();
+                JsonNode antiPatternNode = arrayOfConfigurations.get(i);
 
-                    JsonNode arrayOfThresholds = antiPatternNode.get("thresholds");
+                String antiPatternName = antiPatternNode.get("antiPattern").asText();
 
-                    Map<String, String> newThresholds = new HashMap<String, String>();
+                JsonNode arrayOfThresholds = antiPatternNode.get("thresholds");
 
-                    for (int j = 0; j < arrayOfThresholds.size(); j++) {
-                        JsonNode thresholdNode = arrayOfThresholds.get(j);
+                Map<String, String> newThresholds = new HashMap<String, String>();
 
-                        String thresholdName = thresholdNode.get("thresholdName").asText();
-                        String value = thresholdNode.get("value").asText();
+                for (int j = 0; j < arrayOfThresholds.size(); j++) {
+                    JsonNode thresholdNode = arrayOfThresholds.get(j);
 
+                    String thresholdName = thresholdNode.get("thresholdName").asText();
+                    String value = thresholdNode.get("value").asText();
 
-                        newThresholds.put(thresholdName, value);
-                    }
+                    newThresholds.put(thresholdName, value);
+                }
 
-                    newAntiPatternMap.put(antiPatternName, newThresholds);
+                newAntiPatternMap.put(antiPatternName, newThresholds);
 
-                }
-                configurations.put(configurationName, newAntiPatternMap);
             }
-
-        } catch (Exception e) {
-            e.printStackTrace();
+            configurations.put(configurationName, newAntiPatternMap);
         }
+
         this.allConfigurations = configurations;
 
         LOGGER.info("-------FINISHED READING CONFIGURATIONS FROM FILES-------");
