Skip to content

Commit 82abef2

Browse files
committed
Use DynamicConfigValidator instead of ElideConfigParser
1 parent d37c377 commit 82abef2

File tree

5 files changed

+23
-140
lines changed

5 files changed

+23
-140
lines changed

elide-contrib/elide-dynamic-config-helpers/src/main/java/com/yahoo/elide/contrib/dynamicconfighelpers/compile/ElideDynamicEntityCompiler.java

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55
*/
66
package com.yahoo.elide.contrib.dynamicconfighelpers.compile;
77

8+
import com.yahoo.elide.contrib.dynamicconfighelpers.DynamicConfigHelpers;
89
import com.yahoo.elide.contrib.dynamicconfighelpers.model.ElideSecurityConfig;
910
import com.yahoo.elide.contrib.dynamicconfighelpers.model.ElideTableConfig;
10-
import com.yahoo.elide.contrib.dynamicconfighelpers.parser.ElideConfigParser;
1111
import com.yahoo.elide.contrib.dynamicconfighelpers.parser.handlebars.HandlebarsHydrator;
12-
12+
import com.yahoo.elide.contrib.dynamicconfighelpers.validator.DynamicConfigValidator;
1313
import com.google.common.collect.Sets;
1414

1515
import org.mdkt.compiler.InMemoryJavaCompiler;
@@ -49,13 +49,17 @@ public class ElideDynamicEntityCompiler {
4949
*/
5050
public ElideDynamicEntityCompiler(String path) throws Exception {
5151

52-
ElideTableConfig tableConfig = new ElideTableConfig();
53-
ElideSecurityConfig securityConfig = new ElideSecurityConfig();
54-
ElideConfigParser elideConfigParser = new ElideConfigParser(path);
52+
if (DynamicConfigHelpers.isNullOrEmpty(path)) {
53+
throw new IllegalArgumentException("Config path is null");
54+
}
5555
HandlebarsHydrator hydrator = new HandlebarsHydrator();
5656

57-
tableConfig = elideConfigParser.getElideTableConfig();
58-
securityConfig = elideConfigParser.getElideSecurityConfig();
57+
DynamicConfigValidator dynamicConfigValidator = new DynamicConfigValidator();
58+
dynamicConfigValidator.readAndValidateConfigs(path);
59+
60+
ElideTableConfig tableConfig = dynamicConfigValidator.getElideTableConfig();
61+
ElideSecurityConfig securityConfig = dynamicConfigValidator.getElideSecurityConfig();
62+
5963
tableClasses = hydrator.hydrateTableTemplate(tableConfig);
6064
securityClasses = hydrator.hydrateSecurityTemplate(securityConfig);
6165

elide-contrib/elide-dynamic-config-helpers/src/main/java/com/yahoo/elide/contrib/dynamicconfighelpers/parser/ElideConfigParser.java

Lines changed: 0 additions & 52 deletions
This file was deleted.

elide-contrib/elide-dynamic-config-helpers/src/main/java/com/yahoo/elide/contrib/dynamicconfighelpers/validator/DynamicConfigValidator.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
@Slf4j
4343
@Data
4444
/**
45-
* Util class to validate the model config files in local before deployment.
45+
* Util class to validate and parse the model config files.
4646
*/
4747
public class DynamicConfigValidator {
4848

@@ -74,7 +74,7 @@ public static void main(String[] args) throws IOException, ParseException {
7474
}
7575
String configDir = cli.getOptionValue("configDir");
7676
File file = new File(configDir);
77-
String absoluteBasePath = DynamicConfigHelpers.formatFilePath(file.getAbsolutePath());
77+
String absoluteBasePath = file.getAbsolutePath();
7878
log.info("Absolute Path for Model Configs Directory: " + absoluteBasePath);
7979

8080
if (!file.isDirectory()) {
@@ -89,12 +89,12 @@ public static void main(String[] args) throws IOException, ParseException {
8989

9090
/**
9191
* Read and validate config files under config directory
92-
* @param absoluteBasePath Absolute base path for config directory
92+
* @param filePath path for config directory
9393
* @throws IOException IOException
9494
*/
95-
public void readAndValidateConfigs(String absoluteBasePath) throws IOException {
95+
public void readAndValidateConfigs(String filePath) throws IOException {
9696

97-
this.setConfigDir(absoluteBasePath);
97+
this.setConfigDir(DynamicConfigHelpers.formatFilePath(filePath));
9898
this.readVariableConfig();
9999
if (this.readSecurityConfig()) {
100100
validateRoleInSecurityConfig(this.getElideSecurityConfig());

elide-contrib/elide-dynamic-config-helpers/src/test/java/com/yahoo/elide/contrib/dynamicconfighelpers/parser/ElideConfigParserTest.java

Lines changed: 0 additions & 68 deletions
This file was deleted.

elide-contrib/elide-dynamic-config-helpers/src/test/java/com/yahoo/elide/contrib/dynamicconfighelpers/parser/handlebars/HandlebarsHydratorTest.java

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
import static org.junit.jupiter.api.Assertions.assertEquals;
99

10-
import com.yahoo.elide.contrib.dynamicconfighelpers.parser.ElideConfigParser;
10+
import com.yahoo.elide.contrib.dynamicconfighelpers.validator.DynamicConfigValidator;
1111

1212
import org.junit.jupiter.api.Test;
1313

@@ -242,7 +242,8 @@ public void testConfigHydration() throws IOException {
242242
String absolutePath = file.getAbsolutePath();
243243
String hjsonPath = absolutePath + "/tables/table1.hjson";
244244

245-
ElideConfigParser testClass = new ElideConfigParser(absolutePath);
245+
DynamicConfigValidator testClass = new DynamicConfigValidator();
246+
testClass.readAndValidateConfigs(path);
246247

247248
Map<String, Object> map = testClass.getVariables();
248249

@@ -256,10 +257,9 @@ public void testTableHydration() throws IOException {
256257

257258
HandlebarsHydrator obj = new HandlebarsHydrator();
258259
String path = "src/test/resources/models";
259-
File file = new File(path);
260-
String absolutePath = file.getAbsolutePath();
261260

262-
ElideConfigParser testClass = new ElideConfigParser(absolutePath);
261+
DynamicConfigValidator testClass = new DynamicConfigValidator();
262+
testClass.readAndValidateConfigs(path);
263263

264264
Map<String, String> tableClasses = obj.hydrateTableTemplate(testClass.getElideTableConfig());
265265

@@ -271,10 +271,9 @@ public void testTableHydration() throws IOException {
271271
public void testSecurityHydration() throws IOException {
272272
HandlebarsHydrator obj = new HandlebarsHydrator();
273273
String path = "src/test/resources/models";
274-
File file = new File(path);
275-
String absolutePath = file.getAbsolutePath();
276274

277-
ElideConfigParser testClass = new ElideConfigParser(absolutePath);
275+
DynamicConfigValidator testClass = new DynamicConfigValidator();
276+
testClass.readAndValidateConfigs(path);
278277

279278
Map<String, String> securityClasses = obj.hydrateSecurityTemplate(testClass.getElideSecurityConfig());
280279

0 commit comments

Comments
 (0)