|
1 | 1 | package com.marklogic.appdeployer;
|
2 | 2 |
|
3 | 3 | import java.io.File;
|
| 4 | +import java.io.FileFilter; |
4 | 5 | import java.util.ArrayList;
|
| 6 | +import java.util.Arrays; |
5 | 7 | import java.util.List;
|
6 | 8 |
|
7 | 9 | /**
|
8 | 10 | * Defines all of the directories where configuration files can be found. This is decoupled from the NounManager
|
9 | 11 | * classes, who don't need to care where to look for configuration files, they just need to care about how to load the
|
10 | 12 | * data in those files.
|
11 |
| - * |
12 |
| - * Every directory path referenced in this should have a setter so that it can be modified in e.g. a Gradle build file. |
13 | 13 | */
|
14 | 14 | public class ConfigDir {
|
15 | 15 |
|
16 |
| - private File baseDir; |
| 16 | + private File baseDir; |
17 | 17 |
|
18 |
| - private String databasesPath = "databases"; |
19 |
| - private String defaultContentDatabaseFilename = "content-database.json"; |
| 18 | + private String databasesPath = "databases"; |
| 19 | + private String defaultContentDatabaseFilename = "content-database.json"; |
20 | 20 |
|
21 |
| - private String restApiPath = "rest-api.json"; |
| 21 | + private String restApiPath = "rest-api.json"; |
22 | 22 |
|
23 |
| - private List<File> contentDatabaseFiles; |
| 23 | + private List<File> contentDatabaseFiles; |
24 | 24 |
|
25 |
| - public ConfigDir() { |
26 |
| - this(new File("src/main/ml-config")); |
27 |
| - } |
| 25 | + public ConfigDir() { |
| 26 | + this(new File("src/main/ml-config")); |
| 27 | + } |
| 28 | + |
| 29 | + public ConfigDir(File baseDir) { |
| 30 | + setBaseDir(baseDir); |
| 31 | + } |
| 32 | + |
| 33 | + public void setBaseDir(File baseDir) { |
| 34 | + this.baseDir = baseDir; |
| 35 | + initializeContentDatabaseFiles(); |
| 36 | + } |
| 37 | + |
| 38 | + public File getDatabasesDir() { |
| 39 | + return new File(baseDir, databasesPath); |
| 40 | + } |
| 41 | + |
| 42 | + /** |
| 43 | + * Return a list of every directory under the databases directory. Each such directory is considered to contain |
| 44 | + * resources for the database with a name matching that of the directory. |
| 45 | + * |
| 46 | + * @return |
| 47 | + */ |
| 48 | + public List<File> getDatabaseResourceDirectories() { |
| 49 | + File dbDir = getDatabasesDir(); |
| 50 | + if (dbDir != null && dbDir.exists()) { |
| 51 | + File[] dirs = dbDir.listFiles(new FileFilter() { |
| 52 | + @Override |
| 53 | + public boolean accept(File pathname) { |
| 54 | + return pathname.isDirectory(); |
| 55 | + } |
| 56 | + }); |
| 57 | + return Arrays.asList(dirs); |
| 58 | + } |
| 59 | + return new ArrayList<File>(); |
| 60 | + } |
28 | 61 |
|
29 |
| - public ConfigDir(File baseDir) { |
30 |
| - setBaseDir(baseDir); |
31 |
| - } |
| 62 | + protected void initializeContentDatabaseFiles() { |
| 63 | + contentDatabaseFiles = new ArrayList<>(); |
| 64 | + contentDatabaseFiles.add(new File(getDatabasesDir(), defaultContentDatabaseFilename)); |
| 65 | + } |
32 | 66 |
|
33 |
| - public void setBaseDir(File baseDir) { |
34 |
| - this.baseDir = baseDir; |
35 |
| - initializeContentDatabaseFiles(); |
36 |
| - } |
| 67 | + public File getRestApiFile() { |
| 68 | + return new File(baseDir, restApiPath); |
| 69 | + } |
37 | 70 |
|
38 |
| - public File getDatabasesDir() { |
39 |
| - return new File(baseDir, databasesPath); |
40 |
| - } |
| 71 | + public File getRestApiServerFile() { |
| 72 | + return new File(getServersDir(), "rest-api-server.json"); |
| 73 | + } |
| 74 | + |
| 75 | + public File getSecurityDir() { |
| 76 | + return new File(baseDir, "security"); |
| 77 | + } |
| 78 | + |
| 79 | + public File getServersDir() { |
| 80 | + return new File(baseDir, "servers"); |
| 81 | + } |
| 82 | + |
| 83 | + public File getForestsDir() { |
| 84 | + return new File(baseDir, "forests"); |
| 85 | + } |
41 | 86 |
|
42 |
| - protected void initializeContentDatabaseFiles() { |
43 |
| - contentDatabaseFiles = new ArrayList<>(); |
44 |
| - contentDatabaseFiles.add(new File(getDatabasesDir(), defaultContentDatabaseFilename)); |
45 |
| - } |
| 87 | + public File getCpfDir() { |
| 88 | + return new File(baseDir, "cpf"); |
| 89 | + } |
46 | 90 |
|
47 |
| - public File getRestApiFile() { |
48 |
| - return new File(baseDir, restApiPath); |
49 |
| - } |
| 91 | + public File getClustersDir() { |
| 92 | + return new File(baseDir, "clusters"); |
| 93 | + } |
50 | 94 |
|
51 |
| - public File getRestApiServerFile() { |
52 |
| - return new File(getServersDir(), "rest-api-server.json"); |
53 |
| - } |
| 95 | + public File getAlertDir() { |
| 96 | + return new File(baseDir, "alert"); |
| 97 | + } |
54 | 98 |
|
55 |
| - public File getSecurityDir() { |
56 |
| - return new File(baseDir, "security"); |
57 |
| - } |
| 99 | + public File getAlertConfigsDir() { |
| 100 | + return new File(getAlertDir(), "configs"); |
| 101 | + } |
58 | 102 |
|
59 |
| - public File getServersDir() { return new File(baseDir, "servers"); } |
| 103 | + public File getFlexrepDir() { |
| 104 | + return new File(baseDir, "flexrep"); |
| 105 | + } |
60 | 106 |
|
61 |
| - public File getForestsDir() { |
62 |
| - return new File(baseDir, "forests"); |
63 |
| - } |
| 107 | + public File getFlexrepConfigsDir() { |
| 108 | + return new File(getFlexrepDir(), "configs"); |
| 109 | + } |
64 | 110 |
|
65 |
| - public File getCpfDir() { |
66 |
| - return new File(baseDir, "cpf"); |
67 |
| - } |
| 111 | + public File getViewSchemasDir() { |
| 112 | + return new File(baseDir, "view-schemas"); |
| 113 | + } |
68 | 114 |
|
69 |
| - public File getClustersDir() { |
70 |
| - return new File(baseDir, "clusters"); |
71 |
| - } |
| 115 | + public File getTemporalDir() { |
| 116 | + return new File(baseDir, "temporal"); |
| 117 | + } |
72 | 118 |
|
73 |
| - public File getAlertDir() { |
74 |
| - return new File(baseDir, "alert"); |
75 |
| - } |
| 119 | + public File getTemporalAxesDir() { |
| 120 | + return new File(getTemporalDir(), "axes"); |
| 121 | + } |
76 | 122 |
|
77 |
| - public File getFlexrepDir() { |
78 |
| - return new File(baseDir, "flexrep"); |
79 |
| - } |
| 123 | + public File getTemporalCollectionsDir() { |
| 124 | + return new File(getTemporalDir(), "collections"); |
| 125 | + } |
80 | 126 |
|
81 |
| - public File getTemporalDir() { return new File(baseDir, "temporal"); } |
| 127 | + public File getTemporalCollectionsLsqtDir() { |
| 128 | + return new File(getTemporalCollectionsDir(), "lqst"); |
| 129 | + } |
82 | 130 |
|
83 | 131 | public File getTasksDir() {
|
84 |
| - return new File(baseDir, "tasks"); |
| 132 | + return new File(baseDir, "tasks"); |
85 | 133 | }
|
86 | 134 |
|
87 | 135 | public void setDatabasesPath(String databasesPath) {
|
88 |
| - this.databasesPath = databasesPath; |
89 |
| - } |
| 136 | + this.databasesPath = databasesPath; |
| 137 | + } |
90 | 138 |
|
91 |
| - public void setRestApiPath(String restApiPath) { |
92 |
| - this.restApiPath = restApiPath; |
93 |
| - } |
| 139 | + public void setRestApiPath(String restApiPath) { |
| 140 | + this.restApiPath = restApiPath; |
| 141 | + } |
94 | 142 |
|
95 |
| - public File getBaseDir() { |
96 |
| - return baseDir; |
97 |
| - } |
| 143 | + public File getBaseDir() { |
| 144 | + return baseDir; |
| 145 | + } |
98 | 146 |
|
99 |
| - public List<File> getContentDatabaseFiles() { |
100 |
| - return contentDatabaseFiles; |
101 |
| - } |
| 147 | + public List<File> getContentDatabaseFiles() { |
| 148 | + return contentDatabaseFiles; |
| 149 | + } |
102 | 150 |
|
103 |
| - public void setContentDatabaseFiles(List<File> contentDatabaseFiles) { |
104 |
| - this.contentDatabaseFiles = contentDatabaseFiles; |
105 |
| - } |
| 151 | + public void setContentDatabaseFiles(List<File> contentDatabaseFiles) { |
| 152 | + this.contentDatabaseFiles = contentDatabaseFiles; |
| 153 | + } |
106 | 154 |
|
107 |
| - public String getDefaultContentDatabaseFilename() { |
108 |
| - return defaultContentDatabaseFilename; |
109 |
| - } |
| 155 | + public String getDefaultContentDatabaseFilename() { |
| 156 | + return defaultContentDatabaseFilename; |
| 157 | + } |
110 | 158 |
|
111 |
| - public void setDefaultContentDatabaseFilename(String contentDatabaseFilename) { |
112 |
| - this.defaultContentDatabaseFilename = contentDatabaseFilename; |
113 |
| - } |
| 159 | + public void setDefaultContentDatabaseFilename(String contentDatabaseFilename) { |
| 160 | + this.defaultContentDatabaseFilename = contentDatabaseFilename; |
| 161 | + } |
114 | 162 | }
|
0 commit comments