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

Commit 3ef01e1

Browse files
committed
#241 Added CPF database name property
1 parent 27eb090 commit 3ef01e1

File tree

5 files changed

+62
-21
lines changed

5 files changed

+62
-21
lines changed

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ public class AppConfig {
104104
private String testContentDatabaseName;
105105
private String modulesDatabaseName;
106106
private String triggersDatabaseName;
107+
private String cpfDatabaseName;
107108
private String schemasDatabaseName;
108109

109110
private List<String> modulePaths;
@@ -1204,4 +1205,12 @@ public String getModelsDatabase() {
12041205
public void setModelsDatabase(String modelsDatabase) {
12051206
this.modelsDatabase = modelsDatabase;
12061207
}
1208+
1209+
public String getCpfDatabaseName() {
1210+
return cpfDatabaseName != null ? cpfDatabaseName : getTriggersDatabaseName();
1211+
}
1212+
1213+
public void setCpfDatabaseName(String cpfDatabaseName) {
1214+
this.cpfDatabaseName = cpfDatabaseName;
1215+
}
12071216
}

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,12 @@ public AppConfig newAppConfig() {
105105
c.setTriggersDatabaseName(prop);
106106
}
107107

108+
prop = getProperty("mlCpfDatabaseName");
109+
if (prop != null) {
110+
logger.info("CPF database name: " + prop);
111+
c.setCpfDatabaseName(prop);
112+
}
113+
108114
/**
109115
* Defines the MarkLogic host that requests should be sent to. Defaults to localhost.
110116
*/

src/main/java/com/marklogic/appdeployer/command/cpf/AbstractCpfResourceCommand.java

Lines changed: 32 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -8,26 +8,38 @@
88

99
import java.io.File;
1010

11+
/**
12+
* Base class for commands that deploy CPF resources. By default, this will use getCpfDatabaseName on AppConfig to
13+
* determine what database to deploy CPF resources to. That can be overridden via the setDatabaseIdOrName method
14+
* on this class.
15+
*/
1116
public abstract class AbstractCpfResourceCommand extends AbstractCommand {
1217

13-
protected abstract File getCpfResourceDir(ConfigDir configDir);
14-
15-
protected abstract AbstractCpfResourceManager getResourceManager(CommandContext context, String databaseIdOrName);
16-
17-
@Override
18-
public void execute(CommandContext context) {
19-
AppConfig config = context.getAppConfig();
20-
for (ConfigDir configDir : config.getConfigDirs()) {
21-
File dir = getCpfResourceDir(configDir);
22-
if (dir.exists()) {
23-
AbstractCpfResourceManager mgr = getResourceManager(context, config.getTriggersDatabaseName());
24-
for (File f : listFilesInDirectory(dir)) {
25-
String payload = copyFileToString(f, context);
26-
mgr.save(payload);
27-
}
28-
} else {
29-
logResourceDirectoryNotFound(dir);
30-
}
31-
}
32-
}
18+
private String databaseIdOrName;
19+
20+
protected abstract File getCpfResourceDir(ConfigDir configDir);
21+
22+
protected abstract AbstractCpfResourceManager getResourceManager(CommandContext context, String databaseIdOrName);
23+
24+
@Override
25+
public void execute(CommandContext context) {
26+
AppConfig config = context.getAppConfig();
27+
for (ConfigDir configDir : config.getConfigDirs()) {
28+
File dir = getCpfResourceDir(configDir);
29+
if (dir.exists()) {
30+
final String db = databaseIdOrName != null ? databaseIdOrName : config.getCpfDatabaseName();
31+
AbstractCpfResourceManager mgr = getResourceManager(context, db);
32+
for (File f : listFilesInDirectory(dir)) {
33+
String payload = copyFileToString(f, context);
34+
mgr.save(payload);
35+
}
36+
} else {
37+
logResourceDirectoryNotFound(dir);
38+
}
39+
}
40+
}
41+
42+
public void setDatabaseIdOrName(String databaseIdOrName) {
43+
this.databaseIdOrName = databaseIdOrName;
44+
}
3345
}

src/main/java/com/marklogic/appdeployer/command/cpf/DeployDefaultPipelinesCommand.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public DeployDefaultPipelinesCommand() {
1313

1414
@Override
1515
public void execute(CommandContext context) {
16-
new PipelineManager(context.getManageClient(), context.getAppConfig().getTriggersDatabaseName())
16+
new PipelineManager(context.getManageClient(), context.getAppConfig().getCpfDatabaseName())
1717
.loadDefaultPipelines();
1818
}
1919

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,20 @@ public void appServicesDiffersFromRestAdmin() {
8181
assertEquals("appword", config.getAppServicesPassword());
8282
}
8383

84+
@Test
85+
public void cpfDatabaseName() {
86+
sut = new DefaultAppConfigFactory(new SimplePropertySource("mlAppName", "test"));
87+
AppConfig config = sut.newAppConfig();
88+
assertEquals("test-triggers", config.getTriggersDatabaseName());
89+
assertEquals("CPF database should default to the triggers database when not specified",
90+
"test-triggers", config.getCpfDatabaseName());
91+
92+
sut = new DefaultAppConfigFactory(new SimplePropertySource("mlAppName", "test", "mlCpfDatabaseName", "my-cpf-db"));
93+
config = sut.newAppConfig();
94+
assertEquals("test-triggers", config.getTriggersDatabaseName());
95+
assertEquals("my-cpf-db", config.getCpfDatabaseName());
96+
}
97+
8498
@Test
8599
public void allProperties() {
86100
Properties p = new Properties();

0 commit comments

Comments
 (0)