Skip to content
This repository was archived by the owner on Sep 16, 2024. It is now read-only.

Commit 5624083

Browse files
committed
#341 Now loading schemas from multiple paths
1 parent 679493a commit 5624083

File tree

11 files changed

+128
-58
lines changed

11 files changed

+128
-58
lines changed

src/main/java/com/marklogic/appdeployer/AppConfig.java

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ public class AppConfig {
130130
private Integer modulesLoaderBatchSize;
131131
private boolean incrementalDeploy = false;
132132

133-
private String schemasPath;
133+
private List<String> schemaPaths;
134134
private boolean tdeValidationEnabled = true;
135135

136136
private List<ConfigDir> configDirs;
@@ -253,7 +253,9 @@ public AppConfig(File projectDir) {
253253
String path = projectDir != null ? new File(projectDir, DEFAULT_MODULES_PATH).getAbsolutePath() : DEFAULT_MODULES_PATH;
254254
modulePaths.add(path);
255255

256-
schemasPath = projectDir != null ? new File(projectDir, DEFAULT_SCHEMAS_PATH).getAbsolutePath() : DEFAULT_SCHEMAS_PATH;
256+
String defaultSchemasPath = projectDir != null ? new File(projectDir, DEFAULT_SCHEMAS_PATH).getAbsolutePath() : DEFAULT_SCHEMAS_PATH;
257+
schemaPaths = new ArrayList<>();
258+
schemaPaths.add(defaultSchemasPath);
257259

258260
configDirs = new ArrayList<>();
259261
configDirs.add(ConfigDir.withProjectDir(projectDir));
@@ -531,17 +533,6 @@ public void setTestRestPort(Integer testRestPort) {
531533
this.testRestPort = testRestPort;
532534
}
533535

534-
/**
535-
* @return a list of all the paths from which modules should be loaded into a REST API server modules database
536-
*/
537-
public String getSchemasPath() {
538-
return schemasPath;
539-
}
540-
541-
public void setSchemasPath(String schemasPath) {
542-
this.schemasPath = schemasPath;
543-
}
544-
545536
/**
546537
* @return a list of all the paths from which modules should be loaded into a REST API server modules database
547538
*/
@@ -1335,4 +1326,12 @@ public PluginConfig getPluginConfig() {
13351326
public void setPluginConfig(PluginConfig pluginConfig) {
13361327
this.pluginConfig = pluginConfig;
13371328
}
1329+
1330+
public List<String> getSchemaPaths() {
1331+
return schemaPaths;
1332+
}
1333+
1334+
public void setSchemaPaths(List<String> schemaPaths) {
1335+
this.schemaPaths = schemaPaths;
1336+
}
13381337
}

src/main/java/com/marklogic/appdeployer/DefaultAppConfigFactory.java

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -281,13 +281,15 @@ public void initialize() {
281281
config.setTestContentDatabaseName(prop);
282282
});
283283

284-
/**
285-
* Defines the path to files that should be loaded into a schemas database. Defaults to src/main/ml-schemas.
286-
*/
284+
// Deprecated - use mlSchemaPaths instead
287285
propertyConsumerMap.put("mlSchemasPath", (config, prop) -> {
288-
logger.info("Schemas path: " + prop);
289-
String path = this.projectDir != null ? new File(this.projectDir, prop).getAbsolutePath() : prop;
290-
config.setSchemasPath(path);
286+
logger.info("mlSchemasPath is deprecated as of version 3.13.0; please use mlSchemaPaths instead; schemas path: " + prop);
287+
config.setSchemaPaths(buildPathListFromCommaDelimitedString(prop));
288+
});
289+
290+
propertyConsumerMap.put("mlSchemaPaths", (config, prop) -> {
291+
logger.info("Schema paths: " + prop);
292+
config.setSchemaPaths(buildPathListFromCommaDelimitedString(prop));
291293
});
292294

293295
propertyConsumerMap.put("mlTdeValidationEnabled", (config, prop) -> {
@@ -527,14 +529,7 @@ public void initialize() {
527529
*/
528530
propertyConsumerMap.put("mlModulePaths", (config, prop) -> {
529531
logger.info("Module paths: " + prop);
530-
String[] paths = prop.split(",");
531-
// Ensure we have a modifiable list
532-
List<String> list = new ArrayList<>();
533-
for (String s : paths) {
534-
String path = this.projectDir != null ? new File(projectDir, s).getAbsolutePath() : s;
535-
list.add(path);
536-
}
537-
config.setModulePaths(list);
532+
config.setModulePaths(buildPathListFromCommaDelimitedString(prop));
538533
});
539534

540535
propertyConsumerMap.put("mlModuleTimestampsPath", (config, prop) -> {
@@ -753,12 +748,7 @@ protected void registerPluginProperties() {
753748

754749
propertyConsumerMap.put("mlPluginPaths", (config, prop) -> {
755750
logger.info("Paths that plugins will be installed from: " + prop);
756-
List<String> paths = new ArrayList<>();
757-
for (String s : prop.split(",")) {
758-
String path = this.projectDir != null ? new File(projectDir, s).getAbsolutePath() : s;
759-
paths.add(path);
760-
}
761-
config.getPluginConfig().setPluginPaths(paths);
751+
config.getPluginConfig().setPluginPaths(buildPathListFromCommaDelimitedString(prop));
762752
});
763753

764754
propertyConsumerMap.put("mlPluginUriPrefix", (config, prop) -> {
@@ -790,6 +780,16 @@ protected void setDefaultsForDatabasesWithForestsOnOneHost(AppConfig appConfig)
790780
}
791781
}
792782

783+
protected List<String> buildPathListFromCommaDelimitedString(String prop) {
784+
String[] paths = prop.split(",");
785+
List<String> list = new ArrayList<>();
786+
for (String s : paths) {
787+
String path = this.projectDir != null ? new File(projectDir, s).getAbsolutePath() : s;
788+
list.add(path);
789+
}
790+
return list;
791+
}
792+
793793
protected Map<String, String> buildMapFromCommaDelimitedString(String str) {
794794
Map<String, String> map = new HashMap<>();
795795
String[] tokens = str.split(",");

src/main/java/com/marklogic/appdeployer/command/es/GenerateModelArtifactsCommand.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ protected void generateDatabaseProperties(AppConfig appConfig, GeneratedCode cod
215215
protected void generateSchema(AppConfig appConfig, GeneratedCode code) {
216216
String schema = code.getSchema();
217217
if (schema != null) {
218-
File dir = new File(appConfig.getSchemasPath());
218+
File dir = new File(appConfig.getSchemaPaths().get(0));
219219
dir.mkdirs();
220220
File out = new File(dir, code.getTitle() + "-" + code.getVersion() + ".xsd");
221221
String logMessage = "Wrote schema to: ";
@@ -243,7 +243,7 @@ protected void generateSchema(AppConfig appConfig, GeneratedCode code) {
243243
protected void generateExtractionTemplate(AppConfig appConfig, GeneratedCode code) {
244244
String template = code.getExtractionTemplate();
245245
if (template != null) {
246-
File dir = new File(appConfig.getSchemasPath());
246+
File dir = new File(appConfig.getSchemaPaths().get(0));
247247
dir.mkdirs();
248248
dir = new File(dir, "tde");
249249
dir.mkdirs();

src/main/java/com/marklogic/appdeployer/command/schemas/LoadSchemasCommand.java

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
import java.io.File;
1818
import java.io.FileFilter;
19+
import java.util.List;
1920

2021
public class LoadSchemasCommand extends AbstractCommand {
2122

@@ -25,23 +26,20 @@ public LoadSchemasCommand() {
2526

2627
@Override
2728
public void execute(CommandContext context) {
28-
loadSchemasFromSchemasPath(context);
29+
loadSchemasFromSchemaPaths(context);
2930
loadSchemasFromDatabaseSpecificPaths(context);
3031
}
3132

3233
/**
33-
* This expects a single path to be defined in the AppConfig object. If set, then any files at that path are loaded
34-
* into the schemas database defined by the AppConfig object.
35-
*
3634
* @param context
3735
*/
38-
protected void loadSchemasFromSchemasPath(CommandContext context) {
36+
protected void loadSchemasFromSchemaPaths(CommandContext context) {
3937
AppConfig config = context.getAppConfig();
40-
final String schemasPath = config.getSchemasPath();
41-
if (schemasPath != null && schemasPath.trim().length() > 0) {
42-
loadSchemas(config.getSchemasPath(), config.getSchemasDatabaseName(), context);
43-
} else {
44-
logger.info("Schemas path is empty, so not attempting to load any schemas");
38+
List<String> schemaPaths = config.getSchemaPaths();
39+
if (schemaPaths != null && !schemaPaths.isEmpty()) {
40+
for (String path : schemaPaths) {
41+
loadSchemas(path, config.getSchemasDatabaseName(), context);
42+
}
4543
}
4644
}
4745

src/test/java/com/marklogic/appdeployer/DefaultAppConfigFactoryTest.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public void withProjectDir() {
3434
assertEquals("modulesPath2", appConfig.getModulePaths().get(1));
3535
assertEquals(testPath + "/path1", appConfig.getConfigDirs().get(0).getBaseDir().getAbsolutePath());
3636
assertEquals(testPath + "/path2", appConfig.getConfigDirs().get(1).getBaseDir().getAbsolutePath());
37-
assertEquals("schemasPath", appConfig.getSchemasPath());
37+
assertEquals("schemasPath", appConfig.getSchemaPaths().get(0));
3838

3939
File projectDir = new File("src/test/resources/sample-app");
4040
final String projectPath = projectDir.getAbsolutePath();
@@ -44,7 +44,7 @@ public void withProjectDir() {
4444
assertEquals(projectPath + "/modulesPath2", appConfig.getModulePaths().get(1));
4545
assertEquals(projectPath + "/path1", appConfig.getConfigDirs().get(0).getBaseDir().getAbsolutePath());
4646
assertEquals(projectPath + "/path2", appConfig.getConfigDirs().get(1).getBaseDir().getAbsolutePath());
47-
assertEquals(projectPath + "/schemasPath", appConfig.getSchemasPath());
47+
assertEquals(projectPath + "/schemasPath", appConfig.getSchemaPaths().get(0));
4848
}
4949

5050
/**
@@ -60,15 +60,15 @@ public void withProjectDirAndDefaultPaths() {
6060
AppConfig appConfig = sut.newAppConfig();
6161
assertEquals("src/main/ml-modules", appConfig.getModulePaths().get(0));
6262
assertEquals(testPath + "/src/main/ml-config", appConfig.getConfigDirs().get(0).getBaseDir().getAbsolutePath());
63-
assertEquals("src/main/ml-schemas", appConfig.getSchemasPath());
63+
assertEquals("src/main/ml-schemas", appConfig.getSchemaPaths().get(0));
6464

6565
File projectDir = new File("src/test/resources/sample-app");
6666
final String projectPath = projectDir.getAbsolutePath();
6767
sut.setProjectDir(projectDir);
6868
appConfig = sut.newAppConfig();
6969
assertEquals(projectPath + "/src/main/ml-modules", appConfig.getModulePaths().get(0));
7070
assertEquals(projectPath + "/src/main/ml-config", appConfig.getConfigDirs().get(0).getBaseDir().getAbsolutePath());
71-
assertEquals(projectPath + "/src/main/ml-schemas", appConfig.getSchemasPath());
71+
assertEquals(projectPath + "/src/main/ml-schemas", appConfig.getSchemaPaths().get(0));
7272
}
7373

7474
@Test
@@ -260,7 +260,7 @@ public void mostProperties() {
260260
p.setProperty("mlModulesDatabaseName", "my-modules");
261261
p.setProperty("mlSchemasDatabaseName", "my-schemas-db");
262262
p.setProperty("mlTriggersDatabaseName", "my-triggers-db");
263-
p.setProperty("mlSchemasPath", "/my/schemas");
263+
p.setProperty("mlSchemaPaths", "/my/schemas,/my/other/schemas");
264264
p.setProperty("mlTdeValidationEnabled", "false");
265265
p.setProperty("mlDeleteForests", "false");
266266
p.setProperty("mlDeleteReplicas", "false");
@@ -374,7 +374,8 @@ public void mostProperties() {
374374
assertEquals("my-modules", config.getModulesDatabaseName());
375375
assertEquals("my-schemas-db", config.getSchemasDatabaseName());
376376
assertEquals("my-triggers-db", config.getTriggersDatabaseName());
377-
assertEquals("/my/schemas", config.getSchemasPath());
377+
assertEquals("/my/schemas", config.getSchemaPaths().get(0));
378+
assertEquals("/my/other/schemas", config.getSchemaPaths().get(1));
378379
assertFalse(config.isTdeValidationEnabled());
379380
assertFalse(config.isDeleteForests());
380381
assertFalse(config.isDeleteReplicas());

src/test/java/com/marklogic/appdeployer/command/es/GenerateModelArtifactsTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ public void test() {
3030
appConfig.setModelsPath(projectPath + "/data/entity-services");
3131
appConfig.getModulePaths().clear();
3232
appConfig.getModulePaths().add(projectPath + "/src/main/ml-modules");
33-
appConfig.setSchemasPath(projectPath + "/src/main/ml-schemas");
33+
appConfig.getSchemaPaths().clear();
34+
appConfig.getSchemaPaths().add(projectPath + "/src/main/ml-schemas");
3435
appConfig.setModelsDatabase(appConfig.getContentDatabaseName());
3536

3637
initializeAppDeployer(new DeployContentDatabasesCommand(1), new DeployOtherDatabasesCommand(1),

src/test/java/com/marklogic/appdeployer/command/schemas/LoadSchemasTest.java

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,19 @@
1515

1616
public class LoadSchemasTest extends AbstractAppDeployerTest {
1717

18+
@After
19+
public void cleanup() {
20+
undeploySampleApp();
21+
}
22+
1823
@Test
1924
public void databaseSpecificPaths() {
2025
initializeAppDeployer(new DeployOtherDatabasesCommand(), newCommand());
2126

2227
appConfig.getFirstConfigDir().setBaseDir(new File("src/test/resources/sample-app/multiple-schema-databases/ml-config"));
2328
appConfig.setSchemasDatabaseName("sample-app-schemas1");
24-
appConfig.setSchemasPath("src/test/resources/sample-app/multiple-schema-databases/ml-schemas");
29+
appConfig.getSchemaPaths().clear();
30+
appConfig.getSchemaPaths().add("src/test/resources/sample-app/multiple-schema-databases/ml-schemas");
2531

2632
deploySampleApp();
2733

@@ -61,7 +67,8 @@ public void testSchemaLoading() {
6167
public void testCustomSchemasPathWithCustomFileFilter() {
6268
initializeAppDeployer(new DeployOtherDatabasesCommand(), new DeployContentDatabasesCommand(1), newCommand());
6369

64-
appConfig.setSchemasPath("src/test/resources/schemas-marklogic9");
70+
appConfig.getSchemaPaths().clear();
71+
appConfig.getSchemaPaths().add("src/test/resources/schemas-marklogic9");
6572
appConfig.setSchemasFileFilter(new CustomFileFilter());
6673
appConfig.setTdeValidationEnabled(false);
6774
appDeployer.deploy(appConfig);
@@ -85,7 +92,7 @@ public void testCustomSchemasPathWithCustomFileFilter() {
8592
@Test
8693
public void nullSchemaPath() {
8794
initializeAppDeployer(newCommand());
88-
appConfig.setSchemasPath(null);
95+
appConfig.setSchemaPaths(null);
8996
deploySampleApp();
9097
logger.info("Verifies that no error occurs when the schemas path is null");
9198
}
@@ -104,9 +111,24 @@ public void tdeValidationEnabled() {
104111
}
105112
}
106113

107-
@After
108-
public void cleanup() {
109-
undeploySampleApp();
114+
@Test
115+
public void multipleSchemaPaths() {
116+
File projectDir = new File("src/test/resources/schemas-project");
117+
118+
initializeAppConfig(projectDir);
119+
appConfig.getSchemaPaths().add(new File(projectDir, "src/main/more-schemas").getAbsolutePath());
120+
121+
initializeAppDeployer(new DeployContentDatabasesCommand(1), new DeployOtherDatabasesCommand(),
122+
new LoadSchemasCommand());
123+
deploySampleApp();
124+
125+
DatabaseClient client = appConfig.newSchemasDatabaseClient();
126+
GenericDocumentManager docMgr = client.newDocumentManager();
127+
assertNotNull(docMgr.exists("/tde/template1.json"));
128+
assertNotNull(docMgr.exists("/tde/template2.json"));
129+
130+
assertTrue(docMgr.readMetadata("/tde/template1.json", new DocumentMetadataHandle()).getCollections().contains("http://marklogic.com/xdmp/tde"));
131+
assertTrue(docMgr.readMetadata("/tde/template2.json", new DocumentMetadataHandle()).getCollections().contains("http://marklogic.com/xdmp/tde"));
110132
}
111133

112134
private Command newCommand() {
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"database-name": "%%DATABASE%%",
3+
"schema-database": "%%SCHEMAS_DATABASE%%"
4+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"database-name": "%%SCHEMAS_DATABASE%%"
3+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"template": {
3+
"context": "/example",
4+
"collections": [
5+
"example"
6+
],
7+
"rows": [
8+
{
9+
"schemaName": "Example",
10+
"viewName": "default",
11+
"columns": [
12+
{
13+
"name": "Id",
14+
"scalarType": "string",
15+
"val": "Id"
16+
}
17+
]
18+
}
19+
]
20+
}
21+
}

0 commit comments

Comments
 (0)