Committed by
Gerrit Code Review
Minor refactoring for readiability and addition of comments.
Change-Id: I3e3ea598797ec6078955f5acd9642de9ff7ecd80
Showing
1 changed file
with
42 additions
and
10 deletions
| ... | @@ -140,38 +140,70 @@ public class NetworkConfigLoader { | ... | @@ -140,38 +140,70 @@ public class NetworkConfigLoader { |
| 140 | } | 140 | } |
| 141 | } | 141 | } |
| 142 | 142 | ||
| 143 | + /** | ||
| 144 | + * Save the JSON leaves associated with a specific subject key. | ||
| 145 | + * | ||
| 146 | + * @param sk the subject key string. | ||
| 147 | + * @param node the node associated with the subject key. | ||
| 148 | + */ | ||
| 143 | private void saveJson(String sk, ObjectNode node) { | 149 | private void saveJson(String sk, ObjectNode node) { |
| 144 | node.fieldNames().forEachRemaining(s -> | 150 | node.fieldNames().forEachRemaining(s -> |
| 145 | saveSubjectJson(sk, s, (ObjectNode) node.path(s))); | 151 | saveSubjectJson(sk, s, (ObjectNode) node.path(s))); |
| 146 | } | 152 | } |
| 147 | 153 | ||
| 154 | + /** | ||
| 155 | + * Save the JSON leaves of the tree rooted as the node 'node' with subject key 'sk'. | ||
| 156 | + * | ||
| 157 | + * @param sk the string of the subject key. | ||
| 158 | + * @param s the subject name. | ||
| 159 | + * @param node the node rooting this subtree. | ||
| 160 | + */ | ||
| 148 | private void saveSubjectJson(String sk, | 161 | private void saveSubjectJson(String sk, |
| 149 | String s, ObjectNode node) { | 162 | String s, ObjectNode node) { |
| 150 | node.fieldNames().forEachRemaining(c -> | 163 | node.fieldNames().forEachRemaining(c -> |
| 151 | this.jsons.put(new InnerConfigPosition(sk, s, c), (ObjectNode) node.path(c))); | 164 | this.jsons.put(new InnerConfigPosition(sk, s, c), (ObjectNode) node.path(c))); |
| 152 | } | 165 | } |
| 153 | 166 | ||
| 167 | + /** | ||
| 168 | + * Iterate through the JSON and populate a list of the leaf nodes of the structure. | ||
| 169 | + */ | ||
| 154 | private void populateConfigurations() { | 170 | private void populateConfigurations() { |
| 155 | root.fieldNames().forEachRemaining(sk -> | 171 | root.fieldNames().forEachRemaining(sk -> |
| 156 | saveJson(sk, (ObjectNode) root.path(sk))); | 172 | saveJson(sk, (ObjectNode) root.path(sk))); |
| 157 | 173 | ||
| 158 | } | 174 | } |
| 159 | 175 | ||
| 176 | + /** | ||
| 177 | + * Apply the configurations associated with all of the config classes that are imported and have not yet been | ||
| 178 | + * applied. | ||
| 179 | + */ | ||
| 160 | protected void applyConfigurations() { | 180 | protected void applyConfigurations() { |
| 161 | Iterator<Map.Entry<InnerConfigPosition, ObjectNode>> iter = jsons.entrySet().iterator(); | 181 | Iterator<Map.Entry<InnerConfigPosition, ObjectNode>> iter = jsons.entrySet().iterator(); |
| 182 | + | ||
| 162 | Map.Entry<InnerConfigPosition, ObjectNode> entry; | 183 | Map.Entry<InnerConfigPosition, ObjectNode> entry; |
| 184 | + InnerConfigPosition key; | ||
| 185 | + ObjectNode node; | ||
| 186 | + String subjectKey; | ||
| 187 | + String subject; | ||
| 188 | + String classKey; | ||
| 189 | + | ||
| 163 | while (iter.hasNext()) { | 190 | while (iter.hasNext()) { |
| 164 | entry = iter.next(); | 191 | entry = iter.next(); |
| 165 | - if (networkConfigService.getConfigClass(networkConfigService.getSubjectFactory(entry.getKey(). | 192 | + node = entry.getValue(); |
| 166 | - getSubjectKey()).subjectKey(), entry.getKey().getSubject()) != null) { | 193 | + key = entry.getKey(); |
| 167 | - networkConfigService.applyConfig(networkConfigService.getSubjectFactory( | 194 | + subjectKey = key.getSubjectKey(); |
| 168 | - entry.getKey().getSubjectKey()).createSubject(entry.getKey().getSubject()), | 195 | + subject = key.getSubject(); |
| 169 | - networkConfigService.getConfigClass(networkConfigService.getSubjectFactory(entry.getKey(). | 196 | + classKey = key.getClassKey(); |
| 170 | - getSubjectKey()).subjectKey(), entry.getKey().getClassKey()), | 197 | + //Check that the config class has been imported |
| 171 | - (ObjectNode) root.path(entry.getKey().getSubjectKey()). | 198 | + if (networkConfigService.getConfigClass(subjectKey, subject) != null) { |
| 172 | - path(entry.getKey().getSubject()). | 199 | + |
| 173 | - path(entry.getKey().getClassKey())); | 200 | + //Apply the configuration |
| 174 | - jsons.remove(entry.getKey()); | 201 | + networkConfigService.applyConfig(networkConfigService.getSubjectFactory(subjectKey). |
| 202 | + createSubject(subject), | ||
| 203 | + networkConfigService.getConfigClass(subjectKey, classKey), node); | ||
| 204 | + | ||
| 205 | + //Now that it has been applied the corresponding JSON entry is no longer needed | ||
| 206 | + jsons.remove(key); | ||
| 175 | } | 207 | } |
| 176 | 208 | ||
| 177 | } | 209 | } | ... | ... |
-
Please register or login to post a comment