Projekt

Obecné

Profil

« Předchozí | Další » 

Revize 9904ea40

Přidáno uživatelem stepanekp před asi 3 roky(ů)

Configuration reading from files edited

Zobrazit rozdíly:

src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/repository/ConfigurationRepository.java
45 45
     */
46 46
    private void loadConfigurations(){
47 47
        LOGGER.info("-------START READING CONFIGURATIONS FROM FILES-------");
48
        Map<String, Map<String, Map<String, String>>> configurations = new HashMap<>();
49 48

  
50
        File folder = null;
49
        Map<String, Map<String, Map<String, String>>> configurations = new HashMap<>();
51 50

  
51
        File configurationsFolder = null;
52 52
        try {
53 53
            URL url = servletContext.getResource(CONFIGURATION_DIR);
54
            folder = new File(url.getFile());
54
            configurationsFolder = new File(url.getFile());
55 55
        } catch (Exception e) {
56
            e.printStackTrace();
57 56
            LOGGER.error("Cannot access folder with configurations " + CONFIGURATION_DIR);
57
            return;
58 58
        }
59 59

  
60
        for (final File fileEntry : folder.listFiles()) {
60
        // iterate over all configuration files in the folder
61
        for (final File fileEntry : configurationsFolder.listFiles()) {
61 62
            LOGGER.info("Reading configuration from file " + fileEntry.getName());
62 63

  
63
            String json = "";   // json configuration file
64
            String jsonContent = "";   // json configuration file
64 65
            try {
65 66
                BufferedReader read = new BufferedReader(new InputStreamReader(fileEntry.toURI().toURL().openStream()));
66 67

  
67 68
                String line;
68 69
                while ((line = read.readLine()) != null) {
69
                    json += line;
70
                    jsonContent += line;
70 71
                }
71 72
            }
72 73
            catch(Exception e){
73
                e.printStackTrace();
74 74
                LOGGER.error("Cannot read configuration from file " + fileEntry.getName());
75 75
                continue;
76 76
            }
77 77

  
78
            JsonNode node = null;
78
            // parsing of the json file content
79
            JsonNode rootNode = null;
79 80
            try {
80
                node = JsonParser.parse(json);
81
                rootNode = JsonParser.parse(jsonContent);
81 82
            } catch (IOException e) {
82
                e.printStackTrace();
83 83
                LOGGER.error("Cannot parse configuration from file " + fileEntry.getName());
84 84
                continue;
85 85
            }
86 86

  
87 87
            String configurationName = fileEntry.getName().split("\\.")[0];
88 88

  
89
            JsonNode arrayOfConfigurations = node.get("configuration");
89
            JsonNode arrayOfConfigurations = rootNode.get("configuration");
90 90

  
91
            if(arrayOfConfigurations == null)
91
            if(arrayOfConfigurations == null)   // empty array
92 92
                continue;
93 93

  
94 94
            Map<String, Map<String, String>> newAntiPatternMap = new HashMap<>();
......
111 111

  
112 112
                    newThresholds.put(thresholdName, value);
113 113
                }
114

  
115 114
                newAntiPatternMap.put(antiPatternName, newThresholds);
116 115

  
117 116
            }

Také k dispozici: Unified diff